@zukhruf/shadcn 0.8.46 → 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.
Files changed (3) hide show
  1. package/README.md +50 -19
  2. package/package.json +1 -1
  3. package/styles.css +20 -0
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
- The words in these documents have one meaning each. See the glossary in [CONTEXT.md](./CONTEXT.md).
6
-
7
- ## The problem
8
-
9
- 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.
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.
10
6
 
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
- ## Install
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
- ## Theme
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
 
@@ -81,9 +75,9 @@ The `@theme inline` block of `theme.css` maps these variables to Tailwind CSS co
81
75
 
82
76
  The preset is fixed. The class strings of each component contain the preset, for example the rounded corners and the spacing of the dialog. Thus an app cannot change the preset. An app changes only the theme. See [ADR 0004](./docs/adr/0004-the-components-use-base-ui-and-the-nova-preset.md).
83
77
 
84
- The theme also covers the density of the controls: `--control-height`, `--control-height-sm` and `--control-background` (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).
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
- ## The open state of the sidebar
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
- ## Composition
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
- ## Right to left
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
 
@@ -123,7 +117,7 @@ Not fixed: the mobile sidebar has a hidden title and description in English (`Si
123
117
 
124
118
  ## What the stylesheet adds to stock shadcn/ui
125
119
 
126
- The stylesheet has seven patches:
120
+ The stylesheet has eight patches:
127
121
 
128
122
  - **A pointer cursor on enabled buttons.** In Tailwind CSS 4, a button has the default cursor of the browser, not the pointer. The upgrade guide of Tailwind CSS gives a rule that sets the pointer again. The patch is that rule, in `@layer base`.
129
123
  - **A cap on the height of a dialog.** A dialog is never taller than the window minus `2rem`, and it scrolls when its content is taller. Thus the buttons at the bottom of a tall dialog stay on the screen. The rule is `max-height: calc(100dvh - 2rem); overflow-y: auto` on `[data-slot="dialog-content"]`. The patch is in `@layer components`.
@@ -135,13 +129,15 @@ The stylesheet has seven patches:
135
129
 
136
130
  - **The controls take their height and background from the theme.** `--control-height` sets the height of `Input`, `SelectTrigger` at `data-size="default"`, `InputGroup` and `Button` at the default size, and the minimum height of `Textarea` and `ComboboxChips`. `--control-height-sm` sets the height of `Button` at `size="sm"`. The button rules are keyed on the `group/button` class of `buttonVariants()`, so a link with the classes of a button takes them too. `--control-background` sets the background of `Input`, `Textarea`, `SelectTrigger`, `InputGroup` and `ComboboxChips`. Without a value, each rule falls back to nova: 32px (64px for `Textarea`), 28px, and `transparent` (`input/30` under `.dark`). Each rule is keyed on the nova class that it replaces, for example `[data-slot='input'].h-8`, so a class of the app that tailwind-merge swaps in for that class turns the rule off. A disabled control, an `InputGroup` with a textarea or a block-aligned addon, a hovered dark `SelectTrigger` and a button of an `InputGroup` keep their nova styles. The patch is in `@layer utilities`. See [ADR 0006](./docs/adr/0006-a-host-gets-its-looks-through-theme-tokens-and-data-attribute-patches.md).
137
131
 
132
+ - **The field labels take their colour and size from the theme.** `FieldLabel` and `FieldTitle` both write `data-slot="field-label"`. `--field-label-foreground` sets their colour and `--field-label-font-size` their size. Without a value, a label inherits its colour and keeps nova's `text-sm`, 14px. A label in a `Field` with `data-invalid="true"` keeps the `text-destructive` it inherits from the `Field`. The size rule is keyed on `text-sm`; nova gives a label no colour class, so the colour rule has no specificity and any `text-*` class of the app wins over it. The patch is in `@layer utilities`. See [ADR 0006](./docs/adr/0006-a-host-gets-its-looks-through-theme-tokens-and-data-attribute-patches.md).
133
+
138
134
  The cursor, the cap, the shortcut and the select popup are in layers before `utilities`. Thus a utility class of the app, for example `cursor-wait` or `max-h-none`, still changes them.
139
135
 
140
136
  The width patch is in `@layer utilities`, because only a rule in that layer wins over a utility class. Its selector has three attributes, so it wins over the two parts of `data-[side=left]:w-3/4`. The sidebar does not give its `className` to the mobile `Sheet`, so a utility class of the app cannot get to that element. To change the mobile width, write a rule outside of a layer.
141
137
 
142
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.
143
139
 
144
- ## Links that look like buttons
140
+ ## Make a link look like a button
145
141
 
146
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.
147
143
 
@@ -167,7 +163,7 @@ Use `cn` around `buttonVariants`. `Button` merges the classes that conflict thro
167
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.
168
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.
169
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.
170
- - **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.
171
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.
172
168
 
173
169
  ```tsx
@@ -179,10 +175,23 @@ Use `cn` around `buttonVariants`. `Button` merges the classes that conflict thro
179
175
  </DropdownMenuContent>
180
176
  ```
181
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.
182
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]:`.
183
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.
184
193
 
185
- ## Your own components
194
+ ## Join class names in your own components
186
195
 
187
196
  An app that writes its own components often needs `cn`, the function that joins class names. Import it from the `cn` package:
188
197
 
@@ -192,7 +201,7 @@ import { cn } from 'cn';
192
201
 
193
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).
194
203
 
195
- ## One entry
204
+ ## Import all components from the one entry
196
205
 
197
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`.
198
207
 
@@ -203,6 +212,28 @@ The package has one entry, `@zukhruf/shadcn`. It exports all components, all hoo
203
212
 
204
213
  See [ADR 0002](./docs/adr/0002-one-entry-and-private-imports-between-the-components.md).
205
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
+
206
237
  ## API
207
238
 
208
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.46",
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": {
package/styles.css CHANGED
@@ -134,3 +134,23 @@
134
134
  );
135
135
  }
136
136
  }
137
+
138
+ /*
139
+ * The tone and size of a field label are theme tokens too (ADR 0006).
140
+ * FieldLabel and FieldTitle both write data-slot="field-label". nova gives
141
+ * neither a colour class, so the colour patch has no specificity, as the input
142
+ * group's background has: any text-* class of the host wins over it. A label
143
+ * of an invalid Field keeps the text-destructive it inherits from the Field.
144
+ * The size is keyed on the text-sm both carry.
145
+ */
146
+ @layer utilities {
147
+ :where(
148
+ [data-slot='field-label']:not([data-slot='field'][data-invalid='true'] *)
149
+ ) {
150
+ color: var(--field-label-foreground, currentcolor);
151
+ }
152
+
153
+ [data-slot='field-label'].text-sm {
154
+ font-size: var(--field-label-font-size, var(--text-sm));
155
+ }
156
+ }