@glasshome/ui 1.21.0 → 1.21.2

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 (154) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/lib/use-is-mobile.d.ts +3 -1
  4. package/dist/solid/alert-dialog.d.ts +7 -1
  5. package/dist/solid/bottom-sheet/bottom-sheet.d.ts +7 -1
  6. package/dist/solid/dialog-parts.d.ts +3 -2
  7. package/dist/solid/dialog.d.ts +7 -1
  8. package/dist/solid/docked-panel.d.ts +7 -1
  9. package/dist/solid/index.d.ts +9 -9
  10. package/dist/solid/index.js +5456 -5447
  11. package/dist/solid/media-store.d.ts +4 -1
  12. package/dist/solid/option-card.d.ts +4 -1
  13. package/dist/solid/responsive-dialog.d.ts +7 -1
  14. package/dist/solid/sheet.d.ts +7 -1
  15. package/dist/{utils-CMk7R3zM.js → utils-D5blHO4O.js} +624 -622
  16. package/package.json +128 -126
  17. package/scripts/check-gallery.ts +142 -142
  18. package/scripts/check-pack.ts +13 -13
  19. package/scripts/check-structural-classes.ts +20 -20
  20. package/scripts/check-tokens.ts +27 -27
  21. package/scripts/check-ui-drift.mjs +103 -103
  22. package/src/index.ts +75 -80
  23. package/src/lib/alert-tones.ts +41 -41
  24. package/src/lib/anchor-placement.ts +21 -21
  25. package/src/lib/button-variants.ts +28 -28
  26. package/src/lib/card-classes.ts +9 -9
  27. package/src/lib/carousel-classes.ts +14 -14
  28. package/src/lib/glass-tone.ts +11 -11
  29. package/src/lib/input-classes.ts +6 -6
  30. package/src/lib/layers.ts +4 -4
  31. package/src/lib/logo-lockup.ts +8 -8
  32. package/src/lib/menu-classes.ts +2 -2
  33. package/src/lib/motion-classes.ts +8 -8
  34. package/src/lib/motion-window.ts +24 -24
  35. package/src/lib/overlay-classes.ts +6 -6
  36. package/src/lib/pill-classes.ts +3 -3
  37. package/src/lib/position-bar-classes.ts +1 -1
  38. package/src/lib/spotlight-geometry.ts +67 -67
  39. package/src/lib/thumb-classes.ts +2 -2
  40. package/src/lib/tier-badge.ts +16 -16
  41. package/src/lib/use-is-mobile.ts +17 -14
  42. package/src/lib/utils.ts +1 -1
  43. package/src/solid/accordion.tsx +41 -41
  44. package/src/solid/alert-dialog.tsx +95 -95
  45. package/src/solid/alert.tsx +88 -88
  46. package/src/solid/area-picker.tsx +204 -204
  47. package/src/solid/aspect-ratio.tsx +13 -13
  48. package/src/solid/avatar.tsx +27 -27
  49. package/src/solid/badge.tsx +49 -49
  50. package/src/solid/bottom-sheet/arbitration.ts +22 -22
  51. package/src/solid/bottom-sheet/bottom-sheet.tsx +394 -394
  52. package/src/solid/bottom-sheet/drag-controller.ts +201 -201
  53. package/src/solid/bottom-sheet/focus-trap.ts +51 -47
  54. package/src/solid/bottom-sheet/index.ts +12 -12
  55. package/src/solid/bottom-sheet/keyboard.ts +25 -25
  56. package/src/solid/bottom-sheet/scroll-lock.ts +46 -46
  57. package/src/solid/bottom-sheet/state-machine.ts +28 -28
  58. package/src/solid/bottom-sheet/velocity.ts +29 -29
  59. package/src/solid/breadcrumb.tsx +76 -76
  60. package/src/solid/button-group.tsx +46 -46
  61. package/src/solid/button.tsx +19 -19
  62. package/src/solid/card.tsx +67 -67
  63. package/src/solid/carousel.tsx +246 -246
  64. package/src/solid/charts.tsx +253 -253
  65. package/src/solid/checkbox.tsx +51 -51
  66. package/src/solid/collapsible.tsx +22 -22
  67. package/src/solid/color-disc.tsx +213 -213
  68. package/src/solid/color-slider.tsx +81 -81
  69. package/src/solid/color-wheel.tsx +61 -61
  70. package/src/solid/context-menu.tsx +63 -63
  71. package/src/solid/copy-button.tsx +31 -31
  72. package/src/solid/count-pill.tsx +11 -11
  73. package/src/solid/dashboard-preview.tsx +104 -104
  74. package/src/solid/data-table.tsx +228 -228
  75. package/src/solid/dialog-parts.tsx +129 -129
  76. package/src/solid/dialog.tsx +113 -113
  77. package/src/solid/dock-paging.ts +9 -9
  78. package/src/solid/dock.tsx +339 -338
  79. package/src/solid/docked-panel.tsx +35 -35
  80. package/src/solid/dropdown-menu.tsx +77 -77
  81. package/src/solid/empty.tsx +70 -70
  82. package/src/solid/entity-data.ts +38 -38
  83. package/src/solid/entity-selector.tsx +634 -634
  84. package/src/solid/field.tsx +205 -205
  85. package/src/solid/form.tsx +159 -159
  86. package/src/solid/hero-action.tsx +85 -85
  87. package/src/solid/hover-card.tsx +11 -11
  88. package/src/solid/icon-picker.tsx +401 -401
  89. package/src/solid/icon.tsx +101 -78
  90. package/src/solid/image-picker.tsx +416 -414
  91. package/src/solid/index.ts +265 -304
  92. package/src/solid/input-group.tsx +123 -123
  93. package/src/solid/input-otp.tsx +143 -143
  94. package/src/solid/input.tsx +4 -4
  95. package/src/solid/item.tsx +130 -130
  96. package/src/solid/kbd.tsx +20 -20
  97. package/src/solid/label.tsx +12 -12
  98. package/src/solid/list-reorder.ts +122 -122
  99. package/src/solid/logo.tsx +60 -60
  100. package/src/solid/media-copy.ts +21 -21
  101. package/src/solid/media-store.ts +60 -57
  102. package/src/solid/media-tile.tsx +85 -85
  103. package/src/solid/menu-parts.tsx +164 -164
  104. package/src/solid/number-field.tsx +56 -56
  105. package/src/solid/option-card.tsx +168 -165
  106. package/src/solid/ornament.tsx +43 -43
  107. package/src/solid/overlay.tsx +4 -4
  108. package/src/solid/page-header.tsx +75 -75
  109. package/src/solid/pagination.tsx +80 -80
  110. package/src/solid/password-input.tsx +51 -51
  111. package/src/solid/picker-row.tsx +83 -83
  112. package/src/solid/picker-search.tsx +65 -63
  113. package/src/solid/picker-trigger.tsx +59 -57
  114. package/src/solid/popover.tsx +54 -54
  115. package/src/solid/preview-tile.tsx +67 -67
  116. package/src/solid/progress.tsx +21 -21
  117. package/src/solid/radio-group.tsx +51 -51
  118. package/src/solid/resizable.tsx +128 -128
  119. package/src/solid/responsive-dialog.tsx +134 -134
  120. package/src/solid/schema-form.tsx +746 -739
  121. package/src/solid/scope-indicator.tsx +5 -5
  122. package/src/solid/scroll-area.tsx +16 -16
  123. package/src/solid/section-card.tsx +281 -281
  124. package/src/solid/select.tsx +101 -101
  125. package/src/solid/separator.tsx +25 -25
  126. package/src/solid/settings-row.tsx +122 -122
  127. package/src/solid/sheet.tsx +96 -96
  128. package/src/solid/skeleton.tsx +8 -8
  129. package/src/solid/slider.tsx +132 -132
  130. package/src/solid/sliding-indicator.tsx +280 -265
  131. package/src/solid/sonner.tsx +164 -164
  132. package/src/solid/spinner.tsx +12 -12
  133. package/src/solid/spotlight.tsx +140 -140
  134. package/src/solid/step-indicator.tsx +18 -18
  135. package/src/solid/swatch-picker.tsx +38 -38
  136. package/src/solid/switch.tsx +52 -52
  137. package/src/solid/table.tsx +63 -63
  138. package/src/solid/tabs.tsx +93 -93
  139. package/src/solid/textarea.tsx +8 -8
  140. package/src/solid/toggle-group.tsx +83 -83
  141. package/src/solid/toggle.tsx +33 -33
  142. package/src/solid/tooltip.tsx +16 -16
  143. package/src/solid/widget-card.tsx +90 -90
  144. package/src/solid/widget-identity.tsx +99 -99
  145. package/src/solid/widget-trust-badge.tsx +20 -20
  146. package/src/styles/globals.css +316 -319
  147. package/src/styles/theme.css +448 -448
  148. package/src/tokens/hex.ts +29 -29
  149. package/src/tokens/material.ts +75 -75
  150. package/src/tokens/presets.ts +303 -303
  151. package/src/tokens/readability.ts +32 -32
  152. package/src/tokens/theme-colors.ts +95 -95
  153. package/src/tokens/theme-css.ts +22 -22
  154. package/src/tokens/theme-recipe.ts +106 -106
