@enonic/ui 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,18 +4,16 @@ A modern UI component library built with Preact/React, TypeScript, and Tailwind
4
4
 
5
5
  ## Installation
6
6
 
7
- #### pnpm
8
-
9
7
  #### With React
10
8
 
11
9
  ```bash
12
- pnpm add @enonic/ui react react-dom @radix-ui/react-slot focus-trap-react
10
+ pnpm add @enonic/ui react react-dom @radix-ui/react-slot
13
11
  ```
14
12
 
15
13
  #### With Preact
16
14
 
17
15
  ```bash
18
- pnpm add @enonic/ui preact @radix-ui/react-slot focus-trap-react
16
+ pnpm add @enonic/ui preact @radix-ui/react-slot
19
17
  ```
20
18
 
21
19
  <details>
@@ -24,57 +22,74 @@ pnpm add @enonic/ui preact @radix-ui/react-slot focus-trap-react
24
22
  #### With React
25
23
 
26
24
  ```bash
27
- npm install @enonic/ui react react-dom @radix-ui/react-slot focus-trap-react
25
+ npm install @enonic/ui react react-dom @radix-ui/react-slot
28
26
  ```
29
27
 
30
28
  #### With Preact
31
29
 
32
30
  ```bash
33
- npm install @enonic/ui preact @radix-ui/react-slot focus-trap-react
31
+ npm install @enonic/ui preact @radix-ui/react-slot
34
32
  ```
35
33
 
36
34
  </details>
37
35
 
