@spatika/react 1.1.0 → 1.3.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.
- package/AGENTS.md +71 -0
- package/README.md +4 -3
- package/dist/composites/Card.d.ts +7 -1
- package/dist/composites/Card.d.ts.map +1 -1
- package/dist/composites/Card.js +10 -0
- package/dist/composites/ChartDataGrid.d.ts +33 -0
- package/dist/composites/ChartDataGrid.d.ts.map +1 -0
- package/dist/composites/ChartDataGrid.js +77 -0
- package/dist/composites/CoverHero.d.ts +1 -1
- package/dist/composites/CoverHero.d.ts.map +1 -1
- package/dist/composites/CoverHero.js +2 -2
- package/dist/composites/EntityMediaCard.d.ts +1 -1
- package/dist/composites/EntityMediaCard.d.ts.map +1 -1
- package/dist/composites/EntityMediaCard.js +12 -4
- package/dist/composites/EventCalendar.d.ts +72 -0
- package/dist/composites/EventCalendar.d.ts.map +1 -0
- package/dist/composites/EventCalendar.js +371 -0
- package/dist/composites/EventEditor.d.ts +22 -0
- package/dist/composites/EventEditor.d.ts.map +1 -0
- package/dist/composites/EventEditor.js +86 -0
- package/dist/composites/EventTimeline.d.ts +29 -0
- package/dist/composites/EventTimeline.d.ts.map +1 -0
- package/dist/composites/EventTimeline.js +186 -0
- package/dist/composites/MapChart.d.ts +24 -0
- package/dist/composites/MapChart.d.ts.map +1 -0
- package/dist/composites/MapChart.js +58 -0
- package/dist/composites/ProfileHero.d.ts +6 -4
- package/dist/composites/ProfileHero.d.ts.map +1 -1
- package/dist/composites/ProfileHero.js +8 -8
- package/dist/composites/ScatterWebGL.d.ts +22 -0
- package/dist/composites/ScatterWebGL.d.ts.map +1 -0
- package/dist/composites/ScatterWebGL.js +45 -0
- package/dist/composites/SiteFooter.d.ts +1 -1
- package/dist/composites/SiteFooter.js +1 -1
- package/dist/composites/SiteNav.d.ts +7 -2
- package/dist/composites/SiteNav.d.ts.map +1 -1
- package/dist/composites/SiteNav.js +9 -5
- package/dist/composites/StatCard.d.ts +2 -1
- package/dist/composites/StatCard.d.ts.map +1 -1
- package/dist/composites/StatCard.js +3 -3
- package/dist/composites/StatusDot.d.ts +1 -1
- package/dist/composites/Wordmark.d.ts +2 -2
- package/dist/composites/Wordmark.d.ts.map +1 -1
- package/dist/composites/cartesian-charts.d.ts +138 -0
- package/dist/composites/cartesian-charts.d.ts.map +1 -0
- package/dist/composites/cartesian-charts.js +401 -0
- package/dist/composites/chart-composition.d.ts +139 -0
- package/dist/composites/chart-composition.d.ts.map +1 -0
- package/dist/composites/chart-composition.js +486 -0
- package/dist/composites/chart-ui.d.ts +83 -0
- package/dist/composites/chart-ui.d.ts.map +1 -0
- package/dist/composites/chart-ui.js +108 -0
- package/dist/composites/charts-3d.d.ts +37 -0
- package/dist/composites/charts-3d.d.ts.map +1 -0
- package/dist/composites/charts-3d.js +121 -0
- package/dist/composites/flow-charts.d.ts +89 -0
- package/dist/composites/flow-charts.d.ts.map +1 -0
- package/dist/composites/flow-charts.js +186 -0
- package/dist/composites/radial-charts.d.ts +109 -0
- package/dist/composites/radial-charts.d.ts.map +1 -0
- package/dist/composites/radial-charts.js +176 -0
- package/dist/composites/scheduler-ui.d.ts +44 -0
- package/dist/composites/scheduler-ui.d.ts.map +1 -0
- package/dist/composites/scheduler-ui.js +71 -0
- package/dist/index.d.ts +68 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +58 -7
- package/dist/lib/chart-export.d.ts +10 -0
- package/dist/lib/chart-export.d.ts.map +1 -0
- package/dist/lib/chart-export.js +102 -0
- package/dist/lib/charts.d.ts +235 -0
- package/dist/lib/charts.d.ts.map +1 -0
- package/dist/lib/charts.js +744 -0
- package/dist/lib/geo.d.ts +39 -0
- package/dist/lib/geo.d.ts.map +1 -0
- package/dist/lib/geo.js +101 -0
- package/dist/lib/iso.d.ts +21 -0
- package/dist/lib/iso.d.ts.map +1 -0
- package/dist/lib/iso.js +56 -0
- package/dist/lib/rrule.d.ts +20 -0
- package/dist/lib/rrule.d.ts.map +1 -0
- package/dist/lib/rrule.js +236 -0
- package/dist/lib/scheduler.d.ts +156 -0
- package/dist/lib/scheduler.d.ts.map +1 -0
- package/dist/lib/scheduler.js +502 -0
- package/dist/lib/webgl-scatter.d.ts +44 -0
- package/dist/lib/webgl-scatter.d.ts.map +1 -0
- package/dist/lib/webgl-scatter.js +185 -0
- package/dist/primitives/Accordion.d.ts +44 -20
- package/dist/primitives/Accordion.d.ts.map +1 -1
- package/dist/primitives/Accordion.js +82 -22
- package/dist/primitives/AppBar.d.ts +13 -0
- package/dist/primitives/AppBar.d.ts.map +1 -0
- package/dist/primitives/AppBar.js +27 -0
- package/dist/primitives/Autocomplete.d.ts +28 -0
- package/dist/primitives/Autocomplete.d.ts.map +1 -0
- package/dist/primitives/Autocomplete.js +118 -0
- package/dist/primitives/Avatar.d.ts +13 -1
- package/dist/primitives/Avatar.d.ts.map +1 -1
- package/dist/primitives/Avatar.js +17 -2
- package/dist/primitives/Backdrop.d.ts +17 -0
- package/dist/primitives/Backdrop.d.ts.map +1 -0
- package/dist/primitives/Backdrop.js +17 -0
- package/dist/primitives/BottomNavigation.d.ts +23 -0
- package/dist/primitives/BottomNavigation.d.ts.map +1 -0
- package/dist/primitives/BottomNavigation.js +30 -0
- package/dist/primitives/ButtonBase.d.ts +14 -0
- package/dist/primitives/ButtonBase.d.ts.map +1 -0
- package/dist/primitives/ButtonBase.js +13 -0
- package/dist/primitives/ButtonGroup.d.ts +25 -0
- package/dist/primitives/ButtonGroup.d.ts.map +1 -0
- package/dist/primitives/ButtonGroup.js +44 -0
- package/dist/primitives/CircularProgress.d.ts +16 -0
- package/dist/primitives/CircularProgress.d.ts.map +1 -0
- package/dist/primitives/CircularProgress.js +17 -0
- package/dist/primitives/ClickAwayListener.d.ts +16 -0
- package/dist/primitives/ClickAwayListener.d.ts.map +1 -0
- package/dist/primitives/ClickAwayListener.js +33 -0
- package/dist/primitives/Collapse.d.ts +19 -0
- package/dist/primitives/Collapse.d.ts.map +1 -0
- package/dist/primitives/Collapse.js +14 -0
- package/dist/primitives/Container.d.ts +13 -0
- package/dist/primitives/Container.d.ts.map +1 -0
- package/dist/primitives/Container.js +26 -0
- package/dist/primitives/Fab.d.ts +22 -0
- package/dist/primitives/Fab.d.ts.map +1 -0
- package/dist/primitives/Fab.js +42 -0
- package/dist/primitives/FormControl.d.ts +27 -0
- package/dist/primitives/FormControl.d.ts.map +1 -0
- package/dist/primitives/FormControl.js +24 -0
- package/dist/primitives/FormControlLabel.d.ts +18 -0
- package/dist/primitives/FormControlLabel.d.ts.map +1 -0
- package/dist/primitives/FormControlLabel.js +19 -0
- package/dist/primitives/Grid.d.ts +32 -0
- package/dist/primitives/Grid.d.ts.map +1 -0
- package/dist/primitives/Grid.js +50 -0
- package/dist/primitives/IconButton.d.ts +22 -0
- package/dist/primitives/IconButton.d.ts.map +1 -0
- package/dist/primitives/IconButton.js +39 -0
- package/dist/primitives/ImageList.d.ts +31 -0
- package/dist/primitives/ImageList.d.ts.map +1 -0
- package/dist/primitives/ImageList.js +33 -0
- package/dist/primitives/InputAdornment.d.ts +28 -0
- package/dist/primitives/InputAdornment.d.ts.map +1 -0
- package/dist/primitives/InputAdornment.js +13 -0
- package/dist/primitives/Link.d.ts +17 -0
- package/dist/primitives/Link.d.ts.map +1 -0
- package/dist/primitives/Link.js +29 -0
- package/dist/primitives/List.d.ts +41 -0
- package/dist/primitives/List.d.ts.map +1 -0
- package/dist/primitives/List.js +22 -0
- package/dist/primitives/Masonry.d.ts +14 -0
- package/dist/primitives/Masonry.d.ts.map +1 -0
- package/dist/primitives/Masonry.js +15 -0
- package/dist/primitives/Menu.d.ts +28 -0
- package/dist/primitives/Menu.d.ts.map +1 -0
- package/dist/primitives/Menu.js +54 -0
- package/dist/primitives/MobileStepper.d.ts +15 -0
- package/dist/primitives/MobileStepper.d.ts.map +1 -0
- package/dist/primitives/MobileStepper.js +8 -0
- package/dist/primitives/Modal.d.ts +18 -0
- package/dist/primitives/Modal.d.ts.map +1 -0
- package/dist/primitives/Modal.js +29 -0
- package/dist/primitives/NoSsr.d.ts +15 -0
- package/dist/primitives/NoSsr.d.ts.map +1 -0
- package/dist/primitives/NoSsr.js +19 -0
- package/dist/primitives/Paper.d.ts +22 -0
- package/dist/primitives/Paper.d.ts.map +1 -0
- package/dist/primitives/Paper.js +33 -0
- package/dist/primitives/Progress.d.ts +6 -2
- package/dist/primitives/Progress.d.ts.map +1 -1
- package/dist/primitives/Progress.js +8 -3
- package/dist/primitives/Snackbar.d.ts +23 -0
- package/dist/primitives/Snackbar.d.ts.map +1 -0
- package/dist/primitives/Snackbar.js +33 -0
- package/dist/primitives/SpeedDial.d.ts +26 -0
- package/dist/primitives/SpeedDial.d.ts.map +1 -0
- package/dist/primitives/SpeedDial.js +26 -0
- package/dist/primitives/Stack.d.ts +15 -0
- package/dist/primitives/Stack.d.ts.map +1 -0
- package/dist/primitives/Stack.js +45 -0
- package/dist/primitives/StarRating.d.ts +19 -1
- package/dist/primitives/StarRating.d.ts.map +1 -1
- package/dist/primitives/StarRating.js +36 -6
- package/dist/primitives/Stepper.d.ts +36 -0
- package/dist/primitives/Stepper.d.ts.map +1 -0
- package/dist/primitives/Stepper.js +53 -0
- package/dist/primitives/TablePagination.d.ts +16 -0
- package/dist/primitives/TablePagination.d.ts.map +1 -0
- package/dist/primitives/TablePagination.js +12 -0
- package/dist/primitives/TextField.d.ts +24 -0
- package/dist/primitives/TextField.d.ts.map +1 -0
- package/dist/primitives/TextField.js +19 -0
- package/dist/primitives/TextareaAutosize.d.ts +11 -0
- package/dist/primitives/TextareaAutosize.d.ts.map +1 -0
- package/dist/primitives/TextareaAutosize.js +26 -0
- package/dist/primitives/ToggleButton.d.ts +28 -0
- package/dist/primitives/ToggleButton.d.ts.map +1 -0
- package/dist/primitives/ToggleButton.js +56 -0
- package/dist/primitives/TransferList.d.ts +21 -0
- package/dist/primitives/TransferList.d.ts.map +1 -0
- package/dist/primitives/TransferList.js +40 -0
- package/dist/primitives/Typography.d.ts +23 -0
- package/dist/primitives/Typography.d.ts.map +1 -0
- package/dist/primitives/Typography.js +69 -0
- package/dist/primitives/transitions.d.ts +29 -0
- package/dist/primitives/transitions.d.ts.map +1 -0
- package/dist/primitives/transitions.js +52 -0
- package/package.json +28 -4
- package/skills/spatika-ui/SKILL.md +96 -0
- package/src/composites/Card.tsx +51 -1
- package/src/composites/ChartDataGrid.test.tsx +57 -0
- package/src/composites/ChartDataGrid.tsx +196 -0
- package/src/composites/CoverHero.test.tsx +38 -0
- package/src/composites/CoverHero.tsx +29 -22
- package/src/composites/EntityMediaCard.test.tsx +58 -0
- package/src/composites/EntityMediaCard.tsx +31 -13
- package/src/composites/EventCalendar.tsx +1030 -0
- package/src/composites/EventEditor.tsx +268 -0
- package/src/composites/EventTimeline.tsx +366 -0
- package/src/composites/MapChart.test.tsx +39 -0
- package/src/composites/MapChart.tsx +130 -0
- package/src/composites/ProfileHero.test.tsx +33 -0
- package/src/composites/ProfileHero.tsx +96 -79
- package/src/composites/ScatterWebGL.test.tsx +25 -0
- package/src/composites/ScatterWebGL.tsx +79 -0
- package/src/composites/SiteFooter.test.tsx +37 -0
- package/src/composites/SiteFooter.tsx +1 -1
- package/src/composites/SiteNav.test.tsx +46 -0
- package/src/composites/SiteNav.tsx +14 -4
- package/src/composites/StatCard.test.tsx +30 -0
- package/src/composites/StatCard.tsx +4 -0
- package/src/composites/Wordmark.test.tsx +23 -0
- package/src/composites/Wordmark.tsx +2 -2
- package/src/composites/cartesian-charts.test.tsx +52 -0
- package/src/composites/cartesian-charts.tsx +1287 -0
- package/src/composites/chart-composition.test.tsx +53 -0
- package/src/composites/chart-composition.tsx +898 -0
- package/src/composites/chart-ui.tsx +328 -0
- package/src/composites/charts-3d.test.tsx +25 -0
- package/src/composites/charts-3d.tsx +318 -0
- package/src/composites/charts.test.tsx +254 -0
- package/src/composites/chrome.test.tsx +29 -0
- package/src/composites/flow-charts.test.tsx +79 -0
- package/src/composites/flow-charts.tsx +607 -0
- package/src/composites/marketing.test.tsx +38 -34
- package/src/composites/radial-charts.test.tsx +74 -0
- package/src/composites/radial-charts.tsx +617 -0
- package/src/composites/scheduler-ui.tsx +306 -0
- package/src/composites/scheduler.test.tsx +280 -0
- package/src/index.test.ts +26 -0
- package/src/index.ts +287 -5
- package/src/lib/chart-export.test.ts +20 -0
- package/src/lib/chart-export.ts +99 -0
- package/src/lib/charts-platform.test.ts +93 -0
- package/src/lib/charts.test.ts +132 -0
- package/src/lib/charts.ts +1021 -0
- package/src/lib/geo.test.ts +42 -0
- package/src/lib/geo.ts +138 -0
- package/src/lib/iso.test.ts +22 -0
- package/src/lib/iso.ts +102 -0
- package/src/lib/rrule.test.ts +53 -0
- package/src/lib/rrule.ts +281 -0
- package/src/lib/scheduler.test.ts +199 -0
- package/src/lib/scheduler.ts +693 -0
- package/src/lib/tokens.test.ts +2 -2
- package/src/lib/webgl-scatter.test.ts +36 -0
- package/src/lib/webgl-scatter.ts +230 -0
- package/src/primitives/Accordion.tsx +218 -63
- package/src/primitives/AppBar.tsx +39 -0
- package/src/primitives/Autocomplete.tsx +236 -0
- package/src/primitives/Avatar.tsx +52 -1
- package/src/primitives/Backdrop.tsx +48 -0
- package/src/primitives/BottomNavigation.tsx +102 -0
- package/src/primitives/ButtonBase.tsx +34 -0
- package/src/primitives/ButtonGroup.tsx +90 -0
- package/src/primitives/CircularProgress.tsx +104 -0
- package/src/primitives/ClickAwayListener.tsx +46 -0
- package/src/primitives/Collapse.tsx +39 -0
- package/src/primitives/Container.tsx +40 -0
- package/src/primitives/Fab.tsx +62 -0
- package/src/primitives/FormControl.tsx +90 -0
- package/src/primitives/FormControlLabel.tsx +51 -0
- package/src/primitives/Grid.tsx +101 -0
- package/src/primitives/IconButton.tsx +59 -0
- package/src/primitives/ImageList.test.tsx +48 -0
- package/src/primitives/ImageList.tsx +112 -0
- package/src/primitives/InputAdornment.tsx +86 -0
- package/src/primitives/Link.tsx +48 -0
- package/src/primitives/List.tsx +121 -0
- package/src/primitives/Masonry.tsx +32 -0
- package/src/primitives/Menu.tsx +112 -0
- package/src/primitives/MobileStepper.tsx +64 -0
- package/src/primitives/Modal.tsx +70 -0
- package/src/primitives/NoSsr.tsx +28 -0
- package/src/primitives/Paper.tsx +55 -0
- package/src/primitives/Progress.tsx +25 -7
- package/src/primitives/Snackbar.tsx +83 -0
- package/src/primitives/SpeedDial.tsx +110 -0
- package/src/primitives/Stack.tsx +88 -0
- package/src/primitives/StarRating.tsx +87 -28
- package/src/primitives/Stepper.tsx +184 -0
- package/src/primitives/TablePagination.tsx +58 -0
- package/src/primitives/TextField.tsx +105 -0
- package/src/primitives/TextareaAutosize.tsx +49 -0
- package/src/primitives/ToggleButton.tsx +148 -0
- package/src/primitives/TransferList.tsx +110 -0
- package/src/primitives/Typography.tsx +90 -0
- package/src/primitives/mui-more.test.tsx +76 -0
- package/src/primitives/mui.test.tsx +134 -0
- package/src/primitives/transitions.tsx +120 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cn } from "../lib/cn";
|
|
3
|
+
import { Input } from "./Input";
|
|
4
|
+
import { Label } from "./Label";
|
|
5
|
+
import { Textarea } from "./Textarea";
|
|
6
|
+
|
|
7
|
+
export type TextFieldProps = Omit<React.ComponentPropsWithoutRef<"input">, "size"> & {
|
|
8
|
+
label?: React.ReactNode;
|
|
9
|
+
helperText?: React.ReactNode;
|
|
10
|
+
error?: boolean;
|
|
11
|
+
multiline?: boolean;
|
|
12
|
+
rows?: number;
|
|
13
|
+
fullWidth?: boolean;
|
|
14
|
+
size?: "sm" | "md";
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Labeled input (or textarea) with helper / error copy — MUI TextField analogue.
|
|
19
|
+
*/
|
|
20
|
+
const TextField = React.forwardRef<HTMLInputElement, TextFieldProps>(
|
|
21
|
+
(
|
|
22
|
+
{
|
|
23
|
+
id,
|
|
24
|
+
label,
|
|
25
|
+
helperText,
|
|
26
|
+
error,
|
|
27
|
+
multiline,
|
|
28
|
+
rows = 3,
|
|
29
|
+
fullWidth,
|
|
30
|
+
size = "md",
|
|
31
|
+
className,
|
|
32
|
+
disabled,
|
|
33
|
+
required,
|
|
34
|
+
type,
|
|
35
|
+
...props
|
|
36
|
+
},
|
|
37
|
+
ref,
|
|
38
|
+
) => {
|
|
39
|
+
const autoId = React.useId();
|
|
40
|
+
const fieldId = id ?? autoId;
|
|
41
|
+
const helperId = helperText ? `${fieldId}-helper` : undefined;
|
|
42
|
+
|
|
43
|
+
const fieldClass = cn(
|
|
44
|
+
size === "sm" && "h-8 text-sm",
|
|
45
|
+
error && "aria-invalid:border-destructive",
|
|
46
|
+
className,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const control = multiline ? (
|
|
50
|
+
<Textarea
|
|
51
|
+
id={fieldId}
|
|
52
|
+
rows={rows}
|
|
53
|
+
disabled={disabled}
|
|
54
|
+
required={required}
|
|
55
|
+
aria-invalid={error || undefined}
|
|
56
|
+
aria-describedby={helperId}
|
|
57
|
+
className={cn(fullWidth && "w-full", className)}
|
|
58
|
+
{...(props as React.ComponentPropsWithoutRef<"textarea">)}
|
|
59
|
+
/>
|
|
60
|
+
) : (
|
|
61
|
+
<Input
|
|
62
|
+
ref={ref}
|
|
63
|
+
id={fieldId}
|
|
64
|
+
type={type}
|
|
65
|
+
disabled={disabled}
|
|
66
|
+
required={required}
|
|
67
|
+
aria-invalid={error || undefined}
|
|
68
|
+
aria-describedby={helperId}
|
|
69
|
+
className={cn(fullWidth && "w-full", fieldClass)}
|
|
70
|
+
{...props}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<div
|
|
76
|
+
data-slot="text-field"
|
|
77
|
+
data-error={error ? "" : undefined}
|
|
78
|
+
className={cn("flex flex-col gap-1.5", fullWidth && "w-full")}
|
|
79
|
+
>
|
|
80
|
+
{label ? (
|
|
81
|
+
<Label htmlFor={fieldId}>
|
|
82
|
+
{label}
|
|
83
|
+
{required ? <span className="text-destructive">*</span> : null}
|
|
84
|
+
</Label>
|
|
85
|
+
) : null}
|
|
86
|
+
{control}
|
|
87
|
+
{helperText ? (
|
|
88
|
+
<p
|
|
89
|
+
id={helperId}
|
|
90
|
+
data-slot="text-field-helper"
|
|
91
|
+
className={cn(
|
|
92
|
+
"text-xs font-medium",
|
|
93
|
+
error ? "text-destructive" : "text-muted-foreground",
|
|
94
|
+
)}
|
|
95
|
+
>
|
|
96
|
+
{helperText}
|
|
97
|
+
</p>
|
|
98
|
+
) : null}
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
);
|
|
103
|
+
TextField.displayName = "TextField";
|
|
104
|
+
|
|
105
|
+
export { TextField };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { composeRefs } from "../lib/compose-refs";
|
|
3
|
+
import { cn } from "../lib/cn";
|
|
4
|
+
|
|
5
|
+
export type TextareaAutosizeProps = React.ComponentPropsWithoutRef<"textarea"> & {
|
|
6
|
+
minRows?: number;
|
|
7
|
+
maxRows?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const TextareaAutosize = React.forwardRef<HTMLTextAreaElement, TextareaAutosizeProps>(
|
|
11
|
+
({ className, minRows = 2, maxRows, onChange, style, ...props }, ref) => {
|
|
12
|
+
const inner = React.useRef<HTMLTextAreaElement | null>(null);
|
|
13
|
+
|
|
14
|
+
const resize = React.useCallback(() => {
|
|
15
|
+
const node = inner.current;
|
|
16
|
+
if (!node) return;
|
|
17
|
+
node.style.height = "auto";
|
|
18
|
+
const line = Number.parseFloat(getComputedStyle(node).lineHeight) || 20;
|
|
19
|
+
const min = minRows * line;
|
|
20
|
+
const max = maxRows ? maxRows * line : Number.POSITIVE_INFINITY;
|
|
21
|
+
node.style.height = `${Math.min(max, Math.max(min, node.scrollHeight))}px`;
|
|
22
|
+
}, [minRows, maxRows]);
|
|
23
|
+
|
|
24
|
+
React.useLayoutEffect(() => {
|
|
25
|
+
resize();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<textarea
|
|
30
|
+
ref={composeRefs(ref, inner)}
|
|
31
|
+
data-slot="textarea-autosize"
|
|
32
|
+
rows={minRows}
|
|
33
|
+
className={cn(
|
|
34
|
+
"border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 flex w-full rounded-md border bg-input-background px-3 py-2 text-sm outline-none focus-visible:ring-[3px]",
|
|
35
|
+
className,
|
|
36
|
+
)}
|
|
37
|
+
style={{ overflow: "hidden", resize: "none", ...style }}
|
|
38
|
+
onChange={(event) => {
|
|
39
|
+
onChange?.(event);
|
|
40
|
+
resize();
|
|
41
|
+
}}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
TextareaAutosize.displayName = "TextareaAutosize";
|
|
48
|
+
|
|
49
|
+
export { TextareaAutosize };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
import { useControllableState } from "../lib/use-controllable-state";
|
|
4
|
+
import { cn } from "../lib/cn";
|
|
5
|
+
|
|
6
|
+
const toggleButtonVariants = cva(
|
|
7
|
+
"inline-flex items-center justify-center gap-1.5 border text-sm font-bold outline-none transition-colors focus-visible:z-10 focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-40 [&_svg]:size-4",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
size: {
|
|
11
|
+
sm: "h-8 px-2.5 text-xs",
|
|
12
|
+
md: "h-9 px-3",
|
|
13
|
+
lg: "h-10 px-4",
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
defaultVariants: { size: "md" },
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
type ToggleGroupContextValue = {
|
|
21
|
+
exclusive: boolean;
|
|
22
|
+
value: string | string[] | null;
|
|
23
|
+
setValue: (value: string) => void;
|
|
24
|
+
size: NonNullable<VariantProps<typeof toggleButtonVariants>["size"]>;
|
|
25
|
+
disabled: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ToggleGroupContext = React.createContext<ToggleGroupContextValue | null>(null);
|
|
29
|
+
|
|
30
|
+
export type ToggleButtonGroupProps = Omit<
|
|
31
|
+
React.ComponentPropsWithoutRef<"div">,
|
|
32
|
+
"onChange" | "value" | "defaultValue"
|
|
33
|
+
> & {
|
|
34
|
+
exclusive?: boolean;
|
|
35
|
+
value?: string | string[] | null;
|
|
36
|
+
defaultValue?: string | string[] | null;
|
|
37
|
+
onValueChange?: (value: string | string[] | null) => void;
|
|
38
|
+
size?: VariantProps<typeof toggleButtonVariants>["size"];
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
orientation?: "horizontal" | "vertical";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function ToggleButtonGroup({
|
|
44
|
+
exclusive = false,
|
|
45
|
+
value: valueProp,
|
|
46
|
+
defaultValue,
|
|
47
|
+
onValueChange,
|
|
48
|
+
size = "md",
|
|
49
|
+
disabled = false,
|
|
50
|
+
orientation = "horizontal",
|
|
51
|
+
className,
|
|
52
|
+
children,
|
|
53
|
+
...props
|
|
54
|
+
}: ToggleButtonGroupProps) {
|
|
55
|
+
const [value, setValue] = useControllableState<string | string[] | null>({
|
|
56
|
+
prop: valueProp,
|
|
57
|
+
defaultProp: defaultValue ?? (exclusive ? null : []),
|
|
58
|
+
onChange: onValueChange,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const setFromChild = (next: string) => {
|
|
62
|
+
if (disabled) return;
|
|
63
|
+
setValue((prev) => {
|
|
64
|
+
if (exclusive) return prev === next ? null : next;
|
|
65
|
+
const list = Array.isArray(prev) ? prev : prev ? [prev] : [];
|
|
66
|
+
return list.includes(next) ? list.filter((v) => v !== next) : [...list, next];
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<ToggleGroupContext.Provider
|
|
72
|
+
value={{ exclusive, value: value ?? null, setValue: setFromChild, size: size ?? "md", disabled }}
|
|
73
|
+
>
|
|
74
|
+
<div
|
|
75
|
+
role="group"
|
|
76
|
+
data-slot="toggle-button-group"
|
|
77
|
+
data-orientation={orientation}
|
|
78
|
+
className={cn(
|
|
79
|
+
"inline-flex isolate",
|
|
80
|
+
orientation === "vertical" ? "flex-col" : "flex-row",
|
|
81
|
+
className,
|
|
82
|
+
)}
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
{children}
|
|
86
|
+
</div>
|
|
87
|
+
</ToggleGroupContext.Provider>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
ToggleButtonGroup.displayName = "ToggleButtonGroup";
|
|
91
|
+
|
|
92
|
+
export type ToggleButtonProps = Omit<React.ComponentPropsWithoutRef<"button">, "value"> &
|
|
93
|
+
VariantProps<typeof toggleButtonVariants> & {
|
|
94
|
+
value: string;
|
|
95
|
+
selected?: boolean;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function ToggleButton({
|
|
99
|
+
value,
|
|
100
|
+
selected,
|
|
101
|
+
size: sizeProp,
|
|
102
|
+
className,
|
|
103
|
+
disabled,
|
|
104
|
+
onClick,
|
|
105
|
+
children,
|
|
106
|
+
...props
|
|
107
|
+
}: ToggleButtonProps) {
|
|
108
|
+
const ctx = React.useContext(ToggleGroupContext);
|
|
109
|
+
const size = sizeProp ?? ctx?.size ?? "md";
|
|
110
|
+
const isSelected =
|
|
111
|
+
selected ??
|
|
112
|
+
(ctx
|
|
113
|
+
? Array.isArray(ctx.value)
|
|
114
|
+
? ctx.value.includes(value)
|
|
115
|
+
: ctx.value === value
|
|
116
|
+
: false);
|
|
117
|
+
const isDisabled = disabled || ctx?.disabled;
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<button
|
|
121
|
+
type="button"
|
|
122
|
+
data-slot="toggle-button"
|
|
123
|
+
data-state={isSelected ? "on" : "off"}
|
|
124
|
+
aria-pressed={isSelected}
|
|
125
|
+
disabled={isDisabled}
|
|
126
|
+
className={cn(
|
|
127
|
+
toggleButtonVariants({ size }),
|
|
128
|
+
isSelected
|
|
129
|
+
? "z-[1] border-primary/50 bg-primary/15 text-primary"
|
|
130
|
+
: "border-border/60 bg-background/80 text-foreground hover:bg-muted/40",
|
|
131
|
+
ctx && "first:rounded-l-lg last:rounded-r-lg [&:not(:first-child)]:rounded-l-none [&:not(:last-child)]:rounded-r-none [&:not(:first-child)]:-ml-px",
|
|
132
|
+
!ctx && "rounded-lg",
|
|
133
|
+
className,
|
|
134
|
+
)}
|
|
135
|
+
onClick={(event) => {
|
|
136
|
+
onClick?.(event);
|
|
137
|
+
if (event.defaultPrevented || isDisabled) return;
|
|
138
|
+
ctx?.setValue(value);
|
|
139
|
+
}}
|
|
140
|
+
{...props}
|
|
141
|
+
>
|
|
142
|
+
{children}
|
|
143
|
+
</button>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
ToggleButton.displayName = "ToggleButton";
|
|
147
|
+
|
|
148
|
+
export { ToggleButton, ToggleButtonGroup, toggleButtonVariants };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
3
|
+
import { cn } from "../lib/cn";
|
|
4
|
+
import { Button } from "./Button";
|
|
5
|
+
import { List, ListItemButton, ListItemIcon, ListItemText } from "./List";
|
|
6
|
+
import { Paper } from "./Paper";
|
|
7
|
+
|
|
8
|
+
export type TransferListProps = {
|
|
9
|
+
left: string[];
|
|
10
|
+
right: string[];
|
|
11
|
+
onChange?: (next: { left: string[]; right: string[] }) => void;
|
|
12
|
+
leftTitle?: string;
|
|
13
|
+
rightTitle?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function move(source: string[], target: string[], picked: string[]) {
|
|
18
|
+
return {
|
|
19
|
+
source: source.filter((item) => !picked.includes(item)),
|
|
20
|
+
target: [...target, ...source.filter((item) => picked.includes(item))],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function Column({
|
|
25
|
+
title,
|
|
26
|
+
items,
|
|
27
|
+
checked,
|
|
28
|
+
onToggle,
|
|
29
|
+
}: {
|
|
30
|
+
title: string;
|
|
31
|
+
items: string[];
|
|
32
|
+
checked: string[];
|
|
33
|
+
onToggle: (item: string) => void;
|
|
34
|
+
}) {
|
|
35
|
+
return (
|
|
36
|
+
<Paper variant="outlined" className="min-w-40 flex-1 overflow-hidden">
|
|
37
|
+
<div className="border-b border-border/40 px-3 py-2 text-xs font-black uppercase tracking-widest text-muted-foreground">
|
|
38
|
+
{title}
|
|
39
|
+
</div>
|
|
40
|
+
<List dense disablePadding className="max-h-48 overflow-auto">
|
|
41
|
+
{items.map((item) => (
|
|
42
|
+
<ListItemButton
|
|
43
|
+
key={item}
|
|
44
|
+
selected={checked.includes(item)}
|
|
45
|
+
onClick={() => onToggle(item)}
|
|
46
|
+
>
|
|
47
|
+
<ListItemIcon>
|
|
48
|
+
<span
|
|
49
|
+
className={cn(
|
|
50
|
+
"size-3.5 rounded-sm border",
|
|
51
|
+
checked.includes(item) ? "border-primary bg-primary" : "border-border",
|
|
52
|
+
)}
|
|
53
|
+
/>
|
|
54
|
+
</ListItemIcon>
|
|
55
|
+
<ListItemText primary={item} />
|
|
56
|
+
</ListItemButton>
|
|
57
|
+
))}
|
|
58
|
+
</List>
|
|
59
|
+
</Paper>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Two-list shuttle for picking items — MUI Transfer List analogue.
|
|
65
|
+
*/
|
|
66
|
+
function TransferList({
|
|
67
|
+
left,
|
|
68
|
+
right,
|
|
69
|
+
onChange,
|
|
70
|
+
leftTitle = "Choices",
|
|
71
|
+
rightTitle = "Chosen",
|
|
72
|
+
className,
|
|
73
|
+
}: TransferListProps) {
|
|
74
|
+
const [checkedLeft, setCheckedLeft] = React.useState<string[]>([]);
|
|
75
|
+
const [checkedRight, setCheckedRight] = React.useState<string[]>([]);
|
|
76
|
+
|
|
77
|
+
const toggle = (item: string, side: "left" | "right") => {
|
|
78
|
+
const setter = side === "left" ? setCheckedLeft : setCheckedRight;
|
|
79
|
+
setter((prev) => (prev.includes(item) ? prev.filter((x) => x !== item) : [...prev, item]));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const toRight = () => {
|
|
83
|
+
const next = move(left, right, checkedLeft);
|
|
84
|
+
onChange?.({ left: next.source, right: next.target });
|
|
85
|
+
setCheckedLeft([]);
|
|
86
|
+
};
|
|
87
|
+
const toLeft = () => {
|
|
88
|
+
const next = move(right, left, checkedRight);
|
|
89
|
+
onChange?.({ left: next.target, right: next.source });
|
|
90
|
+
setCheckedRight([]);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div data-slot="transfer-list" className={cn("flex items-center gap-3", className)}>
|
|
95
|
+
<Column title={leftTitle} items={left} checked={checkedLeft} onToggle={(item) => toggle(item, "left")} />
|
|
96
|
+
<div className="flex flex-col gap-2">
|
|
97
|
+
<Button size="sm" variant="outline" disabled={!checkedLeft.length} onClick={toRight} aria-label="Move right">
|
|
98
|
+
<ChevronRight className="size-4" />
|
|
99
|
+
</Button>
|
|
100
|
+
<Button size="sm" variant="outline" disabled={!checkedRight.length} onClick={toLeft} aria-label="Move left">
|
|
101
|
+
<ChevronLeft className="size-4" />
|
|
102
|
+
</Button>
|
|
103
|
+
</div>
|
|
104
|
+
<Column title={rightTitle} items={right} checked={checkedRight} onToggle={(item) => toggle(item, "right")} />
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
TransferList.displayName = "TransferList";
|
|
109
|
+
|
|
110
|
+
export { TransferList };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
import { cn } from "../lib/cn";
|
|
4
|
+
|
|
5
|
+
const typographyVariants = cva("text-foreground", {
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
h1: "text-4xl font-black tracking-tight",
|
|
9
|
+
h2: "text-3xl font-black tracking-tight",
|
|
10
|
+
h3: "text-2xl font-bold tracking-tight",
|
|
11
|
+
h4: "text-xl font-bold",
|
|
12
|
+
h5: "text-lg font-bold",
|
|
13
|
+
h6: "text-base font-bold",
|
|
14
|
+
subtitle1: "text-base font-semibold",
|
|
15
|
+
subtitle2: "text-sm font-semibold",
|
|
16
|
+
body1: "text-base font-medium leading-relaxed",
|
|
17
|
+
body2: "text-sm font-medium leading-relaxed",
|
|
18
|
+
caption: "text-xs font-medium text-muted-foreground",
|
|
19
|
+
overline: "text-[10px] font-black uppercase tracking-widest text-muted-foreground",
|
|
20
|
+
},
|
|
21
|
+
color: {
|
|
22
|
+
default: "",
|
|
23
|
+
muted: "text-muted-foreground",
|
|
24
|
+
primary: "text-primary",
|
|
25
|
+
inherit: "text-inherit",
|
|
26
|
+
},
|
|
27
|
+
align: {
|
|
28
|
+
inherit: "",
|
|
29
|
+
left: "text-left",
|
|
30
|
+
center: "text-center",
|
|
31
|
+
right: "text-right",
|
|
32
|
+
},
|
|
33
|
+
gutterBottom: {
|
|
34
|
+
true: "mb-2",
|
|
35
|
+
false: "",
|
|
36
|
+
},
|
|
37
|
+
noWrap: {
|
|
38
|
+
true: "truncate",
|
|
39
|
+
false: "",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
defaultVariants: {
|
|
43
|
+
variant: "body1",
|
|
44
|
+
color: "default",
|
|
45
|
+
align: "inherit",
|
|
46
|
+
gutterBottom: false,
|
|
47
|
+
noWrap: false,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const variantElement: Record<
|
|
52
|
+
NonNullable<VariantProps<typeof typographyVariants>["variant"]>,
|
|
53
|
+
React.ElementType
|
|
54
|
+
> = {
|
|
55
|
+
h1: "h1",
|
|
56
|
+
h2: "h2",
|
|
57
|
+
h3: "h3",
|
|
58
|
+
h4: "h4",
|
|
59
|
+
h5: "h5",
|
|
60
|
+
h6: "h6",
|
|
61
|
+
subtitle1: "h6",
|
|
62
|
+
subtitle2: "h6",
|
|
63
|
+
body1: "p",
|
|
64
|
+
body2: "p",
|
|
65
|
+
caption: "span",
|
|
66
|
+
overline: "span",
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type TypographyProps = Omit<React.ComponentPropsWithoutRef<"p">, "color"> &
|
|
70
|
+
VariantProps<typeof typographyVariants> & {
|
|
71
|
+
component?: React.ElementType;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const Typography = React.forwardRef<HTMLElement, TypographyProps>(
|
|
75
|
+
({ className, variant = "body1", color, align, gutterBottom, noWrap, component, ...props }, ref) => {
|
|
76
|
+
const Comp = (component ?? variantElement[variant ?? "body1"]) as React.ElementType;
|
|
77
|
+
return (
|
|
78
|
+
<Comp
|
|
79
|
+
ref={ref}
|
|
80
|
+
data-slot="typography"
|
|
81
|
+
data-variant={variant}
|
|
82
|
+
className={cn(typographyVariants({ variant, color, align, gutterBottom, noWrap }), className)}
|
|
83
|
+
{...props}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
Typography.displayName = "Typography";
|
|
89
|
+
|
|
90
|
+
export { Typography, typographyVariants };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { Autocomplete } from "./Autocomplete";
|
|
5
|
+
import { Box, Grid } from "./Grid";
|
|
6
|
+
import { FormControl, FormHelperText, FormLabel } from "./FormControl";
|
|
7
|
+
import { Input } from "./Input";
|
|
8
|
+
import { Rating } from "./StarRating";
|
|
9
|
+
import { TransferList } from "./TransferList";
|
|
10
|
+
import { BottomNavigation, BottomNavigationAction } from "./BottomNavigation";
|
|
11
|
+
import { Fade } from "./transitions";
|
|
12
|
+
import { NoSsr } from "./NoSsr";
|
|
13
|
+
import { Button } from "./Button";
|
|
14
|
+
|
|
15
|
+
describe("Autocomplete", () => {
|
|
16
|
+
it("filters and selects an option", async () => {
|
|
17
|
+
const user = userEvent.setup();
|
|
18
|
+
const onChange = vi.fn();
|
|
19
|
+
render(
|
|
20
|
+
<Autocomplete
|
|
21
|
+
label="Movie"
|
|
22
|
+
options={["Inception", "Heat", "Her"]}
|
|
23
|
+
onChange={onChange}
|
|
24
|
+
/>,
|
|
25
|
+
);
|
|
26
|
+
await user.click(screen.getByRole("combobox"));
|
|
27
|
+
await user.type(screen.getByRole("combobox"), "He");
|
|
28
|
+
await user.click(screen.getByRole("option", { name: "Heat" }));
|
|
29
|
+
expect(onChange).toHaveBeenCalled();
|
|
30
|
+
expect(onChange.mock.calls.at(-1)?.[0]).toBe("Heat");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("layout and form extras", () => {
|
|
35
|
+
it("renders Grid, Box, FormControl, Rating, Fade, and TransferList", async () => {
|
|
36
|
+
const user = userEvent.setup();
|
|
37
|
+
const onTransfer = vi.fn();
|
|
38
|
+
render(
|
|
39
|
+
<Box>
|
|
40
|
+
<Grid container spacing={2}>
|
|
41
|
+
<Grid xs={6}>Left</Grid>
|
|
42
|
+
<Grid xs={6}>Right</Grid>
|
|
43
|
+
</Grid>
|
|
44
|
+
<FormControl error>
|
|
45
|
+
<FormLabel>Email</FormLabel>
|
|
46
|
+
<Input />
|
|
47
|
+
<FormHelperText>Required</FormHelperText>
|
|
48
|
+
</FormControl>
|
|
49
|
+
<Rating defaultValue={3} />
|
|
50
|
+
<Fade in>Shown</Fade>
|
|
51
|
+
<NoSsr>
|
|
52
|
+
<span>Client</span>
|
|
53
|
+
</NoSsr>
|
|
54
|
+
<TransferList left={["Java"]} right={["React"]} onChange={onTransfer} />
|
|
55
|
+
</Box>,
|
|
56
|
+
);
|
|
57
|
+
expect(screen.getByText("Left")).toBeInTheDocument();
|
|
58
|
+
expect(screen.getByText("Required")).toBeInTheDocument();
|
|
59
|
+
expect(screen.getByText("Shown")).toBeInTheDocument();
|
|
60
|
+
await user.click(screen.getByRole("button", { name: /Java/ }));
|
|
61
|
+
await user.click(screen.getByRole("button", { name: "Move right" }));
|
|
62
|
+
expect(onTransfer).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("switches BottomNavigation actions", async () => {
|
|
66
|
+
const user = userEvent.setup();
|
|
67
|
+
render(
|
|
68
|
+
<BottomNavigation defaultValue="home">
|
|
69
|
+
<BottomNavigationAction value="home" label="Home" />
|
|
70
|
+
<BottomNavigationAction value="me" label="You" />
|
|
71
|
+
</BottomNavigation>,
|
|
72
|
+
);
|
|
73
|
+
await user.click(screen.getByRole("button", { name: "You" }));
|
|
74
|
+
expect(screen.getByRole("button", { name: "You" })).toHaveAttribute("aria-current", "page");
|
|
75
|
+
});
|
|
76
|
+
});
|