3.4.0 • Published 3 days ago

@waldronmatt/demo-ui v3.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

Demo-UI

A demo react component library. Heavily inspired by this article.

Features

  • Fully tree shakeable (js and css)
  • SSR compatible
  • Outputs:
    • esm and cjs source files
    • source maps for JavaScript files (.js.map)
    • esm and cjs declaration files (.d.ts and .c.ts)
    • esm and cjs source maps for declaration files (.d.ts.map and .c.ts.map)
    • compiled CSS modules (consuming app is not required to support css modules)
  • Subpath exports for explicit path referencing. Will auto map to the right module system
  • Component updates auto reflect (hmr) in monorepos when referenced via the lib subpath export installed via the workspace: protocol
  • Libraries are externalized for a lighter bundle size (react, react/jsx-runtime)

Installation

Install dependencies:

pnpm add @waldronmatt/demo-ui react react-dom

Install type definitions:

pnpm add -D @types/react @types/react-dom

Getting Started

MyApp.tsx

import { Button } from '@waldronmatt/demo-ui';

function App() {
  return <Button>Hello World</Button>;
}

export default App;

Explicit Paths

You can also declare the path explicitly. Because we are using import, the path below will auto map to the esm bundle of this library:

MyApp.tsx

import { Button } from '@waldronmatt/demo-ui/components/Button/index.js';

function App() {
  return <Button>Hello</Button>;
}

export default App;

Styles

This component library relies on a global css file via styles/global.css that provides token variables used by components.

This component library was tested using a custom css reset file via styles/reset.css.

To use, import into your app's entrypoint above the app and component imports:

MyApp.tsx

// demo-ui css reset file
import '@waldronmatt/demo-ui/styles/reset.css';
// demo-ui global css variable tokens
import '@waldronmatt/demo-ui/styles/global.css';
// demo-ui Button component js and styles
import { Button, type ButtonProps } from '@waldronmatt/demo-ui/components/Button/index.js';
// your app-specific styles, etc.
import './MyApp.css';

Next.js

Configure your next.config.js:

Note: Even though Next.js supports importing global stylesheets anywhere as of version 13.4, you still need to tell Next.js to compile this library. Because this library contains css imports in the final bundle, when consumed by a Next.js host application, Next.js will not be able to process those css import statements from node_modules unless we tell it to through the transpilePackages property.

next.config.js

const nextConfig = {
  transpilePackages: ['@waldronmatt/demo-ui'],
};

module.exports = nextConfig;

Monorepo Use

For use inside this monorepo, we import by referencing the lib subpath export and install via the workspace: protocol.

The advantage is that we can enable auto refresh (hmr) whenever we make updates to the component library.

pnpm add @waldronmatt/demo-ui --workspace --filter myapp

MyApp.tsx

import { Button, type ButtonProps } from '@waldronmatt/demo-ui/lib/index.js';

Explict paths:

import { Button, type ButtonProps } from '@waldronmatt/demo-ui/lib/components/Button/index.js';

License

MIT

3.4.0

3 days ago

3.3.10

1 month ago

3.3.11

1 month ago

3.3.12

1 month ago

3.3.9

2 months ago

3.3.8

2 months ago

3.3.7

2 months ago

3.3.6

3 months ago

3.3.5

3 months ago

3.3.4

3 months ago

3.3.3

3 months ago

3.3.2

3 months ago

3.3.1

3 months ago

3.2.3

3 months ago

3.3.0

3 months ago

3.2.2

4 months ago

3.2.1

4 months ago

3.2.0

4 months ago

3.1.2

4 months ago

3.1.1

4 months ago

3.1.0

4 months ago

3.0.8

4 months ago

3.0.9

4 months ago

3.0.4

4 months ago

3.0.7

4 months ago

3.0.6

4 months ago

3.0.5

4 months ago

3.0.3

4 months ago

3.0.2

4 months ago

3.0.1

4 months ago

3.0.0

5 months ago

2.3.3

5 months ago

2.3.2

5 months ago

2.3.0

5 months ago

2.3.1

5 months ago

2.1.2

5 months ago

2.2.0

5 months ago

2.1.1

5 months ago

2.1.0

5 months ago

2.0.14

5 months ago

2.0.13

5 months ago

2.0.12

5 months ago

2.0.11

5 months ago

2.0.10

5 months ago

2.0.9

5 months ago

2.0.8

5 months ago

2.0.7

5 months ago

2.0.6

6 months ago

2.0.5

6 months ago

2.0.4

6 months ago

2.0.3

6 months ago

2.0.2

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.2.12

6 months ago

1.2.11

6 months ago

1.2.10

6 months ago

1.2.9

6 months ago

1.2.8

7 months ago

1.2.7

7 months ago

1.2.6

7 months ago

1.2.5

7 months ago

1.2.4

7 months ago

1.2.3

7 months ago

1.2.2

7 months ago

1.2.1

7 months ago

1.2.0

7 months ago

1.1.3

7 months ago

1.1.2

8 months ago

1.1.1

8 months ago