@mdigital_ui/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/README.md +296 -0
- package/dist/accordion/index.js +5 -0
- package/dist/accordion/index.js.map +1 -0
- package/dist/badge/index.js +5 -0
- package/dist/badge/index.js.map +1 -0
- package/dist/button/index.js +6 -0
- package/dist/button/index.js.map +1 -0
- package/dist/card/index.js +4 -0
- package/dist/card/index.js.map +1 -0
- package/dist/carousel/index.js +3 -0
- package/dist/carousel/index.js.map +1 -0
- package/dist/cascader/index.js +4 -0
- package/dist/cascader/index.js.map +1 -0
- package/dist/chart/index.js +4 -0
- package/dist/chart/index.js.map +1 -0
- package/dist/checkbox/index.js +5 -0
- package/dist/checkbox/index.js.map +1 -0
- package/dist/checkbox-group/index.js +4 -0
- package/dist/checkbox-group/index.js.map +1 -0
- package/dist/chunk-2JGAYDZR.js +181 -0
- package/dist/chunk-2JGAYDZR.js.map +1 -0
- package/dist/chunk-3PFA3YG6.js +228 -0
- package/dist/chunk-3PFA3YG6.js.map +1 -0
- package/dist/chunk-4OMLQCUV.js +96 -0
- package/dist/chunk-4OMLQCUV.js.map +1 -0
- package/dist/chunk-4P5EMRFI.js +298 -0
- package/dist/chunk-4P5EMRFI.js.map +1 -0
- package/dist/chunk-5UEWVFF6.js +212 -0
- package/dist/chunk-5UEWVFF6.js.map +1 -0
- package/dist/chunk-5VCGW53O.js +332 -0
- package/dist/chunk-5VCGW53O.js.map +1 -0
- package/dist/chunk-75XESYGN.js +49 -0
- package/dist/chunk-75XESYGN.js.map +1 -0
- package/dist/chunk-7AEGBABZ.js +1102 -0
- package/dist/chunk-7AEGBABZ.js.map +1 -0
- package/dist/chunk-AOITJRSV.js +134 -0
- package/dist/chunk-AOITJRSV.js.map +1 -0
- package/dist/chunk-AWPKZYHT.js +152 -0
- package/dist/chunk-AWPKZYHT.js.map +1 -0
- package/dist/chunk-BNILRB4T.js +37 -0
- package/dist/chunk-BNILRB4T.js.map +1 -0
- package/dist/chunk-BP434VYV.js +448 -0
- package/dist/chunk-BP434VYV.js.map +1 -0
- package/dist/chunk-C7SXY3ZV.js +65 -0
- package/dist/chunk-C7SXY3ZV.js.map +1 -0
- package/dist/chunk-CLLQDCDR.js +560 -0
- package/dist/chunk-CLLQDCDR.js.map +1 -0
- package/dist/chunk-CWHFK7ZC.js +128 -0
- package/dist/chunk-CWHFK7ZC.js.map +1 -0
- package/dist/chunk-D3JWPGCA.js +123 -0
- package/dist/chunk-D3JWPGCA.js.map +1 -0
- package/dist/chunk-DOKTHDG3.js +55 -0
- package/dist/chunk-DOKTHDG3.js.map +1 -0
- package/dist/chunk-DPOSWW22.js +126 -0
- package/dist/chunk-DPOSWW22.js.map +1 -0
- package/dist/chunk-E2CYDDYC.js +39 -0
- package/dist/chunk-E2CYDDYC.js.map +1 -0
- package/dist/chunk-EYTOKUBM.js +401 -0
- package/dist/chunk-EYTOKUBM.js.map +1 -0
- package/dist/chunk-FGWSUPVW.js +356 -0
- package/dist/chunk-FGWSUPVW.js.map +1 -0
- package/dist/chunk-FPOXTCYV.js +166 -0
- package/dist/chunk-FPOXTCYV.js.map +1 -0
- package/dist/chunk-FTJOSVTY.js +104 -0
- package/dist/chunk-FTJOSVTY.js.map +1 -0
- package/dist/chunk-FYHQDFKE.js +164 -0
- package/dist/chunk-FYHQDFKE.js.map +1 -0
- package/dist/chunk-H2HIBD5Y.js +158 -0
- package/dist/chunk-H2HIBD5Y.js.map +1 -0
- package/dist/chunk-J3G5WWGR.js +53 -0
- package/dist/chunk-J3G5WWGR.js.map +1 -0
- package/dist/chunk-JZCHZ4B3.js +487 -0
- package/dist/chunk-JZCHZ4B3.js.map +1 -0
- package/dist/chunk-KBCBVH7B.js +51 -0
- package/dist/chunk-KBCBVH7B.js.map +1 -0
- package/dist/chunk-KNQ7UQ2W.js +143 -0
- package/dist/chunk-KNQ7UQ2W.js.map +1 -0
- package/dist/chunk-KTBPIEP2.js +102 -0
- package/dist/chunk-KTBPIEP2.js.map +1 -0
- package/dist/chunk-L3SP7GHC.js +1023 -0
- package/dist/chunk-L3SP7GHC.js.map +1 -0
- package/dist/chunk-LBJG2UWT.js +100 -0
- package/dist/chunk-LBJG2UWT.js.map +1 -0
- package/dist/chunk-MLDX3Z67.js +470 -0
- package/dist/chunk-MLDX3Z67.js.map +1 -0
- package/dist/chunk-NNSS366W.js +331 -0
- package/dist/chunk-NNSS366W.js.map +1 -0
- package/dist/chunk-OQANRZPV.js +197 -0
- package/dist/chunk-OQANRZPV.js.map +1 -0
- package/dist/chunk-OW5A5IIF.js +175 -0
- package/dist/chunk-OW5A5IIF.js.map +1 -0
- package/dist/chunk-R225A5II.js +187 -0
- package/dist/chunk-R225A5II.js.map +1 -0
- package/dist/chunk-ROR4E6IE.js +119 -0
- package/dist/chunk-ROR4E6IE.js.map +1 -0
- package/dist/chunk-RPAQAZTI.js +54 -0
- package/dist/chunk-RPAQAZTI.js.map +1 -0
- package/dist/chunk-RQBXZKTH.js +452 -0
- package/dist/chunk-RQBXZKTH.js.map +1 -0
- package/dist/chunk-S5XJXU52.js +178 -0
- package/dist/chunk-S5XJXU52.js.map +1 -0
- package/dist/chunk-SAVE5ACL.js +324 -0
- package/dist/chunk-SAVE5ACL.js.map +1 -0
- package/dist/chunk-SERJ3TZE.js +640 -0
- package/dist/chunk-SERJ3TZE.js.map +1 -0
- package/dist/chunk-SK5ECBBK.js +175 -0
- package/dist/chunk-SK5ECBBK.js.map +1 -0
- package/dist/chunk-SOV4PE3P.js +218 -0
- package/dist/chunk-SOV4PE3P.js.map +1 -0
- package/dist/chunk-W7BQYIXF.js +687 -0
- package/dist/chunk-W7BQYIXF.js.map +1 -0
- package/dist/chunk-XMAH5PDW.js +59 -0
- package/dist/chunk-XMAH5PDW.js.map +1 -0
- package/dist/chunk-XOBGEMQY.js +94 -0
- package/dist/chunk-XOBGEMQY.js.map +1 -0
- package/dist/chunk-YNNAOXU5.js +57 -0
- package/dist/chunk-YNNAOXU5.js.map +1 -0
- package/dist/chunk-YZVSDRJD.js +253 -0
- package/dist/chunk-YZVSDRJD.js.map +1 -0
- package/dist/collapse/index.js +4 -0
- package/dist/collapse/index.js.map +1 -0
- package/dist/command/index.js +5 -0
- package/dist/command/index.js.map +1 -0
- package/dist/date-picker/index.js +5 -0
- package/dist/date-picker/index.js.map +1 -0
- package/dist/descriptions/index.js +4 -0
- package/dist/descriptions/index.js.map +1 -0
- package/dist/drawer/index.js +4 -0
- package/dist/drawer/index.js.map +1 -0
- package/dist/dropdown/index.js +5 -0
- package/dist/dropdown/index.js.map +1 -0
- package/dist/empty/index.js +4 -0
- package/dist/empty/index.js.map +1 -0
- package/dist/fetching-overlay/index.js +5 -0
- package/dist/fetching-overlay/index.js.map +1 -0
- package/dist/image/index.js +4 -0
- package/dist/image/index.js.map +1 -0
- package/dist/index.d.ts +2672 -0
- package/dist/index.js +976 -0
- package/dist/index.js.map +1 -0
- package/dist/input/index.js +5 -0
- package/dist/input/index.js.map +1 -0
- package/dist/input-group/index.js +4 -0
- package/dist/input-group/index.js.map +1 -0
- package/dist/input-otp/index.js +4 -0
- package/dist/input-otp/index.js.map +1 -0
- package/dist/input-password/index.js +6 -0
- package/dist/input-password/index.js.map +1 -0
- package/dist/kbd/index.js +4 -0
- package/dist/kbd/index.js.map +1 -0
- package/dist/modal/index.js +4 -0
- package/dist/modal/index.js.map +1 -0
- package/dist/multi-select/index.js +5 -0
- package/dist/multi-select/index.js.map +1 -0
- package/dist/notification/index.js +4 -0
- package/dist/notification/index.js.map +1 -0
- package/dist/pagination/index.js +4 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/popover/index.js +4 -0
- package/dist/popover/index.js.map +1 -0
- package/dist/progress/index.js +4 -0
- package/dist/progress/index.js.map +1 -0
- package/dist/radio/index.js +4 -0
- package/dist/radio/index.js.map +1 -0
- package/dist/radio-group/index.js +4 -0
- package/dist/radio-group/index.js.map +1 -0
- package/dist/rating/index.js +4 -0
- package/dist/rating/index.js.map +1 -0
- package/dist/ribbon/index.js +4 -0
- package/dist/ribbon/index.js.map +1 -0
- package/dist/select/index.js +6 -0
- package/dist/select/index.js.map +1 -0
- package/dist/skeleton/index.js +4 -0
- package/dist/skeleton/index.js.map +1 -0
- package/dist/slider/index.js +4 -0
- package/dist/slider/index.js.map +1 -0
- package/dist/spinner/index.js +4 -0
- package/dist/spinner/index.js.map +1 -0
- package/dist/stepper/index.js +4 -0
- package/dist/stepper/index.js.map +1 -0
- package/dist/styles/base.css +161 -0
- package/dist/styles/global.css +633 -0
- package/dist/styles/themes/dark.css +84 -0
- package/dist/styles/themes/light.css +84 -0
- package/dist/switch/index.js +4 -0
- package/dist/switch/index.js.map +1 -0
- package/dist/table/index.js +12 -0
- package/dist/table/index.js.map +1 -0
- package/dist/tabs/index.js +5 -0
- package/dist/tabs/index.js.map +1 -0
- package/dist/textarea/index.js +4 -0
- package/dist/textarea/index.js.map +1 -0
- package/dist/toggle/index.js +4 -0
- package/dist/toggle/index.js.map +1 -0
- package/dist/toggle-group/index.js +4 -0
- package/dist/toggle-group/index.js.map +1 -0
- package/dist/tooltip/index.js +4 -0
- package/dist/tooltip/index.js.map +1 -0
- package/dist/transfer/index.js +6 -0
- package/dist/transfer/index.js.map +1 -0
- package/dist/tree/index.js +4 -0
- package/dist/tree/index.js.map +1 -0
- package/dist/tree-select/index.js +6 -0
- package/dist/tree-select/index.js.map +1 -0
- package/package.json +107 -0
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
import { cn, iconSizes } from './chunk-YNNAOXU5.js';
|
|
2
|
+
import { cva } from 'class-variance-authority';
|
|
3
|
+
import { X, Loader2, ChevronDown, Check, ChevronRight } from 'lucide-react';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
var cascaderTriggerVariants = cva(
|
|
8
|
+
"flex items-center justify-between gap-2 rounded-md border transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed outline-none",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-background border-border hover:border-primary",
|
|
13
|
+
primary: "bg-background border-primary",
|
|
14
|
+
secondary: "bg-background border-secondary",
|
|
15
|
+
accent: "bg-background border-accent",
|
|
16
|
+
success: "bg-background border-success",
|
|
17
|
+
error: "bg-background border-error",
|
|
18
|
+
warning: "bg-background border-warning",
|
|
19
|
+
info: "bg-background border-info"
|
|
20
|
+
},
|
|
21
|
+
size: {
|
|
22
|
+
xs: "h-8 px-1.5 text-xs",
|
|
23
|
+
sm: "h-[var(--input-height-sm)] px-2.5 text-sm",
|
|
24
|
+
md: "h-[var(--input-height-md)] px-3 text-base",
|
|
25
|
+
lg: "h-[var(--input-height-lg)] px-3 text-lg"
|
|
26
|
+
},
|
|
27
|
+
fullWidth: {
|
|
28
|
+
true: "w-full",
|
|
29
|
+
false: "max-w-full"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
defaultVariants: {
|
|
33
|
+
variant: "default",
|
|
34
|
+
size: "md",
|
|
35
|
+
fullWidth: true
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
var cascaderMenuVariants = cva(
|
|
40
|
+
"overflow-auto rounded-md border bg-background w-[200px] max-h-[300px]",
|
|
41
|
+
{
|
|
42
|
+
variants: {
|
|
43
|
+
color: {
|
|
44
|
+
default: "border-border",
|
|
45
|
+
primary: "border-primary",
|
|
46
|
+
secondary: "border-secondary",
|
|
47
|
+
accent: "border-accent",
|
|
48
|
+
success: "border-success",
|
|
49
|
+
error: "border-error",
|
|
50
|
+
warning: "border-warning",
|
|
51
|
+
info: "border-info"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
defaultVariants: {
|
|
55
|
+
color: "default"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
var cascaderItemVariants = cva(
|
|
60
|
+
"relative cursor-pointer select-none text-text-primary transition-colors flex items-center gap-2 w-full",
|
|
61
|
+
{
|
|
62
|
+
variants: {
|
|
63
|
+
size: {
|
|
64
|
+
xs: "px-2 py-1 text-xs min-h-[28px]",
|
|
65
|
+
sm: "px-3 py-1.5 text-sm min-h-[32px]",
|
|
66
|
+
md: "px-4 py-2 text-base min-h-[40px]",
|
|
67
|
+
lg: "px-5 py-2.5 text-lg min-h-[48px]"
|
|
68
|
+
},
|
|
69
|
+
disabled: {
|
|
70
|
+
true: "opacity-50 cursor-not-allowed",
|
|
71
|
+
false: "hover:bg-surface"
|
|
72
|
+
},
|
|
73
|
+
active: {
|
|
74
|
+
true: "bg-surface",
|
|
75
|
+
false: ""
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
defaultVariants: {
|
|
79
|
+
size: "md",
|
|
80
|
+
disabled: false,
|
|
81
|
+
active: false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
var Cascader = React.memo(
|
|
86
|
+
({
|
|
87
|
+
options,
|
|
88
|
+
value,
|
|
89
|
+
defaultValue,
|
|
90
|
+
onChange,
|
|
91
|
+
placeholder = "Please select",
|
|
92
|
+
label,
|
|
93
|
+
helperText,
|
|
94
|
+
messagePosition = "bottom",
|
|
95
|
+
color = "default",
|
|
96
|
+
size = "md",
|
|
97
|
+
position = "left",
|
|
98
|
+
disabled = false,
|
|
99
|
+
loading = false,
|
|
100
|
+
error,
|
|
101
|
+
warning,
|
|
102
|
+
info,
|
|
103
|
+
success,
|
|
104
|
+
fullWidth = true,
|
|
105
|
+
hover = true,
|
|
106
|
+
multiple = false,
|
|
107
|
+
maxChipsVisible = 3,
|
|
108
|
+
displayRender,
|
|
109
|
+
className,
|
|
110
|
+
required
|
|
111
|
+
}) => {
|
|
112
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
113
|
+
const [internalValue, setInternalValue] = React.useState(defaultValue || (multiple ? [] : []));
|
|
114
|
+
const [activeMenus, setActiveMenus] = React.useState([
|
|
115
|
+
options
|
|
116
|
+
]);
|
|
117
|
+
const [hoveredPath, setHoveredPath] = React.useState([]);
|
|
118
|
+
const [selectedPath, setSelectedPath] = React.useState([]);
|
|
119
|
+
const [visibleChipsCount, setVisibleChipsCount] = React.useState(maxChipsVisible);
|
|
120
|
+
const containerRef = React.useRef(null);
|
|
121
|
+
const triggerRef = React.useRef(null);
|
|
122
|
+
const currentValue = value !== void 0 ? value : internalValue;
|
|
123
|
+
const normalizedValue = React.useMemo(() => {
|
|
124
|
+
if (multiple) {
|
|
125
|
+
return Array.isArray(currentValue[0]) ? currentValue : [];
|
|
126
|
+
}
|
|
127
|
+
return Array.isArray(currentValue) && currentValue.length > 0 && !Array.isArray(currentValue[0]) ? [currentValue] : [];
|
|
128
|
+
}, [currentValue, multiple]);
|
|
129
|
+
let variant = color;
|
|
130
|
+
if (error) {
|
|
131
|
+
variant = "error";
|
|
132
|
+
} else if (warning) {
|
|
133
|
+
variant = "warning";
|
|
134
|
+
} else if (success) {
|
|
135
|
+
variant = "success";
|
|
136
|
+
} else if (info) {
|
|
137
|
+
variant = "info";
|
|
138
|
+
}
|
|
139
|
+
const handleToggle = React.useCallback(() => {
|
|
140
|
+
if (!disabled && !loading) {
|
|
141
|
+
setIsOpen((prev) => {
|
|
142
|
+
if (!prev && normalizedValue.length > 0 && !multiple) {
|
|
143
|
+
setSelectedPath(normalizedValue[0] || []);
|
|
144
|
+
} else if (!prev) {
|
|
145
|
+
setSelectedPath([]);
|
|
146
|
+
}
|
|
147
|
+
return !prev;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}, [disabled, loading, normalizedValue, multiple]);
|
|
151
|
+
const handleClose = React.useCallback(() => {
|
|
152
|
+
setIsOpen(false);
|
|
153
|
+
setActiveMenus([options]);
|
|
154
|
+
setHoveredPath([]);
|
|
155
|
+
}, [options]);
|
|
156
|
+
const getSelectedOptions = React.useCallback(
|
|
157
|
+
(path) => {
|
|
158
|
+
const selected = [];
|
|
159
|
+
let currentOptions = options;
|
|
160
|
+
for (const val of path) {
|
|
161
|
+
const option = currentOptions.find((opt) => opt.value === val);
|
|
162
|
+
if (option) {
|
|
163
|
+
selected.push(option);
|
|
164
|
+
currentOptions = option.children || [];
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return selected;
|
|
168
|
+
},
|
|
169
|
+
[options]
|
|
170
|
+
);
|
|
171
|
+
const isPathSelected = React.useCallback(
|
|
172
|
+
(path) => {
|
|
173
|
+
return normalizedValue.some(
|
|
174
|
+
(selectedPath2) => selectedPath2.length === path.length && selectedPath2.every((val, idx) => val === path[idx])
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
[normalizedValue]
|
|
178
|
+
);
|
|
179
|
+
const getAllLeafPaths = React.useCallback(
|
|
180
|
+
(option, currentPath) => {
|
|
181
|
+
const paths = [];
|
|
182
|
+
const fullPath = [...currentPath, option.value];
|
|
183
|
+
if (!option.children || option.children.length === 0) {
|
|
184
|
+
paths.push(fullPath);
|
|
185
|
+
} else {
|
|
186
|
+
option.children.forEach((child) => {
|
|
187
|
+
paths.push(...getAllLeafPaths(child, fullPath));
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return paths;
|
|
191
|
+
},
|
|
192
|
+
[]
|
|
193
|
+
);
|
|
194
|
+
const getNodeSelectionState = React.useCallback(
|
|
195
|
+
(option, currentPath) => {
|
|
196
|
+
if (!option.children || option.children.length === 0) {
|
|
197
|
+
const fullPath = [...currentPath, option.value];
|
|
198
|
+
return {
|
|
199
|
+
checked: isPathSelected(fullPath),
|
|
200
|
+
indeterminate: false
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const leafPaths = getAllLeafPaths(option, currentPath);
|
|
204
|
+
const selectedCount = leafPaths.filter(
|
|
205
|
+
(path) => isPathSelected(path)
|
|
206
|
+
).length;
|
|
207
|
+
return {
|
|
208
|
+
checked: selectedCount === leafPaths.length && leafPaths.length > 0,
|
|
209
|
+
indeterminate: selectedCount > 0 && selectedCount < leafPaths.length
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
[isPathSelected, getAllLeafPaths]
|
|
213
|
+
);
|
|
214
|
+
const handleItemClick = React.useCallback(
|
|
215
|
+
(option, level) => {
|
|
216
|
+
if (option.disabled) return;
|
|
217
|
+
const newPath = [...selectedPath.slice(0, level), option.value];
|
|
218
|
+
setSelectedPath(newPath);
|
|
219
|
+
if (option.children && option.children.length > 0 && !multiple) {
|
|
220
|
+
setActiveMenus((prev) => [
|
|
221
|
+
...prev.slice(0, level + 1),
|
|
222
|
+
option.children
|
|
223
|
+
]);
|
|
224
|
+
} else if (option.children && option.children.length > 0 && multiple) {
|
|
225
|
+
const leafPaths = getAllLeafPaths(
|
|
226
|
+
option,
|
|
227
|
+
selectedPath.slice(0, level)
|
|
228
|
+
);
|
|
229
|
+
const allSelected = leafPaths.every((path) => isPathSelected(path));
|
|
230
|
+
let newValue;
|
|
231
|
+
if (allSelected) {
|
|
232
|
+
newValue = normalizedValue.filter(
|
|
233
|
+
(selectedPath2) => !leafPaths.some(
|
|
234
|
+
(leafPath) => leafPath.length === selectedPath2.length && leafPath.every((val, idx) => val === selectedPath2[idx])
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
} else {
|
|
238
|
+
const pathsToAdd = leafPaths.filter((path) => !isPathSelected(path));
|
|
239
|
+
newValue = [...normalizedValue, ...pathsToAdd];
|
|
240
|
+
}
|
|
241
|
+
const newSelectedOptions = newValue.map(
|
|
242
|
+
(path) => getSelectedOptions(path)
|
|
243
|
+
);
|
|
244
|
+
if (value === void 0) setInternalValue(newValue);
|
|
245
|
+
onChange?.(newValue, newSelectedOptions);
|
|
246
|
+
setActiveMenus((prev) => [
|
|
247
|
+
...prev.slice(0, level + 1),
|
|
248
|
+
option.children
|
|
249
|
+
]);
|
|
250
|
+
} else {
|
|
251
|
+
if (multiple) {
|
|
252
|
+
let newValue;
|
|
253
|
+
if (isPathSelected(newPath)) {
|
|
254
|
+
newValue = normalizedValue.filter(
|
|
255
|
+
(path) => !(path.length === newPath.length && path.every((val, idx) => val === newPath[idx]))
|
|
256
|
+
);
|
|
257
|
+
} else {
|
|
258
|
+
newValue = [...normalizedValue, newPath];
|
|
259
|
+
}
|
|
260
|
+
const newSelectedOptions = newValue.map(
|
|
261
|
+
(path) => getSelectedOptions(path)
|
|
262
|
+
);
|
|
263
|
+
if (value === void 0) setInternalValue(newValue);
|
|
264
|
+
onChange?.(newValue, newSelectedOptions);
|
|
265
|
+
} else {
|
|
266
|
+
const selectedOptions = getSelectedOptions(newPath);
|
|
267
|
+
if (value === void 0) setInternalValue(newPath);
|
|
268
|
+
onChange?.(newPath, selectedOptions);
|
|
269
|
+
handleClose();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
[
|
|
274
|
+
selectedPath,
|
|
275
|
+
value,
|
|
276
|
+
onChange,
|
|
277
|
+
handleClose,
|
|
278
|
+
getSelectedOptions,
|
|
279
|
+
multiple,
|
|
280
|
+
isPathSelected,
|
|
281
|
+
normalizedValue,
|
|
282
|
+
getAllLeafPaths
|
|
283
|
+
]
|
|
284
|
+
);
|
|
285
|
+
const handleItemHover = React.useCallback(
|
|
286
|
+
(option, level, index) => {
|
|
287
|
+
if (hover && !option.disabled) {
|
|
288
|
+
setHoveredPath((prev) => [...prev.slice(0, level), index]);
|
|
289
|
+
if (option.children && option.children.length > 0) {
|
|
290
|
+
setActiveMenus((prev) => [
|
|
291
|
+
...prev.slice(0, level + 1),
|
|
292
|
+
option.children
|
|
293
|
+
]);
|
|
294
|
+
} else {
|
|
295
|
+
setActiveMenus((prev) => prev.slice(0, level + 1));
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
[hover]
|
|
300
|
+
);
|
|
301
|
+
const handleClear = React.useCallback(() => {
|
|
302
|
+
const emptyValue = multiple ? [] : [];
|
|
303
|
+
if (value === void 0) setInternalValue(emptyValue);
|
|
304
|
+
onChange?.(emptyValue, multiple ? [] : []);
|
|
305
|
+
}, [value, onChange, multiple]);
|
|
306
|
+
const removeSelection = React.useCallback(
|
|
307
|
+
(pathToRemove) => {
|
|
308
|
+
if (!multiple) return;
|
|
309
|
+
const newValue = normalizedValue.filter(
|
|
310
|
+
(path) => !(path.length === pathToRemove.length && path.every((val, idx) => val === pathToRemove[idx]))
|
|
311
|
+
);
|
|
312
|
+
const newSelectedOptions = newValue.map(
|
|
313
|
+
(path) => getSelectedOptions(path)
|
|
314
|
+
);
|
|
315
|
+
if (value === void 0) setInternalValue(newValue);
|
|
316
|
+
onChange?.(newValue, newSelectedOptions);
|
|
317
|
+
},
|
|
318
|
+
[multiple, normalizedValue, value, onChange, getSelectedOptions]
|
|
319
|
+
);
|
|
320
|
+
React.useEffect(() => {
|
|
321
|
+
const handleClickOutside = (event) => {
|
|
322
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
323
|
+
handleClose();
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
if (isOpen) {
|
|
327
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
328
|
+
}
|
|
329
|
+
return () => {
|
|
330
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
331
|
+
};
|
|
332
|
+
}, [isOpen, handleClose]);
|
|
333
|
+
React.useEffect(() => {
|
|
334
|
+
if (!multiple || normalizedValue.length === 0 || !triggerRef.current) {
|
|
335
|
+
setVisibleChipsCount(maxChipsVisible);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const calculateVisibleChips = () => {
|
|
339
|
+
const container = triggerRef.current;
|
|
340
|
+
if (!container) return;
|
|
341
|
+
const hiddenChips = container.querySelectorAll("[data-hidden-chip]");
|
|
342
|
+
if (hiddenChips.length === 0) return;
|
|
343
|
+
const containerWidth = container.offsetWidth;
|
|
344
|
+
const padding = size === "xs" ? 8 : size === "sm" ? 12 : size === "md" ? 16 : 20;
|
|
345
|
+
const chevronWidth = 32;
|
|
346
|
+
const gap = 4;
|
|
347
|
+
const plusIndicatorWidth = 50;
|
|
348
|
+
const availableWidth = containerWidth - padding * 2 - chevronWidth;
|
|
349
|
+
let totalWidth = 0;
|
|
350
|
+
let visibleCount = 0;
|
|
351
|
+
for (let i = 0; i < hiddenChips.length; i++) {
|
|
352
|
+
const chipWidth = hiddenChips[i]?.getBoundingClientRect().width || 0;
|
|
353
|
+
const requiredSpace = totalWidth + chipWidth + (visibleCount > 0 ? gap : 0);
|
|
354
|
+
const needsPlusIndicator = i < hiddenChips.length - 1;
|
|
355
|
+
const spaceWithIndicator = requiredSpace + (needsPlusIndicator ? gap + plusIndicatorWidth : 0);
|
|
356
|
+
if (spaceWithIndicator <= availableWidth) {
|
|
357
|
+
totalWidth = requiredSpace;
|
|
358
|
+
visibleCount++;
|
|
359
|
+
} else {
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
setVisibleChipsCount(Math.max(1, visibleCount));
|
|
364
|
+
};
|
|
365
|
+
const timeoutId = setTimeout(calculateVisibleChips, 0);
|
|
366
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
367
|
+
calculateVisibleChips();
|
|
368
|
+
});
|
|
369
|
+
if (triggerRef.current) {
|
|
370
|
+
resizeObserver.observe(triggerRef.current);
|
|
371
|
+
}
|
|
372
|
+
return () => {
|
|
373
|
+
clearTimeout(timeoutId);
|
|
374
|
+
resizeObserver.disconnect();
|
|
375
|
+
};
|
|
376
|
+
}, [normalizedValue, size, maxChipsVisible, multiple]);
|
|
377
|
+
const displayValue = React.useMemo(() => {
|
|
378
|
+
if (normalizedValue.length === 0) return null;
|
|
379
|
+
if (displayRender) {
|
|
380
|
+
if (multiple) {
|
|
381
|
+
const allLabels = normalizedValue.map(
|
|
382
|
+
(path) => getSelectedOptions(path).map((opt) => opt.label)
|
|
383
|
+
);
|
|
384
|
+
return displayRender(allLabels);
|
|
385
|
+
} else {
|
|
386
|
+
const labels = getSelectedOptions(normalizedValue[0] || []).map(
|
|
387
|
+
(opt) => opt.label
|
|
388
|
+
);
|
|
389
|
+
return displayRender(labels);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (!multiple) {
|
|
393
|
+
const labels = getSelectedOptions(normalizedValue[0] || []).map(
|
|
394
|
+
(opt) => opt.label
|
|
395
|
+
);
|
|
396
|
+
return labels.length > 0 ? labels.join(" / ") : null;
|
|
397
|
+
}
|
|
398
|
+
return null;
|
|
399
|
+
}, [normalizedValue, displayRender, getSelectedOptions, multiple]);
|
|
400
|
+
const showClear = normalizedValue.length > 0 && !!normalizedValue[0]?.[0] && !disabled && !loading;
|
|
401
|
+
let status = "default";
|
|
402
|
+
const helperMessage = error || warning || info || success || helperText;
|
|
403
|
+
if (error) {
|
|
404
|
+
status = "error";
|
|
405
|
+
} else if (warning) {
|
|
406
|
+
status = "warning";
|
|
407
|
+
} else if (success) {
|
|
408
|
+
status = "success";
|
|
409
|
+
} else if (info) {
|
|
410
|
+
status = "info";
|
|
411
|
+
}
|
|
412
|
+
const renderCascaderMenus = () => /* @__PURE__ */ jsx("div", { className: "flex [&>*:not(:first-child)]:rounded-l-none [&>*:not(:last-child)]:border-r-0 [&>*:not(:last-child)]:rounded-r-none", children: activeMenus.map((menu, level) => /* @__PURE__ */ jsx(
|
|
413
|
+
"div",
|
|
414
|
+
{
|
|
415
|
+
className: cn(cascaderMenuVariants({ color })),
|
|
416
|
+
children: menu.map((option, index) => {
|
|
417
|
+
const isActive = selectedPath[level] === option.value || hover && hoveredPath[level] === index;
|
|
418
|
+
const currentPath = selectedPath.slice(0, level);
|
|
419
|
+
const selectionState = multiple ? getNodeSelectionState(option, currentPath) : { checked: false, indeterminate: false };
|
|
420
|
+
return /* @__PURE__ */ jsxs(
|
|
421
|
+
"div",
|
|
422
|
+
{
|
|
423
|
+
className: cascaderItemVariants({
|
|
424
|
+
size,
|
|
425
|
+
disabled: !!option.disabled,
|
|
426
|
+
active: isActive
|
|
427
|
+
}),
|
|
428
|
+
onClick: () => handleItemClick(option, level),
|
|
429
|
+
onMouseEnter: () => handleItemHover(option, level, index),
|
|
430
|
+
children: [
|
|
431
|
+
multiple && /* @__PURE__ */ jsxs(
|
|
432
|
+
"div",
|
|
433
|
+
{
|
|
434
|
+
className: cn(
|
|
435
|
+
"w-4 h-4 border rounded flex items-center justify-center shrink-0",
|
|
436
|
+
selectionState.checked ? "bg-primary border-primary" : "border-border"
|
|
437
|
+
),
|
|
438
|
+
children: [
|
|
439
|
+
selectionState.checked && /* @__PURE__ */ jsx(Check, { className: "h-3 w-3 text-background" }),
|
|
440
|
+
selectionState.indeterminate && !selectionState.checked && /* @__PURE__ */ jsx("div", { className: "w-2 h-0.5 bg-primary" })
|
|
441
|
+
]
|
|
442
|
+
}
|
|
443
|
+
),
|
|
444
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 truncate", children: option.label }),
|
|
445
|
+
/* @__PURE__ */ jsx("span", { className: cn("shrink-0", iconSizes[size]), children: option.children && option.children.length > 0 && /* @__PURE__ */ jsx(ChevronRight, { className: iconSizes[size] }) })
|
|
446
|
+
]
|
|
447
|
+
},
|
|
448
|
+
option.value
|
|
449
|
+
);
|
|
450
|
+
})
|
|
451
|
+
},
|
|
452
|
+
level
|
|
453
|
+
)) });
|
|
454
|
+
const triggerButton = /* @__PURE__ */ jsxs(
|
|
455
|
+
"div",
|
|
456
|
+
{
|
|
457
|
+
ref: triggerRef,
|
|
458
|
+
onClick: handleToggle,
|
|
459
|
+
className: cn(
|
|
460
|
+
cascaderTriggerVariants({ variant, size, fullWidth }),
|
|
461
|
+
className
|
|
462
|
+
),
|
|
463
|
+
children: [
|
|
464
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 flex flex-wrap gap-1 items-center min-h-0", children: multiple && normalizedValue.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
465
|
+
normalizedValue.slice(0, visibleChipsCount).map((path, idx) => {
|
|
466
|
+
const labels = getSelectedOptions(path).map((opt) => opt.label);
|
|
467
|
+
const lastLabel = labels[labels.length - 1];
|
|
468
|
+
return /* @__PURE__ */ jsxs(
|
|
469
|
+
"span",
|
|
470
|
+
{
|
|
471
|
+
className: "inline-flex items-center gap-1 px-2 py-0.5 bg-primary/10 text-primary rounded text-sm whitespace-nowrap",
|
|
472
|
+
children: [
|
|
473
|
+
lastLabel,
|
|
474
|
+
/* @__PURE__ */ jsx(
|
|
475
|
+
"button",
|
|
476
|
+
{
|
|
477
|
+
type: "button",
|
|
478
|
+
onClick: (e) => {
|
|
479
|
+
e.stopPropagation();
|
|
480
|
+
removeSelection(path);
|
|
481
|
+
},
|
|
482
|
+
className: "hover:text-error",
|
|
483
|
+
children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3" })
|
|
484
|
+
}
|
|
485
|
+
)
|
|
486
|
+
]
|
|
487
|
+
},
|
|
488
|
+
idx
|
|
489
|
+
);
|
|
490
|
+
}),
|
|
491
|
+
normalizedValue.length > visibleChipsCount && /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center px-2 py-0.5 bg-surface text-text-secondary rounded text-sm whitespace-nowrap", children: [
|
|
492
|
+
"+",
|
|
493
|
+
normalizedValue.length - visibleChipsCount
|
|
494
|
+
] }),
|
|
495
|
+
/* @__PURE__ */ jsx(
|
|
496
|
+
"div",
|
|
497
|
+
{
|
|
498
|
+
className: "absolute opacity-0 pointer-events-none whitespace-nowrap",
|
|
499
|
+
"aria-hidden": "true",
|
|
500
|
+
children: normalizedValue.map((path, idx) => {
|
|
501
|
+
const labels = getSelectedOptions(path).map(
|
|
502
|
+
(opt) => opt.label
|
|
503
|
+
);
|
|
504
|
+
const lastLabel = labels[labels.length - 1];
|
|
505
|
+
return /* @__PURE__ */ jsxs(
|
|
506
|
+
"span",
|
|
507
|
+
{
|
|
508
|
+
"data-hidden-chip": true,
|
|
509
|
+
className: "inline-flex items-center gap-1 bg-surface text-text-primary px-2 py-0.5 rounded text-sm whitespace-nowrap",
|
|
510
|
+
children: [
|
|
511
|
+
lastLabel,
|
|
512
|
+
/* @__PURE__ */ jsx(X, { className: "h-3 w-3" })
|
|
513
|
+
]
|
|
514
|
+
},
|
|
515
|
+
idx
|
|
516
|
+
);
|
|
517
|
+
})
|
|
518
|
+
}
|
|
519
|
+
)
|
|
520
|
+
] }) : /* @__PURE__ */ jsx(
|
|
521
|
+
"span",
|
|
522
|
+
{
|
|
523
|
+
className: cn(
|
|
524
|
+
"truncate text-text-primary",
|
|
525
|
+
!displayValue && "text-text-muted"
|
|
526
|
+
),
|
|
527
|
+
children: displayValue || placeholder
|
|
528
|
+
}
|
|
529
|
+
) }),
|
|
530
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 text-text-secondary shrink-0", children: [
|
|
531
|
+
loading && /* @__PURE__ */ jsx(
|
|
532
|
+
Loader2,
|
|
533
|
+
{
|
|
534
|
+
className: cn("animate-spin text-text-muted", iconSizes[size])
|
|
535
|
+
}
|
|
536
|
+
),
|
|
537
|
+
!loading && showClear && /* @__PURE__ */ jsx(
|
|
538
|
+
"button",
|
|
539
|
+
{
|
|
540
|
+
type: "button",
|
|
541
|
+
onClick: (e) => {
|
|
542
|
+
e.stopPropagation();
|
|
543
|
+
handleClear();
|
|
544
|
+
},
|
|
545
|
+
className: "hover:text-text-primary",
|
|
546
|
+
"aria-label": "Clear selection",
|
|
547
|
+
children: /* @__PURE__ */ jsx(X, { className: iconSizes[size] })
|
|
548
|
+
}
|
|
549
|
+
),
|
|
550
|
+
!loading && /* @__PURE__ */ jsx(
|
|
551
|
+
ChevronDown,
|
|
552
|
+
{
|
|
553
|
+
className: cn(
|
|
554
|
+
"transition-transform",
|
|
555
|
+
iconSizes[size],
|
|
556
|
+
isOpen && "rotate-180"
|
|
557
|
+
)
|
|
558
|
+
}
|
|
559
|
+
)
|
|
560
|
+
] })
|
|
561
|
+
]
|
|
562
|
+
}
|
|
563
|
+
);
|
|
564
|
+
const cascaderElement = /* @__PURE__ */ jsxs(
|
|
565
|
+
"div",
|
|
566
|
+
{
|
|
567
|
+
ref: containerRef,
|
|
568
|
+
className: cn("relative", fullWidth ? "w-full" : "inline-block"),
|
|
569
|
+
children: [
|
|
570
|
+
triggerButton,
|
|
571
|
+
isOpen && /* @__PURE__ */ jsx(
|
|
572
|
+
"div",
|
|
573
|
+
{
|
|
574
|
+
className: cn(
|
|
575
|
+
"absolute z-50 mt-1",
|
|
576
|
+
position === "left" ? "left-0" : "right-0"
|
|
577
|
+
),
|
|
578
|
+
children: renderCascaderMenus()
|
|
579
|
+
}
|
|
580
|
+
)
|
|
581
|
+
]
|
|
582
|
+
}
|
|
583
|
+
);
|
|
584
|
+
if (!label && !helperMessage) return cascaderElement;
|
|
585
|
+
return /* @__PURE__ */ jsxs(
|
|
586
|
+
"div",
|
|
587
|
+
{
|
|
588
|
+
className: cn(
|
|
589
|
+
"w-full flex flex-col relative",
|
|
590
|
+
!fullWidth && "inline-block"
|
|
591
|
+
),
|
|
592
|
+
children: [
|
|
593
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2 items-center relative mb-0.5", children: [
|
|
594
|
+
label && /* @__PURE__ */ jsxs("p", { className: "text-sm font-medium text-text-secondary", children: [
|
|
595
|
+
label,
|
|
596
|
+
required && /* @__PURE__ */ jsx("span", { className: "text-error ml-1", children: "*" })
|
|
597
|
+
] }),
|
|
598
|
+
helperMessage && messagePosition === "top" && /* @__PURE__ */ jsx(
|
|
599
|
+
"p",
|
|
600
|
+
{
|
|
601
|
+
id: `cascader-helper-${status}`,
|
|
602
|
+
className: cn(
|
|
603
|
+
"text-xs",
|
|
604
|
+
status === "error" && "text-error",
|
|
605
|
+
status === "warning" && "text-warning",
|
|
606
|
+
status === "info" && "text-info",
|
|
607
|
+
status === "success" && "text-success",
|
|
608
|
+
status === "default" && "text-text-secondary"
|
|
609
|
+
),
|
|
610
|
+
children: helperMessage
|
|
611
|
+
}
|
|
612
|
+
)
|
|
613
|
+
] }),
|
|
614
|
+
cascaderElement,
|
|
615
|
+
helperMessage && messagePosition === "bottom" && /* @__PURE__ */ jsx(
|
|
616
|
+
"p",
|
|
617
|
+
{
|
|
618
|
+
id: `cascader-helper-${status}`,
|
|
619
|
+
className: cn(
|
|
620
|
+
"text-xs mt-0.5",
|
|
621
|
+
status === "error" && "text-error",
|
|
622
|
+
status === "warning" && "text-warning",
|
|
623
|
+
status === "info" && "text-info",
|
|
624
|
+
status === "success" && "text-success",
|
|
625
|
+
status === "default" && "text-text-secondary"
|
|
626
|
+
),
|
|
627
|
+
children: helperMessage
|
|
628
|
+
}
|
|
629
|
+
)
|
|
630
|
+
]
|
|
631
|
+
}
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
);
|
|
635
|
+
Cascader.displayName = "Cascader";
|
|
636
|
+
var cascader_default = Cascader;
|
|
637
|
+
|
|
638
|
+
export { cascader_default };
|
|
639
|
+
//# sourceMappingURL=chunk-SERJ3TZE.js.map
|
|
640
|
+
//# sourceMappingURL=chunk-SERJ3TZE.js.map
|