@rovula/ui 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bundle.css +175 -26
- package/dist/cjs/bundle.js +675 -675
- package/dist/cjs/bundle.js.map +1 -1
- package/dist/cjs/types/components/Badge/Badge.d.ts +40 -0
- package/dist/cjs/types/components/Badge/Badge.stories.d.ts +295 -0
- package/dist/cjs/types/components/Badge/Badge.styles.d.ts +7 -0
- package/dist/cjs/types/components/Badge/index.d.ts +2 -0
- package/dist/cjs/types/components/Dropdown/Dropdown.d.ts +4 -8
- package/dist/cjs/types/components/Dropdown/Dropdown.stories.d.ts +1 -6
- package/dist/cjs/types/components/DropdownMenu/DropdownMenu.d.ts +5 -1
- package/dist/cjs/types/components/DropdownMenu/DropdownMenu.stories.d.ts +16 -0
- package/dist/cjs/types/index.d.ts +3 -1
- package/dist/cjs/types/patterns/menu/Menu.d.ts +70 -0
- package/dist/cjs/types/{components/Menu → patterns/menu}/Menu.stories.d.ts +17 -10
- package/dist/cjs/types/utils/mergeRefs.d.ts +20 -0
- package/dist/components/Avatar/Avatar.styles.js +2 -2
- package/dist/components/Badge/Badge.js +36 -0
- package/dist/components/Badge/Badge.stories.js +51 -0
- package/dist/components/Badge/Badge.styles.js +62 -0
- package/dist/components/Badge/index.js +2 -0
- package/dist/components/Dropdown/Dropdown.js +54 -163
- package/dist/components/Dropdown/Dropdown.stories.js +29 -0
- package/dist/components/DropdownMenu/DropdownMenu.js +22 -9
- package/dist/components/DropdownMenu/DropdownMenu.stories.js +54 -10
- package/dist/components/TextInput/TextInput.js +6 -3
- package/dist/esm/bundle.css +175 -26
- package/dist/esm/bundle.js +1545 -1545
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/types/components/Badge/Badge.d.ts +40 -0
- package/dist/esm/types/components/Badge/Badge.stories.d.ts +295 -0
- package/dist/esm/types/components/Badge/Badge.styles.d.ts +7 -0
- package/dist/esm/types/components/Badge/index.d.ts +2 -0
- package/dist/esm/types/components/Dropdown/Dropdown.d.ts +4 -8
- package/dist/esm/types/components/Dropdown/Dropdown.stories.d.ts +1 -6
- package/dist/esm/types/components/DropdownMenu/DropdownMenu.d.ts +5 -1
- package/dist/esm/types/components/DropdownMenu/DropdownMenu.stories.d.ts +16 -0
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/types/patterns/menu/Menu.d.ts +70 -0
- package/dist/esm/types/{components/Menu → patterns/menu}/Menu.stories.d.ts +17 -10
- package/dist/esm/types/utils/mergeRefs.d.ts +20 -0
- package/dist/index.d.ts +116 -73
- package/dist/index.js +2 -1
- package/dist/patterns/menu/Menu.js +95 -0
- package/dist/patterns/menu/Menu.stories.js +611 -0
- package/dist/src/theme/global.css +289 -37
- package/dist/utils/mergeRefs.js +42 -0
- package/package.json +1 -1
- package/src/components/Avatar/Avatar.styles.ts +2 -2
- package/src/components/Badge/Badge.stories.tsx +128 -0
- package/src/components/Badge/Badge.styles.ts +70 -0
- package/src/components/Badge/Badge.tsx +103 -0
- package/src/components/Badge/index.ts +3 -0
- package/src/components/Dropdown/Dropdown.stories.tsx +170 -1
- package/src/components/Dropdown/Dropdown.tsx +186 -276
- package/src/components/DropdownMenu/DropdownMenu.stories.tsx +1050 -113
- package/src/components/DropdownMenu/DropdownMenu.tsx +116 -52
- package/src/components/TextInput/TextInput.tsx +6 -3
- package/src/index.ts +3 -1
- package/src/patterns/menu/Menu.stories.tsx +1100 -0
- package/src/patterns/menu/Menu.tsx +282 -0
- package/src/theme/themes/xspector/baseline.css +0 -1
- package/src/theme/tokens/baseline.css +2 -1
- package/src/theme/tokens/components/badge.css +54 -0
- package/src/theme/tokens/components/dropdown-menu.css +15 -4
- package/src/utils/mergeRefs.ts +46 -0
- package/dist/cjs/types/components/Menu/Menu.d.ts +0 -65
- package/dist/cjs/types/components/Menu/helpers.d.ts +0 -19
- package/dist/cjs/types/components/Menu/index.d.ts +0 -4
- package/dist/components/Menu/Menu.js +0 -64
- package/dist/components/Menu/Menu.stories.js +0 -406
- package/dist/components/Menu/helpers.js +0 -28
- package/dist/components/Menu/index.js +0 -3
- package/dist/esm/types/components/Menu/Menu.d.ts +0 -65
- package/dist/esm/types/components/Menu/helpers.d.ts +0 -19
- package/dist/esm/types/components/Menu/index.d.ts +0 -4
- package/src/components/Menu/Menu.stories.tsx +0 -586
- package/src/components/Menu/Menu.tsx +0 -235
- package/src/components/Menu/helpers.ts +0 -45
- package/src/components/Menu/index.ts +0 -7
- package/src/theme/themes/xspector/components/dropdown-menu.css +0 -28
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { Menu } from "./Menu";
|
|
4
|
-
import { optionsToMenuItems } from "./helpers";
|
|
5
|
-
import Button from "../Button/Button";
|
|
6
|
-
import Icon from "../Icon/Icon";
|
|
7
|
-
import TextInput from "../TextInput/TextInput";
|
|
8
|
-
import { ChevronDownIcon } from "@heroicons/react/16/solid";
|
|
9
|
-
const meta = {
|
|
10
|
-
title: "Components/Menu",
|
|
11
|
-
component: Menu,
|
|
12
|
-
tags: ["autodocs"],
|
|
13
|
-
parameters: {
|
|
14
|
-
layout: "centered",
|
|
15
|
-
},
|
|
16
|
-
decorators: [
|
|
17
|
-
(Story) => (_jsx("div", { className: "p-20 flex justify-center", children: _jsx(Story, {}) })),
|
|
18
|
-
],
|
|
19
|
-
};
|
|
20
|
-
export default meta;
|
|
21
|
-
// ==================== Basic Menu ====================
|
|
22
|
-
export const Basic = {
|
|
23
|
-
render: () => {
|
|
24
|
-
const items = [
|
|
25
|
-
{ type: "item", item: { value: "1", label: "Option 1" } },
|
|
26
|
-
{ type: "item", item: { value: "2", label: "Option 2" } },
|
|
27
|
-
{ type: "item", item: { value: "3", label: "Option 3" } },
|
|
28
|
-
{ type: "separator" },
|
|
29
|
-
{ type: "item", item: { value: "4", label: "Option 4", disabled: true } },
|
|
30
|
-
{ type: "item", item: { value: "5", label: "Delete", danger: true } },
|
|
31
|
-
];
|
|
32
|
-
return (_jsx(Menu, { items: items, onSelect: (value) => console.log("Selected:", value) }));
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
// ==================== With Icons ====================
|
|
36
|
-
export const WithIcons = {
|
|
37
|
-
render: () => {
|
|
38
|
-
const items = [
|
|
39
|
-
{
|
|
40
|
-
type: "item",
|
|
41
|
-
item: {
|
|
42
|
-
value: "profile",
|
|
43
|
-
label: "Profile",
|
|
44
|
-
icon: _jsx(Icon, { type: "heroicons", name: "user", className: "size-4" }),
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
type: "item",
|
|
49
|
-
item: {
|
|
50
|
-
value: "settings",
|
|
51
|
-
label: "Settings",
|
|
52
|
-
icon: _jsx(Icon, { type: "heroicons", name: "cog-6-tooth", className: "size-4" }),
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
type: "item",
|
|
57
|
-
item: {
|
|
58
|
-
value: "help",
|
|
59
|
-
label: "Help",
|
|
60
|
-
icon: (_jsx(Icon, { type: "heroicons", name: "question-mark-circle", className: "size-4" })),
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
{ type: "separator" },
|
|
64
|
-
{
|
|
65
|
-
type: "item",
|
|
66
|
-
item: {
|
|
67
|
-
value: "logout",
|
|
68
|
-
label: "Logout",
|
|
69
|
-
icon: (_jsx(Icon, { type: "heroicons", name: "arrow-right-on-rectangle", className: "size-4" })),
|
|
70
|
-
danger: true,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
];
|
|
74
|
-
return (_jsx(Menu, { items: items, onSelect: (value) => console.log("Selected:", value) }));
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
// ==================== With Checkbox ====================
|
|
78
|
-
export const WithCheckbox = {
|
|
79
|
-
render: () => {
|
|
80
|
-
const [checked, setChecked] = useState({
|
|
81
|
-
notifications: true,
|
|
82
|
-
emails: false,
|
|
83
|
-
updates: true,
|
|
84
|
-
});
|
|
85
|
-
const items = [
|
|
86
|
-
{ type: "label", label: "Preferences" },
|
|
87
|
-
{
|
|
88
|
-
type: "item",
|
|
89
|
-
item: {
|
|
90
|
-
value: "notifications",
|
|
91
|
-
label: "Notifications",
|
|
92
|
-
type: "checkbox",
|
|
93
|
-
checked: checked.notifications,
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
type: "item",
|
|
98
|
-
item: {
|
|
99
|
-
value: "emails",
|
|
100
|
-
label: "Email Alerts",
|
|
101
|
-
type: "checkbox",
|
|
102
|
-
checked: checked.emails,
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
type: "item",
|
|
107
|
-
item: {
|
|
108
|
-
value: "updates",
|
|
109
|
-
label: "Product Updates",
|
|
110
|
-
type: "checkbox",
|
|
111
|
-
checked: checked.updates,
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
];
|
|
115
|
-
return (_jsx(Menu, { items: items, onSelect: (value) => {
|
|
116
|
-
setChecked((prev) => (Object.assign(Object.assign({}, prev), { [value]: !prev[value] })));
|
|
117
|
-
} }));
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
// ==================== With Radio ====================
|
|
121
|
-
export const WithRadio = {
|
|
122
|
-
render: () => {
|
|
123
|
-
const [selected, setSelected] = useState("light");
|
|
124
|
-
const items = [
|
|
125
|
-
{ type: "label", label: "Theme" },
|
|
126
|
-
{
|
|
127
|
-
type: "item",
|
|
128
|
-
item: {
|
|
129
|
-
value: "light",
|
|
130
|
-
label: "Light",
|
|
131
|
-
type: "radio",
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
type: "item",
|
|
136
|
-
item: {
|
|
137
|
-
value: "dark",
|
|
138
|
-
label: "Dark",
|
|
139
|
-
type: "radio",
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
type: "item",
|
|
144
|
-
item: {
|
|
145
|
-
value: "system",
|
|
146
|
-
label: "System",
|
|
147
|
-
type: "radio",
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
];
|
|
151
|
-
return (_jsx(Menu, { items: items, selectedValues: [selected], onSelect: (value) => setSelected(value) }));
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
// ==================== Complex Menu ====================
|
|
155
|
-
export const ComplexMenu = {
|
|
156
|
-
render: () => {
|
|
157
|
-
const [preferences, setPreferences] = useState({
|
|
158
|
-
notifications: true,
|
|
159
|
-
emails: false,
|
|
160
|
-
});
|
|
161
|
-
const [theme, setTheme] = useState("light");
|
|
162
|
-
const items = [
|
|
163
|
-
{ type: "label", label: "My Account" },
|
|
164
|
-
{
|
|
165
|
-
type: "item",
|
|
166
|
-
item: {
|
|
167
|
-
value: "profile",
|
|
168
|
-
label: "Profile",
|
|
169
|
-
icon: _jsx(Icon, { type: "heroicons", name: "user", className: "size-4" }),
|
|
170
|
-
onClick: () => console.log("Go to profile"),
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
type: "item",
|
|
175
|
-
item: {
|
|
176
|
-
value: "billing",
|
|
177
|
-
label: "Billing",
|
|
178
|
-
icon: _jsx(Icon, { type: "heroicons", name: "credit-card", className: "size-4" }),
|
|
179
|
-
onClick: () => console.log("Go to billing"),
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
{ type: "separator" },
|
|
183
|
-
{ type: "label", label: "Preferences" },
|
|
184
|
-
{
|
|
185
|
-
type: "item",
|
|
186
|
-
item: {
|
|
187
|
-
value: "notifications",
|
|
188
|
-
label: "Push Notifications",
|
|
189
|
-
type: "checkbox",
|
|
190
|
-
checked: preferences.notifications,
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
type: "item",
|
|
195
|
-
item: {
|
|
196
|
-
value: "emails",
|
|
197
|
-
label: "Email Notifications",
|
|
198
|
-
type: "checkbox",
|
|
199
|
-
checked: preferences.emails,
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
{ type: "separator" },
|
|
203
|
-
{ type: "label", label: "Theme" },
|
|
204
|
-
{
|
|
205
|
-
type: "item",
|
|
206
|
-
item: {
|
|
207
|
-
value: "light",
|
|
208
|
-
label: "Light Mode",
|
|
209
|
-
type: "radio",
|
|
210
|
-
},
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
type: "item",
|
|
214
|
-
item: {
|
|
215
|
-
value: "dark",
|
|
216
|
-
label: "Dark Mode",
|
|
217
|
-
type: "radio",
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
{ type: "separator" },
|
|
221
|
-
{
|
|
222
|
-
type: "item",
|
|
223
|
-
item: {
|
|
224
|
-
value: "logout",
|
|
225
|
-
label: "Logout",
|
|
226
|
-
icon: (_jsx(Icon, { type: "heroicons", name: "arrow-right-on-rectangle", className: "size-4" })),
|
|
227
|
-
danger: true,
|
|
228
|
-
onClick: () => console.log("Logout"),
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
];
|
|
232
|
-
return (_jsx(Menu, { items: items, selectedValues: [theme], onSelect: (value, item) => {
|
|
233
|
-
// Handle different types
|
|
234
|
-
if (item.type === "checkbox") {
|
|
235
|
-
// Toggle checkbox
|
|
236
|
-
const key = value;
|
|
237
|
-
if (key in preferences) {
|
|
238
|
-
setPreferences(Object.assign(Object.assign({}, preferences), { [key]: !preferences[key] }));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else if (item.type === "radio") {
|
|
242
|
-
// Radio select
|
|
243
|
-
setTheme(value);
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
// Regular item
|
|
247
|
-
console.log("Item clicked:", value);
|
|
248
|
-
}
|
|
249
|
-
} }));
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
// ==================== With Dropdown Trigger ====================
|
|
253
|
-
export const WithDropdownTrigger = {
|
|
254
|
-
render: () => {
|
|
255
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
256
|
-
const items = [
|
|
257
|
-
{
|
|
258
|
-
type: "item",
|
|
259
|
-
item: {
|
|
260
|
-
value: "edit",
|
|
261
|
-
label: "Edit",
|
|
262
|
-
icon: _jsx(Icon, { type: "heroicons", name: "pencil", className: "size-4" }),
|
|
263
|
-
onClick: () => {
|
|
264
|
-
console.log("Edit");
|
|
265
|
-
setIsOpen(false);
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
{
|
|
270
|
-
type: "item",
|
|
271
|
-
item: {
|
|
272
|
-
value: "duplicate",
|
|
273
|
-
label: "Duplicate",
|
|
274
|
-
icon: (_jsx(Icon, { type: "heroicons", name: "document-duplicate", className: "size-4" })),
|
|
275
|
-
onClick: () => {
|
|
276
|
-
console.log("Duplicate");
|
|
277
|
-
setIsOpen(false);
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
{ type: "separator" },
|
|
282
|
-
{
|
|
283
|
-
type: "item",
|
|
284
|
-
item: {
|
|
285
|
-
value: "archive",
|
|
286
|
-
label: "Archive",
|
|
287
|
-
icon: _jsx(Icon, { type: "heroicons", name: "archive-box", className: "size-4" }),
|
|
288
|
-
onClick: () => {
|
|
289
|
-
console.log("Archive");
|
|
290
|
-
setIsOpen(false);
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
},
|
|
294
|
-
{
|
|
295
|
-
type: "item",
|
|
296
|
-
item: {
|
|
297
|
-
value: "delete",
|
|
298
|
-
label: "Delete",
|
|
299
|
-
icon: _jsx(Icon, { type: "heroicons", name: "trash", className: "size-4" }),
|
|
300
|
-
danger: true,
|
|
301
|
-
onClick: () => {
|
|
302
|
-
console.log("Delete");
|
|
303
|
-
setIsOpen(false);
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
},
|
|
307
|
-
];
|
|
308
|
-
return (_jsxs("div", { className: "relative", children: [_jsx(Button, { onClick: () => setIsOpen(!isOpen), children: "Actions" }), isOpen && (_jsxs(_Fragment, { children: [_jsx("div", { className: "fixed inset-0 z-40", onClick: () => setIsOpen(false) }), _jsx("div", { className: "absolute top-full mt-2 z-50", children: _jsx(Menu, { items: items }) })] }))] }));
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
|
-
// ==================== Custom Items ====================
|
|
312
|
-
export const CustomItems = {
|
|
313
|
-
render: () => {
|
|
314
|
-
const items = [
|
|
315
|
-
{ type: "label", label: "Recent Projects" },
|
|
316
|
-
{
|
|
317
|
-
type: "custom",
|
|
318
|
-
render: () => (_jsxs("div", { className: "px-4 py-3 hover:bg-[var(--dropdown-menu-hover-bg)] cursor-pointer", children: [_jsx("div", { className: "font-semibold", children: "Project Alpha" }), _jsx("div", { className: "text-xs text-gray-500", children: "Updated 2 hours ago" })] })),
|
|
319
|
-
},
|
|
320
|
-
{
|
|
321
|
-
type: "custom",
|
|
322
|
-
render: () => (_jsxs("div", { className: "px-4 py-3 hover:bg-[var(--dropdown-menu-hover-bg)] cursor-pointer", children: [_jsx("div", { className: "font-semibold", children: "Project Beta" }), _jsx("div", { className: "text-xs text-gray-500", children: "Updated yesterday" })] })),
|
|
323
|
-
},
|
|
324
|
-
{ type: "separator" },
|
|
325
|
-
{
|
|
326
|
-
type: "item",
|
|
327
|
-
item: {
|
|
328
|
-
value: "view-all",
|
|
329
|
-
label: "View All Projects",
|
|
330
|
-
icon: _jsx(Icon, { type: "heroicons", name: "folder-open", className: "size-4" }),
|
|
331
|
-
},
|
|
332
|
-
},
|
|
333
|
-
];
|
|
334
|
-
return (_jsx(Menu, { items: items, onSelect: (value) => console.log("Selected:", value) }));
|
|
335
|
-
},
|
|
336
|
-
};
|
|
337
|
-
// ==================== Dropdown Pattern (Select with Search) ====================
|
|
338
|
-
export const DropdownPattern = {
|
|
339
|
-
render: () => {
|
|
340
|
-
var _a;
|
|
341
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
342
|
-
const [selectedValue, setSelectedValue] = useState("");
|
|
343
|
-
const [searchText, setSearchText] = useState("");
|
|
344
|
-
// Simulate options like Dropdown component
|
|
345
|
-
const allOptions = [
|
|
346
|
-
{ value: "apple", label: "Apple" },
|
|
347
|
-
{ value: "banana", label: "Banana" },
|
|
348
|
-
{ value: "cherry", label: "Cherry" },
|
|
349
|
-
{ value: "date", label: "Date" },
|
|
350
|
-
{ value: "elderberry", label: "Elderberry" },
|
|
351
|
-
{ value: "fig", label: "Fig" },
|
|
352
|
-
{ value: "grape", label: "Grape" },
|
|
353
|
-
];
|
|
354
|
-
// Filter options based on search
|
|
355
|
-
const filteredOptions = allOptions.filter((opt) => opt.label.toLowerCase().includes(searchText.toLowerCase()));
|
|
356
|
-
// Convert to MenuItemType
|
|
357
|
-
const menuItems = optionsToMenuItems(filteredOptions);
|
|
358
|
-
// Add "not found" message if no results
|
|
359
|
-
if (filteredOptions.length === 0) {
|
|
360
|
-
menuItems.push({
|
|
361
|
-
type: "custom",
|
|
362
|
-
render: () => (_jsx("div", { className: "px-4 py-14 text-center text-input-text", children: "Not found" })),
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
const selectedLabel = ((_a = allOptions.find((opt) => opt.value === selectedValue)) === null || _a === void 0 ? void 0 : _a.label) || "";
|
|
366
|
-
return (_jsxs("div", { className: "relative w-80", children: [_jsx(TextInput, { value: searchText || selectedLabel, onChange: (e) => setSearchText(e.target.value), onFocus: () => setIsOpen(true), onBlur: () => setTimeout(() => setIsOpen(false), 200), placeholder: "Select a fruit...", endIcon: _jsx(ChevronDownIcon, { className: "size-5 text-gray-400" }) }), isOpen && (_jsx("div", { className: "absolute top-full mt-1 w-full z-50", children: _jsx(Menu, { items: menuItems, selectedValues: [selectedValue], onSelect: (value) => {
|
|
367
|
-
setSelectedValue(value);
|
|
368
|
-
setSearchText("");
|
|
369
|
-
setIsOpen(false);
|
|
370
|
-
}, className: "max-h-60 overflow-y-auto" }) }))] }));
|
|
371
|
-
},
|
|
372
|
-
};
|
|
373
|
-
// ==================== Multi-Select Pattern ====================
|
|
374
|
-
export const MultiSelectPattern = {
|
|
375
|
-
render: () => {
|
|
376
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
377
|
-
const [selectedValues, setSelectedValues] = useState([]);
|
|
378
|
-
const options = [
|
|
379
|
-
{ value: "react", label: "React" },
|
|
380
|
-
{ value: "vue", label: "Vue" },
|
|
381
|
-
{ value: "angular", label: "Angular" },
|
|
382
|
-
{ value: "svelte", label: "Svelte" },
|
|
383
|
-
{ value: "solid", label: "Solid" },
|
|
384
|
-
];
|
|
385
|
-
const items = options.map((opt) => ({
|
|
386
|
-
type: "item",
|
|
387
|
-
item: {
|
|
388
|
-
value: opt.value,
|
|
389
|
-
label: opt.label,
|
|
390
|
-
type: "checkbox",
|
|
391
|
-
checked: selectedValues.includes(opt.value),
|
|
392
|
-
},
|
|
393
|
-
}));
|
|
394
|
-
const displayText = selectedValues.length > 0
|
|
395
|
-
? `${selectedValues.length} selected`
|
|
396
|
-
: "Select frameworks...";
|
|
397
|
-
return (_jsxs("div", { className: "relative w-80", children: [_jsxs(Button, { onClick: () => setIsOpen(!isOpen), className: "w-full justify-between", children: [displayText, _jsx(ChevronDownIcon, { className: "size-5 ml-2" })] }), isOpen && (_jsxs(_Fragment, { children: [_jsx("div", { className: "fixed inset-0 z-40", onClick: () => setIsOpen(false) }), _jsx("div", { className: "absolute top-full mt-2 w-full z-50", children: _jsx(Menu, { items: items, onSelect: (value) => {
|
|
398
|
-
if (selectedValues.includes(value)) {
|
|
399
|
-
setSelectedValues(selectedValues.filter((v) => v !== value));
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
setSelectedValues([...selectedValues, value]);
|
|
403
|
-
}
|
|
404
|
-
} }) })] }))] }));
|
|
405
|
-
},
|
|
406
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper function to convert simple options to MenuItemType
|
|
3
|
-
* Useful for integrating with Dropdown component
|
|
4
|
-
*/
|
|
5
|
-
export function optionsToMenuItems(options) {
|
|
6
|
-
return options.map((option) => ({
|
|
7
|
-
type: "item",
|
|
8
|
-
item: {
|
|
9
|
-
value: option.value,
|
|
10
|
-
label: option.label,
|
|
11
|
-
disabled: option.disabled,
|
|
12
|
-
},
|
|
13
|
-
}));
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Helper to add separator between menu items
|
|
17
|
-
*/
|
|
18
|
-
export function withSeparator(items, atIndex) {
|
|
19
|
-
const result = [...items];
|
|
20
|
-
result.splice(atIndex, 0, { type: "separator" });
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Helper to add label/header to menu items
|
|
25
|
-
*/
|
|
26
|
-
export function withLabel(label, items) {
|
|
27
|
-
return [{ type: "label", label }, ...items];
|
|
28
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import React, { CSSProperties, ReactNode } from "react";
|
|
2
|
-
export type MenuOption = {
|
|
3
|
-
value: string;
|
|
4
|
-
label: ReactNode;
|
|
5
|
-
/**
|
|
6
|
-
* Visual type - กำหนดว่าจะแสดง icon อะไร
|
|
7
|
-
* - "default": ไม่มี icon (แค่ highlight background)
|
|
8
|
-
* - "checkbox": แสดง ✓ icon
|
|
9
|
-
* - "radio": แสดง ● icon
|
|
10
|
-
*/
|
|
11
|
-
type?: "default" | "checkbox" | "radio";
|
|
12
|
-
icon?: ReactNode;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
danger?: boolean;
|
|
15
|
-
checked?: boolean;
|
|
16
|
-
onClick?: () => void;
|
|
17
|
-
};
|
|
18
|
-
export type MenuItemType = {
|
|
19
|
-
type: "item";
|
|
20
|
-
item: MenuOption;
|
|
21
|
-
} | {
|
|
22
|
-
type: "separator";
|
|
23
|
-
} | {
|
|
24
|
-
type: "label";
|
|
25
|
-
label: string;
|
|
26
|
-
} | {
|
|
27
|
-
type: "custom";
|
|
28
|
-
render: () => ReactNode;
|
|
29
|
-
};
|
|
30
|
-
export type MenuProps = {
|
|
31
|
-
items: MenuItemType[];
|
|
32
|
-
/**
|
|
33
|
-
* Selected values - ใช้กับ type="item"
|
|
34
|
-
*/
|
|
35
|
-
selectedValues?: string[];
|
|
36
|
-
/**
|
|
37
|
-
* Callback เมื่อเลือก item
|
|
38
|
-
* - ถ้า item.type="checkbox" → toggle checked state
|
|
39
|
-
* - ถ้า item.type="radio" → single select (clear others)
|
|
40
|
-
* - ถ้า item.type="default" หรือไม่ระบุ → ตาม selectedValues
|
|
41
|
-
*/
|
|
42
|
-
onSelect?: (value: string, item: MenuOption) => void;
|
|
43
|
-
className?: string;
|
|
44
|
-
style?: CSSProperties;
|
|
45
|
-
isAbove?: boolean;
|
|
46
|
-
};
|
|
47
|
-
export declare const Menu: React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<HTMLDivElement>>;
|
|
48
|
-
type MenuItemProps = {
|
|
49
|
-
option: MenuOption;
|
|
50
|
-
visualType: "default" | "checkbox" | "radio";
|
|
51
|
-
isChecked: boolean;
|
|
52
|
-
onSelect: () => void;
|
|
53
|
-
className?: string;
|
|
54
|
-
};
|
|
55
|
-
export declare const MenuItem: React.ForwardRefExoticComponent<MenuItemProps & React.RefAttributes<HTMLDivElement>>;
|
|
56
|
-
type MenuSeparatorProps = {
|
|
57
|
-
className?: string;
|
|
58
|
-
};
|
|
59
|
-
export declare const MenuSeparator: React.ForwardRefExoticComponent<MenuSeparatorProps & React.RefAttributes<HTMLDivElement>>;
|
|
60
|
-
type MenuLabelProps = {
|
|
61
|
-
children: ReactNode;
|
|
62
|
-
className?: string;
|
|
63
|
-
};
|
|
64
|
-
export declare const MenuLabel: React.ForwardRefExoticComponent<MenuLabelProps & React.RefAttributes<HTMLDivElement>>;
|
|
65
|
-
export default Menu;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { MenuItemType } from "./Menu";
|
|
2
|
-
/**
|
|
3
|
-
* Helper function to convert simple options to MenuItemType
|
|
4
|
-
* Useful for integrating with Dropdown component
|
|
5
|
-
*/
|
|
6
|
-
export declare function optionsToMenuItems(options: Array<{
|
|
7
|
-
value: string;
|
|
8
|
-
label: string | React.ReactNode;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
renderLabel?: any;
|
|
11
|
-
}>): MenuItemType[];
|
|
12
|
-
/**
|
|
13
|
-
* Helper to add separator between menu items
|
|
14
|
-
*/
|
|
15
|
-
export declare function withSeparator(items: MenuItemType[], atIndex: number): MenuItemType[];
|
|
16
|
-
/**
|
|
17
|
-
* Helper to add label/header to menu items
|
|
18
|
-
*/
|
|
19
|
-
export declare function withLabel(label: string, items: MenuItemType[]): MenuItemType[];
|