@@ -5,71 +5,71 @@ import { cn } from "../lib/utils.js";
5
5
  import { Button } from "./button.js";
6
6
 
7
7
  const InputGroup: Component<ComponentProps<"div">> = (props) => {
8
- const [local, rest] = splitProps(props, ["class"]);
9
- return (
10
- // biome-ignore lint/a11y/useSemanticElements: fieldset would carry default browser styling and break the input layout; role=group conveys the same semantics.
11
- <div
12
- data-slot="input-group"
13
- role="group"
14
- class={cn(
15
- `group/input-group relative flex w-full items-center rounded-md ${INPUT_SURFACE} outline-none transition-[color,box-shadow]`,
16
- `${CONTROL_H.default} min-w-0 has-[>textarea]:h-auto`,
17
- "has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col",
18
- "has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col",
19
- // The shell wears the focus and invalid state for the control inside
20
- // it; on glass the edge moves through the knob, never through border-*.
21
- "has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot=input-group-control]:focus-visible]:[--glass-edge:var(--ring)]",
22
- "has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[[data-slot][aria-invalid=true]]:[--glass-edge:var(--destructive)]",
23
- local.class,
24
- )}
25
- {...rest}
26
- />
27
- );
8
+ const [local, rest] = splitProps(props, ["class"]);
9
+ return (
10
+ // biome-ignore lint/a11y/useSemanticElements: fieldset would carry default browser styling and break the input layout; role=group conveys the same semantics.
11
+ <div
12
+ data-slot="input-group"
13
+ role="group"
14
+ class={cn(
15
+ `group/input-group relative flex w-full items-center rounded-md ${INPUT_SURFACE} transition-[color,box-shadow] outline-none`,
16
+ `${CONTROL_H.default} min-w-0 has-[>textarea]:h-auto`,
17
+ "has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col",
18
+ "has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col",
19
+ // The shell wears the focus and invalid state for the control inside
20
+ // it; on glass the edge moves through the knob, never through border-*.
21
+ "has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:[--glass-edge:var(--ring)]",
22
+ "has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[[data-slot][aria-invalid=true]]:[--glass-edge:var(--destructive)]",
23
+ local.class,
24
+ )}
25
+ {...rest}
26
+ />
27
+ );
28
28
  };
