torch-glare 2.4.1 → 2.4.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 (79) hide show
  1. package/apps/lib/components/Button.tsx +1 -1
  2. package/apps/lib/components/Card.tsx +47 -20
  3. package/apps/lib/components/ColorPicker.tsx +441 -0
  4. package/apps/lib/components/ConclusionHeader.tsx +148 -0
  5. package/apps/lib/components/DatePicker.tsx +2 -0
  6. package/apps/lib/components/Drawer.tsx +66 -24
  7. package/apps/lib/components/FormBuilder/DisplayField.tsx +40 -0
  8. package/apps/lib/components/FormBuilder/context.ts +71 -0
  9. package/apps/lib/components/FormBuilder/fields/ChoiceFields.tsx +65 -0
  10. package/apps/lib/components/FormBuilder/fields/ColorField.tsx +76 -0
  11. package/apps/lib/components/FormBuilder/fields/CustomField.tsx +16 -0
  12. package/apps/lib/components/FormBuilder/fields/DateField.tsx +34 -0
  13. package/apps/lib/components/FormBuilder/fields/FieldArray.tsx +79 -0
  14. package/apps/lib/components/FormBuilder/fields/FieldShell.tsx +174 -0
  15. package/apps/lib/components/FormBuilder/fields/FileField.tsx +40 -0
  16. package/apps/lib/components/FormBuilder/fields/OptionListFields.tsx +139 -0
  17. package/apps/lib/components/FormBuilder/fields/OtpField.tsx +32 -0
  18. package/apps/lib/components/FormBuilder/fields/PhoneField.tsx +82 -0
  19. package/apps/lib/components/FormBuilder/fields/RichTextEditorField.tsx +37 -0
  20. package/apps/lib/components/FormBuilder/fields/SelectField.tsx +101 -0
  21. package/apps/lib/components/FormBuilder/fields/SignatureField.tsx +175 -0
  22. package/apps/lib/components/FormBuilder/fields/SliderField.tsx +72 -0
  23. package/apps/lib/components/FormBuilder/fields/SwitchBoxField.tsx +42 -0
  24. package/apps/lib/components/FormBuilder/fields/TableField.tsx +312 -0
  25. package/apps/lib/components/FormBuilder/fields/TextField.tsx +222 -0
  26. package/apps/lib/components/FormBuilder/fields/TreeSelectField.tsx +49 -0
  27. package/apps/lib/components/FormBuilder/fields/countries.ts +303 -0
  28. package/apps/lib/components/FormBuilder/fields/index.ts +25 -0
  29. package/apps/lib/components/FormBuilder/form-builder.tsx +292 -0
  30. package/apps/lib/components/FormBuilder/header.tsx +105 -0
  31. package/apps/lib/components/FormBuilder/index.ts +37 -0
  32. package/apps/lib/components/FormBuilder/numberFormat.ts +16 -0
  33. package/apps/lib/components/FormBuilder/stepper.tsx +217 -0
  34. package/apps/lib/components/FormBuilder/submit.tsx +41 -0
  35. package/apps/lib/components/FormBuilder/types.ts +264 -0
  36. package/apps/lib/components/FormBuilder/viewFormat.tsx +137 -0
  37. package/apps/lib/components/FormRenderer/FormDrawer.tsx +121 -0
  38. package/apps/lib/components/FormRenderer/form-renderer.tsx +113 -0
  39. package/apps/lib/components/FormRenderer/index.ts +9 -0
  40. package/apps/lib/components/FormRenderer/types.ts +79 -0
  41. package/apps/lib/components/FormSummary.tsx +282 -0
  42. package/apps/lib/components/ImageAttachment.tsx +36 -61
  43. package/apps/lib/components/Label.tsx +49 -42
  44. package/apps/lib/components/RadioCard.tsx +2 -0
  45. package/apps/lib/components/SearchableSelect.tsx +9 -3
  46. package/apps/lib/components/SectionBlock.tsx +16 -8
  47. package/apps/lib/components/Select.tsx +41 -120
  48. package/apps/lib/components/TextEditor/RichTextField.tsx +46 -0
  49. package/apps/lib/components/{TextEditor.tsx → TextEditor/TextEditor.tsx} +63 -9
  50. package/apps/lib/components/TextEditor/TextEditorToolbar.tsx +429 -0
  51. package/apps/lib/components/TextEditor/editor-tools/AlignmentTune.ts +70 -0
  52. package/apps/lib/components/TextEditor/editor-tools/ColorInlineTool.ts +50 -0
  53. package/apps/lib/components/TextEditor/editor-tools/StrikethroughInlineTool.ts +48 -0
  54. package/apps/lib/components/TextEditor/editor-tools/inlineFormat.ts +98 -0
  55. package/apps/lib/{types → components/TextEditor}/editorjs.d.ts +19 -0
  56. package/apps/lib/components/TextEditor/index.ts +7 -0
  57. package/apps/lib/components/Textarea.tsx +1 -1
  58. package/apps/lib/registry.json +51 -58
  59. package/apps/lib/tsconfig.tsbuildinfo +1 -0
  60. package/apps/lib/utils/color.ts +175 -0
  61. package/docs/components/card.md +4 -2
  62. package/docs/components/chart-block-tool.md +5 -4
  63. package/docs/components/color-picker.md +101 -0
  64. package/docs/components/conclusion-header.md +80 -0
  65. package/docs/components/drawer.md +153 -102
  66. package/docs/components/form-builder.md +270 -0
  67. package/docs/components/form-renderer.md +228 -0
  68. package/docs/components/form-summary.md +123 -0
  69. package/docs/components/image-attachment.md +10 -4
  70. package/docs/components/table-dnd-wrapper.md +5 -3
  71. package/docs/components/text-editor.md +18 -0
  72. package/docs/how-to/form-and-list-recipes.md +26 -19
  73. package/docs/how-to/forms-with-form-builder.md +408 -0
  74. package/docs/how-to/guides.md +153 -179
  75. package/docs/tutorials/building-first-form.md +150 -159
  76. package/package.json +1 -1
  77. /package/apps/lib/components/{ChartBlockTool.ts → TextEditor/ChartBlockTool.ts} +0 -0
  78. /package/apps/lib/components/{TableDnDWrapper.ts → TextEditor/TableDnDWrapper.ts} +0 -0
  79. /package/apps/lib/{utils → components/TextEditor}/markdownParser.ts +0 -0
@@ -5,6 +5,7 @@ import { Drawer as DrawerPrimitive } from "vaul";
5
5
  import { cva, type VariantProps } from "class-variance-authority";
6
6
 
7
7
  import { cn } from "../utils/cn";
8
+ import { Button } from "./Button";
8
9
 
9
10
  const Drawer = ({
10
11
  shouldScaleBackground = true,
@@ -47,9 +48,58 @@ interface DrawerContentProps extends React.ComponentPropsWithoutRef<
47
48
  */
48
49
  framed?: boolean;
49
50
  wrapperClassName?: string;
51
+ /**
52
+ * @deprecated Use `className` — it now targets the tray directly. Kept as an
53
+ * alias (merged last, so it still wins) for the pre-`DrawerPanel` API.
54
+ */
50
55
  trayClassName?: string;
51
56
  }
52
57
 
58
+ interface DrawerPanelProps extends React.HTMLAttributes<HTMLDivElement> {
59
+ /** Panel border + inset shadow that pairs with the tray's frame. Default `true`. */
60
+ framed?: boolean;
61
+ /** Show the drag handle (bottom sheets). Default `false`. */
62
+ showHandle?: boolean;
63
+ }
64
+
65
+ /**
66
+ * The light `#F0F0F0` content surface inside a `DrawerContent`.
67
+ *
68
+ * It is an ordinary child, not something the tray paints — so a drawer can hold a panel
69
+ * and something else beside it (e.g. a `FormSummary`), each bringing its own background.
70
+ * Give the tray a `gap-*` to space them.
71
+ *
72
+ * ```tsx
73
+ * <DrawerContent className="gap-[6px]">
74
+ * <DrawerPanel>…form…</DrawerPanel>
75
+ * <FormSummary … />
76
+ * </DrawerContent>
77
+ * ```
78
+ */
79
+ const DrawerPanel = React.forwardRef<HTMLDivElement, DrawerPanelProps>(
80
+ ({ className, framed = true, showHandle = false, children, ...props }, ref) => (
81
+ <div
82
+ ref={ref}
83
+ // The content surface is always light (#F0F0F0) regardless of the page
84
+ // theme, so pin a light theme here. This makes theme-aware content tokens
85
+ // (DrawerTitle/Description and any consumer content) resolve to their
86
+ // dark-on-light values instead of following a dark page theme (which
87
+ // would render white-on-light = invisible).
88
+ data-theme="light"
89
+ className={cn(
90
+ "flex flex-1 gap-2 rounded-t-[16px] p-1 bg-[#F0F0F0] min-h-0",
91
+ framed && "border border-[#D4D4D4] shadow-[inset_0_-4px_16px_rgba(0,0,0,0.1)]",
92
+ className,
93
+ )}
94
+ {...props}
95
+ >
96
+ {showHandle && <div className="mx-auto h-2 w-[100px] rounded-full bg-[#D4D4D4]" />}
97
+ {children}
98
+ </div>
99
+ ),
100
+ );
101
+ DrawerPanel.displayName = "DrawerPanel";
102
+
53
103
  const DrawerContent = React.forwardRef<
54
104
  React.ElementRef<typeof DrawerPrimitive.Content>,
55
105
  DrawerContentProps
@@ -58,7 +108,6 @@ const DrawerContent = React.forwardRef<
58
108
  {
59
109
  className,
60
110
  children,
61
- showHandle = true,
62
111
  notch,
63
112
  notchSide = "left",
64
113
  framed: framedProp,
@@ -89,9 +138,12 @@ const DrawerContent = React.forwardRef<
89
138
  : notch}
90
139
  </div>
91
140
  )}
141
+ {/* The tray. It frames and positions, but paints nothing over its children —
142
+ each child brings its own background (see `DrawerPanel`). Supply a `gap-*`
143
+ via `className` when the tray holds more than one. */}
92
144
  <div
93
145
  className={cn(
94
- "flex flex-1 flex-col min-h-0",
146
+ "flex flex-1 min-h-0",
95
147
  framed
96
148
  ? "p-1.5 bg-black-400 shadow-[0_0_4px_rgba(0,0,0,0.2),0_0_30px_rgba(0,0,0,0.4)]"
97
149
  : "p-0",
@@ -102,27 +154,11 @@ const DrawerContent = React.forwardRef<
102
154
  : framed
103
155
  ? "rounded-t-[22px]"
104
156
  : "",
157
+ className,
105
158
  trayClassName,
106
159
  )}
107
160
  >
108
- <div
109
- // The content surface is always light (#F0F0F0) regardless of the
110
- // page theme, so pin a light theme here. This makes theme-aware
111
- // content tokens (DrawerTitle/Description and any consumer content)
112
- // resolve to their dark-on-light values instead of following a dark
113
- // page theme (which would render white-on-light = invisible).
114
- data-theme="light"
115
- className={cn(
116
- "flex flex-1 flex-col gap-2 rounded-t-[16px] p-1.5 bg-[#F0F0F0] min-h-0",
117
- framed && "border border-[#D4D4D4] shadow-[inset_0_-4px_16px_rgba(0,0,0,0.1)]",
118
- className,
119
- )}
120
- >
121
- {showHandle && !notch && (
122
- <div className="mx-auto h-2 w-[100px] rounded-full bg-[#D4D4D4]" />
123
- )}
124
- {children}
125
- </div>
161
+ {children}
126
162
  </div>
127
163
  </DrawerPrimitive.Content>
128
164
  </DrawerPortal>
@@ -233,18 +269,23 @@ const DrawerNotchClose = React.forwardRef<
233
269
  HTMLButtonElement,
234
270
  React.ButtonHTMLAttributes<HTMLButtonElement>
