@carbonbits/sixr 1.3.0 → 1.4.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.
Files changed (42) hide show
  1. package/README.md +77 -18
  2. package/dist/chunk-NZHHNVXZ.js +118 -0
  3. package/dist/chunk-NZHHNVXZ.js.map +1 -0
  4. package/dist/email-input.cjs +390 -0
  5. package/dist/email-input.cjs.map +1 -0
  6. package/dist/email-input.d.cts +14 -0
  7. package/dist/email-input.d.ts +14 -0
  8. package/dist/email-input.js +367 -0
  9. package/dist/email-input.js.map +1 -0
  10. package/dist/index-DwjxC4l4.d.cts +62 -0
  11. package/dist/index-DwjxC4l4.d.ts +62 -0
  12. package/dist/index.cjs +112 -0
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +48 -9
  15. package/dist/index.d.ts +48 -9
  16. package/dist/index.js +1 -0
  17. package/dist/password-input.cjs +406 -0
  18. package/dist/password-input.cjs.map +1 -0
  19. package/dist/password-input.d.cts +20 -0
  20. package/dist/password-input.d.ts +20 -0
  21. package/dist/password-input.js +385 -0
  22. package/dist/password-input.js.map +1 -0
  23. package/dist/phone-input.cjs +386 -0
  24. package/dist/phone-input.cjs.map +1 -0
  25. package/dist/phone-input.d.cts +12 -0
  26. package/dist/phone-input.d.ts +12 -0
  27. package/dist/phone-input.js +363 -0
  28. package/dist/phone-input.js.map +1 -0
  29. package/dist/styles.css +1 -1
  30. package/dist/text-input.cjs +228 -59
  31. package/dist/text-input.cjs.map +1 -1
  32. package/dist/text-input.d.cts +10 -58
  33. package/dist/text-input.d.ts +10 -58
  34. package/dist/text-input.js +226 -60
  35. package/dist/text-input.js.map +1 -1
  36. package/dist/typography.cjs +120 -0
  37. package/dist/typography.cjs.map +1 -0
  38. package/dist/typography.d.cts +46 -0
  39. package/dist/typography.d.ts +46 -0
  40. package/dist/typography.js +3 -0
  41. package/dist/typography.js.map +1 -0
  42. package/package.json +45 -1
