@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,521 @@
|
|
|
1
|
+
// oxlint-disable max-statements
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import React, {
|
|
6
|
+
createContext,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
} from "react";
|
|
14
|
+
import {
|
|
15
|
+
HANDLE_SIZE,
|
|
16
|
+
root,
|
|
17
|
+
rootHorizontal,
|
|
18
|
+
rootVertical,
|
|
19
|
+
rootDisabled,
|
|
20
|
+
panel,
|
|
21
|
+
handle,
|
|
22
|
+
handleActive,
|
|
23
|
+
handleHorizontal,
|
|
24
|
+
handleVertical,
|
|
25
|
+
} from "./splitter.css";
|
|
26
|
+
|
|
27
|
+
// ─── Public types ──────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
export interface SplitterPanelProps {
|
|
30
|
+
defaultSize?: number;
|
|
31
|
+
size?: number;
|
|
32
|
+
minSize?: number;
|
|
33
|
+
maxSize?: number;
|
|
34
|
+
collapsible?: boolean;
|
|
35
|
+
collapsedSize?: number;
|
|
36
|
+
children?: React.ReactNode;
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface SplitterHandleProps {
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
className?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface SplitterProps {
|
|
46
|
+
orientation?: "horizontal" | "vertical";
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
storageKey?: string;
|
|
49
|
+
children?: React.ReactNode;
|
|
50
|
+
onResizeStart?: () => void;
|
|
51
|
+
onResize?: (sizes: number[]) => void;
|
|
52
|
+
onResizeEnd?: (sizes: number[]) => void;
|
|
53
|
+
className?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ─── Internal types ────────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
interface PanelConstraints {
|
|
59
|
+
minSize: number;
|
|
60
|
+
maxSize: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface InternalCtxValue {
|
|
64
|
+
orientation: "horizontal" | "vertical";
|
|
65
|
+
disabled: boolean;
|
|
66
|
+
sizes: number[];
|
|
67
|
+
panelConstraintsRef: React.MutableRefObject<(PanelConstraints | undefined)[]>;
|
|
68
|
+
panelRefs: React.MutableRefObject<(HTMLDivElement | null)[]>;
|
|
69
|
+
setSizes: React.Dispatch<React.SetStateAction<number[]>>;
|
|
70
|
+
handlePointerDown: (handleIndex: number, e: React.PointerEvent) => void;
|
|
71
|
+
handleKeyDown: (handleIndex: number, e: React.KeyboardEvent) => void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const InternalCtx = createContext<InternalCtxValue | null>(null);
|
|
75
|
+
|
|
76
|
+
function useInternalCtx(): InternalCtxValue {
|
|
77
|
+
const ctx = useContext(InternalCtx);
|
|
78
|
+
if (!ctx) {
|
|
79
|
+
throw new Error("Splitter compound components must be used within <Splitter>");
|
|
80
|
+
}
|
|
81
|
+
return ctx;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ─── Helpers ───────────────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
function isPanel(child: React.ReactNode): child is React.ReactElement<SplitterPanelProps> {
|
|
87
|
+
return React.isValidElement(child) && child.type === SplitterPanel;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isHandle(child: React.ReactNode): child is React.ReactElement<SplitterHandleProps> {
|
|
91
|
+
return React.isValidElement(child) && child.type === SplitterHandle;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function calculateSizes(panelProps: SplitterPanelProps[], storageKey?: string): number[] {
|
|
95
|
+
const count = panelProps.length;
|
|
96
|
+
|
|
97
|
+
if (count === 0) return [];
|
|
98
|
+
|
|
99
|
+
// Restore from storage
|
|
100
|
+
if (storageKey) {
|
|
101
|
+
try {
|
|
102
|
+
const stored = localStorage.getItem(storageKey);
|
|
103
|
+
if (stored) {
|
|
104
|
+
const parsed = JSON.parse(stored) as number[];
|
|
105
|
+
if (Array.isArray(parsed) && parsed.length === count) {
|
|
106
|
+
return parsed;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
/* Ignore */
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const result = Array.from({ length: count }, () => 0);
|
|
115
|
+
let usedSize = 0;
|
|
116
|
+
let unsetCount = count;
|
|
117
|
+
|
|
118
|
+
for (let i = 0; i < count; i++) {
|
|
119
|
+
const p = panelProps[i];
|
|
120
|
+
const sz = p?.size ?? p?.defaultSize;
|
|
121
|
+
if (sz != null) {
|
|
122
|
+
result[i] = sz;
|
|
123
|
+
usedSize += sz;
|
|
124
|
+
unsetCount--;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const equalShare = unsetCount > 0 ? (100 - usedSize) / unsetCount : 0;
|
|
129
|
+
for (let i = 0; i < count; i++) {
|
|
130
|
+
if (result[i] == null) {
|
|
131
|
+
result[i] = equalShare;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const total = result.reduce((a, b) => a + b, 0);
|
|
136
|
+
if (Math.abs(total - 100) > 0.01 && total > 0) {
|
|
137
|
+
for (let i = 0; i < count; i++) {
|
|
138
|
+
result[i] = ((result[i] as number) / total) * 100;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function clamp(value: number, min: number, max: number): number {
|
|
146
|
+
return Math.min(Math.max(value, min), max);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ─── Splitter ──────────────────────────────────────────────────────────────
|
|
150
|
+
|
|
151
|
+
export function Splitter({
|
|
152
|
+
orientation = "horizontal",
|
|
153
|
+
disabled: isDisabled = false,
|
|
154
|
+
storageKey,
|
|
155
|
+
children,
|
|
156
|
+
onResizeStart,
|
|
157
|
+
onResize,
|
|
158
|
+
onResizeEnd,
|
|
159
|
+
className,
|
|
160
|
+
}: SplitterProps) {
|
|
161
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
162
|
+
const panelConstraintsRef = useRef<(PanelConstraints | undefined)[]>([]);
|
|
163
|
+
const panelRefs = useRef<(HTMLDivElement | null)[]>([]);
|
|
164
|
+
const sizesRef = useRef<number[]>([]);
|
|
165
|
+
const isFirstRender = useRef(true);
|
|
166
|
+
|
|
167
|
+
const onResizeStartRef = useRef(onResizeStart);
|
|
168
|
+
const onResizeRef = useRef(onResize);
|
|
169
|
+
const onResizeEndRef = useRef(onResizeEnd);
|
|
170
|
+
onResizeStartRef.current = onResizeStart;
|
|
171
|
+
onResizeRef.current = onResize;
|
|
172
|
+
onResizeEndRef.current = onResizeEnd;
|
|
173
|
+
|
|
174
|
+
// Collect panel props from children (for initial size calculation)
|
|
175
|
+
const panelPropsList = useMemo(() => {
|
|
176
|
+
const list: SplitterPanelProps[] = [];
|
|
177
|
+
React.Children.forEach(children, (child) => {
|
|
178
|
+
if (isPanel(child)) {
|
|
179
|
+
list.push(child.props);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
return list;
|
|
183
|
+
}, [children]);
|
|
184
|
+
|
|
185
|
+
const panelCount = panelPropsList.length;
|
|
186
|
+
|
|
187
|
+
// ── State ──────────────────────────────────────────────────────────────
|
|
188
|
+
const [sizes, setSizes] = useState<number[]>(() => calculateSizes(panelPropsList, storageKey));
|
|
189
|
+
sizesRef.current = sizes;
|
|
190
|
+
|
|
191
|
+
// Recalculate if panel count changes
|
|
192
|
+
const prevPanelCount = useRef(panelCount);
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
if (prevPanelCount.current !== panelCount) {
|
|
195
|
+
prevPanelCount.current = panelCount;
|
|
196
|
+
setSizes(calculateSizes(panelPropsList, storageKey));
|
|
197
|
+
}
|
|
198
|
+
}, [panelCount, panelPropsList, storageKey]);
|
|
199
|
+
|
|
200
|
+
// ── Persist ────────────────────────────────────────────────────────────
|
|
201
|
+
useEffect(() => {
|
|
202
|
+
if (isFirstRender.current) {
|
|
203
|
+
isFirstRender.current = false;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (storageKey) {
|
|
207
|
+
try {
|
|
208
|
+
localStorage.setItem(storageKey, JSON.stringify(sizes));
|
|
209
|
+
} catch {
|
|
210
|
+
/* Ignore */
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}, [storageKey, sizes]);
|
|
214
|
+
|
|
215
|
+
// ── Pointer resize ─────────────────────────────────────────────────────
|
|
216
|
+
const handlePointerDown = useCallback(
|
|
217
|
+
(handleIndex: number, e: React.PointerEvent) => {
|
|
218
|
+
if (isDisabled) return;
|
|
219
|
+
e.preventDefault();
|
|
220
|
+
|
|
221
|
+
const root = rootRef.current;
|
|
222
|
+
if (!root) return;
|
|
223
|
+
|
|
224
|
+
const rect = root.getBoundingClientRect();
|
|
225
|
+
const totalPx = orientation === "horizontal" ? rect.width : rect.height;
|
|
226
|
+
const startPos = orientation === "horizontal" ? e.clientX : e.clientY;
|
|
227
|
+
|
|
228
|
+
const handleCount = panelCount - 1;
|
|
229
|
+
const handlesPx = handleCount * HANDLE_SIZE;
|
|
230
|
+
const availablePx = totalPx - handlesPx;
|
|
231
|
+
|
|
232
|
+
if (availablePx <= 0) return;
|
|
233
|
+
|
|
234
|
+
const startSizes = [...sizesRef.current];
|
|
235
|
+
|
|
236
|
+
onResizeStartRef.current?.();
|
|
237
|
+
|
|
238
|
+
const onMove = (ev: PointerEvent) => {
|
|
239
|
+
const currentPos = orientation === "horizontal" ? ev.clientX : ev.clientY;
|
|
240
|
+
const deltaPx = currentPos - startPos;
|
|
241
|
+
const deltaPct = (deltaPx / availablePx) * 100;
|
|
242
|
+
|
|
243
|
+
const newSizes = [...startSizes];
|
|
244
|
+
let left = (startSizes[handleIndex] ?? 0) + deltaPct;
|
|
245
|
+
let right = (startSizes[handleIndex + 1] ?? 0) - deltaPct;
|
|
246
|
+
|
|
247
|
+
const cLeft = panelConstraintsRef.current[handleIndex];
|
|
248
|
+
const cRight = panelConstraintsRef.current[handleIndex + 1];
|
|
249
|
+
const minL = cLeft?.minSize ?? 0;
|
|
250
|
+
const maxL = cLeft?.maxSize ?? 100;
|
|
251
|
+
const minR = cRight?.minSize ?? 0;
|
|
252
|
+
const maxR = cRight?.maxSize ?? 100;
|
|
253
|
+
|
|
254
|
+
if (left < minL) {
|
|
255
|
+
right += left - minL;
|
|
256
|
+
left = minL;
|
|
257
|
+
}
|
|
258
|
+
if (left > maxL) {
|
|
259
|
+
right -= left - maxL;
|
|
260
|
+
left = maxL;
|
|
261
|
+
}
|
|
262
|
+
if (right < minR) {
|
|
263
|
+
left -= minR - right;
|
|
264
|
+
right = minR;
|
|
265
|
+
}
|
|
266
|
+
if (right > maxR) {
|
|
267
|
+
left += right - maxR;
|
|
268
|
+
right = maxR;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
left = clamp(left, minL, maxL);
|
|
272
|
+
right = clamp(right, minR, maxR);
|
|
273
|
+
|
|
274
|
+
newSizes[handleIndex] = left;
|
|
275
|
+
newSizes[handleIndex + 1] = right;
|
|
276
|
+
|
|
277
|
+
setSizes(newSizes);
|
|
278
|
+
onResizeRef.current?.(newSizes);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const onUp = () => {
|
|
282
|
+
document.removeEventListener("pointermove", onMove);
|
|
283
|
+
document.removeEventListener("pointerup", onUp);
|
|
284
|
+
document.body.style.userSelect = "";
|
|
285
|
+
document.body.style.pointerEvents = "";
|
|
286
|
+
onResizeEndRef.current?.([...sizesRef.current]);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
document.addEventListener("pointermove", onMove);
|
|
290
|
+
document.addEventListener("pointerup", onUp);
|
|
291
|
+
document.body.style.userSelect = "none";
|
|
292
|
+
document.body.style.pointerEvents = "none";
|
|
293
|
+
},
|
|
294
|
+
[isDisabled, orientation, panelCount],
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
// ── Keyboard resize ────────────────────────────────────────────────────
|
|
298
|
+
const handleKeyDown = useCallback(
|
|
299
|
+
(handleIndex: number, e: React.KeyboardEvent) => {
|
|
300
|
+
if (isDisabled) return;
|
|
301
|
+
|
|
302
|
+
let delta = 0;
|
|
303
|
+
const step = e.shiftKey ? 10 : 1;
|
|
304
|
+
|
|
305
|
+
if (orientation === "horizontal") {
|
|
306
|
+
if (e.key === "ArrowLeft") delta = -step;
|
|
307
|
+
else if (e.key === "ArrowRight") delta = step;
|
|
308
|
+
} else {
|
|
309
|
+
if (e.key === "ArrowUp") delta = -step;
|
|
310
|
+
else if (e.key === "ArrowDown") delta = step;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (delta === 0) return;
|
|
314
|
+
e.preventDefault();
|
|
315
|
+
|
|
316
|
+
const currentSizes = sizesRef.current;
|
|
317
|
+
const newSizes = [...currentSizes];
|
|
318
|
+
let left = (currentSizes[handleIndex] ?? 0) + delta;
|
|
319
|
+
let right = (currentSizes[handleIndex + 1] ?? 0) - delta;
|
|
320
|
+
|
|
321
|
+
const cLeft = panelConstraintsRef.current[handleIndex];
|
|
322
|
+
const cRight = panelConstraintsRef.current[handleIndex + 1];
|
|
323
|
+
const minL = cLeft?.minSize ?? 0;
|
|
324
|
+
const maxL = cLeft?.maxSize ?? 100;
|
|
325
|
+
const minR = cRight?.minSize ?? 0;
|
|
326
|
+
const maxR = cRight?.maxSize ?? 100;
|
|
327
|
+
|
|
328
|
+
if (left < minL) {
|
|
329
|
+
right += left - minL;
|
|
330
|
+
left = minL;
|
|
331
|
+
}
|
|
332
|
+
if (left > maxL) {
|
|
333
|
+
right -= left - maxL;
|
|
334
|
+
left = maxL;
|
|
335
|
+
}
|
|
336
|
+
if (right < minR) {
|
|
337
|
+
left -= minR - right;
|
|
338
|
+
right = minR;
|
|
339
|
+
}
|
|
340
|
+
if (right > maxR) {
|
|
341
|
+
left += right - maxR;
|
|
342
|
+
right = maxR;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
left = clamp(left, minL, maxL);
|
|
346
|
+
right = clamp(right, minR, maxR);
|
|
347
|
+
|
|
348
|
+
newSizes[handleIndex] = left;
|
|
349
|
+
newSizes[handleIndex + 1] = right;
|
|
350
|
+
|
|
351
|
+
setSizes(newSizes);
|
|
352
|
+
onResizeRef.current?.(newSizes);
|
|
353
|
+
},
|
|
354
|
+
[isDisabled, orientation],
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
// ── Context value ──────────────────────────────────────────────────────
|
|
358
|
+
const ctxValue = useMemo<InternalCtxValue>(
|
|
359
|
+
() => ({
|
|
360
|
+
orientation,
|
|
361
|
+
disabled: isDisabled,
|
|
362
|
+
sizes,
|
|
363
|
+
panelConstraintsRef,
|
|
364
|
+
panelRefs,
|
|
365
|
+
setSizes,
|
|
366
|
+
handlePointerDown,
|
|
367
|
+
handleKeyDown,
|
|
368
|
+
}),
|
|
369
|
+
[orientation, isDisabled, sizes, handlePointerDown, handleKeyDown],
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
// ── Render children with indices ──────────────────────────────────────
|
|
373
|
+
let panelIdx = 0;
|
|
374
|
+
let handleIdx = 0;
|
|
375
|
+
|
|
376
|
+
const mapped = React.Children.map(children, (child) => {
|
|
377
|
+
if (isPanel(child)) {
|
|
378
|
+
const idx = panelIdx++;
|
|
379
|
+
return (
|
|
380
|
+
<SplitterPanel
|
|
381
|
+
{...(child.props as SplitterPanelProps)}
|
|
382
|
+
__panelIndex={idx}
|
|
383
|
+
key={child.key ?? `splitter-panel-${idx}`}
|
|
384
|
+
/>
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
if (isHandle(child)) {
|
|
388
|
+
const idx = handleIdx++;
|
|
389
|
+
return (
|
|
390
|
+
<SplitterHandle
|
|
391
|
+
{...(child.props as SplitterHandleProps)}
|
|
392
|
+
__handleIndex={idx}
|
|
393
|
+
key={child.key ?? `splitter-handle-${idx}`}
|
|
394
|
+
/>
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
return child;
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
return (
|
|
401
|
+
<InternalCtx.Provider value={ctxValue}>
|
|
402
|
+
<div
|
|
403
|
+
ref={rootRef}
|
|
404
|
+
className={clsx(
|
|
405
|
+
root,
|
|
406
|
+
orientation === "horizontal" ? rootHorizontal : rootVertical,
|
|
407
|
+
isDisabled && rootDisabled,
|
|
408
|
+
className,
|
|
409
|
+
)}
|
|
410
|
+
data-orientation={orientation}
|
|
411
|
+
>
|
|
412
|
+
{mapped}
|
|
413
|
+
</div>
|
|
414
|
+
</InternalCtx.Provider>
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// ─── SplitterPanel ─────────────────────────────────────────────────────────
|
|
419
|
+
|
|
420
|
+
export function SplitterPanel({
|
|
421
|
+
defaultSize: _defaultSize,
|
|
422
|
+
size: _size,
|
|
423
|
+
minSize = 0,
|
|
424
|
+
maxSize = 100,
|
|
425
|
+
collapsible: _collapsible = false,
|
|
426
|
+
collapsedSize: _collapsedSize = 0,
|
|
427
|
+
children,
|
|
428
|
+
className,
|
|
429
|
+
__panelIndex,
|
|
430
|
+
}: SplitterPanelProps & { __panelIndex?: number }) {
|
|
431
|
+
const ctx = useInternalCtx();
|
|
432
|
+
const index = __panelIndex!;
|
|
433
|
+
|
|
434
|
+
// Register constraints
|
|
435
|
+
useEffect(() => {
|
|
436
|
+
const ref = ctx.panelConstraintsRef.current;
|
|
437
|
+
ref[index] = { minSize, maxSize };
|
|
438
|
+
return () => {
|
|
439
|
+
ref[index] = undefined;
|
|
440
|
+
};
|
|
441
|
+
}, [index, minSize, maxSize, ctx.panelConstraintsRef]);
|
|
442
|
+
|
|
443
|
+
const panelSize = ctx.sizes[index] ?? 0;
|
|
444
|
+
|
|
445
|
+
return (
|
|
446
|
+
<div
|
|
447
|
+
ref={(el) => {
|
|
448
|
+
ctx.panelRefs.current[index] = el;
|
|
449
|
+
}}
|
|
450
|
+
className={clsx(panel, className)}
|
|
451
|
+
style={{ flex: `${panelSize} 0 0` }}
|
|
452
|
+
data-slot="splitter-panel"
|
|
453
|
+
>
|
|
454
|
+
{children}
|
|
455
|
+
</div>
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// ─── SplitterHandle ────────────────────────────────────────────────────────
|
|
460
|
+
|
|
461
|
+
export function SplitterHandle({
|
|
462
|
+
disabled: handleDisabled,
|
|
463
|
+
className,
|
|
464
|
+
__handleIndex,
|
|
465
|
+
}: SplitterHandleProps & { __handleIndex?: number }) {
|
|
466
|
+
const ctx = useInternalCtx();
|
|
467
|
+
const index = __handleIndex!;
|
|
468
|
+
const [active, setActive] = useState(false);
|
|
469
|
+
|
|
470
|
+
const onPointerDown = useCallback(
|
|
471
|
+
(e: React.PointerEvent) => {
|
|
472
|
+
if (handleDisabled || ctx.disabled) return;
|
|
473
|
+
setActive(true);
|
|
474
|
+
ctx.handlePointerDown(index, e);
|
|
475
|
+
},
|
|
476
|
+
[handleDisabled, ctx, index],
|
|
477
|
+
);
|
|
478
|
+
|
|
479
|
+
const onKeyDown = useCallback(
|
|
480
|
+
(e: React.KeyboardEvent) => {
|
|
481
|
+
ctx.handleKeyDown(index, e);
|
|
482
|
+
},
|
|
483
|
+
[ctx, index],
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
useEffect(() => {
|
|
487
|
+
if (!active) return;
|
|
488
|
+
const onUp = () => setActive(false);
|
|
489
|
+
document.addEventListener("pointerup", onUp);
|
|
490
|
+
return () => document.removeEventListener("pointerup", onUp);
|
|
491
|
+
}, [active]);
|
|
492
|
+
|
|
493
|
+
const panelSize = ctx.sizes[index] ?? 0;
|
|
494
|
+
|
|
495
|
+
return (
|
|
496
|
+
// oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
497
|
+
<hr
|
|
498
|
+
tabIndex={handleDisabled || ctx.disabled ? -1 : 0}
|
|
499
|
+
aria-orientation={ctx.orientation}
|
|
500
|
+
aria-valuenow={Math.round(panelSize)}
|
|
501
|
+
aria-valuemin={0}
|
|
502
|
+
aria-valuemax={100}
|
|
503
|
+
aria-disabled={handleDisabled || ctx.disabled || undefined}
|
|
504
|
+
onPointerDown={onPointerDown}
|
|
505
|
+
onKeyDown={onKeyDown}
|
|
506
|
+
className={clsx(
|
|
507
|
+
handle,
|
|
508
|
+
ctx.orientation === "horizontal" ? handleHorizontal : handleVertical,
|
|
509
|
+
active && handleActive,
|
|
510
|
+
(handleDisabled || ctx.disabled) && handleDisabled,
|
|
511
|
+
className,
|
|
512
|
+
)}
|
|
513
|
+
data-slot="splitter-handle"
|
|
514
|
+
/>
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// ─── Namespace props ───────────────────────────────────────────────────────
|
|
519
|
+
|
|
520
|
+
Splitter.Panel = SplitterPanel;
|
|
521
|
+
Splitter.Handle = SplitterHandle;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./stack";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { recipe } from "@vanilla-extract/recipes";
|
|
2
|
+
import { tokenVars } from "@blenx-dev/theme/contract";
|
|
3
|
+
|
|
4
|
+
export const stackRecipe = recipe({
|
|
5
|
+
variants: {
|
|
6
|
+
gap: {
|
|
7
|
+
none: { gap: 0 },
|
|
8
|
+
xxs: { gap: tokenVars.spacing.xxs },
|
|
9
|
+
xs: { gap: tokenVars.spacing.xs },
|
|
10
|
+
sm: { gap: tokenVars.spacing.sm },
|
|
11
|
+
md: { gap: tokenVars.spacing.md },
|
|
12
|
+
lg: { gap: tokenVars.spacing.lg },
|
|
13
|
+
xl: { gap: tokenVars.spacing.xl },
|
|
14
|
+
xxl: { gap: tokenVars.spacing.xxl },
|
|
15
|
+
xxxl: { gap: tokenVars.spacing.xxxl },
|
|
16
|
+
huge: { gap: tokenVars.spacing.huge },
|
|
17
|
+
massive: { gap: tokenVars.spacing.massive },
|
|
18
|
+
},
|
|
19
|
+
align: {
|
|
20
|
+
start: { alignItems: "flex-start" },
|
|
21
|
+
center: { alignItems: "center" },
|
|
22
|
+
end: { alignItems: "flex-end" },
|
|
23
|
+
stretch: { alignItems: "stretch" },
|
|
24
|
+
baseline: { alignItems: "baseline" },
|
|
25
|
+
},
|
|
26
|
+
justify: {
|
|
27
|
+
start: { justifyContent: "flex-start" },
|
|
28
|
+
center: { justifyContent: "center" },
|
|
29
|
+
end: { justifyContent: "flex-end" },
|
|
30
|
+
between: { justifyContent: "space-between" },
|
|
31
|
+
around: { justifyContent: "space-around" },
|
|
32
|
+
evenly: { justifyContent: "space-evenly" },
|
|
33
|
+
stretch: { justifyContent: "stretch" },
|
|
34
|
+
},
|
|
35
|
+
wrap: {
|
|
36
|
+
true: { flexWrap: "wrap" },
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
defaultVariants: {
|
|
40
|
+
gap: "md",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import type { BoxProps } from "../Box/box";
|
|
3
|
+
import { Box } from "../Box/box";
|
|
4
|
+
import { stackRecipe } from "./stack.css";
|
|
5
|
+
import type { RecipeVariants } from "@vanilla-extract/recipes";
|
|
6
|
+
|
|
7
|
+
type StackVariants = RecipeVariants<typeof stackRecipe>;
|
|
8
|
+
|
|
9
|
+
export type StackProps = Omit<BoxProps, "display"> & StackVariants;
|
|
10
|
+
|
|
11
|
+
export function Stack({ gap, align, justify, wrap, className, style, ...props }: StackProps) {
|
|
12
|
+
return (
|
|
13
|
+
<Box
|
|
14
|
+
display="flex"
|
|
15
|
+
className={clsx(stackRecipe({ gap, align, justify, wrap }), className)}
|
|
16
|
+
style={style}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type VStackProps = Omit<StackProps, "direction">;
|
|
23
|
+
|
|
24
|
+
export function VStack(props: VStackProps) {
|
|
25
|
+
return <Stack direction="column" {...props} />;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type HStackProps = Omit<StackProps, "direction">;
|
|
29
|
+
|
|
30
|
+
export function HStack(props: HStackProps) {
|
|
31
|
+
return <Stack direction="row" {...props} />;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./surface";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { recipe } from "@vanilla-extract/recipes";
|
|
2
|
+
import { semanticVars, tokenVars } from "@blenx-dev/theme/contract";
|
|
3
|
+
|
|
4
|
+
export const variantRecipe = recipe({
|
|
5
|
+
base: { textDecoration: "none" },
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
default: {
|
|
9
|
+
backgroundColor: semanticVars.surface.default,
|
|
10
|
+
},
|
|
11
|
+
outline: {
|
|
12
|
+
backgroundColor: semanticVars.surface.default,
|
|
13
|
+
borderWidth: 1,
|
|
14
|
+
borderStyle: "solid",
|
|
15
|
+
borderColor: semanticVars.border.default,
|
|
16
|
+
},
|
|
17
|
+
raised: {
|
|
18
|
+
backgroundColor: semanticVars.surface.raised,
|
|
19
|
+
boxShadow: tokenVars.shadow.md,
|
|
20
|
+
},
|
|
21
|
+
sunken: {
|
|
22
|
+
backgroundColor: semanticVars.background.subtle,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
interactive: {
|
|
26
|
+
true: {
|
|
27
|
+
cursor: "pointer",
|
|
28
|
+
selectors: {
|
|
29
|
+
"&:hover": {
|
|
30
|
+
backgroundColor: semanticVars.background.subtle,
|
|
31
|
+
},
|
|
32
|
+
"&:focus-visible": {
|
|
33
|
+
outline: `2px solid ${semanticVars.focus.ring}`,
|
|
34
|
+
outlineOffset: "2px",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import type { BoxProps } from "../Box/box";
|
|
3
|
+
import { Box } from "../Box/box";
|
|
4
|
+
import { variantRecipe } from "./surface.css";
|
|
5
|
+
import type { RecipeVariants } from "@vanilla-extract/recipes";
|
|
6
|
+
type SurfaceProps = BoxProps & RecipeVariants<typeof variantRecipe>;
|
|
7
|
+
|
|
8
|
+
function Surface({ variant, interactive, className, style, ...props }: SurfaceProps) {
|
|
9
|
+
return (
|
|
10
|
+
<Box
|
|
11
|
+
className={clsx(variantRecipe({ variant, interactive }), className)}
|
|
12
|
+
style={style}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type { SurfaceProps };
|
|
19
|
+
export { Surface };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./switch";
|