@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.
- package/LICENSE +201 -201
- package/README.md +101 -101
- package/package.json +50 -50
- package/scripts/postinstall.js +91 -91
- package/template/app/ClientNav.tsx +258 -310
- package/template/app/globals.css +2 -167
- package/template/app/layout.tsx +94 -82
- package/template/app/themes/dark-mc.css +51 -51
- package/template/app/themes/dark.css +51 -51
- package/template/app/themes/light-mc.css +51 -51
- package/template/app/themes/light.css +51 -51
- package/template/app/themes/theme.css +272 -82
- package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
- package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
- package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
- package/template/components/(buttons)/button.tsx +164 -0
- package/template/components/(controls)/slider/Slider.module.css +250 -0
- package/template/components/(controls)/slider/Slider.tsx +386 -0
- package/template/components/{layout → (controls)}/switch/Switch.module.css +108 -102
- package/template/components/{layout → (controls)}/switch/Switch.tsx +69 -48
- package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
- package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
- package/template/components/(date & time)/dateField/DateField.module.css +25 -0
- package/template/components/(date & time)/dateField/DateField.tsx +193 -0
- package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
- package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
- package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
- package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
- package/template/components/(date & time)/shared/dateUtils.ts +107 -0
- package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
- package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
- package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
- package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
- package/template/components/(feedback)/meter/Meter.tsx +111 -0
- package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
- package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
- package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
- package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
- package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
- package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
- package/template/components/(forms)/description/Description.tsx +34 -0
- package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
- package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
- package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
- package/template/components/(forms)/form/Form.tsx +54 -0
- package/template/components/(forms)/input/Input.tsx +50 -0
- package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
- package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
- package/template/components/(forms)/label/Label.tsx +46 -0
- package/template/components/(forms)/numberField/NumberField.tsx +292 -0
- package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
- package/template/components/(forms)/searchField/SearchField.tsx +139 -0
- package/template/components/(forms)/shared/field.module.css +75 -0
- package/template/components/(forms)/shared/fieldContext.ts +28 -0
- package/template/components/(forms)/textArea/TextArea.tsx +55 -0
- package/template/components/(forms)/textField/TextField.tsx +91 -0
- package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
- package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
- package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
- package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
- package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
- package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
- package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
- package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
- package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
- package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
- package/template/components/(layout)/accordion/Accordion.module.css +108 -0
- package/template/components/(layout)/accordion/Accordion.tsx +251 -0
- package/template/components/(layout)/card/Card.module.css +136 -0
- package/template/components/(layout)/card/Card.tsx +371 -0
- package/template/components/(layout)/list/List.module.css +83 -0
- package/template/components/(layout)/list/List.tsx +332 -0
- package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
- package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
- package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
- package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
- package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
- package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
- package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
- package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
- package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
- package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
- package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
- package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
- package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
- package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
- package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
- package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -473
- package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
- package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
- package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
- package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
- package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
- package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
- package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
- package/template/components/(layout)/separator/Separator.tsx +112 -0
- package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
- package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
- package/template/components/(overlays)/modal/Modal.tsx +654 -0
- package/template/components/(overlays)/popover/Popover.tsx +420 -0
- package/template/components/(overlays)/toast/Toast.tsx +692 -0
- package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
- package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
- package/template/components/(pickers)/select/Select.tsx +188 -0
- package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
- package/template/components/(pickers)/shared/PickerItem.ts +13 -0
- package/template/components/tools/CustomScrollbar.tsx +107 -0
- package/template/components/tools/Divider.tsx +11 -11
- package/template/components/tools/ReduceMotionContext.tsx +5 -5
- package/template/components/tools/Sinewave.tsx +396 -199
- package/template/components/tools/SinewaveProgress.tsx +140 -135
- package/template/components/tools/badge/Badge.tsx +28 -28
- package/template/components/tools/dropdown/drop.module.css +196 -0
- package/template/components/tools/dropdown/drop.tsx +568 -0
- package/template/components/tools/easing.ts +118 -0
- package/template/components/tools/flubber.d.ts +6 -6
- package/template/components/tools/footer/Footer.tsx +20 -0
- package/template/components/tools/input/Input.module.css +45 -0
- package/template/components/tools/input/Input.tsx +99 -0
- package/template/components/tools/label/Icon.tsx +39 -0
- package/template/components/tools/label/Label.tsx +156 -0
- package/template/components/tools/mobileViewProvider.tsx +53 -58
- package/template/components/tools/ripple/ripple.css +38 -41
- package/template/components/tools/ripple/ripple.tsx +78 -53
- package/template/components/tools/shape/Shape.module.css +25 -0
- package/template/components/tools/shape/{ShapeMorph.tsx → Shape.tsx} +316 -190
- package/template/components/tools/shape/ShapeLoader.tsx +104 -101
- package/template/components/tools/shape/ShapePaths.ts +116 -116
- package/template/components/tools/switch/Switch.module.css +102 -102
- package/template/components/tools/switch/Switch.tsx +48 -48
- package/template/components/tools/useBodyScrollLock.tsx +27 -27
- package/template/components/tools/useImageColor.ts +47 -47
- package/template/components/tools/useNavSheetDrag.tsx +196 -196
- package/template/components/layout/accordion/Accordion.module.css +0 -149
- package/template/components/layout/accordion/Accordion.tsx +0 -114
- package/template/components/layout/button/button.tsx +0 -128
- package/template/components/layout/button/drop.module.css +0 -229
- package/template/components/layout/button/drop.tsx +0 -516
- package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
- package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
- package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
- package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
- package/template/components/layout/modals/alert/Alert.tsx +0 -188
- package/template/components/layout/navigation/MioCard.module.css +0 -88
- package/template/components/layout/navigation/MioCard.tsx +0 -266
- package/template/components/tools/ProgressiveBlur.tsx +0 -73
- package/template/components/tools/icon/icon.module.css +0 -0
- package/template/components/tools/icon/icon.tsx +0 -125
- package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
- package/template/components/tools/react-bits/FadeContent.tsx +0 -90
- package/template/components/tools/react-bits/GlareHover.tsx +0 -73
- package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
- package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
- package/template/components/tools/react-bits/Magnet.tsx +0 -118
- package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
- 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
|
+
}
|