@@ -0,0 +1,385 @@
1
+ "use client";
2
+ "use client";
3
+
4
+ // src/components/password-input/index.tsx
5
+ import { useCallback as useCallback2, useState as useState2 } from "react";
6
+
7
+ // src/components/field/index.tsx
8
+ import { Label } from "@radix-ui/react-label";
9
+ import { useId } from "react";
10
+
11
+ // src/components/field/use-field-behaviour.ts
12
+ import {
13
+ useCallback,
14
+ useState
15
+ } from "react";
16
+ var FALLBACK_MESSAGE = "Invalid value";
17
+ function runSchema(schema, value) {
18
+ if (!schema) {
19
+ return { valid: true };
20
+ }
21
+ const result = schema.safeParse(value);
22
+ if (result.success) {
23
+ return { valid: true };
24
+ }
25
+ return {
26
+ valid: false,
27
+ error: result.error.issues[0]?.message ?? FALLBACK_MESSAGE
28
+ };
29
+ }
30
+ function useFieldBehaviour({
31
+ value,
32
+ defaultValue,
33
+ error,
34
+ onChange,
35
+ onBlur,
36
+ schema,
37
+ validateOn = "blur",
38
+ onValidationChange
39
+ }) {
40
+ const [uncontrolledValue, setUncontrolledValue] = useState(
41
+ defaultValue ?? ""
42
+ );
43
+ const [schemaError, setSchemaError] = useState(void 0);
44
+ const isControlled = value !== void 0;
45
+ const validate = useCallback(
46
+ (next) => {
47
+ const state = runSchema(schema, next);
48
+ setSchemaError(state.error);
49
+ onValidationChange?.(state);
50
+ },
51
+ [schema, onValidationChange]
52
+ );
53
+ const handleChange = useCallback(
54
+ (event) => {
55
+ const next = event.target.value;
56
+ if (!isControlled) {
57
+ setUncontrolledValue(next);
58
+ }
59
+ onChange?.(next);
60
+ if (validateOn === "change" || validateOn === "blur" && schemaError) {
61
+ validate(next);
62
+ }
63
+ },
64
+ [isControlled, onChange, validateOn, schemaError, validate]
65
+ );
66
+ const handleBlur = useCallback(
67
+ (event) => {
68
+ if (validateOn === "blur") {
69
+ validate(event.target.value);
70
+ }
71
+ onBlur?.(event);
72
+ },
73
+ [validateOn, validate, onBlur]
74
+ );
75
+ return {
76
+ currentValue: isControlled ? value : uncontrolledValue,
77
+ // A caller-supplied error outranks the schema's verdict.
78
+ shownError: error ?? schemaError,
79
+ handleChange,
80
+ handleBlur
81
+ };
82
+ }
83
+
84
+ // src/components/typography/index.tsx
85
+ import { Slot } from "@radix-ui/react-slot";
86
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
87
+ var DEFAULT_ELEMENT = {
88
+ display: "h1",
89
+ heading: "h2",
90
+ subheading: "h3",
91
+ body: "p",
92
+ label: "span",
93
+ hint: "p",
94
+ code: "code"
95
+ };
96
+ var DEFAULT_WEIGHT = {
97
+ display: "semibold",
98
+ heading: "semibold",
99
+ subheading: "medium",
100
+ body: "regular",
101
+ label: "semibold",
102
+ hint: "regular",
103
+ code: "regular"
104
+ };
105
+ var VARIANT_CLASSES = {
106
+ display: "text-display leading-tight tracking-tight",
107
+ heading: "text-heading leading-tight tracking-tight",
108
+ subheading: "text-subheading leading-snug",
109
+ body: "text-field leading-normal",
110
+ label: "text-label leading-normal",
111
+ hint: "text-hint leading-normal",
112
+ code: "font-code text-field leading-normal"
113
+ };
114
+ var TONE_CLASSES = {
115
+ default: "text-fg",
116
+ muted: "text-fg-muted",
117
+ subtle: "text-fg-subtle",
118
+ accent: "text-accent",
119
+ "on-accent": "text-on-accent",
120
+ success: "text-success",
121
+ warning: "text-warning",
122
+ info: "text-info",
123
+ danger: "text-danger"
124
+ };
125
+ var WEIGHT_CLASSES = {
126
+ regular: "font-normal",
127
+ medium: "font-medium",
128
+ semibold: "font-semibold",
129
+ bold: "font-bold"
130
+ };
131
+ var ALIGN_CLASSES = {
132
+ start: "text-start",
133
+ center: "text-center",
134
+ end: "text-end"
135
+ };
136
+ var ICON_CLASSES = "inline-flex shrink-0 items-center [&>svg]:h-[1em] [&>svg]:w-[1em]";
137
+ function typographyClassName({
138
+ variant,
139
+ tone,
140
+ weight,
141
+ align,
142
+ truncate,
143
+ hasIcon,
144
+ className
145
+ }) {
146
+ return [
147
+ VARIANT_CLASSES[variant],
148
+ TONE_CLASSES[tone],
149
+ WEIGHT_CLASSES[weight],
150
+ align ? ALIGN_CLASSES[align] : "",
151
+ hasIcon ? "inline-flex items-center gap-1.5" : "",
152
+ // With an icon the root is a flex container, and text-overflow only
153
+ // clips block text, so the text span carries the truncation instead.
154
+ truncate && !hasIcon ? "truncate" : "",
155
+ className ?? ""
156
+ ].filter(Boolean).join(" ");
157
+ }
158
+ function Typography({
159
+ variant = "body",
160
+ tone = "default",
161
+ weight,
162
+ align,
163
+ truncate = false,
164
+ icon,
165
+ iconPosition = "leading",
166
+ as,
167
+ asChild = false,
168
+ className,
169
+ children,
170
+ ...rest
171
+ }) {
172
+ const hasIcon = icon !== void 0 && icon !== null;
173
+ const Component = asChild ? Slot : as ?? DEFAULT_ELEMENT[variant];
174
+ const iconNode = hasIcon ? /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: ICON_CLASSES, children: icon }) : null;
175
+ const content = hasIcon ? /* @__PURE__ */ jsxs(Fragment, { children: [
176
+ iconPosition === "leading" ? iconNode : null,
177
+ /* @__PURE__ */ jsx("span", { className: truncate ? "min-w-0 truncate" : void 0, children }),
178
+ iconPosition === "trailing" ? iconNode : null
179
+ ] }) : children;
180
+ return /* @__PURE__ */ jsx(
181
+ Component,
182
+ {
183
+ ...rest,
184
+ className: typographyClassName({
185
+ variant,
186
+ tone,
187
+ weight: weight ?? DEFAULT_WEIGHT[variant],
188
+ align,
189
+ truncate,
190
+ hasIcon,
191
+ className
192
+ }),
193
+ children: content
194
+ }
195
+ );
196
+ }
197
+
198
+ // src/components/field/index.tsx
199
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
200
+ var FIELD_CLASSES = "h-10 w-full rounded-field border bg-surface px-3 font-[inherit] text-field text-fg outline-none placeholder:text-fg-subtle disabled:cursor-not-allowed disabled:opacity-45";
201
+ var VALID_CLASSES = "border-line focus:border-accent focus:ring-3 focus:ring-accent-soft";
202
+ var INVALID_CLASSES = "border-danger focus:border-danger focus:ring-3 focus:ring-danger-soft";
203
+ function fieldClassName(invalid, hasTrailing, className) {
204
+ return [
205
+ FIELD_CLASSES,
206
+ invalid ? INVALID_CLASSES : VALID_CLASSES,
207
+ hasTrailing ? "pr-16" : "",
208
+ className ?? ""
209
+ ].filter(Boolean).join(" ");
210
+ }
211
+ function FieldLabel({
212
+ htmlFor,
213
+ label,
214
+ optional,
215
+ action
216
+ }) {
217
+ if (!label) {
218
+ return null;
219
+ }
220
+ return /* @__PURE__ */ jsx2(
221
+ Typography,
222
+ {
223
+ variant: "label",
224
+ tone: "muted",
225
+ className: "mb-1.5 flex items-center",
226
+ asChild: true,
227
+ children: /* @__PURE__ */ jsxs2(Label, { htmlFor, children: [
228
+ label,
229
+ optional ? /* @__PURE__ */ jsx2(
230
+ Typography,
231
+ {
232
+ as: "span",
233
+ variant: "hint",
234
+ tone: "subtle",
235
+ weight: "semibold",
236
+ className: "ml-auto",
237
+ children: "Optional"
238
+ }
239
+ ) : null,
240
+ action ? /* @__PURE__ */ jsx2("span", { className: "ml-auto", children: action }) : null
241
+ ] })
242
+ }
243
+ );
244
+ }
245
+ function FieldMessage({
246
+ id,
247
+ error,
248
+ hint
249
+ }) {
250
+ if (error) {
251
+ return /* @__PURE__ */ jsx2(
252
+ Typography,
253
+ {
254
+ as: "p",
255
+ variant: "hint",
256
+ tone: "danger",
257
+ id,
258
+ role: "alert",
259
+ className: "mt-1.5",
260
+ children: error
261
+ }
262
+ );
263
+ }
264
+ if (hint) {
265
+ return /* @__PURE__ */ jsx2(
266
+ Typography,
267
+ {
268
+ as: "p",
269
+ variant: "hint",
270
+ tone: "subtle",
271
+ id,
272
+ className: "mt-1.5",
273
+ children: hint
274
+ }
275
+ );
276
+ }
277
+ return null;
278
+ }
279
+ function Field({
280
+ label,
281
+ hint,
282
+ error,
283
+ optional = false,
284
+ action,
285
+ trailing,
286
+ type,
287
+ value,
288
+ defaultValue,
289
+ onChange,
290
+ schema,
291
+ validateOn = "blur",
292
+ onValidationChange,
293
+ id,
294
+ className,
295
+ onBlur,
296
+ ...rest
297
+ }) {
298
+ const generatedId = useId();
299
+ const inputId = id ?? generatedId;
300
+ const describedById = `${inputId}-description`;
301
+ const { currentValue, shownError, handleChange, handleBlur } = useFieldBehaviour({
302
+ value,
303
+ defaultValue,
304
+ error,
305
+ onChange,
306
+ onBlur,
307
+ schema,
308
+ validateOn,
309
+ onValidationChange
310
+ });
311
+ return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col", children: [
312
+ /* @__PURE__ */ jsx2(
313
+ FieldLabel,
314
+ {
315
+ htmlFor: inputId,
316
+ label,
317
+ optional,
318
+ action
319
+ }
320
+ ),
321
+ /* @__PURE__ */ jsxs2("div", { className: trailing ? "relative" : void 0, children: [
322
+ /* @__PURE__ */ jsx2(
323
+ "input",
324
+ {
325
+ ...rest,
326
+ id: inputId,
327
+ type,
328
+ value: currentValue,
329
+ "aria-invalid": shownError ? true : void 0,
330
+ "aria-describedby": shownError || hint ? describedById : void 0,
331
+ onChange: handleChange,
332
+ onBlur: handleBlur,
333
+ className: fieldClassName(
334
+ Boolean(shownError),
335
+ Boolean(trailing),
336
+ className
337
+ )
338
+ }
339
+ ),
340
+ trailing ? /* @__PURE__ */ jsx2("span", { className: "absolute top-1/2 right-[9px] flex -translate-y-1/2 items-center text-hint font-semibold text-fg-subtle", children: trailing }) : null
341
+ ] }),
342
+ /* @__PURE__ */ jsx2(FieldMessage, { id: describedById, error: shownError, hint })
343
+ ] });
344
+ }
345
+
346
+ // src/components/password-input/index.tsx
347
+ import { jsx as jsx3 } from "react/jsx-runtime";
348
+ var DEFAULT_REVEAL_LABELS = { show: "Show", hide: "Hide" };
349
+ var TOGGLE_CLASSES = "cursor-pointer rounded-field font-[inherit] text-hint font-semibold text-fg-subtle outline-none hover:text-fg focus-visible:ring-3 focus-visible:ring-accent-soft disabled:cursor-not-allowed";
350
+ function PasswordInput({
351
+ revealable = true,
352
+ revealLabels = DEFAULT_REVEAL_LABELS,
353
+ autoComplete = "current-password",
354
+ ...rest
355
+ }) {
356
+ const [revealed, setRevealed] = useState2(false);
357
+ const toggleRevealed = useCallback2(
358
+ () => setRevealed((current) => !current),
359
+ []
360
+ );
361
+ const toggle = revealable ? /* @__PURE__ */ jsx3(
362
+ "button",
363
+ {
364
+ type: "button",
365
+ "aria-pressed": revealed,
366
+ "aria-label": revealed ? "Hide password" : "Show password",
367
+ className: TOGGLE_CLASSES,
368
+ onClick: toggleRevealed,
369
+ children: revealed ? revealLabels.hide : revealLabels.show
370
+ }
371
+ ) : void 0;
372
+ return /* @__PURE__ */ jsx3(
373
+ Field,
374
+ {
375
+ ...rest,
376
+ type: revealed ? "text" : "password",
377
+ autoComplete,
378
+ trailing: toggle
379
+ }
380
+ );
381
+ }
382
+ export {
383
+ PasswordInput
384
+ };
385
+ //# sourceMappingURL=password-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/password-input/index.tsx","../src/components/field/index.tsx","../src/components/field/use-field-behaviour.ts","../src/components/typography/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\nimport { Field, type FieldProps } from \"@/components/field\";\n\nexport type {\n FieldSchema,\n FieldValidation,\n} from \"@/components/field\";\n\n/**\n * A password. Fixes `type=\"password\"` and owns the design's in-field peek\n * affordance, so the trailing slot is not exposed here — the toggle is it.\n */\nexport type PasswordInputProps = Omit<FieldProps, \"trailing\"> & {\n /** Show the \"Show\"/\"Hide\" toggle. On by default, as the design has it. */\n revealable?: boolean;\n /** Labels for the toggle, for localisation. */\n revealLabels?: { show: string; hide: string };\n};\n\nconst DEFAULT_REVEAL_LABELS = { show: \"Show\", hide: \"Hide\" };\n\nconst TOGGLE_CLASSES =\n \"cursor-pointer rounded-field font-[inherit] text-hint font-semibold text-fg-subtle outline-none hover:text-fg focus-visible:ring-3 focus-visible:ring-accent-soft disabled:cursor-not-allowed\";\n\nexport function PasswordInput({\n revealable = true,\n revealLabels = DEFAULT_REVEAL_LABELS,\n autoComplete = \"current-password\",\n ...rest\n}: PasswordInputProps) {\n const [revealed, setRevealed] = useState(false);\n const toggleRevealed = useCallback(\n () => setRevealed((current) => !current),\n [],\n );\n\n const toggle = revealable ? (\n <button\n type=\"button\"\n aria-pressed={revealed}\n aria-label={revealed ? \"Hide password\" : \"Show password\"}\n className={TOGGLE_CLASSES}\n onClick={toggleRevealed}\n >\n {revealed ? revealLabels.hide : revealLabels.show}\n </button>\n ) : undefined;\n\n return (\n <Field\n {...rest}\n type={revealed ? \"text\" : \"password\"}\n autoComplete={autoComplete}\n trailing={toggle}\n />\n );\n}\n","\"use client\";\n\nimport { Label } from \"@radix-ui/react-label\";\nimport { type InputHTMLAttributes, type ReactNode, useId } from \"react\";\nimport {\n type FieldSchema,\n type FieldValidation,\n useFieldBehaviour,\n} from \"@/components/field/use-field-behaviour\";\nimport { Typography } from \"@/components/typography\";\n\nexport type {\n FieldSchema,\n FieldValidation,\n} from \"@/components/field/use-field-behaviour\";\n\n/**\n * The single-line input behind `TextInput`, `EmailInput`, `PasswordInput` and\n * `PhoneInput`. Each of those fixes the `type` (and the keyboard, autocomplete\n * and validation defaults that go with it) and hands everything else here.\n *\n * Internal: this module has no subpath of its own. Consumers reach it through\n * the specialised inputs, and its shared types through the barrel.\n */\n\nexport type FieldType = \"text\" | \"email\" | \"password\" | \"tel\";\n\n/** Props every specialised input shares. `type` is fixed by the wrapper. */\nexport type FieldProps = Omit<\n InputHTMLAttributes<HTMLInputElement>,\n \"onChange\" | \"value\" | \"defaultValue\" | \"type\"\n> & {\n label?: string;\n /** Guidance under the field. Replaced by the error message while invalid. */\n hint?: ReactNode;\n /**\n * Error supplied by the caller — a server-side or cross-field failure. Takes\n * precedence over the schema, so a form can hold a field invalid regardless\n * of what `schema` makes of the value on its own.\n */\n error?: string;\n /** Renders the design's muted \"Optional\" marker at the end of the label. */\n optional?: boolean;\n /** Trailing label slot, for affordances like the design's \"Forgot?\" link. */\n action?: ReactNode;\n /** Trailing in-field slot, for affordances like the design's password peek. */\n trailing?: ReactNode;\n value?: string;\n defaultValue?: string;\n onChange?: (value: string) => void;\n /**\n * Any zod schema that accepts a string. Only `safeParse` is used, so a\n * refined, transformed or preprocessed schema works as well as a plain one.\n */\n schema?: FieldSchema;\n /**\n * When the schema runs. `blur` — the default — avoids scolding someone\n * mid-keystroke; once a field has gone invalid it revalidates on every\n * keystroke so the message clears as soon as it is fixed.\n */\n validateOn?: \"blur\" | \"change\" | \"never\";\n onValidationChange?: (state: FieldValidation) => void;\n};\n\nconst FIELD_CLASSES =\n \"h-10 w-full rounded-field border bg-surface px-3 font-[inherit] text-field text-fg outline-none placeholder:text-fg-subtle disabled:cursor-not-allowed disabled:opacity-45\";\nconst VALID_CLASSES =\n \"border-line focus:border-accent focus:ring-3 focus:ring-accent-soft\";\nconst INVALID_CLASSES =\n \"border-danger focus:border-danger focus:ring-3 focus:ring-danger-soft\";\nfunction fieldClassName(\n invalid: boolean,\n hasTrailing: boolean,\n className: string | undefined,\n): string {\n return [\n FIELD_CLASSES,\n invalid ? INVALID_CLASSES : VALID_CLASSES,\n hasTrailing ? \"pr-16\" : \"\",\n className ?? \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n}\n\nfunction FieldLabel({\n htmlFor,\n label,\n optional,\n action,\n}: {\n htmlFor: string;\n label: string | undefined;\n optional: boolean;\n action: ReactNode;\n}) {\n if (!label) {\n return null;\n }\n\n return (\n <Typography\n variant=\"label\"\n tone=\"muted\"\n className=\"mb-1.5 flex items-center\"\n asChild\n >\n <Label htmlFor={htmlFor}>\n {label}\n {optional ? (\n <Typography\n as=\"span\"\n variant=\"hint\"\n tone=\"subtle\"\n weight=\"semibold\"\n className=\"ml-auto\"\n >\n Optional\n </Typography>\n ) : null}\n {action ? <span className=\"ml-auto\">{action}</span> : null}\n </Label>\n </Typography>\n );\n}\n\nfunction FieldMessage({\n id,\n error,\n hint,\n}: {\n id: string;\n error: string | undefined;\n hint: ReactNode;\n}) {\n if (error) {\n return (\n <Typography\n as=\"p\"\n variant=\"hint\"\n tone=\"danger\"\n id={id}\n role=\"alert\"\n className=\"mt-1.5\"\n >\n {error}\n </Typography>\n );\n }\n\n if (hint) {\n return (\n <Typography\n as=\"p\"\n variant=\"hint\"\n tone=\"subtle\"\n id={id}\n className=\"mt-1.5\"\n >\n {hint}\n </Typography>\n );\n }\n\n return null;\n}\n\nexport type FieldComponentProps = FieldProps & { type: FieldType };\n\nexport function Field({\n label,\n hint,\n error,\n optional = false,\n action,\n trailing,\n type,\n value,\n defaultValue,\n onChange,\n schema,\n validateOn = \"blur\",\n onValidationChange,\n id,\n className,\n onBlur,\n ...rest\n}: FieldComponentProps) {\n const generatedId = useId();\n const inputId = id ?? generatedId;\n const describedById = `${inputId}-description`;\n\n const { currentValue, shownError, handleChange, handleBlur } =\n useFieldBehaviour({\n value,\n defaultValue,\n error,\n onChange,\n onBlur,\n schema,\n validateOn,\n onValidationChange,\n });\n\n return (\n <div className=\"flex flex-col\">\n <FieldLabel\n htmlFor={inputId}\n label={label}\n optional={optional}\n action={action}\n />\n\n <div className={trailing ? \"relative\" : undefined}>\n <input\n {...rest}\n id={inputId}\n type={type}\n value={currentValue}\n aria-invalid={shownError ? true : undefined}\n aria-describedby={shownError || hint ? describedById : undefined}\n onChange={handleChange}\n onBlur={handleBlur}\n className={fieldClassName(\n Boolean(shownError),\n Boolean(trailing),\n className,\n )}\n />\n {trailing ? (\n <span className=\"absolute top-1/2 right-[9px] flex -translate-y-1/2 items-center text-hint font-semibold text-fg-subtle\">\n {trailing}\n </span>\n ) : null}\n </div>\n\n <FieldMessage id={describedById} error={shownError} hint={hint} />\n </div>\n );\n}\n","import {\n type ChangeEvent,\n type FocusEvent,\n useCallback,\n useState,\n} from \"react\";\n\n/**\n * Structural shape of a zod schema — every zod schema satisfies it, and any\n * version of zod does. Declaring it this way rather than importing `ZodType`\n * keeps zod out of this module's public types, so consumers who only want an\n * input do not have to install zod to typecheck it.\n */\nexport type FieldSchema = {\n safeParse: (\n value: unknown,\n ) =>\n | { success: true }\n | { success: false; error: { issues: readonly { message: string }[] } };\n};\n\n/** Outcome of a single validation pass, handed to `onValidationChange`. */\nexport type FieldValidation = {\n valid: boolean;\n /** First issue reported by the schema, or `undefined` when valid. */\n error?: string;\n};\n\nexport type FieldBehaviour = {\n value?: string;\n defaultValue?: string;\n /** A caller-supplied error. Outranks the schema's verdict. */\n error?: string;\n onChange?: (value: string) => void;\n onBlur?: (event: FocusEvent<HTMLInputElement>) => void;\n schema?: FieldSchema;\n validateOn?: \"blur\" | \"change\" | \"never\";\n onValidationChange?: (state: FieldValidation) => void;\n};\n\nconst FALLBACK_MESSAGE = \"Invalid value\";\n\nfunction runSchema(\n schema: FieldSchema | undefined,\n value: string,\n): FieldValidation {\n if (!schema) {\n return { valid: true };\n }\n\n const result = schema.safeParse(value);\n if (result.success) {\n return { valid: true };\n }\n\n return {\n valid: false,\n error: result.error.issues[0]?.message ?? FALLBACK_MESSAGE,\n };\n}\n\n/**\n * Owns the value (controlled or not), the schema verdict, and when to re-run\n * it. Split out so the `Field` component itself stays markup.\n */\nexport function useFieldBehaviour({\n value,\n defaultValue,\n error,\n onChange,\n onBlur,\n schema,\n validateOn = \"blur\",\n onValidationChange,\n}: FieldBehaviour) {\n const [uncontrolledValue, setUncontrolledValue] = useState(\n defaultValue ?? \"\",\n );\n const [schemaError, setSchemaError] = useState<string | undefined>(undefined);\n\n const isControlled = value !== undefined;\n\n const validate = useCallback(\n (next: string) => {\n const state = runSchema(schema, next);\n setSchemaError(state.error);\n onValidationChange?.(state);\n },\n [schema, onValidationChange],\n );\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n const next = event.target.value;\n if (!isControlled) {\n setUncontrolledValue(next);\n }\n onChange?.(next);\n\n // Revalidate on every keystroke once the field is already invalid, so a\n // corrected value clears the message without waiting for another blur.\n if (validateOn === \"change\" || (validateOn === \"blur\" && schemaError)) {\n validate(next);\n }\n },\n [isControlled, onChange, validateOn, schemaError, validate],\n );\n\n const handleBlur = useCallback(\n (event: FocusEvent<HTMLInputElement>) => {\n if (validateOn === \"blur\") {\n validate(event.target.value);\n }\n onBlur?.(event);\n },\n [validateOn, validate, onBlur],\n );\n\n return {\n currentValue: isControlled ? value : uncontrolledValue,\n // A caller-supplied error outranks the schema's verdict.\n shownError: error ?? schemaError,\n handleChange,\n handleBlur,\n };\n}\n","import { Slot } from \"@radix-ui/react-slot\";\nimport type { ElementType, HTMLAttributes, ReactNode, Ref } from \"react\";\n\n/**\n * The library's type scale. Everything that renders text — field labels, hints,\n * form errors, headings — goes through here, so a size or colour lives in one\n * place and the tokens in `src/styles/index.css` stay the single source of\n * truth for what \"hint\" or \"muted\" means.\n *\n * Server-safe: no state, no handlers, no directive. It composes Radix `Slot`\n * for `asChild`, which is how a consumer puts these styles on their own\n * element (a `next/link`, a Radix `Label`) without an extra wrapper.\n */\n\nexport type TypographyVariant =\n | \"display\"\n | \"heading\"\n | \"subheading\"\n | \"body\"\n | \"label\"\n | \"hint\"\n | \"code\";\n\nexport type TypographyTone =\n | \"default\"\n | \"muted\"\n | \"subtle\"\n | \"accent\"\n | \"on-accent\"\n | \"success\"\n | \"warning\"\n | \"info\"\n | \"danger\";\n\nexport type TypographyWeight = \"regular\" | \"medium\" | \"semibold\" | \"bold\";\n\nexport type TypographyElement =\n | \"p\"\n | \"span\"\n | \"div\"\n | \"h1\"\n | \"h2\"\n | \"h3\"\n | \"h4\"\n | \"h5\"\n | \"h6\"\n | \"label\"\n | \"code\"\n | \"strong\"\n | \"em\"\n | \"small\";\n\nexport type TypographyProps = Omit<HTMLAttributes<HTMLElement>, \"color\"> & {\n /** Size and default element. `body` unless told otherwise. */\n variant?: TypographyVariant;\n /** Colour role, from the design tokens. */\n tone?: TypographyTone;\n /** Overrides the variant's default weight. */\n weight?: TypographyWeight;\n align?: \"start\" | \"center\" | \"end\";\n /** Clip to one line with an ellipsis. */\n truncate?: boolean;\n /**\n * An icon rendered beside the text, hidden from assistive tech. Sized to the\n * text with `1em`, so the same SVG fits every variant.\n */\n icon?: ReactNode;\n iconPosition?: \"leading\" | \"trailing\";\n /** The element to render. Defaults per variant (`h2` for a heading, and so on). */\n as?: TypographyElement;\n /**\n * Radix-style composition: render the child element itself, with these\n * styles merged onto it, instead of a wrapper. Takes precedence over `as`.\n */\n asChild?: boolean;\n ref?: Ref<HTMLElement>;\n children?: ReactNode;\n};\n\nconst DEFAULT_ELEMENT: Record<TypographyVariant, TypographyElement> = {\n display: \"h1\",\n heading: \"h2\",\n subheading: \"h3\",\n body: \"p\",\n label: \"span\",\n hint: \"p\",\n code: \"code\",\n};\n\nconst DEFAULT_WEIGHT: Record<TypographyVariant, TypographyWeight> = {\n display: \"semibold\",\n heading: \"semibold\",\n subheading: \"medium\",\n body: \"regular\",\n label: \"semibold\",\n hint: \"regular\",\n code: \"regular\",\n};\n\nconst VARIANT_CLASSES: Record<TypographyVariant, string> = {\n display: \"text-display leading-tight tracking-tight\",\n heading: \"text-heading leading-tight tracking-tight\",\n subheading: \"text-subheading leading-snug\",\n body: \"text-field leading-normal\",\n label: \"text-label leading-normal\",\n hint: \"text-hint leading-normal\",\n code: \"font-code text-field leading-normal\",\n};\n\nconst TONE_CLASSES: Record<TypographyTone, string> = {\n default: \"text-fg\",\n muted: \"text-fg-muted\",\n subtle: \"text-fg-subtle\",\n accent: \"text-accent\",\n \"on-accent\": \"text-on-accent\",\n success: \"text-success\",\n warning: \"text-warning\",\n info: \"text-info\",\n danger: \"text-danger\",\n};\n\nconst WEIGHT_CLASSES: Record<TypographyWeight, string> = {\n regular: \"font-normal\",\n medium: \"font-medium\",\n semibold: \"font-semibold\",\n bold: \"font-bold\",\n};\n\nconst ALIGN_CLASSES = {\n start: \"text-start\",\n center: \"text-center\",\n end: \"text-end\",\n} as const;\n\nconst ICON_CLASSES =\n \"inline-flex shrink-0 items-center [&>svg]:h-[1em] [&>svg]:w-[1em]\";\n\nfunction typographyClassName({\n variant,\n tone,\n weight,\n align,\n truncate,\n hasIcon,\n className,\n}: {\n variant: TypographyVariant;\n tone: TypographyTone;\n weight: TypographyWeight;\n align: \"start\" | \"center\" | \"end\" | undefined;\n truncate: boolean;\n hasIcon: boolean;\n className: string | undefined;\n}): string {\n return [\n VARIANT_CLASSES[variant],\n TONE_CLASSES[tone],\n WEIGHT_CLASSES[weight],\n align ? ALIGN_CLASSES[align] : \"\",\n hasIcon ? \"inline-flex items-center gap-1.5\" : \"\",\n // With an icon the root is a flex container, and text-overflow only\n // clips block text, so the text span carries the truncation instead.\n truncate && !hasIcon ? \"truncate\" : \"\",\n className ?? \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n}\n\nexport function Typography({\n variant = \"body\",\n tone = \"default\",\n weight,\n align,\n truncate = false,\n icon,\n iconPosition = \"leading\",\n as,\n asChild = false,\n className,\n children,\n ...rest\n}: TypographyProps) {\n const hasIcon = icon !== undefined && icon !== null;\n // Widened to `ElementType`: the union of intrinsic tags would otherwise\n // demand a `ref` typed to one specific element.\n const Component: ElementType = asChild\n ? Slot\n : (as ?? DEFAULT_ELEMENT[variant]);\n\n const iconNode = hasIcon ? (\n <span aria-hidden=\"true\" className={ICON_CLASSES}>\n {icon}\n </span>\n ) : null;\n\n const content = hasIcon ? (\n <>\n {iconPosition === \"leading\" ? iconNode : null}\n <span className={truncate ? \"min-w-0 truncate\" : undefined}>\n {children}\n </span>\n {iconPosition === \"trailing\" ? iconNode : null}\n </>\n ) : (\n children\n );\n\n return (\n <Component\n {...rest}\n className={typographyClassName({\n variant,\n tone,\n weight: weight ?? DEFAULT_WEIGHT[variant],\n align,\n truncate,\n hasIcon,\n className,\n })}\n >\n {content}\n </Component>\n );\n}\n"],"mappings":";;;;AAEA,SAAS,eAAAA,cAAa,YAAAC,iBAAgB;;;ACAtC,SAAS,aAAa;AACtB,SAAmD,aAAa;;;ACHhE;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAmCP,IAAM,mBAAmB;AAEzB,SAAS,UACP,QACA,OACiB;AACjB,MAAI,CAAC,QAAQ;AACX,WAAO,EAAE,OAAO,KAAK;AAAA,EACvB;AAEA,QAAM,SAAS,OAAO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