235
271
  >(({ className, children, ...props }, ref) => (
236
- <button
272
+ <Button
237
273
  ref={ref}
238
274
  type="button"
239
275
  aria-label="Close"
276
+ buttonType="icon"
277
+ size="S"
278
+ variant="PrimeContStyle"
240
279
  className={cn(
241
- "inline-flex h-[22px] w-[22px] items-center justify-center rounded-[13px] bg-white/15 text-content-presentation-global-primary transition-colors hover:bg-white/25",
280
+ // Glare Button (icon, S = 22×22) with the notch's own circular radius + translucent look
281
+ // (S is otherwise rounded-[4px]).
282
+ "!rounded-[13px] bg-white/15 text-white hover:bg-white/25 hover:text-white",
242
283
  className,
243
284
  )}
244
285
  {...props}
245
286
  >
246
- {children ?? <i className="ri-close-fill text-[14px]" />}
247
- </button>
287
+ {children ?? <i className="ri-close-fill !text-[14px]" />}
288
+ </Button>
248
289
  ));
249
290
  DrawerNotchClose.displayName = "DrawerNotchClose";
250
291
 
@@ -346,6 +387,7 @@ export {
346
387
  DrawerTrigger,
347
388
  DrawerClose,
348
389
  DrawerContent,
390
+ DrawerPanel,
349
391
  DrawerHeader,
350
392
  DrawerHeaderTitle,
351
393
  DrawerHeaderActions,
@@ -0,0 +1,40 @@
1
+ import { ReactNode } from "react";
2
+
3
+ import { cn } from "../../utils/cn";
4
+
5
+ export interface DisplayFieldProps {
6
+ label?: ReactNode;
7
+ /** Plain string value — falls back to an em-dash when empty. */
8
+ value?: string | null;
9
+ /** Rich value (badges, chips, formatted nodes) — takes precedence over `value`. */
10
+ valueNode?: ReactNode;
11
+ className?: string;
12
+ }
13
+
14
+ /**
15
+ * Read-only field: a label above its value. Used by FormBuilder's `mode: "view"`
16
+ * so the same config renders as a detail view. Mirrors the products-services
17
+ * `DisplayField` (label + value/valueNode, em-dash fallback).
18
+ */
19
+ export function DisplayField({ label, value, valueNode, className }: DisplayFieldProps) {
20
+ return (
21
+ <div className={cn("flex w-full flex-col gap-1.5", className)}>
22
+ {label != null && (
23
+ <p className="typography-body-small-regular text-content-presentation-global-secondary">
24
+ {label}
25
+ </p>
26
+ )}
27
+ {valueNode != null ? (
28
+ <div className="typography-body-medium-medium text-content-presentation-global-primary">
29
+ {valueNode}
30
+ </div>
31
+ ) : (
32
+ <span className="typography-body-medium-medium text-content-presentation-global-primary">
33
+ {value != null && value !== "" ? value : "—"}
34
+ </span>
35
+ )}
36
+ </div>
37
+ );
38
+ }
39
+
40
+ DisplayField.displayName = "DisplayField";
@@ -0,0 +1,71 @@
1
+ "use client";
2
+
3
+ import { createContext, useContext } from "react";
4
+
5
+ export type FormBuilderMode = "edit" | "view";
6
+ export type FieldDirection = "horizontal" | "vertical";
7
+
8
+ /** Loading flag — drives the Submit spinner and disables inputs. */
9
+ export const LoadingContext = createContext<boolean>(false);
10
+ export const useLoading = () => useContext(LoadingContext);
11
+
12
+ /** Edit vs read-only. Fields render `DisplayField` in `"view"`. */
13
+ export const ModeContext = createContext<FormBuilderMode>("edit");
14
+ export const useMode = () => useContext(ModeContext);
15
+
16
+ /**
17
+ * The `<form>`'s `id`. Provided by the FormBuilder root so a `FormBuilder.Submit` rendered
18
+ * **outside** the `<form>` element — the absolute header's action pill, or the drawer header —
19
+ * can still submit it via native `form={id}` association without the caller wiring an id by hand.
20
+ */
21
+ export const FormIdContext = createContext<string | undefined>(undefined);
22
+ export const useFormId = () => useContext(FormIdContext);
23
+
24
+ /**
25
+ * Field row direction — set via `FormBuilder`'s `fieldDirection` prop. `undefined` (the default)
26
+ * means "don't force one": `FieldSection` then uses its own responsive `flexible` layout, which
27
+ * stacks on small screens and goes two-column at `lg`. Only set this to pin a direction.
28
+ */
29
+ export const DirectionContext = createContext<FieldDirection | undefined>(undefined);
30
+ export const useDirection = () => useContext(DirectionContext);
31
+
32
+ /**
33
+ * Cell mode — set to `true` by `FormBuilder.Table` around each cell's field so `FieldShell`
34
+ * renders just the control (no label/row chrome) and surfaces validation errors as a tooltip
35
+ * on the control instead of a stacked hint. Off (`false`) everywhere else, so normal fields
36
+ * keep their full `FieldSection` layout.
37
+ */
38
+ export const CellContext = createContext<boolean>(false);
39
+ export const useCell = () => useContext(CellContext);
40
+
41
+ /**
42
+ * Step registry — a `FormBuilder.Step` provides this so the fields rendered
43
+ * inside it can register their `name`. `FormBuilder.Next` then validates just
44
+ * those names before advancing. `null` when not inside a stepper.
45
+ */
46
+ export interface StepRegistry {
47
+ register: (name: string) => void;
48
+ unregister: (name: string) => void;
49
+ }
50
+ export const StepContext = createContext<StepRegistry | null>(null);
51
+ export const useStepRegistry = () => useContext(StepContext);
52
+
53
+ /** Stepper state shared by the nav + Back/Next/Submit buttons. */
54
+ export interface StepperContextValue {
55
+ currentStep: number;
56
+ totalSteps: number;
57
+ titles: string[];
58
+ isFirstStep: boolean;
59
+ isLastStep: boolean;
60
+ goToNext: () => void | Promise<void>;
61
+ goToPrevious: () => void;
62
+ goToStep: (index: number) => void;
63
+ /** Field names registered per step, for per-step validation. */
64
+ stepFields: Record<number, Set<string>>;
65
+ }
66
+ export const StepperContext = createContext<StepperContextValue | null>(null);
67
+ export const useStepper = () => {
68
+ const ctx = useContext(StepperContext);
69
+ if (!ctx) throw new Error("FormBuilder.Step/Back/Next must be used within FormBuilder.Stepper");
70
+ return ctx;
71
+ };
@@ -0,0 +1,65 @@
1
+ "use client";
2
+
3
+ import { LabeledCheckBox } from "../../LabeledCheckBox";
4
+ import { RadioGroup } from "../../Radio";
5
+ import { RadioCard } from "../../RadioCard";
6
+ import { useLoading } from "../context";
7
+ import { formatFieldView } from "../viewFormat";
8
+ import type { CheckboxFieldProps, RadioCardsFieldProps } from "../types";
9
+ import { FieldShell } from "./FieldShell";
10
+
11
+ /**
12
+ * `FormBuilder.Checkbox` — a single boolean checkbox. The field `label` sits in the
13
+ * normal label column; an optional `subLabel` renders inline beside the checkbox (via
14
+ * the clickable `LabeledCheckBox`).
15
+ */
16
+ export function CheckboxField({ subLabel, ...props }: CheckboxFieldProps) {
17
+ const loading = useLoading();
18
+ return (
19
+ <FieldShell {...props} view={(v) => formatFieldView({ kind: "boolean", value: v })}>
20
+ {(field) => (
21
+ <div className="flex w-full items-center ps-2.5">
22
+ <LabeledCheckBox
23
+ id={props.name}
24
+ label={subLabel ?? ""}
25
+ checked={!!field.value}
26
+ size="S"
27
+ onCheckedChange={(checked) => field.onChange(checked === true)}
28
+ disabled={props.disabled || loading}
29
+ />
30
+ </div>
31
+ )}
32
+ </FieldShell>
33
+ );
34
+ }
35
+
36
+ /** `FormBuilder.RadioCards` — radio options rendered as cards (Glare `RadioCard`). */
37
+ export function RadioCardsField(props: RadioCardsFieldProps) {
38
+ const loading = useLoading();
39
+ const options = props.options.map((o) => ({
40
+ label: typeof o.label === "string" ? o.label : String(o.value),
41
+ value: o.value,
42
+ }));
43
+ return (
44
+ <FieldShell {...props} view={(v) => formatFieldView({ kind: "option", value: v, options })}>
45
+ {(field) => (
46
+ <RadioGroup
47
+ value={field.value ?? ""}
48
+ onValueChange={field.onChange}
49
+ className="grid w-full grid-cols-2 gap-3"
50
+ >
51
+ {props.options.map((opt) => (
52
+ <RadioCard
53
+ key={opt.value}
54
+ id={`${props.name}-${opt.value}`}
55
+ value={opt.value}
56
+ headerLabel={opt.label}
57
+ description={opt.description}
58
+ disabled={opt.disabled || props.disabled || loading}
59
+ />
60
+ ))}
61
+ </RadioGroup>
62
+ )}
63
+ </FieldShell>
64
+ );
65
+ }
@@ -0,0 +1,76 @@
1
+ "use client";
2
+
3
+ import { InputField } from "../../InputField";
4
+ import { ColorPicker, CHECKERBOARD } from "../../ColorPicker";
5
+ import { useLoading } from "../context";
6
+ import type { ColorFieldProps } from "../types";
7
+ import { FieldShell } from "./FieldShell";
8
+
9
+ /**
10
+ * `FormBuilder.Color` — an `InputField` holding the hex text, with a trailing action button that
11
+ * carries the colour itself. That button is the `ColorPicker` trigger: clicking it opens the full
12
+ * palette. Value is a hex string.
13
+ */
14
+ export function ColorField(props: ColorFieldProps) {
15
+ const loading = useLoading();
16
+
17
+ return (
18
+ <FieldShell
19
+ {...props}
20
+ view={(v) =>
21
+ v
22
+ ? {
23
+ valueNode: (
24
+ <span className="inline-flex items-center gap-2">
25
+ <span
26
+ className="h-4 w-4 rounded-[4px] border border-border-presentation-action-primary"
27
+ style={{ background: String(v) }}
28
+ />
29
+ {String(v)}
30
+ </span>
31
+ ),
32
+ }
33
+ : { value: "" }
34
+ }
35
+ >
36
+ {(field) => {
37
+ const value = typeof field.value === "string" ? field.value : "";
38
+ const disabled = props.disabled || loading;
39
+ return (
40
+ // The InputField IS the trigger: ColorPicker detects it as an input (it takes a `value`)
41
+ // and feeds it the hex, so clicking the field opens the palette.
42
+ <ColorPicker
43
+ value={value || undefined}
44
+ onChange={field.onChange}
45
+ presets={props.presets}
46
+ alpha={props.alpha ?? true}
47
+ disabled={disabled}
48
+ >
49
+ <InputField
50
+ // Explicit — otherwise Radix's trigger `type="button"` would land on the input.
51
+ type="text"
52
+ value={value}
53
+ onChange={(e) => field.onChange(e.target.value)}
54
+ placeholder={props.placeholder ?? "#000000"}
55
+ disabled={disabled}
56
+ className="w-full"
57
+ // The trailing action button holds the colour itself.
58
+ childrenSide={
59
+ <span
60
+ aria-hidden
61
+ className="block h-[26px] w-[26px] shrink-0 overflow-hidden rounded-[6px] border border-border-presentation-action-primary"
62
+ style={CHECKERBOARD}
63
+ >
64
+ <span
65
+ className="block h-full w-full"
66
+ style={{ backgroundColor: value || "#000000" }}
67
+ />
68
+ </span>
69
+ }
70
+ />
71
+ </ColorPicker>
72
+ );
73
+ }}
74
+ </FieldShell>
75
+ );
76
+ }
@@ -0,0 +1,16 @@
1
+ "use client";
2
+
3
+ import type { CustomFieldProps } from "../types";
4
+ import { FieldShell } from "./FieldShell";
5
+
6
+ /** `FormBuilder.Custom` — render any control, keeping the FieldSection + validation wiring. */
7
+ export function CustomField(props: CustomFieldProps) {
8
+ return (
9
+ <FieldShell
10
+ {...props}
11
+ view={(v) => ({ valueNode: props.formatView ? props.formatView(v) : String(v ?? "—") })}
12
+ >
13
+ {(field, fieldState) => props.render({ field, fieldState })}
14
+ </FieldShell>
15
+ );
16
+ }
@@ -0,0 +1,34 @@
1
+ "use client";
2
+
3
+ import { DatePicker } from "../../DatePicker";
4
+ import { useCell } from "../context";
5
+ import { formatFieldView } from "../viewFormat";
6
+ import type { DateFieldProps } from "../types";
7
+ import { FieldShell } from "./FieldShell";
8
+
9
+ /**
10
+ * `FormBuilder.Date` (single) — and, via `mode`/`timePicker`, the presets
11
+ * `.DateRange` (value `{from,to}`), `.DateMultiple` (value `Date[]`), and
12
+ * `.DateTime` (date + time). All back onto the one Glare `DatePicker`.
13
+ */
14
+ export function DateField(props: DateFieldProps) {
15
+ const kind = props.mode === "range" ? "daterange" : props.mode === "multiple" ? "dates" : "date";
16
+ const cell = useCell();
17
+
18
+ return (
19
+ <FieldShell {...props} view={(v) => formatFieldView({ kind, value: v })}>
20
+ {(field) => (
21
+ <DatePicker
22
+ mode={props.mode ?? "single"}
23
+ timePicker={props.timePicker}
24
+ dateFormat={props.dateFormat}
25
+ value={field.value}
26
+ onTable={cell}
27
+ onChange={(e) =>
28
+ field.onChange((e as unknown as { target: { value: unknown } }).target.value)
29
+ }
30
+ />
31
+ )}
32
+ </FieldShell>
33
+ );
34
+ }
@@ -0,0 +1,79 @@
1
+ "use client";
2
+
3
+ import { useFormContext, useFieldArray, type FieldValues, type ArrayPath } from "react-hook-form";
4
+
5
+ import { Button } from "../../Button";
6
+ import { Card } from "../../Card";
7
+ import { useMode } from "../context";
8
+ import type { FieldArrayProps } from "../types";
9
+
10
+ /**
11
+ * `FormBuilder.FieldArray` — a repeating list of sub-fields (RHF `useFieldArray`).
12
+ * `children` renders one row's fields; name them `${rowName}.field`. Add/Remove is
13
+ * hidden in view mode.
14
+ */
15
+ export function FieldArray(props: FieldArrayProps) {
16
+ const form = useFormContext<FieldValues>();
17
+ const mode = useMode();
18
+ const { fields, append, remove } = useFieldArray({
19
+ control: form.control,
20
+ name: props.name as ArrayPath<FieldValues>,
21
+ });
22
+
23
+ if (props.hidden) return null;
24
+
25
+ const addButton = mode !== "view" && (
26
+ <Button
27
+ type="button"
28
+ size="S"
29
+ variant="BorderStyle"
30
+ onClick={() => append((props.defaultItem ?? {}) as never)}
31
+ >
32
+ <i className="ri-add-line" />
33
+ {props.addLabel ?? "Add"}
34
+ </Button>
35
+ );
36
+
37
+ return (
38
+ <section className="grid w-full max-w-[1200px] gap-3 px-[12px] py-[16px]">
39
+ <div className="flex items-center justify-between">
40
+ {props.label ? (
41
+ <span className="typography-body-medium-medium text-content-presentation-global-primary">
42
+ {props.label}
43
+ </span>
44
+ ) : (
45
+ <span />
46
+ )}
47
+ {addButton}
48
+ </div>
49
+ {props.description && (
50
+ <p className="typography-body-small-regular text-content-presentation-global-secondary">
51
+ {props.description}
52
+ </p>
53
+ )}
54
+
55
+ <div className="flex flex-col gap-3">
56
+ {fields.map((f, index) => (
57
+ <Card key={f.id} className="relative gap-3 pr-8">
58
+ {mode !== "view" && (
59
+ <button
60
+ type="button"
61
+ aria-label="Remove"
62
+ onClick={() => remove(index)}
63
+ className="absolute right-2 top-2 inline-flex h-[22px] w-[22px] items-center justify-center rounded-full text-content-presentation-state-negative transition-colors hover:bg-background-presentation-action-hover"
64
+ >
65
+ <i className="ri-close-line text-[16px]" />
66
+ </button>
67
+ )}
68
+ {props.children(`${props.name}.${index}`, index, () => remove(index))}
69
+ </Card>
70
+ ))}
71
+ {fields.length === 0 && (
72
+ <p className="typography-body-small-regular text-content-presentation-global-secondary">
73
+ No items yet.
74
+ </p>
75
+ )}
76
+ </div>
77
+ </section>
78
+ );
79
+ }