@vvedantb/ui 0.60.0 → 0.62.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 +43 -0
- package/dist/src/client.js +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/ui/badge.js +3 -1
- package/dist/src/ui/button.js +31 -3
- package/dist/src/ui/confirm-dialog-parts.js +6 -0
- package/dist/src/ui/field.js +317 -0
- package/dist/src/ui/search-input.js +5 -0
- package/dist/src/ui/spinner.js +2 -1
- package/dist/src/ui/tabs-transition.js +159 -0
- package/dist/src/ui/tabs.js +3 -1
- package/package.json +3 -3
- package/src/client.ts +2 -0
- package/src/index.ts +2 -0
- package/src/ui/__snapshots__/alt-wrappers.test.tsx.snap +1 -1
- package/src/ui/badge.tsx +2 -1
- package/src/ui/button.tsx +41 -8
- package/src/ui/confirm-dialog-parts.tsx +6 -1
- package/src/ui/confirm-dialog.tsx +3 -0
- package/src/ui/field.tsx +148 -0
- package/src/ui/search-input.tsx +3 -1
- package/src/ui/spinner.tsx +4 -3
- package/src/ui/tabs-transition.tsx +103 -0
- package/src/ui/tabs.tsx +5 -1
package/README.md
CHANGED
|
@@ -26,6 +26,31 @@ Removed in 0.4.0-rc.1: the `/cn`, `/sonner`, `/audio`, `/shell`, `/app`, `/compo
|
|
|
26
26
|
@source "../node_modules/@vvedantb/ui/src/**/*.{ts,tsx}";
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
## Component docs and gallery
|
|
30
|
+
|
|
31
|
+
The web gallery in the repository (`apps/ui-gallery`) renders the components below on one page, in light and dark. Run it with `pnpm --filter ui-gallery dev`. It is the web counterpart of `apps/native-gallery`.
|
|
32
|
+
|
|
33
|
+
Each doc has a default usage sample, a variant or props table, a composition example and the `@vvedantb/native-ui` equivalent.
|
|
34
|
+
|
|
35
|
+
| Component | Doc |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `Button` | [docs/components/button.md](docs/components/button.md) |
|
|
38
|
+
| `Input` | [docs/components/input.md](docs/components/input.md) |
|
|
39
|
+
| `SearchInput` | [docs/components/search-input.md](docs/components/search-input.md) |
|
|
40
|
+
| `Field` | [docs/components/field.md](docs/components/field.md) |
|
|
41
|
+
| `Dialog` | [docs/components/dialog.md](docs/components/dialog.md) |
|
|
42
|
+
| `Sheet` | [docs/components/sheet.md](docs/components/sheet.md) |
|
|
43
|
+
| `AlertDialog` | [docs/components/alert-dialog.md](docs/components/alert-dialog.md) |
|
|
44
|
+
| `ConfirmDialog` | [docs/components/confirm-dialog.md](docs/components/confirm-dialog.md) |
|
|
45
|
+
| `Tabs` | [docs/components/tabs.md](docs/components/tabs.md) |
|
|
46
|
+
| `TabsBar` | [docs/components/tabs-bar.md](docs/components/tabs-bar.md) |
|
|
47
|
+
| `Badge` | [docs/components/badge.md](docs/components/badge.md) |
|
|
48
|
+
| `Spinner` | [docs/components/spinner.md](docs/components/spinner.md) |
|
|
49
|
+
| `PageTitle` | [docs/components/page-title.md](docs/components/page-title.md) |
|
|
50
|
+
| `Conversation` | [docs/components/conversation.md](docs/components/conversation.md) |
|
|
51
|
+
| `Message` | [docs/components/message.md](docs/components/message.md) |
|
|
52
|
+
| `PromptInput` | [docs/components/prompt-input.md](docs/components/prompt-input.md) |
|
|
53
|
+
|
|
29
54
|
## Reply chime
|
|
30
55
|
|
|
31
56
|
```tsx
|
|
@@ -292,6 +317,24 @@ import {
|
|
|
292
317
|
```
|
|
293
318
|
|
|
294
319
|
- `Button`: variants `flat`, `success` and `warning` (each is `ghost` plus an override). `loading` disables the button, sets `data-loading="true"` and shows a spinner in place of `startContent`; without `loading` there is no `data-loading` attribute. `endContent` renders after the children. Both are ignored with `asChild` (`loading` still disables).
|
|
320
|
+
- `Button` aliases and recipes: `variant` accepts `primary` (= `default`), `tertiary` (= `ghost`) and `danger` (= `destructive`); `size` accepts `md` (= `default`). Roles: `primary`/`default` is the one main action, `secondary` an alternative, `tertiary`/`ghost` a dismissive action, `destructive`/`danger` a destructive action, `success` and `warning` show status, and `outline`, `link` and `flat` are visual. The omitted-prop defaults stay `"default"`. `buttonVariants`, `badgeVariants` and `tabsBarVariants` are the cva recipes; the types `ButtonVariant`, `ButtonSize` and `ButtonShape` are exported. Use a recipe to style a link like a button. `UiConfigProvider` overrides apply to the `Button` component only, not to raw `buttonVariants()` calls.
|
|
321
|
+
|
|
322
|
+
```tsx
|
|
323
|
+
<a href="/docs" className={buttonVariants({ variant: "default" })}>Read the docs</a>
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
- Sizes: the canonical scale is `sm`, `default` (or `md`) and `lg`. `Spinner` `size="default"` equals `md`. `SearchInput` `size="default"` equals `md` (`h-10`); its omitted default stays `sm`. `ConfirmDialog` sizes are width caps (`sm`/`md`: `sm:max-w-96`), not a scale.
|
|
327
|
+
- `Field`, `FieldLabel`, `FieldControl`, `FieldDescription`, `FieldError`: a labelled control with the wiring done for you. `Field` generates the id (or takes `controlId`); `FieldLabel` sets `htmlFor`; `FieldControl` is an `Input` with that `id`, an `aria-describedby` that lists the description and error ids only while they render, and `aria-invalid` while an error renders. A plain `<Input />` is unchanged.
|
|
328
|
+
|
|
329
|
+
```tsx
|
|
330
|
+
<Field>
|
|
331
|
+
<FieldLabel>Email</FieldLabel>
|
|
332
|
+
<FieldControl type="email" />
|
|
333
|
+
<FieldDescription>We never share it.</FieldDescription>
|
|
334
|
+
{error ? <FieldError>{error}</FieldError> : null}
|
|
335
|
+
</Field>
|
|
336
|
+
```
|
|
337
|
+
|
|
295
338
|
- `DropdownMenuContent`: `fitViewport` caps the height on small screens and scrolls. It reads the optional `--vv-height` CSS variable, which the app may set to the visual viewport height (falls back to `70dvh`). `suppressAltKey` stops a bare Alt press from moving focus. `restoreScrollLockOnClose` calls `restoreModalScrollLock` on close (now and on the next tick). `ContextMenuContent` takes `suppressAltKey` too.
|
|
296
339
|
- `DropdownMenuItem` `endContent` and `ContextMenuItem` `startContent`, `description` and `endContent`: the label moves into a growing column (`min-w-0 flex-1`), the description sits under it and `endContent` sits at the end. `DropdownMenuSubTrigger` and `ContextMenuSubTrigger` take `startContent`.
|
|
297
340
|
- `PopoverContent` `fitViewport`: grows from the trigger (`--radix-popper-transform-origin`) and, on small screens, caps width to `100vw - 1.5rem` and height as above.
|
package/dist/src/client.js
CHANGED
|
@@ -58,6 +58,7 @@ export * from "./ui/alert-dialog.js";
|
|
|
58
58
|
export * from "./ui/confirm-dialog.js";
|
|
59
59
|
export * from "./ui/dropdown-menu.js";
|
|
60
60
|
export * from "./ui/empty-state.js";
|
|
61
|
+
export * from "./ui/field.js";
|
|
61
62
|
export * from "./ui/hover-card.js";
|
|
62
63
|
export * from "./ui/input.js";
|
|
63
64
|
export * from "./ui/label.js";
|
|
@@ -84,6 +85,7 @@ export * from "./ui/surface.js";
|
|
|
84
85
|
export * from "./ui/switch.js";
|
|
85
86
|
export * from "./ui/table.js";
|
|
86
87
|
export * from "./ui/tabs.js";
|
|
88
|
+
export * from "./ui/tabs-transition.js";
|
|
87
89
|
export * from "./ui/textarea.js";
|
|
88
90
|
export * from "./ui/toolbar-search-input.js";
|
|
89
91
|
export * from "./ui/time-picker.js";
|
package/dist/src/index.js
CHANGED
|
@@ -54,6 +54,7 @@ export * from "./ui/alert-dialog.js";
|
|
|
54
54
|
export * from "./ui/confirm-dialog.js";
|
|
55
55
|
export * from "./ui/dropdown-menu.js";
|
|
56
56
|
export * from "./ui/empty-state.js";
|
|
57
|
+
export * from "./ui/field.js";
|
|
57
58
|
export * from "./ui/hover-card.js";
|
|
58
59
|
export * from "./ui/input.js";
|
|
59
60
|
export * from "./ui/label.js";
|
|
@@ -80,6 +81,7 @@ export * from "./ui/surface.js";
|
|
|
80
81
|
export * from "./ui/switch.js";
|
|
81
82
|
export * from "./ui/table.js";
|
|
82
83
|
export * from "./ui/tabs.js";
|
|
84
|
+
export * from "./ui/tabs-transition.js";
|
|
83
85
|
export * from "./ui/textarea.js";
|
|
84
86
|
export * from "./ui/toolbar-search-input.js";
|
|
85
87
|
export * from "./ui/time-picker.js";
|
package/dist/src/ui/badge.js
CHANGED
|
@@ -13,7 +13,9 @@ const badgeVariantClasses = {
|
|
|
13
13
|
success: "border-success/25 bg-success/12 text-success",
|
|
14
14
|
warning: "border-warning/25 bg-warning/12 text-warning"
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
/** The class recipe of `Badge`. Ignores `UiConfig.Badge` overrides. */
|
|
18
|
+
export const badgeVariants = cva(badgeBaseClasses, {
|
|
17
19
|
variants: {
|
|
18
20
|
variant: badgeVariantClasses
|
|
19
21
|
},
|
package/dist/src/ui/button.js
CHANGED
|
@@ -7,12 +7,27 @@ import { useCn, useUiConfig } from "./ui-config.js";
|
|
|
7
7
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
8
|
const ghostClass = "text-muted-foreground hover:bg-surface-tertiary hover:text-foreground";
|
|
9
9
|
const buttonBaseClasses = "inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium tracking-normal transition-[transform,background-color,box-shadow,opacity,border-color] duration-200 ease-smooth focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 active:scale-[0.96] active:duration-[var(--motion-fast,150ms)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0";
|
|
10
|
+
const defaultVariantClass = "bg-primary text-primary-foreground hover:-translate-y-0.5 hover:opacity-90";
|
|
11
|
+
const destructiveVariantClass = "bg-[oklch(47.2%_0.195_25.7)] text-white hover:bg-[oklch(42.5%_0.185_25.7)]";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Variant hierarchy:
|
|
15
|
+
* - `primary` (alias of `default`): the one main action.
|
|
16
|
+
* - `secondary`: an alternative action.
|
|
17
|
+
* - `tertiary` (alias of `ghost`): a dismissive action.
|
|
18
|
+
* - `destructive` (alias `danger`): a destructive action.
|
|
19
|
+
* - `success`, `warning`: status.
|
|
20
|
+
* - `outline`, `link`, `flat`: visual treatments with no fixed role.
|
|
21
|
+
*/
|
|
10
22
|
const buttonVariantClasses = {
|
|
11
|
-
default:
|
|
12
|
-
|
|
23
|
+
default: defaultVariantClass,
|
|
24
|
+
primary: defaultVariantClass,
|
|
25
|
+
destructive: destructiveVariantClass,
|
|
26
|
+
danger: destructiveVariantClass,
|
|
13
27
|
outline: "border border-border bg-transparent text-foreground hover:bg-default",
|
|
14
28
|
secondary: "bg-default text-default-foreground hover:bg-default/78",
|
|
15
29
|
ghost: ghostClass,
|
|
30
|
+
tertiary: ghostClass,
|
|
16
31
|
link: "text-primary underline-offset-4 hover:underline active:scale-100",
|
|
17
32
|
// Ghost plus an override; tailwind-merge drops the clashing ghost classes.
|
|
18
33
|
flat: `${ghostClass} bg-transparent text-muted hover:bg-surface-tertiary hover:text-foreground`,
|
|
@@ -24,6 +39,8 @@ const buttonVariantClasses = {
|
|
|
24
39
|
// No radius here: `shape` sets it.
|
|
25
40
|
const buttonSizeClasses = {
|
|
26
41
|
default: "h-10 px-4 py-2",
|
|
42
|
+
// Alias of `default`, for the canonical sm / md / lg scale.
|
|
43
|
+
md: "h-10 px-4 py-2",
|
|
27
44
|
xs: "h-7 px-2 text-xs hit-target [&_svg:not([class*='size-'])]:size-3.5",
|
|
28
45
|
sm: "h-8 px-3 text-xs max-sm:hit-target",
|
|
29
46
|
lg: "h-11 px-6",
|
|
@@ -38,10 +55,21 @@ const buttonShapeClasses = {
|
|
|
38
55
|
pill: "rounded-full",
|
|
39
56
|
rounded: "rounded-lg"
|
|
40
57
|
};
|
|
58
|
+
|
|
59
|
+
/** `primary`, `tertiary` and `danger` alias `default`, `ghost` and `destructive`. */
|
|
60
|
+
|
|
61
|
+
/** `md` aliases `default` (`h-10`). */
|
|
62
|
+
|
|
41
63
|
// `rounded` keeps the smaller radius the two 28px sizes had.
|
|
42
64
|
const roundedSmallSizes = ["xs", "icon-xs"];
|
|
43
65
|
const roundedSmallClass = "rounded-md";
|
|
44
|
-
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The class recipe of `Button`, for links and other elements that should look
|
|
69
|
+
* like one: `<a className={buttonVariants({ variant: "default" })}>`. It
|
|
70
|
+
* ignores `UiConfig.Button` overrides; only the `Button` component applies those.
|
|
71
|
+
*/
|
|
72
|
+
export const buttonVariants = cva(buttonBaseClasses, {
|
|
45
73
|
variants: {
|
|
46
74
|
variant: buttonVariantClasses,
|
|
47
75
|
size: buttonSizeClasses,
|
|
@@ -9,6 +9,12 @@ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, D
|
|
|
9
9
|
import { Input } from "./input.js";
|
|
10
10
|
import { useUiConfig } from "./ui-config.js";
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Width caps, not a size scale. `"default"` keeps the dialog's own width;
|
|
14
|
+
* `"sm"` and `"md"` cap the content at `sm:max-w-96` from the `sm` breakpoint.
|
|
15
|
+
* They also change the padding and type of the parts (see each part).
|
|
16
|
+
*/
|
|
17
|
+
|
|
12
18
|
/**
|
|
13
19
|
* App-wide classes for the confirm dialog parts, merged after each part's
|
|
14
20
|
* size classes (so an app can tighten `md`'s padding or widen its content).
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Input } from "./input.js";
|
|
4
|
+
import { Label } from "./label.js";
|
|
5
|
+
import { useCn } from "./ui-config.js";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const FieldContext = /*#__PURE__*/React.createContext(null);
|
|
8
|
+
function useField(part) {
|
|
9
|
+
const value = React.useContext(FieldContext);
|
|
10
|
+
if (!value) {
|
|
11
|
+
throw new Error(`${part} must be used inside <Field>.`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Stack for one labelled control. It generates the control `id` and the ids of
|
|
17
|
+
* the description and error, so `FieldLabel` (`htmlFor`) and `FieldControl`
|
|
18
|
+
* (`id`, `aria-describedby`) link up without any manual wiring.
|
|
19
|
+
*
|
|
20
|
+
* A plain `<Input />` does not need it. Use it when a field has a label, a
|
|
21
|
+
* hint or an error message.
|
|
22
|
+
*/
|
|
23
|
+
const Field = /*#__PURE__*/React.forwardRef((t0, ref) => {
|
|
24
|
+
const $ = _c(20);
|
|
25
|
+
let className;
|
|
26
|
+
let controlId;
|
|
27
|
+
let props;
|
|
28
|
+
if ($[0] !== t0) {
|
|
29
|
+
({
|
|
30
|
+
className,
|
|
31
|
+
controlId,
|
|
32
|
+
...props
|
|
33
|
+
} = t0);
|
|
34
|
+
$[0] = t0;
|
|
35
|
+
$[1] = className;
|
|
36
|
+
$[2] = controlId;
|
|
37
|
+
$[3] = props;
|
|
38
|
+
} else {
|
|
39
|
+
className = $[1];
|
|
40
|
+
controlId = $[2];
|
|
41
|
+
props = $[3];
|
|
42
|
+
}
|
|
43
|
+
const merge = useCn();
|
|
44
|
+
const generated = React.useId();
|
|
45
|
+
const [hasDescription, setHasDescription] = React.useState(false);
|
|
46
|
+
const [hasError, setHasError] = React.useState(false);
|
|
47
|
+
const id = controlId ?? generated;
|
|
48
|
+
const t1 = `${id}-description`;
|
|
49
|
+
const t2 = `${id}-error`;
|
|
50
|
+
let t3;
|
|
51
|
+
if ($[4] !== hasDescription || $[5] !== hasError || $[6] !== id || $[7] !== t1 || $[8] !== t2) {
|
|
52
|
+
t3 = {
|
|
53
|
+
controlId: id,
|
|
54
|
+
descriptionId: t1,
|
|
55
|
+
errorId: t2,
|
|
56
|
+
hasDescription,
|
|
57
|
+
hasError,
|
|
58
|
+
setHasDescription,
|
|
59
|
+
setHasError
|
|
60
|
+
};
|
|
61
|
+
$[4] = hasDescription;
|
|
62
|
+
$[5] = hasError;
|
|
63
|
+
$[6] = id;
|
|
64
|
+
$[7] = t1;
|
|
65
|
+
$[8] = t2;
|
|
66
|
+
$[9] = t3;
|
|
67
|
+
} else {
|
|
68
|
+
t3 = $[9];
|
|
69
|
+
}
|
|
70
|
+
const context = t3;
|
|
71
|
+
let t4;
|
|
72
|
+
if ($[10] !== className || $[11] !== merge) {
|
|
73
|
+
t4 = merge("grid gap-2", className);
|
|
74
|
+
$[10] = className;
|
|
75
|
+
$[11] = merge;
|
|
76
|
+
$[12] = t4;
|
|
77
|
+
} else {
|
|
78
|
+
t4 = $[12];
|
|
79
|
+
}
|
|
80
|
+
let t5;
|
|
81
|
+
if ($[13] !== props || $[14] !== ref || $[15] !== t4) {
|
|
82
|
+
t5 = /*#__PURE__*/_jsx("div", {
|
|
83
|
+
ref: ref,
|
|
84
|
+
className: t4,
|
|
85
|
+
...props
|
|
86
|
+
});
|
|
87
|
+
$[13] = props;
|
|
88
|
+
$[14] = ref;
|
|
89
|
+
$[15] = t4;
|
|
90
|
+
$[16] = t5;
|
|
91
|
+
} else {
|
|
92
|
+
t5 = $[16];
|
|
93
|
+
}
|
|
94
|
+
let t6;
|
|
95
|
+
if ($[17] !== context || $[18] !== t5) {
|
|
96
|
+
t6 = /*#__PURE__*/_jsx(FieldContext.Provider, {
|
|
97
|
+
value: context,
|
|
98
|
+
children: t5
|
|
99
|
+
});
|
|
100
|
+
$[17] = context;
|
|
101
|
+
$[18] = t5;
|
|
102
|
+
$[19] = t6;
|
|
103
|
+
} else {
|
|
104
|
+
t6 = $[19];
|
|
105
|
+
}
|
|
106
|
+
return t6;
|
|
107
|
+
});
|
|
108
|
+
Field.displayName = "Field";
|
|
109
|
+
|
|
110
|
+
/** `Label` with `htmlFor` set to the control id of the nearest `Field`. */
|
|
111
|
+
const FieldLabel = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
112
|
+
const $ = _c(4);
|
|
113
|
+
const {
|
|
114
|
+
controlId
|
|
115
|
+
} = useField("FieldLabel");
|
|
116
|
+
let t0;
|
|
117
|
+
if ($[0] !== controlId || $[1] !== props || $[2] !== ref) {
|
|
118
|
+
t0 = /*#__PURE__*/_jsx(Label, {
|
|
119
|
+
ref: ref,
|
|
120
|
+
htmlFor: controlId,
|
|
121
|
+
...props
|
|
122
|
+
});
|
|
123
|
+
$[0] = controlId;
|
|
124
|
+
$[1] = props;
|
|
125
|
+
$[2] = ref;
|
|
126
|
+
$[3] = t0;
|
|
127
|
+
} else {
|
|
128
|
+
t0 = $[3];
|
|
129
|
+
}
|
|
130
|
+
return t0;
|
|
131
|
+
});
|
|
132
|
+
FieldLabel.displayName = "FieldLabel";
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* `Input` with the `id` of the nearest `Field`. `aria-describedby` lists the
|
|
136
|
+
* description and error ids that are rendered, and nothing when there are none.
|
|
137
|
+
* `aria-invalid` is set while a `FieldError` is rendered. Both merge with props
|
|
138
|
+
* you pass.
|
|
139
|
+
*/
|
|
140
|
+
const FieldControl = /*#__PURE__*/React.forwardRef((t0, ref) => {
|
|
141
|
+
const $ = _c(14);
|
|
142
|
+
let describedBy;
|
|
143
|
+
let invalid;
|
|
144
|
+
let props;
|
|
145
|
+
if ($[0] !== t0) {
|
|
146
|
+
({
|
|
147
|
+
"aria-describedby": describedBy,
|
|
148
|
+
"aria-invalid": invalid,
|
|
149
|
+
...props
|
|
150
|
+
} = t0);
|
|
151
|
+
$[0] = t0;
|
|
152
|
+
$[1] = describedBy;
|
|
153
|
+
$[2] = invalid;
|
|
154
|
+
$[3] = props;
|
|
155
|
+
} else {
|
|
156
|
+
describedBy = $[1];
|
|
157
|
+
invalid = $[2];
|
|
158
|
+
props = $[3];
|
|
159
|
+
}
|
|
160
|
+
const field = useField("FieldControl");
|
|
161
|
+
const t1 = field.hasDescription ? field.descriptionId : undefined;
|
|
162
|
+
const t2 = field.hasError ? field.errorId : undefined;
|
|
163
|
+
let t3;
|
|
164
|
+
if ($[4] !== describedBy || $[5] !== t1 || $[6] !== t2) {
|
|
165
|
+
t3 = [describedBy, t1, t2].filter(Boolean);
|
|
166
|
+
$[4] = describedBy;
|
|
167
|
+
$[5] = t1;
|
|
168
|
+
$[6] = t2;
|
|
169
|
+
$[7] = t3;
|
|
170
|
+
} else {
|
|
171
|
+
t3 = $[7];
|
|
172
|
+
}
|
|
173
|
+
const ids = t3.join(" ");
|
|
174
|
+
const t4 = ids || undefined;
|
|
175
|
+
const t5 = invalid ?? (field.hasError ? true : undefined);
|
|
176
|
+
let t6;
|
|
177
|
+
if ($[8] !== field.controlId || $[9] !== props || $[10] !== ref || $[11] !== t4 || $[12] !== t5) {
|
|
178
|
+
t6 = /*#__PURE__*/_jsx(Input, {
|
|
179
|
+
...props,
|
|
180
|
+
ref: ref,
|
|
181
|
+
id: field.controlId,
|
|
182
|
+
"aria-describedby": t4,
|
|
183
|
+
"aria-invalid": t5
|
|
184
|
+
});
|
|
185
|
+
$[8] = field.controlId;
|
|
186
|
+
$[9] = props;
|
|
187
|
+
$[10] = ref;
|
|
188
|
+
$[11] = t4;
|
|
189
|
+
$[12] = t5;
|
|
190
|
+
$[13] = t6;
|
|
191
|
+
} else {
|
|
192
|
+
t6 = $[13];
|
|
193
|
+
}
|
|
194
|
+
return t6;
|
|
195
|
+
});
|
|
196
|
+
FieldControl.displayName = "FieldControl";
|
|
197
|
+
function useRegister(set) {
|
|
198
|
+
const $ = _c(3);
|
|
199
|
+
let t0;
|
|
200
|
+
let t1;
|
|
201
|
+
if ($[0] !== set) {
|
|
202
|
+
t0 = () => {
|
|
203
|
+
set(true);
|
|
204
|
+
return () => set(false);
|
|
205
|
+
};
|
|
206
|
+
t1 = [set];
|
|
207
|
+
$[0] = set;
|
|
208
|
+
$[1] = t0;
|
|
209
|
+
$[2] = t1;
|
|
210
|
+
} else {
|
|
211
|
+
t0 = $[1];
|
|
212
|
+
t1 = $[2];
|
|
213
|
+
}
|
|
214
|
+
React.useLayoutEffect(t0, t1);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Muted hint under the control. Its id joins the control's `aria-describedby`. */
|
|
218
|
+
const FieldDescription = /*#__PURE__*/React.forwardRef((t0, ref) => {
|
|
219
|
+
const $ = _c(11);
|
|
220
|
+
let className;
|
|
221
|
+
let props;
|
|
222
|
+
if ($[0] !== t0) {
|
|
223
|
+
({
|
|
224
|
+
className,
|
|
225
|
+
...props
|
|
226
|
+
} = t0);
|
|
227
|
+
$[0] = t0;
|
|
228
|
+
$[1] = className;
|
|
229
|
+
$[2] = props;
|
|
230
|
+
} else {
|
|
231
|
+
className = $[1];
|
|
232
|
+
props = $[2];
|
|
233
|
+
}
|
|
234
|
+
const field = useField("FieldDescription");
|
|
235
|
+
const merge = useCn();
|
|
236
|
+
useRegister(field.setHasDescription);
|
|
237
|
+
const t1 = field.descriptionId;
|
|
238
|
+
let t2;
|
|
239
|
+
if ($[3] !== className || $[4] !== merge) {
|
|
240
|
+
t2 = merge("text-sm text-muted-foreground", className);
|
|
241
|
+
$[3] = className;
|
|
242
|
+
$[4] = merge;
|
|
243
|
+
$[5] = t2;
|
|
244
|
+
} else {
|
|
245
|
+
t2 = $[5];
|
|
246
|
+
}
|
|
247
|
+
let t3;
|
|
248
|
+
if ($[6] !== field.descriptionId || $[7] !== props || $[8] !== ref || $[9] !== t2) {
|
|
249
|
+
t3 = /*#__PURE__*/_jsx("p", {
|
|
250
|
+
ref: ref,
|
|
251
|
+
id: t1,
|
|
252
|
+
className: t2,
|
|
253
|
+
...props
|
|
254
|
+
});
|
|
255
|
+
$[6] = field.descriptionId;
|
|
256
|
+
$[7] = props;
|
|
257
|
+
$[8] = ref;
|
|
258
|
+
$[9] = t2;
|
|
259
|
+
$[10] = t3;
|
|
260
|
+
} else {
|
|
261
|
+
t3 = $[10];
|
|
262
|
+
}
|
|
263
|
+
return t3;
|
|
264
|
+
});
|
|
265
|
+
FieldDescription.displayName = "FieldDescription";
|
|
266
|
+
|
|
267
|
+
/** Error message under the control. Its id joins the control's `aria-describedby`, and the control becomes `aria-invalid`. */
|
|
268
|
+
const FieldError = /*#__PURE__*/React.forwardRef((t0, ref) => {
|
|
269
|
+
const $ = _c(11);
|
|
270
|
+
let className;
|
|
271
|
+
let props;
|
|
272
|
+
if ($[0] !== t0) {
|
|
273
|
+
({
|
|
274
|
+
className,
|
|
275
|
+
...props
|
|
276
|
+
} = t0);
|
|
277
|
+
$[0] = t0;
|
|
278
|
+
$[1] = className;
|
|
279
|
+
$[2] = props;
|
|
280
|
+
} else {
|
|
281
|
+
className = $[1];
|
|
282
|
+
props = $[2];
|
|
283
|
+
}
|
|
284
|
+
const field = useField("FieldError");
|
|
285
|
+
const merge = useCn();
|
|
286
|
+
useRegister(field.setHasError);
|
|
287
|
+
const t1 = field.errorId;
|
|
288
|
+
let t2;
|
|
289
|
+
if ($[3] !== className || $[4] !== merge) {
|
|
290
|
+
t2 = merge("text-sm text-danger", className);
|
|
291
|
+
$[3] = className;
|
|
292
|
+
$[4] = merge;
|
|
293
|
+
$[5] = t2;
|
|
294
|
+
} else {
|
|
295
|
+
t2 = $[5];
|
|
296
|
+
}
|
|
297
|
+
let t3;
|
|
298
|
+
if ($[6] !== field.errorId || $[7] !== props || $[8] !== ref || $[9] !== t2) {
|
|
299
|
+
t3 = /*#__PURE__*/_jsx("p", {
|
|
300
|
+
ref: ref,
|
|
301
|
+
id: t1,
|
|
302
|
+
role: "alert",
|
|
303
|
+
className: t2,
|
|
304
|
+
...props
|
|
305
|
+
});
|
|
306
|
+
$[6] = field.errorId;
|
|
307
|
+
$[7] = props;
|
|
308
|
+
$[8] = ref;
|
|
309
|
+
$[9] = t2;
|
|
310
|
+
$[10] = t3;
|
|
311
|
+
} else {
|
|
312
|
+
t3 = $[10];
|
|
313
|
+
}
|
|
314
|
+
return t3;
|
|
315
|
+
});
|
|
316
|
+
FieldError.displayName = "FieldError";
|
|
317
|
+
export { Field, FieldControl, FieldDescription, FieldError, FieldLabel };
|
package/dist/src/ui/spinner.js
CHANGED
|
@@ -6,6 +6,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
const sizeClasses = {
|
|
7
7
|
sm: "size-4",
|
|
8
8
|
md: "size-6",
|
|
9
|
+
default: "size-6",
|
|
9
10
|
lg: "size-8"
|
|
10
11
|
};
|
|
11
12
|
|
|
@@ -396,7 +397,7 @@ function RingSpinner(t0) {
|
|
|
396
397
|
t3 = /*#__PURE__*/_jsx("path", {
|
|
397
398
|
className: "opacity-75",
|
|
398
399
|
fill: "currentColor",
|
|
399
|
-
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014
|
|
400
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
400
401
|
});
|
|
401
402
|
$[6] = t2;
|
|
402
403
|
$[7] = t3;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { c as _c } from "react/compiler-runtime";
|
|
4
|
+
import { AnimatePresence, m } from "motion/react";
|
|
5
|
+
import { useState } from "react";
|
|
6
|
+
import { motionEase } from "../motion/presets.js";
|
|
7
|
+
import { cn } from "../utils/cn.js";
|
|
8
|
+
import { useUiConfig } from "./ui-config.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* How tab content moves when the tab changes. The new panel comes from the
|
|
12
|
+
* side of the tab that was picked (right of the old one: from the right), as a
|
|
13
|
+
* phone swipe does.
|
|
14
|
+
* - `"none"` (default): swap at once.
|
|
15
|
+
* - `"slide"`: a short 32px slide with a fade. Reads the direction without
|
|
16
|
+
* moving the page; the desktop default for apps that opt in.
|
|
17
|
+
* - `"push"`: the old panel leaves the full width as the new one enters, like
|
|
18
|
+
* a phone pager. Heavier; suits narrow or swipe-driven surfaces.
|
|
19
|
+
*/
|
|
20
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
|
+
const SLIDE_PX = 32;
|
|
22
|
+
const variants = {
|
|
23
|
+
slide: {
|
|
24
|
+
enter: dir => ({
|
|
25
|
+
x: dir * SLIDE_PX,
|
|
26
|
+
opacity: 0
|
|
27
|
+
}),
|
|
28
|
+
center: {
|
|
29
|
+
x: 0,
|
|
30
|
+
opacity: 1,
|
|
31
|
+
transition: {
|
|
32
|
+
duration: 0.24,
|
|
33
|
+
ease: motionEase
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
// Leaves faster than it enters, so the old panel never lingers.
|
|
37
|
+
exit: dir => ({
|
|
38
|
+
x: -dir * SLIDE_PX,
|
|
39
|
+
opacity: 0,
|
|
40
|
+
transition: {
|
|
41
|
+
duration: 0.14,
|
|
42
|
+
ease: motionEase
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
},
|
|
46
|
+
push: {
|
|
47
|
+
enter: dir => ({
|
|
48
|
+
x: `${dir * 100}%`
|
|
49
|
+
}),
|
|
50
|
+
center: {
|
|
51
|
+
x: "0%",
|
|
52
|
+
transition: {
|
|
53
|
+
duration: 0.32,
|
|
54
|
+
ease: motionEase
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
exit: dir => ({
|
|
58
|
+
x: `${-dir * 100}%`,
|
|
59
|
+
transition: {
|
|
60
|
+
duration: 0.32,
|
|
61
|
+
ease: motionEase
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Wraps the content of a tab set and moves it when the tab changes. Works with
|
|
68
|
+
* any tab content, routed or not: it keys on `value`, so the outgoing panel can
|
|
69
|
+
* leave while the new one enters. The container clips the slide sideways only,
|
|
70
|
+
* so content keeps its natural height. Motion settings apply: `MotionProvider
|
|
71
|
+
* reducedMotion` and page-motion off stop the slide.
|
|
72
|
+
*/
|
|
73
|
+
export function TabsTransition(t0) {
|
|
74
|
+
const $ = _c(16);
|
|
75
|
+
const {
|
|
76
|
+
value,
|
|
77
|
+
order,
|
|
78
|
+
variant: variantProp,
|
|
79
|
+
className,
|
|
80
|
+
children
|
|
81
|
+
} = t0;
|
|
82
|
+
const configVariant = useUiConfig("Tabs")?.transition;
|
|
83
|
+
const variant = variantProp ?? configVariant ?? "none";
|
|
84
|
+
const [previous, setPrevious] = useState(value);
|
|
85
|
+
const [direction, setDirection] = useState(1);
|
|
86
|
+
if (value !== previous) {
|
|
87
|
+
setDirection(order.indexOf(value) >= order.indexOf(previous) ? 1 : -1);
|
|
88
|
+
setPrevious(value);
|
|
89
|
+
}
|
|
90
|
+
if (variant === "none") {
|
|
91
|
+
let t1;
|
|
92
|
+
if ($[0] !== children || $[1] !== className) {
|
|
93
|
+
t1 = /*#__PURE__*/_jsx("div", {
|
|
94
|
+
className: className,
|
|
95
|
+
children: children
|
|
96
|
+
});
|
|
97
|
+
$[0] = children;
|
|
98
|
+
$[1] = className;
|
|
99
|
+
$[2] = t1;
|
|
100
|
+
} else {
|
|
101
|
+
t1 = $[2];
|
|
102
|
+
}
|
|
103
|
+
return t1;
|
|
104
|
+
}
|
|
105
|
+
let t1;
|
|
106
|
+
if ($[3] !== className) {
|
|
107
|
+
t1 = cn("relative overflow-x-clip", className);
|
|
108
|
+
$[3] = className;
|
|
109
|
+
$[4] = t1;
|
|
110
|
+
} else {
|
|
111
|
+
t1 = $[4];
|
|
112
|
+
}
|
|
113
|
+
const t2 = variants[variant];
|
|
114
|
+
let t3;
|
|
115
|
+
if ($[5] !== children || $[6] !== direction || $[7] !== t2 || $[8] !== value) {
|
|
116
|
+
t3 = /*#__PURE__*/_jsx(m.div, {
|
|
117
|
+
custom: direction,
|
|
118
|
+
variants: t2,
|
|
119
|
+
initial: "enter",
|
|
120
|
+
animate: "center",
|
|
121
|
+
exit: "exit",
|
|
122
|
+
children: children
|
|
123
|
+
}, value);
|
|
124
|
+
$[5] = children;
|
|
125
|
+
$[6] = direction;
|
|
126
|
+
$[7] = t2;
|
|
127
|
+
$[8] = value;
|
|
128
|
+
$[9] = t3;
|
|
129
|
+
} else {
|
|
130
|
+
t3 = $[9];
|
|
131
|
+
}
|
|
132
|
+
let t4;
|
|
133
|
+
if ($[10] !== direction || $[11] !== t3) {
|
|
134
|
+
t4 = /*#__PURE__*/_jsx(AnimatePresence, {
|
|
135
|
+
initial: false,
|
|
136
|
+
custom: direction,
|
|
137
|
+
mode: "popLayout",
|
|
138
|
+
children: t3
|
|
139
|
+
});
|
|
140
|
+
$[10] = direction;
|
|
141
|
+
$[11] = t3;
|
|
142
|
+
$[12] = t4;
|
|
143
|
+
} else {
|
|
144
|
+
t4 = $[12];
|
|
145
|
+
}
|
|
146
|
+
let t5;
|
|
147
|
+
if ($[13] !== t1 || $[14] !== t4) {
|
|
148
|
+
t5 = /*#__PURE__*/_jsx("div", {
|
|
149
|
+
className: t1,
|
|
150
|
+
children: t4
|
|
151
|
+
});
|
|
152
|
+
$[13] = t1;
|
|
153
|
+
$[14] = t4;
|
|
154
|
+
$[15] = t5;
|
|
155
|
+
} else {
|
|
156
|
+
t5 = $[15];
|
|
157
|
+
}
|
|
158
|
+
return t5;
|
|
159
|
+
}
|
package/dist/src/ui/tabs.js
CHANGED
|
@@ -298,7 +298,9 @@ const TabsContent = /*#__PURE__*/React.forwardRef((t0, ref) => {
|
|
|
298
298
|
return t3;
|
|
299
299
|
});
|
|
300
300
|
TabsContent.displayName = TabsPrimitive.Content.displayName;
|
|
301
|
-
|
|
301
|
+
|
|
302
|
+
/** The class recipe of `TabsBar`. Ignores `UiConfig.Tabs` overrides. */
|
|
303
|
+
export const tabsBarVariants = cva("flex shrink-0 flex-wrap items-center gap-2 border-b border-border", {
|
|
302
304
|
variants: {
|
|
303
305
|
size: {
|
|
304
306
|
default: "px-3 py-2",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React 19 UI for web apps: one main JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, artifact viewers over the @vvedantb/server artifacts core, native tokens), third-party brand logos (also @vvedantb/ui/logos), motion-driven animated SVG icons (@vvedantb/ui/icons/animated), a client entry without @vvedantb/server, convex or Clerk for Chrome extensions, design-token CSS, shared Tailwind v4 CSS, a Tailwind preset and packaged Instrument Sans fonts.",
|
|
6
6
|
"type": "module",
|
|
@@ -208,7 +208,7 @@
|
|
|
208
208
|
"streamdown": "^2.7.1",
|
|
209
209
|
"tailwind-merge": "^2.6.0",
|
|
210
210
|
"tailwindcss": "4.3.3",
|
|
211
|
-
"typescript": "
|
|
211
|
+
"typescript": "7.0.2",
|
|
212
212
|
"use-stick-to-bottom": "^1.1.0",
|
|
213
213
|
"vaul": "^1.1.0",
|
|
214
214
|
"vitest": "^3.2.0",
|
|
@@ -245,7 +245,7 @@
|
|
|
245
245
|
"scripts": {
|
|
246
246
|
"check:client-graph": "node scripts/check-client-graph.mjs",
|
|
247
247
|
"check:tokens": "node tokens/scripts/check-component-tokens.mjs",
|
|
248
|
-
"build": "node scripts/build-dist.mjs && node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs &&
|
|
248
|
+
"build": "node scripts/build-dist.mjs && node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsrs -p tsconfig.json",
|
|
249
249
|
"typecheck": "tsrs --noEmit --fast -p tsconfig.json && tsrs --noEmit --fast -p tsconfig.consumer.json && tsrs --noEmit --fast -p tsconfig.consumer-speech.json && tsrs --noEmit --fast -p tokens/tsconfig.json",
|
|
250
250
|
"test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
|
|
251
251
|
"verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
|
package/src/client.ts
CHANGED
|
@@ -82,6 +82,7 @@ export * from "./ui/alert-dialog";
|
|
|
82
82
|
export * from "./ui/confirm-dialog";
|
|
83
83
|
export * from "./ui/dropdown-menu";
|
|
84
84
|
export * from "./ui/empty-state";
|
|
85
|
+
export * from "./ui/field";
|
|
85
86
|
export * from "./ui/hover-card";
|
|
86
87
|
export * from "./ui/input";
|
|
87
88
|
export * from "./ui/label";
|
|
@@ -119,6 +120,7 @@ export * from "./ui/surface";
|
|
|
119
120
|
export * from "./ui/switch";
|
|
120
121
|
export * from "./ui/table";
|
|
121
122
|
export * from "./ui/tabs";
|
|
123
|
+
export * from "./ui/tabs-transition";
|
|
122
124
|
export * from "./ui/textarea";
|
|
123
125
|
export * from "./ui/toolbar-search-input";
|
|
124
126
|
export * from "./ui/time-picker";
|
package/src/index.ts
CHANGED
|
@@ -78,6 +78,7 @@ export * from "./ui/alert-dialog";
|
|
|
78
78
|
export * from "./ui/confirm-dialog";
|
|
79
79
|
export * from "./ui/dropdown-menu";
|
|
80
80
|
export * from "./ui/empty-state";
|
|
81
|
+
export * from "./ui/field";
|
|
81
82
|
export * from "./ui/hover-card";
|
|
82
83
|
export * from "./ui/input";
|
|
83
84
|
export * from "./ui/label";
|
|
@@ -115,6 +116,7 @@ export * from "./ui/surface";
|
|
|
115
116
|
export * from "./ui/switch";
|
|
116
117
|
export * from "./ui/table";
|
|
117
118
|
export * from "./ui/tabs";
|
|
119
|
+
export * from "./ui/tabs-transition";
|
|
118
120
|
export * from "./ui/textarea";
|
|
119
121
|
export * from "./ui/toolbar-search-input";
|
|
120
122
|
export * from "./ui/time-picker";
|
|
@@ -16,4 +16,4 @@ exports[`InputGroupAlt markup > input className and props 1`] = `"<div data-inpu
|
|
|
16
16
|
|
|
17
17
|
exports[`InputGroupAlt markup > input with every addon align and button size 1`] = `"<div data-input-group="" class="flex h-10 flex-wrap rounded-field border border-border bg-field-background text-sm transition-[border-color,box-shadow] duration-200 ease-smooth has-[textarea]:h-auto has-data-[slot=input-group-control]:h-auto has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-focus-visible:outline-hidden has-focus-visible:border-focus-border has-focus-visible:ring-1 has-focus-visible:ring-focus-ring"><div class="flex items-center flex-row ps-3"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="tabler-icon tabler-icon-search"><path d="M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"></path><path d="M21 21l-6 -6"></path></svg></div><div data-align="inline-start" class="flex items-center flex-row ps-3"><span class="flex items-center text-sm text-muted-foreground/95">https://</span></div><input class="flex w-full max-sm:min-w-0 border-border text-base sm:pointer-fine:text-sm transition-[border-color,box-shadow,background-color] duration-200 ease-smooth file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-field-placeholder disabled:cursor-not-allowed disabled:opacity-50 focus-visible:outline-hidden focus-visible:border-focus-border focus-visible:ring-focus-ring h-full flex-1 rounded-none border-0 bg-transparent px-3 py-2 shadow-none focus-visible:border-0 focus-visible:ring-0" placeholder="Search"><div data-align="inline-end" class="flex items-center flex-row pe-3"><button class="inline-flex items-center justify-center gap-2 whitespace-nowrap font-medium tracking-normal transition-[transform,background-color,box-shadow,opacity,border-color] duration-200 ease-smooth focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 active:scale-[0.96] active:duration-[var(--motion-fast,150ms)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 text-muted-foreground hover:bg-surface-tertiary hover:text-foreground py-2 shrink-0 shadow-none h-7 rounded-lg px-2 text-xs">Go</button><button class="inline-flex items-center justify-center gap-2 whitespace-nowrap font-medium tracking-normal transition-[transform,background-color,box-shadow,opacity,border-color] duration-200 ease-smooth focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 active:scale-[0.96] active:duration-[var(--motion-fast,150ms)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 text-muted-foreground hover:bg-surface-tertiary hover:text-foreground py-2 shrink-0 shadow-none h-8 rounded-lg px-2.5 text-xs">Small</button><button class="inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium tracking-normal transition-[transform,background-color,box-shadow,opacity,border-color] duration-200 ease-smooth focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 active:scale-[0.96] active:duration-[var(--motion-fast,150ms)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 text-muted-foreground hover:bg-surface-tertiary hover:text-foreground px-4 py-2 shrink-0 shadow-none h-7 w-7 rounded-lg" aria-label="A"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="tabler-icon tabler-icon-search"><path d="M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"></path><path d="M21 21l-6 -6"></path></svg></button><button class="inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium tracking-normal transition-[transform,background-color,box-shadow,opacity,border-color] duration-200 ease-smooth focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 active:scale-[0.96] active:duration-[var(--motion-fast,150ms)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 bg-primary text-primary-foreground hover:-translate-y-0.5 hover:opacity-90 px-4 py-2 shrink-0 shadow-none h-8 w-8 rounded-lg" type="submit" aria-label="B"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="tabler-icon tabler-icon-search"><path d="M3 10a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"></path><path d="M21 21l-6 -6"></path></svg></button></div></div>"`;
|
|
18
18
|
|
|
19
|
-
exports[`InputGroupAlt markup > textarea with block addons, error and classNames 1`] = `"<div data-input-group="" class="flex h-10 flex-wrap rounded-field border bg-field-background text-sm transition-[border-color,box-shadow] duration-200 ease-smooth has-[textarea]:h-auto has-data-[slot=input-group-control]:h-auto has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-focus-visible:outline-hidden has-focus-visible:ring-1 border-danger-border has-focus-visible:border-danger has-focus-visible:ring-danger-ring root-x" id="g"><div data-align="block-start" class="flex items-center w-full flex-row border-b border-separator px-3 py-2 addon-x"><span class="flex items-center text-sm text-x">Title</span></div><textarea class="flex min-h-20 w-full max-sm:min-w-0 border-border text-base sm:pointer-fine:text-sm placeholder:text-field-placeholder disabled:cursor-not-allowed disabled:opacity-50 focus-visible:outline-hidden focus-visible:border-focus-border focus-visible:ring-focus-ring flex-1 resize-none rounded-none border-0 bg-transparent px-3 py-2.5 shadow-none focus-visible:border-0 focus-visible:ring-0 field-sizing-content ta-x" rows="2">v</textarea><div data-align="block-end" class="flex items-center w-full flex-row px-3 py-2"><button class="inline-flex items-center justify-center gap-2 whitespace-nowrap font-medium tracking-normal transition-[transform,background-color,box-shadow,opacity,border-color] duration-200 ease-smooth focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 active:scale-[0.96] active:duration-[var(--motion-fast,150ms)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 text-muted-foreground hover:bg-surface-tertiary hover:text-foreground py-2 shrink-0 shadow-none h-7 rounded-lg px-2 text-xs btn-x" disabled="" data-loading="true"><svg class="h-4 w-4 animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014
|
|
19
|
+
exports[`InputGroupAlt markup > textarea with block addons, error and classNames 1`] = `"<div data-input-group="" class="flex h-10 flex-wrap rounded-field border bg-field-background text-sm transition-[border-color,box-shadow] duration-200 ease-smooth has-[textarea]:h-auto has-data-[slot=input-group-control]:h-auto has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-focus-visible:outline-hidden has-focus-visible:ring-1 border-danger-border has-focus-visible:border-danger has-focus-visible:ring-danger-ring root-x" id="g"><div data-align="block-start" class="flex items-center w-full flex-row border-b border-separator px-3 py-2 addon-x"><span class="flex items-center text-sm text-x">Title</span></div><textarea class="flex min-h-20 w-full max-sm:min-w-0 border-border text-base sm:pointer-fine:text-sm placeholder:text-field-placeholder disabled:cursor-not-allowed disabled:opacity-50 focus-visible:outline-hidden focus-visible:border-focus-border focus-visible:ring-focus-ring flex-1 resize-none rounded-none border-0 bg-transparent px-3 py-2.5 shadow-none focus-visible:border-0 focus-visible:ring-0 field-sizing-content ta-x" rows="2">v</textarea><div data-align="block-end" class="flex items-center w-full flex-row px-3 py-2"><button class="inline-flex items-center justify-center gap-2 whitespace-nowrap font-medium tracking-normal transition-[transform,background-color,box-shadow,opacity,border-color] duration-200 ease-smooth focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 active:scale-[0.96] active:duration-[var(--motion-fast,150ms)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 text-muted-foreground hover:bg-surface-tertiary hover:text-foreground py-2 shrink-0 shadow-none h-7 rounded-lg px-2 text-xs btn-x" disabled="" data-loading="true"><svg class="h-4 w-4 animate-spin" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>Send</button></div></div>"`;
|
package/src/ui/badge.tsx
CHANGED
|
@@ -15,7 +15,8 @@ const badgeVariantClasses = {
|
|
|
15
15
|
warning: "border-warning/25 bg-warning/12 text-warning",
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/** The class recipe of `Badge`. Ignores `UiConfig.Badge` overrides. */
|
|
19
|
+
export const badgeVariants = cva(badgeBaseClasses, {
|
|
19
20
|
variants: {
|
|
20
21
|
variant: badgeVariantClasses,
|
|
21
22
|
},
|
package/src/ui/button.tsx
CHANGED
|
@@ -10,15 +10,30 @@ const ghostClass =
|
|
|
10
10
|
const buttonBaseClasses =
|
|
11
11
|
"inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium tracking-normal transition-[transform,background-color,box-shadow,opacity,border-color] duration-200 ease-smooth focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50 active:scale-[0.96] active:duration-[var(--motion-fast,150ms)] [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0";
|
|
12
12
|
|
|
13
|
+
const defaultVariantClass =
|
|
14
|
+
"bg-primary text-primary-foreground hover:-translate-y-0.5 hover:opacity-90";
|
|
15
|
+
const destructiveVariantClass =
|
|
16
|
+
"bg-[oklch(47.2%_0.195_25.7)] text-white hover:bg-[oklch(42.5%_0.185_25.7)]";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Variant hierarchy:
|
|
20
|
+
* - `primary` (alias of `default`): the one main action.
|
|
21
|
+
* - `secondary`: an alternative action.
|
|
22
|
+
* - `tertiary` (alias of `ghost`): a dismissive action.
|
|
23
|
+
* - `destructive` (alias `danger`): a destructive action.
|
|
24
|
+
* - `success`, `warning`: status.
|
|
25
|
+
* - `outline`, `link`, `flat`: visual treatments with no fixed role.
|
|
26
|
+
*/
|
|
13
27
|
const buttonVariantClasses = {
|
|
14
|
-
default:
|
|
15
|
-
|
|
16
|
-
destructive:
|
|
17
|
-
|
|
28
|
+
default: defaultVariantClass,
|
|
29
|
+
primary: defaultVariantClass,
|
|
30
|
+
destructive: destructiveVariantClass,
|
|
31
|
+
danger: destructiveVariantClass,
|
|
18
32
|
outline:
|
|
19
33
|
"border border-border bg-transparent text-foreground hover:bg-default",
|
|
20
34
|
secondary: "bg-default text-default-foreground hover:bg-default/78",
|
|
21
35
|
ghost: ghostClass,
|
|
36
|
+
tertiary: ghostClass,
|
|
22
37
|
link: "text-primary underline-offset-4 hover:underline active:scale-100",
|
|
23
38
|
// Ghost plus an override; tailwind-merge drops the clashing ghost classes.
|
|
24
39
|
flat: `${ghostClass} bg-transparent text-muted hover:bg-surface-tertiary hover:text-foreground`, // check-tokens-allow: text-muted
|
|
@@ -29,6 +44,8 @@ const buttonVariantClasses = {
|
|
|
29
44
|
// No radius here: `shape` sets it.
|
|
30
45
|
const buttonSizeClasses = {
|
|
31
46
|
default: "h-10 px-4 py-2",
|
|
47
|
+
// Alias of `default`, for the canonical sm / md / lg scale.
|
|
48
|
+
md: "h-10 px-4 py-2",
|
|
32
49
|
xs: "h-7 px-2 text-xs hit-target [&_svg:not([class*='size-'])]:size-3.5",
|
|
33
50
|
sm: "h-8 px-3 text-xs max-sm:hit-target",
|
|
34
51
|
lg: "h-11 px-6",
|
|
@@ -44,15 +61,22 @@ const buttonShapeClasses = {
|
|
|
44
61
|
rounded: "rounded-lg",
|
|
45
62
|
};
|
|
46
63
|
|
|
47
|
-
|
|
48
|
-
type
|
|
49
|
-
|
|
64
|
+
/** `primary`, `tertiary` and `danger` alias `default`, `ghost` and `destructive`. */
|
|
65
|
+
export type ButtonVariant = keyof typeof buttonVariantClasses;
|
|
66
|
+
/** `md` aliases `default` (`h-10`). */
|
|
67
|
+
export type ButtonSize = keyof typeof buttonSizeClasses;
|
|
68
|
+
export type ButtonShape = keyof typeof buttonShapeClasses;
|
|
50
69
|
|
|
51
70
|
// `rounded` keeps the smaller radius the two 28px sizes had.
|
|
52
71
|
const roundedSmallSizes: ButtonSize[] = ["xs", "icon-xs"];
|
|
53
72
|
const roundedSmallClass = "rounded-md";
|
|
54
73
|
|
|
55
|
-
|
|
74
|
+
/**
|
|
75
|
+
* The class recipe of `Button`, for links and other elements that should look
|
|
76
|
+
* like one: `<a className={buttonVariants({ variant: "default" })}>`. It
|
|
77
|
+
* ignores `UiConfig.Button` overrides; only the `Button` component applies those.
|
|
78
|
+
*/
|
|
79
|
+
export const buttonVariants = cva(buttonBaseClasses, {
|
|
56
80
|
variants: {
|
|
57
81
|
variant: buttonVariantClasses,
|
|
58
82
|
size: buttonSizeClasses,
|
|
@@ -89,6 +113,15 @@ export interface ButtonProps
|
|
|
89
113
|
extends
|
|
90
114
|
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
91
115
|
VariantProps<typeof buttonVariants> {
|
|
116
|
+
/**
|
|
117
|
+
* `primary` (alias of `default`) is the one main action; `secondary` an
|
|
118
|
+
* alternative; `tertiary` (alias of `ghost`) a dismissive one; `destructive`
|
|
119
|
+
* (alias `danger`) a destructive one; `success` and `warning` show status;
|
|
120
|
+
* `outline`, `link` and `flat` are visual. Default `"default"`.
|
|
121
|
+
*/
|
|
122
|
+
variant?: ButtonVariant | null;
|
|
123
|
+
/** `md` is an alias of `default`. Default `"default"`. */
|
|
124
|
+
size?: ButtonSize | null;
|
|
92
125
|
asChild?: boolean;
|
|
93
126
|
/** Rendered before the children. Ignored with `asChild`. */
|
|
94
127
|
startContent?: React.ReactNode;
|
|
@@ -19,6 +19,11 @@ import {
|
|
|
19
19
|
import { Input } from "./input";
|
|
20
20
|
import { useUiConfig } from "./ui-config";
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Width caps, not a size scale. `"default"` keeps the dialog's own width;
|
|
24
|
+
* `"sm"` and `"md"` cap the content at `sm:max-w-96` from the `sm` breakpoint.
|
|
25
|
+
* They also change the padding and type of the parts (see each part).
|
|
26
|
+
*/
|
|
22
27
|
export type ConfirmDialogSize = "default" | "sm" | "md";
|
|
23
28
|
|
|
24
29
|
/**
|
|
@@ -67,7 +72,7 @@ export function useConfirmDialog(): ConfirmDialogContextValue {
|
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
export type ConfirmDialogRootProps = React.ComponentProps<typeof Dialog> & {
|
|
70
|
-
/** Layout slot for the other parts. Default `"default"`. */
|
|
75
|
+
/** Layout slot for the other parts. A width cap (`"sm"` and `"md"`: `sm:max-w-96`), not a size scale. Default `"default"`. */
|
|
71
76
|
size?: ConfirmDialogSize;
|
|
72
77
|
/** Blocking alert dialog: no outside dismiss, no close button, Cancel focused. Default `size === "default"`. */
|
|
73
78
|
alert?: boolean;
|
|
@@ -47,6 +47,9 @@ export type ConfirmDialogProps = Omit<
|
|
|
47
47
|
* button close it). Confirm does not close it; the caller controls `open`.
|
|
48
48
|
* `"md"`: dismissible dialog like `"sm"`, with a header, description and
|
|
49
49
|
* footer in separate sections and default-size buttons.
|
|
50
|
+
*
|
|
51
|
+
* The sizes are width caps: `"sm"` and `"md"` cap the content at
|
|
52
|
+
* `sm:max-w-96`; `"default"` keeps the dialog width.
|
|
50
53
|
*/
|
|
51
54
|
size?: "default" | "sm" | "md";
|
|
52
55
|
};
|
package/src/ui/field.tsx
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Input } from "./input";
|
|
3
|
+
import { Label } from "./label";
|
|
4
|
+
import { useCn } from "./ui-config";
|
|
5
|
+
|
|
6
|
+
interface FieldContextValue {
|
|
7
|
+
controlId: string;
|
|
8
|
+
descriptionId: string;
|
|
9
|
+
errorId: string;
|
|
10
|
+
hasDescription: boolean;
|
|
11
|
+
hasError: boolean;
|
|
12
|
+
setHasDescription: (present: boolean) => void;
|
|
13
|
+
setHasError: (present: boolean) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const FieldContext = React.createContext<FieldContextValue | null>(null);
|
|
17
|
+
|
|
18
|
+
function useField(part: string): FieldContextValue {
|
|
19
|
+
const value = React.useContext(FieldContext);
|
|
20
|
+
if (!value) throw new Error(`${part} must be used inside <Field>.`);
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface FieldProps extends React.ComponentPropsWithoutRef<"div"> {
|
|
25
|
+
/** The `id` of the control, which `FieldLabel` points at with `htmlFor`. Default: a generated id. */
|
|
26
|
+
controlId?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Stack for one labelled control. It generates the control `id` and the ids of
|
|
31
|
+
* the description and error, so `FieldLabel` (`htmlFor`) and `FieldControl`
|
|
32
|
+
* (`id`, `aria-describedby`) link up without any manual wiring.
|
|
33
|
+
*
|
|
34
|
+
* A plain `<Input />` does not need it. Use it when a field has a label, a
|
|
35
|
+
* hint or an error message.
|
|
36
|
+
*/
|
|
37
|
+
const Field = React.forwardRef<HTMLDivElement, FieldProps>(
|
|
38
|
+
({ className, controlId, ...props }, ref) => {
|
|
39
|
+
const merge = useCn();
|
|
40
|
+
const generated = React.useId();
|
|
41
|
+
const [hasDescription, setHasDescription] = React.useState(false);
|
|
42
|
+
const [hasError, setHasError] = React.useState(false);
|
|
43
|
+
const id = controlId ?? generated;
|
|
44
|
+
const context = React.useMemo<FieldContextValue>(
|
|
45
|
+
() => ({
|
|
46
|
+
controlId: id,
|
|
47
|
+
descriptionId: `${id}-description`,
|
|
48
|
+
errorId: `${id}-error`,
|
|
49
|
+
hasDescription,
|
|
50
|
+
hasError,
|
|
51
|
+
setHasDescription,
|
|
52
|
+
setHasError,
|
|
53
|
+
}),
|
|
54
|
+
[id, hasDescription, hasError],
|
|
55
|
+
);
|
|
56
|
+
return (
|
|
57
|
+
<FieldContext.Provider value={context}>
|
|
58
|
+
<div ref={ref} className={merge("grid gap-2", className)} {...props} />
|
|
59
|
+
</FieldContext.Provider>
|
|
60
|
+
);
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
Field.displayName = "Field";
|
|
64
|
+
|
|
65
|
+
/** `Label` with `htmlFor` set to the control id of the nearest `Field`. */
|
|
66
|
+
const FieldLabel = React.forwardRef<
|
|
67
|
+
React.ComponentRef<typeof Label>,
|
|
68
|
+
React.ComponentPropsWithoutRef<typeof Label>
|
|
69
|
+
>((props, ref) => {
|
|
70
|
+
const { controlId } = useField("FieldLabel");
|
|
71
|
+
return <Label ref={ref} htmlFor={controlId} {...props} />;
|
|
72
|
+
});
|
|
73
|
+
FieldLabel.displayName = "FieldLabel";
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* `Input` with the `id` of the nearest `Field`. `aria-describedby` lists the
|
|
77
|
+
* description and error ids that are rendered, and nothing when there are none.
|
|
78
|
+
* `aria-invalid` is set while a `FieldError` is rendered. Both merge with props
|
|
79
|
+
* you pass.
|
|
80
|
+
*/
|
|
81
|
+
const FieldControl = React.forwardRef<HTMLInputElement, React.ComponentProps<"input">>(
|
|
82
|
+
({ "aria-describedby": describedBy, "aria-invalid": invalid, ...props }, ref) => {
|
|
83
|
+
const field = useField("FieldControl");
|
|
84
|
+
const ids = [
|
|
85
|
+
describedBy,
|
|
86
|
+
field.hasDescription ? field.descriptionId : undefined,
|
|
87
|
+
field.hasError ? field.errorId : undefined,
|
|
88
|
+
]
|
|
89
|
+
.filter(Boolean)
|
|
90
|
+
.join(" ");
|
|
91
|
+
return (
|
|
92
|
+
<Input
|
|
93
|
+
{...props}
|
|
94
|
+
ref={ref}
|
|
95
|
+
id={field.controlId}
|
|
96
|
+
aria-describedby={ids || undefined}
|
|
97
|
+
aria-invalid={invalid ?? (field.hasError ? true : undefined)}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
);
|
|
102
|
+
FieldControl.displayName = "FieldControl";
|
|
103
|
+
|
|
104
|
+
function useRegister(set: (present: boolean) => void) {
|
|
105
|
+
React.useLayoutEffect(() => {
|
|
106
|
+
set(true);
|
|
107
|
+
return () => set(false);
|
|
108
|
+
}, [set]);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Muted hint under the control. Its id joins the control's `aria-describedby`. */
|
|
112
|
+
const FieldDescription = React.forwardRef<HTMLParagraphElement, React.ComponentPropsWithoutRef<"p">>(
|
|
113
|
+
({ className, ...props }, ref) => {
|
|
114
|
+
const field = useField("FieldDescription");
|
|
115
|
+
const merge = useCn();
|
|
116
|
+
useRegister(field.setHasDescription);
|
|
117
|
+
return (
|
|
118
|
+
<p
|
|
119
|
+
ref={ref}
|
|
120
|
+
id={field.descriptionId}
|
|
121
|
+
className={merge("text-sm text-muted-foreground", className)}
|
|
122
|
+
{...props}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
FieldDescription.displayName = "FieldDescription";
|
|
128
|
+
|
|
129
|
+
/** Error message under the control. Its id joins the control's `aria-describedby`, and the control becomes `aria-invalid`. */
|
|
130
|
+
const FieldError = React.forwardRef<HTMLParagraphElement, React.ComponentPropsWithoutRef<"p">>(
|
|
131
|
+
({ className, ...props }, ref) => {
|
|
132
|
+
const field = useField("FieldError");
|
|
133
|
+
const merge = useCn();
|
|
134
|
+
useRegister(field.setHasError);
|
|
135
|
+
return (
|
|
136
|
+
<p
|
|
137
|
+
ref={ref}
|
|
138
|
+
id={field.errorId}
|
|
139
|
+
role="alert"
|
|
140
|
+
className={merge("text-sm text-danger", className)}
|
|
141
|
+
{...props}
|
|
142
|
+
/>
|
|
143
|
+
);
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
FieldError.displayName = "FieldError";
|
|
147
|
+
|
|
148
|
+
export { Field, FieldControl, FieldDescription, FieldError, FieldLabel };
|
package/src/ui/search-input.tsx
CHANGED
|
@@ -7,6 +7,8 @@ import { useCn, useUiConfig } from "./ui-config";
|
|
|
7
7
|
const sizeClasses = {
|
|
8
8
|
sm: { input: "h-8 pl-8 text-base sm:pointer-fine:text-sm", icon: "left-2" },
|
|
9
9
|
md: { input: "h-10 pl-9", icon: "left-3" },
|
|
10
|
+
// Alias of `md`.
|
|
11
|
+
default: { input: "h-10 pl-9", icon: "left-3" },
|
|
10
12
|
};
|
|
11
13
|
|
|
12
14
|
const variantClasses = {
|
|
@@ -42,7 +44,7 @@ export interface SearchInputProps extends Omit<ClearInputProps, "leading" | "siz
|
|
|
42
44
|
label?: string;
|
|
43
45
|
/** Key hint shown on the right while the value is empty, such as `"/"` or `"⌘K"`. */
|
|
44
46
|
shortcut?: string;
|
|
45
|
-
/** `sm` is `h-8
|
|
47
|
+
/** `sm` is `h-8`; `md` and its alias `default` are `h-10`. Default `"sm"`. */
|
|
46
48
|
size?: keyof typeof sizeClasses;
|
|
47
49
|
/** `toolbar`: transparent until hover or focus, fixed width from `sm`. Default `"default"`. */
|
|
48
50
|
variant?: keyof typeof variantClasses;
|
package/src/ui/spinner.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { useCn, useUiConfig } from "./ui-config";
|
|
|
5
5
|
const sizeClasses = {
|
|
6
6
|
sm: "size-4",
|
|
7
7
|
md: "size-6",
|
|
8
|
+
default: "size-6",
|
|
8
9
|
lg: "size-8",
|
|
9
10
|
};
|
|
10
11
|
|
|
@@ -54,8 +55,8 @@ export type SpinnerProps = Omit<React.ComponentPropsWithoutRef<"svg">, "size" |
|
|
|
54
55
|
* carry the state); `size`, `tone`, `stroke` and `decorative` do not apply.
|
|
55
56
|
*/
|
|
56
57
|
variant?: "icon" | "circle" | "ring";
|
|
57
|
-
/** Named size (a `size-*` class) or a pixel size (`width`/`height`, no size class). Default `"md"`. Not used with `"ring"`. */
|
|
58
|
-
size?: "sm" | "md" | "lg" | number;
|
|
58
|
+
/** Named size (a `size-*` class; `default` is an alias of `md`) or a pixel size (`width`/`height`, no size class). Default `"md"`. Not used with `"ring"`. */
|
|
59
|
+
size?: "sm" | "md" | "default" | "lg" | number;
|
|
59
60
|
/** Icon stroke width. Default the icon's own (2). Only for `"icon"`. */
|
|
60
61
|
stroke?: number | string;
|
|
61
62
|
/** `"muted"` adds `text-muted-foreground`; `"inherit"` adds no colour class, so the icon uses `currentColor`. Default `"muted"`. Only for `"icon"`. */
|
|
@@ -225,7 +226,7 @@ function RingSpinner({
|
|
|
225
226
|
return (
|
|
226
227
|
<svg className={merge("h-4 w-4 animate-spin", className)} xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" {...props}>
|
|
227
228
|
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
|
228
|
-
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014
|
|
229
|
+
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
|
|
229
230
|
</svg>
|
|
230
231
|
);
|
|
231
232
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { AnimatePresence, m, type Variants } from "motion/react";
|
|
4
|
+
import { useState, type ReactNode } from "react";
|
|
5
|
+
import { motionEase } from "../motion/presets";
|
|
6
|
+
import { cn } from "../utils/cn";
|
|
7
|
+
import { useUiConfig } from "./ui-config";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* How tab content moves when the tab changes. The new panel comes from the
|
|
11
|
+
* side of the tab that was picked (right of the old one: from the right), as a
|
|
12
|
+
* phone swipe does.
|
|
13
|
+
* - `"none"` (default): swap at once.
|
|
14
|
+
* - `"slide"`: a short 32px slide with a fade. Reads the direction without
|
|
15
|
+
* moving the page; the desktop default for apps that opt in.
|
|
16
|
+
* - `"push"`: the old panel leaves the full width as the new one enters, like
|
|
17
|
+
* a phone pager. Heavier; suits narrow or swipe-driven surfaces.
|
|
18
|
+
*/
|
|
19
|
+
export type TabsTransitionVariant = "none" | "slide" | "push";
|
|
20
|
+
|
|
21
|
+
type Direction = 1 | -1;
|
|
22
|
+
|
|
23
|
+
const SLIDE_PX = 32;
|
|
24
|
+
|
|
25
|
+
const variants: Record<Exclude<TabsTransitionVariant, "none">, Variants> = {
|
|
26
|
+
slide: {
|
|
27
|
+
enter: (dir: Direction) => ({ x: dir * SLIDE_PX, opacity: 0 }),
|
|
28
|
+
center: { x: 0, opacity: 1, transition: { duration: 0.24, ease: motionEase } },
|
|
29
|
+
// Leaves faster than it enters, so the old panel never lingers.
|
|
30
|
+
exit: (dir: Direction) => ({
|
|
31
|
+
x: -dir * SLIDE_PX,
|
|
32
|
+
opacity: 0,
|
|
33
|
+
transition: { duration: 0.14, ease: motionEase },
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
push: {
|
|
37
|
+
enter: (dir: Direction) => ({ x: `${dir * 100}%` }),
|
|
38
|
+
center: { x: "0%", transition: { duration: 0.32, ease: motionEase } },
|
|
39
|
+
exit: (dir: Direction) => ({
|
|
40
|
+
x: `${-dir * 100}%`,
|
|
41
|
+
transition: { duration: 0.32, ease: motionEase },
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export interface TabsTransitionProps {
|
|
47
|
+
/** The selected tab. A new value plays the transition. */
|
|
48
|
+
value: string;
|
|
49
|
+
/** Tab values in their on-screen order, left to right; gives the direction. */
|
|
50
|
+
order: ReadonlyArray<string>;
|
|
51
|
+
/** Defaults to the app's `UiConfig.Tabs.transition`, then `"none"`. */
|
|
52
|
+
variant?: TabsTransitionVariant;
|
|
53
|
+
className?: string;
|
|
54
|
+
/** The selected tab's content. */
|
|
55
|
+
children: ReactNode;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Wraps the content of a tab set and moves it when the tab changes. Works with
|
|
60
|
+
* any tab content, routed or not: it keys on `value`, so the outgoing panel can
|
|
61
|
+
* leave while the new one enters. The container clips the slide sideways only,
|
|
62
|
+
* so content keeps its natural height. Motion settings apply: `MotionProvider
|
|
63
|
+
* reducedMotion` and page-motion off stop the slide.
|
|
64
|
+
*/
|
|
65
|
+
export function TabsTransition({
|
|
66
|
+
value,
|
|
67
|
+
order,
|
|
68
|
+
variant: variantProp,
|
|
69
|
+
className,
|
|
70
|
+
children,
|
|
71
|
+
}: TabsTransitionProps) {
|
|
72
|
+
const configVariant = useUiConfig("Tabs")?.transition;
|
|
73
|
+
const variant = variantProp ?? configVariant ?? "none";
|
|
74
|
+
// Direction follows the move from the previous tab to this one. Derived in
|
|
75
|
+
// render (adjust-state-on-change), so the first frame already knows it.
|
|
76
|
+
const [previous, setPrevious] = useState(value);
|
|
77
|
+
const [direction, setDirection] = useState<Direction>(1);
|
|
78
|
+
if (value !== previous) {
|
|
79
|
+
setDirection(order.indexOf(value) >= order.indexOf(previous) ? 1 : -1);
|
|
80
|
+
setPrevious(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (variant === "none") {
|
|
84
|
+
return <div className={className}>{children}</div>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div className={cn("relative overflow-x-clip", className)}>
|
|
89
|
+
<AnimatePresence initial={false} custom={direction} mode="popLayout">
|
|
90
|
+
<m.div
|
|
91
|
+
key={value}
|
|
92
|
+
custom={direction}
|
|
93
|
+
variants={variants[variant]}
|
|
94
|
+
initial="enter"
|
|
95
|
+
animate="center"
|
|
96
|
+
exit="exit"
|
|
97
|
+
>
|
|
98
|
+
{children}
|
|
99
|
+
</m.div>
|
|
100
|
+
</AnimatePresence>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
package/src/ui/tabs.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { cva, type VariantProps } from "class-variance-authority";
|
|
|
4
4
|
import { assignRef } from "../utils/ref";
|
|
5
5
|
import { syncTabsPill, type TabsPillMotion } from "./tabsSliding";
|
|
6
6
|
import { useCn, useUiConfig } from "./ui-config";
|
|
7
|
+
import type { TabsTransitionVariant } from "./tabs-transition";
|
|
7
8
|
|
|
8
9
|
const Tabs = TabsPrimitive.Root;
|
|
9
10
|
|
|
@@ -24,6 +25,8 @@ type TabsListSize = "default" | "sm";
|
|
|
24
25
|
export interface TabsConfig {
|
|
25
26
|
variant?: TabsListVariant;
|
|
26
27
|
pillMotion?: TabsPillMotion;
|
|
28
|
+
/** Default `TabsTransition` variant for every tab set in the app. */
|
|
29
|
+
transition?: TabsTransitionVariant;
|
|
27
30
|
classes?: {
|
|
28
31
|
list?: string;
|
|
29
32
|
size?: Partial<Record<TabsListSize, string>>;
|
|
@@ -195,7 +198,8 @@ const TabsContent = React.forwardRef<
|
|
|
195
198
|
});
|
|
196
199
|
TabsContent.displayName = TabsPrimitive.Content.displayName;
|
|
197
200
|
|
|
198
|
-
|
|
201
|
+
/** The class recipe of `TabsBar`. Ignores `UiConfig.Tabs` overrides. */
|
|
202
|
+
export const tabsBarVariants = cva(
|
|
199
203
|
"flex shrink-0 flex-wrap items-center gap-2 border-b border-border",
|
|
200
204
|
{
|
|
201
205
|
variants: {
|