@mzc-fe/design-system 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/accordion.d.ts +7 -0
- package/dist/components/alert-dialog.d.ts +14 -0
- package/dist/components/alert.d.ts +9 -0
- package/dist/components/aspect-ratio.d.ts +3 -0
- package/dist/components/avatar.d.ts +6 -0
- package/dist/components/badge.d.ts +9 -0
- package/dist/components/breadcrumb.d.ts +11 -0
- package/dist/components/button-group.d.ts +11 -0
- package/dist/components/button.d.ts +10 -0
- package/dist/components/calendar.d.ts +8 -0
- package/dist/components/card.d.ts +9 -0
- package/dist/components/carousel.d.ts +19 -0
- package/dist/components/chart.d.ts +40 -0
- package/dist/components/checkbox.d.ts +4 -0
- package/dist/components/collapsible.d.ts +5 -0
- package/dist/components/command.d.ts +18 -0
- package/dist/components/context-menu.d.ts +25 -0
- package/dist/components/dialog.d.ts +15 -0
- package/dist/components/drawer.d.ts +13 -0
- package/dist/components/dropdown-menu.d.ts +25 -0
- package/dist/components/empty.d.ts +11 -0
- package/dist/components/field.d.ts +24 -0
- package/dist/components/form.d.ts +24 -0
- package/dist/components/hover-card.d.ts +6 -0
- package/dist/components/input-group.d.ts +16 -0
- package/dist/components/input-otp.d.ts +11 -0
- package/dist/components/input.d.ts +3 -0
- package/dist/components/item.d.ts +23 -0
- package/dist/components/kbd.d.ts +3 -0
- package/dist/components/label.d.ts +4 -0
- package/dist/components/menubar.d.ts +26 -0
- package/dist/components/navigation-menu.d.ts +14 -0
- package/dist/components/pagination.d.ts +13 -0
- package/dist/components/popover.d.ts +7 -0
- package/dist/components/progress.d.ts +4 -0
- package/dist/components/radio-group.d.ts +5 -0
- package/dist/components/resizable.d.ts +8 -0
- package/dist/components/scroll-area.d.ts +5 -0
- package/dist/components/select.d.ts +15 -0
- package/dist/components/separator.d.ts +4 -0
- package/dist/components/sheet.d.ts +13 -0
- package/dist/components/sidebar.d.ts +69 -0
- package/dist/components/skeleton.d.ts +2 -0
- package/dist/components/slider.d.ts +4 -0
- package/dist/components/sonner.d.ts +3 -0
- package/dist/components/spinner.d.ts +2 -0
- package/dist/components/switch.d.ts +4 -0
- package/dist/components/table.d.ts +10 -0
- package/dist/components/tabs.d.ts +7 -0
- package/dist/components/textarea.d.ts +3 -0
- package/dist/components/toggle-group.d.ts +9 -0
- package/dist/components/toggle.d.ts +9 -0
- package/dist/components/tooltip.d.ts +7 -0
- package/dist/design-system.css +1 -0
- package/dist/design-system.es.js +30200 -0
- package/dist/design-system.umd.js +260 -0
- package/dist/foundations/ThemeProvider.d.ts +13 -0
- package/dist/hooks/use-mobile.d.ts +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/lib/utils.d.ts +2 -0
- package/package.json +14 -1
- package/.husky/pre-push +0 -21
- package/.storybook/main.ts +0 -11
- package/.storybook/preview.tsx +0 -30
- package/.vscode/settings.json +0 -12
- package/.vscode/tailwind.json +0 -105
- package/bitbucket-pipelines.yml +0 -50
- package/components.json +0 -21
- package/eslint.config.js +0 -38
- package/src/components/accordion.stories.tsx +0 -258
- package/src/components/accordion.test.tsx +0 -390
- package/src/components/accordion.tsx +0 -64
- package/src/components/alert-dialog.stories.tsx +0 -213
- package/src/components/alert-dialog.test.tsx +0 -80
- package/src/components/alert-dialog.tsx +0 -155
- package/src/components/alert.stories.tsx +0 -84
- package/src/components/alert.test.tsx +0 -35
- package/src/components/alert.tsx +0 -66
- package/src/components/aspect-ratio.stories.tsx +0 -97
- package/src/components/aspect-ratio.test.tsx +0 -47
- package/src/components/aspect-ratio.tsx +0 -11
- package/src/components/avatar.stories.tsx +0 -76
- package/src/components/avatar.test.tsx +0 -50
- package/src/components/avatar.tsx +0 -51
- package/src/components/badge.stories.tsx +0 -64
- package/src/components/badge.test.tsx +0 -34
- package/src/components/badge.tsx +0 -46
- package/src/components/breadcrumb.stories.tsx +0 -86
- package/src/components/breadcrumb.test.tsx +0 -74
- package/src/components/breadcrumb.tsx +0 -109
- package/src/components/button-group.stories.tsx +0 -62
- package/src/components/button-group.tsx +0 -83
- package/src/components/button.stories.tsx +0 -118
- package/src/components/button.test.tsx +0 -64
- package/src/components/button.tsx +0 -62
- package/src/components/calendar.stories.tsx +0 -81
- package/src/components/calendar.tsx +0 -220
- package/src/components/card.stories.tsx +0 -110
- package/src/components/card.test.tsx +0 -56
- package/src/components/card.tsx +0 -92
- package/src/components/carousel.stories.tsx +0 -90
- package/src/components/carousel.tsx +0 -239
- package/src/components/chart.tsx +0 -357
- package/src/components/checkbox.stories.tsx +0 -108
- package/src/components/checkbox.test.tsx +0 -67
- package/src/components/checkbox.tsx +0 -32
- package/src/components/collapsible.stories.tsx +0 -106
- package/src/components/collapsible.test.tsx +0 -92
- package/src/components/collapsible.tsx +0 -31
- package/src/components/command.stories.tsx +0 -90
- package/src/components/command.tsx +0 -182
- package/src/components/context-menu.stories.tsx +0 -63
- package/src/components/context-menu.tsx +0 -252
- package/src/components/dialog.stories.tsx +0 -128
- package/src/components/dialog.tsx +0 -141
- package/src/components/drawer.stories.tsx +0 -104
- package/src/components/drawer.tsx +0 -135
- package/src/components/dropdown-menu.stories.tsx +0 -97
- package/src/components/dropdown-menu.tsx +0 -255
- package/src/components/empty.stories.tsx +0 -90
- package/src/components/empty.test.tsx +0 -55
- package/src/components/empty.tsx +0 -104
- package/src/components/field.tsx +0 -246
- package/src/components/form.tsx +0 -168
- package/src/components/hover-card.stories.tsx +0 -66
- package/src/components/hover-card.tsx +0 -44
- package/src/components/input-group.stories.tsx +0 -57
- package/src/components/input-group.test.tsx +0 -40
- package/src/components/input-group.tsx +0 -170
- package/src/components/input-otp.stories.tsx +0 -94
- package/src/components/input-otp.test.tsx +0 -60
- package/src/components/input-otp.tsx +0 -75
- package/src/components/input.stories.tsx +0 -94
- package/src/components/input.test.tsx +0 -53
- package/src/components/input.tsx +0 -21
- package/src/components/item.tsx +0 -193
- package/src/components/kbd.stories.tsx +0 -100
- package/src/components/kbd.test.tsx +0 -28
- package/src/components/kbd.tsx +0 -28
- package/src/components/label.stories.tsx +0 -48
- package/src/components/label.test.tsx +0 -28
- package/src/components/label.tsx +0 -24
- package/src/components/menubar.tsx +0 -274
- package/src/components/navigation-menu.tsx +0 -168
- package/src/components/pagination.stories.tsx +0 -107
- package/src/components/pagination.tsx +0 -127
- package/src/components/popover.stories.tsx +0 -102
- package/src/components/popover.tsx +0 -48
- package/src/components/progress.stories.tsx +0 -76
- package/src/components/progress.test.tsx +0 -36
- package/src/components/progress.tsx +0 -29
- package/src/components/radio-group.stories.tsx +0 -73
- package/src/components/radio-group.test.tsx +0 -74
- package/src/components/radio-group.tsx +0 -45
- package/src/components/resizable.stories.tsx +0 -120
- package/src/components/resizable.tsx +0 -54
- package/src/components/scroll-area.stories.tsx +0 -64
- package/src/components/scroll-area.test.tsx +0 -46
- package/src/components/scroll-area.tsx +0 -58
- package/src/components/select.stories.tsx +0 -111
- package/src/components/select.test.tsx +0 -90
- package/src/components/select.tsx +0 -188
- package/src/components/separator.stories.tsx +0 -76
- package/src/components/separator.test.tsx +0 -24
- package/src/components/separator.tsx +0 -28
- package/src/components/sheet.stories.tsx +0 -122
- package/src/components/sheet.tsx +0 -137
- package/src/components/sidebar.tsx +0 -726
- package/src/components/skeleton.stories.tsx +0 -53
- package/src/components/skeleton.test.tsx +0 -24
- package/src/components/skeleton.tsx +0 -13
- package/src/components/slider.stories.tsx +0 -97
- package/src/components/slider.test.tsx +0 -49
- package/src/components/slider.tsx +0 -63
- package/src/components/sonner.stories.tsx +0 -96
- package/src/components/sonner.tsx +0 -38
- package/src/components/spinner.stories.tsx +0 -54
- package/src/components/spinner.test.tsx +0 -30
- package/src/components/spinner.tsx +0 -16
- package/src/components/switch.stories.tsx +0 -108
- package/src/components/switch.test.tsx +0 -62
- package/src/components/switch.tsx +0 -31
- package/src/components/table.stories.tsx +0 -139
- package/src/components/table.test.tsx +0 -85
- package/src/components/table.tsx +0 -114
- package/src/components/tabs.stories.tsx +0 -99
- package/src/components/tabs.test.tsx +0 -64
- package/src/components/tabs.tsx +0 -66
- package/src/components/textarea.stories.tsx +0 -89
- package/src/components/textarea.test.tsx +0 -53
- package/src/components/textarea.tsx +0 -18
- package/src/components/toggle-group.stories.tsx +0 -108
- package/src/components/toggle-group.test.tsx +0 -66
- package/src/components/toggle-group.tsx +0 -81
- package/src/components/toggle.stories.tsx +0 -98
- package/src/components/toggle.test.tsx +0 -42
- package/src/components/toggle.tsx +0 -45
- package/src/components/tooltip.stories.tsx +0 -111
- package/src/components/tooltip.tsx +0 -61
- package/src/foundations/README.md +0 -141
- package/src/foundations/ThemeProvider.tsx +0 -77
- package/src/foundations/color.css +0 -232
- package/src/foundations/color.stories.tsx +0 -719
- package/src/foundations/palette.css +0 -249
- package/src/foundations/spacing.css +0 -8
- package/src/foundations/typography.css +0 -143
- package/src/foundations/typography.stories.tsx +0 -17
- package/src/hooks/use-mobile.ts +0 -19
- package/src/index.css +0 -176
- package/src/index.ts +0 -336
- package/src/lib/utils.ts +0 -6
- package/src/test/setup.ts +0 -8
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.app.json +0 -33
- package/tsconfig.json +0 -13
- package/tsconfig.node.json +0 -25
- package/vite.config.ts +0 -30
- package/vitest.config.ts +0 -25
- /package/{public → dist}/vite.svg +0 -0
package/src/components/chart.tsx
DELETED
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import * as RechartsPrimitive from "recharts";
|
|
5
|
-
|
|
6
|
-
import { cn } from "@/lib/utils";
|
|
7
|
-
|
|
8
|
-
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
9
|
-
const THEMES = { light: "", dark: ".dark" } as const;
|
|
10
|
-
|
|
11
|
-
export type ChartConfig = {
|
|
12
|
-
[k in string]: {
|
|
13
|
-
label?: React.ReactNode;
|
|
14
|
-
icon?: React.ComponentType;
|
|
15
|
-
} & (
|
|
16
|
-
| { color?: string; theme?: never }
|
|
17
|
-
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
18
|
-
);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type ChartContextProps = {
|
|
22
|
-
config: ChartConfig;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
|
26
|
-
|
|
27
|
-
function useChart() {
|
|
28
|
-
const context = React.useContext(ChartContext);
|
|
29
|
-
|
|
30
|
-
if (!context) {
|
|
31
|
-
throw new Error("useChart must be used within a <ChartContainer />");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return context;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function ChartContainer({
|
|
38
|
-
id,
|
|
39
|
-
className,
|
|
40
|
-
children,
|
|
41
|
-
config,
|
|
42
|
-
...props
|
|
43
|
-
}: React.ComponentProps<"div"> & {
|
|
44
|
-
config: ChartConfig;
|
|
45
|
-
children: React.ComponentProps<
|
|
46
|
-
typeof RechartsPrimitive.ResponsiveContainer
|
|
47
|
-
>["children"];
|
|
48
|
-
}) {
|
|
49
|
-
const uniqueId = React.useId();
|
|
50
|
-
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<ChartContext.Provider value={{ config }}>
|
|
54
|
-
<div
|
|
55
|
-
data-slot="chart"
|
|
56
|
-
data-chart={chartId}
|
|
57
|
-
className={cn(
|
|
58
|
-
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
|
|
59
|
-
className
|
|
60
|
-
)}
|
|
61
|
-
{...props}
|
|
62
|
-
>
|
|
63
|
-
<ChartStyle id={chartId} config={config} />
|
|
64
|
-
<RechartsPrimitive.ResponsiveContainer>
|
|
65
|
-
{children}
|
|
66
|
-
</RechartsPrimitive.ResponsiveContainer>
|
|
67
|
-
</div>
|
|
68
|
-
</ChartContext.Provider>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
73
|
-
const colorConfig = Object.entries(config).filter(
|
|
74
|
-
([, config]) => config.theme || config.color
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
if (!colorConfig.length) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<style
|
|
83
|
-
dangerouslySetInnerHTML={{
|
|
84
|
-
__html: Object.entries(THEMES)
|
|
85
|
-
.map(
|
|
86
|
-
([theme, prefix]) => `
|
|
87
|
-
${prefix} [data-chart=${id}] {
|
|
88
|
-
${colorConfig
|
|
89
|
-
.map(([key, itemConfig]) => {
|
|
90
|
-
const color =
|
|
91
|
-
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
|
92
|
-
itemConfig.color;
|
|
93
|
-
return color ? ` --color-${key}: ${color};` : null;
|
|
94
|
-
})
|
|
95
|
-
.join("\n")}
|
|
96
|
-
}
|
|
97
|
-
`
|
|
98
|
-
)
|
|
99
|
-
.join("\n"),
|
|
100
|
-
}}
|
|
101
|
-
/>
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
106
|
-
|
|
107
|
-
function ChartTooltipContent({
|
|
108
|
-
active,
|
|
109
|
-
payload,
|
|
110
|
-
className,
|
|
111
|
-
indicator = "dot",
|
|
112
|
-
hideLabel = false,
|
|
113
|
-
hideIndicator = false,
|
|
114
|
-
label,
|
|
115
|
-
labelFormatter,
|
|
116
|
-
labelClassName,
|
|
117
|
-
formatter,
|
|
118
|
-
color,
|
|
119
|
-
nameKey,
|
|
120
|
-
labelKey,
|
|
121
|
-
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
122
|
-
React.ComponentProps<"div"> & {
|
|
123
|
-
hideLabel?: boolean;
|
|
124
|
-
hideIndicator?: boolean;
|
|
125
|
-
indicator?: "line" | "dot" | "dashed";
|
|
126
|
-
nameKey?: string;
|
|
127
|
-
labelKey?: string;
|
|
128
|
-
}) {
|
|
129
|
-
const { config } = useChart();
|
|
130
|
-
|
|
131
|
-
const tooltipLabel = React.useMemo(() => {
|
|
132
|
-
if (hideLabel || !payload?.length) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const [item] = payload;
|
|
137
|
-
const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
|
|
138
|
-
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
139
|
-
const value =
|
|
140
|
-
!labelKey && typeof label === "string"
|
|
141
|
-
? config[label as keyof typeof config]?.label || label
|
|
142
|
-
: itemConfig?.label;
|
|
143
|
-
|
|
144
|
-
if (labelFormatter) {
|
|
145
|
-
return (
|
|
146
|
-
<div className={cn("font-medium", labelClassName)}>
|
|
147
|
-
{labelFormatter(value, payload)}
|
|
148
|
-
</div>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!value) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
157
|
-
}, [
|
|
158
|
-
label,
|
|
159
|
-
labelFormatter,
|
|
160
|
-
payload,
|
|
161
|
-
hideLabel,
|
|
162
|
-
labelClassName,
|
|
163
|
-
config,
|
|
164
|
-
labelKey,
|
|
165
|
-
]);
|
|
166
|
-
|
|
167
|
-
if (!active || !payload?.length) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
172
|
-
|
|
173
|
-
return (
|
|
174
|
-
<div
|
|
175
|
-
className={cn(
|
|
176
|
-
"border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
|
|
177
|
-
className
|
|
178
|
-
)}
|
|
179
|
-
>
|
|
180
|
-
{!nestLabel ? tooltipLabel : null}
|
|
181
|
-
<div className="grid gap-1.5">
|
|
182
|
-
{payload
|
|
183
|
-
.filter((item) => item.type !== "none")
|
|
184
|
-
.map((item, index) => {
|
|
185
|
-
const key = `${nameKey || item.name || item.dataKey || "value"}`;
|
|
186
|
-
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
187
|
-
const indicatorColor = color || item.payload.fill || item.color;
|
|
188
|
-
|
|
189
|
-
return (
|
|
190
|
-
<div
|
|
191
|
-
key={item.dataKey}
|
|
192
|
-
className={cn(
|
|
193
|
-
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
|
|
194
|
-
indicator === "dot" && "items-center"
|
|
195
|
-
)}
|
|
196
|
-
>
|
|
197
|
-
{formatter && item?.value !== undefined && item.name ? (
|
|
198
|
-
formatter(item.value, item.name, item, index, item.payload)
|
|
199
|
-
) : (
|
|
200
|
-
<>
|
|
201
|
-
{itemConfig?.icon ? (
|
|
202
|
-
<itemConfig.icon />
|
|
203
|
-
) : (
|
|
204
|
-
!hideIndicator && (
|
|
205
|
-
<div
|
|
206
|
-
className={cn(
|
|
207
|
-
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
208
|
-
{
|
|
209
|
-
"h-2.5 w-2.5": indicator === "dot",
|
|
210
|
-
"w-1": indicator === "line",
|
|
211
|
-
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
212
|
-
indicator === "dashed",
|
|
213
|
-
"my-0.5": nestLabel && indicator === "dashed",
|
|
214
|
-
}
|
|
215
|
-
)}
|
|
216
|
-
style={
|
|
217
|
-
{
|
|
218
|
-
"--color-bg": indicatorColor,
|
|
219
|
-
"--color-border": indicatorColor,
|
|
220
|
-
} as React.CSSProperties
|
|
221
|
-
}
|
|
222
|
-
/>
|
|
223
|
-
)
|
|
224
|
-
)}
|
|
225
|
-
<div
|
|
226
|
-
className={cn(
|
|
227
|
-
"flex flex-1 justify-between leading-none",
|
|
228
|
-
nestLabel ? "items-end" : "items-center"
|
|
229
|
-
)}
|
|
230
|
-
>
|
|
231
|
-
<div className="grid gap-1.5">
|
|
232
|
-
{nestLabel ? tooltipLabel : null}
|
|
233
|
-
<span className="text-muted-foreground">
|
|
234
|
-
{itemConfig?.label || item.name}
|
|
235
|
-
</span>
|
|
236
|
-
</div>
|
|
237
|
-
{item.value && (
|
|
238
|
-
<span className="text-foreground font-mono font-medium tabular-nums">
|
|
239
|
-
{item.value.toLocaleString()}
|
|
240
|
-
</span>
|
|
241
|
-
)}
|
|
242
|
-
</div>
|
|
243
|
-
</>
|
|
244
|
-
)}
|
|
245
|
-
</div>
|
|
246
|
-
);
|
|
247
|
-
})}
|
|
248
|
-
</div>
|
|
249
|
-
</div>
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const ChartLegend = RechartsPrimitive.Legend;
|
|
254
|
-
|
|
255
|
-
function ChartLegendContent({
|
|
256
|
-
className,
|
|
257
|
-
hideIcon = false,
|
|
258
|
-
payload,
|
|
259
|
-
verticalAlign = "bottom",
|
|
260
|
-
nameKey,
|
|
261
|
-
}: React.ComponentProps<"div"> &
|
|
262
|
-
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
|
263
|
-
hideIcon?: boolean;
|
|
264
|
-
nameKey?: string;
|
|
265
|
-
}) {
|
|
266
|
-
const { config } = useChart();
|
|
267
|
-
|
|
268
|
-
if (!payload?.length) {
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return (
|
|
273
|
-
<div
|
|
274
|
-
className={cn(
|
|
275
|
-
"flex items-center justify-center gap-4",
|
|
276
|
-
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
277
|
-
className
|
|
278
|
-
)}
|
|
279
|
-
>
|
|
280
|
-
{payload
|
|
281
|
-
.filter((item) => item.type !== "none")
|
|
282
|
-
.map((item) => {
|
|
283
|
-
const key = `${nameKey || item.dataKey || "value"}`;
|
|
284
|
-
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
285
|
-
|
|
286
|
-
return (
|
|
287
|
-
<div
|
|
288
|
-
key={item.value}
|
|
289
|
-
className={cn(
|
|
290
|
-
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3"
|
|
291
|
-
)}
|
|
292
|
-
>
|
|
293
|
-
{itemConfig?.icon && !hideIcon ? (
|
|
294
|
-
<itemConfig.icon />
|
|
295
|
-
) : (
|
|
296
|
-
<div
|
|
297
|
-
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
298
|
-
style={{
|
|
299
|
-
backgroundColor: item.color,
|
|
300
|
-
}}
|
|
301
|
-
/>
|
|
302
|
-
)}
|
|
303
|
-
{itemConfig?.label}
|
|
304
|
-
</div>
|
|
305
|
-
);
|
|
306
|
-
})}
|
|
307
|
-
</div>
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Helper to extract item config from a payload.
|
|
312
|
-
function getPayloadConfigFromPayload(
|
|
313
|
-
config: ChartConfig,
|
|
314
|
-
payload: unknown,
|
|
315
|
-
key: string
|
|
316
|
-
) {
|
|
317
|
-
if (typeof payload !== "object" || payload === null) {
|
|
318
|
-
return undefined;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const payloadPayload =
|
|
322
|
-
"payload" in payload &&
|
|
323
|
-
typeof payload.payload === "object" &&
|
|
324
|
-
payload.payload !== null
|
|
325
|
-
? payload.payload
|
|
326
|
-
: undefined;
|
|
327
|
-
|
|
328
|
-
let configLabelKey: string = key;
|
|
329
|
-
|
|
330
|
-
if (
|
|
331
|
-
key in payload &&
|
|
332
|
-
typeof payload[key as keyof typeof payload] === "string"
|
|
333
|
-
) {
|
|
334
|
-
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
335
|
-
} else if (
|
|
336
|
-
payloadPayload &&
|
|
337
|
-
key in payloadPayload &&
|
|
338
|
-
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
339
|
-
) {
|
|
340
|
-
configLabelKey = payloadPayload[
|
|
341
|
-
key as keyof typeof payloadPayload
|
|
342
|
-
] as string;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return configLabelKey in config
|
|
346
|
-
? config[configLabelKey]
|
|
347
|
-
: config[key as keyof typeof config];
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export {
|
|
351
|
-
ChartContainer,
|
|
352
|
-
ChartTooltip,
|
|
353
|
-
ChartTooltipContent,
|
|
354
|
-
ChartLegend,
|
|
355
|
-
ChartLegendContent,
|
|
356
|
-
ChartStyle,
|
|
357
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { Checkbox } from "./checkbox";
|
|
4
|
-
import { Label } from "./label";
|
|
5
|
-
import type { CheckedState } from "@radix-ui/react-checkbox";
|
|
6
|
-
|
|
7
|
-
const meta = {
|
|
8
|
-
title: "Components/Checkbox",
|
|
9
|
-
component: Checkbox,
|
|
10
|
-
parameters: {
|
|
11
|
-
layout: "padded",
|
|
12
|
-
},
|
|
13
|
-
tags: ["autodocs"],
|
|
14
|
-
argTypes: {
|
|
15
|
-
checked: {
|
|
16
|
-
control: "boolean",
|
|
17
|
-
description: "Whether the checkbox is checked.",
|
|
18
|
-
},
|
|
19
|
-
disabled: {
|
|
20
|
-
control: "boolean",
|
|
21
|
-
description: "Whether the checkbox is disabled.",
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
} satisfies Meta<typeof Checkbox>;
|
|
25
|
-
|
|
26
|
-
export default meta;
|
|
27
|
-
type Story = StoryObj<typeof meta>;
|
|
28
|
-
|
|
29
|
-
export const Default: Story = {
|
|
30
|
-
render: () => {
|
|
31
|
-
const [checked, setChecked] = useState<CheckedState>();
|
|
32
|
-
return (
|
|
33
|
-
<div className="flex items-center space-x-2">
|
|
34
|
-
<Checkbox id="terms" checked={checked} onCheckedChange={setChecked} />
|
|
35
|
-
<Label htmlFor="terms">Accept terms and conditions</Label>
|
|
36
|
-
</div>
|
|
37
|
-
);
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const Checked: Story = {
|
|
42
|
-
render: () => (
|
|
43
|
-
<div className="flex items-center space-x-2">
|
|
44
|
-
<Checkbox id="checked" defaultChecked />
|
|
45
|
-
<Label htmlFor="checked">Checked by default</Label>
|
|
46
|
-
</div>
|
|
47
|
-
),
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const Disabled: Story = {
|
|
51
|
-
render: () => (
|
|
52
|
-
<div className="space-y-4">
|
|
53
|
-
<div className="flex items-center space-x-2">
|
|
54
|
-
<Checkbox id="disabled" disabled />
|
|
55
|
-
<Label htmlFor="disabled">Disabled unchecked</Label>
|
|
56
|
-
</div>
|
|
57
|
-
<div className="flex items-center space-x-2">
|
|
58
|
-
<Checkbox id="disabled-checked" disabled defaultChecked />
|
|
59
|
-
<Label htmlFor="disabled-checked">Disabled checked</Label>
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
),
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const Multiple: Story = {
|
|
66
|
-
render: () => {
|
|
67
|
-
const [items, setItems] = useState({
|
|
68
|
-
item1: false,
|
|
69
|
-
item2: true,
|
|
70
|
-
item3: false,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<div className="space-y-3">
|
|
75
|
-
<div className="flex items-center space-x-2">
|
|
76
|
-
<Checkbox
|
|
77
|
-
id="item1"
|
|
78
|
-
checked={items.item1}
|
|
79
|
-
onCheckedChange={(checked) =>
|
|
80
|
-
setItems({ ...items, item1: checked as boolean })
|
|
81
|
-
}
|
|
82
|
-
/>
|
|
83
|
-
<Label htmlFor="item1">Item 1</Label>
|
|
84
|
-
</div>
|
|
85
|
-
<div className="flex items-center space-x-2">
|
|
86
|
-
<Checkbox
|
|
87
|
-
id="item2"
|
|
88
|
-
checked={items.item2}
|
|
89
|
-
onCheckedChange={(checked) =>
|
|
90
|
-
setItems({ ...items, item2: checked as boolean })
|
|
91
|
-
}
|
|
92
|
-
/>
|
|
93
|
-
<Label htmlFor="item2">Item 2</Label>
|
|
94
|
-
</div>
|
|
95
|
-
<div className="flex items-center space-x-2">
|
|
96
|
-
<Checkbox
|
|
97
|
-
id="item3"
|
|
98
|
-
checked={items.item3}
|
|
99
|
-
onCheckedChange={(checked) =>
|
|
100
|
-
setItems({ ...items, item3: checked as boolean })
|
|
101
|
-
}
|
|
102
|
-
/>
|
|
103
|
-
<Label htmlFor="item3">Item 3</Label>
|
|
104
|
-
</div>
|
|
105
|
-
</div>
|
|
106
|
-
);
|
|
107
|
-
},
|
|
108
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from "vitest";
|
|
2
|
-
import { render } from "@testing-library/react";
|
|
3
|
-
import userEvent from "@testing-library/user-event";
|
|
4
|
-
import { Checkbox } from "./checkbox";
|
|
5
|
-
|
|
6
|
-
describe("Checkbox", () => {
|
|
7
|
-
it("should render checkbox", () => {
|
|
8
|
-
const { container } = render(<Checkbox />);
|
|
9
|
-
const checkbox = container.querySelector('[data-slot="checkbox"]');
|
|
10
|
-
expect(checkbox).toBeInTheDocument();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("should be checked when checked prop is true", () => {
|
|
14
|
-
const { container } = render(<Checkbox checked />);
|
|
15
|
-
const checkbox = container.querySelector('[data-slot="checkbox"]');
|
|
16
|
-
expect(checkbox).toHaveAttribute("data-state", "checked");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should be unchecked by default", () => {
|
|
20
|
-
const { container } = render(<Checkbox />);
|
|
21
|
-
const checkbox = container.querySelector('[data-slot="checkbox"]');
|
|
22
|
-
expect(checkbox).toHaveAttribute("data-state", "unchecked");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should call onCheckedChange when clicked", async () => {
|
|
26
|
-
const user = userEvent.setup();
|
|
27
|
-
const handleChange = vi.fn();
|
|
28
|
-
const { container } = render(<Checkbox onCheckedChange={handleChange} />);
|
|
29
|
-
const checkbox = container.querySelector(
|
|
30
|
-
'[data-slot="checkbox"]'
|
|
31
|
-
) as HTMLElement;
|
|
32
|
-
await user.click(checkbox);
|
|
33
|
-
expect(handleChange).toHaveBeenCalledWith(true);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("should toggle checked state when clicked", async () => {
|
|
37
|
-
const user = userEvent.setup();
|
|
38
|
-
const handleChange = vi.fn();
|
|
39
|
-
const { container } = render(
|
|
40
|
-
<Checkbox checked={false} onCheckedChange={handleChange} />
|
|
41
|
-
);
|
|
42
|
-
const checkbox = container.querySelector(
|
|
43
|
-
'[data-slot="checkbox"]'
|
|
44
|
-
) as HTMLElement;
|
|
45
|
-
await user.click(checkbox);
|
|
46
|
-
expect(handleChange).toHaveBeenCalledWith(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should be disabled when disabled prop is true", () => {
|
|
50
|
-
const { container } = render(<Checkbox disabled />);
|
|
51
|
-
const checkbox = container.querySelector('[data-slot="checkbox"]');
|
|
52
|
-
expect(checkbox).toHaveAttribute("data-disabled");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should not call onCheckedChange when disabled", async () => {
|
|
56
|
-
const user = userEvent.setup();
|
|
57
|
-
const handleChange = vi.fn();
|
|
58
|
-
const { container } = render(
|
|
59
|
-
<Checkbox disabled onCheckedChange={handleChange} />
|
|
60
|
-
);
|
|
61
|
-
const checkbox = container.querySelector(
|
|
62
|
-
'[data-slot="checkbox"]'
|
|
63
|
-
) as HTMLElement;
|
|
64
|
-
await user.click(checkbox);
|
|
65
|
-
expect(handleChange).not.toHaveBeenCalled();
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import * as React from "react"
|
|
4
|
-
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
|
5
|
-
import { CheckIcon } from "lucide-react"
|
|
6
|
-
|
|
7
|
-
import { cn } from "@/lib/utils"
|
|
8
|
-
|
|
9
|
-
function Checkbox({
|
|
10
|
-
className,
|
|
11
|
-
...props
|
|
12
|
-
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
13
|
-
return (
|
|
14
|
-
<CheckboxPrimitive.Root
|
|
15
|
-
data-slot="checkbox"
|
|
16
|
-
className={cn(
|
|
17
|
-
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
|
18
|
-
className
|
|
19
|
-
)}
|
|
20
|
-
{...props}
|
|
21
|
-
>
|
|
22
|
-
<CheckboxPrimitive.Indicator
|
|
23
|
-
data-slot="checkbox-indicator"
|
|
24
|
-
className="grid place-content-center text-current transition-none"
|
|
25
|
-
>
|
|
26
|
-
<CheckIcon className="size-3.5" />
|
|
27
|
-
</CheckboxPrimitive.Indicator>
|
|
28
|
-
</CheckboxPrimitive.Root>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { Checkbox }
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import {
|
|
4
|
-
Collapsible,
|
|
5
|
-
CollapsibleContent,
|
|
6
|
-
CollapsibleTrigger,
|
|
7
|
-
} from "./collapsible";
|
|
8
|
-
import { Button } from "./button";
|
|
9
|
-
import { ChevronDownIcon } from "lucide-react";
|
|
10
|
-
|
|
11
|
-
const meta = {
|
|
12
|
-
title: "Components/Collapsible",
|
|
13
|
-
component: Collapsible,
|
|
14
|
-
parameters: {
|
|
15
|
-
layout: "padded",
|
|
16
|
-
},
|
|
17
|
-
tags: ["autodocs"],
|
|
18
|
-
} satisfies Meta<typeof Collapsible>;
|
|
19
|
-
|
|
20
|
-
export default meta;
|
|
21
|
-
type Story = StoryObj<typeof meta>;
|
|
22
|
-
|
|
23
|
-
export const Default: Story = {
|
|
24
|
-
render: () => {
|
|
25
|
-
const [open, setOpen] = useState(false);
|
|
26
|
-
return (
|
|
27
|
-
<Collapsible open={open} onOpenChange={setOpen} className="w-[350px]">
|
|
28
|
-
<div className="flex items-center justify-between space-x-4 px-4">
|
|
29
|
-
<h4 className="text-sm font-semibold">
|
|
30
|
-
@peduarte starred 3 repositories
|
|
31
|
-
</h4>
|
|
32
|
-
<CollapsibleTrigger asChild>
|
|
33
|
-
<Button variant="ghost" size="icon">
|
|
34
|
-
<ChevronDownIcon className="h-4 w-4" />
|
|
35
|
-
<span className="sr-only">Toggle</span>
|
|
36
|
-
</Button>
|
|
37
|
-
</CollapsibleTrigger>
|
|
38
|
-
</div>
|
|
39
|
-
<div className="px-4 py-2 space-y-2">
|
|
40
|
-
<div className="rounded-md border px-4 py-2 text-sm">
|
|
41
|
-
@radix-ui/primitives
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
<CollapsibleContent className="space-y-2">
|
|
45
|
-
<div className="rounded-md border px-4 py-2 text-sm">
|
|
46
|
-
@radix-ui/colors
|
|
47
|
-
</div>
|
|
48
|
-
<div className="rounded-md border px-4 py-2 text-sm">
|
|
49
|
-
@stitches/react
|
|
50
|
-
</div>
|
|
51
|
-
</CollapsibleContent>
|
|
52
|
-
</Collapsible>
|
|
53
|
-
);
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const Simple: Story = {
|
|
58
|
-
render: () => {
|
|
59
|
-
const [open, setOpen] = useState(false);
|
|
60
|
-
return (
|
|
61
|
-
<Collapsible open={open} onOpenChange={setOpen} className="w-[350px]">
|
|
62
|
-
<CollapsibleTrigger asChild>
|
|
63
|
-
<Button variant="outline" className="w-full justify-between">
|
|
64
|
-
Click to {open ? "collapse" : "expand"}
|
|
65
|
-
<ChevronDownIcon
|
|
66
|
-
className={`h-4 w-4 transition-transform ${open ? "rotate-180" : ""}`}
|
|
67
|
-
/>
|
|
68
|
-
</Button>
|
|
69
|
-
</CollapsibleTrigger>
|
|
70
|
-
<CollapsibleContent className="mt-2 space-y-2">
|
|
71
|
-
<div className="rounded-md border p-4">
|
|
72
|
-
<p className="text-sm">
|
|
73
|
-
This is the collapsible content. It can contain any content you
|
|
74
|
-
want.
|
|
75
|
-
</p>
|
|
76
|
-
</div>
|
|
77
|
-
</CollapsibleContent>
|
|
78
|
-
</Collapsible>
|
|
79
|
-
);
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const DefaultOpen: Story = {
|
|
84
|
-
render: () => (
|
|
85
|
-
<Collapsible defaultOpen className="w-[350px]">
|
|
86
|
-
<div className="flex items-center justify-between space-x-4 px-4">
|
|
87
|
-
<h4 className="text-sm font-semibold">Open by default</h4>
|
|
88
|
-
<CollapsibleTrigger asChild>
|
|
89
|
-
<Button variant="ghost" size="icon">
|
|
90
|
-
<ChevronDownIcon className="h-4 w-4" />
|
|
91
|
-
<span className="sr-only">Toggle</span>
|
|
92
|
-
</Button>
|
|
93
|
-
</CollapsibleTrigger>
|
|
94
|
-
</div>
|
|
95
|
-
<CollapsibleContent className="space-y-2 px-4">
|
|
96
|
-
<div className="rounded-md border px-4 py-2 text-sm">
|
|
97
|
-
This content is visible by default.
|
|
98
|
-
</div>
|
|
99
|
-
<div className="rounded-md border px-4 py-2 text-sm">
|
|
100
|
-
You can collapse it by clicking the button.
|
|
101
|
-
</div>
|
|
102
|
-
</CollapsibleContent>
|
|
103
|
-
</Collapsible>
|
|
104
|
-
),
|
|
105
|
-
};
|
|
106
|
-
|