@zukhruf/shadcn 0.8.47 → 0.8.48
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 +46 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Each [shadcn/ui](https://ui.shadcn.com) component, as one package. The components use Base UI as their headless library and nova as their preset. An app imports the components from one entry and the styles from one stylesheet. The app sets its theme with CSS variables.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## The problem
|
|
5
|
+
shadcn/ui is not a package. Its CLI copies the source of each component into the repo of the app. Thus each app keeps its own copy, and the copies drift apart. A fix in one copy does not go into the other copies. For example, two apps each wrote the same fix for a tall dialog, and other apps still do not have it. Also, `shadcn add --overwrite` writes over a copy, and it removes the changes that an app made by hand. This package keeps one copy. A fix goes into the package one time, and each app gets it with the next version.
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
This package keeps one copy. A fix goes into the package one time, and each app gets it with the next version.
|
|
7
|
+
The words in these documents have one meaning each. See the glossary in [CONTEXT.md](./CONTEXT.md).
|
|
12
8
|
|
|
13
|
-
##
|
|
9
|
+
## Use it
|
|
14
10
|
|
|
15
11
|
```sh
|
|
16
12
|
npm i @zukhruf/shadcn
|
|
@@ -18,8 +14,6 @@ npm i @zukhruf/shadcn
|
|
|
18
14
|
|
|
19
15
|
The peer dependencies are `react` 19, `react-dom` 19 and `tailwindcss` 4. The other dependencies, for example `@base-ui/react` and `lucide-react`, install with the package.
|
|
20
16
|
|
|
21
|
-
## Use it
|
|
22
|
-
|
|
23
17
|
Import the stylesheet in the Tailwind CSS file of the app, after Tailwind:
|
|
24
18
|
|
|
25
19
|
```css
|
|
@@ -38,7 +32,7 @@ Obey two rules:
|
|
|
38
32
|
- **Use a plain `@import`.** Do not write `@import '@zukhruf/shadcn/styles.css' layer(components);`. A `layer()` puts all of the stylesheet into a layer, also its `@utility` and `@source` rules. Tailwind CSS refuses these rules in a layer. The build stops with the error "`@utility` cannot be nested."
|
|
39
33
|
- **Do not add an `@source` for the package.** The stylesheet registers its own `dist` folder. Tailwind CSS then finds the classes of the components. See [ADR 0003](./docs/adr/0003-the-stylesheet-registers-its-own-source-and-keeps-its-patches-in-layers.md).
|
|
40
34
|
|
|
41
|
-
##
|
|
35
|
+
## Set the theme
|
|
42
36
|
|
|
43
37
|
The theme is the values of a set of CSS variables, for example `--primary`, `--background` and `--radius`. To change the theme, set the variables after the import:
|
|
44
38
|
|
|
@@ -83,7 +77,7 @@ The preset is fixed. The class strings of each component contain the preset, for
|
|
|
83
77
|
|
|
84
78
|
The theme also covers the density of the controls and the field labels: `--control-height`, `--control-height-sm`, `--control-background`, `--field-label-foreground` and `--field-label-font-size` (see [what the stylesheet adds](#what-the-stylesheet-adds-to-stock-shadcnui)). Set a token, not a `className` restyle such as `h-10 bg-card` on each control. A subtree can set a second value, for example taller controls on the auth pages. See [ADR 0006](./docs/adr/0006-a-host-gets-its-looks-through-theme-tokens-and-data-attribute-patches.md).
|
|
85
79
|
|
|
86
|
-
##
|
|
80
|
+
## Read the open state of the sidebar on the server
|
|
87
81
|
|
|
88
82
|
`SidebarProvider` keeps its open state in a cookie. `SIDEBAR_COOKIE_NAME` is the name of that cookie. Use it to read the open state of the sidebar on the server, and give the value to `defaultOpen`:
|
|
89
83
|
|
|
@@ -95,7 +89,7 @@ const defaultOpen = cookies.get(SIDEBAR_COOKIE_NAME)?.value !== 'false';
|
|
|
95
89
|
<SidebarProvider defaultOpen={defaultOpen}>{children}</SidebarProvider>;
|
|
96
90
|
```
|
|
97
91
|
|
|
98
|
-
##
|
|
92
|
+
## Set the element that a component renders
|
|
99
93
|
|
|
100
94
|
Base UI uses the `render` prop where Radix UI uses `asChild`. The `render` prop sets the element that the component renders.
|
|
101
95
|
|
|
@@ -113,7 +107,7 @@ Base UI:
|
|
|
113
107
|
<DialogTrigger render={<Button variant="outline" />}>Open</DialogTrigger>
|
|
114
108
|
```
|
|
115
109
|
|
|
116
|
-
##
|
|
110
|
+
## Show the components right to left
|
|
117
111
|
|
|
118
112
|
The sync installs the components in the RTL mode of shadcn (`"rtl": true` in `components.json`). The CLI then writes logical classes in place of physical ones: `ps-2.5` for `pl-2.5`, `end-2` for `right-2`, `text-start` for `text-left`, `rtl:rotate-180` on a chevron that points forward, `rtl:` translations for the switch thumb and the submenu line of the sidebar, and `side="inline-end"` for a submenu. Thus each component mirrors itself in a right-to-left page, and it renders as before in a left-to-right page.
|
|
119
113
|
|
|
@@ -143,7 +137,7 @@ The width patch is in `@layer utilities`, because only a rule in that layer wins
|
|
|
143
137
|
|
|
144
138
|
The tabs patch is in `@layer utilities` for the same reason. Its selector has two attributes and a class, so it wins over the one class of `group-data-horizontal/tabs:h-8` in any order of the rules.
|
|
145
139
|
|
|
146
|
-
##
|
|
140
|
+
## Make a link look like a button
|
|
147
141
|
|
|
148
142
|
A control that goes to a different page must stay a link. Do not write `<Button render={<Link />} nativeButton={false}>`. This makes an `<a>` with `role="button"`. A screen reader then calls the link a button, and the Space key activates it.
|
|
149
143
|
|
|
@@ -169,7 +163,7 @@ Use `cn` around `buttonVariants`. `Button` merges the classes that conflict thro
|
|
|
169
163
|
- **Use a component of the package first.** Before you write a new component, look for one in this package. Use it when it does the job.
|
|
170
164
|
- **Keep your own components in the app.** A component that you make from the components of this package belongs to the app. Do not add it to this package. The sync writes over the generated source, and the package holds only the components of shadcn/ui.
|
|
171
165
|
- **Remove the outline of a `Card` with `ring-0`.** `Card` draws its outline with `ring-1`, not with a border. Thus `border-0` does not remove the outline.
|
|
172
|
-
- **Use the standard names of the theme variables.** Set `--primary`, `--background` and the other variables of the [theme](#theme). Do not add a brand prefix, for example `--acme-primary`. The components read only the standard names.
|
|
166
|
+
- **Use the standard names of the theme variables.** Set `--primary`, `--background` and the other variables of the [theme](#set-the-theme). Do not add a brand prefix, for example `--acme-primary`. The components read only the standard names.
|
|
173
167
|
- **Put a `DropdownMenuLabel` in a `DropdownMenuGroup`.** `DropdownMenuLabel` uses `Menu.GroupLabel` of Base UI, and that component reads the context of a group. A label outside a group throws Base UI error #31, and the full menu stops. Radix UI accepted a label outside a group, thus an app that moves from Radix UI must find these labels. text2sql found one when it moved.
|
|
174
168
|
|
|
175
169
|
```tsx
|
|
@@ -181,10 +175,23 @@ Use `cn` around `buttonVariants`. `Button` merges the classes that conflict thro
|
|
|
181
175
|
</DropdownMenuContent>
|
|
182
176
|
```
|
|
183
177
|
|
|
178
|
+
- **Put each `SelectItem` in a `SelectGroup`, and each `CommandItem` in a `CommandGroup`.** The list of `SelectContent` and `CommandList` have no padding. `SelectGroup` and `CommandGroup` give the `p-1` (`src/components/select.tsx`, `src/components/command.tsx`). Without a group, the items touch the edge of the popup, and `alignItemWithTrigger` moves the select popup about 5px off its trigger. text2sql put 58 Selects in a `SelectGroup` for this (text2sql 3e13c74f2). The `react` concept of `@zukhruf/eslint` refuses an item outside a group with `zukhruf/require-select-group` (b06049b1) and `zukhruf/require-command-group` (dd748598).
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
<SelectContent>
|
|
182
|
+
<SelectGroup>
|
|
183
|
+
<SelectItem value="light">Light</SelectItem>
|
|
184
|
+
<SelectItem value="dark">Dark</SelectItem>
|
|
185
|
+
</SelectGroup>
|
|
186
|
+
</SelectContent>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- **Give a `SelectTrigger` the width that you need.** `SelectTrigger` is `w-fit` (`src/components/select.tsx`). An app that moves from an old copy adds `w-full` where the old copy had it. The migrations of the apps found this.
|
|
190
|
+
- **Mount one `Toaster`.** By default, each `Toaster` reads the one `toast` manager of the package (`toastManager = toast` in `src/components/toast.tsx`). An app that moves from an old copy moves all of its toasts in one commit, and never mounts two Toasters at once.
|
|
184
191
|
- **Know that the stylesheet changes the `data-*` variants of your own classes too.** `theme.css` imports `shadcn/tailwind.css`, and its `@custom-variant` rules redefine `data-open`, `data-closed`, `data-checked`, `data-unchecked`, `data-selected`, `data-disabled`, `data-active`, `data-horizontal` and `data-vertical` (`node_modules/shadcn/dist/tailwind.css`, `shadcn@4.23.0`). Stock Tailwind CSS makes `data-selected:` match an element that has the attribute, with any value ([Tailwind CSS: data attributes](https://tailwindcss.com/docs/hover-focus-and-other-states#data-attributes)). With the stylesheet, `data-selected:` matches only `[data-selected="true"]`. `data-open:`, `data-closed:`, `data-checked:`, `data-unchecked:`, `data-disabled:` and `data-active:` do not match the value `"false"`, and all of them except `data-disabled:` also match the same value of `data-state`, for example `[data-state="open"]`. `data-horizontal:` and `data-vertical:` match `[data-orientation="horizontal"]` and `[data-orientation="vertical"]`. These rules apply to each class of the app, not only to the components. For a different value, write the full form, for example `data-[selected=false]:`.
|
|
185
192
|
- **Show an error at the place where it occurs.** Show a form error or a field error next to the field or the action that failed, for example with `FieldError`. Show the error of a background task or of a mutation as a toast. Use `toast` and `Toaster` of this package, which use the toast of Base UI.
|
|
186
193
|
|
|
187
|
-
##
|
|
194
|
+
## Join class names in your own components
|
|
188
195
|
|
|
189
196
|
An app that writes its own components often needs `cn`, the function that joins class names. Import it from the `cn` package:
|
|
190
197
|
|
|
@@ -194,7 +201,7 @@ import { cn } from 'cn';
|
|
|
194
201
|
|
|
195
202
|
This package does not export `cn`. Each symbol has one home ([zukhruf ADR 0001](../../docs/adr/0001-zukhruf-is-a-layered-standard-library.md), rule 6).
|
|
196
203
|
|
|
197
|
-
##
|
|
204
|
+
## Import all components from the one entry
|
|
198
205
|
|
|
199
206
|
The package has one entry, `@zukhruf/shadcn`. It exports all components, all hooks and the hand-written modules, for example `SIDEBAR_COOKIE_NAME`. There are no subpaths such as `@zukhruf/shadcn/button`.
|
|
200
207
|
|
|
@@ -205,6 +212,28 @@ The package has one entry, `@zukhruf/shadcn`. It exports all components, all hoo
|
|
|
205
212
|
|
|
206
213
|
See [ADR 0002](./docs/adr/0002-one-entry-and-private-imports-between-the-components.md).
|
|
207
214
|
|
|
215
|
+
## What the package does not do
|
|
216
|
+
|
|
217
|
+
- **It does not export `cn`.** Import `cn` from the `cn` package. Each symbol has one home ([zukhruf ADR 0001](../../docs/adr/0001-zukhruf-is-a-layered-standard-library.md), rule 6).
|
|
218
|
+
- **It has no subpaths.** An app imports each component from the one entry ([ADR 0002](./docs/adr/0002-one-entry-and-private-imports-between-the-components.md)).
|
|
219
|
+
- **It does not hold the components of an app.** A component that an app makes from these components stays in the app. The sync writes over the generated source, and the package holds only the components of shadcn/ui ([ADR 0001](./docs/adr/0001-the-shadcn-cli-writes-the-source-and-the-commit-pins-it.md)).
|
|
220
|
+
- **It does not let an app change the preset.** The class strings of each component contain nova. An app changes only the theme ([ADR 0004](./docs/adr/0004-the-components-use-base-ui-and-the-nova-preset.md)).
|
|
221
|
+
- **It does not set `--destructive-foreground`, `--success`, `--warning` or `--font-heading`.** An app that needs one sets it and maps it in its own `@theme inline` block (see [Set the theme](#set-the-theme)).
|
|
222
|
+
|
|
223
|
+
## Who uses it
|
|
224
|
+
|
|
225
|
+
Each app imports the stylesheet in its Tailwind CSS file and the components from the entry. A library, such as blackboard `packages/annotation` or deepagents `packages/react/genai`, imports only the components, and the app that hosts it imports the stylesheet.
|
|
226
|
+
|
|
227
|
+
| Consumer | How | Record |
|
|
228
|
+
| ----------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
|
|
229
|
+
| sdk-it `packages/apiref` | `@import '@zukhruf/shadcn/styles.css'` in `app/styles.css`. It replaced both shadcn copies of the repo. | sdk-it 245d1b7 |
|
|
230
|
+
| blackboard `apps/web`, `packages/annotation` | It replaced the local shadcn copy, and the Radix UI components of `annotation`. | blackboard e6323a0, dcb9449 |
|
|
231
|
+
| deepagents `apps/evals-web-runner`, `packages/devtool/host`, `packages/react/genai` | It replaced `@deepagents/react-shadcn`. `react-genai` has the package as a peer dependency (f7ceed16). | deepagents 65b7db3a |
|
|
232
|
+
| text2sql, its frontends and UI packages, for example `apps/authx/frontend` | `@import "@zukhruf/shadcn/styles.css"` in `src/styles.css`. About 25 commits, one for each project, replaced the copy, and the last one deleted it. | text2sql c0c95b42 |
|
|
233
|
+
| factory `apps/factory/web` | The shadcn components of the app come from the entry, for example in `src/app/routes/Layout/Layout.tsx`. | factory f1513cc |
|
|
234
|
+
| context-compiler `packages/ui` | `@import '@zukhruf/shadcn/styles.css'` in `src/page.css`. `ContextMenu` and `Select` replaced the Radix UI menus and list. | context-compiler 4c83084 |
|
|
235
|
+
| theagentlab `apps/hackathon` | `@import '@zukhruf/shadcn/styles.css'` in `src/styles.css`. `Select` replaced four native `<select>` elements. | theagentlab 640ddd6 |
|
|
236
|
+
|
|
208
237
|
## API
|
|
209
238
|
|
|
210
239
|
The entry (`src/index.ts`) has one `export *` line for each file of 63 components, two hooks and one hand-written module. The component files are in `src/components`: `accordion`, `alert-dialog`, `alert`, `aspect-ratio`, `attachment`, `avatar`, `badge`, `breadcrumb`, `bubble`, `button-group`, `button`, `calendar`, `card`, `carousel`, `chart`, `checkbox`, `code-block`, `collapsible`, `combobox`, `command`, `context-menu`, `dialog`, `direction`, `drawer`, `dropdown-menu`, `empty`, `field`, `hover-card`, `input-group`, `input-otp`, `input`, `item`, `kbd`, `label`, `marker`, `menubar`, `message-scroller`, `message`, `native-select`, `navigation-menu`, `pagination`, `popover`, `progress`, `questionnaire`, `radio-group`, `resizable`, `scroll-area`, `select`, `separator`, `sheet`, `sidebar`, `skeleton`, `slider`, `spinner`, `switch`, `table`, `tabs`, `textarea`, `toast`, `toggle-group`, `toggle`, `tooltip` and `trace`. Each file holds the components of the registry item with the same name.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/shadcn",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.48",
|
|
4
4
|
"description": "Each shadcn/ui component for Base UI with the nova preset, in one package. An app imports the components from one entry and the styles from one stylesheet. The shadcn CLI writes the source, and nobody edits it by hand.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|