@yamatozhen/design_system 1.0.1 → 1.1.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 (184) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +101 -101
  3. package/package.json +50 -50
  4. package/scripts/postinstall.js +91 -91
  5. package/template/app/ClientNav.tsx +258 -310
  6. package/template/app/globals.css +2 -167
  7. package/template/app/layout.tsx +94 -82
  8. package/template/app/themes/dark-mc 2.css +51 -0
  9. package/template/app/themes/dark-mc.css +51 -51
  10. package/template/app/themes/dark.css +51 -51
  11. package/template/app/themes/light 2.css +51 -0
  12. package/template/app/themes/light-mc 2.css +51 -0
  13. package/template/app/themes/light-mc.css +51 -51
  14. package/template/app/themes/light.css +51 -51
  15. package/template/app/themes/theme 2.css +272 -0
  16. package/template/app/themes/theme.css +272 -82
  17. package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
  18. package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
  19. package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
  20. package/template/components/(buttons)/button.tsx +164 -0
  21. package/template/components/(controls)/slider/Slider.module.css +250 -0
  22. package/template/components/(controls)/slider/Slider.tsx +386 -0
  23. package/template/components/(controls)/switch/Switch.module.css +108 -0
  24. package/template/components/(controls)/switch/Switch.tsx +69 -0
  25. package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
  26. package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
  27. package/template/components/(date & time)/dateField/DateField.module.css +25 -0
  28. package/template/components/(date & time)/dateField/DateField.tsx +193 -0
  29. package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
  30. package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
  31. package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
  32. package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
  33. package/template/components/(date & time)/shared/dateUtils.ts +107 -0
  34. package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
  35. package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
  36. package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
  37. package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
  38. package/template/components/(feedback)/meter/Meter.tsx +111 -0
  39. package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
  40. package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
  41. package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
  42. package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
  43. package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
  44. package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
  45. package/template/components/(forms)/description/Description.tsx +34 -0
  46. package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
  47. package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
  48. package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
  49. package/template/components/(forms)/form/Form.tsx +54 -0
  50. package/template/components/(forms)/input/Input.tsx +50 -0
  51. package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
  52. package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
  53. package/template/components/(forms)/label/Label.tsx +46 -0
  54. package/template/components/(forms)/numberField/NumberField.tsx +292 -0
  55. package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
  56. package/template/components/(forms)/searchField/SearchField.tsx +139 -0
  57. package/template/components/(forms)/shared/field.module.css +75 -0
  58. package/template/components/(forms)/shared/fieldContext.ts +28 -0
  59. package/template/components/(forms)/textArea/TextArea.tsx +55 -0
  60. package/template/components/(forms)/textField/TextField.tsx +91 -0
  61. package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
  62. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
  63. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
  64. package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
  65. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
  66. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
  67. package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
  68. package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
  69. package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
  70. package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
  71. package/template/components/(layout)/accordion/Accordion.module.css +108 -0
  72. package/template/components/(layout)/accordion/Accordion.tsx +251 -0
  73. package/template/components/(layout)/card/Card.module.css +136 -0
  74. package/template/components/(layout)/card/Card.tsx +371 -0
  75. package/template/components/(layout)/list/List.module.css +83 -0
  76. package/template/components/(layout)/list/List.tsx +332 -0
  77. package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
  78. package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
  79. package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
  80. package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
  81. package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
  82. package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
  83. package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
  84. package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
  85. package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
  86. package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
  87. package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
  88. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
  89. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
  90. package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
  91. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
  92. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -473
  93. package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
  94. package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
  95. package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
  96. package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
  97. package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
  98. package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
  99. package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
  100. package/template/components/(layout)/separator/Separator.tsx +112 -0
  101. package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
  102. package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
  103. package/template/components/(overlays)/modal/Modal.tsx +654 -0
  104. package/template/components/(overlays)/popover/Popover.tsx +420 -0
  105. package/template/components/(overlays)/toast/Toast.tsx +692 -0
  106. package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
  107. package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
  108. package/template/components/(pickers)/select/Select.tsx +188 -0
  109. package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
  110. package/template/components/(pickers)/shared/PickerItem.ts +13 -0
  111. package/template/components/tools/CustomScrollbar 2.tsx +107 -0
  112. package/template/components/tools/CustomScrollbar.tsx +107 -0
  113. package/template/components/tools/Divider 2.tsx +11 -0
  114. package/template/components/tools/Divider.tsx +11 -11
  115. package/template/components/tools/ReduceMotionContext 2.tsx +5 -0
  116. package/template/components/tools/ReduceMotionContext.tsx +5 -5
  117. package/template/components/tools/Sinewave 2.tsx +206 -0
  118. package/template/components/tools/Sinewave.tsx +396 -199
  119. package/template/components/tools/SinewaveProgress 2.tsx +140 -0
  120. package/template/components/tools/SinewaveProgress.tsx +140 -135
  121. package/template/components/tools/badge/Badge 2.tsx +28 -0
  122. package/template/components/tools/badge/Badge.tsx +28 -28
  123. package/template/components/tools/dropdown/drop.module.css +196 -0
  124. package/template/components/tools/dropdown/drop.tsx +568 -0
  125. package/template/components/tools/easing.ts +118 -0
  126. package/template/components/tools/flubber.d 2.ts +7 -0
  127. package/template/components/tools/flubber.d.ts +6 -6
  128. package/template/components/tools/footer/Footer.tsx +20 -0
  129. package/template/components/tools/input/Input 2.tsx +99 -0
  130. package/template/components/tools/input/Input.module 2.css +45 -0
  131. package/template/components/tools/input/Input.module.css +45 -0
  132. package/template/components/tools/input/Input.tsx +99 -0
  133. package/template/components/tools/label/Icon 2.tsx +39 -0
  134. package/template/components/tools/label/Icon.tsx +39 -0
  135. package/template/components/tools/label/Label 2.tsx +150 -0
  136. package/template/components/tools/label/Label.tsx +156 -0
  137. package/template/components/tools/mobileViewProvider 2.tsx +53 -0
  138. package/template/components/tools/mobileViewProvider.tsx +53 -58
  139. package/template/components/tools/ripple/ripple 2.css +38 -0
  140. package/template/components/tools/ripple/ripple 2.tsx +78 -0
  141. package/template/components/tools/ripple/ripple.css +38 -41
  142. package/template/components/tools/ripple/ripple.tsx +78 -53
  143. package/template/components/tools/shape/{ShapeMorph.tsx → Shape 2.tsx } +313 -190
  144. package/template/components/tools/shape/Shape.module 2.css +21 -0
  145. package/template/components/tools/shape/Shape.module.css +25 -0
  146. package/template/components/tools/shape/Shape.tsx +316 -0
  147. package/template/components/tools/shape/ShapeLoader 2.tsx +104 -0
  148. package/template/components/tools/shape/ShapeLoader.tsx +104 -101
  149. package/template/components/tools/shape/ShapePaths 2.ts +116 -0
  150. package/template/components/tools/shape/ShapePaths.ts +116 -116
  151. package/template/components/{layout/switch/Switch.tsx → tools/switch/Switch 2.tsx } +48 -48
  152. package/template/components/{layout/switch/Switch.module.css → tools/switch/Switch.module 2.css } +102 -102
  153. package/template/components/tools/switch/Switch.module.css +102 -102
  154. package/template/components/tools/switch/Switch.tsx +48 -48
  155. package/template/components/tools/useBodyScrollLock 2.tsx +27 -0
  156. package/template/components/tools/useBodyScrollLock.tsx +27 -27
  157. package/template/components/tools/useImageColor 2.ts +47 -0
  158. package/template/components/tools/useImageColor.ts +47 -47
  159. package/template/components/tools/useNavSheetDrag 2.tsx +196 -0
  160. package/template/components/tools/useNavSheetDrag.tsx +196 -196
  161. package/template/public/fonts/material-symbols/MaterialSymbolsRounded-VariableFont_FILL,GRAD,opsz,wght 2.woff2 +0 -0
  162. package/template/components/layout/accordion/Accordion.module.css +0 -149
  163. package/template/components/layout/accordion/Accordion.tsx +0 -114
  164. package/template/components/layout/button/button.tsx +0 -128
  165. package/template/components/layout/button/drop.module.css +0 -229
  166. package/template/components/layout/button/drop.tsx +0 -516
  167. package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
  168. package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
  169. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
  170. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
  171. package/template/components/layout/modals/alert/Alert.tsx +0 -188
  172. package/template/components/layout/navigation/MioCard.module.css +0 -88
  173. package/template/components/layout/navigation/MioCard.tsx +0 -266
  174. package/template/components/tools/ProgressiveBlur.tsx +0 -73
  175. package/template/components/tools/icon/icon.module.css +0 -0
  176. package/template/components/tools/icon/icon.tsx +0 -125
  177. package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
  178. package/template/components/tools/react-bits/FadeContent.tsx +0 -90
  179. package/template/components/tools/react-bits/GlareHover.tsx +0 -73
  180. package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
  181. package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
  182. package/template/components/tools/react-bits/Magnet.tsx +0 -118
  183. package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
  184. package/template/components/tools/react-bits/Stepper/Stepper.tsx +0 -412
@@ -0,0 +1,121 @@
1
+ "use client";
2
+ import React, { useId } from "react";
3
+ import Icon from "@/components/tools/label/Icon";
4
+ import { useCheckboxGroupContext } from "@/components/(forms)/checkboxGroup/CheckboxGroup";
5
+
6
+ export type CheckboxVariant = "primary" | "secondary" | "tertiary";
7
+
8
+ export interface CheckboxProps {
9
+ /** Required to participate in a parent CheckboxGroup — ignored (and
10
+ * unnecessary) for a standalone checkbox. */
11
+ value?: string;
12
+ isSelected?: boolean;
13
+ defaultSelected?: boolean;
14
+ onChange?: (isSelected: boolean) => void;
15
+ isDisabled?: boolean;
16
+ isIndeterminate?: boolean;
17
+ variant?: CheckboxVariant;
18
+ children?: React.ReactNode;
19
+ className?: string;
20
+ style?: React.CSSProperties;
21
+ }
22
+
23
+ export default function Checkbox({
24
+ value,
25
+ isSelected: controlledSelected,
26
+ defaultSelected = false,
27
+ onChange,
28
+ isDisabled = false,
29
+ isIndeterminate = false,
30
+ variant = "primary",
31
+ children,
32
+ className,
33
+ style,
34
+ }: CheckboxProps) {
35
+ const group = useCheckboxGroupContext();
36
+ const id = useId();
37
+
38
+ // Group mode: this checkbox's own selection state is derived from
39
+ // whether `value` is in the group's array, and toggling delegates to
40
+ // the group instead of any local/controlled state.
41
+ const inGroup = group !== null && value !== undefined;
42
+ const [internalSelected, setInternalSelected] = React.useState(
43
+ defaultSelected,
44
+ );
45
+ const isSelected = inGroup
46
+ ? group.values.includes(value)
47
+ : (controlledSelected ?? internalSelected);
48
+ const disabled = isDisabled || (inGroup && group.isDisabled);
49
+
50
+ const handleChange = () => {
51
+ const next = !isSelected;
52
+ if (inGroup) {
53
+ group.toggle(value, next);
54
+ } else {
55
+ if (controlledSelected === undefined) setInternalSelected(next);
56
+ onChange?.(next);
57
+ }
58
+ };
59
+
60
+ return (
61
+ <label
62
+ htmlFor={id}
63
+ style={{
64
+ display: "inline-flex",
65
+ alignItems: "center",
66
+ gap: 8,
67
+ cursor: disabled ? "not-allowed" : "pointer",
68
+ opacity: disabled ? 0.5 : 1,
69
+ ...style,
70
+ }}
71
+ className={className}
72
+ >
73
+ <input
74
+ id={id}
75
+ type="checkbox"
76
+ checked={isSelected}
77
+ disabled={disabled}
78
+ onChange={handleChange}
79
+ ref={(el) => {
80
+ if (el) el.indeterminate = isIndeterminate;
81
+ }}
82
+ style={{ position: "absolute", opacity: 0, width: 0, height: 0 }}
83
+ />
84
+ <span
85
+ aria-hidden
86
+ style={{
87
+ display: "flex",
88
+ alignItems: "center",
89
+ justifyContent: "center",
90
+ width: 20,
91
+ height: 20,
92
+ flexShrink: 0,
93
+ borderRadius: "var(--borderRadius-xs)",
94
+ border: `2px solid ${
95
+ isSelected || isIndeterminate
96
+ ? `var(--md-sys-color-${variant})`
97
+ : "var(--md-sys-color-outline)"
98
+ }`,
99
+ backgroundColor:
100
+ isSelected || isIndeterminate
101
+ ? `var(--md-sys-color-${variant})`
102
+ : "transparent",
103
+ color: `var(--md-sys-color-on-${variant})`,
104
+ transition:
105
+ "background-color var(--transition-expressive-color), border-color var(--transition-expressive-color)",
106
+ }}
107
+ >
108
+ {isIndeterminate ? (
109
+ <Icon systemName="remove" style={{ fontSize: 14 }} />
110
+ ) : isSelected ? (
111
+ <Icon systemName="check" style={{ fontSize: 14 }} />
112
+ ) : null}
113
+ </span>
114
+ {children && (
115
+ <span style={{ fontSize: 14, color: "var(--md-sys-color-on-surface)" }}>
116
+ {children}
117
+ </span>
118
+ )}
119
+ </label>
120
+ );
121
+ }
@@ -0,0 +1,83 @@
1
+ "use client";
2
+ import React, { createContext, useContext, useId, useState } from "react";
3
+
4
+ export interface CheckboxGroupContextValue {
5
+ values: string[];
6
+ toggle: (value: string, isSelected: boolean) => void;
7
+ isDisabled: boolean;
8
+ name?: string;
9
+ }
10
+
11
+ export const CheckboxGroupContext =
12
+ createContext<CheckboxGroupContextValue | null>(null);
13
+
14
+ export interface CheckboxGroupProps {
15
+ value?: string[];
16
+ defaultValue?: string[];
17
+ onChange?: (value: string[]) => void;
18
+ isDisabled?: boolean;
19
+ name?: string;
20
+ label?: string;
21
+ children?: React.ReactNode;
22
+ className?: string;
23
+ style?: React.CSSProperties;
24
+ }
25
+
26
+ // A Checkbox with a `value` prop rendered inside CheckboxGroup
27
+ // automatically participates in this group's array instead of needing
28
+ // isSelected/onChange wired by hand on every single one — same idea as
29
+ // RadioGroup, but toggling adds/removes from an array rather than
30
+ // exclusively selecting one.
31
+ export default function CheckboxGroup({
32
+ value: controlledValue,
33
+ defaultValue = [],
34
+ onChange,
35
+ isDisabled = false,
36
+ name,
37
+ label,
38
+ children,
39
+ className,
40
+ style,
41
+ }: CheckboxGroupProps) {
42
+ const isControlled = controlledValue !== undefined;
43
+ const [internalValues, setInternalValues] = useState(defaultValue);
44
+ const values = isControlled ? controlledValue : internalValues;
45
+ const labelId = useId();
46
+
47
+ const toggle = (value: string, isSelected: boolean) => {
48
+ const next = isSelected
49
+ ? [...values, value]
50
+ : values.filter((v) => v !== value);
51
+ if (!isControlled) setInternalValues(next);
52
+ onChange?.(next);
53
+ };
54
+
55
+ return (
56
+ <CheckboxGroupContext.Provider value={{ values, toggle, isDisabled, name }}>
57
+ <div
58
+ role="group"
59
+ aria-labelledby={label ? labelId : undefined}
60
+ className={className}
61
+ style={{ display: "flex", flexDirection: "column", gap: 8, ...style }}
62
+ >
63
+ {label && (
64
+ <span
65
+ id={labelId}
66
+ style={{
67
+ fontSize: 14,
68
+ fontWeight: 500,
69
+ color: "var(--md-sys-color-on-surface)",
70
+ }}
71
+ >
72
+ {label}
73
+ </span>
74
+ )}
75
+ {children}
76
+ </div>
77
+ </CheckboxGroupContext.Provider>
78
+ );
79
+ }
80
+
81
+ export function useCheckboxGroupContext() {
82
+ return useContext(CheckboxGroupContext);
83
+ }
@@ -0,0 +1,34 @@
1
+ "use client";
2
+ import { useFieldContext } from "@/components/(forms)/shared/fieldContext";
3
+
4
+ export interface DescriptionProps {
5
+ children?: React.ReactNode;
6
+ className?: string;
7
+ style?: React.CSSProperties;
8
+ }
9
+
10
+ // Auto-hidden while the field is invalid — same rule HeroUI's own
11
+ // [data-invalid="true"] CSS applies: a FieldError message takes the
12
+ // description's place rather than stacking both.
13
+ export default function Description({
14
+ children,
15
+ className,
16
+ style,
17
+ }: DescriptionProps) {
18
+ const field = useFieldContext();
19
+ if (field?.isInvalid) return null;
20
+
21
+ return (
22
+ <div
23
+ id={field?.descriptionId}
24
+ className={className}
25
+ style={{
26
+ fontSize: 12,
27
+ color: "var(--md-sys-color-on-surface-variant)",
28
+ ...style,
29
+ }}
30
+ >
31
+ {children}
32
+ </div>
33
+ );
34
+ }
@@ -0,0 +1,31 @@
1
+ export interface ErrorMessageProps {
2
+ children?: React.ReactNode;
3
+ className?: string;
4
+ style?: React.CSSProperties;
5
+ }
6
+
7
+ // Generic, standalone error text — unlike FieldError, this doesn't read
8
+ // any Field context or gate on isInvalid; it always renders whatever
9
+ // you give it. Use this for a one-off error message outside a Field
10
+ // wrapper (e.g. a form-level submit failure banner); use FieldError for
11
+ // per-field validation tied to a TextField/NumberField/etc.
12
+ export default function ErrorMessage({
13
+ children,
14
+ className,
15
+ style,
16
+ }: ErrorMessageProps) {
17
+ if (!children) return null;
18
+ return (
19
+ <div
20
+ role="alert"
21
+ className={className}
22
+ style={{
23
+ fontSize: 12,
24
+ color: "var(--md-sys-color-error)",
25
+ ...style,
26
+ }}
27
+ >
28
+ {children}
29
+ </div>
30
+ );
31
+ }
@@ -0,0 +1,39 @@
1
+ "use client";
2
+ import { useFieldContext } from "@/components/(forms)/shared/fieldContext";
3
+
4
+ export interface FieldErrorProps {
5
+ /** Overrides the field's own errorMessage (from TextField/NumberField/
6
+ * etc.'s `isInvalid`+message props) when given explicitly. */
7
+ children?: React.ReactNode;
8
+ className?: string;
9
+ style?: React.CSSProperties;
10
+ }
11
+
12
+ // Field-context-aware: renders nothing at all unless the nearest Field
13
+ // wrapper is actually invalid — unlike ErrorMessage, which always shows
14
+ // whatever you give it regardless of any validation state.
15
+ export default function FieldError({
16
+ children,
17
+ className,
18
+ style,
19
+ }: FieldErrorProps) {
20
+ const field = useFieldContext();
21
+ if (!field?.isInvalid) return null;
22
+ const message = children ?? field.errorMessage;
23
+ if (!message) return null;
24
+
25
+ return (
26
+ <div
27
+ id={field.errorId}
28
+ role="alert"
29
+ className={className}
30
+ style={{
31
+ fontSize: 12,
32
+ color: "var(--md-sys-color-error)",
33
+ ...style,
34
+ }}
35
+ >
36
+ {message}
37
+ </div>
38
+ );
39
+ }
@@ -0,0 +1,51 @@
1
+ export interface FieldsetProps {
2
+ /** Rendered as the <legend> — omit for a legend-less group (still a
3
+ * real <fieldset>, just with no visible heading). */
4
+ legend?: React.ReactNode;
5
+ isDisabled?: boolean;
6
+ children?: React.ReactNode;
7
+ className?: string;
8
+ style?: React.CSSProperties;
9
+ }
10
+
11
+ // Groups related fields under a shared <legend> — a real <fieldset>, so
12
+ // `disabled` on it natively disables every nested form control without
13
+ // each one needing its own isDisabled prop threaded through.
14
+ export default function Fieldset({
15
+ legend,
16
+ isDisabled = false,
17
+ children,
18
+ className,
19
+ style,
20
+ }: FieldsetProps) {
21
+ return (
22
+ <fieldset
23
+ disabled={isDisabled}
24
+ className={className}
25
+ style={{
26
+ display: "flex",
27
+ flexDirection: "column",
28
+ gap: 16,
29
+ border: "1px solid var(--globalUIBorderCard)",
30
+ borderRadius: "var(--borderRadius-md)",
31
+ padding: 16,
32
+ margin: 0,
33
+ ...style,
34
+ }}
35
+ >
36
+ {legend && (
37
+ <legend
38
+ style={{
39
+ padding: "0 6px",
40
+ fontSize: 16,
41
+ fontWeight: 600,
42
+ color: "var(--md-sys-color-on-surface)",
43
+ }}
44
+ >
45
+ {legend}
46
+ </legend>
47
+ )}
48
+ {children}
49
+ </fieldset>
50
+ );
51
+ }
@@ -0,0 +1,54 @@
1
+ "use client";
2
+ import React, { createContext, useContext } from "react";
3
+
4
+ export interface FormValidationErrors {
5
+ [fieldName: string]: string[];
6
+ }
7
+
8
+ const FormValidationContext = createContext<FormValidationErrors>({});
9
+
10
+ /** Consumed by TextField/NumberField/etc. when given a matching `name` —
11
+ * lets server-side validation errors flow down without each field needing
12
+ * its own isInvalid/errorMessage wired by hand. */
13
+ export function useFormFieldErrors(name?: string): string[] | undefined {
14
+ const errors = useContext(FormValidationContext);
15
+ return name ? errors[name] : undefined;
16
+ }
17
+
18
+ export interface FormProps {
19
+ onSubmit?: (
20
+ e: React.FormEvent<HTMLFormElement>,
21
+ data: FormData,
22
+ ) => void;
23
+ /** Field name → error messages, e.g. from a server response — made
24
+ * available to any field below with a matching `name` via
25
+ * useFormFieldErrors. */
26
+ validationErrors?: FormValidationErrors;
27
+ children?: React.ReactNode;
28
+ className?: string;
29
+ style?: React.CSSProperties;
30
+ }
31
+
32
+ export default function Form({
33
+ onSubmit,
34
+ validationErrors = {},
35
+ children,
36
+ className,
37
+ style,
38
+ }: FormProps) {
39
+ return (
40
+ <FormValidationContext.Provider value={validationErrors}>
41
+ <form
42
+ noValidate
43
+ onSubmit={(e) => {
44
+ e.preventDefault();
45
+ onSubmit?.(e, new FormData(e.currentTarget));
46
+ }}
47
+ className={className}
48
+ style={{ display: "flex", flexDirection: "column", gap: 16, ...style }}
49
+ >
50
+ {children}
51
+ </form>
52
+ </FormValidationContext.Provider>
53
+ );
54
+ }
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import React from "react";
3
+ import { useFieldContext } from "@/components/(forms)/shared/fieldContext";
4
+ import fieldStyles from "@/components/(forms)/shared/field.module.css";
5
+
6
+ export type InputVariant = "primary" | "secondary";
7
+
8
+ export interface InputProps
9
+ extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> {
10
+ variant?: InputVariant;
11
+ fullWidth?: boolean;
12
+ }
13
+
14
+ // Primitive single-line input — accepts all standard <input> attributes.
15
+ // For labels/descriptions/validation wiring, use TextField as the parent;
16
+ // standalone (outside a TextField) it just behaves like a plain input.
17
+ export default function Input({
18
+ variant = "primary",
19
+ fullWidth = false,
20
+ className,
21
+ style,
22
+ disabled,
23
+ id,
24
+ "aria-describedby": ariaDescribedBy,
25
+ ...props
26
+ }: InputProps) {
27
+ const field = useFieldContext();
28
+ const isDisabled = disabled ?? field?.isDisabled;
29
+ const isInvalid = field?.isInvalid;
30
+
31
+ const describedBy =
32
+ [field?.descriptionId, field && isInvalid ? field.errorId : null, ariaDescribedBy]
33
+ .filter(Boolean)
34
+ .join(" ") || undefined;
35
+
36
+ return (
37
+ <input
38
+ id={id ?? field?.id}
39
+ disabled={isDisabled}
40
+ required={field?.isRequired || props.required}
41
+ aria-invalid={isInvalid || undefined}
42
+ aria-describedby={describedBy}
43
+ data-variant={variant}
44
+ data-invalid={isInvalid || undefined}
45
+ className={[fieldStyles.field, className].filter(Boolean).join(" ")}
46
+ style={{ width: fullWidth ? "100%" : undefined, ...style }}
47
+ {...props}
48
+ />
49
+ );
50
+ }
@@ -0,0 +1,65 @@
1
+ import fieldStyles from "@/components/(forms)/shared/field.module.css";
2
+
3
+ export interface InputGroupProps {
4
+ /** Rendered before the input, e.g. an Icon or a currency symbol. */
5
+ startAddon?: React.ReactNode;
6
+ /** Rendered after the input, e.g. a unit label or a clear button. */
7
+ endAddon?: React.ReactNode;
8
+ children?: React.ReactNode;
9
+ className?: string;
10
+ style?: React.CSSProperties;
11
+ }
12
+
13
+ // Wraps an Input/TextArea with prefix/suffix addons inside the same
14
+ // bordered surface (rather than each addon getting its own box) — the
15
+ // addons sit inside the group's own border, the inner Input is styled
16
+ // borderless via [data-in-group] so there's only ever one visible edge.
17
+ export default function InputGroup({
18
+ startAddon,
19
+ endAddon,
20
+ children,
21
+ className,
22
+ style,
23
+ }: InputGroupProps) {
24
+ return (
25
+ <div
26
+ data-in-group="true"
27
+ className={`${className} ${fieldStyles.field}`}
28
+ style={{
29
+ display: "flex",
30
+ alignItems: "center",
31
+ gap: 8,
32
+ width: "100%",
33
+ boxSizing: "border-box",
34
+ boxShadow: "0 0 0 1px var(--globalUIBorderCard)",
35
+ borderRadius: "var(--borderRadius-md)",
36
+ padding: "0 12px",
37
+ ...style,
38
+ }}
39
+ >
40
+ {startAddon && (
41
+ <span
42
+ style={{
43
+ display: "flex",
44
+ flexShrink: 0,
45
+ color: "var(--md-sys-color-on-surface-variant)",
46
+ }}
47
+ >
48
+ {startAddon}
49
+ </span>
50
+ )}
51
+ <div style={{ flex: 1, minWidth: 0 }}>{children}</div>
52
+ {endAddon && (
53
+ <span
54
+ style={{
55
+ display: "flex",
56
+ flexShrink: 0,
57
+ color: "var(--md-sys-color-on-surface-variant)",
58
+ }}
59
+ >
60
+ {endAddon}
61
+ </span>
62
+ )}
63
+ </div>
64
+ );
65
+ }
@@ -0,0 +1,139 @@
1
+ "use client";
2
+ import React, { useId, useRef, useState } from "react";
3
+ import fieldStyles from "@/components/(forms)/shared/field.module.css";
4
+
5
+ export interface InputOtpProps {
6
+ length?: number;
7
+ value?: string;
8
+ defaultValue?: string;
9
+ onChange?: (value: string) => void;
10
+ /** Fired once, when every segment has been filled. */
11
+ onComplete?: (value: string) => void;
12
+ isDisabled?: boolean;
13
+ steps?: number;
14
+ isInvalid?: boolean;
15
+ /** Restricts each segment to a single digit. @default "text" */
16
+ type?: "text" | "number";
17
+ "aria-label"?: string;
18
+ className?: string;
19
+ style?: React.CSSProperties;
20
+ }
21
+
22
+ export default function InputOtp({
23
+ length = 6,
24
+ value: controlledValue,
25
+ defaultValue = "",
26
+ steps = 3,
27
+ onChange,
28
+ onComplete,
29
+ isDisabled = false,
30
+ isInvalid = false,
31
+ type = "text",
32
+ "aria-label": ariaLabel = "One-time code",
33
+ className,
34
+ style,
35
+ }: InputOtpProps) {
36
+ const isControlled = controlledValue !== undefined;
37
+ const [internalValue, setInternalValue] = useState(defaultValue);
38
+ const value = isControlled ? controlledValue : internalValue;
39
+ const chars = Array.from({ length }, (_, i) => value[i] ?? "");
40
+ const inputRefs = useRef<Array<HTMLInputElement | null>>([]);
41
+ const groupId = useId();
42
+
43
+ const commit = (next: string) => {
44
+ if (!isControlled) setInternalValue(next);
45
+ onChange?.(next);
46
+ if (next.length === length) onComplete?.(next);
47
+ };
48
+
49
+ const setChar = (index: number, char: string) => {
50
+ const next = chars.slice();
51
+ next[index] = char;
52
+ commit(next.join(""));
53
+ };
54
+
55
+ const handleChange = (index: number, raw: string) => {
56
+ const filtered = type === "number" ? raw.replace(/\D/g, "") : raw;
57
+ const char = filtered.slice(-1);
58
+ setChar(index, char);
59
+ if (char && index < length - 1) inputRefs.current[index + 1]?.focus();
60
+ };
61
+
62
+ const handleKeyDown = (index: number, e: React.KeyboardEvent) => {
63
+ if (e.key === "Backspace" && !chars[index] && index > 0) {
64
+ inputRefs.current[index - 1]?.focus();
65
+ setChar(index - 1, "");
66
+ } else if (e.key === "ArrowLeft" && index > 0) {
67
+ e.preventDefault();
68
+ inputRefs.current[index - 1]?.focus();
69
+ } else if (e.key === "ArrowRight" && index < length - 1) {
70
+ e.preventDefault();
71
+ inputRefs.current[index + 1]?.focus();
72
+ }
73
+ };
74
+
75
+ const handlePaste = (index: number, e: React.ClipboardEvent) => {
76
+ e.preventDefault();
77
+ const pasted = e.clipboardData.getData("text");
78
+ const filtered = type === "number" ? pasted.replace(/\D/g, "") : pasted;
79
+ if (!filtered) return;
80
+ const next = chars.slice();
81
+ for (let i = 0; i < filtered.length && index + i < length; i++) {
82
+ next[index + i] = filtered[i];
83
+ }
84
+ commit(next.join(""));
85
+ const lastFilled = Math.min(index + filtered.length, length) - 1;
86
+ inputRefs.current[Math.max(lastFilled, 0)]?.focus();
87
+ };
88
+
89
+ return (
90
+ <div
91
+ role="group"
92
+ aria-label={ariaLabel}
93
+ id={groupId}
94
+ className={className}
95
+ style={{ display: "flex", gap: 8, alignItems: "center", ...style }}
96
+ >
97
+ {chars.map((char, index) => (
98
+ <React.Fragment key={index}>
99
+ {index > 0 && steps && index % steps === 0 && (
100
+ <span
101
+ style={{
102
+ margin: "0 8px",
103
+ height: 2,
104
+ width: 12,
105
+ backgroundColor: "var(--md-sys-color-outline)",
106
+ }}
107
+ />
108
+ )}
109
+
110
+ <input
111
+ ref={(el) => {
112
+ inputRefs.current[index] = el;
113
+ }}
114
+ type="text"
115
+ inputMode={type === "number" ? "numeric" : "text"}
116
+ maxLength={1}
117
+ disabled={isDisabled}
118
+ aria-invalid={isInvalid || undefined}
119
+ aria-label={`Digit ${index + 1} of ${length}`}
120
+ value={char}
121
+ onChange={(e) => handleChange(index, e.target.value)}
122
+ onKeyDown={(e) => handleKeyDown(index, e)}
123
+ onPaste={(e) => handlePaste(index, e)}
124
+ data-invalid={isInvalid || undefined}
125
+ className={fieldStyles.field}
126
+ style={{
127
+ width: 36,
128
+ height: 48,
129
+ padding: 0,
130
+ textAlign: "center",
131
+ fontSize: 18,
132
+ fontWeight: 400,
133
+ }}
134
+ />
135
+ </React.Fragment>
136
+ ))}
137
+ </div>
138
+ );
139
+ }