@blenx-dev/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/package.json +49 -0
- package/src/DataTable/data-table-column-toggle.tsx +73 -0
- package/src/DataTable/data-table-empty.tsx +27 -0
- package/src/DataTable/data-table-error.tsx +25 -0
- package/src/DataTable/data-table-infinite-loader.tsx +73 -0
- package/src/DataTable/data-table-loading.tsx +67 -0
- package/src/DataTable/data-table-pagination.tsx +80 -0
- package/src/DataTable/data-table-toolbar.tsx +62 -0
- package/src/DataTable/data-table.css.ts +420 -0
- package/src/DataTable/data-table.tsx +507 -0
- package/src/DataTable/index.ts +24 -0
- package/src/DataTable/types.ts +169 -0
- package/src/DataTable/use-infinite-scroll.ts +67 -0
- package/src/components/Accordion/accordion.css.ts +84 -0
- package/src/components/Accordion/accordion.tsx +87 -0
- package/src/components/Accordion/index.ts +8 -0
- package/src/components/Alert/alert.css.ts +29 -0
- package/src/components/Alert/alert.tsx +40 -0
- package/src/components/Alert/index.ts +1 -0
- package/src/components/AlertDialog/alert-dialog.css.ts +62 -0
- package/src/components/AlertDialog/alert-dialog.tsx +199 -0
- package/src/components/AlertDialog/index.ts +1 -0
- package/src/components/AspectRatio/aspect-ratio.css.ts +7 -0
- package/src/components/AspectRatio/aspect-ratio.tsx +20 -0
- package/src/components/AspectRatio/index.ts +1 -0
- package/src/components/Autocomplete/autocomplete.css.ts +167 -0
- package/src/components/Autocomplete/autocomplete.tsx +226 -0
- package/src/components/Autocomplete/index.ts +1 -0
- package/src/components/Avatar/avatar.css.ts +65 -0
- package/src/components/Avatar/avatar.tsx +44 -0
- package/src/components/Avatar/index.ts +1 -0
- package/src/components/Badge/badge.css.ts +180 -0
- package/src/components/Badge/badge.tsx +47 -0
- package/src/components/Badge/index.ts +1 -0
- package/src/components/Box/box.css.ts +5 -0
- package/src/components/Box/box.tsx +21 -0
- package/src/components/Box/index.ts +1 -0
- package/src/components/Breadcrumbs/breadcrumbs.css.ts +72 -0
- package/src/components/Breadcrumbs/breadcrumbs.tsx +79 -0
- package/src/components/Breadcrumbs/index.ts +9 -0
- package/src/components/Button/button.css.ts +200 -0
- package/src/components/Button/button.tsx +55 -0
- package/src/components/Button/index.ts +1 -0
- package/src/components/Calendar/calendar.css.ts +187 -0
- package/src/components/Calendar/calendar.tsx +143 -0
- package/src/components/Calendar/index.ts +1 -0
- package/src/components/Card/card.tsx +32 -0
- package/src/components/Card/index.ts +1 -0
- package/src/components/Checkbox/checkbox.css.ts +76 -0
- package/src/components/Checkbox/checkbox.tsx +94 -0
- package/src/components/Checkbox/index.ts +1 -0
- package/src/components/CloseButton/close-button.css.ts +11 -0
- package/src/components/CloseButton/close-button.tsx +15 -0
- package/src/components/CloseButton/index.ts +2 -0
- package/src/components/ColorPicker/color-picker.tsx +123 -0
- package/src/components/ColorPicker/index.ts +1 -0
- package/src/components/ColorSwatch/color-swatch.tsx +21 -0
- package/src/components/ColorSwatch/index.ts +1 -0
- package/src/components/Combobox/combobox.css.ts +333 -0
- package/src/components/Combobox/combobox.tsx +350 -0
- package/src/components/Combobox/index.ts +1 -0
- package/src/components/Command/command.css.ts +130 -0
- package/src/components/Command/command.tsx +413 -0
- package/src/components/Command/index.ts +7 -0
- package/src/components/Container/container.css.ts +41 -0
- package/src/components/Container/container.tsx +25 -0
- package/src/components/Container/index.ts +1 -0
- package/src/components/CopyButton/copy-button.css.ts +11 -0
- package/src/components/CopyButton/copy-button.tsx +45 -0
- package/src/components/CopyButton/index.ts +2 -0
- package/src/components/DatePicker/date-picker.tsx +75 -0
- package/src/components/DatePicker/index.ts +1 -0
- package/src/components/Dialog/dialog.css.ts +57 -0
- package/src/components/Dialog/dialog.tsx +181 -0
- package/src/components/Dialog/index.ts +1 -0
- package/src/components/Drawer/drawer.css.ts +404 -0
- package/src/components/Drawer/drawer.tsx +573 -0
- package/src/components/Drawer/index.ts +1 -0
- package/src/components/Field/field.css.ts +35 -0
- package/src/components/Field/field.tsx +101 -0
- package/src/components/Field/index.ts +1 -0
- package/src/components/Grid/grid.css.ts +12 -0
- package/src/components/Grid/grid.tsx +32 -0
- package/src/components/Grid/index.ts +1 -0
- package/src/components/Icon/icon.css.ts +10 -0
- package/src/components/Icon/icon.tsx +15 -0
- package/src/components/Icon/index.ts +1 -0
- package/src/components/IconButton/icon-button.css.ts +6 -0
- package/src/components/IconButton/icon-button.tsx +11 -0
- package/src/components/IconButton/index.ts +2 -0
- package/src/components/Input/index.ts +1 -0
- package/src/components/Input/input.css.ts +72 -0
- package/src/components/Input/input.tsx +50 -0
- package/src/components/InputGroup/index.ts +1 -0
- package/src/components/InputGroup/input-group.css.ts +156 -0
- package/src/components/InputGroup/input-group.tsx +133 -0
- package/src/components/Menu/index.ts +1 -0
- package/src/components/Menu/menu.css.ts +121 -0
- package/src/components/Menu/menu.tsx +115 -0
- package/src/components/OTPField/index.ts +1 -0
- package/src/components/OTPField/otp-field.css.ts +54 -0
- package/src/components/OTPField/otp-field.tsx +46 -0
- package/src/components/Popover/index.ts +1 -0
- package/src/components/Popover/popover.css.ts +81 -0
- package/src/components/Popover/popover.tsx +113 -0
- package/src/components/Progress/index.ts +7 -0
- package/src/components/Progress/progress.css.ts +37 -0
- package/src/components/Progress/progress.tsx +62 -0
- package/src/components/Radio/index.ts +1 -0
- package/src/components/Radio/radio.css.ts +72 -0
- package/src/components/Radio/radio.tsx +49 -0
- package/src/components/ScrollArea/index.ts +1 -0
- package/src/components/ScrollArea/scroll-area.css.ts +79 -0
- package/src/components/ScrollArea/scroll-area.tsx +96 -0
- package/src/components/SegmentedControl/index.ts +1 -0
- package/src/components/SegmentedControl/segmented-control.tsx +42 -0
- package/src/components/Select/index.ts +1 -0
- package/src/components/Select/select.css.ts +182 -0
- package/src/components/Select/select.tsx +165 -0
- package/src/components/Separator/index.ts +1 -0
- package/src/components/Separator/separator.css.ts +59 -0
- package/src/components/Separator/separator.tsx +34 -0
- package/src/components/Sheet/index.ts +1 -0
- package/src/components/Sheet/sheet.css.ts +184 -0
- package/src/components/Sheet/sheet.tsx +215 -0
- package/src/components/Slider/index.ts +1 -0
- package/src/components/Slider/slider.css.ts +81 -0
- package/src/components/Slider/slider.tsx +100 -0
- package/src/components/Spinner/index.ts +1 -0
- package/src/components/Spinner/spinner.css.ts +17 -0
- package/src/components/Spinner/spinner.tsx +15 -0
- package/src/components/Splitter/index.ts +1 -0
- package/src/components/Splitter/splitter.css.ts +69 -0
- package/src/components/Splitter/splitter.tsx +521 -0
- package/src/components/Stack/index.ts +1 -0
- package/src/components/Stack/stack.css.ts +42 -0
- package/src/components/Stack/stack.tsx +32 -0
- package/src/components/Surface/index.ts +1 -0
- package/src/components/Surface/surface.css.ts +40 -0
- package/src/components/Surface/surface.tsx +19 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Switch/switch.css.ts +46 -0
- package/src/components/Switch/switch.tsx +25 -0
- package/src/components/Table/index.ts +2 -0
- package/src/components/Table/table.css.ts +71 -0
- package/src/components/Table/table.tsx +117 -0
- package/src/components/Tabs/index.ts +1 -0
- package/src/components/Tabs/tabs.css.ts +250 -0
- package/src/components/Tabs/tabs.tsx +119 -0
- package/src/components/Text/index.ts +2 -0
- package/src/components/Text/text.css.ts +118 -0
- package/src/components/Text/text.tsx +66 -0
- package/src/components/Textarea/index.ts +1 -0
- package/src/components/Textarea/textarea.css.ts +66 -0
- package/src/components/Textarea/textarea.tsx +48 -0
- package/src/components/Toggle/index.ts +1 -0
- package/src/components/Toggle/toggle.css.ts +91 -0
- package/src/components/Toggle/toggle.tsx +44 -0
- package/src/components/ToggleGroup/index.ts +1 -0
- package/src/components/ToggleGroup/toggle-group.css.ts +77 -0
- package/src/components/ToggleGroup/toggle-group.tsx +131 -0
- package/src/components/index.ts +54 -0
- package/src/index.ts +3 -0
- package/src/utils/drawer-styles.css.ts +85 -0
- package/src/utils/heights.ts +16 -0
- package/src/utils/sprinkles.css.ts +197 -0
- package/src/utils/sprinkles.tokens.ts +74 -0
- package/src/utils/types.ts +10 -0
- package/src/utils/ve-style.utils.ts +51 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { style } from "@vanilla-extract/css";
|
|
2
|
+
import { semanticVars, tokenVars } from "@blenx-dev/theme/contract";
|
|
3
|
+
|
|
4
|
+
export const root = style({
|
|
5
|
+
display: "flex",
|
|
6
|
+
flexDirection: "column",
|
|
7
|
+
width: "100%",
|
|
8
|
+
maxHeight: "100%",
|
|
9
|
+
overflow: "hidden",
|
|
10
|
+
backgroundColor: semanticVars.surface.default,
|
|
11
|
+
borderWidth: 1,
|
|
12
|
+
borderStyle: "solid",
|
|
13
|
+
borderColor: semanticVars.border.default,
|
|
14
|
+
borderRadius: tokenVars.borderRadius.lg,
|
|
15
|
+
boxShadow: tokenVars.shadow.lg,
|
|
16
|
+
boxSizing: "border-box",
|
|
17
|
+
outline: "none",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const inputWrapper = style({
|
|
21
|
+
display: "flex",
|
|
22
|
+
alignItems: "center",
|
|
23
|
+
gap: tokenVars.spacing.sm,
|
|
24
|
+
paddingLeft: tokenVars.spacing.sm,
|
|
25
|
+
paddingRight: tokenVars.spacing.sm,
|
|
26
|
+
borderBottomWidth: 1,
|
|
27
|
+
borderBottomStyle: "solid",
|
|
28
|
+
borderBottomColor: semanticVars.border.subtle,
|
|
29
|
+
boxSizing: "border-box",
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const inputIcon = style({
|
|
33
|
+
display: "flex",
|
|
34
|
+
alignItems: "center",
|
|
35
|
+
flexShrink: 0,
|
|
36
|
+
color: semanticVars.text.disabled,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const input = style({
|
|
40
|
+
width: "100%",
|
|
41
|
+
height: 44,
|
|
42
|
+
border: "none",
|
|
43
|
+
outline: "none",
|
|
44
|
+
backgroundColor: "transparent",
|
|
45
|
+
fontSize: tokenVars.fontSize.sm,
|
|
46
|
+
fontFamily: "inherit",
|
|
47
|
+
color: semanticVars.text.primary,
|
|
48
|
+
selectors: {
|
|
49
|
+
"&::placeholder": {
|
|
50
|
+
color: semanticVars.text.disabled,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const list = style({
|
|
56
|
+
overflow: "auto",
|
|
57
|
+
maxHeight: 300,
|
|
58
|
+
padding: tokenVars.spacing.xs,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
export const group = style({
|
|
62
|
+
display: "flex",
|
|
63
|
+
flexDirection: "column",
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export const groupHeading = style({
|
|
67
|
+
paddingTop: tokenVars.spacing.sm,
|
|
68
|
+
paddingBottom: tokenVars.spacing.xs,
|
|
69
|
+
paddingLeft: tokenVars.spacing.sm,
|
|
70
|
+
paddingRight: tokenVars.spacing.sm,
|
|
71
|
+
fontSize: tokenVars.fontSize.xs,
|
|
72
|
+
fontWeight: tokenVars.fontWeight.semibold,
|
|
73
|
+
color: semanticVars.text.secondary,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export const item = style({
|
|
77
|
+
display: "flex",
|
|
78
|
+
alignItems: "center",
|
|
79
|
+
gap: tokenVars.spacing.sm,
|
|
80
|
+
boxSizing: "border-box",
|
|
81
|
+
minHeight: 32,
|
|
82
|
+
paddingTop: tokenVars.spacing.xs,
|
|
83
|
+
paddingBottom: tokenVars.spacing.xs,
|
|
84
|
+
paddingLeft: tokenVars.spacing.sm,
|
|
85
|
+
paddingRight: tokenVars.spacing.sm,
|
|
86
|
+
borderRadius: tokenVars.borderRadius.sm,
|
|
87
|
+
fontSize: tokenVars.fontSize.sm,
|
|
88
|
+
lineHeight: "1.4",
|
|
89
|
+
color: semanticVars.text.primary,
|
|
90
|
+
cursor: "pointer",
|
|
91
|
+
userSelect: "none",
|
|
92
|
+
outline: "none",
|
|
93
|
+
selectors: {
|
|
94
|
+
"&:hover": {
|
|
95
|
+
backgroundColor: semanticVars.background.subtle,
|
|
96
|
+
},
|
|
97
|
+
"&:focus-visible": {
|
|
98
|
+
boxShadow: `0 0 0 2px ${semanticVars.focus.ring}`,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export const itemActive = style({
|
|
104
|
+
backgroundColor: semanticVars.background.subtle,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
export const itemDisabled = style({
|
|
108
|
+
color: semanticVars.text.disabled,
|
|
109
|
+
cursor: "default",
|
|
110
|
+
selectors: {
|
|
111
|
+
"&:hover": {
|
|
112
|
+
backgroundColor: "transparent",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
export const separator = style({
|
|
118
|
+
height: 1,
|
|
119
|
+
marginTop: tokenVars.spacing.xs,
|
|
120
|
+
marginBottom: tokenVars.spacing.xs,
|
|
121
|
+
backgroundColor: semanticVars.border.subtle,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export const empty = style({
|
|
125
|
+
paddingTop: tokenVars.spacing.lg,
|
|
126
|
+
paddingBottom: tokenVars.spacing.lg,
|
|
127
|
+
textAlign: "center",
|
|
128
|
+
fontSize: tokenVars.fontSize.sm,
|
|
129
|
+
color: semanticVars.text.secondary,
|
|
130
|
+
});
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/prefer-tag-over-role */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ReactNode,
|
|
5
|
+
type KeyboardEvent,
|
|
6
|
+
type Dispatch,
|
|
7
|
+
type SetStateAction,
|
|
8
|
+
createContext,
|
|
9
|
+
useCallback,
|
|
10
|
+
useContext,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useState,
|
|
14
|
+
useRef,
|
|
15
|
+
} from "react";
|
|
16
|
+
import clsx from "clsx";
|
|
17
|
+
import { MagnifyingGlass } from "@phosphor-icons/react";
|
|
18
|
+
import {
|
|
19
|
+
root,
|
|
20
|
+
inputWrapper,
|
|
21
|
+
inputIcon,
|
|
22
|
+
input as inputStyle,
|
|
23
|
+
list,
|
|
24
|
+
empty,
|
|
25
|
+
group as groupStyle,
|
|
26
|
+
groupHeading,
|
|
27
|
+
item,
|
|
28
|
+
itemActive,
|
|
29
|
+
itemDisabled,
|
|
30
|
+
separator,
|
|
31
|
+
} from "./command.css";
|
|
32
|
+
|
|
33
|
+
interface CommandItemData {
|
|
34
|
+
id: string;
|
|
35
|
+
value: string;
|
|
36
|
+
keywords?: string[];
|
|
37
|
+
disabled: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface CommandContextValue {
|
|
41
|
+
query: string;
|
|
42
|
+
setQuery: Dispatch<SetStateAction<string>>;
|
|
43
|
+
filteredItems: CommandItemData[];
|
|
44
|
+
activeIndex: number;
|
|
45
|
+
setActiveIndex: Dispatch<SetStateAction<number>>;
|
|
46
|
+
onItemSelect: (value: string) => void;
|
|
47
|
+
registerItem: (item: CommandItemData) => () => void;
|
|
48
|
+
listboxId: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const CommandContext = createContext<CommandContextValue | null>(null);
|
|
52
|
+
|
|
53
|
+
function useCommandContext() {
|
|
54
|
+
const ctx = useContext(CommandContext);
|
|
55
|
+
if (!ctx) {
|
|
56
|
+
throw new Error("Command compound components must be used within <Command>");
|
|
57
|
+
}
|
|
58
|
+
return ctx;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface CommandProps {
|
|
62
|
+
children: ReactNode;
|
|
63
|
+
onItemSelect?: (value: string) => void;
|
|
64
|
+
className?: string;
|
|
65
|
+
style?: React.CSSProperties;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let listboxIdCounter = 0;
|
|
69
|
+
function nextListboxId(): string {
|
|
70
|
+
return `cmd-listbox-${++listboxIdCounter}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function Command({ children, onItemSelect, className, style }: CommandProps) {
|
|
74
|
+
const [query, setQuery] = useState("");
|
|
75
|
+
const [activeIndex, setActiveIndex] = useState(-1);
|
|
76
|
+
const [items, setItems] = useState<Map<string, CommandItemData>>(new Map());
|
|
77
|
+
const listboxId = useRef(nextListboxId()).current;
|
|
78
|
+
|
|
79
|
+
const handleItemSelect = useCallback(
|
|
80
|
+
(value: string) => {
|
|
81
|
+
onItemSelect?.(value);
|
|
82
|
+
},
|
|
83
|
+
[onItemSelect],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const registerItem = useCallback((item: CommandItemData) => {
|
|
87
|
+
setItems((prev) => {
|
|
88
|
+
const next = new Map(prev);
|
|
89
|
+
next.set(item.id, item);
|
|
90
|
+
return next;
|
|
91
|
+
});
|
|
92
|
+
return () => {
|
|
93
|
+
setItems((prev) => {
|
|
94
|
+
const next = new Map(prev);
|
|
95
|
+
next.delete(item.id);
|
|
96
|
+
return next;
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}, []);
|
|
100
|
+
|
|
101
|
+
const filteredItems = useMemo(() => {
|
|
102
|
+
const allItems = [...items.values()];
|
|
103
|
+
if (!query.trim()) return allItems;
|
|
104
|
+
const q = query.toLowerCase().trim();
|
|
105
|
+
return allItems.filter((item) => {
|
|
106
|
+
if (item.disabled) return false;
|
|
107
|
+
if (item.value.toLowerCase().includes(q)) return true;
|
|
108
|
+
if (item.keywords?.some((k) => k.toLowerCase().includes(q))) return true;
|
|
109
|
+
return false;
|
|
110
|
+
});
|
|
111
|
+
}, [query, items]);
|
|
112
|
+
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
setActiveIndex(-1);
|
|
115
|
+
}, [query]);
|
|
116
|
+
|
|
117
|
+
const contextValue = useMemo<CommandContextValue>(
|
|
118
|
+
() => ({
|
|
119
|
+
query,
|
|
120
|
+
setQuery,
|
|
121
|
+
filteredItems,
|
|
122
|
+
activeIndex,
|
|
123
|
+
setActiveIndex,
|
|
124
|
+
onItemSelect: handleItemSelect,
|
|
125
|
+
registerItem,
|
|
126
|
+
listboxId,
|
|
127
|
+
}),
|
|
128
|
+
[query, filteredItems, activeIndex, handleItemSelect, registerItem, listboxId],
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<CommandContext.Provider value={contextValue}>
|
|
133
|
+
<div
|
|
134
|
+
role="combobox"
|
|
135
|
+
aria-expanded
|
|
136
|
+
aria-haspopup="listbox"
|
|
137
|
+
aria-controls={listboxId}
|
|
138
|
+
className={clsx(root, className)}
|
|
139
|
+
style={style}
|
|
140
|
+
>
|
|
141
|
+
{children}
|
|
142
|
+
</div>
|
|
143
|
+
</CommandContext.Provider>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface CommandInputProps {
|
|
148
|
+
placeholder?: string;
|
|
149
|
+
className?: string;
|
|
150
|
+
style?: React.CSSProperties;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function CommandInput({
|
|
154
|
+
placeholder = "Search\u2026",
|
|
155
|
+
className,
|
|
156
|
+
style,
|
|
157
|
+
}: CommandInputProps) {
|
|
158
|
+
const { query, setQuery } = useCommandContext();
|
|
159
|
+
|
|
160
|
+
const handleKeyDown = useCallback(
|
|
161
|
+
(e: KeyboardEvent<HTMLInputElement>) => {
|
|
162
|
+
if (e.key === "Escape" && query) {
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
e.stopPropagation();
|
|
165
|
+
setQuery("");
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (e.key === "Escape") {
|
|
169
|
+
(e.target as HTMLInputElement).blur();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (e.key === "ArrowDown") {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
const list = (e.currentTarget as HTMLElement).parentElement
|
|
175
|
+
?.nextElementSibling as HTMLElement | null;
|
|
176
|
+
list?.focus();
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
[query, setQuery],
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<div className={clsx(inputWrapper, className)} style={style}>
|
|
184
|
+
<span className={inputIcon}>
|
|
185
|
+
<MagnifyingGlass size={16} weight="regular" />
|
|
186
|
+
</span>
|
|
187
|
+
<input
|
|
188
|
+
className={inputStyle}
|
|
189
|
+
role="searchbox"
|
|
190
|
+
placeholder={placeholder}
|
|
191
|
+
value={query}
|
|
192
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
193
|
+
onKeyDown={handleKeyDown}
|
|
194
|
+
autoComplete="off"
|
|
195
|
+
autoCorrect="off"
|
|
196
|
+
spellCheck={false}
|
|
197
|
+
/>
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
interface CommandListProps {
|
|
203
|
+
children: ReactNode;
|
|
204
|
+
className?: string;
|
|
205
|
+
style?: React.CSSProperties;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function CommandList({ children, className, style }: CommandListProps) {
|
|
209
|
+
const { filteredItems, activeIndex, setActiveIndex, onItemSelect, listboxId } =
|
|
210
|
+
useCommandContext();
|
|
211
|
+
const listRef = useRef<HTMLDivElement>(null);
|
|
212
|
+
|
|
213
|
+
const handleKeyDown = useCallback(
|
|
214
|
+
(e: KeyboardEvent<HTMLDivElement>) => {
|
|
215
|
+
if (filteredItems.length === 0) return;
|
|
216
|
+
|
|
217
|
+
switch (e.key) {
|
|
218
|
+
case "ArrowDown": {
|
|
219
|
+
e.preventDefault();
|
|
220
|
+
setActiveIndex((prev) => {
|
|
221
|
+
const next = prev < filteredItems.length - 1 ? prev + 1 : 0;
|
|
222
|
+
return next;
|
|
223
|
+
});
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
case "ArrowUp": {
|
|
227
|
+
e.preventDefault();
|
|
228
|
+
setActiveIndex((prev) => {
|
|
229
|
+
const next = prev > 0 ? prev - 1 : filteredItems.length - 1;
|
|
230
|
+
return next;
|
|
231
|
+
});
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case "Enter": {
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
const activeItem = filteredItems[activeIndex];
|
|
237
|
+
if (activeItem && !activeItem.disabled) {
|
|
238
|
+
onItemSelect(activeItem.value);
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
case "Escape": {
|
|
243
|
+
e.preventDefault();
|
|
244
|
+
(e.target as HTMLElement).blur();
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
[filteredItems, setActiveIndex, onItemSelect, activeIndex],
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
return (
|
|
253
|
+
<div
|
|
254
|
+
ref={listRef}
|
|
255
|
+
id={listboxId}
|
|
256
|
+
role="listbox"
|
|
257
|
+
tabIndex={-1}
|
|
258
|
+
className={clsx(list, className)}
|
|
259
|
+
style={style}
|
|
260
|
+
onKeyDown={handleKeyDown}
|
|
261
|
+
>
|
|
262
|
+
{children}
|
|
263
|
+
</div>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
interface CommandEmptyProps {
|
|
268
|
+
children?: ReactNode;
|
|
269
|
+
className?: string;
|
|
270
|
+
style?: React.CSSProperties;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export function CommandEmpty({ children, className, style }: CommandEmptyProps) {
|
|
274
|
+
const { query, filteredItems } = useCommandContext();
|
|
275
|
+
|
|
276
|
+
if (query.trim() && filteredItems.length === 0) {
|
|
277
|
+
return (
|
|
278
|
+
<div className={clsx(empty, className)} style={style}>
|
|
279
|
+
{children ?? "No results found."}
|
|
280
|
+
</div>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
interface CommandGroupProps {
|
|
288
|
+
heading?: string;
|
|
289
|
+
children: ReactNode;
|
|
290
|
+
className?: string;
|
|
291
|
+
style?: React.CSSProperties;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function CommandGroup({ heading, children, className, style }: CommandGroupProps) {
|
|
295
|
+
return (
|
|
296
|
+
<div role="group" aria-label={heading} className={clsx(groupStyle, className)} style={style}>
|
|
297
|
+
{heading && <div className={groupHeading}>{heading}</div>}
|
|
298
|
+
{children}
|
|
299
|
+
</div>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
interface CommandItemProps {
|
|
304
|
+
value: string;
|
|
305
|
+
keywords?: string[];
|
|
306
|
+
disabled?: boolean;
|
|
307
|
+
children?: ReactNode;
|
|
308
|
+
className?: string;
|
|
309
|
+
style?: React.CSSProperties;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function CommandItem({
|
|
313
|
+
value,
|
|
314
|
+
keywords,
|
|
315
|
+
disabled = false,
|
|
316
|
+
children,
|
|
317
|
+
className,
|
|
318
|
+
style,
|
|
319
|
+
}: CommandItemProps) {
|
|
320
|
+
const { filteredItems, activeIndex, setActiveIndex, registerItem, onItemSelect } =
|
|
321
|
+
useCommandContext();
|
|
322
|
+
|
|
323
|
+
useEffect(() => {
|
|
324
|
+
const unregister = registerItem({
|
|
325
|
+
id: value,
|
|
326
|
+
value,
|
|
327
|
+
keywords,
|
|
328
|
+
disabled,
|
|
329
|
+
});
|
|
330
|
+
return () => {
|
|
331
|
+
unregister();
|
|
332
|
+
};
|
|
333
|
+
}, [value, keywords, disabled, registerItem]);
|
|
334
|
+
|
|
335
|
+
const isVisible = useMemo(
|
|
336
|
+
() => filteredItems.some((item) => item.id === value),
|
|
337
|
+
[filteredItems, value],
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
const itemIndex = useMemo(
|
|
341
|
+
() => filteredItems.findIndex((item) => item.id === value),
|
|
342
|
+
[filteredItems, value],
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
const isActive = activeIndex >= 0 && itemIndex === activeIndex;
|
|
346
|
+
const itemRef = useRef<HTMLDivElement>(null);
|
|
347
|
+
|
|
348
|
+
useEffect(() => {
|
|
349
|
+
if (isActive && itemRef.current) {
|
|
350
|
+
itemRef.current.scrollIntoView({ block: "nearest" });
|
|
351
|
+
}
|
|
352
|
+
}, [isActive]);
|
|
353
|
+
|
|
354
|
+
const handleClick = useCallback(() => {
|
|
355
|
+
if (!disabled) {
|
|
356
|
+
onItemSelect(value);
|
|
357
|
+
}
|
|
358
|
+
}, [disabled, onItemSelect, value]);
|
|
359
|
+
|
|
360
|
+
const handleKeyDown = useCallback(
|
|
361
|
+
(e: KeyboardEvent<HTMLDivElement>) => {
|
|
362
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
363
|
+
e.preventDefault();
|
|
364
|
+
if (!disabled) {
|
|
365
|
+
onItemSelect(value);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
[disabled, onItemSelect, value],
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
const handleMouseEnter = useCallback(() => {
|
|
373
|
+
if (!disabled && itemIndex >= 0) {
|
|
374
|
+
setActiveIndex(itemIndex);
|
|
375
|
+
}
|
|
376
|
+
}, [disabled, setActiveIndex, itemIndex]);
|
|
377
|
+
|
|
378
|
+
if (!isVisible) return null;
|
|
379
|
+
|
|
380
|
+
return (
|
|
381
|
+
<div
|
|
382
|
+
ref={itemRef}
|
|
383
|
+
role="option"
|
|
384
|
+
aria-selected={isActive}
|
|
385
|
+
aria-disabled={disabled}
|
|
386
|
+
data-value={value}
|
|
387
|
+
tabIndex={-1}
|
|
388
|
+
className={clsx(item, isActive && itemActive, disabled && itemDisabled, className)}
|
|
389
|
+
style={style}
|
|
390
|
+
onClick={handleClick}
|
|
391
|
+
onKeyDown={handleKeyDown}
|
|
392
|
+
onMouseEnter={handleMouseEnter}
|
|
393
|
+
>
|
|
394
|
+
{children}
|
|
395
|
+
</div>
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
interface CommandSeparatorProps {
|
|
400
|
+
className?: string;
|
|
401
|
+
style?: React.CSSProperties;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function CommandSeparator({ className, style }: CommandSeparatorProps) {
|
|
405
|
+
return (
|
|
406
|
+
<div
|
|
407
|
+
role="separator"
|
|
408
|
+
aria-orientation="horizontal"
|
|
409
|
+
className={clsx(separator, className)}
|
|
410
|
+
style={style}
|
|
411
|
+
/>
|
|
412
|
+
);
|
|
413
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Command } from "./command";
|
|
2
|
+
export { CommandInput } from "./command";
|
|
3
|
+
export { CommandList } from "./command";
|
|
4
|
+
export { CommandEmpty } from "./command";
|
|
5
|
+
export { CommandGroup } from "./command";
|
|
6
|
+
export { CommandItem } from "./command";
|
|
7
|
+
export { CommandSeparator } from "./command";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { recipe } from "@vanilla-extract/recipes";
|
|
2
|
+
|
|
3
|
+
export const containerRecipe = recipe({
|
|
4
|
+
base: {
|
|
5
|
+
boxSizing: "border-box",
|
|
6
|
+
minWidth: 0,
|
|
7
|
+
},
|
|
8
|
+
variants: {
|
|
9
|
+
size: {
|
|
10
|
+
xxs: { width: "min(240px, 100%)" },
|
|
11
|
+
xs: { width: "min(320px, 100%)" },
|
|
12
|
+
sm: { width: "min(480px, 100%)" },
|
|
13
|
+
md: { width: "min(640px, 100%)" },
|
|
14
|
+
lg: { width: "min(768px, 100%)" },
|
|
15
|
+
xl: { width: "min(1024px, 100%)" },
|
|
16
|
+
xxl: { width: "min(1280px, 100%)" },
|
|
17
|
+
xxxl: { width: "min(1440px, 100%)" },
|
|
18
|
+
xxxxl: { width: "min(1536px, 100%)" },
|
|
19
|
+
full: { maxWidth: "100%", width: "100%" },
|
|
20
|
+
},
|
|
21
|
+
centered: {
|
|
22
|
+
true: {
|
|
23
|
+
marginLeft: "auto",
|
|
24
|
+
marginRight: "auto",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
contentCentered: {
|
|
29
|
+
true: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
flexDirection: "column",
|
|
32
|
+
justifyContent: "center",
|
|
33
|
+
alignItems: "center",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
defaultVariants: {
|
|
38
|
+
size: "lg",
|
|
39
|
+
centered: true,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BoxProps } from "../Box/box";
|
|
2
|
+
import { Box } from "../Box/box";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { containerRecipe } from "./container.css";
|
|
5
|
+
import type { RecipeVariants } from "@vanilla-extract/recipes";
|
|
6
|
+
export type ContainerVariants = RecipeVariants<typeof containerRecipe>;
|
|
7
|
+
|
|
8
|
+
type Props = BoxProps & ContainerVariants;
|
|
9
|
+
export type ContainerProps = Props;
|
|
10
|
+
export function Container({ size, centered = true, contentCentered, className, ...props }: Props) {
|
|
11
|
+
return (
|
|
12
|
+
<Box
|
|
13
|
+
{...props}
|
|
14
|
+
flexShrink={0}
|
|
15
|
+
className={clsx(
|
|
16
|
+
containerRecipe({
|
|
17
|
+
size,
|
|
18
|
+
centered,
|
|
19
|
+
contentCentered,
|
|
20
|
+
}),
|
|
21
|
+
className,
|
|
22
|
+
)}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./container";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useState, useCallback, type MouseEvent } from "react";
|
|
2
|
+
import { IconButton, type IconButtonProps } from "../IconButton/icon-button";
|
|
3
|
+
import { icon } from "./copy-button.css";
|
|
4
|
+
|
|
5
|
+
export type CopyButtonProps = Omit<IconButtonProps, "onClick"> & {
|
|
6
|
+
copyValue?: string;
|
|
7
|
+
onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function CopyButton({ copyValue, onClick, ...props }: CopyButtonProps) {
|
|
11
|
+
const [copied, setCopied] = useState(false);
|
|
12
|
+
|
|
13
|
+
const handleClick = useCallback(
|
|
14
|
+
(e: MouseEvent<HTMLButtonElement>) => {
|
|
15
|
+
if (copyValue) {
|
|
16
|
+
navigator.clipboard.writeText(copyValue).then(() => {
|
|
17
|
+
setCopied(true);
|
|
18
|
+
setTimeout(() => setCopied(false), 2000);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
onClick?.(e);
|
|
22
|
+
},
|
|
23
|
+
[copyValue, onClick],
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<IconButton
|
|
28
|
+
variant="soft"
|
|
29
|
+
{...props}
|
|
30
|
+
title={copied ? "Copied!" : `Copy ${copyValue ?? ""}`}
|
|
31
|
+
onClick={handleClick}
|
|
32
|
+
>
|
|
33
|
+
{copied ? (
|
|
34
|
+
<svg className={icon} viewBox="0 0 24 24" aria-hidden="true">
|
|
35
|
+
<polyline points="20 6 9 17 4 12" />
|
|
36
|
+
</svg>
|
|
37
|
+
) : (
|
|
38
|
+
<svg className={icon} viewBox="0 0 24 24" aria-hidden="true">
|
|
39
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
|
|
40
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
|
|
41
|
+
</svg>
|
|
42
|
+
)}
|
|
43
|
+
</IconButton>
|
|
44
|
+
);
|
|
45
|
+
}
|