@zukhruf/shadcn 0.8.42 → 0.8.44
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 +50 -2
- package/package.json +1 -1
- package/styles.css +26 -0
package/README.md
CHANGED
|
@@ -59,6 +59,24 @@ The theme is the values of a set of CSS variables, for example `--primary`, `--b
|
|
|
59
59
|
- The package sets the default theme in `@layer base`. A rule outside of a layer wins over it. A rule in `@layer base` that comes after the import also wins over it. Thus a host theme in a layer, for example the ChatGPT tokens of OpenAI, can set the variables. A rule in `@layer theme` loses, because Tailwind CSS declares `theme` before `base`. See [ADR 0005](./docs/adr/0005-the-default-theme-is-in-layer-base.md).
|
|
60
60
|
- The `.dark` class switches to the dark theme. Put it on an element, usually `<html>`. The element and all elements in it then use the `.dark` variables.
|
|
61
61
|
|
|
62
|
+
The `@theme inline` block of `theme.css` maps these variables to Tailwind CSS colors, so that a class such as `bg-primary` reads them:
|
|
63
|
+
|
|
64
|
+
- `--background`, `--foreground`, `--card`, `--card-foreground`, `--popover`, `--popover-foreground`, `--primary`, `--primary-foreground`, `--secondary`, `--secondary-foreground`, `--muted`, `--muted-foreground`, `--accent`, `--accent-foreground`, `--destructive`, `--border`, `--input` and `--ring`.
|
|
65
|
+
- `--chart-1` to `--chart-5`.
|
|
66
|
+
- `--sidebar`, `--sidebar-foreground`, `--sidebar-primary`, `--sidebar-primary-foreground`, `--sidebar-accent`, `--sidebar-accent-foreground`, `--sidebar-border` and `--sidebar-ring`.
|
|
67
|
+
|
|
68
|
+
`--radius` gives the radii `--radius-sm` to `--radius-4xl`. `theme.css` does not set or map `--destructive-foreground`, `--success`, `--warning` or `--font-heading`. Thus a class such as `text-destructive-foreground` or `bg-success` has no color. An app that needs such a variable sets it, and maps it in its own `@theme inline` block ([Tailwind CSS: theme variables](https://tailwindcss.com/docs/theme)):
|
|
69
|
+
|
|
70
|
+
```css
|
|
71
|
+
:root {
|
|
72
|
+
--success: oklch(0.6 0.15 150);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@theme inline {
|
|
76
|
+
--color-success: var(--success);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
62
80
|
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).
|
|
63
81
|
|
|
64
82
|
## The open state of the sidebar
|
|
@@ -101,17 +119,22 @@ Not fixed: the mobile sidebar has a hidden title and description in English (`Si
|
|
|
101
119
|
|
|
102
120
|
## What the stylesheet adds to stock shadcn/ui
|
|
103
121
|
|
|
104
|
-
The stylesheet has
|
|
122
|
+
The stylesheet has six patches:
|
|
105
123
|
|
|
106
124
|
- **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`.
|
|
107
125
|
- **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`.
|
|
108
126
|
- **The width of the mobile sidebar.** On a small screen, the sidebar is in a `Sheet`. The class `data-[side=left]:w-3/4` of the `Sheet` wins over the class `w-(--sidebar-width)` of the sidebar. Thus the sidebar was 3/4 of the window: 292.5px, not 288px, in a window of 390px. The patch sets `width: var(--sidebar-width)` on `[data-slot="sidebar"][data-mobile="true"][data-side]`.
|
|
109
127
|
- **A keyboard shortcut reads left to right.** In Arabic, the direction of the page shows the shortcut `⌘P` of a menu item as `P⌘`. The rule `unicode-bidi: plaintext` on `[data-slot="dropdown-menu-shortcut"]` takes the direction of the shortcut from its own text. The element stays right to left, so its `ms-auto` still puts it at the far end of the item. `direction: ltr` would turn `ms-auto` into a left margin, and the shortcut would move next to the label. The patch is in `@layer components`.
|
|
128
|
+
- **A tabs list that wraps grows to its rows.** The class `group-data-horizontal/tabs:h-8` of `TabsList` wins over the class `h-auto` of the app: both have the specificity of one class, and Tailwind CSS puts a class with a variant after a plain class. Thus a horizontal list with `flex-wrap` stayed 32px tall and its second row covered the content below it. In Meddit, at a width of 390px, four tabs took two rows of 74px in a list of 32px. The patch sets `height: auto` on `[data-slot="tabs-list"][data-orientation="horizontal"].flex-wrap`. A list with `flex-wrap` on one row also takes the height of its triggers: in Meddit at 1440px, 34px in place of 32px. The patch leaves a list without `flex-wrap` at 32px. Its triggers are `h-[calc(100%-1px)]`, thus 25px, and in a list of auto height the percentage does not resolve, so they would grow to 26px.
|
|
110
129
|
|
|
111
|
-
|
|
130
|
+
- **A select popup sits on its trigger.** With `alignItemWithTrigger`, the default of `SelectContent`, Base UI lines up the text of the selected item with the text of the trigger. The trigger's text starts after a 1px border and `ps-2.5`, 11px; the popup draws its edge with `ring-1`, a shadow, so the item's text started at 10px. Thus the popup sat 1px off the trigger: in Meddit at 1280px, 769–1169 for a trigger at 768–1168, and the label under the popup showed at its edge. The patch sets `padding-inline: 1px` on `[data-slot="select-content"]`, in `@layer components`. The popup then has the trigger's edges in both directions, and a popup opened without `alignItemWithTrigger` lines up its text with the trigger's text too.
|
|
131
|
+
|
|
132
|
+
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.
|
|
112
133
|
|
|
113
134
|
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.
|
|
114
135
|
|
|
136
|
+
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.
|
|
137
|
+
|
|
115
138
|
## Links that look like buttons
|
|
116
139
|
|
|
117
140
|
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.
|
|
@@ -150,6 +173,7 @@ Use `cn` around `buttonVariants`. `Button` merges the classes that conflict thro
|
|
|
150
173
|
</DropdownMenuContent>
|
|
151
174
|
```
|
|
152
175
|
|
|
176
|
+
- **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]:`.
|
|
153
177
|
- **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.
|
|
154
178
|
|
|
155
179
|
## Your own components
|
|
@@ -173,6 +197,30 @@ The package has one entry, `@zukhruf/shadcn`. It exports all components, all hoo
|
|
|
173
197
|
|
|
174
198
|
See [ADR 0002](./docs/adr/0002-one-entry-and-private-imports-between-the-components.md).
|
|
175
199
|
|
|
200
|
+
## API
|
|
201
|
+
|
|
202
|
+
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.
|
|
203
|
+
|
|
204
|
+
The hooks and the hand-written module:
|
|
205
|
+
|
|
206
|
+
```ts
|
|
207
|
+
// src/hooks/use-mobile.ts
|
|
208
|
+
// true when the window is narrower than 768px; it changes when the width crosses 768px.
|
|
209
|
+
export function useIsMobile(): boolean;
|
|
210
|
+
|
|
211
|
+
// src/hooks/use-highlighted-code.ts
|
|
212
|
+
// One node for each line of `value`, highlighted with Shiki for `language`.
|
|
213
|
+
// Until the highlighter of the language loads, each line is plain text.
|
|
214
|
+
export function useHighlightedCode(
|
|
215
|
+
value: string,
|
|
216
|
+
language: string,
|
|
217
|
+
): React.ReactNode[];
|
|
218
|
+
|
|
219
|
+
// src/hand-written/sidebar-cookie.ts
|
|
220
|
+
// The cookie in which SidebarProvider keeps its open state.
|
|
221
|
+
export const SIDEBAR_COOKIE_NAME = 'sidebar_state';
|
|
222
|
+
```
|
|
223
|
+
|
|
176
224
|
## Documentation
|
|
177
225
|
|
|
178
226
|
**Decisions**: the [architecture decision records](./docs/adr) tell why the design is as it is.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/shadcn",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.44",
|
|
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
|
@@ -28,6 +28,32 @@
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/*
|
|
32
|
+
* a horizontal tabs list that the app lets wrap grows to its rows. The list's
|
|
33
|
+
* group-data-horizontal/tabs:h-8 has the app's h-auto specificity (0,1,0), and
|
|
34
|
+
* Tailwind emits a variant after a plain utility, so it wins; (0,3,0) wins
|
|
35
|
+
* without relying on source order. A list without flex-wrap keeps its 32px,
|
|
36
|
+
* which the triggers' h-[calc(100%-1px)] resolves against.
|
|
37
|
+
*/
|
|
38
|
+
@layer utilities {
|
|
39
|
+
[data-slot='tabs-list'][data-orientation='horizontal'].flex-wrap {
|
|
40
|
+
height: auto;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* a select popup sits exactly on its trigger. alignItemWithTrigger lines up the
|
|
46
|
+
* selected item's text with the trigger's value text, which starts after a 1px
|
|
47
|
+
* border and ps-2.5; the popup draws its edge with ring-1, a shadow, so its text
|
|
48
|
+
* starts 1px sooner (p-1 + ps-1.5) and Base UI moved the popup 1px off. The 1px
|
|
49
|
+
* stands in for the trigger's border on both sides, in both directions.
|
|
50
|
+
*/
|
|
51
|
+
@layer components {
|
|
52
|
+
[data-slot='select-content'] {
|
|
53
|
+
padding-inline: 1px;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
31
57
|
/*
|
|
32
58
|
* a shortcut such as ⌘P reads left to right also in Arabic; plaintext keeps
|
|
33
59
|
* the element right to left, so its ms-auto still pushes it to the far end
|