38
- <details>
39
- <summary><b>Yarn</b></summary>
36
+ > Some components and styling paths need extra packages — `focus-trap-react` (dialogs and overlays), `react-virtuoso` (virtualized lists), and `tw-animate-css` (the Tailwind styling path). See [Peer Dependencies](#peer-dependencies).
40
37
 
41
- #### With React
38
+ ## Usage
42
39
 
43
- ```bash
44
- yarn add @enonic/ui react react-dom @radix-ui/react-slot focus-trap-react
45
- ```
40
+ ### Styles
46
41
 
47
- #### With Preact
42
+ > **Important**: Components are styled with Tailwind CSS utility classes and render unstyled until you load the CSS. Pick one of the two paths below.
48
43
 
49
- ```bash
50
- yarn add @enonic/ui preact @radix-ui/react-slot focus-trap-react
44
+ #### Option A — No Tailwind (prebuilt stylesheet)
45
+
46
+ Import the fully compiled stylesheet. It bundles Tailwind's output, the design tokens, and component animations — nothing else to configure:
47
+
48
+ ```css
49
+ @import '@enonic/ui/style.css';
51
50
  ```
52
51
 
53
- </details>
52
+ #### Option B — Your own Tailwind CSS (recommended)
54
53
 
55
- ## Usage
54
+ If your project already runs **Tailwind CSS v4**, integrate the design tokens through `preset.css` so components share your Tailwind build — one set of utilities, your theme overrides apply, and a smaller bundle. A working setup needs all of the following:
56
55
 
57
- ### Styles
56
+ ```css
57
+ /* Declare layer order first so your own overrides win over component styles */
58
+ @layer theme, base, components, utilities, overrides;
59
+
60
+ @import 'tailwindcss/theme.css' layer(theme);
61
+ @import 'tailwindcss/preflight.css' layer(base);
62
+ @import '@enonic/ui/preset.css'; /* design tokens, dark variant, base + custom utilities */
63
+ @import 'tw-animate-css'; /* component enter/exit animations (required — see below) */
64
+ @import 'tailwindcss/utilities.css' layer(utilities);
65
+
66
+ /* Let Tailwind scan @enonic/ui's compiled files for the classes its components use.
67
+ The path is relative to THIS file — adjust the number of ../ to reach node_modules. */
68
+ @source '../node_modules/@enonic/ui';
69
+ ```
58
70
 
59
- > **Important**: Components render unstyled without CSS setup. Choose one of the paths below before importing components.
71
+ > **`@source` is mandatory.** Tailwind v4 only generates the utilities it finds in scanned sources, and it ignores `node_modules` by default. The classes used inside `@enonic/ui` components live in its compiled output, so without `@source` pointing at the package those utilities are never generated and components render unstyled.
60
72
 
61
- #### Tailwind CSS
73
+ > **`tw-animate-css` is required on this path.** Components such as `Dialog`, `Toast`, and `Tooltip` emit `animate-in` / `fade-*` / `zoom-*` classes from [`tw-animate-css`](https://www.npmjs.com/package/tw-animate-css), which `preset.css` does not include. Install it (`pnpm add tw-animate-css`) and import it as shown. The prebuilt `style.css` already inlines these, so Option A doesn't need it.
62
74
 
63
- If your project uses Tailwind CSS, import the preset in your main CSS file:
75
+ If you don't need explicit layer control, the shorthand also works:
64
76
 
65
77
  ```css
66
78
  @import 'tailwindcss';
67
79
  @import 'tw-animate-css';
68
80
  @import '@enonic/ui/preset.css';
81
+ @source '../node_modules/@enonic/ui';
69
82
  ```
70
83
 
71
- #### CSS Only
84
+ #### CSS exports
72
85
 
73
- If your project does not use Tailwind CSS, import the pre-built stylesheet instead:
74
-
75
- ```css
76
- @import '@enonic/ui/style.css';
77
- ```
86
+ | Export | Contents | Use when |
87
+ | -------------------------- | --------------------------------------------------------------------- | --------------------------------- |
88
+ | `@enonic/ui/style.css` | Fully compiled — Tailwind output + tokens + animations | You don't run Tailwind (Option A) |
89
+ | `@enonic/ui/preset.css` | Design tokens (`@theme`), dark variant, base styles, custom utilities | You run Tailwind (Option B) |
90
+ | `@enonic/ui/tokens.css` | Design tokens + dark variant only | Tokens without base/utilities |
91
+ | `@enonic/ui/base.css` | Root font size + base text color | Granular composition |
92
+ | `@enonic/ui/utilities.css` | Custom `@utility` definitions (shimmer, `scrollbar-none`, …) | Granular composition |
78
93
 
79
94
  ### Import Components
80
95
 
@@ -93,59 +108,58 @@ function App() {
93
108
  }
94
109
  ```
95
110
 
96
- ## Peer Dependencies
111
+ ### Dark Mode
97
112
 
98
- This library requires one of the following frameworks:
113
+ The library ships light and dark themes as CSS variables, switched by a class. Add `dark` to a root element (or a shadow-DOM host) and every token updates:
99
114
 
100
- ### React
115
+ ```html
116
+ <html class="dark">
117
+ <!-- ... -->
118
+ </html>
119
+ ```
101
120
 
102
- ```json
103
- {
104
- "react": "^19.0.0",
105
- "react-dom": "^19.0.0",
106
- "@radix-ui/react-slot": "^1.2.0",
107
- "focus-trap-react": "^11.0.0"
108
- }
121
+ ```ts
122
+ // Toggle at runtime
123
+ document.documentElement.classList.toggle('dark', isDark);
109
124
  ```
110
125
 
111
- ### Preact
126
+ The variant is defined as `@custom-variant dark (&:where(.dark, .dark *))` and also matches `:host(.dark)` for web-component hosts. Use the `dark:` variant in your own markup as usual.
112
127
 
113
- ```json
114
- {
115
- "preact": ">=10.0.0",
116
- "@radix-ui/react-slot": "^1.2.0",
117
- "focus-trap-react": "^11.0.0"
118
- }
119
- ```
128
+ ### Icons
120
129
 
121
- ### Icon Libraries (Optional)
130
+ Icons used internally by components are bundled — no icon library install is required for components to render.
122
131
 
123
- The library uses and expects one of the following icon libraries to be used to provide icons for the components:
132
+ You only need a Lucide package when you pass a custom icon to a component that accepts one (e.g. `Tab`, `Link`, and `VirtualizedTreeList` expose an `icon` prop):
124
133
 
125
- - `lucide-react` (>=0.500.0) - For React projects
126
- - `lucide-preact` (>=0.500.0) - For Preact projects
134
+ ```tsx
135
+ import { Tab } from '@enonic/ui';
136
+ import { Star } from 'lucide-react'; // React
137
+ // import { Star } from 'lucide-preact'; // Preact
138
+
139
+ <Tab icon={Star} label='Favorites' />;
140
+ ```
127
141
 
128
- ## Development
142
+ Use `lucide-react` in React projects and `lucide-preact` in Preact projects — the `icon` prop accepts either.
129
143
 
130
- ```bash
131
- # Install dependencies
132
- pnpm install
144
+ ## Peer Dependencies
133
145
 
134
- # Start development server with Storybook
135
- pnpm dev
146
+ Installing `@enonic/ui` surfaces any unmet peers with the exact ranges it needs (defined in `package.json` — the source of truth).
136
147
 
137
- # Build the library
138
- pnpm build
148
+ **Required**
139
149
 
140
- # Run type checking
141
- pnpm typecheck
150
+ - `@radix-ui/react-slot` — backs the `asChild` prop used across components
142
151
 
143
- # Run linting
144
- pnpm lint
152
+ …plus one framework:
145
153
 
146
- # Check bundle size
147
- pnpm size
148
- ```
154
+ | React | Preact |
155
+ | --------------------------- | --------------- |
156
+ | `react` + `react-dom` (v19) | `preact` (v10+) |
157
+
158
+ **Optional** — add only if you use the related feature:
159
+
160
+ - `focus-trap-react` — focus management for `Dialog` and other overlay components
161
+ - `react-virtuoso` — required by `VirtualizedTreeList` and other virtualized lists
162
+ - `tw-animate-css` — component animations when integrating through `preset.css` (see [Styles](#styles))
149
163
 
150
164
  ## License
151
165