@vuer-ai/vuer-uikit 0.0.96 → 0.0.98
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 +106 -7
- package/cli/dial-cli.js +49 -7
- package/dist/SyncScroll/SyncScroll.cjs +10 -10
- package/dist/SyncScroll/SyncScroll.mjs +3 -3
- package/dist/SyncScroll/index.cjs +10 -10
- package/dist/SyncScroll/index.mjs +3 -3
- package/dist/chunk-3HEZVWRW.mjs +62 -0
- package/dist/chunk-4KWGGESI.cjs +494 -0
- package/dist/{chunk-CCMKL2OA.cjs → chunk-7GWDO25E.cjs} +2 -2
- package/dist/chunk-A5LCX2UQ.cjs +208 -0
- package/dist/chunk-BEJIZ56L.mjs +300 -0
- package/dist/chunk-C7VGRU3O.mjs +283 -0
- package/dist/{chunk-LONOMMFA.cjs → chunk-LJMNHTTG.cjs} +21 -21
- package/dist/chunk-O66RESRR.cjs +285 -0
- package/dist/{chunk-RINTUFYQ.cjs → chunk-RMK6W774.cjs} +24 -19
- package/dist/{chunk-BFQ2WL5U.mjs → chunk-TTYSYGVE.mjs} +2 -2
- package/dist/chunk-VA3PEYFM.mjs +489 -0
- package/dist/chunk-VBBJSIY7.cjs +308 -0
- package/dist/{chunk-AIINOWEH.mjs → chunk-W4JCKCW7.mjs} +5 -5
- package/dist/chunk-WWGF6TBZ.mjs +206 -0
- package/dist/chunk-ZGN4UEJR.cjs +679 -0
- package/dist/chunk-ZQLRMOUW.mjs +661 -0
- package/dist/dial/DialPanel.cjs +24 -24
- package/dist/dial/DialPanel.mjs +23 -23
- package/dist/dial/DialProvider.cjs +3 -3
- package/dist/dial/DialProvider.d.cts +1 -0
- package/dist/dial/DialProvider.d.ts +1 -0
- package/dist/dial/DialProvider.example.cjs +72 -0
- package/dist/dial/DialProvider.example.d.cts +7 -0
- package/dist/dial/DialProvider.example.d.ts +7 -0
- package/dist/dial/DialProvider.example.mjs +68 -0
- package/dist/dial/DialProvider.mjs +1 -1
- package/dist/dial/index.cjs +42 -42
- package/dist/dial/index.mjs +23 -23
- package/dist/dial/wrapped-inputs/ControlledInputs.cjs +27 -27
- package/dist/dial/wrapped-inputs/ControlledInputs.mjs +23 -23
- package/dist/dial/wrapped-inputs/DialInputs.cjs +34 -34
- package/dist/dial/wrapped-inputs/DialInputs.mjs +23 -23
- package/dist/dial/wrapped-inputs/DialVectorInput.cjs +24 -24
- package/dist/dial/wrapped-inputs/DialVectorInput.mjs +23 -23
- package/dist/dial/wrapped-inputs/index.cjs +39 -39
- package/dist/dial/wrapped-inputs/index.mjs +23 -23
- package/dist/highlight-cursor/cursor-provider.cjs +3 -3
- package/dist/highlight-cursor/cursor-provider.mjs +2 -2
- package/dist/highlight-cursor/enhanced-components.cjs +10 -10
- package/dist/highlight-cursor/enhanced-components.mjs +5 -5
- package/dist/highlight-cursor/index.cjs +16 -16
- package/dist/highlight-cursor/index.mjs +6 -6
- package/dist/hooks/index.cjs +5 -5
- package/dist/hooks/index.mjs +1 -1
- package/dist/index.cjs +190 -190
- package/dist/index.mjs +23 -23
- package/dist/ui/UIKitBadge.cjs +6 -6
- package/dist/ui/UIKitBadge.mjs +2 -2
- package/dist/ui/avatar.cjs +1 -1
- package/dist/ui/avatar.mjs +1 -1
- package/dist/ui/badge.cjs +1 -1
- package/dist/ui/badge.d.cts +1 -1
- package/dist/ui/badge.d.ts +1 -1
- package/dist/ui/badge.mjs +1 -1
- package/dist/ui/button.cjs +1 -1
- package/dist/ui/button.mjs +1 -1
- package/dist/ui/card.cjs +1 -1
- package/dist/ui/card.mjs +1 -1
- package/dist/ui/checkbox.cjs +1 -1
- package/dist/ui/checkbox.mjs +1 -1
- package/dist/ui/collapsible.cjs +1 -1
- package/dist/ui/collapsible.mjs +1 -1
- package/dist/ui/drawer.cjs +1 -1
- package/dist/ui/drawer.mjs +1 -1
- package/dist/ui/dropdown.cjs +1 -1
- package/dist/ui/dropdown.mjs +1 -1
- package/dist/ui/index.cjs +107 -107
- package/dist/ui/index.mjs +17 -17
- package/dist/ui/inputs/color-input.cjs +1 -1
- package/dist/ui/inputs/color-input.mjs +1 -1
- package/dist/ui/inputs/index.cjs +11 -11
- package/dist/ui/inputs/index.mjs +3 -3
- package/dist/ui/inputs/input-numbers.cjs +1 -1
- package/dist/ui/inputs/input-numbers.mjs +1 -1
- package/dist/ui/inputs/input.cjs +1 -1
- package/dist/ui/inputs/input.d.cts +1 -1
- package/dist/ui/inputs/input.d.ts +1 -1
- package/dist/ui/inputs/input.mjs +1 -1
- package/dist/ui/inputs/number-inputs/CmInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/CmInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/DegInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/DegInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerDegInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerDegInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerRadInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerRadInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/InchInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/InchInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/IntInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/IntInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/KVectorInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/KVectorInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/QuaternionInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/QuaternionInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/RadInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/RadInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/TimeInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/TimeInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/Vec3Input.cjs +1 -1
- package/dist/ui/inputs/number-inputs/Vec3Input.mjs +1 -1
- package/dist/ui/inputs/number-inputs/VectorInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/VectorInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/index.cjs +11 -11
- package/dist/ui/inputs/number-inputs/index.mjs +3 -3
- package/dist/ui/inputs/presets-input.cjs +1 -1
- package/dist/ui/inputs/presets-input.mjs +1 -1
- package/dist/ui/label.cjs +1 -1
- package/dist/ui/label.mjs +1 -1
- package/dist/ui/layout.cjs +1 -1
- package/dist/ui/layout.mjs +1 -1
- package/dist/ui/layouts/dock-layout/DockLayoutView.cjs +1 -1
- package/dist/ui/layouts/dock-layout/DockLayoutView.mjs +1 -1
- package/dist/ui/layouts/dock-layout/LayoutSlots.cjs +1 -1
- package/dist/ui/layouts/dock-layout/LayoutSlots.mjs +1 -1
- package/dist/ui/layouts/dock-layout/index.cjs +1 -1
- package/dist/ui/layouts/dock-layout/index.mjs +1 -1
- package/dist/ui/layouts/index.cjs +2 -2
- package/dist/ui/layouts/index.mjs +2 -2
- package/dist/ui/layouts/liquid-layout/LayoutSlots.cjs +1 -1
- package/dist/ui/layouts/liquid-layout/LayoutSlots.mjs +1 -1
- package/dist/ui/layouts/liquid-layout/LiquidLayoutView.cjs +1 -1
- package/dist/ui/layouts/liquid-layout/LiquidLayoutView.mjs +1 -1
- package/dist/ui/layouts/liquid-layout/index.cjs +1 -1
- package/dist/ui/layouts/liquid-layout/index.mjs +1 -1
- package/dist/ui/modal.cjs +1 -1
- package/dist/ui/modal.mjs +1 -1
- package/dist/ui/navigation.cjs +1 -1
- package/dist/ui/navigation.mjs +1 -1
- package/dist/ui/pagination.cjs +1 -1
- package/dist/ui/pagination.mjs +1 -1
- package/dist/ui/panel.cjs +1 -1
- package/dist/ui/panel.mjs +1 -1
- package/dist/ui/popover.cjs +1 -1
- package/dist/ui/popover.mjs +1 -1
- package/dist/ui/radio-group.cjs +1 -1
- package/dist/ui/radio-group.mjs +1 -1
- package/dist/ui/resizable.cjs +1 -1
- package/dist/ui/resizable.mjs +1 -1
- package/dist/ui/select.cjs +1 -1
- package/dist/ui/select.d.cts +1 -1
- package/dist/ui/select.d.ts +1 -1
- package/dist/ui/select.mjs +1 -1
- package/dist/ui/separator.cjs +1 -1
- package/dist/ui/separator.mjs +1 -1
- package/dist/ui/sheet.cjs +1 -1
- package/dist/ui/sheet.mjs +1 -1
- package/dist/ui/sidebar.cjs +26 -26
- package/dist/ui/sidebar.mjs +2 -2
- package/dist/ui/simple-tree-view.cjs +1 -1
- package/dist/ui/simple-tree-view.mjs +1 -1
- package/dist/ui/skeleton.cjs +1 -1
- package/dist/ui/skeleton.mjs +1 -1
- package/dist/ui/slider.cjs +1 -1
- package/dist/ui/slider.mjs +1 -1
- package/dist/ui/switch.cjs +1 -1
- package/dist/ui/switch.mjs +1 -1
- package/dist/ui/table.cjs +1 -1
- package/dist/ui/table.mjs +1 -1
- package/dist/ui/tabs.cjs +1 -1
- package/dist/ui/tabs.mjs +1 -1
- package/dist/ui/textarea.cjs +1 -1
- package/dist/ui/textarea.d.cts +1 -1
- package/dist/ui/textarea.d.ts +1 -1
- package/dist/ui/textarea.mjs +1 -1
- package/dist/ui/theme/ThemeToggles.cjs +1 -1
- package/dist/ui/theme/ThemeToggles.mjs +1 -1
- package/dist/ui/theme/index.cjs +1 -1
- package/dist/ui/theme/index.mjs +1 -1
- package/dist/ui/toggle-buttons.cjs +1 -1
- package/dist/ui/toggle-buttons.mjs +1 -1
- package/dist/ui/toggle-group.cjs +1 -1
- package/dist/ui/toggle-group.mjs +1 -1
- package/dist/ui/toggle.cjs +1 -1
- package/dist/ui/toggle.mjs +1 -1
- package/dist/ui/toolbar.cjs +1 -1
- package/dist/ui/toolbar.mjs +1 -1
- package/dist/ui/tooltip.cjs +1 -1
- package/dist/ui/tooltip.mjs +1 -1
- package/dist/ui/tree-view/TreeSearchBar.cjs +1 -1
- package/dist/ui/tree-view/TreeSearchBar.mjs +1 -1
- package/dist/ui/tree-view/TreeView.cjs +1 -1
- package/dist/ui/tree-view/TreeView.mjs +1 -1
- package/dist/ui/tree-view/index.cjs +6 -6
- package/dist/ui/tree-view/index.mjs +2 -2
- package/dist/ui/tree-view-legacy.cjs +9 -9
- package/dist/ui/tree-view-legacy.mjs +5 -5
- package/dist/ui/waterfall/CursorOverlay.cjs +1 -1
- package/dist/ui/waterfall/CursorOverlay.mjs +1 -1
- package/dist/ui/waterfall/TimelineEvent.cjs +1 -1
- package/dist/ui/waterfall/TimelineEvent.mjs +1 -1
- package/dist/ui/waterfall/TimelineProcessBar.cjs +1 -1
- package/dist/ui/waterfall/TimelineProcessBar.mjs +1 -1
- package/dist/ui/waterfall/Wedges.cjs +1 -1
- package/dist/ui/waterfall/Wedges.mjs +1 -1
- package/dist/ui/waterfall/index.cjs +8 -8
- package/dist/ui/waterfall/index.mjs +7 -7
- package/package.json +28 -2
- package/src/SyncScroll/README.md +283 -0
- package/src/SyncScroll/SyncScroll.tsx +361 -0
- package/src/SyncScroll/index.ts +22 -0
- package/src/SyncScroll/useSyncScroll.tsx +226 -0
- package/src/cli/dial-cli.ts +1133 -0
- package/src/dial/DialPanel.tsx +208 -0
- package/src/dial/DialProvider.example.tsx +80 -0
- package/src/dial/DialProvider.tsx +138 -0
- package/src/dial/index.ts +26 -0
- package/src/dial/wrapped-inputs/ControlledInputs.tsx +176 -0
- package/src/dial/wrapped-inputs/DialInputs.tsx +401 -0
- package/src/dial/wrapped-inputs/DialVectorInput.tsx +125 -0
- package/src/dial/wrapped-inputs/index.ts +25 -0
- package/src/highlight-cursor/cursor-context.tsx +23 -0
- package/src/highlight-cursor/cursor-provider.tsx +264 -0
- package/src/highlight-cursor/enhanced-components.tsx +16 -0
- package/src/highlight-cursor/index.ts +21 -0
- package/src/highlight-cursor/tabs-cursor-context.tsx +121 -0
- package/src/highlight-cursor/types.ts +40 -0
- package/src/highlight-cursor/with-cursor.tsx +144 -0
- package/src/hooks/clientOnly.tsx +54 -0
- package/src/hooks/cn.ts +33 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/useDocument.tsx +18 -0
- package/src/hooks/useDragSelect.ts +116 -0
- package/src/hooks/useIsMobile.ts +35 -0
- package/src/hooks/useLocalStorage.ts +122 -0
- package/src/hooks/useLocation.tsx +95 -0
- package/src/hooks/useQueryParams.tsx +31 -0
- package/src/hooks/useWindow.tsx +18 -0
- package/src/index.css +5 -0
- package/src/index.ts +5 -0
- package/src/styles/.editorconfig +0 -0
- package/src/styles/theme.css +152 -0
- package/src/styles/toast.css +67 -0
- package/src/styles/variables.css +229 -0
- package/src/ui/UIKitBadge.tsx +171 -0
- package/src/ui/avatar.tsx +221 -0
- package/src/ui/badge.tsx +74 -0
- package/src/ui/button.tsx +143 -0
- package/src/ui/card.tsx +146 -0
- package/src/ui/checkbox.tsx +78 -0
- package/src/ui/collapsible.tsx +43 -0
- package/src/ui/drag-selectable/DragSelectProvider.tsx +178 -0
- package/src/ui/drag-selectable/createSelectable.tsx +43 -0
- package/src/ui/drag-selectable/index.ts +2 -0
- package/src/ui/drawer.tsx +137 -0
- package/src/ui/dropdown.tsx +707 -0
- package/src/ui/icons/MouseCursorIcons.tsx +39 -0
- package/src/ui/icons/cursor.tsx +38 -0
- package/src/ui/icons/index.ts +2 -0
- package/src/ui/index.ts +45 -0
- package/src/ui/inputs/color-input.tsx +61 -0
- package/src/ui/inputs/index.tsx +5 -0
- package/src/ui/inputs/input-numbers.tsx +394 -0
- package/src/ui/inputs/input.tsx +155 -0
- package/src/ui/inputs/number-inputs/CmInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/DegInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/EulerDegInput.tsx +14 -0
- package/src/ui/inputs/number-inputs/EulerInput.tsx +30 -0
- package/src/ui/inputs/number-inputs/EulerRadInput.tsx +14 -0
- package/src/ui/inputs/number-inputs/InchInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/IntInput.tsx +46 -0
- package/src/ui/inputs/number-inputs/KVectorInput.tsx +20 -0
- package/src/ui/inputs/number-inputs/QuaternionInput.tsx +27 -0
- package/src/ui/inputs/number-inputs/RadInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/TimeInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/Vec3Input.tsx +26 -0
- package/src/ui/inputs/number-inputs/VectorInput.tsx +38 -0
- package/src/ui/inputs/number-inputs/index.ts +38 -0
- package/src/ui/inputs/presets-input.tsx +59 -0
- package/src/ui/label.tsx +35 -0
- package/src/ui/layout.tsx +43 -0
- package/src/ui/layouts/dock-layout/DockLayoutView.tsx +128 -0
- package/src/ui/layouts/dock-layout/LayoutSlots.tsx +85 -0
- package/src/ui/layouts/dock-layout/index.tsx +2 -0
- package/src/ui/layouts/index.ts +2 -0
- package/src/ui/layouts/liquid-layout/LayoutSlots.tsx +82 -0
- package/src/ui/layouts/liquid-layout/LiquidLayoutView.tsx +76 -0
- package/src/ui/layouts/liquid-layout/index.ts +1 -0
- package/src/ui/modal.tsx +211 -0
- package/src/ui/navigation.tsx +86 -0
- package/src/ui/pagination.tsx +129 -0
- package/src/ui/panel.tsx +146 -0
- package/src/ui/popover.tsx +112 -0
- package/src/ui/radio-group.tsx +63 -0
- package/src/ui/resizable.tsx +52 -0
- package/src/ui/select.tsx +365 -0
- package/src/ui/separator.tsx +26 -0
- package/src/ui/sheet.tsx +257 -0
- package/src/ui/sidebar.tsx +695 -0
- package/src/ui/simple-tree-view.tsx +604 -0
- package/src/ui/skeleton.tsx +15 -0
- package/src/ui/slider.tsx +204 -0
- package/src/ui/switch.tsx +45 -0
- package/src/ui/table.tsx +99 -0
- package/src/ui/tabs.tsx +192 -0
- package/src/ui/textarea.tsx +55 -0
- package/src/ui/theme/ThemeProvider.tsx +319 -0
- package/src/ui/theme/ThemeToggles.tsx +84 -0
- package/src/ui/theme/index.ts +21 -0
- package/src/ui/theme/themeScript.tsx +179 -0
- package/src/ui/theme/types.ts +61 -0
- package/src/ui/toast.tsx +30 -0
- package/src/ui/toggle-buttons.tsx +290 -0
- package/src/ui/toggle-group.tsx +236 -0
- package/src/ui/toggle.tsx +94 -0
- package/src/ui/toolbar.tsx +54 -0
- package/src/ui/tooltip.tsx +171 -0
- package/src/ui/tree-view/TreeSearchBar.tsx +88 -0
- package/src/ui/tree-view/TreeView.tsx +232 -0
- package/src/ui/tree-view/hooks.tsx +289 -0
- package/src/ui/tree-view/index.ts +4 -0
- package/src/ui/tree-view/types.ts +23 -0
- package/src/ui/tree-view-legacy.tsx +644 -0
- package/src/ui/version-badge.tsx +0 -0
- package/src/ui/waterfall/CursorOverlay.tsx +96 -0
- package/src/ui/waterfall/NavigationControls.tsx +42 -0
- package/src/ui/waterfall/Tick.tsx +51 -0
- package/src/ui/waterfall/TimeRuleEventDot.tsx +19 -0
- package/src/ui/waterfall/TimelineEvent.tsx +60 -0
- package/src/ui/waterfall/TimelineProcessBar.tsx +207 -0
- package/src/ui/waterfall/Wedges.tsx +67 -0
- package/src/ui/waterfall/WheelZoomContext.tsx +128 -0
- package/src/ui/waterfall/hooks/useTimelineState.tsx +134 -0
- package/src/ui/waterfall/hooks/useViewport.tsx +293 -0
- package/src/ui/waterfall/index.tsx +326 -0
- package/src/ui/waterfall/types.ts +20 -0
- package/src/ui/waterfall/utils.ts +91 -0
- package/dist/chunk-W2YAQV5N.mjs +0 -57
- package/dist/{chunk-QLCEHV4Q.mjs → chunk-2OZK5DY5.mjs} +2 -2
- package/dist/{chunk-Z35DNFRZ.cjs → chunk-7IS37C3P.cjs} +2 -2
- package/dist/{chunk-4AOAH77D.mjs → chunk-A2PCEL5S.mjs} +2 -2
- package/dist/{chunk-K4VD5PPY.mjs → chunk-BIUDC66P.mjs} +1 -1
- package/dist/{chunk-RKJR6RZU.cjs → chunk-OYNLQTHW.cjs} +1 -1
- package/dist/{chunk-VE3XLQLO.cjs → chunk-QUFZWF4E.cjs} +2 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
import { type ComponentProps, forwardRef } from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../hooks";
|
|
6
|
+
|
|
7
|
+
export const buttonVariants = cva(
|
|
8
|
+
[
|
|
9
|
+
"inline-flex",
|
|
10
|
+
"cursor-pointer",
|
|
11
|
+
"items-center",
|
|
12
|
+
"justify-center",
|
|
13
|
+
"shrink-0",
|
|
14
|
+
"whitespace-nowrap",
|
|
15
|
+
"transition-all",
|
|
16
|
+
"[&_svg]:shrink-0 ",
|
|
17
|
+
"[&_svg]:pointer-events-none",
|
|
18
|
+
"outline-none",
|
|
19
|
+
"disabled:pointer-events-none",
|
|
20
|
+
"disabled:bg-bg-tertiary",
|
|
21
|
+
"disabled:text-text-tertiary",
|
|
22
|
+
"focus-visible:border-ring",
|
|
23
|
+
"focus-visible:ring-ring/50",
|
|
24
|
+
"focus-visible:ring-[3px]",
|
|
25
|
+
"focus-visible:bg-brand-tertiary",
|
|
26
|
+
"aria-invalid:ring-destructive/20",
|
|
27
|
+
"aria-invalid:border-destructive",
|
|
28
|
+
],
|
|
29
|
+
{
|
|
30
|
+
variants: {
|
|
31
|
+
variant: {
|
|
32
|
+
primary: [
|
|
33
|
+
"bg-brand-primary",
|
|
34
|
+
"text-text-withbg",
|
|
35
|
+
"hover:bg-brand-hover",
|
|
36
|
+
"active:bg-brand-pressed",
|
|
37
|
+
],
|
|
38
|
+
secondary: [
|
|
39
|
+
"bg-alt-primary",
|
|
40
|
+
"text-text-highlight",
|
|
41
|
+
"hover:bg-alt-hover",
|
|
42
|
+
"active:bg-alt-pressed",
|
|
43
|
+
],
|
|
44
|
+
destructive: [
|
|
45
|
+
"bg-danger-primary",
|
|
46
|
+
"text-text-withbg",
|
|
47
|
+
"hover:bg-danger-secondary",
|
|
48
|
+
"active:bg-danger-tertiary",
|
|
49
|
+
],
|
|
50
|
+
ghost: [
|
|
51
|
+
"text-text-primary",
|
|
52
|
+
"hover:text-text-highlight",
|
|
53
|
+
"hover:bg-alt-primary",
|
|
54
|
+
"active:bg-bg-secondary",
|
|
55
|
+
// "active:text-brand-primary",
|
|
56
|
+
// todo: add state sensitivity (can do via toggle button)
|
|
57
|
+
// "[value]:text-brand-primary",
|
|
58
|
+
],
|
|
59
|
+
link: ["text-text-primary", "underline-offset-4", "hover:underline"],
|
|
60
|
+
},
|
|
61
|
+
size: {
|
|
62
|
+
sm: [
|
|
63
|
+
"rounded-uk-sm",
|
|
64
|
+
"text-uk-sm",
|
|
65
|
+
"py-sm",
|
|
66
|
+
"gap-xxs",
|
|
67
|
+
"px-sm",
|
|
68
|
+
"leading-4",
|
|
69
|
+
"[&_svg:not([class*='size-'])]:size-3",
|
|
70
|
+
],
|
|
71
|
+
md: [
|
|
72
|
+
"rounded-uk-md",
|
|
73
|
+
"text-uk-md",
|
|
74
|
+
"py-sm",
|
|
75
|
+
"gap-xs",
|
|
76
|
+
"px-lg",
|
|
77
|
+
"leading-5",
|
|
78
|
+
"[&_svg:not([class*='size-'])]:size-4",
|
|
79
|
+
],
|
|
80
|
+
lg: [
|
|
81
|
+
"rounded-uk-lg",
|
|
82
|
+
"text-uk-lg",
|
|
83
|
+
"py-sm",
|
|
84
|
+
"gap-xs",
|
|
85
|
+
"px-xl",
|
|
86
|
+
"leading-6",
|
|
87
|
+
"[&_svg:not([class*='size-'])]:size-5",
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
icon: { false: null, true: null },
|
|
91
|
+
value: {
|
|
92
|
+
false: null,
|
|
93
|
+
true: ["text-brand-primary", "[&_svg]:text-brand-primary"],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
compoundVariants: [
|
|
97
|
+
{ size: "sm", icon: true, class: ["px-xs", "py-xs", " size-6"] },
|
|
98
|
+
{ size: "md", icon: true, class: ["px-sm", "py-sm", "size-8"] },
|
|
99
|
+
{ size: "lg", icon: true, class: ["px-md", "py-md", " size-9"] },
|
|
100
|
+
],
|
|
101
|
+
defaultVariants: {
|
|
102
|
+
variant: "primary",
|
|
103
|
+
size: "md",
|
|
104
|
+
icon: false,
|
|
105
|
+
value: false,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
interface ButtonProps
|
|
111
|
+
extends Omit<ComponentProps<"button">, "value">,
|
|
112
|
+
VariantProps<typeof buttonVariants> {
|
|
113
|
+
asChild?: boolean;
|
|
114
|
+
value?: boolean;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Button component with variant and size styling.
|
|
119
|
+
* Wraps a native `button` or a child element when `asChild` is true.
|
|
120
|
+
*
|
|
121
|
+
* @param variant - Visual style variant (e.g. "primary", "secondary", "destructive", "ghost", "link")
|
|
122
|
+
* @param size - Control size ("sm" | "md" | "lg")
|
|
123
|
+
* @param icon - If true, adjusts paddings to present as an icon button
|
|
124
|
+
* @param asChild - When true, renders the child element instead of a button using Slot
|
|
125
|
+
*/
|
|
126
|
+
const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
|
|
127
|
+
{ className, variant, size, icon, value, asChild = false, ...props },
|
|
128
|
+
ref,
|
|
129
|
+
) {
|
|
130
|
+
const Comp = asChild ? Slot : "button";
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<Comp
|
|
134
|
+
ref={ref}
|
|
135
|
+
data-slot="button"
|
|
136
|
+
className={cn(buttonVariants({ variant, size, icon, value, className }))}
|
|
137
|
+
{...props}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export { Button };
|
|
143
|
+
export type { ButtonProps };
|
package/src/ui/card.tsx
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { type ComponentProps } from "react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "../hooks";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Variants for the card component.
|
|
8
|
+
*/
|
|
9
|
+
const cardVariants = cva(
|
|
10
|
+
[
|
|
11
|
+
"flex",
|
|
12
|
+
"flex-col",
|
|
13
|
+
"rounded-uk-lg",
|
|
14
|
+
"bg-bg-primary",
|
|
15
|
+
"shadow-[0_4px_16px_0_var(--color-shadow-secondary)]",
|
|
16
|
+
"liquid:liquid-bg",
|
|
17
|
+
],
|
|
18
|
+
{
|
|
19
|
+
variants: {
|
|
20
|
+
size: {
|
|
21
|
+
sm: "p-sm",
|
|
22
|
+
md: "p-md",
|
|
23
|
+
lg: "p-lg",
|
|
24
|
+
xl: "p-xl",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: {
|
|
28
|
+
size: "lg",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export interface CardProps extends ComponentProps<"div">, VariantProps<typeof cardVariants> {}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Container card with default padding, radius and shadow.
|
|
37
|
+
*/
|
|
38
|
+
function Card({ className, size, ...props }: CardProps) {
|
|
39
|
+
return <div data-slot="card" className={cn(cardVariants({ size, className }))} {...props} />;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Variants for the card header component.
|
|
44
|
+
*/
|
|
45
|
+
const cardHeaderVariants = cva(["flex", "flex-row", "items-center", "justify-between"], {
|
|
46
|
+
variants: {
|
|
47
|
+
size: {
|
|
48
|
+
sm: "gap-sm",
|
|
49
|
+
md: "gap-md",
|
|
50
|
+
lg: "gap-lg",
|
|
51
|
+
xl: "gap-xl",
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
defaultVariants: {
|
|
55
|
+
size: "lg",
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export interface CardHeaderProps
|
|
60
|
+
extends ComponentProps<"div">,
|
|
61
|
+
VariantProps<typeof cardHeaderVariants> {}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Horizontal header row for card.
|
|
65
|
+
*/
|
|
66
|
+
function CardHeader({ className, size, ...props }: CardHeaderProps) {
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
data-slot="card-header"
|
|
70
|
+
className={cn(cardHeaderVariants({ size, className }))}
|
|
71
|
+
{...props}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Title text styling within card.
|
|
78
|
+
*/
|
|
79
|
+
function CardTitle({ className, ...props }: ComponentProps<"div">) {
|
|
80
|
+
return (
|
|
81
|
+
<div
|
|
82
|
+
data-slot="card-title"
|
|
83
|
+
className={cn(
|
|
84
|
+
"text-text-highlight",
|
|
85
|
+
"text-uk-md",
|
|
86
|
+
"leading-uk-md",
|
|
87
|
+
"font-medium",
|
|
88
|
+
"-mt-2",
|
|
89
|
+
"vertical-align-middle",
|
|
90
|
+
className,
|
|
91
|
+
)}
|
|
92
|
+
{...props}
|
|
93
|
+
/>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Secondary description text.
|
|
99
|
+
*/
|
|
100
|
+
function CardDescription({ className, ...props }: ComponentProps<"div">) {
|
|
101
|
+
return (
|
|
102
|
+
<div
|
|
103
|
+
data-slot="card-description"
|
|
104
|
+
className={cn("text-uk-sm", "-mt-2", "text-text-secondary", "leading-uk-sm", className)}
|
|
105
|
+
{...props}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Right-aligned action area.
|
|
112
|
+
*/
|
|
113
|
+
function CardAction({ className, ...props }: ComponentProps<"div">) {
|
|
114
|
+
return (
|
|
115
|
+
<div
|
|
116
|
+
data-slot="card-action"
|
|
117
|
+
className={cn(
|
|
118
|
+
"text-text-secondary",
|
|
119
|
+
"text-uk-sm",
|
|
120
|
+
"leading-uk-sm",
|
|
121
|
+
"-mt-2",
|
|
122
|
+
"-mr-3",
|
|
123
|
+
"font-medium",
|
|
124
|
+
"vertical-align-middle",
|
|
125
|
+
className,
|
|
126
|
+
)}
|
|
127
|
+
{...props}
|
|
128
|
+
/>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Main content area.
|
|
134
|
+
*/
|
|
135
|
+
function CardContent({ className, ...props }: ComponentProps<"div">) {
|
|
136
|
+
return <div data-slot="card-content" className={cn("", className)} {...props} />;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Footer row for actions or meta.
|
|
141
|
+
*/
|
|
142
|
+
function CardFooter({ className, ...props }: ComponentProps<"div">) {
|
|
143
|
+
return <div data-slot="card-footer" className={cn("flex items-center", className)} {...props} />;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
2
|
+
import { CheckIcon } from "lucide-react";
|
|
3
|
+
import { type ComponentProps } from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../hooks";
|
|
6
|
+
|
|
7
|
+
interface CheckboxProps extends Omit<ComponentProps<typeof CheckboxPrimitive.Root>, "className"> {
|
|
8
|
+
checkall?: boolean;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Checkbox with optional "checkall" appearance.
|
|
14
|
+
* When `checkall` is true, renders a filled square state.
|
|
15
|
+
*/
|
|
16
|
+
const Checkbox = ({ className, checkall, ...props }: CheckboxProps) => (
|
|
17
|
+
<CheckboxPrimitive.Root
|
|
18
|
+
data-slot="checkbox"
|
|
19
|
+
className={cn(
|
|
20
|
+
"group",
|
|
21
|
+
"relative",
|
|
22
|
+
"w-[16px]",
|
|
23
|
+
"h-[16px]",
|
|
24
|
+
"rounded-[3px]",
|
|
25
|
+
"border-[1.5px]",
|
|
26
|
+
"border-solid",
|
|
27
|
+
"border-bg-tertiary",
|
|
28
|
+
"data-[state=checked]:bg-brand-primary",
|
|
29
|
+
"data-[state=checked]:border-none",
|
|
30
|
+
"disabled:cursor-not-allowed",
|
|
31
|
+
"disabled:bg-bg-secondary",
|
|
32
|
+
"disabled:data-[state=checked]:bg-bg-secondary",
|
|
33
|
+
"disabled:data-[state=checked]:border-[1.5px]",
|
|
34
|
+
"disabled:data-[state=checked]:border-solid",
|
|
35
|
+
"disabled:data-[state=checked]:border-bg-tertiary",
|
|
36
|
+
checkall && [
|
|
37
|
+
"data-[state=checked]:bg-bg-transparent",
|
|
38
|
+
"data-[state=checked]:border-[1.5px]",
|
|
39
|
+
"data-[state=checked]:border-solid",
|
|
40
|
+
"data-[state=checked]:border-bg-tertiary",
|
|
41
|
+
],
|
|
42
|
+
className,
|
|
43
|
+
)}
|
|
44
|
+
{...props}
|
|
45
|
+
>
|
|
46
|
+
{checkall ? (
|
|
47
|
+
<CheckboxPrimitive.Indicator
|
|
48
|
+
data-slot="checkbox-indicator"
|
|
49
|
+
className={cn(
|
|
50
|
+
"absolute",
|
|
51
|
+
"inset-0",
|
|
52
|
+
"m-auto",
|
|
53
|
+
"w-[8px]",
|
|
54
|
+
"h-[8px]",
|
|
55
|
+
"bg-brand-primary",
|
|
56
|
+
"group-disabled:bg-bg-tertiary",
|
|
57
|
+
)}
|
|
58
|
+
></CheckboxPrimitive.Indicator>
|
|
59
|
+
) : (
|
|
60
|
+
<CheckboxPrimitive.Indicator
|
|
61
|
+
data-slot="checkbox-indicator"
|
|
62
|
+
className={cn(
|
|
63
|
+
"flex",
|
|
64
|
+
"items-center",
|
|
65
|
+
"justify-center",
|
|
66
|
+
"text-current",
|
|
67
|
+
"transition-none",
|
|
68
|
+
"text-icon-withbg",
|
|
69
|
+
"group-disabled:text-bg-tertiary",
|
|
70
|
+
)}
|
|
71
|
+
>
|
|
72
|
+
<CheckIcon className="size-3.5" />
|
|
73
|
+
</CheckboxPrimitive.Indicator>
|
|
74
|
+
)}
|
|
75
|
+
</CheckboxPrimitive.Root>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
export { Checkbox };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
|
2
|
+
import type { ComponentProps } from "react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "../hooks";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Root container for collapsible content.
|
|
8
|
+
*/
|
|
9
|
+
const Collapsible = ({ ...props }: ComponentProps<typeof CollapsiblePrimitive.Root>) => (
|
|
10
|
+
<CollapsiblePrimitive.Root data-slot="collapsible" {...props} />
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Trigger element that toggles the collapsible state.
|
|
15
|
+
*/
|
|
16
|
+
const CollapsibleTrigger = ({
|
|
17
|
+
...props
|
|
18
|
+
}: ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) => (
|
|
19
|
+
<CollapsiblePrimitive.CollapsibleTrigger data-slot="collapsible-trigger" {...props} />
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Content area that animates open/close.
|
|
24
|
+
*/
|
|
25
|
+
const CollapsibleContent = ({
|
|
26
|
+
className,
|
|
27
|
+
...props
|
|
28
|
+
}: ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) => (
|
|
29
|
+
<CollapsiblePrimitive.CollapsibleContent
|
|
30
|
+
data-slot="collapsible-content"
|
|
31
|
+
className={cn(
|
|
32
|
+
[
|
|
33
|
+
"overflow-hidden",
|
|
34
|
+
"data-[state=open]:animate-collapsible-down",
|
|
35
|
+
"data-[state=closed]:animate-collapsible-up",
|
|
36
|
+
],
|
|
37
|
+
className,
|
|
38
|
+
)}
|
|
39
|
+
{...props}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export { Collapsible, CollapsibleTrigger, CollapsibleContent };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
type ReactNode,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
|
|
11
|
+
type SelectionMode = "replace" | "add" | "toggle";
|
|
12
|
+
|
|
13
|
+
interface DragSelectContextType {
|
|
14
|
+
selectedItems: Set<string>;
|
|
15
|
+
isDragging: boolean;
|
|
16
|
+
registerItem: (id: string, index: number) => void;
|
|
17
|
+
unregisterItem: (id: string) => void;
|
|
18
|
+
startDrag: (startId: string, mode?: SelectionMode) => void;
|
|
19
|
+
updateSelection: (currentId: string) => void;
|
|
20
|
+
endDrag: () => void;
|
|
21
|
+
clearSelection: () => void;
|
|
22
|
+
isSelected: (id: string) => boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DragSelectContext = createContext<DragSelectContextType | undefined>(undefined);
|
|
26
|
+
|
|
27
|
+
interface DragSelectProviderProps {
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const DragSelectProvider = ({ children }: DragSelectProviderProps) => {
|
|
32
|
+
const [selectedItems, setSelectedItems] = useState<Set<string>>(new Set());
|
|
33
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
34
|
+
const dragStartId = useRef<string | null>(null);
|
|
35
|
+
const dragMode = useRef<SelectionMode>("replace");
|
|
36
|
+
const dragStartSelection = useRef<Set<string>>(new Set());
|
|
37
|
+
const registeredItems = useRef<Map<string, number>>(new Map());
|
|
38
|
+
|
|
39
|
+
const registerItem = useCallback((id: string, index: number) => {
|
|
40
|
+
registeredItems.current.set(id, index);
|
|
41
|
+
}, []);
|
|
42
|
+
|
|
43
|
+
const unregisterItem = useCallback((id: string) => {
|
|
44
|
+
registeredItems.current.delete(id);
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
const startDrag = useCallback(
|
|
48
|
+
(startId: string, mode: SelectionMode = "replace") => {
|
|
49
|
+
setIsDragging(true);
|
|
50
|
+
dragStartId.current = startId;
|
|
51
|
+
dragMode.current = mode;
|
|
52
|
+
dragStartSelection.current = new Set(selectedItems);
|
|
53
|
+
|
|
54
|
+
if (mode === "replace") {
|
|
55
|
+
setSelectedItems(new Set([startId]));
|
|
56
|
+
} else if (mode === "add") {
|
|
57
|
+
setSelectedItems((prev) => new Set(Array.from(prev).concat([startId])));
|
|
58
|
+
} else if (mode === "toggle") {
|
|
59
|
+
setSelectedItems((prev) => {
|
|
60
|
+
const newSelection = new Set(prev);
|
|
61
|
+
if (newSelection.has(startId)) {
|
|
62
|
+
newSelection.delete(startId);
|
|
63
|
+
} else {
|
|
64
|
+
newSelection.add(startId);
|
|
65
|
+
}
|
|
66
|
+
return newSelection;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
[selectedItems],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const updateSelection = useCallback(
|
|
74
|
+
(currentId: string) => {
|
|
75
|
+
if (!isDragging || !dragStartId.current) return;
|
|
76
|
+
|
|
77
|
+
const startIndex = registeredItems.current.get(dragStartId.current);
|
|
78
|
+
const currentIndex = registeredItems.current.get(currentId);
|
|
79
|
+
|
|
80
|
+
if (startIndex === undefined || currentIndex === undefined) return;
|
|
81
|
+
|
|
82
|
+
const minIndex = Math.min(startIndex, currentIndex);
|
|
83
|
+
const maxIndex = Math.max(startIndex, currentIndex);
|
|
84
|
+
|
|
85
|
+
const dragSelection = new Set<string>();
|
|
86
|
+
Array.from(registeredItems.current.entries()).forEach(([itemId, itemIndex]) => {
|
|
87
|
+
if (itemIndex >= minIndex && itemIndex <= maxIndex) {
|
|
88
|
+
dragSelection.add(itemId);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (dragMode.current === "replace") {
|
|
93
|
+
setSelectedItems(dragSelection);
|
|
94
|
+
} else if (dragMode.current === "add") {
|
|
95
|
+
setSelectedItems(
|
|
96
|
+
() => new Set(Array.from(dragStartSelection.current).concat(Array.from(dragSelection))),
|
|
97
|
+
);
|
|
98
|
+
} else if (dragMode.current === "toggle") {
|
|
99
|
+
setSelectedItems(() => {
|
|
100
|
+
const newSelection = new Set(dragStartSelection.current);
|
|
101
|
+
Array.from(dragSelection).forEach((itemId) => {
|
|
102
|
+
if (newSelection.has(itemId)) {
|
|
103
|
+
newSelection.delete(itemId);
|
|
104
|
+
} else {
|
|
105
|
+
newSelection.add(itemId);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return newSelection;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[isDragging],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const endDrag = useCallback(() => {
|
|
116
|
+
setIsDragging(false);
|
|
117
|
+
dragStartId.current = null;
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
const clearSelection = useCallback(() => {
|
|
121
|
+
setSelectedItems(new Set());
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
const isSelected = useCallback(
|
|
125
|
+
(id: string) => {
|
|
126
|
+
return selectedItems.has(id);
|
|
127
|
+
},
|
|
128
|
+
[selectedItems],
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
const handleMouseUp = () => {
|
|
133
|
+
if (isDragging) {
|
|
134
|
+
endDrag();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
139
|
+
if (e.key === "Escape") {
|
|
140
|
+
clearSelection();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
145
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
146
|
+
|
|
147
|
+
return () => {
|
|
148
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
149
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
150
|
+
};
|
|
151
|
+
}, [isDragging, endDrag, clearSelection]);
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<DragSelectContext.Provider
|
|
155
|
+
value={{
|
|
156
|
+
selectedItems,
|
|
157
|
+
isDragging,
|
|
158
|
+
registerItem,
|
|
159
|
+
unregisterItem,
|
|
160
|
+
startDrag,
|
|
161
|
+
updateSelection,
|
|
162
|
+
endDrag,
|
|
163
|
+
clearSelection,
|
|
164
|
+
isSelected,
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
{children}
|
|
168
|
+
</DragSelectContext.Provider>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export const useDragSelectContext = () => {
|
|
173
|
+
const context = useContext(DragSelectContext);
|
|
174
|
+
if (context === undefined) {
|
|
175
|
+
throw new Error("useDragSelectContext must be used within a DragSelectProvider");
|
|
176
|
+
}
|
|
177
|
+
return context;
|
|
178
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { ComponentType, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import { useDragSelectContext } from "./DragSelectProvider";
|
|
4
|
+
|
|
5
|
+
interface SelectableProps {
|
|
6
|
+
id: string;
|
|
7
|
+
index: number;
|
|
8
|
+
isSelected?: boolean;
|
|
9
|
+
onMouseDown?: (e: React.MouseEvent) => void;
|
|
10
|
+
onMouseEnter?: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createSelectable<T extends object>(Component: ComponentType<T & SelectableProps>) {
|
|
14
|
+
return function SelectableComponent(props: T & { id: string; index: number }) {
|
|
15
|
+
const { registerItem, unregisterItem, startDrag, updateSelection, isSelected } =
|
|
16
|
+
useDragSelectContext();
|
|
17
|
+
|
|
18
|
+
const { id, index } = props;
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
registerItem(id, index);
|
|
22
|
+
return () => unregisterItem(id);
|
|
23
|
+
}, [id, index, registerItem, unregisterItem]);
|
|
24
|
+
|
|
25
|
+
const handleMouseDown = (e: React.MouseEvent) => {
|
|
26
|
+
const mode = e.ctrlKey || e.metaKey ? "replace" : "toggle";
|
|
27
|
+
startDrag(id, mode);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const handleMouseEnter = () => {
|
|
31
|
+
updateSelection(id);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Component
|
|
36
|
+
{...props}
|
|
37
|
+
isSelected={isSelected(id)}
|
|
38
|
+
onMouseDown={handleMouseDown}
|
|
39
|
+
onMouseEnter={handleMouseEnter}
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
}
|