29
29
 
30
30
  /* An addon owns the distance to the panel edge, and only that: the control
31
31
  * keeps its own px-3, so nothing reaches into a sibling to trim it. A button
32
32
  * or kbd inside already carries its own padding, so the addon sits closer. */
33
33
  const inputGroupAddonVariants = cva({
34
- base: "flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 font-medium text-muted-foreground text-sm group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-sm [&>svg:not([class*='size-'])]:size-4",
35
- variants: {
36
- align: {
37
- "inline-start": "order-first pl-3 has-[>button]:pl-1.5 has-[>kbd]:pl-2",
38
- "inline-end": "order-last pr-3 has-[>button]:pr-1.5 has-[>kbd]:pr-2",
39
- "block-start": "order-first w-full justify-start px-3 pt-3 [.border-b]:pb-3",
40
- "block-end": "order-last w-full justify-start px-3 pb-3 [.border-t]:pt-3",
41
- },
42
- },
43
- defaultVariants: {
44
- align: "inline-start",
45
- },
34
+ base: "text-muted-foreground flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-sm [&>svg:not([class*='size-'])]:size-4",
35
+ variants: {
36
+ align: {
37
+ "inline-start": "order-first pl-3 has-[>button]:pl-1.5 has-[>kbd]:pl-2",
38
+ "inline-end": "order-last pr-3 has-[>button]:pr-1.5 has-[>kbd]:pr-2",
39
+ "block-start": "order-first w-full justify-start px-3 pt-3 [.border-b]:pb-3",
40
+ "block-end": "order-last w-full justify-start px-3 pb-3 [.border-t]:pt-3",
41
+ },
42
+ },
43
+ defaultVariants: {
44
+ align: "inline-start",
45
+ },
46
46
  });
