3.5.18 • Published 5 months ago

@waldronmatt/demo-ui v3.5.18

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

Demo-UI

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

This includes many modern best practices for publishing and consuming in monorepos.

Features

  • Fully tree shakeable (js and css)
  • SSR compatible
  • Outputs:
    • esm and cjs source files
    • source maps for JavaScript files (.js.map)
    • separate esm and cjs declaration files (.d.ts and .d.cts)
    • separate esm and cjs source maps for declaration files (.d.ts.map and .d.cts.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
  • Live monorepo hmr supported:
    • sub-packages in this monorepo install this package via the pnpm workspace: protocol
    • sub-packages in this monorepo reference this package's lib subpath export (can be lib/index.js or any files under lib)
  • Live monorepo types supported (approach detailed here):
    • top-level exports field defines types for source files
    • publishConfig defines types for production (will override exports when publishing to npm)
  • Passes all publint and arethetypeswrong audits.
  • 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.5.18

5 months ago

3.5.14

6 months ago

3.5.17

6 months ago

3.5.16

6 months ago

3.5.15

6 months ago

3.5.13

9 months ago

3.5.12

9 months ago

3.5.11

10 months ago

3.5.10

1 year ago

3.5.9

1 year ago

3.5.8

1 year ago

3.5.7

1 year ago

3.5.6

1 year ago

3.5.5

1 year ago

3.5.4

1 year ago

3.5.3

1 year ago

3.5.2

1 year ago

3.5.1

1 year ago

3.5.0

1 year ago

3.4.0

1 year ago

3.3.10

1 year ago

3.3.11

1 year ago

3.3.12

1 year ago

3.3.9

1 year ago

3.3.8

1 year ago

3.3.7

1 year ago

3.3.6

1 year ago

3.3.5

1 year ago

3.3.4

1 year ago

3.3.3

1 year ago

3.3.2

1 year ago

3.3.1

1 year ago

3.2.3

1 year ago

3.3.0

1 year ago

3.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.8

1 year ago

3.0.9

1 year ago

3.0.4

1 year ago

3.0.7

1 year ago

3.0.6

1 year ago

3.0.5

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

2 years ago

3.0.0

2 years ago

2.3.3

2 years ago

2.3.2

2 years ago

2.3.0

2 years ago

2.3.1

2 years ago

2.1.2

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.14

2 years ago

2.0.13

2 years ago

2.0.12

2 years ago

2.0.11

2 years ago

2.0.10

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.12

2 years ago

1.2.11

2 years ago

1.2.10

2 years ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago