@yamatozhen/design_system 1.0.1 → 1.2.1

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 (156) 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.css +51 -51
  9. package/template/app/themes/dark.css +51 -51
  10. package/template/app/themes/light-mc.css +51 -51
  11. package/template/app/themes/light.css +51 -51
  12. package/template/app/themes/theme.css +272 -82
  13. package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
  14. package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
  15. package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
  16. package/template/components/(buttons)/button.tsx +164 -0
  17. package/template/components/(controls)/slider/Slider.module.css +250 -0
  18. package/template/components/(controls)/slider/Slider.tsx +386 -0
  19. package/template/components/{layout → (controls)}/switch/Switch.module.css +108 -102
  20. package/template/components/{layout → (controls)}/switch/Switch.tsx +69 -48
  21. package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
  22. package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
  23. package/template/components/(date & time)/dateField/DateField.module.css +25 -0
  24. package/template/components/(date & time)/dateField/DateField.tsx +193 -0
  25. package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
  26. package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
  27. package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
  28. package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
  29. package/template/components/(date & time)/shared/dateUtils.ts +107 -0
  30. package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
  31. package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
  32. package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
  33. package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
  34. package/template/components/(feedback)/meter/Meter.tsx +111 -0
  35. package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
  36. package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
  37. package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
  38. package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
  39. package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
  40. package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
  41. package/template/components/(forms)/description/Description.tsx +34 -0
  42. package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
  43. package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
  44. package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
  45. package/template/components/(forms)/form/Form.tsx +54 -0
  46. package/template/components/(forms)/input/Input.tsx +50 -0
  47. package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
  48. package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
  49. package/template/components/(forms)/label/Label.tsx +46 -0
  50. package/template/components/(forms)/numberField/NumberField.tsx +292 -0
  51. package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
  52. package/template/components/(forms)/searchField/SearchField.tsx +139 -0
  53. package/template/components/(forms)/shared/field.module.css +75 -0
  54. package/template/components/(forms)/shared/fieldContext.ts +28 -0
  55. package/template/components/(forms)/textArea/TextArea.tsx +55 -0
  56. package/template/components/(forms)/textField/TextField.tsx +91 -0
  57. package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
  58. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
  59. package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
  60. package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
  61. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
  62. package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
  63. package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
  64. package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
  65. package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
  66. package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
  67. package/template/components/(layout)/accordion/Accordion.module.css +108 -0
  68. package/template/components/(layout)/accordion/Accordion.tsx +251 -0
  69. package/template/components/(layout)/card/Card.module.css +136 -0
  70. package/template/components/(layout)/card/Card.tsx +371 -0
  71. package/template/components/(layout)/list/List.module.css +83 -0
  72. package/template/components/(layout)/list/List.tsx +332 -0
  73. package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
  74. package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
  75. package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
  76. package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
  77. package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
  78. package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
  79. package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
  80. package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
  81. package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
  82. package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
  83. package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
  84. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
  85. package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
  86. package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
  87. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
  88. package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -473
  89. package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
  90. package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
  91. package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
  92. package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
  93. package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
  94. package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
  95. package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
  96. package/template/components/(layout)/separator/Separator.tsx +112 -0
  97. package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
  98. package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
  99. package/template/components/(overlays)/modal/Modal.tsx +654 -0
  100. package/template/components/(overlays)/popover/Popover.tsx +420 -0
  101. package/template/components/(overlays)/toast/Toast.tsx +692 -0
  102. package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
  103. package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
  104. package/template/components/(pickers)/select/Select.tsx +188 -0
  105. package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
  106. package/template/components/(pickers)/shared/PickerItem.ts +13 -0
  107. package/template/components/tools/CustomScrollbar.tsx +107 -0
  108. package/template/components/tools/Divider.tsx +11 -11
  109. package/template/components/tools/ReduceMotionContext.tsx +5 -5
  110. package/template/components/tools/Sinewave.tsx +396 -199
  111. package/template/components/tools/SinewaveProgress.tsx +140 -135
  112. package/template/components/tools/badge/Badge.tsx +28 -28
  113. package/template/components/tools/dropdown/drop.module.css +196 -0
  114. package/template/components/tools/dropdown/drop.tsx +568 -0
  115. package/template/components/tools/easing.ts +118 -0
  116. package/template/components/tools/flubber.d.ts +6 -6
  117. package/template/components/tools/footer/Footer.tsx +20 -0
  118. package/template/components/tools/input/Input.module.css +45 -0
  119. package/template/components/tools/input/Input.tsx +99 -0
  120. package/template/components/tools/label/Icon.tsx +39 -0
  121. package/template/components/tools/label/Label.tsx +156 -0
  122. package/template/components/tools/mobileViewProvider.tsx +53 -58
  123. package/template/components/tools/ripple/ripple.css +38 -41
  124. package/template/components/tools/ripple/ripple.tsx +78 -53
  125. package/template/components/tools/shape/Shape.module.css +25 -0
  126. package/template/components/tools/shape/{ShapeMorph.tsx → Shape.tsx} +316 -190
  127. package/template/components/tools/shape/ShapeLoader.tsx +104 -101
  128. package/template/components/tools/shape/ShapePaths.ts +116 -116
  129. package/template/components/tools/switch/Switch.module.css +102 -102
  130. package/template/components/tools/switch/Switch.tsx +48 -48
  131. package/template/components/tools/useBodyScrollLock.tsx +27 -27
  132. package/template/components/tools/useImageColor.ts +47 -47
  133. package/template/components/tools/useNavSheetDrag.tsx +196 -196
  134. package/template/components/layout/accordion/Accordion.module.css +0 -149
  135. package/template/components/layout/accordion/Accordion.tsx +0 -114
  136. package/template/components/layout/button/button.tsx +0 -128
  137. package/template/components/layout/button/drop.module.css +0 -229
  138. package/template/components/layout/button/drop.tsx +0 -516
  139. package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
  140. package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
  141. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
  142. package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
  143. package/template/components/layout/modals/alert/Alert.tsx +0 -188
  144. package/template/components/layout/navigation/MioCard.module.css +0 -88
  145. package/template/components/layout/navigation/MioCard.tsx +0 -266
  146. package/template/components/tools/ProgressiveBlur.tsx +0 -73
  147. package/template/components/tools/icon/icon.module.css +0 -0
  148. package/template/components/tools/icon/icon.tsx +0 -125
  149. package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
  150. package/template/components/tools/react-bits/FadeContent.tsx +0 -90
  151. package/template/components/tools/react-bits/GlareHover.tsx +0 -73
  152. package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
  153. package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
  154. package/template/components/tools/react-bits/Magnet.tsx +0 -118
  155. package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
  156. package/template/components/tools/react-bits/Stepper/Stepper.tsx +0 -412
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ import { useFieldContext } from "@/components/(forms)/shared/fieldContext";
3
+
4
+ export interface FieldLabelProps {
5
+ children?: React.ReactNode;
6
+ className?: string;
7
+ style?: React.CSSProperties;
8
+ }
9
+
10
+ // Named FieldLabel (not Label) to avoid colliding with
11
+ // components/tools/label/Label.tsx — an unrelated, pre-existing
12
+ // icon+text swap-animated label used inside buttons. Same name,
13
+ // completely different component; don't confuse the two.
14
+ export default function FieldLabel({
15
+ children,
16
+ className,
17
+ style,
18
+ }: FieldLabelProps) {
19
+ const field = useFieldContext();
20
+ return (
21
+ <label
22
+ htmlFor={field?.id}
23
+ id={field?.labelId}
24
+ className={className}
25
+ style={{
26
+ fontSize: 14,
27
+ fontWeight: 500,
28
+ color: "var(--md-sys-color-on-surface)",
29
+ display: "inline-flex",
30
+ alignItems: "center",
31
+ gap: 4,
32
+ ...style,
33
+ }}
34
+ >
35
+ {children}
36
+ {field?.isRequired && (
37
+ <span
38
+ aria-hidden
39
+ style={{ color: "var(--md-sys-color-error)" }}
40
+ >
41
+ *
42
+ </span>
43
+ )}
44
+ </label>
45
+ );
46
+ }
@@ -0,0 +1,292 @@
1
+ "use client";
2
+ import React, { createContext, useContext, useId, useState } from "react";
3
+ import Icon from "@/components/tools/label/Icon";
4
+ import {
5
+ FieldContext,
6
+ type FieldContextValue,
7
+ } from "@/components/(forms)/shared/fieldContext";
8
+ import fieldStyles from "@/components/(forms)/shared/field.module.css";
9
+ import Button from "@/components/(buttons)/button";
10
+
11
+ export type NumberFieldVariant = "primary" | "secondary";
12
+
13
+ export interface NumberFieldProps {
14
+ value?: number;
15
+ defaultValue?: number;
16
+ onChange?: (value: number) => void;
17
+ minValue?: number;
18
+ maxValue?: number;
19
+ step?: number;
20
+ formatOptions?: Intl.NumberFormatOptions;
21
+ isDisabled?: boolean;
22
+ isRequired?: boolean;
23
+ isInvalid?: boolean;
24
+ errorMessage?: string;
25
+ variant?: NumberFieldVariant;
26
+ fullWidth?: boolean;
27
+ id?: string;
28
+ children?: React.ReactNode;
29
+ className?: string;
30
+ style?: React.CSSProperties;
31
+ }
32
+
33
+ interface NumberFieldContextValue {
34
+ rawText: string;
35
+ isFocused: boolean;
36
+ onFocus: () => void;
37
+ onBlur: () => void;
38
+ onRawChange: (text: string) => void;
39
+ increment: () => void;
40
+ decrement: () => void;
41
+ canIncrement: boolean;
42
+ canDecrement: boolean;
43
+ variant: NumberFieldVariant;
44
+ }
45
+
46
+ const NumberFieldContext = createContext<NumberFieldContextValue | null>(null);
47
+ function useNumberFieldContext(component: string) {
48
+ const ctx = useContext(NumberFieldContext);
49
+ if (!ctx) {
50
+ throw new Error(
51
+ `<NumberField.${component}> must be rendered inside <NumberField>`,
52
+ );
53
+ }
54
+ return ctx;
55
+ }
56
+
57
+ function clampToStep(n: number, min: number, step: number) {
58
+ return min + Math.round((n - min) / step) * step;
59
+ }
60
+
61
+ function NumberField({
62
+ value: controlledValue,
63
+ defaultValue = 0,
64
+ onChange,
65
+ minValue = -Infinity,
66
+ maxValue = Infinity,
67
+ step = 1,
68
+ formatOptions,
69
+ isDisabled = false,
70
+ isRequired = false,
71
+ isInvalid = false,
72
+ errorMessage,
73
+ variant = "primary",
74
+ fullWidth = false,
75
+ id,
76
+ children,
77
+ className,
78
+ style,
79
+ }: NumberFieldProps) {
80
+ const generatedId = useId();
81
+ const fieldId = id ?? generatedId;
82
+ const isControlled = controlledValue !== undefined;
83
+ const [internalValue, setInternalValue] = useState(defaultValue);
84
+ const value = isControlled ? controlledValue : internalValue;
85
+
86
+ const format = (n: number) =>
87
+ new Intl.NumberFormat(undefined, formatOptions).format(n);
88
+
89
+ const [isFocused, setIsFocused] = useState(false);
90
+ const [rawText, setRawText] = useState(() => format(value));
91
+
92
+ const commit = (next: number) => {
93
+ const clamped = Math.min(
94
+ maxValue,
95
+ Math.max(
96
+ minValue,
97
+ clampToStep(next, minValue === -Infinity ? 0 : minValue, step),
98
+ ),
99
+ );
100
+ if (!isControlled) setInternalValue(clamped);
101
+ onChange?.(clamped);
102
+ setRawText(format(clamped));
103
+ };
104
+
105
+ const numberFieldContext: NumberFieldContextValue = {
106
+ rawText: isFocused ? rawText : format(value),
107
+ isFocused,
108
+ onFocus: () => {
109
+ setIsFocused(true);
110
+ setRawText(String(value));
111
+ },
112
+ onBlur: () => {
113
+ setIsFocused(false);
114
+ const parsed = parseFloat(rawText);
115
+ commit(Number.isFinite(parsed) ? parsed : value);
116
+ },
117
+ onRawChange: setRawText,
118
+ increment: () => commit(value + step),
119
+ decrement: () => commit(value - step),
120
+ canIncrement: value < maxValue,
121
+ canDecrement: value > minValue,
122
+ variant,
123
+ };
124
+
125
+ const fieldContextValue: FieldContextValue = {
126
+ id: fieldId,
127
+ labelId: `${fieldId}-label`,
128
+ descriptionId: `${fieldId}-description`,
129
+ errorId: `${fieldId}-error`,
130
+ isDisabled,
131
+ isInvalid,
132
+ isRequired,
133
+ errorMessage,
134
+ };
135
+
136
+ return (
137
+ <FieldContext.Provider value={fieldContextValue}>
138
+ <NumberFieldContext.Provider value={numberFieldContext}>
139
+ <div
140
+ data-invalid={isInvalid || undefined}
141
+ data-disabled={isDisabled || undefined}
142
+ className={className}
143
+ style={{
144
+ display: "flex",
145
+ flexDirection: "column",
146
+ gap: 4,
147
+ width: fullWidth ? "100%" : undefined,
148
+ ...style,
149
+ }}
150
+ >
151
+ {children}
152
+ </div>
153
+ </NumberFieldContext.Provider>
154
+ </FieldContext.Provider>
155
+ );
156
+ }
157
+
158
+ function NumberFieldGroup({
159
+ children,
160
+ className,
161
+ style,
162
+ }: {
163
+ children?: React.ReactNode;
164
+ className?: string;
165
+ style?: React.CSSProperties;
166
+ }) {
167
+ const { variant } = useNumberFieldContext("Group");
168
+ return (
169
+ <div
170
+ data-variant={variant}
171
+ className={[fieldStyles.field, className].filter(Boolean).join(" ")}
172
+ style={{
173
+ display: "flex",
174
+ alignItems: "center",
175
+ padding: 0,
176
+ overflow: "hidden",
177
+ ...style,
178
+ }}
179
+ >
180
+ {children}
181
+ </div>
182
+ );
183
+ }
184
+
185
+ function NumberFieldInput({
186
+ className,
187
+ style,
188
+ }: {
189
+ className?: string;
190
+ style?: React.CSSProperties;
191
+ }) {
192
+ const field = useContext(FieldContext);
193
+ const { rawText, onFocus, onBlur, onRawChange } =
194
+ useNumberFieldContext("Input");
195
+ return (
196
+ <input
197
+ id={field?.id}
198
+ type="text"
199
+ inputMode="decimal"
200
+ disabled={field?.isDisabled}
201
+ required={field?.isRequired}
202
+ aria-invalid={field?.isInvalid || undefined}
203
+ value={rawText}
204
+ onFocus={onFocus}
205
+ onBlur={onBlur}
206
+ onChange={(e) => onRawChange(e.target.value)}
207
+ className={className}
208
+ style={{
209
+ flex: 1,
210
+ minWidth: 60,
211
+ border: "none",
212
+ background: "transparent",
213
+ fontSize: 14,
214
+ padding: "0 4px",
215
+ fontFamily: "inherit",
216
+ color: "inherit",
217
+ outline: "none",
218
+ textAlign: "right",
219
+ ...style,
220
+ }}
221
+ />
222
+ );
223
+ }
224
+
225
+ function stepButtonStyle(disabled: boolean): React.CSSProperties {
226
+ return {
227
+ borderRadius: 60,
228
+ padding: 0,
229
+ maxWidth: 36,
230
+ minWidth: 36,
231
+ minHeight: 36,
232
+ maxHeight: 36,
233
+ margin: 4,
234
+ };
235
+ }
236
+
237
+ function NumberFieldIncrementButton({
238
+ children,
239
+ className,
240
+ }: {
241
+ children?: React.ReactNode;
242
+ className?: string;
243
+ }) {
244
+ const field = useContext(FieldContext);
245
+ const { increment, canIncrement } = useNumberFieldContext("IncrementButton");
246
+ const disabled = field?.isDisabled || !canIncrement;
247
+ return (
248
+ <Button
249
+ type="button"
250
+ variant="text"
251
+ aria-label="Increment"
252
+ disabled={disabled}
253
+ onClick={increment}
254
+ className={className}
255
+ style={{ borderRadius: "60px !important", ...stepButtonStyle(disabled) }}
256
+ >
257
+ {children ?? <Icon systemName="add" />}
258
+ </Button>
259
+ );
260
+ }
261
+
262
+ function NumberFieldDecrementButton({
263
+ children,
264
+ className,
265
+ }: {
266
+ children?: React.ReactNode;
267
+ className?: string;
268
+ }) {
269
+ const field = useContext(FieldContext);
270
+ const { decrement, canDecrement } = useNumberFieldContext("DecrementButton");
271
+ const disabled = field?.isDisabled || !canDecrement;
272
+ return (
273
+ <Button
274
+ variant="text"
275
+ type="button"
276
+ aria-label="Decrement"
277
+ disabled={disabled}
278
+ onClick={decrement}
279
+ className={className}
280
+ style={stepButtonStyle(disabled)}
281
+ >
282
+ {children ?? <Icon systemName="remove" />}
283
+ </Button>
284
+ );
285
+ }
286
+
287
+ export default Object.assign(NumberField, {
288
+ Group: NumberFieldGroup,
289
+ Input: NumberFieldInput,
290
+ IncrementButton: NumberFieldIncrementButton,
291
+ DecrementButton: NumberFieldDecrementButton,
292
+ });
@@ -0,0 +1,175 @@
1
+ "use client";
2
+ import React, { createContext, useContext, useId, useState } from "react";
3
+
4
+ export type RadioVariant = "primary" | "secondary" | "tertiary";
5
+
6
+ interface RadioGroupContextValue {
7
+ selectedValue: string | undefined;
8
+ select: (value: string) => void;
9
+ isDisabled: boolean;
10
+ variant: RadioVariant;
11
+ name: string;
12
+ }
13
+ const RadioGroupContext = createContext<RadioGroupContextValue | null>(null);
14
+ function useRadioGroupContext() {
15
+ const ctx = useContext(RadioGroupContext);
16
+ if (!ctx) {
17
+ throw new Error("<RadioGroup.Radio> must be rendered inside <RadioGroup>");
18
+ }
19
+ return ctx;
20
+ }
21
+
22
+ export interface RadioGroupProps {
23
+ value?: string;
24
+ defaultValue?: string;
25
+ onChange?: (value: string) => void;
26
+ isDisabled?: boolean;
27
+ variant?: RadioVariant;
28
+ /** Falls back to a generated id — set explicitly only if you need it to
29
+ * match a specific <form> field name. */
30
+ name?: string;
31
+ label?: string;
32
+ orientation?: "vertical" | "horizontal";
33
+ children?: React.ReactNode;
34
+ className?: string;
35
+ style?: React.CSSProperties;
36
+ }
37
+
38
+ function RadioGroup({
39
+ value: controlledValue,
40
+ defaultValue,
41
+ onChange,
42
+ isDisabled = false,
43
+ variant = "primary",
44
+ name,
45
+ label,
46
+ orientation = "vertical",
47
+ children,
48
+ className,
49
+ style,
50
+ }: RadioGroupProps) {
51
+ const generatedName = useId();
52
+ const isControlled = controlledValue !== undefined;
53
+ const [internalValue, setInternalValue] = useState(defaultValue);
54
+ const selectedValue = isControlled ? controlledValue : internalValue;
55
+ const labelId = useId();
56
+
57
+ const select = (next: string) => {
58
+ if (!isControlled) setInternalValue(next);
59
+ onChange?.(next);
60
+ };
61
+
62
+ return (
63
+ <RadioGroupContext.Provider
64
+ value={{
65
+ selectedValue,
66
+ select,
67
+ isDisabled,
68
+ variant,
69
+ name: name ?? generatedName,
70
+ }}
71
+ >
72
+ <div
73
+ role="radiogroup"
74
+ aria-labelledby={label ? labelId : undefined}
75
+ className={className}
76
+ style={{
77
+ display: "flex",
78
+ flexDirection: orientation === "vertical" ? "column" : "row",
79
+ gap: orientation === "vertical" ? 8 : 16,
80
+ ...style,
81
+ }}
82
+ >
83
+ {label && (
84
+ <span
85
+ id={labelId}
86
+ style={{
87
+ fontSize: 14,
88
+ fontWeight: 500,
89
+ color: "var(--md-sys-color-on-surface)",
90
+ }}
91
+ >
92
+ {label}
93
+ </span>
94
+ )}
95
+ {children}
96
+ </div>
97
+ </RadioGroupContext.Provider>
98
+ );
99
+ }
100
+
101
+ export interface RadioProps {
102
+ value: string;
103
+ isDisabled?: boolean;
104
+ children?: React.ReactNode;
105
+ className?: string;
106
+ style?: React.CSSProperties;
107
+ }
108
+
109
+ function Radio({ value, isDisabled, children, className, style }: RadioProps) {
110
+ const group = useRadioGroupContext();
111
+ const id = useId();
112
+ const isSelected = group.selectedValue === value;
113
+ const disabled = isDisabled ?? group.isDisabled;
114
+
115
+ return (
116
+ <label
117
+ htmlFor={id}
118
+ className={className}
119
+ style={{
120
+ display: "inline-flex",
121
+ alignItems: "center",
122
+ gap: 8,
123
+ cursor: disabled ? "not-allowed" : "pointer",
124
+ opacity: disabled ? 0.5 : 1,
125
+ ...style,
126
+ }}
127
+ >
128
+ <input
129
+ id={id}
130
+ type="radio"
131
+ name={group.name}
132
+ checked={isSelected}
133
+ disabled={disabled}
134
+ onChange={() => group.select(value)}
135
+ style={{ position: "absolute", opacity: 0, width: 0, height: 0 }}
136
+ />
137
+ <span
138
+ aria-hidden
139
+ style={{
140
+ display: "flex",
141
+ alignItems: "center",
142
+ justifyContent: "center",
143
+ width: 20,
144
+ height: 20,
145
+ flexShrink: 0,
146
+ borderRadius: "50%",
147
+ border: `2px solid ${
148
+ isSelected
149
+ ? `var(--md-sys-color-${group.variant})`
150
+ : "var(--md-sys-color-outline)"
151
+ }`,
152
+ transition: "border-color var(--transition-expressive-color)",
153
+ }}
154
+ >
155
+ {isSelected && (
156
+ <span
157
+ style={{
158
+ width: 10,
159
+ height: 10,
160
+ borderRadius: "50%",
161
+ backgroundColor: `var(--md-sys-color-${group.variant})`,
162
+ }}
163
+ />
164
+ )}
165
+ </span>
166
+ {children && (
167
+ <span style={{ fontSize: 14, color: "var(--md-sys-color-on-surface)" }}>
168
+ {children}
169
+ </span>
170
+ )}
171
+ </label>
172
+ );
173
+ }
174
+
175
+ export default Object.assign(RadioGroup, { Radio });
@@ -0,0 +1,139 @@
1
+ "use client";
2
+ import React, { useId, useState } from "react";
3
+ import Icon from "@/components/tools/label/Icon";
4
+ import {
5
+ FieldContext,
6
+ type FieldContextValue,
7
+ } from "@/components/(forms)/shared/fieldContext";
8
+ import fieldStyles from "@/components/(forms)/shared/field.module.css";
9
+ import Button from "@/components/(buttons)/button";
10
+
11
+ export interface SearchFieldProps {
12
+ value?: string;
13
+ defaultValue?: string;
14
+ onChange?: (value: string) => void;
15
+ /** Fired when the value is cleared, either via the built-in clear
16
+ * button or Escape. */
17
+ onClear?: () => void;
18
+ placeholder?: string;
19
+ isDisabled?: boolean;
20
+ isRequired?: boolean;
21
+ fullWidth?: boolean;
22
+ "aria-label"?: string;
23
+ id?: string;
24
+ className?: string;
25
+ style?: React.CSSProperties;
26
+ }
27
+
28
+ // A self-contained Field — unlike TextField, this doesn't take
29
+ // Label/Input as children, since a search box's search icon + clear
30
+ // button are integral to it, not optional composition.
31
+ export default function SearchField({
32
+ value: controlledValue,
33
+ defaultValue = "",
34
+ onChange,
35
+ onClear,
36
+ placeholder = "Search",
37
+ isDisabled = false,
38
+ isRequired = false,
39
+ fullWidth = false,
40
+ "aria-label": ariaLabel,
41
+ id,
42
+ className,
43
+ style,
44
+ }: SearchFieldProps) {
45
+ const generatedId = useId();
46
+ const fieldId = id ?? generatedId;
47
+ const isControlled = controlledValue !== undefined;
48
+ const [internalValue, setInternalValue] = useState(defaultValue);
49
+ const value = isControlled ? controlledValue : internalValue;
50
+
51
+ const setValue = (next: string) => {
52
+ if (!isControlled) setInternalValue(next);
53
+ onChange?.(next);
54
+ };
55
+ const clear = () => {
56
+ setValue("");
57
+ onClear?.();
58
+ };
59
+
60
+ const fieldContextValue: FieldContextValue = {
61
+ id: fieldId,
62
+ labelId: `${fieldId}-label`,
63
+ descriptionId: `${fieldId}-description`,
64
+ errorId: `${fieldId}-error`,
65
+ isDisabled,
66
+ isInvalid: false,
67
+ isRequired,
68
+ };
69
+
70
+ return (
71
+ <FieldContext.Provider value={fieldContextValue}>
72
+ <div
73
+ className={`${className}`}
74
+ style={{
75
+ position: "relative",
76
+ display: "flex",
77
+ alignItems: "center",
78
+ width: fullWidth ? "100%" : undefined,
79
+ ...style,
80
+ }}
81
+ >
82
+ <Icon
83
+ systemName="search"
84
+ style={{
85
+ position: "absolute",
86
+ marginLeft: 18,
87
+ }}
88
+ />
89
+ <input
90
+ id={fieldId}
91
+ type="search"
92
+ role="searchbox"
93
+ disabled={isDisabled}
94
+ required={isRequired}
95
+ aria-label={ariaLabel ?? "Search"}
96
+ placeholder={placeholder}
97
+ value={value}
98
+ onChange={(e) => setValue(e.target.value)}
99
+ onKeyDown={(e) => {
100
+ if (e.key === "Escape" && value) clear();
101
+ }}
102
+ className={fieldStyles.field}
103
+ style={{
104
+ padding: "18px 52px",
105
+ minHeight: 60,
106
+ borderRadius: "var(--borderRadius-l)",
107
+ background: "var(--md-sys-color-surface-container-lowest)",
108
+ fontSize: 14,
109
+ boxShadow:
110
+ " 0 0 0 1px var(--globalUIBorder), 0 1px 1px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.1)",
111
+ }}
112
+ />
113
+ {value && (
114
+ <Button
115
+ type="button"
116
+ aria-label="Clear search"
117
+ onClick={clear}
118
+ variant="text"
119
+ style={{
120
+ position: "absolute",
121
+ right: 8,
122
+ top: 8,
123
+ borderRadius: "var(--borderRadius-xl)",
124
+ cursor: "pointer",
125
+ padding: 0,
126
+ maxWidth: 36,
127
+ minWidth: 36,
128
+ minHeight: 36,
129
+ maxHeight: 36,
130
+ margin: 4,
131
+ }}
132
+ >
133
+ <Icon systemName="close" style={{ fontSize: 24 }} />
134
+ </Button>
135
+ )}
136
+ </div>
137
+ </FieldContext.Provider>
138
+ );
139
+ }