47
47
 
48
48
  const InputGroupAddon: Component<
49
- ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>
49
+ ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>
50
50
  > = (props) => {
51
- const [local, rest] = splitProps(props, ["class", "align"] as const);
52
- const align = () => local.align ?? "inline-start";
53
- return (
54
- // Addon click forwards focus to the sibling input (cursor-text affordance); buttons inside keep their own behavior.
55
- // biome-ignore lint/a11y/useKeyWithClickEvents: see above
56
- // biome-ignore lint/a11y/useSemanticElements: see above
57
- <div
58
- role="group"
59
- data-slot="input-group-addon"
60
- data-align={align()}
61
- class={cn(inputGroupAddonVariants({ align: align() }), local.class)}
62
- onClick={(e) => {
63
- if ((e.target as HTMLElement).closest("button")) {
64
- return;
65
- }
66
- (e.currentTarget as HTMLElement).parentElement
67
- ?.querySelector<HTMLInputElement>("input")
68
- ?.focus();
69
- }}
70
- {...rest}
71
- />
72
- );
51
+ const [local, rest] = splitProps(props, ["class", "align"] as const);
52
+ const align = () => local.align ?? "inline-start";
53
+ return (
54
+ // Addon click forwards focus to the sibling input (cursor-text affordance); buttons inside keep their own behavior.
55
+ // biome-ignore lint/a11y/useKeyWithClickEvents: see above
56
+ // biome-ignore lint/a11y/useSemanticElements: see above
57
+ <div
58
+ role="group"
59
+ data-slot="input-group-addon"
60
+ data-align={align()}
61
+ class={cn(inputGroupAddonVariants({ align: align() }), local.class)}
62
+ onClick={(e) => {
63
+ if ((e.target as HTMLElement).closest("button")) {
64
+ return;
65
+ }
66
+ (e.currentTarget as HTMLElement).parentElement
67
+ ?.querySelector<HTMLInputElement>("input")
68
+ ?.focus();
69
+ }}
70
+ {...rest}
71
+ />
72
+ );
73
73
  };
74
74
 
75
75
  /* Both button sizes come from the shared control heights: sm fits inside the
@@ -78,53 +78,53 @@ const GROUP_BUTTON_SM = `${CONTROL_H.sm} gap-1.5 px-2.5 has-[>svg]:px-2.5`;
78
78
  const GROUP_BUTTON_ICON_SM = "size-8 p-0 has-[>svg]:p-0";
79
79
 
80
80
  const inputGroupButtonVariants = cva({
81
- base: "flex items-center gap-2 rounded-sm text-sm shadow-none",
82
- variants: {
83
- size: {
84
- /** @deprecated Use "sm". */
85
- xs: GROUP_BUTTON_SM,
86
- sm: GROUP_BUTTON_SM,
87
- default: `${CONTROL_H.default} px-3 has-[>svg]:px-3`,
88
- /** @deprecated Use "icon-sm". */
89
- "icon-xs": GROUP_BUTTON_ICON_SM,
90
- "icon-sm": GROUP_BUTTON_ICON_SM,
91
- "icon-default": "size-9 p-0 has-[>svg]:p-0",
92
- },
93
- },
94
- defaultVariants: {
95
- size: "sm",
96
- },
81
+ base: "flex items-center gap-2 rounded-sm text-sm shadow-none",
82
+ variants: {
83
+ size: {
84
+ /** @deprecated Use "sm". */
85
+ xs: GROUP_BUTTON_SM,
86
+ sm: GROUP_BUTTON_SM,
87
+ default: `${CONTROL_H.default} px-3 has-[>svg]:px-3`,
88
+ /** @deprecated Use "icon-sm". */
89
+ "icon-xs": GROUP_BUTTON_ICON_SM,
90
+ "icon-sm": GROUP_BUTTON_ICON_SM,
91
+ "icon-default": "size-9 p-0 has-[>svg]:p-0",
92
+ },
93
+ },
94
+ defaultVariants: {
95
+ size: "sm",
96
+ },
97
97
  });
98
98
 
99
99
  const InputGroupButton: Component<
