@suphark/ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/components.json +21 -0
- package/package.json +108 -0
- package/scripts/audit-base-ui-props.mjs +179 -0
- package/scripts/audit-tailwind-typography.mjs +100 -0
- package/src/components/design-system/design-system-showcase.tsx +138 -0
- package/src/components/design-system/sections/showcase-data-display.tsx +454 -0
- package/src/components/design-system/sections/showcase-feedback.tsx +273 -0
- package/src/components/design-system/sections/showcase-forms.tsx +373 -0
- package/src/components/design-system/sections/showcase-foundations.tsx +384 -0
- package/src/components/design-system/sections/showcase-guidelines-recipes.tsx +397 -0
- package/src/components/design-system/sections/showcase-overlays-navigation.tsx +479 -0
- package/src/components/design-system/sections/showcase-overview.tsx +368 -0
- package/src/components/design-system/sections/showcase-primitives.tsx +463 -0
- package/src/components/shared/__tests__/multi-select-combobox.test.tsx +180 -0
- package/src/components/shared/__tests__/name-id-fields.test.ts +24 -0
- package/src/components/shared/button/add-new-button.tsx +19 -0
- package/src/components/shared/button/base/action-button.tsx +134 -0
- package/src/components/shared/button/base/link-button.tsx +130 -0
- package/src/components/shared/button/cancel-button.tsx +27 -0
- package/src/components/shared/button/confirm-button.tsx +26 -0
- package/src/components/shared/button/delete-button.tsx +36 -0
- package/src/components/shared/button/floating-save-button.tsx +89 -0
- package/src/components/shared/button/index.ts +13 -0
- package/src/components/shared/button/print-button.tsx +67 -0
- package/src/components/shared/button/refresh-button.tsx +63 -0
- package/src/components/shared/button/save-button.tsx +29 -0
- package/src/components/shared/button/submit-button.tsx +58 -0
- package/src/components/shared/client-redirect.tsx +11 -0
- package/src/components/shared/combobox.tsx +116 -0
- package/src/components/shared/data-list.tsx +65 -0
- package/src/components/shared/date/date-range-picker.tsx +106 -0
- package/src/components/shared/description-list.tsx +27 -0
- package/src/components/shared/empty-row.tsx +13 -0
- package/src/components/shared/empty-state.tsx +31 -0
- package/src/components/shared/env-snippet.tsx +62 -0
- package/src/components/shared/form/__tests__/simple-select.test.tsx +72 -0
- package/src/components/shared/form/form-field-boolean.tsx +93 -0
- package/src/components/shared/form/form-field-color-select.tsx +86 -0
- package/src/components/shared/form/form-field-combobox.tsx +167 -0
- package/src/components/shared/form/form-field-date.tsx +55 -0
- package/src/components/shared/form/form-field-formatted-number.tsx +103 -0
- package/src/components/shared/form/form-field-input.tsx +372 -0
- package/src/components/shared/form/form-field-radio-cards.tsx +127 -0
- package/src/components/shared/form/form-field-radio-group.tsx +56 -0
- package/src/components/shared/form/form-field-select.tsx +312 -0
- package/src/components/shared/form/simple-select.tsx +152 -0
- package/src/components/shared/form-dialog.tsx +109 -0
- package/src/components/shared/form-message.tsx +30 -0
- package/src/components/shared/initials.tsx +33 -0
- package/src/components/shared/layout/error-state.tsx +160 -0
- package/src/components/shared/layout/page-shell.tsx +57 -0
- package/src/components/shared/link/transition-link.tsx +72 -0
- package/src/components/shared/multi-select-combobox.tsx +392 -0
- package/src/components/shared/name-id-fields.tsx +133 -0
- package/src/components/shared/navigation/page-breadcrumb.tsx +100 -0
- package/src/components/shared/notice.tsx +35 -0
- package/src/components/shared/number/formatted-number.tsx +133 -0
- package/src/components/shared/page-header.tsx +25 -0
- package/src/components/shared/page-skeleton.tsx +18 -0
- package/src/components/shared/row-actions.tsx +93 -0
- package/src/components/shared/row-menu.tsx +55 -0
- package/src/components/shared/secret-reveal.tsx +53 -0
- package/src/components/shared/section-card.tsx +44 -0
- package/src/components/shared/stat.tsx +26 -0
- package/src/components/shared/status-badge.tsx +47 -0
- package/src/components/shared/text/primary-secondary-text.tsx +186 -0
- package/src/components/shared/theme/index.ts +4 -0
- package/src/components/shared/theme/theme-menu-items.tsx +43 -0
- package/src/components/shared/theme/theme-provider.tsx +39 -0
- package/src/components/shared/theme/theme-switch.tsx +36 -0
- package/src/components/shared/theme/theme-toggle.tsx +76 -0
- package/src/components/shared/time/client-date-formatter.tsx +188 -0
- package/src/components/shared/ui-text.tsx +47 -0
- package/src/components/ui/__tests__/combobox.test.tsx +40 -0
- package/src/components/ui/__tests__/date-picker.test.tsx +53 -0
- package/src/components/ui/__tests__/slider.test.tsx +18 -0
- package/src/components/ui/__tests__/tabs.test.tsx +33 -0
- package/src/components/ui/accordion.tsx +69 -0
- package/src/components/ui/alert-dialog.tsx +161 -0
- package/src/components/ui/alert.tsx +68 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/attachment.tsx +194 -0
- package/src/components/ui/avatar.tsx +92 -0
- package/src/components/ui/badge.tsx +48 -0
- package/src/components/ui/breadcrumb.tsx +102 -0
- package/src/components/ui/button-group.tsx +77 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/calendar.tsx +184 -0
- package/src/components/ui/card.tsx +87 -0
- package/src/components/ui/carousel.tsx +230 -0
- package/src/components/ui/chart.tsx +338 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +17 -0
- package/src/components/ui/combobox.tsx +272 -0
- package/src/components/ui/command.tsx +180 -0
- package/src/components/ui/context-menu.tsx +244 -0
- package/src/components/ui/date-picker.tsx +308 -0
- package/src/components/ui/dialog.tsx +137 -0
- package/src/components/ui/drawer.tsx +208 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/empty.tsx +93 -0
- package/src/components/ui/field.tsx +223 -0
- package/src/components/ui/form.tsx +161 -0
- package/src/components/ui/hover-card.tsx +46 -0
- package/src/components/ui/input-group.tsx +145 -0
- package/src/components/ui/input-otp.tsx +85 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +187 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/menubar.tsx +266 -0
- package/src/components/ui/navigation-menu.tsx +160 -0
- package/src/components/ui/pagination.tsx +117 -0
- package/src/components/ui/popover.tsx +76 -0
- package/src/components/ui/progress.tsx +66 -0
- package/src/components/ui/radio-group.tsx +38 -0
- package/src/components/ui/relative-date.tsx +40 -0
- package/src/components/ui/resizable.tsx +41 -0
- package/src/components/ui/scroll-area.tsx +67 -0
- package/src/components/ui/searchable-select.tsx +124 -0
- package/src/components/ui/select.tsx +189 -0
- package/src/components/ui/separator.tsx +21 -0
- package/src/components/ui/sheet.tsx +124 -0
- package/src/components/ui/sidebar.tsx +691 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +55 -0
- package/src/components/ui/sonner.tsx +45 -0
- package/src/components/ui/spinner.tsx +16 -0
- package/src/components/ui/switch.tsx +32 -0
- package/src/components/ui/table.tsx +95 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toggle-group.tsx +86 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +54 -0
- package/src/hooks/use-copy-to-clipboard.ts +27 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/index.ts +156 -0
- package/src/lib/formatters.ts +44 -0
- package/src/lib/permission.ts +75 -0
- package/src/lib/status-colors.ts +52 -0
- package/src/lib/utils.ts +6 -0
- package/src/next.ts +15 -0
- package/src/styles.css +214 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { cn } from "@suphark/ui/lib/utils";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import type { TooltipValueType } from "recharts";
|
|
6
|
+
import * as RechartsPrimitive from "recharts";
|
|
7
|
+
|
|
8
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
9
|
+
const THEMES = { light: "", dark: ".dark" } as const;
|
|
10
|
+
|
|
11
|
+
const INITIAL_DIMENSION = { width: 320, height: 200 } as const;
|
|
12
|
+
type TooltipNameType = number | string;
|
|
13
|
+
|
|
14
|
+
export type ChartConfig = Record<
|
|
15
|
+
string,
|
|
16
|
+
{
|
|
17
|
+
label?: React.ReactNode;
|
|
18
|
+
icon?: React.ComponentType;
|
|
19
|
+
} & (
|
|
20
|
+
| { color?: string; theme?: never }
|
|
21
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
22
|
+
)
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
type ChartContextProps = {
|
|
26
|
+
config: ChartConfig;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
|
30
|
+
|
|
31
|
+
function useChart() {
|
|
32
|
+
const context = React.useContext(ChartContext);
|
|
33
|
+
|
|
34
|
+
if (!context) {
|
|
35
|
+
throw new Error("useChart must be used within a <ChartContainer />");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return context;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function ChartContainer({
|
|
42
|
+
id,
|
|
43
|
+
className,
|
|
44
|
+
children,
|
|
45
|
+
config,
|
|
46
|
+
initialDimension = INITIAL_DIMENSION,
|
|
47
|
+
...props
|
|
48
|
+
}: React.ComponentProps<"div"> & {
|
|
49
|
+
config: ChartConfig;
|
|
50
|
+
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
|
|
51
|
+
initialDimension?: {
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
};
|
|
55
|
+
}) {
|
|
56
|
+
const uniqueId = React.useId();
|
|
57
|
+
const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<ChartContext.Provider value={{ config }}>
|
|
61
|
+
<div
|
|
62
|
+
data-slot="chart"
|
|
63
|
+
data-chart={chartId}
|
|
64
|
+
className={cn(
|
|
65
|
+
"flex aspect-video justify-center text-xs [&_.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-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.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 [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-hidden [&_.recharts-surface]:outline-hidden",
|
|
66
|
+
className,
|
|
67
|
+
)}
|
|
68
|
+
{...props}
|
|
69
|
+
>
|
|
70
|
+
<ChartStyle id={chartId} config={config} />
|
|
71
|
+
<RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>
|
|
72
|
+
{children}
|
|
73
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
74
|
+
</div>
|
|
75
|
+
</ChartContext.Provider>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
80
|
+
const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);
|
|
81
|
+
|
|
82
|
+
if (!colorConfig.length) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<style
|
|
88
|
+
dangerouslySetInnerHTML={{
|
|
89
|
+
__html: Object.entries(THEMES)
|
|
90
|
+
.map(
|
|
91
|
+
([theme, prefix]) => `
|
|
92
|
+
${prefix} [data-chart=${id}] {
|
|
93
|
+
${colorConfig
|
|
94
|
+
.map(([key, itemConfig]) => {
|
|
95
|
+
const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ?? itemConfig.color;
|
|
96
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
97
|
+
})
|
|
98
|
+
.join("\n")}
|
|
99
|
+
}
|
|
100
|
+
`,
|
|
101
|
+
)
|
|
102
|
+
.join("\n"),
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
109
|
+
|
|
110
|
+
function ChartTooltipContent({
|
|
111
|
+
active,
|
|
112
|
+
payload,
|
|
113
|
+
className,
|
|
114
|
+
indicator = "dot",
|
|
115
|
+
hideLabel = false,
|
|
116
|
+
hideIndicator = false,
|
|
117
|
+
label,
|
|
118
|
+
labelFormatter,
|
|
119
|
+
labelClassName,
|
|
120
|
+
formatter,
|
|
121
|
+
color,
|
|
122
|
+
nameKey,
|
|
123
|
+
labelKey,
|
|
124
|
+
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
125
|
+
React.ComponentProps<"div"> & {
|
|
126
|
+
hideLabel?: boolean;
|
|
127
|
+
hideIndicator?: boolean;
|
|
128
|
+
indicator?: "line" | "dot" | "dashed";
|
|
129
|
+
nameKey?: string;
|
|
130
|
+
labelKey?: string;
|
|
131
|
+
} & Omit<
|
|
132
|
+
RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>,
|
|
133
|
+
"accessibilityLayer"
|
|
134
|
+
>) {
|
|
135
|
+
const { config } = useChart();
|
|
136
|
+
|
|
137
|
+
const tooltipLabel = React.useMemo(() => {
|
|
138
|
+
if (hideLabel || !payload?.length) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const [item] = payload;
|
|
143
|
+
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
|
|
144
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
145
|
+
const value =
|
|
146
|
+
!labelKey && typeof label === "string" ? (config[label]?.label ?? label) : itemConfig?.label;
|
|
147
|
+
|
|
148
|
+
if (labelFormatter) {
|
|
149
|
+
return (
|
|
150
|
+
<div className={cn("font-medium", labelClassName)}>{labelFormatter(value, payload)}</div>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!value) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
159
|
+
}, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
|
|
160
|
+
|
|
161
|
+
if (!active || !payload?.length) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<div
|
|
169
|
+
className={cn(
|
|
170
|
+
"grid min-w-32 items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
|
|
171
|
+
className,
|
|
172
|
+
)}
|
|
173
|
+
>
|
|
174
|
+
{!nestLabel ? tooltipLabel : null}
|
|
175
|
+
<div className="grid gap-1.5">
|
|
176
|
+
{payload
|
|
177
|
+
.filter((item) => item.type !== "none")
|
|
178
|
+
.map((item, index) => {
|
|
179
|
+
const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;
|
|
180
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
181
|
+
const indicatorColor = color ?? item.payload?.fill ?? item.color;
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<div
|
|
185
|
+
key={index}
|
|
186
|
+
className={cn(
|
|
187
|
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
|
|
188
|
+
indicator === "dot" && "items-center",
|
|
189
|
+
)}
|
|
190
|
+
>
|
|
191
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
192
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
193
|
+
) : (
|
|
194
|
+
<>
|
|
195
|
+
{itemConfig?.icon ? (
|
|
196
|
+
<itemConfig.icon />
|
|
197
|
+
) : (
|
|
198
|
+
!hideIndicator && (
|
|
199
|
+
<div
|
|
200
|
+
className={cn(
|
|
201
|
+
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
202
|
+
{
|
|
203
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
204
|
+
"w-1": indicator === "line",
|
|
205
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
206
|
+
indicator === "dashed",
|
|
207
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
208
|
+
},
|
|
209
|
+
)}
|
|
210
|
+
style={
|
|
211
|
+
{
|
|
212
|
+
"--color-bg": indicatorColor,
|
|
213
|
+
"--color-border": indicatorColor,
|
|
214
|
+
} as React.CSSProperties
|
|
215
|
+
}
|
|
216
|
+
/>
|
|
217
|
+
)
|
|
218
|
+
)}
|
|
219
|
+
<div
|
|
220
|
+
className={cn(
|
|
221
|
+
"flex flex-1 justify-between leading-none",
|
|
222
|
+
nestLabel ? "items-end" : "items-center",
|
|
223
|
+
)}
|
|
224
|
+
>
|
|
225
|
+
<div className="grid gap-1.5">
|
|
226
|
+
{nestLabel ? tooltipLabel : null}
|
|
227
|
+
<span className="text-muted-foreground">
|
|
228
|
+
{itemConfig?.label ?? item.name}
|
|
229
|
+
</span>
|
|
230
|
+
</div>
|
|
231
|
+
{item.value != null && (
|
|
232
|
+
<span className="font-medium font-mono text-foreground tabular-nums">
|
|
233
|
+
{typeof item.value === "number"
|
|
234
|
+
? item.value.toLocaleString()
|
|
235
|
+
: String(item.value)}
|
|
236
|
+
</span>
|
|
237
|
+
)}
|
|
238
|
+
</div>
|
|
239
|
+
</>
|
|
240
|
+
)}
|
|
241
|
+
</div>
|
|
242
|
+
);
|
|
243
|
+
})}
|
|
244
|
+
</div>
|
|
245
|
+
</div>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const ChartLegend = RechartsPrimitive.Legend;
|
|
250
|
+
|
|
251
|
+
function ChartLegendContent({
|
|
252
|
+
className,
|
|
253
|
+
hideIcon = false,
|
|
254
|
+
payload,
|
|
255
|
+
verticalAlign = "bottom",
|
|
256
|
+
nameKey,
|
|
257
|
+
}: React.ComponentProps<"div"> & {
|
|
258
|
+
hideIcon?: boolean;
|
|
259
|
+
nameKey?: string;
|
|
260
|
+
} & RechartsPrimitive.DefaultLegendContentProps) {
|
|
261
|
+
const { config } = useChart();
|
|
262
|
+
|
|
263
|
+
if (!payload?.length) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<div
|
|
269
|
+
className={cn(
|
|
270
|
+
"flex items-center justify-center gap-4",
|
|
271
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
272
|
+
className,
|
|
273
|
+
)}
|
|
274
|
+
>
|
|
275
|
+
{payload
|
|
276
|
+
.filter((item) => item.type !== "none")
|
|
277
|
+
.map((item, index) => {
|
|
278
|
+
const key = `${nameKey ?? item.dataKey ?? "value"}`;
|
|
279
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<div
|
|
283
|
+
key={index}
|
|
284
|
+
className={cn(
|
|
285
|
+
"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",
|
|
286
|
+
)}
|
|
287
|
+
>
|
|
288
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
289
|
+
<itemConfig.icon />
|
|
290
|
+
) : (
|
|
291
|
+
<div
|
|
292
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
293
|
+
style={{
|
|
294
|
+
backgroundColor: item.color,
|
|
295
|
+
}}
|
|
296
|
+
/>
|
|
297
|
+
)}
|
|
298
|
+
{itemConfig?.label}
|
|
299
|
+
</div>
|
|
300
|
+
);
|
|
301
|
+
})}
|
|
302
|
+
</div>
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {
|
|
307
|
+
if (typeof payload !== "object" || payload === null) {
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const payloadPayload =
|
|
312
|
+
"payload" in payload && typeof payload.payload === "object" && payload.payload !== null
|
|
313
|
+
? payload.payload
|
|
314
|
+
: undefined;
|
|
315
|
+
|
|
316
|
+
let configLabelKey: string = key;
|
|
317
|
+
|
|
318
|
+
if (key in payload && typeof payload[key as keyof typeof payload] === "string") {
|
|
319
|
+
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
320
|
+
} else if (
|
|
321
|
+
payloadPayload &&
|
|
322
|
+
key in payloadPayload &&
|
|
323
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
324
|
+
) {
|
|
325
|
+
configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return configLabelKey in config ? config[configLabelKey] : config[key];
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export {
|
|
332
|
+
ChartContainer,
|
|
333
|
+
ChartLegend,
|
|
334
|
+
ChartLegendContent,
|
|
335
|
+
ChartStyle,
|
|
336
|
+
ChartTooltip,
|
|
337
|
+
ChartTooltipContent,
|
|
338
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox";
|
|
4
|
+
import { cn } from "@suphark/ui/lib/utils";
|
|
5
|
+
import { CheckIcon } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) {
|
|
8
|
+
return (
|
|
9
|
+
<CheckboxPrimitive.Root
|
|
10
|
+
data-slot="checkbox"
|
|
11
|
+
className={cn(
|
|
12
|
+
"peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input outline-none transition-colors after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 group-has-[:focus-visible]/field-label:not-data-checked:border-input group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:bg-input/30 dark:data-checked:bg-primary dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
13
|
+
className,
|
|
14
|
+
)}
|
|
15
|
+
{...props}
|
|
16
|
+
>
|
|
17
|
+
<CheckboxPrimitive.Indicator
|
|
18
|
+
data-slot="checkbox-indicator"
|
|
19
|
+
className="grid place-content-center text-current transition-none [&>svg]:size-3.5"
|
|
20
|
+
>
|
|
21
|
+
<CheckIcon />
|
|
22
|
+
</CheckboxPrimitive.Indicator>
|
|
23
|
+
</CheckboxPrimitive.Root>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { Checkbox };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible";
|
|
4
|
+
|
|
5
|
+
function Collapsible({ ...props }: CollapsiblePrimitive.Root.Props) {
|
|
6
|
+
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function CollapsibleTrigger({ ...props }: CollapsiblePrimitive.Trigger.Props) {
|
|
10
|
+
return <CollapsiblePrimitive.Trigger data-slot="collapsible-trigger" {...props} />;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function CollapsibleContent({ ...props }: CollapsiblePrimitive.Panel.Props) {
|
|
14
|
+
return <CollapsiblePrimitive.Panel data-slot="collapsible-content" {...props} />;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { Collapsible, CollapsibleContent, CollapsibleTrigger };
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Combobox as ComboboxPrimitive } from "@base-ui/react";
|
|
4
|
+
import { Button } from "@suphark/ui/components/ui/button";
|
|
5
|
+
import {
|
|
6
|
+
InputGroup,
|
|
7
|
+
InputGroupAddon,
|
|
8
|
+
InputGroupButton,
|
|
9
|
+
InputGroupInput,
|
|
10
|
+
} from "@suphark/ui/components/ui/input-group";
|
|
11
|
+
import { cn } from "@suphark/ui/lib/utils";
|
|
12
|
+
import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react";
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
|
|
15
|
+
const Combobox = ComboboxPrimitive.Root;
|
|
16
|
+
|
|
17
|
+
function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props) {
|
|
18
|
+
return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function ComboboxTrigger({ className, children, ...props }: ComboboxPrimitive.Trigger.Props) {
|
|
22
|
+
return (
|
|
23
|
+
<ComboboxPrimitive.Trigger
|
|
24
|
+
data-slot="combobox-trigger"
|
|
25
|
+
className={cn("[&_svg:not([class*='size-'])]:size-4", className)}
|
|
26
|
+
{...props}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
<ChevronDownIcon className="pointer-events-none size-4 text-muted-foreground" />
|
|
30
|
+
</ComboboxPrimitive.Trigger>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) {
|
|
35
|
+
return (
|
|
36
|
+
<ComboboxPrimitive.Clear
|
|
37
|
+
data-slot="combobox-clear"
|
|
38
|
+
render={<InputGroupButton variant="ghost" size="icon-xs" />}
|
|
39
|
+
className={cn(className)}
|
|
40
|
+
{...props}
|
|
41
|
+
>
|
|
42
|
+
<XIcon className="pointer-events-none" />
|
|
43
|
+
</ComboboxPrimitive.Clear>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function ComboboxInput({
|
|
48
|
+
className,
|
|
49
|
+
children,
|
|
50
|
+
disabled = false,
|
|
51
|
+
showTrigger = true,
|
|
52
|
+
showClear = false,
|
|
53
|
+
...props
|
|
54
|
+
}: ComboboxPrimitive.Input.Props & {
|
|
55
|
+
showTrigger?: boolean;
|
|
56
|
+
showClear?: boolean;
|
|
57
|
+
}) {
|
|
58
|
+
return (
|
|
59
|
+
<InputGroup className={cn("w-auto", className)}>
|
|
60
|
+
<ComboboxPrimitive.Input render={<InputGroupInput disabled={disabled} />} {...props} />
|
|
61
|
+
<InputGroupAddon align="inline-end">
|
|
62
|
+
{showTrigger && (
|
|
63
|
+
<InputGroupButton
|
|
64
|
+
size="icon-xs"
|
|
65
|
+
variant="ghost"
|
|
66
|
+
render={<ComboboxTrigger />}
|
|
67
|
+
data-slot="input-group-button"
|
|
68
|
+
className="group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent"
|
|
69
|
+
disabled={disabled}
|
|
70
|
+
/>
|
|
71
|
+
)}
|
|
72
|
+
{showClear && <ComboboxClear disabled={disabled} />}
|
|
73
|
+
</InputGroupAddon>
|
|
74
|
+
{children}
|
|
75
|
+
</InputGroup>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function ComboboxContent({
|
|
80
|
+
className,
|
|
81
|
+
side = "bottom",
|
|
82
|
+
sideOffset = 6,
|
|
83
|
+
align = "start",
|
|
84
|
+
alignOffset = 0,
|
|
85
|
+
anchor,
|
|
86
|
+
...props
|
|
87
|
+
}: ComboboxPrimitive.Popup.Props &
|
|
88
|
+
Pick<
|
|
89
|
+
ComboboxPrimitive.Positioner.Props,
|
|
90
|
+
"side" | "align" | "sideOffset" | "alignOffset" | "anchor"
|
|
91
|
+
>) {
|
|
92
|
+
return (
|
|
93
|
+
<ComboboxPrimitive.Portal>
|
|
94
|
+
<ComboboxPrimitive.Positioner
|
|
95
|
+
side={side}
|
|
96
|
+
sideOffset={sideOffset}
|
|
97
|
+
align={align}
|
|
98
|
+
alignOffset={alignOffset}
|
|
99
|
+
anchor={anchor}
|
|
100
|
+
className="isolate z-50"
|
|
101
|
+
>
|
|
102
|
+
<ComboboxPrimitive.Popup
|
|
103
|
+
data-slot="combobox-content"
|
|
104
|
+
data-chips={!!anchor}
|
|
105
|
+
className={cn(
|
|
106
|
+
"group/combobox-content data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:fade-in-0 data-open:zoom-in-95 data-closed:fade-out-0 data-closed:zoom-out-95 relative max-h-(--available-height) w-(--anchor-width) min-w-[calc(var(--anchor-width)+--spacing(7))] max-w-(--available-width) origin-(--transform-origin) overflow-hidden rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[chips=true]:min-w-(--anchor-width) data-closed:animate-out data-open:animate-in *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-8 *:data-[slot=input-group]:border-input/30 *:data-[slot=input-group]:bg-input/30 *:data-[slot=input-group]:shadow-none",
|
|
107
|
+
className,
|
|
108
|
+
)}
|
|
109
|
+
{...props}
|
|
110
|
+
/>
|
|
111
|
+
</ComboboxPrimitive.Positioner>
|
|
112
|
+
</ComboboxPrimitive.Portal>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) {
|
|
117
|
+
return (
|
|
118
|
+
<ComboboxPrimitive.List
|
|
119
|
+
data-slot="combobox-list"
|
|
120
|
+
className={cn(
|
|
121
|
+
"no-scrollbar max-h-[min(calc(--spacing(72)---spacing(9)),calc(var(--available-height)---spacing(9)))] scroll-py-1 overflow-y-auto overscroll-contain p-1 data-empty:p-0",
|
|
122
|
+
className,
|
|
123
|
+
)}
|
|
124
|
+
{...props}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function ComboboxItem({ className, children, ...props }: ComboboxPrimitive.Item.Props) {
|
|
130
|
+
return (
|
|
131
|
+
<ComboboxPrimitive.Item
|
|
132
|
+
data-slot="combobox-item"
|
|
133
|
+
className={cn(
|
|
134
|
+
"relative flex w-full cursor-default select-none items-center gap-2 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-50 not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
135
|
+
className,
|
|
136
|
+
)}
|
|
137
|
+
{...props}
|
|
138
|
+
>
|
|
139
|
+
{children}
|
|
140
|
+
<ComboboxPrimitive.ItemIndicator
|
|
141
|
+
render={
|
|
142
|
+
<span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center" />
|
|
143
|
+
}
|
|
144
|
+
>
|
|
145
|
+
<CheckIcon className="pointer-events-none" />
|
|
146
|
+
</ComboboxPrimitive.ItemIndicator>
|
|
147
|
+
</ComboboxPrimitive.Item>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function ComboboxGroup({ className, ...props }: ComboboxPrimitive.Group.Props) {
|
|
152
|
+
return (
|
|
153
|
+
<ComboboxPrimitive.Group data-slot="combobox-group" className={cn(className)} {...props} />
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function ComboboxLabel({ className, ...props }: ComboboxPrimitive.GroupLabel.Props) {
|
|
158
|
+
return (
|
|
159
|
+
<ComboboxPrimitive.GroupLabel
|
|
160
|
+
data-slot="combobox-label"
|
|
161
|
+
className={cn("px-2 py-1.5 text-muted-foreground text-xs", className)}
|
|
162
|
+
{...props}
|
|
163
|
+
/>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function ComboboxCollection({ ...props }: ComboboxPrimitive.Collection.Props) {
|
|
168
|
+
return <ComboboxPrimitive.Collection data-slot="combobox-collection" {...props} />;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) {
|
|
172
|
+
return (
|
|
173
|
+
<ComboboxPrimitive.Empty
|
|
174
|
+
data-slot="combobox-empty"
|
|
175
|
+
className={cn(
|
|
176
|
+
"hidden w-full justify-center py-2 text-center text-muted-foreground text-sm group-data-empty/combobox-content:flex",
|
|
177
|
+
className,
|
|
178
|
+
)}
|
|
179
|
+
{...props}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function ComboboxSeparator({ className, ...props }: ComboboxPrimitive.Separator.Props) {
|
|
185
|
+
return (
|
|
186
|
+
<ComboboxPrimitive.Separator
|
|
187
|
+
data-slot="combobox-separator"
|
|
188
|
+
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
|
189
|
+
{...props}
|
|
190
|
+
/>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function ComboboxChips({
|
|
195
|
+
className,
|
|
196
|
+
...props
|
|
197
|
+
}: React.ComponentPropsWithRef<typeof ComboboxPrimitive.Chips> & ComboboxPrimitive.Chips.Props) {
|
|
198
|
+
return (
|
|
199
|
+
<ComboboxPrimitive.Chips
|
|
200
|
+
data-slot="combobox-chips"
|
|
201
|
+
className={cn(
|
|
202
|
+
"flex min-h-8 flex-wrap items-center gap-1 rounded-lg border border-input bg-transparent bg-clip-padding px-2.5 py-1 text-sm transition-colors focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50 has-aria-invalid:border-destructive has-data-[slot=combobox-chip]:px-1 has-aria-invalid:ring-3 has-aria-invalid:ring-destructive/20 dark:bg-input/30 dark:has-aria-invalid:border-destructive/50 dark:has-aria-invalid:ring-destructive/40",
|
|
203
|
+
className,
|
|
204
|
+
)}
|
|
205
|
+
{...props}
|
|
206
|
+
/>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function ComboboxChip({
|
|
211
|
+
className,
|
|
212
|
+
children,
|
|
213
|
+
showRemove = true,
|
|
214
|
+
...props
|
|
215
|
+
}: ComboboxPrimitive.Chip.Props & {
|
|
216
|
+
showRemove?: boolean;
|
|
217
|
+
}) {
|
|
218
|
+
return (
|
|
219
|
+
<ComboboxPrimitive.Chip
|
|
220
|
+
data-slot="combobox-chip"
|
|
221
|
+
className={cn(
|
|
222
|
+
"flex h-[calc(--spacing(5.25))] w-fit items-center justify-center gap-1 whitespace-nowrap rounded-sm bg-muted px-1.5 font-medium text-foreground text-xs has-disabled:pointer-events-none has-disabled:cursor-not-allowed has-data-[slot=combobox-chip-remove]:pr-0 has-disabled:opacity-50",
|
|
223
|
+
className,
|
|
224
|
+
)}
|
|
225
|
+
{...props}
|
|
226
|
+
>
|
|
227
|
+
{children}
|
|
228
|
+
{showRemove && (
|
|
229
|
+
<ComboboxPrimitive.ChipRemove
|
|
230
|
+
render={<Button variant="ghost" size="icon-xs" />}
|
|
231
|
+
className="-ml-1 opacity-50 hover:opacity-100"
|
|
232
|
+
data-slot="combobox-chip-remove"
|
|
233
|
+
>
|
|
234
|
+
<XIcon className="pointer-events-none" />
|
|
235
|
+
</ComboboxPrimitive.ChipRemove>
|
|
236
|
+
)}
|
|
237
|
+
</ComboboxPrimitive.Chip>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function ComboboxChipsInput({ className, ...props }: ComboboxPrimitive.Input.Props) {
|
|
242
|
+
return (
|
|
243
|
+
<ComboboxPrimitive.Input
|
|
244
|
+
data-slot="combobox-chip-input"
|
|
245
|
+
className={cn("min-w-16 flex-1 outline-none", className)}
|
|
246
|
+
{...props}
|
|
247
|
+
/>
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function useComboboxAnchor() {
|
|
252
|
+
return React.useRef<HTMLDivElement | null>(null);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export {
|
|
256
|
+
Combobox,
|
|
257
|
+
ComboboxChip,
|
|
258
|
+
ComboboxChips,
|
|
259
|
+
ComboboxChipsInput,
|
|
260
|
+
ComboboxCollection,
|
|
261
|
+
ComboboxContent,
|
|
262
|
+
ComboboxEmpty,
|
|
263
|
+
ComboboxGroup,
|
|
264
|
+
ComboboxInput,
|
|
265
|
+
ComboboxItem,
|
|
266
|
+
ComboboxLabel,
|
|
267
|
+
ComboboxList,
|
|
268
|
+
ComboboxSeparator,
|
|
269
|
+
ComboboxTrigger,
|
|
270
|
+
ComboboxValue,
|
|
271
|
+
useComboboxAnchor,
|
|
272
|
+
};
|