@enablo/swirlcn-ui 0.0.0-stage → 0.5.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/LICENSE +21 -0
- package/README.md +30 -2
- package/dist/chunk-3DJWDNQL.js +77 -0
- package/dist/chunk-7XUCETA6.js +447 -0
- package/dist/chunk-KZESIYUN.js +18 -0
- package/dist/flip.d.ts +98 -0
- package/dist/flip.js +158 -0
- package/dist/fonts/Inter-italic.var.woff2 +0 -0
- package/dist/fonts/Inter.var.woff2 +0 -0
- package/dist/fonts/OFL.txt +96 -0
- package/dist/index.d.ts +2459 -0
- package/dist/index.js +8439 -0
- package/dist/server.d.ts +144 -0
- package/dist/server.js +88 -0
- package/dist/spacing-BQaEPbUv.d.ts +59 -0
- package/dist/theme.css +146 -0
- package/package.json +84 -3
- package/src/components/accordion.tsx +102 -0
- package/src/components/action-list.tsx +294 -0
- package/src/components/alert-dialog.tsx +155 -0
- package/src/components/autocomplete.tsx +313 -0
- package/src/components/avatar.tsx +258 -0
- package/src/components/badge.tsx +100 -0
- package/src/components/banner.tsx +112 -0
- package/src/components/button-group.tsx +87 -0
- package/src/components/button.tsx +362 -0
- package/src/components/card.tsx +186 -0
- package/src/components/carousel.tsx +245 -0
- package/src/components/checkbox.tsx +125 -0
- package/src/components/chip.tsx +153 -0
- package/src/components/color-input.tsx +98 -0
- package/src/components/data-cell.tsx +230 -0
- package/src/components/date-input.tsx +223 -0
- package/src/components/date-picker.tsx +276 -0
- package/src/components/description-list.tsx +97 -0
- package/src/components/dialog.tsx +405 -0
- package/src/components/empty-state.tsx +63 -0
- package/src/components/file-chip.tsx +206 -0
- package/src/components/file-uploader.tsx +148 -0
- package/src/components/flip-app-header.tsx +104 -0
- package/src/components/flip-brand.tsx +77 -0
- package/src/components/flip-theme.tsx +95 -0
- package/src/components/form-control.tsx +397 -0
- package/src/components/form-group.tsx +26 -0
- package/src/components/heading.tsx +70 -0
- package/src/components/icon.tsx +119 -0
- package/src/components/image-grid.tsx +285 -0
- package/src/components/inline-notification.tsx +167 -0
- package/src/components/inline-status.tsx +100 -0
- package/src/components/input.tsx +390 -0
- package/src/components/label.tsx +28 -0
- package/src/components/lightbox.tsx +314 -0
- package/src/components/link.tsx +46 -0
- package/src/components/list.tsx +40 -0
- package/src/components/menu.tsx +530 -0
- package/src/components/option-list.tsx +582 -0
- package/src/components/pagination.tsx +336 -0
- package/src/components/popover.tsx +194 -0
- package/src/components/progress.tsx +158 -0
- package/src/components/radio-group.tsx +136 -0
- package/src/components/resource-list.tsx +686 -0
- package/src/components/search.tsx +127 -0
- package/src/components/select.tsx +456 -0
- package/src/components/separator.tsx +93 -0
- package/src/components/skeleton-box.tsx +63 -0
- package/src/components/skeleton-text.tsx +66 -0
- package/src/components/spinner.tsx +83 -0
- package/src/components/stack.tsx +86 -0
- package/src/components/status-indicator.tsx +31 -0
- package/src/components/switch.tsx +90 -0
- package/src/components/table.tsx +242 -0
- package/src/components/tabs.tsx +147 -0
- package/src/components/tag.tsx +169 -0
- package/src/components/text.tsx +126 -0
- package/src/components/textarea.tsx +130 -0
- package/src/components/theme-provider.tsx +115 -0
- package/src/components/thumbnail.tsx +250 -0
- package/src/components/time-input.tsx +123 -0
- package/src/components/toast.tsx +217 -0
- package/src/components/toggle-group.tsx +124 -0
- package/src/components/toolbar.tsx +105 -0
- package/src/components/tooltip.tsx +97 -0
- package/src/components/tree-navigation.tsx +194 -0
- package/src/components/tree-view.tsx +292 -0
- package/src/flip.ts +12 -0
- package/src/index.ts +317 -0
- package/src/lib/date-mask.ts +176 -0
- package/src/lib/field-context.ts +86 -0
- package/src/lib/flip-app-script.ts +38 -0
- package/src/lib/flip-host.ts +84 -0
- package/src/lib/flip-theme-css.ts +90 -0
- package/src/lib/focus.ts +18 -0
- package/src/lib/glyphs.ts +137 -0
- package/src/lib/spacing.ts +93 -0
- package/src/lib/theme-context.ts +27 -0
- package/src/lib/theme-script.ts +49 -0
- package/src/lib/use-mobile.ts +17 -0
- package/src/lib/utils.ts +28 -0
- package/src/server.ts +20 -0
- package/src/styles/fonts/Inter-italic.var.woff2 +0 -0
- package/src/styles/fonts/Inter.var.woff2 +0 -0
- package/src/styles/fonts/OFL.txt +96 -0
- package/src/styles/theme.css +146 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
import { cn } from "../lib/utils";
|
|
4
|
+
import { setNativeValue, useFieldText, type FieldContextValue } from "../lib/field-context";
|
|
5
|
+
import { Glyph } from "../lib/glyphs";
|
|
6
|
+
|
|
7
|
+
export const inputVariants = cva(
|
|
8
|
+
[
|
|
9
|
+
"flex w-full min-w-0 bg-surface text-foreground",
|
|
10
|
+
"outline-1 -outline-offset-1 outline-border-strong",
|
|
11
|
+
"placeholder:text-subdued",
|
|
12
|
+
"transition-[outline-color,background-color]",
|
|
13
|
+
"hover:outline-border-strong",
|
|
14
|
+
"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-focus",
|
|
15
|
+
"disabled:cursor-default disabled:bg-surface-raised disabled:text-disabled disabled:outline-border",
|
|
16
|
+
"aria-invalid:outline-border-critical aria-invalid:focus-visible:outline-border-critical",
|
|
17
|
+
// Swirl matches the native control to the page theme.
|
|
18
|
+
"[color-scheme:inherit]",
|
|
19
|
+
],
|
|
20
|
+
{
|
|
21
|
+
variants: {
|
|
22
|
+
size: {
|
|
23
|
+
s: "min-h-7 rounded-sm px-2 py-1 text-sm leading-5",
|
|
24
|
+
// Swirl's text is 16/24 on touch screens and 14/20 on desktop.
|
|
25
|
+
m: "min-h-10 rounded-base px-3 py-2 text-base leading-6 desktop:min-h-[2.375rem] desktop:text-sm desktop:leading-5",
|
|
26
|
+
l: "min-h-12 rounded-base px-4 py-3 text-base leading-6",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: { size: "m" },
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
/** shadcn's `size` spellings, mapped onto Swirl's scale. */
|
|
34
|
+
const shadcnSizes = { sm: "s", default: "m", lg: "l" } as const;
|
|
35
|
+
|
|
36
|
+
/** Text size of a control inside a field, following the field's `fontSize`. */
|
|
37
|
+
export function fieldTextSize(field: FieldContextValue) {
|
|
38
|
+
return field.fontSize === "sm"
|
|
39
|
+
? "text-sm leading-5"
|
|
40
|
+
: field.fontSize === "base"
|
|
41
|
+
? "text-base leading-6"
|
|
42
|
+
: "text-base leading-6 desktop:text-sm desktop:leading-5";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The classes a text control gets inside a field: no box, just text. */
|
|
46
|
+
export function bareFieldControl(field: FieldContextValue) {
|
|
47
|
+
return cn(
|
|
48
|
+
"w-full min-w-0 border-0 bg-transparent p-0 text-foreground outline-none caret-border-highlight",
|
|
49
|
+
"placeholder:text-subdued disabled:cursor-default disabled:text-subdued",
|
|
50
|
+
fieldTextSize(field),
|
|
51
|
+
// While the label stands in for it, the control's own placeholder hides.
|
|
52
|
+
field.labelAsPlaceholder && "placeholder:text-transparent",
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
const iconButton = cn(
|
|
58
|
+
"inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-xs border-0 bg-transparent p-0",
|
|
59
|
+
"text-icon-default outline-focus focus:not-focus-visible:outline-none focus-visible:outline-2",
|
|
60
|
+
"desktop:size-5 [&>svg]:size-full",
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export interface InputProps
|
|
64
|
+
extends Omit<React.ComponentProps<"input">, "size" | "prefix">,
|
|
65
|
+
Omit<VariantProps<typeof inputVariants>, "size"> {
|
|
66
|
+
/** Standalone size. Inside a `FormControl` the field sets the size. */
|
|
67
|
+
size?: "s" | "m" | "l" | keyof typeof shadcnSizes;
|
|
68
|
+
/** An element before the text, such as an icon. */
|
|
69
|
+
prefix?: React.ReactNode;
|
|
70
|
+
/** An element after the text. */
|
|
71
|
+
suffix?: React.ReactNode;
|
|
72
|
+
/** Quiet text before the value, such as a currency sign. */
|
|
73
|
+
prefixLabel?: string;
|
|
74
|
+
/** Quiet text after the value, such as a unit. It sits right after the text. */
|
|
75
|
+
suffixLabel?: string;
|
|
76
|
+
/** Show a button that clears the value. Not for password or number fields. */
|
|
77
|
+
clearable?: boolean;
|
|
78
|
+
clearButtonLabel?: string;
|
|
79
|
+
/** Called after the clear button empties the field. */
|
|
80
|
+
onClear?: () => void;
|
|
81
|
+
/** Accessible name of the show/hide button on a password field. */
|
|
82
|
+
passwordToggleLabel?: string;
|
|
83
|
+
/** Show "used / max" characters. Use with `maxLength`. */
|
|
84
|
+
showCharacterCounter?: boolean;
|
|
85
|
+
/** Only show the counter from 80% of `maxLength`. */
|
|
86
|
+
showCharacterCounterNearLimit?: boolean;
|
|
87
|
+
characterCounterLabel?: string;
|
|
88
|
+
/** Select the whole value on focus. */
|
|
89
|
+
autoSelect?: boolean;
|
|
90
|
+
/** Wrapper class, used when the input has a box around extras. */
|
|
91
|
+
wrapperClassName?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Swirl's text input. Inside a `FormControl` it renders bare, and the field
|
|
96
|
+
* draws the box and label; on its own it has a box of its own.
|
|
97
|
+
*
|
|
98
|
+
* It covers Swirl's text-input extras: `clearable`, a show/hide toggle on
|
|
99
|
+
* password fields, a stepper on number fields, a character counter, and
|
|
100
|
+
* prefix and suffix labels.
|
|
101
|
+
*/
|
|
102
|
+
export function Input({
|
|
103
|
+
className,
|
|
104
|
+
wrapperClassName,
|
|
105
|
+
size,
|
|
106
|
+
type = "text",
|
|
107
|
+
prefix,
|
|
108
|
+
suffix,
|
|
109
|
+
prefixLabel,
|
|
110
|
+
suffixLabel,
|
|
111
|
+
clearable = false,
|
|
112
|
+
clearButtonLabel = "Clear input",
|
|
113
|
+
onClear,
|
|
114
|
+
passwordToggleLabel = "Toggle password display",
|
|
115
|
+
showCharacterCounter = false,
|
|
116
|
+
showCharacterCounterNearLimit = false,
|
|
117
|
+
characterCounterLabel = "Used characters",
|
|
118
|
+
autoSelect = false,
|
|
119
|
+
value,
|
|
120
|
+
defaultValue,
|
|
121
|
+
onChange,
|
|
122
|
+
onFocus,
|
|
123
|
+
onKeyDown,
|
|
124
|
+
placeholder,
|
|
125
|
+
maxLength,
|
|
126
|
+
disabled,
|
|
127
|
+
readOnly,
|
|
128
|
+
ref,
|
|
129
|
+
id,
|
|
130
|
+
...props
|
|
131
|
+
}: InputProps) {
|
|
132
|
+
const { field, text, handleChange } = useFieldText<HTMLInputElement>(value, defaultValue, onChange);
|
|
133
|
+
const generatedId = React.useId();
|
|
134
|
+
const inputId = id ?? field?.id ?? generatedId;
|
|
135
|
+
// The buttons find the input by id, so the caller's `ref` passes straight through.
|
|
136
|
+
const getInput = () => document.getElementById(inputId) as HTMLInputElement | null;
|
|
137
|
+
const [revealed, setRevealed] = React.useState(false);
|
|
138
|
+
|
|
139
|
+
const setHasPlaceholder = field?.setHasPlaceholder;
|
|
140
|
+
const setHasCounter = field?.setHasCounter;
|
|
141
|
+
React.useEffect(() => {
|
|
142
|
+
setHasPlaceholder?.(Boolean(placeholder));
|
|
143
|
+
}, [setHasPlaceholder, placeholder]);
|
|
144
|
+
React.useEffect(() => {
|
|
145
|
+
setHasCounter?.(showCharacterCounter);
|
|
146
|
+
}, [setHasCounter, showCharacterCounter]);
|
|
147
|
+
|
|
148
|
+
const isDisabled = disabled ?? field?.disabled;
|
|
149
|
+
const isReadOnly = readOnly ?? field?.readOnly;
|
|
150
|
+
const password = type === "password";
|
|
151
|
+
const number = type === "number";
|
|
152
|
+
const interactive = !isDisabled && !isReadOnly;
|
|
153
|
+
|
|
154
|
+
const showClear = clearable && text !== "" && interactive && !password && !number;
|
|
155
|
+
const showCounter =
|
|
156
|
+
showCharacterCounter &&
|
|
157
|
+
(!showCharacterCounterNearLimit || (maxLength != null && text.length >= maxLength * 0.8));
|
|
158
|
+
const trailing = showClear || password || number;
|
|
159
|
+
|
|
160
|
+
const clear = () => {
|
|
161
|
+
const input = getInput();
|
|
162
|
+
if (!input) return;
|
|
163
|
+
setNativeValue(input, "");
|
|
164
|
+
input.focus();
|
|
165
|
+
onClear?.();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const step = (direction: 1 | -1) => {
|
|
169
|
+
const input = getInput();
|
|
170
|
+
if (!input || !interactive) return;
|
|
171
|
+
if (direction === 1) input.stepUp();
|
|
172
|
+
else input.stepDown();
|
|
173
|
+
setNativeValue(input, input.value);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const inputProps: React.ComponentProps<"input"> = {
|
|
177
|
+
...props,
|
|
178
|
+
ref,
|
|
179
|
+
id: inputId,
|
|
180
|
+
type: password && revealed ? "text" : type,
|
|
181
|
+
value,
|
|
182
|
+
defaultValue,
|
|
183
|
+
placeholder,
|
|
184
|
+
maxLength,
|
|
185
|
+
disabled: isDisabled,
|
|
186
|
+
readOnly: isReadOnly,
|
|
187
|
+
required: props.required ?? (field?.required || undefined),
|
|
188
|
+
"aria-describedby": props["aria-describedby"] ?? field?.describedBy,
|
|
189
|
+
"aria-invalid": props["aria-invalid"] ?? (field?.invalid || undefined),
|
|
190
|
+
onChange: handleChange,
|
|
191
|
+
onFocus: (event) => {
|
|
192
|
+
onFocus?.(event);
|
|
193
|
+
if (autoSelect) event.currentTarget.select();
|
|
194
|
+
},
|
|
195
|
+
onKeyDown: (event) => {
|
|
196
|
+
onKeyDown?.(event);
|
|
197
|
+
// As in Swirl, a number field takes digits only: no signs or exponents.
|
|
198
|
+
if (number && ["+", "-", "e", "E"].includes(event.key)) event.preventDefault();
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const numberClasses =
|
|
203
|
+
number &&
|
|
204
|
+
"[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none";
|
|
205
|
+
|
|
206
|
+
const clearButton = showClear && (
|
|
207
|
+
<button type="button" aria-label={clearButtonLabel} className={iconButton} onClick={clear}>
|
|
208
|
+
<Glyph name="cancel" />
|
|
209
|
+
</button>
|
|
210
|
+
);
|
|
211
|
+
const passwordButton = password && (
|
|
212
|
+
<button
|
|
213
|
+
type="button"
|
|
214
|
+
aria-label={passwordToggleLabel}
|
|
215
|
+
aria-pressed={revealed}
|
|
216
|
+
disabled={isDisabled}
|
|
217
|
+
className={iconButton}
|
|
218
|
+
onClick={() => setRevealed((shown) => !shown)}
|
|
219
|
+
>
|
|
220
|
+
<Glyph name={revealed ? "visibilityOff" : "visibility"} />
|
|
221
|
+
</button>
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const counter = showCounter && (
|
|
225
|
+
<span aria-live="polite" className="shrink-0 text-sm leading-5 text-subdued tabular-nums">
|
|
226
|
+
<span className="sr-only">{characterCounterLabel}</span>
|
|
227
|
+
{text.length}
|
|
228
|
+
{maxLength != null ? ` / ${maxLength}` : ""}
|
|
229
|
+
</span>
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
/* ------------------------------------------------------- inside a field */
|
|
233
|
+
|
|
234
|
+
if (field) {
|
|
235
|
+
const compact = field.inline || field.labelPosition === "outside";
|
|
236
|
+
const textSize = fieldTextSize(field);
|
|
237
|
+
// While the label sits in the empty box, Swirl hides everything else in it.
|
|
238
|
+
const collapsed = !compact && field.labelAsPlaceholder;
|
|
239
|
+
return (
|
|
240
|
+
// Room for the buttons Swirl centres on the right of a tall field. It sits
|
|
241
|
+
// on the row, not the input, so a suffix label can still hug the text.
|
|
242
|
+
<div className={cn("flex w-full items-center", trailing && !compact && "pr-8")}>
|
|
243
|
+
{prefix && <span className="mr-2 flex shrink-0 items-center text-subdued">{prefix}</span>}
|
|
244
|
+
{prefixLabel && <span className={cn("shrink-0 pr-1 text-subdued", textSize)}>{prefixLabel}</span>}
|
|
245
|
+
<input
|
|
246
|
+
{...inputProps}
|
|
247
|
+
className={cn(
|
|
248
|
+
bareFieldControl(field),
|
|
249
|
+
suffixLabel && !password && !placeholder && "w-auto grow-0 field-sizing-content",
|
|
250
|
+
number && compact && "pr-9",
|
|
251
|
+
numberClasses,
|
|
252
|
+
className,
|
|
253
|
+
)}
|
|
254
|
+
/>
|
|
255
|
+
{suffixLabel && <span className={cn("shrink-0 pl-1 text-subdued", textSize)}>{suffixLabel}</span>}
|
|
256
|
+
{suffix && <span className="ml-2 flex shrink-0 items-center text-subdued">{suffix}</span>}
|
|
257
|
+
|
|
258
|
+
{/* Swirl centres the buttons in a tall field, and keeps them in line in a compact one. */}
|
|
259
|
+
{(showClear || password) && (
|
|
260
|
+
<span
|
|
261
|
+
className={cn(
|
|
262
|
+
"flex items-center gap-1",
|
|
263
|
+
compact ? "ml-2" : "absolute top-1/2 right-4 -translate-y-1/2",
|
|
264
|
+
collapsed && "invisible",
|
|
265
|
+
)}
|
|
266
|
+
>
|
|
267
|
+
{clearButton}
|
|
268
|
+
{passwordButton}
|
|
269
|
+
</span>
|
|
270
|
+
)}
|
|
271
|
+
{number && (
|
|
272
|
+
<Stepper
|
|
273
|
+
compact={compact}
|
|
274
|
+
disabled={!interactive}
|
|
275
|
+
onStep={step}
|
|
276
|
+
className={cn(
|
|
277
|
+
compact ? "absolute inset-y-0 right-0" : "absolute top-1/2 right-4 -translate-y-1/2",
|
|
278
|
+
collapsed && "invisible",
|
|
279
|
+
)}
|
|
280
|
+
/>
|
|
281
|
+
)}
|
|
282
|
+
{counter && (
|
|
283
|
+
<span
|
|
284
|
+
className={cn(
|
|
285
|
+
"absolute right-0 flex",
|
|
286
|
+
// Tall field: on the label's row. Compact: under the box.
|
|
287
|
+
compact ? "top-full mt-1" : "top-3 right-4",
|
|
288
|
+
collapsed && "invisible",
|
|
289
|
+
)}
|
|
290
|
+
>
|
|
291
|
+
{counter}
|
|
292
|
+
</span>
|
|
293
|
+
)}
|
|
294
|
+
</div>
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/* ---------------------------------------------------------- standalone */
|
|
299
|
+
|
|
300
|
+
const resolvedSize = (size && size in shadcnSizes
|
|
301
|
+
? shadcnSizes[size as keyof typeof shadcnSizes]
|
|
302
|
+
: (size ?? "m")) as "s" | "m" | "l";
|
|
303
|
+
|
|
304
|
+
if (!prefix && !suffix && !prefixLabel && !suffixLabel && !trailing && !counter) {
|
|
305
|
+
return (
|
|
306
|
+
<input {...inputProps} className={cn(inputVariants({ size: resolvedSize }), numberClasses, className)} />
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<div
|
|
312
|
+
className={cn(
|
|
313
|
+
inputVariants({ size: resolvedSize }),
|
|
314
|
+
"relative items-center gap-2",
|
|
315
|
+
// The ring belongs to the wrapper now; mirror the input's own states.
|
|
316
|
+
"focus-within:outline-2 focus-within:-outline-offset-2 focus-within:outline-focus",
|
|
317
|
+
"has-disabled:bg-surface-raised has-disabled:text-disabled has-disabled:outline-border",
|
|
318
|
+
"has-aria-invalid:outline-border-critical",
|
|
319
|
+
number && "pr-9",
|
|
320
|
+
wrapperClassName,
|
|
321
|
+
)}
|
|
322
|
+
>
|
|
323
|
+
{prefix && <span className="flex shrink-0 items-center text-subdued">{prefix}</span>}
|
|
324
|
+
{prefixLabel && <span className="shrink-0 text-subdued">{prefixLabel}</span>}
|
|
325
|
+
<input
|
|
326
|
+
{...inputProps}
|
|
327
|
+
className={cn(
|
|
328
|
+
"min-w-0 flex-1 border-0 bg-transparent p-0 text-inherit outline-none placeholder:text-subdued",
|
|
329
|
+
"disabled:cursor-default disabled:text-disabled",
|
|
330
|
+
suffixLabel && !password && !placeholder && "flex-none field-sizing-content",
|
|
331
|
+
numberClasses,
|
|
332
|
+
className,
|
|
333
|
+
)}
|
|
334
|
+
/>
|
|
335
|
+
{suffixLabel && <span className="shrink-0 text-subdued">{suffixLabel}</span>}
|
|
336
|
+
{suffix && <span className="flex shrink-0 items-center text-subdued">{suffix}</span>}
|
|
337
|
+
{clearButton}
|
|
338
|
+
{passwordButton}
|
|
339
|
+
{counter}
|
|
340
|
+
{number && (
|
|
341
|
+
<Stepper compact disabled={!interactive} onStep={step} className="absolute inset-y-0 right-0" />
|
|
342
|
+
)}
|
|
343
|
+
</div>
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Swirl's number stepper. Hidden from assistive tech and out of the tab
|
|
349
|
+
* order, as in Swirl: the arrow keys already step a number field.
|
|
350
|
+
*/
|
|
351
|
+
function Stepper({
|
|
352
|
+
compact,
|
|
353
|
+
disabled,
|
|
354
|
+
onStep,
|
|
355
|
+
className,
|
|
356
|
+
}: {
|
|
357
|
+
compact: boolean;
|
|
358
|
+
disabled: boolean;
|
|
359
|
+
onStep: (direction: 1 | -1) => void;
|
|
360
|
+
className?: string;
|
|
361
|
+
}) {
|
|
362
|
+
const button = (direction: 1 | -1) => (
|
|
363
|
+
<button
|
|
364
|
+
type="button"
|
|
365
|
+
tabIndex={-1}
|
|
366
|
+
disabled={disabled}
|
|
367
|
+
// Keep focus in the input while stepping.
|
|
368
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
369
|
+
onClick={() => onStep(direction)}
|
|
370
|
+
className={cn(
|
|
371
|
+
"inline-flex cursor-pointer items-center justify-center border-0 p-0 text-icon-default disabled:cursor-default disabled:text-disabled",
|
|
372
|
+
compact
|
|
373
|
+
? [
|
|
374
|
+
"h-1/2 w-8 bg-surface-raised not-disabled:hover:bg-surface-raised-hovered [&>svg]:size-5",
|
|
375
|
+
direction === 1 ? "rounded-tr-sm" : "rounded-br-sm",
|
|
376
|
+
]
|
|
377
|
+
: "size-6 bg-transparent desktop:size-5 [&>svg]:size-full",
|
|
378
|
+
)}
|
|
379
|
+
>
|
|
380
|
+
<Glyph name={direction === 1 ? "expandLess" : "expandMore"} />
|
|
381
|
+
</button>
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
return (
|
|
385
|
+
<span aria-hidden className={cn("flex flex-col", className)}>
|
|
386
|
+
{button(1)}
|
|
387
|
+
{button(-1)}
|
|
388
|
+
</span>
|
|
389
|
+
);
|
|
390
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Label as LabelPrimitive } from "radix-ui";
|
|
2
|
+
import { cn } from "../lib/utils";
|
|
3
|
+
|
|
4
|
+
export interface LabelProps extends React.ComponentProps<typeof LabelPrimitive.Root> {
|
|
5
|
+
/** Append Swirl's required marker. */
|
|
6
|
+
required?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function Label({ className, required, children, ...props }: LabelProps) {
|
|
10
|
+
return (
|
|
11
|
+
<LabelPrimitive.Root
|
|
12
|
+
className={cn(
|
|
13
|
+
"text-sm font-medium leading-5 text-foreground select-none",
|
|
14
|
+
// Radix sets data-disabled on the label when its control is disabled.
|
|
15
|
+
"peer-disabled:text-disabled data-disabled:text-disabled",
|
|
16
|
+
className,
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
>
|
|
20
|
+
{children}
|
|
21
|
+
{required && (
|
|
22
|
+
<span className="ml-0.5 text-critical" aria-hidden>
|
|
23
|
+
*
|
|
24
|
+
</span>
|
|
25
|
+
)}
|
|
26
|
+
</LabelPrimitive.Root>
|
|
27
|
+
);
|
|
28
|
+
}
|