100
- Omit<ComponentProps<typeof Button>, "size"> & VariantProps<typeof inputGroupButtonVariants>
100
+ Omit<ComponentProps<typeof Button>, "size"> & VariantProps<typeof inputGroupButtonVariants>
101
101
  > = (props) => {
102
- const [local, rest] = splitProps(props, ["class", "type", "variant", "size"] as const);
103
- const size = () => local.size ?? "sm";
104
- return (
105
- <Button
106
- type={local.type ?? "button"}
107
- data-slot="input-group-button"
108
- data-size={size()}
109
- variant={local.variant ?? "ghost"}
110
- class={cn(inputGroupButtonVariants({ size: size() }), local.class)}
111
- {...rest}
112
- />
113
- );
102
+ const [local, rest] = splitProps(props, ["class", "type", "variant", "size"] as const);
103
+ const size = () => local.size ?? "sm";
104
+ return (
105
+ <Button
106
+ type={local.type ?? "button"}
107
+ data-slot="input-group-button"
108
+ data-size={size()}
109
+ variant={local.variant ?? "ghost"}
110
+ class={cn(inputGroupButtonVariants({ size: size() }), local.class)}
111
+ {...rest}
112
+ />
113
+ );
114
114
  };
115
115
 
116
116
  const InputGroupText: Component<ComponentProps<"span">> = (props) => {
117
- const [local, rest] = splitProps(props, ["class"]);
118
- return (
119
- <span
120
- data-slot="input-group-text"
121
- class={cn(
122
- "flex items-center gap-2 text-muted-foreground text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none",
123
- local.class,
124
- )}
125
- {...rest}
126
- />
127
- );
117
+ const [local, rest] = splitProps(props, ["class"]);
118
+ return (
119
+ <span
120
+ data-slot="input-group-text"
121
+ class={cn(
122
+ "text-muted-foreground flex items-center gap-2 text-sm [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
123
+ local.class,
124
+ )}
125
+ {...rest}
126
+ />
127
+ );
128
128
  };
129
129
 
130
130
  // The control inside a group is SURFACELESS — the <InputGroup> owns the border,
@@ -133,38 +133,38 @@ const InputGroupText: Component<ComponentProps<"span">> = (props) => {
133
133
  // gradient inside the group (a `bg-transparent` can't clear the `background`
134
134
  // shorthand's image layers) and stacks a second concave surface.
135
135
  const InputGroupInput: Component<ComponentProps<"input">> = (props) => {
136
- const [local, rest] = splitProps(props, ["class"]);
137
- return (
138
- <input
139
- data-slot="input-group-control"
140
- class={cn(
141
- `${CONTROL_H.default} w-full flex-1 rounded-none border-0 bg-transparent px-3 py-1 ${FIELD_TEXT} shadow-none outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,
142
- local.class,
143
- )}
144
- {...rest}
145
- />
146
- );
136
+ const [local, rest] = splitProps(props, ["class"]);
137
+ return (
138
+ <input
139
+ data-slot="input-group-control"
140
+ class={cn(
141
+ `${CONTROL_H.default} w-full flex-1 rounded-none border-0 bg-transparent px-3 py-1 ${FIELD_TEXT} placeholder:text-muted-foreground shadow-none outline-none disabled:cursor-not-allowed disabled:opacity-50`,
142
+ local.class,
143
+ )}
144
+ {...rest}
145
+ />
146
+ );
147
147
  };
148
148
 
149
149
  const InputGroupTextarea: Component<ComponentProps<"textarea">> = (props) => {
150
- const [local, rest] = splitProps(props, ["class"]);
151
- return (
152
- <textarea
153
- data-slot="input-group-control"
154
- class={cn(
155
- `field-sizing-content min-h-16 w-full flex-1 resize-none rounded-none border-0 bg-transparent px-3 py-2 ${FIELD_TEXT} shadow-none outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`,
156
- local.class,
157
- )}
158
- {...rest}
159
- />
160
- );
150
+ const [local, rest] = splitProps(props, ["class"]);
151
+ return (
152
+ <textarea
153
+ data-slot="input-group-control"
154
+ class={cn(
155
+ `field-sizing-content min-h-16 w-full flex-1 resize-none rounded-none border-0 bg-transparent px-3 py-2 ${FIELD_TEXT} placeholder:text-muted-foreground shadow-none outline-none disabled:cursor-not-allowed disabled:opacity-50`,
156
+ local.class,
157
+ )}
158
+ {...rest}
159
+ />
160
+ );
161
161
  };
162
162
 
163
163
  export {
164
- InputGroup,
165
- InputGroupAddon,
166
- InputGroupButton,
167
- InputGroupInput,
168
- InputGroupText,
169
- InputGroupTextarea,
164
+ InputGroup,
165
+ InputGroupAddon,
166
+ InputGroupButton,
167
+ InputGroupInput,
168
+ InputGroupText,
169
+ InputGroupTextarea,
170
170
  };
@@ -1,175 +1,175 @@
1
1
  import {
2
- type Component,
3
- type ComponentProps,
4
- createContext,
5
- createSignal,
6
- type ParentComponent,
7
- Show,
8
- splitProps,
9
- useContext,
2
+ type Component,
3
+ type ComponentProps,
4
+ createContext,
5
+ createSignal,
6
+ type ParentComponent,
7
+ Show,
8
+ splitProps,
9
+ useContext,
10
10
  } from "solid-js";
11
11
  import { CONTROL_H, FOCUS_RING, INPUT_SURFACE } from "../lib/input-classes.js";
12
12
  import { cn } from "../lib/utils.js";
13
13
  import { Icon } from "./icon.js";
14
14
 
15
15
  interface InputOTPContextValue {
16
- value: () => string;
17
- activeIndex: () => number;
18
- isActive: () => boolean;
16
+ value: () => string;
17
+ activeIndex: () => number;
18
+ isActive: () => boolean;
19
19
  }
20
20
 
21
21
  const InputOTPContext = createContext<InputOTPContextValue>();
22
22
 
23
23
  const InputOTP: ParentComponent<
24
- ComponentProps<"div"> & {
25
- maxLength: number;
26
- value?: string;
27
- onValueChange?: (value: string) => void;
28
- onComplete?: (value: string) => void;
29
- containerClass?: string;
30
- pattern?: string;
31
- }
24
+ ComponentProps<"div"> & {
25
+ maxLength: number;
26
+ value?: string;
27
+ onValueChange?: (value: string) => void;
28
+ onComplete?: (value: string) => void;
29
+ containerClass?: string;
30
+ pattern?: string;
31
+ }
32
32
  > = (props) => {
33
- const [local, rest] = splitProps(props, [
34
- "class",
35
- "children",
36
- "maxLength",
37
- "value",
38
- "onValueChange",
39
- "onComplete",
40
- "containerClass",
41
- "pattern",
42
- ]);
43
- const [internalValue, setInternalValue] = createSignal(local.value ?? "");
44
- const [activeIndex, setActiveIndex] = createSignal(-1);
45
- const [isActive, setIsActive] = createSignal(false);
46
- let inputRef!: HTMLInputElement;
33
+ const [local, rest] = splitProps(props, [
34
+ "class",
35
+ "children",
36
+ "maxLength",
37
+ "value",
38
+ "onValueChange",
39
+ "onComplete",
40
+ "containerClass",
41
+ "pattern",
42
+ ]);
43
+ const [internalValue, setInternalValue] = createSignal(local.value ?? "");
44
+ const [activeIndex, setActiveIndex] = createSignal(-1);
45
+ const [isActive, setIsActive] = createSignal(false);
46
+ let inputRef!: HTMLInputElement;
47
47
 
48
- const value = () => (local.value !== undefined ? local.value : internalValue());
48
+ const value = () => (local.value !== undefined ? local.value : internalValue());
49
49
 
50
- const handleInput = (e: InputEvent) => {
51
- const target = e.target as HTMLInputElement;
52
- let newValue = target.value.slice(0, local.maxLength);
53
- if (local.pattern) {
54
- const regex = new RegExp(local.pattern);
55
- newValue = newValue
56
- .split("")
57
- .filter((c) => regex.test(c))
58
- .join("");
59
- }
60
- setInternalValue(newValue);
61
- local.onValueChange?.(newValue);
62
- setActiveIndex(newValue.length);
63
- if (newValue.length === local.maxLength) {
64
- local.onComplete?.(newValue);
65
- }
66
- };
50
+ const handleInput = (e: InputEvent) => {
51
+ const target = e.target as HTMLInputElement;
52
+ let newValue = target.value.slice(0, local.maxLength);
53
+ if (local.pattern) {
54
+ const regex = new RegExp(local.pattern);
55
+ newValue = newValue
56
+ .split("")
57
+ .filter((c) => regex.test(c))
58
+ .join("");
59
+ }
60
+ setInternalValue(newValue);
61
+ local.onValueChange?.(newValue);
62
+ setActiveIndex(newValue.length);
63
+ if (newValue.length === local.maxLength) {
64
+ local.onComplete?.(newValue);
65
+ }
66
+ };
67
67
 
68
- const handleKeyDown = (e: KeyboardEvent) => {
69
- if (e.key === "Backspace") {
70
- const val = value();
71
- if (val.length > 0) {
72
- const newValue = val.slice(0, -1);
73
- setInternalValue(newValue);
74
- local.onValueChange?.(newValue);
75
- setActiveIndex(newValue.length);
76
- }
77
- e.preventDefault();
78
- }
79
- };
68
+ const handleKeyDown = (e: KeyboardEvent) => {
69
+ if (e.key === "Backspace") {
70
+ const val = value();
71
+ if (val.length > 0) {
72
+ const newValue = val.slice(0, -1);
73
+ setInternalValue(newValue);
74
+ local.onValueChange?.(newValue);
75
+ setActiveIndex(newValue.length);
76
+ }
77
+ e.preventDefault();
78
+ }
79
+ };
80
80
 
81
- const handleFocus = () => {
82
- setIsActive(true);
83
- setActiveIndex(value().length);
84
- };
81
+ const handleFocus = () => {
82
+ setIsActive(true);
83
+ setActiveIndex(value().length);
84
+ };
85
85
 
86
- const handleBlur = () => {
87
- setIsActive(false);
88
- setActiveIndex(-1);
89
- };
86
+ const handleBlur = () => {
87
+ setIsActive(false);
88
+ setActiveIndex(-1);
89
+ };
90
90
 
91
- return (
92
- <InputOTPContext.Provider value={{ value, activeIndex, isActive }}>
93
- {/* Container click forwards focus to the visually hidden input, which owns all keyboard interaction. */}
94
- {/* biome-ignore lint/a11y/noStaticElementInteractions: see above */}
95
- {/* biome-ignore lint/a11y/useKeyWithClickEvents: see above */}
96
- <div
97
- data-slot="input-otp"
98
- class={cn("flex items-center gap-2 has-[:disabled]:opacity-50", local.containerClass)}
99
- onClick={() => inputRef.focus()}
100
- {...rest}
101
- >
102
- <input
103
- ref={inputRef}
104
- type="text"
105
- inputMode="numeric"
106
- autocomplete="one-time-code"
107
- maxLength={local.maxLength}
108
- value={value()}
109
- onInput={handleInput}
110
- onKeyDown={handleKeyDown}
111
- onFocus={handleFocus}
112
- onBlur={handleBlur}
113
- class={cn(
114
- "pointer-events-none absolute opacity-0",
115
- "disabled:cursor-not-allowed",
116
- local.class,
117
- )}
118
- />
119
- {local.children}
120
- </div>
121
- </InputOTPContext.Provider>
122
- );
91
+ return (
92
+ <InputOTPContext.Provider value={{ value, activeIndex, isActive }}>
93
+ {/* Container click forwards focus to the visually hidden input, which owns all keyboard interaction. */}
94
+ {/* biome-ignore lint/a11y/noStaticElementInteractions: see above */}
95
+ {/* biome-ignore lint/a11y/useKeyWithClickEvents: see above */}
96
+ <div
97
+ data-slot="input-otp"
98
+ class={cn("flex items-center gap-2 has-[:disabled]:opacity-50", local.containerClass)}
99
+ onClick={() => inputRef.focus()}
100
+ {...rest}
101
+ >
102
+ <input
103
+ ref={inputRef}
104
+ type="text"
105
+ inputMode="numeric"
106
+ autocomplete="one-time-code"
107
+ maxLength={local.maxLength}
108
+ value={value()}
109
+ onInput={handleInput}
110
+ onKeyDown={handleKeyDown}
111
+ onFocus={handleFocus}
112
+ onBlur={handleBlur}
113
+ class={cn(
114
+ "pointer-events-none absolute opacity-0",
115
+ "disabled:cursor-not-allowed",
116
+ local.class,
117
+ )}
118
+ />
119
+ {local.children}
120
+ </div>
121
+ </InputOTPContext.Provider>
122
+ );
123
123
  };
124
124
 
125
125
  const InputOTPGroup: Component<ComponentProps<"div">> = (props) => {
126
- const [local, rest] = splitProps(props, ["class"]);
127
- return (
128
- <div
129
- data-slot="input-otp-group"
130
- class={cn("flex items-center gap-1.5", local.class)}
131
- {...rest}
132
- />
133
- );
126
+ const [local, rest] = splitProps(props, ["class"]);
127
+ return (
128
+ <div
129
+ data-slot="input-otp-group"
130
+ class={cn("flex items-center gap-1.5", local.class)}
131
+ {...rest}
132
+ />
133
+ );
134
134
  };
135
135
 
136
136
  const InputOTPSlot: Component<ComponentProps<"div"> & { index: number }> = (props) => {
137
- const [local, rest] = splitProps(props, ["class", "index"]);
138
- const context = useContext(InputOTPContext);
139
- const char = () => context?.value()[local.index] ?? "";
140
- const isSlotActive = () => context?.isActive() && context?.activeIndex() === local.index;
141
- const hasFakeCaret = () => isSlotActive() && !char();
137
+ const [local, rest] = splitProps(props, ["class", "index"]);
138
+ const context = useContext(InputOTPContext);
139
+ const char = () => context?.value()[local.index] ?? "";
140
+ const isSlotActive = () => context?.isActive() && context?.activeIndex() === local.index;
141
+ const hasFakeCaret = () => isSlotActive() && !char();
142
142
 
143
- return (
144
- <div
145
- data-slot="input-otp-slot"
146
- data-active={isSlotActive()}
147
- class={cn(
148
- // Same constraint as the checkbox box: the theme's smallest radius token
149
- // fully rounds a cell this size, and a digit cell is not a dot.
150
- `relative flex ${CONTROL_H.default} w-9 items-center justify-center rounded-xs ${INPUT_SURFACE} text-sm transition-glass ${FOCUS_RING}`,
151
- "data-[active=true]:z-10 data-[active=true]:ring-[3px] data-[active=true]:ring-ring/50 data-[active=true]:[--glass-edge:var(--ring)]",
152
- "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:[--glass-edge:var(--destructive)]",
153
- local.class,
154
- )}
155
- {...rest}
156
- >
157
- {char()}
158
- <Show when={hasFakeCaret()}>
159
- <div class="pointer-events-none absolute inset-0 flex items-center justify-center">
160
- <div class="h-4 w-px animate-caret-blink bg-foreground duration-1000" />
161
- </div>
162
- </Show>
163
- </div>
164
- );
143
+ return (
144
+ <div
145
+ data-slot="input-otp-slot"
146
+ data-active={isSlotActive()}
147
+ class={cn(
148
+ // Same constraint as the checkbox box: the theme's smallest radius token
149
+ // fully rounds a cell this size, and a digit cell is not a dot.
150
+ `relative flex ${CONTROL_H.default} w-9 items-center justify-center rounded-xs ${INPUT_SURFACE} transition-glass text-sm ${FOCUS_RING}`,
151
+ "data-[active=true]:ring-ring/50 data-[active=true]:z-10 data-[active=true]:ring-[3px] data-[active=true]:[--glass-edge:var(--ring)]",
152
+ "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:[--glass-edge:var(--destructive)]",
153
+ local.class,
154
+ )}
155
+ {...rest}
156
+ >
157
+ {char()}
158
+ <Show when={hasFakeCaret()}>
159
+ <div class="pointer-events-none absolute inset-0 flex items-center justify-center">
160
+ <div class="animate-caret-blink bg-foreground h-4 w-px duration-1000" />
161
+ </div>
162
+ </Show>
163
+ </div>
164
+ );
165
165
  };
166
166
 
167
167
  const InputOTPSeparator: Component<ComponentProps<"div">> = (props) => {
168
- return (
169
- <div data-slot="input-otp-separator" aria-hidden="true" {...props}>
170
- <Icon icon="lucide:minus" width={16} height={16} />
171
- </div>
172
- );
168
+ return (
169
+ <div data-slot="input-otp-separator" aria-hidden="true" {...props}>
170
+ <Icon icon="lucide:minus" width={16} height={16} />
171
+ </div>
172
+ );
173
173
  };
174
174
 
175
175
  export { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot };
@@ -3,10 +3,10 @@ import { INPUT_CLASS } from "../lib/input-classes.js";
3
3
  import { cn } from "../lib/utils.js";
4
4
 
5
5
  const Input: Component<ComponentProps<"input">> = (props) => {
6
- const [local, others] = splitProps(props, ["class", "type"]);
7
- return (
8
- <input type={local.type} data-slot="input" class={cn(INPUT_CLASS, local.class)} {...others} />
9
- );
6
+ const [local, others] = splitProps(props, ["class", "type"]);
7
+ return (
8
+ <input type={local.type} data-slot="input" class={cn(INPUT_CLASS, local.class)} {...others} />
9
+ );
10
10
  };
11
11
 
12
12
  export { Input };