@raydenui/ui 0.9.7 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -49
- package/dist/Table-DCNSxua1.d.cts +31 -0
- package/dist/Table-DCNSxua1.d.ts +31 -0
- package/dist/blocks/ApplicationShellBlock.cjs +157 -0
- package/dist/blocks/ApplicationShellBlock.js +154 -0
- package/dist/blocks/CheckoutReviewBlock.cjs +16 -0
- package/dist/blocks/CheckoutReviewBlock.js +13 -0
- package/dist/blocks/CommandPaletteBlock.cjs +334 -0
- package/dist/blocks/CommandPaletteBlock.js +331 -0
- package/dist/blocks/CreateAccountBlock.cjs +147 -0
- package/dist/blocks/CreateAccountBlock.js +143 -0
- package/dist/blocks/EmptyStateBlock.cjs +19 -0
- package/dist/blocks/EmptyStateBlock.js +16 -0
- package/dist/blocks/FeatureOverviewBlock.cjs +54 -0
- package/dist/blocks/FeatureOverviewBlock.js +51 -0
- package/dist/blocks/HeaderBlock.cjs +230 -0
- package/dist/blocks/HeaderBlock.js +227 -0
- package/dist/blocks/KpiOverviewBlock.cjs +63 -0
- package/dist/blocks/KpiOverviewBlock.js +60 -0
- package/dist/blocks/LoginBlock.cjs +66 -0
- package/dist/blocks/LoginBlock.js +63 -0
- package/dist/blocks/NotificationsBlock.cjs +17 -0
- package/dist/blocks/NotificationsBlock.js +14 -0
- package/dist/blocks/PageHeaderBlock.cjs +121 -0
- package/dist/blocks/PageHeaderBlock.js +118 -0
- package/dist/blocks/PricingPlansBlock.cjs +146 -0
- package/dist/blocks/PricingPlansBlock.js +143 -0
- package/dist/blocks/ProductCollectionBlock.cjs +37 -0
- package/dist/blocks/ProductCollectionBlock.js +34 -0
- package/dist/blocks/ProductDetailBlock.cjs +30 -0
- package/dist/blocks/ProductDetailBlock.js +27 -0
- package/dist/blocks/ProductHeroBlock.cjs +83 -0
- package/dist/blocks/ProductHeroBlock.js +80 -0
- package/dist/blocks/ProfileSettingsBlock.cjs +130 -0
- package/dist/blocks/ProfileSettingsBlock.js +126 -0
- package/dist/blocks/QuickSendBlock.cjs +11 -0
- package/dist/blocks/QuickSendBlock.js +8 -0
- package/dist/blocks/RecentTransactionsBlock.cjs +13 -0
- package/dist/blocks/RecentTransactionsBlock.js +10 -0
- package/dist/blocks/SearchableTableBlock.cjs +91 -0
- package/dist/blocks/SearchableTableBlock.js +88 -0
- package/dist/blocks/ShoppingCartBlock.cjs +16 -0
- package/dist/blocks/ShoppingCartBlock.js +13 -0
- package/dist/blocks/SiteFooterBlock.cjs +69 -0
- package/dist/blocks/SiteFooterBlock.js +66 -0
- package/dist/blocks/TableBlock.cjs +20 -0
- package/dist/blocks/TableBlock.js +17 -0
- package/dist/blocks/TaskListBlock.cjs +198 -0
- package/dist/blocks/TaskListBlock.js +195 -0
- package/dist/blocks/WorkspaceSwitcherBlock.cjs +291 -0
- package/dist/blocks/WorkspaceSwitcherBlock.js +288 -0
- package/dist/blocks/commerce.cjs +44 -0
- package/dist/blocks/commerce.js +35 -0
- package/dist/blocks/index.cjs +53 -0
- package/dist/blocks/index.js +24 -0
- package/dist/blocks.d.cts +1820 -0
- package/dist/blocks.d.ts +1820 -0
- package/dist/chart.cjs +13 -0
- package/dist/chart.d.cts +59 -0
- package/dist/chart.d.ts +59 -0
- package/dist/chart.js +5 -0
- package/dist/components/Accordion/Accordion.cjs +94 -0
- package/dist/components/Accordion/Accordion.js +91 -0
- package/dist/components/Accordion/index.cjs +8 -0
- package/dist/components/Accordion/index.js +1 -0
- package/dist/components/ActivityFeed/ActivityContent.cjs +40 -0
- package/dist/components/ActivityFeed/ActivityContent.js +37 -0
- package/dist/components/ActivityFeed/ActivityItem.cjs +19 -0
- package/dist/components/ActivityFeed/ActivityItem.js +16 -0
- package/dist/components/ActivityFeed/index.cjs +7 -0
- package/dist/components/ActivityFeed/index.js +2 -0
- package/dist/components/Alert/Alert.cjs +42 -0
- package/dist/components/Alert/Alert.js +39 -0
- package/dist/components/Alert/index.cjs +5 -0
- package/dist/components/Alert/index.js +1 -0
- package/dist/components/Avatar/Avatar.cjs +101 -0
- package/dist/components/Avatar/Avatar.js +98 -0
- package/dist/components/Avatar/index.cjs +6 -0
- package/dist/components/Avatar/index.js +1 -0
- package/dist/components/Badge/Badge.cjs +53 -0
- package/dist/components/Badge/Badge.js +50 -0
- package/dist/components/Badge/index.cjs +5 -0
- package/dist/components/Badge/index.js +1 -0
- package/dist/components/Banner/Banner.cjs +83 -0
- package/dist/components/Banner/Banner.js +80 -0
- package/dist/components/Banner/index.cjs +5 -0
- package/dist/components/Banner/index.js +1 -0
- package/dist/components/Breadcrumb/Breadcrumb.cjs +31 -0
- package/dist/components/Breadcrumb/Breadcrumb.js +28 -0
- package/dist/components/Breadcrumb/index.cjs +5 -0
- package/dist/components/Breadcrumb/index.js +1 -0
- package/dist/components/Button/Button.cjs +88 -0
- package/dist/components/Button/Button.js +85 -0
- package/dist/components/Button/index.cjs +5 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/ButtonGroup/ButtonGroup.cjs +8 -0
- package/dist/components/ButtonGroup/ButtonGroup.js +5 -0
- package/dist/components/ButtonGroup/ButtonGroupItem.cjs +15 -0
- package/dist/components/ButtonGroup/ButtonGroupItem.js +12 -0
- package/dist/components/ButtonGroup/index.cjs +7 -0
- package/dist/components/ButtonGroup/index.js +2 -0
- package/dist/components/Card/Card.cjs +94 -0
- package/dist/components/Card/Card.js +91 -0
- package/dist/components/Card/index.cjs +9 -0
- package/dist/components/Card/index.js +1 -0
- package/dist/components/Chart/Chart.cjs +160 -0
- package/dist/components/Chart/Chart.js +153 -0
- package/dist/components/Chart/index.cjs +10 -0
- package/dist/components/Chart/index.js +2 -0
- package/dist/components/Chart/theme.cjs +67 -0
- package/dist/components/Chart/theme.js +62 -0
- package/dist/components/Chip/Chip.cjs +18 -0
- package/dist/components/Chip/Chip.js +15 -0
- package/dist/components/Chip/index.cjs +5 -0
- package/dist/components/Chip/index.js +1 -0
- package/dist/components/Counter/Counter.cjs +74 -0
- package/dist/components/Counter/Counter.js +71 -0
- package/dist/components/Counter/index.cjs +6 -0
- package/dist/components/Counter/index.js +1 -0
- package/dist/components/DatePicker/DatePicker.cjs +343 -0
- package/dist/components/DatePicker/DatePicker.js +340 -0
- package/dist/components/DatePicker/index.cjs +5 -0
- package/dist/components/DatePicker/index.js +1 -0
- package/dist/components/Divider/Divider.cjs +31 -0
- package/dist/components/Divider/Divider.js +28 -0
- package/dist/components/Divider/index.cjs +5 -0
- package/dist/components/Divider/index.js +1 -0
- package/dist/components/DropdownMenu/DropdownMenu.cjs +108 -0
- package/dist/components/DropdownMenu/DropdownMenu.js +105 -0
- package/dist/components/DropdownMenu/index.cjs +11 -0
- package/dist/components/DropdownMenu/index.js +1 -0
- package/dist/components/EmptyStateIllustration/EmptyStateIllustration.cjs +42 -0
- package/dist/components/EmptyStateIllustration/EmptyStateIllustration.js +39 -0
- package/dist/components/EmptyStateIllustration/illustrations.cjs +3322 -0
- package/dist/components/EmptyStateIllustration/illustrations.js +3319 -0
- package/dist/components/EmptyStateIllustration/index.cjs +7 -0
- package/dist/components/EmptyStateIllustration/index.js +2 -0
- package/dist/components/FileUpload/FileUpload.cjs +116 -0
- package/dist/components/FileUpload/FileUpload.js +113 -0
- package/dist/components/FileUpload/FileUploadDropZone.cjs +58 -0
- package/dist/components/FileUpload/FileUploadDropZone.js +55 -0
- package/dist/components/FileUpload/FileUploadIcons.cjs +55 -0
- package/dist/components/FileUpload/FileUploadIcons.js +50 -0
- package/dist/components/FileUpload/FileUploadItem.cjs +34 -0
- package/dist/components/FileUpload/FileUploadItem.js +31 -0
- package/dist/components/FileUpload/index.cjs +9 -0
- package/dist/components/FileUpload/index.js +3 -0
- package/dist/components/FormControl/Checkbox.cjs +27 -0
- package/dist/components/FormControl/Checkbox.js +24 -0
- package/dist/components/FormControl/Radio.cjs +15 -0
- package/dist/components/FormControl/Radio.js +12 -0
- package/dist/components/FormControl/Toggle.cjs +15 -0
- package/dist/components/FormControl/Toggle.js +12 -0
- package/dist/components/FormControl/index.cjs +9 -0
- package/dist/components/FormControl/index.js +3 -0
- package/dist/components/Icon/Icon.cjs +70 -0
- package/dist/components/Icon/Icon.js +34 -0
- package/dist/components/Icon/catalog.cjs +1672 -0
- package/dist/components/Icon/catalog.js +1669 -0
- package/dist/components/Icon/icons.cjs +5621 -0
- package/dist/components/Icon/icons.js +5610 -0
- package/dist/components/Icon/index.cjs +8 -0
- package/dist/components/Icon/index.js +2 -0
- package/dist/components/Input/Input.cjs +64 -0
- package/dist/components/Input/Input.js +61 -0
- package/dist/components/Input/index.cjs +5 -0
- package/dist/components/Input/index.js +1 -0
- package/dist/components/MetricsCard/MetricsCard.cjs +107 -0
- package/dist/components/MetricsCard/MetricsCard.js +104 -0
- package/dist/components/MetricsCard/index.cjs +5 -0
- package/dist/components/MetricsCard/index.js +1 -0
- package/dist/components/Modal/Modal.cjs +126 -0
- package/dist/components/Modal/Modal.js +123 -0
- package/dist/components/Modal/index.cjs +5 -0
- package/dist/components/Modal/index.js +1 -0
- package/dist/components/Pagination/Pagination.cjs +42 -0
- package/dist/components/Pagination/Pagination.js +39 -0
- package/dist/components/Pagination/index.cjs +5 -0
- package/dist/components/Pagination/index.js +1 -0
- package/dist/components/ProgressBar/ProgressBar.cjs +34 -0
- package/dist/components/ProgressBar/ProgressBar.js +31 -0
- package/dist/components/ProgressBar/index.cjs +5 -0
- package/dist/components/ProgressBar/index.js +1 -0
- package/dist/components/ProgressCircle/ProgressCircle.cjs +34 -0
- package/dist/components/ProgressCircle/ProgressCircle.js +31 -0
- package/dist/components/ProgressCircle/index.cjs +5 -0
- package/dist/components/ProgressCircle/index.js +1 -0
- package/dist/components/Select/Select.cjs +84 -0
- package/dist/components/Select/Select.js +80 -0
- package/dist/components/Select/SelectOption.cjs +26 -0
- package/dist/components/Select/SelectOption.js +23 -0
- package/dist/components/Select/index.cjs +7 -0
- package/dist/components/Select/index.js +2 -0
- package/dist/components/SidebarMenu/SidebarMenu.cjs +85 -0
- package/dist/components/SidebarMenu/SidebarMenu.js +81 -0
- package/dist/components/SidebarMenu/SidebarMenuItem.cjs +126 -0
- package/dist/components/SidebarMenu/SidebarMenuItem.js +122 -0
- package/dist/components/SidebarMenu/SidebarMenuSection.cjs +14 -0
- package/dist/components/SidebarMenu/SidebarMenuSection.js +11 -0
- package/dist/components/SidebarMenu/index.cjs +12 -0
- package/dist/components/SidebarMenu/index.js +4 -0
- package/dist/components/Slider/Slider.cjs +161 -0
- package/dist/components/Slider/Slider.js +158 -0
- package/dist/components/Slider/index.cjs +6 -0
- package/dist/components/Slider/index.js +1 -0
- package/dist/components/Spinner/Spinner.cjs +93 -0
- package/dist/components/Spinner/Spinner.js +90 -0
- package/dist/components/Spinner/index.cjs +5 -0
- package/dist/components/Spinner/index.js +1 -0
- package/dist/components/Stepper/Stepper.cjs +82 -0
- package/dist/components/Stepper/Stepper.js +79 -0
- package/dist/components/Stepper/index.cjs +7 -0
- package/dist/components/Stepper/index.js +1 -0
- package/dist/components/Table/Table.cjs +25 -0
- package/dist/components/Table/Table.js +22 -0
- package/dist/components/Table/index.cjs +10 -0
- package/dist/components/Table/index.js +1 -0
- package/dist/components/Table/useTableSelection.cjs +60 -0
- package/dist/components/Table/useTableSelection.js +57 -0
- package/dist/components/Tabs/Tab.cjs +70 -0
- package/dist/components/Tabs/Tab.js +67 -0
- package/dist/components/Tabs/Tabs.cjs +133 -0
- package/dist/components/Tabs/Tabs.js +129 -0
- package/dist/components/Tabs/index.cjs +7 -0
- package/dist/components/Tabs/index.js +2 -0
- package/dist/components/Tooltip/Tooltip.cjs +101 -0
- package/dist/components/Tooltip/Tooltip.js +98 -0
- package/dist/components/Tooltip/index.cjs +5 -0
- package/dist/components/Tooltip/index.js +1 -0
- package/dist/context/ThemeContext.cjs +97 -0
- package/dist/context/ThemeContext.js +92 -0
- package/dist/fonts/README.md +13 -0
- package/dist/fonts/hanken-grotesk-cyrillic-ext-italic.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-cyrillic-ext-normal.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-latin-ext-italic.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-latin-ext-normal.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-latin-italic.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-latin-normal.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-vietnamese-italic.woff2 +0 -0
- package/dist/fonts/hanken-grotesk-vietnamese-normal.woff2 +0 -0
- package/dist/fonts/hankengrotesk-LICENSE.txt +94 -0
- package/dist/fonts/manrope-LICENSE.txt +93 -0
- package/dist/fonts/manrope-cyrillic-ext-normal.woff2 +0 -0
- package/dist/fonts/manrope-cyrillic-normal.woff2 +0 -0
- package/dist/fonts/manrope-greek-normal.woff2 +0 -0
- package/dist/fonts/manrope-latin-ext-normal.woff2 +0 -0
- package/dist/fonts/manrope-latin-normal.woff2 +0 -0
- package/dist/fonts/manrope-vietnamese-normal.woff2 +0 -0
- package/dist/fonts.css +148 -0
- package/dist/hooks/form/index.cjs +11 -0
- package/dist/hooks/form/index.js +3 -0
- package/dist/hooks/form/useRaydenFormControl.cjs +81 -0
- package/dist/hooks/form/useRaydenFormControl.js +76 -0
- package/dist/hooks/form/useRaydenInput.cjs +38 -0
- package/dist/hooks/form/useRaydenInput.js +35 -0
- package/dist/hooks/form/useRaydenSelect.cjs +45 -0
- package/dist/hooks/form/useRaydenSelect.js +42 -0
- package/dist/hooks/index.cjs +17 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useBodyScrollLock.cjs +24 -0
- package/dist/hooks/useBodyScrollLock.js +21 -0
- package/dist/hooks/useCollisionAwareSide.cjs +72 -0
- package/dist/hooks/useCollisionAwareSide.js +69 -0
- package/dist/hooks/useControllableValue.cjs +16 -0
- package/dist/hooks/useControllableValue.js +13 -0
- package/dist/hooks/useDismissableLayer.cjs +100 -0
- package/dist/hooks/useDismissableLayer.js +97 -0
- package/dist/hooks/usePopupList.cjs +101 -0
- package/dist/hooks/usePopupList.js +98 -0
- package/dist/icons-8yD7I5jO.d.cts +430 -0
- package/dist/icons-8yD7I5jO.d.ts +430 -0
- package/dist/icons.cjs +2111 -418
- package/dist/icons.d.cts +1256 -429
- package/dist/icons.d.ts +1256 -429
- package/dist/icons.js +2089 -1
- package/dist/index.cjs +128 -15046
- package/dist/index.d.cts +697 -662
- package/dist/index.d.ts +697 -662
- package/dist/index.js +43 -14962
- package/dist/motion/Collapse.cjs +28 -0
- package/dist/motion/Collapse.js +25 -0
- package/dist/motion/MotionProvider.cjs +43 -0
- package/dist/motion/MotionProvider.js +38 -0
- package/dist/motion/Pressable.cjs +46 -0
- package/dist/motion/Pressable.js +43 -0
- package/dist/motion/Reveal.cjs +19 -0
- package/dist/motion/Reveal.js +16 -0
- package/dist/motion/SharedLayout.cjs +46 -0
- package/dist/motion/SharedLayout.js +43 -0
- package/dist/motion/index.cjs +19 -0
- package/dist/motion/index.js +6 -0
- package/dist/motion/presence.cjs +58 -0
- package/dist/motion/presence.js +55 -0
- package/dist/motion/presets.cjs +88 -0
- package/dist/motion/presets.js +84 -0
- package/dist/motion.d.cts +51 -0
- package/dist/motion.d.ts +51 -0
- package/dist/preset.cjs +356 -195
- package/dist/preset.d.cts +111 -32
- package/dist/preset.d.ts +111 -32
- package/dist/preset.js +353 -187
- package/dist/presets-Ba5QndHg.d.cts +144 -0
- package/dist/presets-Ba5QndHg.d.ts +144 -0
- package/dist/styles.css +1 -1
- package/dist/utils/cn.cjs +38 -0
- package/dist/utils/cn.js +35 -0
- package/dist/utils/resolveIcon.cjs +18 -0
- package/dist/utils/resolveIcon.js +15 -0
- package/package.json +79 -21
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useId, useMemo } from "react";
|
|
3
|
+
import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, BarElement, ArcElement, RadialLinearScale, Filler, Tooltip, Legend, } from "chart.js";
|
|
4
|
+
import { Line, Bar, Pie, Doughnut, Radar, Scatter, Bubble, PolarArea } from "react-chartjs-2";
|
|
5
|
+
import { cn } from "../../utils/cn.js";
|
|
6
|
+
import { chartColors, chartFont } from "./theme.js";
|
|
7
|
+
// Register Chart.js components
|
|
8
|
+
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, BarElement, ArcElement, RadialLinearScale, Filler, Tooltip, Legend);
|
|
9
|
+
/* ─── Default Options ──────────────────────────────────────────────────── */
|
|
10
|
+
function getDefaultOptions(type) {
|
|
11
|
+
const base = {
|
|
12
|
+
responsive: true,
|
|
13
|
+
maintainAspectRatio: false,
|
|
14
|
+
plugins: {
|
|
15
|
+
legend: {
|
|
16
|
+
display: true,
|
|
17
|
+
position: "bottom",
|
|
18
|
+
labels: {
|
|
19
|
+
font: { ...chartFont, size: 12 },
|
|
20
|
+
color: chartColors.grey[500],
|
|
21
|
+
padding: 16,
|
|
22
|
+
usePointStyle: true,
|
|
23
|
+
pointStyle: "circle",
|
|
24
|
+
boxWidth: 8,
|
|
25
|
+
boxHeight: 8,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
tooltip: {
|
|
29
|
+
backgroundColor: chartColors.grey[900],
|
|
30
|
+
titleFont: { ...chartFont, weight: "bold", size: 13 },
|
|
31
|
+
bodyFont: { ...chartFont, size: 12 },
|
|
32
|
+
cornerRadius: 8,
|
|
33
|
+
padding: 12,
|
|
34
|
+
boxPadding: 6,
|
|
35
|
+
usePointStyle: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
if (type === "line" || type === "bar" || type === "scatter" || type === "bubble") {
|
|
40
|
+
base.scales = {
|
|
41
|
+
x: {
|
|
42
|
+
grid: { color: chartColors.grey[100], drawTicks: false },
|
|
43
|
+
ticks: { font: chartFont, color: chartColors.grey[400], padding: 8 },
|
|
44
|
+
border: { display: false },
|
|
45
|
+
},
|
|
46
|
+
y: {
|
|
47
|
+
grid: { color: chartColors.grey[100], drawTicks: false },
|
|
48
|
+
ticks: { font: chartFont, color: chartColors.grey[400], padding: 8 },
|
|
49
|
+
border: { display: false },
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (type === "line") {
|
|
54
|
+
base.elements = {
|
|
55
|
+
line: { tension: 0.4, borderWidth: 2 },
|
|
56
|
+
point: { radius: 0, hoverRadius: 5, hitRadius: 20 },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (type === "bar") {
|
|
60
|
+
base.elements = {
|
|
61
|
+
bar: { borderRadius: 4 },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (type === "radar") {
|
|
65
|
+
base.scales = {
|
|
66
|
+
r: {
|
|
67
|
+
grid: { color: chartColors.grey[200] },
|
|
68
|
+
angleLines: { color: chartColors.grey[200] },
|
|
69
|
+
pointLabels: { font: { ...chartFont, size: 11 }, color: chartColors.grey[500] },
|
|
70
|
+
ticks: { display: false },
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (type === "polar-area") {
|
|
75
|
+
base.scales = {
|
|
76
|
+
r: {
|
|
77
|
+
grid: { color: chartColors.grey[200] },
|
|
78
|
+
ticks: { display: false },
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return base;
|
|
83
|
+
}
|
|
84
|
+
/* ─── Merge Options ────────────────────────────────────────────────────── */
|
|
85
|
+
function deepMerge(target, source) {
|
|
86
|
+
const output = { ...target };
|
|
87
|
+
for (const key of Object.keys(source)) {
|
|
88
|
+
if (source[key] &&
|
|
89
|
+
typeof source[key] === "object" &&
|
|
90
|
+
!Array.isArray(source[key]) &&
|
|
91
|
+
target[key] &&
|
|
92
|
+
typeof target[key] === "object") {
|
|
93
|
+
output[key] = deepMerge(target[key], source[key]);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
output[key] = source[key];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return output;
|
|
100
|
+
}
|
|
101
|
+
/* ─── Chart Component ──────────────────────────────────────────────────── */
|
|
102
|
+
/** Render one dataset value as text for the accessible table. */
|
|
103
|
+
function formatCell(value) {
|
|
104
|
+
if (value == null)
|
|
105
|
+
return "—";
|
|
106
|
+
if (typeof value === "number" || typeof value === "string")
|
|
107
|
+
return String(value);
|
|
108
|
+
if (typeof value === "object") {
|
|
109
|
+
const point = value;
|
|
110
|
+
if ("y" in point) {
|
|
111
|
+
const xy = `${String(point.x ?? "")}, ${String(point.y ?? "")}`;
|
|
112
|
+
return "r" in point ? `${xy}, ${String(point.r)}` : xy;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return String(value);
|
|
116
|
+
}
|
|
117
|
+
const chartComponentMap = {
|
|
118
|
+
line: Line,
|
|
119
|
+
bar: Bar,
|
|
120
|
+
pie: Pie,
|
|
121
|
+
doughnut: Doughnut,
|
|
122
|
+
radar: Radar,
|
|
123
|
+
scatter: Scatter,
|
|
124
|
+
bubble: Bubble,
|
|
125
|
+
"polar-area": PolarArea,
|
|
126
|
+
};
|
|
127
|
+
export const RaydenChart = forwardRef(({ type, data, options, height = 300, width, className, title, summary, dataTable = true, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, ...rest }, ref) => {
|
|
128
|
+
const mergedOptions = useMemo(() => deepMerge(getDefaultOptions(type), options ?? {}), [type, options]);
|
|
129
|
+
const ChartComponent = chartComponentMap[type];
|
|
130
|
+
const generatedId = useId();
|
|
131
|
+
const summaryId = summary ? `${generatedId}-summary` : undefined;
|
|
132
|
+
const tableId = `${generatedId}-table`;
|
|
133
|
+
// react-chartjs-2 hardcodes role="img" on the canvas. Without a name that is an
|
|
134
|
+
// unlabelled image; without a tabular equivalent the values are canvas-only.
|
|
135
|
+
const labels = (data?.labels ?? []);
|
|
136
|
+
const datasets = (data?.datasets ?? []);
|
|
137
|
+
// Scatter and bubble data carries no `labels` — its points are {x, y} / {x, y, r}
|
|
138
|
+
// objects. Keying the table off labels alone left those charts with no alternative
|
|
139
|
+
// at all, so fall back to one row per point index.
|
|
140
|
+
const rowCount = labels.length || Math.max(0, ...datasets.map((d) => d.data?.length ?? 0));
|
|
141
|
+
const pointBased = labels.length === 0;
|
|
142
|
+
const showTable = dataTable && rowCount > 0 && datasets.length > 0;
|
|
143
|
+
// Last-resort name so the canvas is never an unnamed role="img". Callers should
|
|
144
|
+
// pass a meaningful `title`; this only keeps the default case from being nameless.
|
|
145
|
+
const fallbackName = `${type.replace("-", " ")} chart`;
|
|
146
|
+
const resolvedName = title ?? ariaLabel ?? fallbackName;
|
|
147
|
+
const describedBy = [ariaDescribedBy, summaryId, showTable ? tableId : undefined].filter(Boolean).join(" ") ||
|
|
148
|
+
undefined;
|
|
149
|
+
return (_jsxs("div", { ref: ref, className: cn("relative", className), style: { height, width }, ...rest, children: [_jsx(ChartComponent, { data: data, options: mergedOptions, "aria-label": ariaLabelledBy ? undefined : resolvedName, "aria-labelledby": ariaLabelledBy, "aria-describedby": describedBy, fallbackContent: _jsx("p", { children: resolvedName }) }), summary && (_jsx("p", { id: summaryId, className: "sr-only", children: summary })), showTable && (_jsxs("table", { id: tableId, className: "sr-only", children: [_jsx("caption", { children: `${resolvedName} — data table` }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: pointBased ? "Point" : "Category" }), datasets.map((set, i) => (_jsx("th", { scope: "col", children: set.label ?? `Series ${i + 1}` }, i)))] }) }), _jsx("tbody", { children: Array.from({ length: rowCount }, (_, row) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: pointBased ? row + 1 : String(labels[row]) }), datasets.map((set, i) => (_jsx("td", { children: formatCell(set.data?.[row]) }, i)))] }, row))) })] }))] }));
|
|
150
|
+
});
|
|
151
|
+
RaydenChart.displayName = "RaydenChart";
|
|
152
|
+
/* ─── Re-export theme utilities ────────────────────────────────────────── */
|
|
153
|
+
export { chartColors, chartFont, hexToRgba, createGradientFill } from "./theme.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createGradientFill = exports.hexToRgba = exports.chartFont = exports.chartColors = exports.RaydenChart = void 0;
|
|
4
|
+
var Chart_1 = require("./Chart.cjs");
|
|
5
|
+
Object.defineProperty(exports, "RaydenChart", { enumerable: true, get: function () { return Chart_1.RaydenChart; } });
|
|
6
|
+
var theme_1 = require("./theme.cjs");
|
|
7
|
+
Object.defineProperty(exports, "chartColors", { enumerable: true, get: function () { return theme_1.chartColors; } });
|
|
8
|
+
Object.defineProperty(exports, "chartFont", { enumerable: true, get: function () { return theme_1.chartFont; } });
|
|
9
|
+
Object.defineProperty(exports, "hexToRgba", { enumerable: true, get: function () { return theme_1.hexToRgba; } });
|
|
10
|
+
Object.defineProperty(exports, "createGradientFill", { enumerable: true, get: function () { return theme_1.createGradientFill; } });
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Rayna UI chart theme — color palette and defaults for Chart.js components.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.chartFont = exports.chartColors = void 0;
|
|
7
|
+
exports.hexToRgba = hexToRgba;
|
|
8
|
+
exports.createGradientFill = createGradientFill;
|
|
9
|
+
exports.chartColors = {
|
|
10
|
+
primary: [
|
|
11
|
+
"#F56630", // primary-400
|
|
12
|
+
"#FA9874", // primary-200
|
|
13
|
+
"#FCB59A", // primary-100
|
|
14
|
+
"#FCD2C2", // primary-75
|
|
15
|
+
"#FFECE5", // primary-50
|
|
16
|
+
],
|
|
17
|
+
semantic: [
|
|
18
|
+
"#F56630", // primary-400 (orange)
|
|
19
|
+
"#0F973D", // success-400 (green)
|
|
20
|
+
"#1671D9", // secondary-400 (blue)
|
|
21
|
+
"#F3A218", // warning-400 (amber)
|
|
22
|
+
"#D42620", // error-400 (red)
|
|
23
|
+
"#0BA5EC", // info-400 (cyan)
|
|
24
|
+
],
|
|
25
|
+
extended: [
|
|
26
|
+
"#F56630",
|
|
27
|
+
"#0F973D",
|
|
28
|
+
"#1671D9",
|
|
29
|
+
"#F3A218",
|
|
30
|
+
"#D42620",
|
|
31
|
+
"#0BA5EC",
|
|
32
|
+
"#475CCC", // indigo
|
|
33
|
+
"#8D8484", // office-brown
|
|
34
|
+
"#F77A4A", // primary-300
|
|
35
|
+
"#40B869", // success-300
|
|
36
|
+
],
|
|
37
|
+
grey: {
|
|
38
|
+
50: "#F9FAFB",
|
|
39
|
+
100: "#F0F2F5",
|
|
40
|
+
200: "#E4E7EC",
|
|
41
|
+
300: "#D0D5DD",
|
|
42
|
+
400: "#98A2B3",
|
|
43
|
+
500: "#667185",
|
|
44
|
+
700: "#344054",
|
|
45
|
+
900: "#101928",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
/** Default font for Chart.js */
|
|
49
|
+
exports.chartFont = {
|
|
50
|
+
family: "'Hanken Grotesk', ui-sans-serif, system-ui, sans-serif",
|
|
51
|
+
size: 12,
|
|
52
|
+
weight: "normal",
|
|
53
|
+
};
|
|
54
|
+
/** Create an rgba version of a hex color */
|
|
55
|
+
function hexToRgba(hex, alpha) {
|
|
56
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
57
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
58
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
59
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
60
|
+
}
|
|
61
|
+
/** Generate a gradient fill for area charts */
|
|
62
|
+
function createGradientFill(ctx, color, height) {
|
|
63
|
+
const gradient = ctx.createLinearGradient(0, 0, 0, height);
|
|
64
|
+
gradient.addColorStop(0, hexToRgba(color, 0.2));
|
|
65
|
+
gradient.addColorStop(1, hexToRgba(color, 0.01));
|
|
66
|
+
return gradient;
|
|
67
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rayna UI chart theme — color palette and defaults for Chart.js components.
|
|
3
|
+
*/
|
|
4
|
+
export const chartColors = {
|
|
5
|
+
primary: [
|
|
6
|
+
"#F56630", // primary-400
|
|
7
|
+
"#FA9874", // primary-200
|
|
8
|
+
"#FCB59A", // primary-100
|
|
9
|
+
"#FCD2C2", // primary-75
|
|
10
|
+
"#FFECE5", // primary-50
|
|
11
|
+
],
|
|
12
|
+
semantic: [
|
|
13
|
+
"#F56630", // primary-400 (orange)
|
|
14
|
+
"#0F973D", // success-400 (green)
|
|
15
|
+
"#1671D9", // secondary-400 (blue)
|
|
16
|
+
"#F3A218", // warning-400 (amber)
|
|
17
|
+
"#D42620", // error-400 (red)
|
|
18
|
+
"#0BA5EC", // info-400 (cyan)
|
|
19
|
+
],
|
|
20
|
+
extended: [
|
|
21
|
+
"#F56630",
|
|
22
|
+
"#0F973D",
|
|
23
|
+
"#1671D9",
|
|
24
|
+
"#F3A218",
|
|
25
|
+
"#D42620",
|
|
26
|
+
"#0BA5EC",
|
|
27
|
+
"#475CCC", // indigo
|
|
28
|
+
"#8D8484", // office-brown
|
|
29
|
+
"#F77A4A", // primary-300
|
|
30
|
+
"#40B869", // success-300
|
|
31
|
+
],
|
|
32
|
+
grey: {
|
|
33
|
+
50: "#F9FAFB",
|
|
34
|
+
100: "#F0F2F5",
|
|
35
|
+
200: "#E4E7EC",
|
|
36
|
+
300: "#D0D5DD",
|
|
37
|
+
400: "#98A2B3",
|
|
38
|
+
500: "#667185",
|
|
39
|
+
700: "#344054",
|
|
40
|
+
900: "#101928",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
/** Default font for Chart.js */
|
|
44
|
+
export const chartFont = {
|
|
45
|
+
family: "'Hanken Grotesk', ui-sans-serif, system-ui, sans-serif",
|
|
46
|
+
size: 12,
|
|
47
|
+
weight: "normal",
|
|
48
|
+
};
|
|
49
|
+
/** Create an rgba version of a hex color */
|
|
50
|
+
export function hexToRgba(hex, alpha) {
|
|
51
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
52
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
53
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
54
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
55
|
+
}
|
|
56
|
+
/** Generate a gradient fill for area charts */
|
|
57
|
+
export function createGradientFill(ctx, color, height) {
|
|
58
|
+
const gradient = ctx.createLinearGradient(0, 0, 0, height);
|
|
59
|
+
gradient.addColorStop(0, hexToRgba(color, 0.2));
|
|
60
|
+
gradient.addColorStop(1, hexToRgba(color, 0.01));
|
|
61
|
+
return gradient;
|
|
62
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Chip = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const cn_1 = require("../../utils/cn.cjs");
|
|
7
|
+
const resolveIcon_1 = require("../../utils/resolveIcon.cjs");
|
|
8
|
+
const Icon_1 = require("../Icon/index.cjs");
|
|
9
|
+
exports.Chip = (0, react_1.forwardRef)(({ variant = "input", icon, disabled = false, onClose, onDropdown, className, children, ...rest }, ref) => {
|
|
10
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ref: ref, className: (0, cn_1.cn)("inline-flex items-center gap-1 rounded-md border px-2 py-1 text-sm font-medium transition-colors", disabled
|
|
11
|
+
? "border-grey-200 bg-grey-100 text-grey-300 cursor-not-allowed"
|
|
12
|
+
: "border-control-border bg-surface text-on-surface-body cursor-default focus-within:bg-primary-50 focus-within:border-primary-600", className), ...rest, children: [icon && (0, jsx_runtime_1.jsx)("span", { className: "shrink-0 size-4", children: (0, resolveIcon_1.resolveIcon)(icon, "sm") }), (0, jsx_runtime_1.jsx)("span", { children: children }), variant === "input" && onClose && ((0, jsx_runtime_1.jsx)("button", { type: "button", onClick: onClose, disabled: disabled, className: (0, cn_1.cn)("shrink-0 size-4 box-content p-1 -m-1 inline-flex items-center justify-center rounded-sm", disabled
|
|
13
|
+
? "cursor-not-allowed text-grey-300"
|
|
14
|
+
: "cursor-pointer text-on-surface-muted hover:text-on-surface-body"), "aria-label": "Remove", children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { name: "multiply", size: "xs" }) })), variant === "filter" && ((0, jsx_runtime_1.jsx)("button", { type: "button", onClick: onDropdown, disabled: disabled, className: (0, cn_1.cn)("shrink-0 size-4 box-content p-1 -m-1 inline-flex items-center justify-center", disabled
|
|
15
|
+
? "cursor-not-allowed text-grey-300"
|
|
16
|
+
: "cursor-pointer text-on-surface-muted hover:text-on-surface-body"), "aria-label": "Open filter", children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { name: "chevron-down", size: "xs" }) }))] }));
|
|
17
|
+
});
|
|
18
|
+
exports.Chip.displayName = "Chip";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { cn } from "../../utils/cn.js";
|
|
4
|
+
import { resolveIcon } from "../../utils/resolveIcon.js";
|
|
5
|
+
import { Icon } from "../Icon/index.js";
|
|
6
|
+
export const Chip = forwardRef(({ variant = "input", icon, disabled = false, onClose, onDropdown, className, children, ...rest }, ref) => {
|
|
7
|
+
return (_jsxs("div", { ref: ref, className: cn("inline-flex items-center gap-1 rounded-md border px-2 py-1 text-sm font-medium transition-colors", disabled
|
|
8
|
+
? "border-grey-200 bg-grey-100 text-grey-300 cursor-not-allowed"
|
|
9
|
+
: "border-control-border bg-surface text-on-surface-body cursor-default focus-within:bg-primary-50 focus-within:border-primary-600", className), ...rest, children: [icon && _jsx("span", { className: "shrink-0 size-4", children: resolveIcon(icon, "sm") }), _jsx("span", { children: children }), variant === "input" && onClose && (_jsx("button", { type: "button", onClick: onClose, disabled: disabled, className: cn("shrink-0 size-4 box-content p-1 -m-1 inline-flex items-center justify-center rounded-sm", disabled
|
|
10
|
+
? "cursor-not-allowed text-grey-300"
|
|
11
|
+
: "cursor-pointer text-on-surface-muted hover:text-on-surface-body"), "aria-label": "Remove", children: _jsx(Icon, { name: "multiply", size: "xs" }) })), variant === "filter" && (_jsx("button", { type: "button", onClick: onDropdown, disabled: disabled, className: cn("shrink-0 size-4 box-content p-1 -m-1 inline-flex items-center justify-center", disabled
|
|
12
|
+
? "cursor-not-allowed text-grey-300"
|
|
13
|
+
: "cursor-pointer text-on-surface-muted hover:text-on-surface-body"), "aria-label": "Open filter", children: _jsx(Icon, { name: "chevron-down", size: "xs" }) }))] }));
|
|
14
|
+
});
|
|
15
|
+
Chip.displayName = "Chip";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Chip } from "./Chip.js";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberCounter = exports.Counter = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const cn_1 = require("../../utils/cn.cjs");
|
|
7
|
+
/* ─── Icons ────────────────────────────────────────────────────────────── */
|
|
8
|
+
function MinusIcon({ className }) {
|
|
9
|
+
return ((0, jsx_runtime_1.jsx)("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", children: (0, jsx_runtime_1.jsx)("path", { d: "M5 12h14" }) }));
|
|
10
|
+
}
|
|
11
|
+
function PlusIcon({ className }) {
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", children: (0, jsx_runtime_1.jsx)("path", { d: "M12 5v14M5 12h14" }) }));
|
|
13
|
+
}
|
|
14
|
+
/* ─── Size Config ──────────────────────────────────────────────────────── */
|
|
15
|
+
const buttonSize = {
|
|
16
|
+
sm: "size-8 rounded-[10px]",
|
|
17
|
+
md: "size-10 rounded-xl",
|
|
18
|
+
lg: "size-12 rounded-xl",
|
|
19
|
+
};
|
|
20
|
+
const iconSize = {
|
|
21
|
+
sm: "size-4",
|
|
22
|
+
md: "size-5",
|
|
23
|
+
lg: "size-6",
|
|
24
|
+
};
|
|
25
|
+
const containerShape = {
|
|
26
|
+
rounded: { sm: "rounded-[10px]", md: "rounded-xl", lg: "rounded-xl" },
|
|
27
|
+
block: { sm: "", md: "", lg: "" },
|
|
28
|
+
pill: { sm: "rounded-full", md: "rounded-[28px]", lg: "rounded-[28px]" },
|
|
29
|
+
};
|
|
30
|
+
const valueText = {
|
|
31
|
+
sm: "text-sm w-7",
|
|
32
|
+
md: "text-sm w-7",
|
|
33
|
+
lg: "text-base w-7",
|
|
34
|
+
};
|
|
35
|
+
/* ─── Counter ──────────────────────────────────────────────────────────── */
|
|
36
|
+
exports.Counter = (0, react_1.forwardRef)(({ value: controlledValue, onChange, defaultValue = 0, size = "sm", shape = "rounded", min = 0, max = Infinity, step = 1, disabled = false, className, ...rest }, ref) => {
|
|
37
|
+
// Only update() used to clamp, so min=5 still displayed 0 until first use.
|
|
38
|
+
const clamp = (0, react_1.useCallback)((n) => Math.min(max, Math.max(min, n)), [min, max]);
|
|
39
|
+
const [uncontrolled, setUncontrolled] = (0, react_1.useState)(() => clamp(defaultValue));
|
|
40
|
+
// Keep an uncontrolled value inside bounds when the bounds themselves change.
|
|
41
|
+
(0, react_1.useEffect)(() => {
|
|
42
|
+
if (controlledValue === undefined)
|
|
43
|
+
setUncontrolled((prev) => clamp(prev));
|
|
44
|
+
}, [clamp, controlledValue]);
|
|
45
|
+
const val = controlledValue ?? uncontrolled;
|
|
46
|
+
const update = (0, react_1.useCallback)((next) => {
|
|
47
|
+
const clamped = Math.min(max, Math.max(min, next));
|
|
48
|
+
if (controlledValue === undefined)
|
|
49
|
+
setUncontrolled(clamped);
|
|
50
|
+
onChange?.(clamped);
|
|
51
|
+
}, [controlledValue, onChange, min, max]);
|
|
52
|
+
const canDecrement = val > min;
|
|
53
|
+
const canIncrement = val < max;
|
|
54
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ref: ref, className: (0, cn_1.cn)("inline-flex items-center border border-control-border overflow-hidden", containerShape[shape][size], disabled && "opacity-50", className), ...rest, children: [(0, jsx_runtime_1.jsx)("button", { type: "button", disabled: disabled || !canDecrement, onClick: () => update(val - step), className: (0, cn_1.cn)("flex items-center justify-center p-2.5 text-on-surface cursor-pointer transition-colors hover:bg-grey-100", buttonSize[size], (disabled || !canDecrement) && "text-grey-300 cursor-not-allowed hover:bg-transparent"), "aria-label": "Decrease", children: (0, jsx_runtime_1.jsx)(MinusIcon, { className: iconSize[size] }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-center shrink-0", children: (0, jsx_runtime_1.jsx)("span", { className: (0, cn_1.cn)("font-medium text-on-surface text-center leading-[1.45]", valueText[size]), children: val }) }), (0, jsx_runtime_1.jsx)("button", { type: "button", disabled: disabled || !canIncrement, onClick: () => update(val + step), className: (0, cn_1.cn)("flex items-center justify-center p-2.5 text-on-surface cursor-pointer transition-colors hover:bg-grey-100", buttonSize[size], (disabled || !canIncrement) && "text-grey-300 cursor-not-allowed hover:bg-transparent"), "aria-label": "Increase", children: (0, jsx_runtime_1.jsx)(PlusIcon, { className: iconSize[size] }) })] }));
|
|
55
|
+
});
|
|
56
|
+
exports.Counter.displayName = "Counter";
|
|
57
|
+
/* ─── NumberCounter ────────────────────────────────────────────────────── */
|
|
58
|
+
const ncSize = {
|
|
59
|
+
sm: { container: "p-1 rounded-[4px]", text: "text-xs size-4" },
|
|
60
|
+
md: { container: "p-1 rounded-md size-7", text: "text-sm" },
|
|
61
|
+
lg: { container: "p-2 rounded-md size-9", text: "text-base" },
|
|
62
|
+
};
|
|
63
|
+
const ncColor = {
|
|
64
|
+
orange: { bg: "bg-action-primary", text: "text-white" },
|
|
65
|
+
red: { bg: "bg-error-400", text: "text-white" },
|
|
66
|
+
grey: { bg: "bg-grey-300", text: "text-white" },
|
|
67
|
+
white: { bg: "bg-surface", text: "text-on-surface-secondary" },
|
|
68
|
+
};
|
|
69
|
+
exports.NumberCounter = (0, react_1.forwardRef)(({ value, size = "sm", color = "orange", className, ...rest }, ref) => {
|
|
70
|
+
const s = ncSize[size];
|
|
71
|
+
const c = ncColor[color];
|
|
72
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, className: (0, cn_1.cn)("inline-flex items-center justify-center", s.container, c.bg, className), ...rest, children: (0, jsx_runtime_1.jsx)("span", { className: (0, cn_1.cn)("font-semibold text-center leading-[1.45] tracking-tight", s.text, c.text), children: value }) }));
|
|
73
|
+
});
|
|
74
|
+
exports.NumberCounter.displayName = "NumberCounter";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { cn } from "../../utils/cn.js";
|
|
4
|
+
/* ─── Icons ────────────────────────────────────────────────────────────── */
|
|
5
|
+
function MinusIcon({ className }) {
|
|
6
|
+
return (_jsx("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", children: _jsx("path", { d: "M5 12h14" }) }));
|
|
7
|
+
}
|
|
8
|
+
function PlusIcon({ className }) {
|
|
9
|
+
return (_jsx("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", children: _jsx("path", { d: "M12 5v14M5 12h14" }) }));
|
|
10
|
+
}
|
|
11
|
+
/* ─── Size Config ──────────────────────────────────────────────────────── */
|
|
12
|
+
const buttonSize = {
|
|
13
|
+
sm: "size-8 rounded-[10px]",
|
|
14
|
+
md: "size-10 rounded-xl",
|
|
15
|
+
lg: "size-12 rounded-xl",
|
|
16
|
+
};
|
|
17
|
+
const iconSize = {
|
|
18
|
+
sm: "size-4",
|
|
19
|
+
md: "size-5",
|
|
20
|
+
lg: "size-6",
|
|
21
|
+
};
|
|
22
|
+
const containerShape = {
|
|
23
|
+
rounded: { sm: "rounded-[10px]", md: "rounded-xl", lg: "rounded-xl" },
|
|
24
|
+
block: { sm: "", md: "", lg: "" },
|
|
25
|
+
pill: { sm: "rounded-full", md: "rounded-[28px]", lg: "rounded-[28px]" },
|
|
26
|
+
};
|
|
27
|
+
const valueText = {
|
|
28
|
+
sm: "text-sm w-7",
|
|
29
|
+
md: "text-sm w-7",
|
|
30
|
+
lg: "text-base w-7",
|
|
31
|
+
};
|
|
32
|
+
/* ─── Counter ──────────────────────────────────────────────────────────── */
|
|
33
|
+
export const Counter = forwardRef(({ value: controlledValue, onChange, defaultValue = 0, size = "sm", shape = "rounded", min = 0, max = Infinity, step = 1, disabled = false, className, ...rest }, ref) => {
|
|
34
|
+
// Only update() used to clamp, so min=5 still displayed 0 until first use.
|
|
35
|
+
const clamp = useCallback((n) => Math.min(max, Math.max(min, n)), [min, max]);
|
|
36
|
+
const [uncontrolled, setUncontrolled] = useState(() => clamp(defaultValue));
|
|
37
|
+
// Keep an uncontrolled value inside bounds when the bounds themselves change.
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (controlledValue === undefined)
|
|
40
|
+
setUncontrolled((prev) => clamp(prev));
|
|
41
|
+
}, [clamp, controlledValue]);
|
|
42
|
+
const val = controlledValue ?? uncontrolled;
|
|
43
|
+
const update = useCallback((next) => {
|
|
44
|
+
const clamped = Math.min(max, Math.max(min, next));
|
|
45
|
+
if (controlledValue === undefined)
|
|
46
|
+
setUncontrolled(clamped);
|
|
47
|
+
onChange?.(clamped);
|
|
48
|
+
}, [controlledValue, onChange, min, max]);
|
|
49
|
+
const canDecrement = val > min;
|
|
50
|
+
const canIncrement = val < max;
|
|
51
|
+
return (_jsxs("div", { ref: ref, className: cn("inline-flex items-center border border-control-border overflow-hidden", containerShape[shape][size], disabled && "opacity-50", className), ...rest, children: [_jsx("button", { type: "button", disabled: disabled || !canDecrement, onClick: () => update(val - step), className: cn("flex items-center justify-center p-2.5 text-on-surface cursor-pointer transition-colors hover:bg-grey-100", buttonSize[size], (disabled || !canDecrement) && "text-grey-300 cursor-not-allowed hover:bg-transparent"), "aria-label": "Decrease", children: _jsx(MinusIcon, { className: iconSize[size] }) }), _jsx("div", { className: "flex items-center justify-center shrink-0", children: _jsx("span", { className: cn("font-medium text-on-surface text-center leading-[1.45]", valueText[size]), children: val }) }), _jsx("button", { type: "button", disabled: disabled || !canIncrement, onClick: () => update(val + step), className: cn("flex items-center justify-center p-2.5 text-on-surface cursor-pointer transition-colors hover:bg-grey-100", buttonSize[size], (disabled || !canIncrement) && "text-grey-300 cursor-not-allowed hover:bg-transparent"), "aria-label": "Increase", children: _jsx(PlusIcon, { className: iconSize[size] }) })] }));
|
|
52
|
+
});
|
|
53
|
+
Counter.displayName = "Counter";
|
|
54
|
+
/* ─── NumberCounter ────────────────────────────────────────────────────── */
|
|
55
|
+
const ncSize = {
|
|
56
|
+
sm: { container: "p-1 rounded-[4px]", text: "text-xs size-4" },
|
|
57
|
+
md: { container: "p-1 rounded-md size-7", text: "text-sm" },
|
|
58
|
+
lg: { container: "p-2 rounded-md size-9", text: "text-base" },
|
|
59
|
+
};
|
|
60
|
+
const ncColor = {
|
|
61
|
+
orange: { bg: "bg-action-primary", text: "text-white" },
|
|
62
|
+
red: { bg: "bg-error-400", text: "text-white" },
|
|
63
|
+
grey: { bg: "bg-grey-300", text: "text-white" },
|
|
64
|
+
white: { bg: "bg-surface", text: "text-on-surface-secondary" },
|
|
65
|
+
};
|
|
66
|
+
export const NumberCounter = forwardRef(({ value, size = "sm", color = "orange", className, ...rest }, ref) => {
|
|
67
|
+
const s = ncSize[size];
|
|
68
|
+
const c = ncColor[color];
|
|
69
|
+
return (_jsx("div", { ref: ref, className: cn("inline-flex items-center justify-center", s.container, c.bg, className), ...rest, children: _jsx("span", { className: cn("font-semibold text-center leading-[1.45] tracking-tight", s.text, c.text), children: value }) }));
|
|
70
|
+
});
|
|
71
|
+
NumberCounter.displayName = "NumberCounter";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NumberCounter = exports.Counter = void 0;
|
|
4
|
+
var Counter_1 = require("./Counter.cjs");
|
|
5
|
+
Object.defineProperty(exports, "Counter", { enumerable: true, get: function () { return Counter_1.Counter; } });
|
|
6
|
+
Object.defineProperty(exports, "NumberCounter", { enumerable: true, get: function () { return Counter_1.NumberCounter; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Counter, NumberCounter } from "./Counter.js";
|