1.5.3 • Published 5 months ago

cadells-vanilla-components v1.5.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Cadell's Vanilla Components

A basic component library built with vanilla-extract for use in my NextJS sites, namely prawn.cadell.dev and emojis.cadell.dev.

It uses tsup and np for building and publishing to NPM.

Commands

  • npm run build - Build the package.
  • npm run release - Publish a new version to NPM.
  • npm run build-release - Build and Publish to NPM.

Use with NextJS

Cadell's NextJS Template uses this package.

  1. Add cadells-vanilla-components.
    npm install cadells-vanilla-components @fontsource/source-sans-pro
  2. Add MDX dependencies.
    npm install --save-dev @next/mdx
  3. Add vanilla-extract dependencies.
    npm install --save-dev @vanilla-extract/css @vanilla-extract/next-plugin
  4. Setup next.config.js.

    const withMDX = require("@next/mdx")({
        extension: /\.mdx$/,
    });
    
    const { createVanillaExtractPlugin } = require("@vanilla-extract/next-plugin");
    const withVanillaExtract = createVanillaExtractPlugin();
    
    const nextConfig = {
        pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"],
    };
    
    module.exports = withVanillaExtract(withMDX(nextConfig));
  5. Configure _document.tsx inside /pages.

    import { InitialiseTheme } from "cadells-vanilla-components";
    import Document, { Html, Head, Main, NextScript } from "next/document";
    
    export default class MyDocument extends Document {
        static async getInitialProps(ctx: any) {
            const initialProps = await Document.getInitialProps(ctx);
            return { ...initialProps };
        }
    
        render() {
            return (
                <Html lang="en">
                    <Head>
                        <link
                            rel="icon"
                            href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>😏</text></svg>"
                        />
                    </Head>
                    <body>
                        <InitialiseTheme />
                        <Main />
                        <NextScript />
                    </body>
                </Html>
            );
        }
    }
  6. Configure _app.tsx inside /pages.

    import { Container, ThemeToggle } from "cadells-vanilla-components";
    import "cadells-vanilla-components/dist/index.css";
    import "@fontsource/source-sans-pro/400.css";
    import "@fontsource/source-sans-pro/600.css";
    
    const App = ({ Component, pageProps }) => (
        <Container>
            <ThemeToggle />
            <Component {...pageProps} />
        </Container>
    );
    
    export default App;
  7. Create mdx-components.tsx.

    import { mdComponents } from "cadells-vanilla-components";
    
    export function useMDXComponents() {
        return mdComponents;
    }

References:

Implementation

I've built NextJS apps with MDX and custom components for projects like prawn.cadell.dev before but I wanted to split this out into a separate package for emojis.cadell.dev. This is the result! I also created template.cadell.dev as a template for showing how to use it.

Creating this package was a bit harder than first thought but I'm happy with the result and I think emojis.cadell.dev looks great. I originally tried using tsdx but the typescript types weren't correct and I couldn't work out why. I decided to change direction and started looking for a tool based on esbuild instead of Rollup and found tsup which pretty much worked out of the box. Happy days! Tsdx did introduce me to np for publishing to NPM so I kept that and it works really well. Everything happened for a reason.

Todo

  1. Storybook.
  2. Tests.

References

1.5.3

5 months ago

1.5.2

5 months ago

1.5.1

5 months ago

1.5.0

5 months ago

1.2.0

6 months ago

1.1.0

6 months ago

1.0.0

6 months ago

1.4.0

6 months ago

0.4.1

8 months ago

0.4.0

8 months ago

0.4.2

8 months ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.18

2 years ago

0.3.13

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.9

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago