@pixel-point/toolcraft 0.0.2
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/LICENSE.md +98 -0
- package/README.md +41 -0
- package/bin/create-toolcraft-app.mjs +8 -0
- package/bin/toolcraft.mjs +8 -0
- package/package.json +24 -0
- package/scripts/prepare-pack.mjs +29 -0
- package/src/cli.mjs +392 -0
- package/src/cli.test.mjs +284 -0
- package/src/copy-recursive.mjs +86 -0
- package/src/generate.mjs +212 -0
- package/src/generate.test.mjs +322 -0
- package/src/import-map.mjs +14 -0
- package/src/package-json.mjs +80 -0
- package/src/package-json.test.mjs +67 -0
- package/src/rewrite-imports.mjs +85 -0
- package/src/rewrite-imports.test.mjs +58 -0
- package/templates/runtime/contracts/component-contracts.test.ts +1165 -0
- package/templates/runtime/contracts/component-contracts.ts +1340 -0
- package/templates/runtime/contracts/decision-contracts.test.ts +206 -0
- package/templates/runtime/contracts/decision-contracts.ts +283 -0
- package/templates/runtime/contracts/index.test.ts +14 -0
- package/templates/runtime/contracts/index.ts +3 -0
- package/templates/runtime/contracts/types.ts +56 -0
- package/templates/runtime/export/export.test.ts +203 -0
- package/templates/runtime/export/export.ts +132 -0
- package/templates/runtime/export/index.ts +1 -0
- package/templates/runtime/index.ts +14 -0
- package/templates/runtime/react/canvas-shell.test.tsx +424 -0
- package/templates/runtime/react/canvas-shell.tsx +408 -0
- package/templates/runtime/react/control-renderers.ts +31 -0
- package/templates/runtime/react/controls-panel.test.tsx +3736 -0
- package/templates/runtime/react/controls-panel.tsx +2327 -0
- package/templates/runtime/react/curve-geometry.test.ts +70 -0
- package/templates/runtime/react/index.ts +15 -0
- package/templates/runtime/react/layer-tree.ts +96 -0
- package/templates/runtime/react/layers-panel.test.tsx +487 -0
- package/templates/runtime/react/layers-panel.tsx +1348 -0
- package/templates/runtime/react/media-file.ts +82 -0
- package/templates/runtime/react/panel-host-config.ts +80 -0
- package/templates/runtime/react/panel-host-geometry.test.ts +66 -0
- package/templates/runtime/react/panel-host-geometry.ts +109 -0
- package/templates/runtime/react/panel-host-types.ts +74 -0
- package/templates/runtime/react/panel-host.test.tsx +102 -0
- package/templates/runtime/react/panel-host.tsx +353 -0
- package/templates/runtime/react/runtime-public-api.test.tsx +132 -0
- package/templates/runtime/react/settings-transfer.test.ts +150 -0
- package/templates/runtime/react/settings-transfer.ts +279 -0
- package/templates/runtime/react/storage-key-migration.ts +48 -0
- package/templates/runtime/react/theme-runtime.tsx +177 -0
- package/templates/runtime/react/timeline-panel.test.tsx +668 -0
- package/templates/runtime/react/timeline-panel.tsx +2953 -0
- package/templates/runtime/react/toolbar-panel.test.tsx +212 -0
- package/templates/runtime/react/toolbar-panel.tsx +205 -0
- package/templates/runtime/react/toolcraft-app.integration.test.tsx +350 -0
- package/templates/runtime/react/toolcraft-app.test.tsx +339 -0
- package/templates/runtime/react/toolcraft-app.tsx +81 -0
- package/templates/runtime/react/toolcraft-root.test.tsx +347 -0
- package/templates/runtime/react/toolcraft-root.tsx +203 -0
- package/templates/runtime/react/use-toolcraft.ts +41 -0
- package/templates/runtime/schema/define-toolcraft.test.ts +1524 -0
- package/templates/runtime/schema/define-toolcraft.ts +1442 -0
- package/templates/runtime/schema/keyframe-capability.test.ts +90 -0
- package/templates/runtime/schema/keyframe-capability.ts +51 -0
- package/templates/runtime/schema/runtime-targets.ts +40 -0
- package/templates/runtime/schema/types.ts +370 -0
- package/templates/runtime/state/canvas-zoom.ts +8 -0
- package/templates/runtime/state/create-template-state.test.ts +242 -0
- package/templates/runtime/state/create-template-state.ts +95 -0
- package/templates/runtime/state/keyframe-evaluation.test.ts +141 -0
- package/templates/runtime/state/keyframe-evaluation.ts +203 -0
- package/templates/runtime/state/persistence.test.ts +217 -0
- package/templates/runtime/state/persistence.ts +511 -0
- package/templates/runtime/state/reducer.test.ts +937 -0
- package/templates/runtime/state/reducer.ts +1212 -0
- package/templates/runtime/state/timeline-readiness.ts +43 -0
- package/templates/runtime/state/types.ts +242 -0
- package/templates/runtime/styles.css +125 -0
- package/templates/runtime/testing/performance.test.ts +1058 -0
- package/templates/runtime/testing/performance.ts +1078 -0
- package/templates/starter/AGENTS.md +186 -0
- package/templates/starter/LICENSE.md +98 -0
- package/templates/starter/NOTICE.md +8 -0
- package/templates/starter/docs/toolcraft/README.md +41 -0
- package/templates/starter/docs/toolcraft/acceptance-testing.md +205 -0
- package/templates/starter/docs/toolcraft/agent-worklog.md +81 -0
- package/templates/starter/docs/toolcraft/assembly-workflow.md +206 -0
- package/templates/starter/docs/toolcraft/component-rules.md +299 -0
- package/templates/starter/docs/toolcraft/custom-controls.md +71 -0
- package/templates/starter/docs/toolcraft/decision-contract.md +71 -0
- package/templates/starter/docs/toolcraft/performance.md +112 -0
- package/templates/starter/docs/toolcraft/renderer-technique.md +48 -0
- package/templates/starter/docs/toolcraft/schema-reference.md +265 -0
- package/templates/starter/docs/toolcraft/workflow.md +87 -0
- package/templates/starter/e2e/app-browser-acceptance.spec.ts +785 -0
- package/templates/starter/e2e/app-controls.spec.ts +41 -0
- package/templates/starter/e2e/app-performance.spec.ts +326 -0
- package/templates/starter/e2e/canvas-handle-helpers.ts +244 -0
- package/templates/starter/e2e/performance-helpers.ts +612 -0
- package/templates/starter/e2e/product-observable-helpers.ts +170 -0
- package/templates/starter/index.html +12 -0
- package/templates/starter/package.json +52 -0
- package/templates/starter/playwright.config.ts +43 -0
- package/templates/starter/scripts/check-ai-skills.mjs +95 -0
- package/templates/starter/scripts/check-toolcraft-docs.mjs +159 -0
- package/templates/starter/scripts/check-toolcraft-integrity.mjs +232 -0
- package/templates/starter/scripts/run-vite-on-free-port.mjs +48 -0
- package/templates/starter/scripts/toolcraft-port.mjs +54 -0
- package/templates/starter/scripts/toolcraft-port.test.mjs +73 -0
- package/templates/starter/src/app/starter-acceptance.test.ts +5959 -0
- package/templates/starter/src/app/starter-acceptance.ts +2646 -0
- package/templates/starter/src/app/starter-performance.test.ts +1390 -0
- package/templates/starter/src/app/starter-performance.ts +12 -0
- package/templates/starter/src/app/starter-schema.test.ts +70 -0
- package/templates/starter/src/app/starter-schema.ts +15 -0
- package/templates/starter/src/main.tsx +18 -0
- package/templates/starter/src/router.tsx +16 -0
- package/templates/starter/src/routes/index.tsx +7 -0
- package/templates/starter/src/routes/root.tsx +19 -0
- package/templates/starter/src/styles.css +120 -0
- package/templates/starter/tsconfig.json +11 -0
- package/templates/starter/vite.config.ts +13 -0
- package/templates/ui/components/composites/accordion.tsx +73 -0
- package/templates/ui/components/composites/alert-dialog.tsx +190 -0
- package/templates/ui/components/composites/alert.tsx +74 -0
- package/templates/ui/components/composites/aspect-ratio.tsx +22 -0
- package/templates/ui/components/composites/avatar.tsx +98 -0
- package/templates/ui/components/composites/badge.tsx +69 -0
- package/templates/ui/components/composites/breadcrumb.tsx +106 -0
- package/templates/ui/components/composites/card.tsx +91 -0
- package/templates/ui/components/composites/combobox.tsx +486 -0
- package/templates/ui/components/composites/command.tsx +296 -0
- package/templates/ui/components/composites/context-menu.tsx +247 -0
- package/templates/ui/components/composites/dialog.tsx +282 -0
- package/templates/ui/components/composites/dropdown-menu.tsx +299 -0
- package/templates/ui/components/composites/empty.tsx +110 -0
- package/templates/ui/components/composites/hover-card.tsx +44 -0
- package/templates/ui/components/composites/index.ts +30 -0
- package/templates/ui/components/composites/menubar.tsx +214 -0
- package/templates/ui/components/composites/navigation-menu.tsx +167 -0
- package/templates/ui/components/composites/pagination.tsx +131 -0
- package/templates/ui/components/composites/progress.tsx +72 -0
- package/templates/ui/components/composites/radio-group.tsx +84 -0
- package/templates/ui/components/composites/resizable.tsx +42 -0
- package/templates/ui/components/composites/sheet.tsx +153 -0
- package/templates/ui/components/composites/sidebar-structural.tsx +310 -0
- package/templates/ui/components/composites/sidebar.tsx +431 -0
- package/templates/ui/components/composites/sonner.tsx +35 -0
- package/templates/ui/components/composites/spinner.tsx +43 -0
- package/templates/ui/components/composites/table.tsx +108 -0
- package/templates/ui/components/composites/tabs.tsx +83 -0
- package/templates/ui/components/control-layout/index.tsx +437 -0
- package/templates/ui/components/controls/actions/actions-control.tsx +139 -0
- package/templates/ui/components/controls/actions/index.ts +9 -0
- package/templates/ui/components/controls/anchor-grid/anchor-grid-control.tsx +107 -0
- package/templates/ui/components/controls/anchor-grid/index.ts +4 -0
- package/templates/ui/components/controls/boolean/boolean-controls.tsx +79 -0
- package/templates/ui/components/controls/boolean/index.ts +4 -0
- package/templates/ui/components/controls/channel-mixer/channel-mixer-control.tsx +95 -0
- package/templates/ui/components/controls/channel-mixer/index.ts +4 -0
- package/templates/ui/components/controls/channel-tabs/channel-tabs.tsx +42 -0
- package/templates/ui/components/controls/channel-tabs/index.ts +6 -0
- package/templates/ui/components/controls/code-textarea/code-textarea-control.tsx +90 -0
- package/templates/ui/components/controls/code-textarea/index.ts +4 -0
- package/templates/ui/components/controls/color/color-control.tsx +571 -0
- package/templates/ui/components/controls/color/color-picker-popover.tsx +104 -0
- package/templates/ui/components/controls/color/index.ts +41 -0
- package/templates/ui/components/controls/color/palette-control-data.ts +436 -0
- package/templates/ui/components/controls/color/palette-control.tsx +535 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-channel-utils.ts +162 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-interactions.ts +190 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-logic.ts +485 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-parts.tsx +710 -0
- package/templates/ui/components/controls/color/style-guide-color-picker.tsx +503 -0
- package/templates/ui/components/controls/control-types.ts +43 -0
- package/templates/ui/components/controls/curves/curve-geometry.ts +355 -0
- package/templates/ui/components/controls/curves/curve-graph.tsx +390 -0
- package/templates/ui/components/controls/curves/curves-control.tsx +445 -0
- package/templates/ui/components/controls/curves/index.ts +6 -0
- package/templates/ui/components/controls/file-drop/file-drop-control.tsx +191 -0
- package/templates/ui/components/controls/file-drop/index.ts +5 -0
- package/templates/ui/components/controls/font-picker/font-catalog.json +15360 -0
- package/templates/ui/components/controls/font-picker/font-catalog.ts +116 -0
- package/templates/ui/components/controls/font-picker/font-picker-control.tsx +1202 -0
- package/templates/ui/components/controls/font-picker/font-preview-loader.ts +336 -0
- package/templates/ui/components/controls/font-picker/index.ts +24 -0
- package/templates/ui/components/controls/font-picker/use-hover-intent.ts +46 -0
- package/templates/ui/components/controls/gradient/gradient-control-utils.ts +190 -0
- package/templates/ui/components/controls/gradient/gradient-control.tsx +612 -0
- package/templates/ui/components/controls/gradient/gradient-stop-list.tsx +400 -0
- package/templates/ui/components/controls/gradient/gradient-toolbar.tsx +152 -0
- package/templates/ui/components/controls/gradient/index.ts +4 -0
- package/templates/ui/components/controls/image-picker/image-picker-control.tsx +139 -0
- package/templates/ui/components/controls/image-picker/index.ts +7 -0
- package/templates/ui/components/controls/index.ts +192 -0
- package/templates/ui/components/controls/range-input/index.ts +4 -0
- package/templates/ui/components/controls/range-input/range-input-control.tsx +173 -0
- package/templates/ui/components/controls/range-slider/index.ts +4 -0
- package/templates/ui/components/controls/range-slider/range-slider-control.tsx +122 -0
- package/templates/ui/components/controls/range-slider/range-slider-value.ts +61 -0
- package/templates/ui/components/controls/segmented/index.ts +8 -0
- package/templates/ui/components/controls/segmented/segmented-control.tsx +94 -0
- package/templates/ui/components/controls/select/index.ts +4 -0
- package/templates/ui/components/controls/select/select-control.tsx +223 -0
- package/templates/ui/components/controls/slider/index.ts +4 -0
- package/templates/ui/components/controls/slider/slider-control.tsx +150 -0
- package/templates/ui/components/controls/slider/slider-value.ts +56 -0
- package/templates/ui/components/controls/text-input/index.ts +4 -0
- package/templates/ui/components/controls/text-input/text-input-control.tsx +158 -0
- package/templates/ui/components/controls/use-measured-element-width.ts +42 -0
- package/templates/ui/components/controls/vector/index.ts +8 -0
- package/templates/ui/components/controls/vector/vector-control.tsx +401 -0
- package/templates/ui/components/panel/index.ts +19 -0
- package/templates/ui/components/panel/panel-actions.tsx +165 -0
- package/templates/ui/components/panel/panel-header.tsx +61 -0
- package/templates/ui/components/panel/panel-icon-button.tsx +96 -0
- package/templates/ui/components/panel/panel-section.tsx +168 -0
- package/templates/ui/components/panel/panel-surface.tsx +206 -0
- package/templates/ui/components/panel/panel.tsx +210 -0
- package/templates/ui/components/primitives/animated-loader.tsx +61 -0
- package/templates/ui/components/primitives/button-group.tsx +134 -0
- package/templates/ui/components/primitives/button.tsx +429 -0
- package/templates/ui/components/primitives/checkbox.tsx +62 -0
- package/templates/ui/components/primitives/editable-slider-value-label.tsx +337 -0
- package/templates/ui/components/primitives/field.tsx +225 -0
- package/templates/ui/components/primitives/index.ts +82 -0
- package/templates/ui/components/primitives/input-group.tsx +298 -0
- package/templates/ui/components/primitives/input.tsx +61 -0
- package/templates/ui/components/primitives/internal/button-loading.tsx +178 -0
- package/templates/ui/components/primitives/label.tsx +16 -0
- package/templates/ui/components/primitives/popover.tsx +126 -0
- package/templates/ui/components/primitives/portal-layer-context.tsx +33 -0
- package/templates/ui/components/primitives/primitive-arrow-icon.tsx +38 -0
- package/templates/ui/components/primitives/scroll-fade-logic.ts +441 -0
- package/templates/ui/components/primitives/scroll-fade-render.tsx +75 -0
- package/templates/ui/components/primitives/scroll-fade-types.ts +41 -0
- package/templates/ui/components/primitives/scroll-fade.tsx +72 -0
- package/templates/ui/components/primitives/select.tsx +408 -0
- package/templates/ui/components/primitives/selection-state.ts +31 -0
- package/templates/ui/components/primitives/separator.tsx +21 -0
- package/templates/ui/components/primitives/slider/index.ts +4 -0
- package/templates/ui/components/primitives/slider/slider-interaction.tsx +96 -0
- package/templates/ui/components/primitives/slider/slider-parts.tsx +303 -0
- package/templates/ui/components/primitives/slider/slider-reset.ts +152 -0
- package/templates/ui/components/primitives/slider/slider-value.ts +114 -0
- package/templates/ui/components/primitives/slider/slider.tsx +511 -0
- package/templates/ui/components/primitives/switch.tsx +35 -0
- package/templates/ui/components/primitives/textarea.tsx +49 -0
- package/templates/ui/components/primitives/toggle-group.tsx +114 -0
- package/templates/ui/components/primitives/toggle.tsx +46 -0
- package/templates/ui/components/primitives/tooltip.tsx +100 -0
- package/templates/ui/hooks/use-mobile.ts +21 -0
- package/templates/ui/index.ts +31 -0
- package/templates/ui/lib/control-outline.ts +3 -0
- package/templates/ui/lib/input-control-style.ts +131 -0
- package/templates/ui/lib/style-guide-color-utils.ts +111 -0
- package/templates/ui/lib/utils.ts +6 -0
- package/templates/ui/styles.css +291 -0
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Slider as SliderPrimitive } from "@base-ui/react/slider";
|
|
5
|
+
import type { BaseUIEvent } from "@base-ui/react/types";
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../../lib/utils";
|
|
8
|
+
import { useSliderInteractionValueChange } from "./slider-interaction";
|
|
9
|
+
import { SliderControlContent } from "./slider-parts";
|
|
10
|
+
import { useSliderThumbReset } from "./slider-reset";
|
|
11
|
+
import {
|
|
12
|
+
getSliderValues,
|
|
13
|
+
normalizeSliderValueShape,
|
|
14
|
+
snapSliderValue,
|
|
15
|
+
valuesMatch,
|
|
16
|
+
type SliderRuntimeValue,
|
|
17
|
+
type SliderValue,
|
|
18
|
+
} from "./slider-value";
|
|
19
|
+
|
|
20
|
+
type SliderVariant = "continuous" | "discrete";
|
|
21
|
+
|
|
22
|
+
type SliderProps<Value extends number | readonly number[]> = SliderPrimitive.Root.Props<Value> & {
|
|
23
|
+
getAriaLabel?: (index: number) => string;
|
|
24
|
+
markerCount?: number;
|
|
25
|
+
markerValues?: readonly number[];
|
|
26
|
+
resetValue?: Value;
|
|
27
|
+
showFill?: boolean;
|
|
28
|
+
snapValues?: readonly number[];
|
|
29
|
+
variant?: SliderVariant;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type SliderPointerEvent = BaseUIEvent<React.PointerEvent<HTMLDivElement>>;
|
|
33
|
+
type SliderFocusEvent = BaseUIEvent<React.FocusEvent<HTMLDivElement>>;
|
|
34
|
+
type SliderPointerEventHandler = (event: SliderPointerEvent) => void;
|
|
35
|
+
type SliderFocusEventHandler = (event: SliderFocusEvent) => void;
|
|
36
|
+
|
|
37
|
+
type SliderValueStateOptions<Value extends number | readonly number[]> = {
|
|
38
|
+
defaultValue?: Value;
|
|
39
|
+
largeStep?: number;
|
|
40
|
+
max: number;
|
|
41
|
+
min: number;
|
|
42
|
+
onValueChange?: SliderProps<Value>["onValueChange"];
|
|
43
|
+
onValueCommitted?: SliderProps<Value>["onValueCommitted"];
|
|
44
|
+
snapValues?: readonly number[];
|
|
45
|
+
step: number;
|
|
46
|
+
value?: Value;
|
|
47
|
+
variant: SliderVariant;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type ControlledDiscreteValueResetOptions<Value extends number | readonly number[]> = {
|
|
51
|
+
discreteValue: Value | undefined;
|
|
52
|
+
isDiscrete: boolean;
|
|
53
|
+
lastInternalDiscreteValueRef: React.RefObject<Value | undefined>;
|
|
54
|
+
max: number;
|
|
55
|
+
min: number;
|
|
56
|
+
setDiscreteValue: React.Dispatch<React.SetStateAction<Value | undefined>>;
|
|
57
|
+
snapValues?: readonly number[];
|
|
58
|
+
step: number;
|
|
59
|
+
value: Value | undefined;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type SliderPointerDraggingOptions = {
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
onBlurCapture?: SliderFocusEventHandler;
|
|
65
|
+
onPointerCancelCapture?: SliderPointerEventHandler;
|
|
66
|
+
onPointerDownCapture?: SliderPointerEventHandler;
|
|
67
|
+
onPointerUpCapture?: SliderPointerEventHandler;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type SliderRuntimeOptions<Value extends number | readonly number[]> = {
|
|
71
|
+
defaultValue?: Value;
|
|
72
|
+
disabled?: boolean;
|
|
73
|
+
largeStep?: number;
|
|
74
|
+
markerCount?: number;
|
|
75
|
+
markerValues?: readonly number[];
|
|
76
|
+
max: number;
|
|
77
|
+
min: number;
|
|
78
|
+
onBlurCapture?: SliderFocusEventHandler;
|
|
79
|
+
onPointerCancelCapture?: SliderPointerEventHandler;
|
|
80
|
+
onPointerDownCapture?: SliderPointerEventHandler;
|
|
81
|
+
onPointerUpCapture?: SliderPointerEventHandler;
|
|
82
|
+
onValueChange?: SliderProps<Value>["onValueChange"];
|
|
83
|
+
onValueCommitted?: SliderProps<Value>["onValueCommitted"];
|
|
84
|
+
resetValue?: Value;
|
|
85
|
+
snapValues?: readonly number[];
|
|
86
|
+
step: number;
|
|
87
|
+
value?: Value;
|
|
88
|
+
variant: SliderVariant;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
function getSliderStepMarkerCount({
|
|
92
|
+
max,
|
|
93
|
+
min,
|
|
94
|
+
step,
|
|
95
|
+
}: {
|
|
96
|
+
max: number;
|
|
97
|
+
min: number;
|
|
98
|
+
step: number;
|
|
99
|
+
}): number | undefined {
|
|
100
|
+
if (
|
|
101
|
+
!Number.isFinite(step) ||
|
|
102
|
+
!Number.isFinite(min) ||
|
|
103
|
+
!Number.isFinite(max) ||
|
|
104
|
+
step <= 0 ||
|
|
105
|
+
max <= min
|
|
106
|
+
) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const rawStepCount = (max - min) / step;
|
|
111
|
+
const roundedStepCount = Math.round(rawStepCount);
|
|
112
|
+
const stepCount =
|
|
113
|
+
Math.abs(rawStepCount - roundedStepCount) < Number.EPSILON * 100
|
|
114
|
+
? roundedStepCount
|
|
115
|
+
: Math.floor(rawStepCount) + 1;
|
|
116
|
+
|
|
117
|
+
return Math.max(2, stepCount + 1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function useControlledDiscreteValueReset<Value extends number | readonly number[]>({
|
|
121
|
+
discreteValue,
|
|
122
|
+
isDiscrete,
|
|
123
|
+
lastInternalDiscreteValueRef,
|
|
124
|
+
max,
|
|
125
|
+
min,
|
|
126
|
+
setDiscreteValue,
|
|
127
|
+
snapValues,
|
|
128
|
+
step,
|
|
129
|
+
value,
|
|
130
|
+
}: ControlledDiscreteValueResetOptions<Value>) {
|
|
131
|
+
React.useEffect(() => {
|
|
132
|
+
if (!isDiscrete || value === undefined || discreteValue === undefined) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const lastInternalValue = lastInternalDiscreteValueRef.current;
|
|
137
|
+
if (lastInternalValue !== undefined) {
|
|
138
|
+
if (valuesMatch(value, lastInternalValue)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const snappedInternalValue = snapSliderValue(lastInternalValue, min, max, step, snapValues);
|
|
143
|
+
if (valuesMatch(value, snappedInternalValue)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
setDiscreteValue(undefined);
|
|
149
|
+
}, [
|
|
150
|
+
discreteValue,
|
|
151
|
+
isDiscrete,
|
|
152
|
+
lastInternalDiscreteValueRef,
|
|
153
|
+
max,
|
|
154
|
+
min,
|
|
155
|
+
setDiscreteValue,
|
|
156
|
+
snapValues,
|
|
157
|
+
step,
|
|
158
|
+
value,
|
|
159
|
+
]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function useSliderValueState<Value extends number | readonly number[]>({
|
|
163
|
+
defaultValue,
|
|
164
|
+
largeStep,
|
|
165
|
+
max,
|
|
166
|
+
min,
|
|
167
|
+
onValueChange,
|
|
168
|
+
onValueCommitted,
|
|
169
|
+
snapValues,
|
|
170
|
+
step,
|
|
171
|
+
value,
|
|
172
|
+
variant,
|
|
173
|
+
}: SliderValueStateOptions<Value>) {
|
|
174
|
+
const [discreteValue, setDiscreteValue] = React.useState<Value | undefined>(() =>
|
|
175
|
+
value === undefined ? defaultValue : undefined,
|
|
176
|
+
);
|
|
177
|
+
const lastInternalDiscreteValueRef = React.useRef<Value | undefined>(
|
|
178
|
+
value === undefined ? defaultValue : undefined,
|
|
179
|
+
);
|
|
180
|
+
const lastChangeDetailsRef = React.useRef<SliderPrimitive.Root.ChangeEventDetails | null>(null);
|
|
181
|
+
const isDiscrete = variant === "discrete";
|
|
182
|
+
const resolvedValue = isDiscrete ? (discreteValue ?? value ?? defaultValue) : value;
|
|
183
|
+
const rootStep = isDiscrete ? Math.max((max - min) / 1000, 0.000001) : step;
|
|
184
|
+
const rootLargeStep = isDiscrete ? (largeStep ?? step) : largeStep;
|
|
185
|
+
const values = React.useMemo(
|
|
186
|
+
() => getSliderValues(resolvedValue, defaultValue, min, max),
|
|
187
|
+
[resolvedValue, defaultValue, min, max],
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
useControlledDiscreteValueReset({
|
|
191
|
+
discreteValue,
|
|
192
|
+
isDiscrete,
|
|
193
|
+
lastInternalDiscreteValueRef,
|
|
194
|
+
max,
|
|
195
|
+
min,
|
|
196
|
+
setDiscreteValue,
|
|
197
|
+
snapValues,
|
|
198
|
+
step,
|
|
199
|
+
value,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const handleValueChange = React.useCallback(
|
|
203
|
+
(nextValue: SliderValue<Value>, eventDetails: SliderPrimitive.Root.ChangeEventDetails) => {
|
|
204
|
+
lastChangeDetailsRef.current = eventDetails;
|
|
205
|
+
if (isDiscrete) {
|
|
206
|
+
const normalizedNextValue = normalizeSliderValueShape(
|
|
207
|
+
nextValue as SliderRuntimeValue,
|
|
208
|
+
value,
|
|
209
|
+
defaultValue,
|
|
210
|
+
min,
|
|
211
|
+
);
|
|
212
|
+
lastInternalDiscreteValueRef.current = normalizedNextValue;
|
|
213
|
+
setDiscreteValue(normalizedNextValue);
|
|
214
|
+
onValueChange?.(
|
|
215
|
+
snapSliderValue(normalizedNextValue, min, max, step, snapValues) as SliderValue<Value>,
|
|
216
|
+
eventDetails,
|
|
217
|
+
);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
onValueChange?.(nextValue, eventDetails);
|
|
222
|
+
},
|
|
223
|
+
[defaultValue, isDiscrete, max, min, onValueChange, snapValues, step, value],
|
|
224
|
+
);
|
|
225
|
+
const handleValueCommitted = React.useCallback(
|
|
226
|
+
(nextValue: SliderValue<Value>, eventDetails: SliderPrimitive.Root.CommitEventDetails) => {
|
|
227
|
+
if (!isDiscrete) {
|
|
228
|
+
onValueCommitted?.(nextValue, eventDetails);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const normalizedNextValue = normalizeSliderValueShape(
|
|
233
|
+
nextValue as SliderRuntimeValue,
|
|
234
|
+
value,
|
|
235
|
+
defaultValue,
|
|
236
|
+
min,
|
|
237
|
+
);
|
|
238
|
+
const snappedValue = snapSliderValue(normalizedNextValue, min, max, step, snapValues);
|
|
239
|
+
lastInternalDiscreteValueRef.current = snappedValue;
|
|
240
|
+
setDiscreteValue(snappedValue);
|
|
241
|
+
|
|
242
|
+
if (!valuesMatch(snappedValue, normalizedNextValue) && lastChangeDetailsRef.current) {
|
|
243
|
+
onValueChange?.(snappedValue as SliderValue<Value>, lastChangeDetailsRef.current);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
onValueCommitted?.(snappedValue as SliderValue<Value>, eventDetails);
|
|
247
|
+
},
|
|
248
|
+
[defaultValue, isDiscrete, max, min, onValueChange, onValueCommitted, snapValues, step, value],
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
handleValueChange,
|
|
253
|
+
handleValueCommitted,
|
|
254
|
+
isDiscrete,
|
|
255
|
+
resolvedValue,
|
|
256
|
+
rootLargeStep,
|
|
257
|
+
rootStep,
|
|
258
|
+
values,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function useSliderPointerDragging({
|
|
263
|
+
disabled,
|
|
264
|
+
onBlurCapture,
|
|
265
|
+
onPointerCancelCapture,
|
|
266
|
+
onPointerDownCapture,
|
|
267
|
+
onPointerUpCapture,
|
|
268
|
+
}: SliderPointerDraggingOptions) {
|
|
269
|
+
const [isPointerDragging, setIsPointerDragging] = React.useState(false);
|
|
270
|
+
const stopPointerDrag = React.useCallback(() => {
|
|
271
|
+
setIsPointerDragging(false);
|
|
272
|
+
}, []);
|
|
273
|
+
const handlePointerDownCapture = React.useCallback(
|
|
274
|
+
(event: SliderPointerEvent) => {
|
|
275
|
+
onPointerDownCapture?.(event);
|
|
276
|
+
if (event.defaultPrevented || disabled || event.button !== 0) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
setIsPointerDragging(true);
|
|
281
|
+
},
|
|
282
|
+
[disabled, onPointerDownCapture],
|
|
283
|
+
);
|
|
284
|
+
const handlePointerUpCapture = React.useCallback(
|
|
285
|
+
(event: SliderPointerEvent) => {
|
|
286
|
+
onPointerUpCapture?.(event);
|
|
287
|
+
stopPointerDrag();
|
|
288
|
+
},
|
|
289
|
+
[onPointerUpCapture, stopPointerDrag],
|
|
290
|
+
);
|
|
291
|
+
const handlePointerCancelCapture = React.useCallback(
|
|
292
|
+
(event: SliderPointerEvent) => {
|
|
293
|
+
onPointerCancelCapture?.(event);
|
|
294
|
+
stopPointerDrag();
|
|
295
|
+
},
|
|
296
|
+
[onPointerCancelCapture, stopPointerDrag],
|
|
297
|
+
);
|
|
298
|
+
const handleBlurCapture = React.useCallback(
|
|
299
|
+
(event: SliderFocusEvent) => {
|
|
300
|
+
onBlurCapture?.(event);
|
|
301
|
+
stopPointerDrag();
|
|
302
|
+
},
|
|
303
|
+
[onBlurCapture, stopPointerDrag],
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
React.useEffect(() => {
|
|
307
|
+
if (!isPointerDragging) {
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
window.addEventListener("pointerup", stopPointerDrag);
|
|
312
|
+
window.addEventListener("pointercancel", stopPointerDrag);
|
|
313
|
+
window.addEventListener("blur", stopPointerDrag);
|
|
314
|
+
|
|
315
|
+
return () => {
|
|
316
|
+
window.removeEventListener("pointerup", stopPointerDrag);
|
|
317
|
+
window.removeEventListener("pointercancel", stopPointerDrag);
|
|
318
|
+
window.removeEventListener("blur", stopPointerDrag);
|
|
319
|
+
};
|
|
320
|
+
}, [isPointerDragging, stopPointerDrag]);
|
|
321
|
+
|
|
322
|
+
return {
|
|
323
|
+
handleBlurCapture,
|
|
324
|
+
handlePointerCancelCapture,
|
|
325
|
+
handlePointerDownCapture,
|
|
326
|
+
handlePointerUpCapture,
|
|
327
|
+
isPointerDragging,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function useSliderRuntime<Value extends number | readonly number[]>({
|
|
332
|
+
defaultValue,
|
|
333
|
+
disabled,
|
|
334
|
+
largeStep,
|
|
335
|
+
markerCount,
|
|
336
|
+
markerValues,
|
|
337
|
+
max,
|
|
338
|
+
min,
|
|
339
|
+
onBlurCapture,
|
|
340
|
+
onPointerCancelCapture,
|
|
341
|
+
onPointerDownCapture,
|
|
342
|
+
onPointerUpCapture,
|
|
343
|
+
onValueChange,
|
|
344
|
+
onValueCommitted,
|
|
345
|
+
resetValue,
|
|
346
|
+
snapValues,
|
|
347
|
+
step,
|
|
348
|
+
value,
|
|
349
|
+
variant,
|
|
350
|
+
}: SliderRuntimeOptions<Value>) {
|
|
351
|
+
const sliderValue = useSliderValueState({
|
|
352
|
+
defaultValue,
|
|
353
|
+
largeStep,
|
|
354
|
+
max,
|
|
355
|
+
min,
|
|
356
|
+
onValueChange,
|
|
357
|
+
onValueCommitted,
|
|
358
|
+
snapValues,
|
|
359
|
+
step,
|
|
360
|
+
value,
|
|
361
|
+
variant,
|
|
362
|
+
});
|
|
363
|
+
const pointerDrag = useSliderPointerDragging({
|
|
364
|
+
disabled,
|
|
365
|
+
onBlurCapture,
|
|
366
|
+
onPointerCancelCapture,
|
|
367
|
+
onPointerDownCapture,
|
|
368
|
+
onPointerUpCapture,
|
|
369
|
+
});
|
|
370
|
+
const resolvedMarkerCount =
|
|
371
|
+
variant === "discrete"
|
|
372
|
+
? (
|
|
373
|
+
markerCount ??
|
|
374
|
+
getSliderStepMarkerCount({ max, min, step }) ??
|
|
375
|
+
Math.max(2, Math.round(max - min) + 1)
|
|
376
|
+
)
|
|
377
|
+
: (markerCount ?? Math.max(2, Math.round(max - min) + 1));
|
|
378
|
+
const handleValueChange = useSliderInteractionValueChange({
|
|
379
|
+
disabled,
|
|
380
|
+
handleValueChange: sliderValue.handleValueChange,
|
|
381
|
+
max,
|
|
382
|
+
min,
|
|
383
|
+
values: sliderValue.values,
|
|
384
|
+
});
|
|
385
|
+
const handleThumbDoubleClick = useSliderThumbReset({
|
|
386
|
+
defaultValue,
|
|
387
|
+
disabled,
|
|
388
|
+
handleValueChange,
|
|
389
|
+
handleValueCommitted: sliderValue.handleValueCommitted,
|
|
390
|
+
isDiscrete: sliderValue.isDiscrete,
|
|
391
|
+
max,
|
|
392
|
+
min,
|
|
393
|
+
resetValue,
|
|
394
|
+
snapValues,
|
|
395
|
+
step,
|
|
396
|
+
value,
|
|
397
|
+
values: sliderValue.values,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
return {
|
|
401
|
+
handleThumbDoubleClick,
|
|
402
|
+
handleValueChange,
|
|
403
|
+
pointerDrag,
|
|
404
|
+
resolvedMarkerCount,
|
|
405
|
+
sliderValue,
|
|
406
|
+
markerValues,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function Slider<Value extends number | readonly number[]>({
|
|
411
|
+
className,
|
|
412
|
+
defaultValue,
|
|
413
|
+
disabled,
|
|
414
|
+
getAriaLabel,
|
|
415
|
+
largeStep,
|
|
416
|
+
markerCount,
|
|
417
|
+
markerValues,
|
|
418
|
+
onBlurCapture,
|
|
419
|
+
onPointerCancelCapture,
|
|
420
|
+
onPointerDownCapture,
|
|
421
|
+
onPointerUpCapture,
|
|
422
|
+
onValueChange,
|
|
423
|
+
onValueCommitted,
|
|
424
|
+
orientation = "horizontal",
|
|
425
|
+
resetValue,
|
|
426
|
+
showFill = true,
|
|
427
|
+
snapValues,
|
|
428
|
+
step = 1,
|
|
429
|
+
thumbAlignment = "edge",
|
|
430
|
+
variant = "continuous",
|
|
431
|
+
value,
|
|
432
|
+
min = 0,
|
|
433
|
+
max = 100,
|
|
434
|
+
...props
|
|
435
|
+
}: SliderProps<Value>) {
|
|
436
|
+
const {
|
|
437
|
+
handleThumbDoubleClick,
|
|
438
|
+
handleValueChange,
|
|
439
|
+
pointerDrag,
|
|
440
|
+
resolvedMarkerCount,
|
|
441
|
+
sliderValue,
|
|
442
|
+
} = useSliderRuntime({
|
|
443
|
+
defaultValue,
|
|
444
|
+
disabled,
|
|
445
|
+
largeStep,
|
|
446
|
+
markerCount,
|
|
447
|
+
markerValues,
|
|
448
|
+
max,
|
|
449
|
+
min,
|
|
450
|
+
onBlurCapture,
|
|
451
|
+
onPointerCancelCapture,
|
|
452
|
+
onPointerDownCapture,
|
|
453
|
+
onPointerUpCapture,
|
|
454
|
+
onValueChange,
|
|
455
|
+
onValueCommitted,
|
|
456
|
+
resetValue,
|
|
457
|
+
snapValues,
|
|
458
|
+
step,
|
|
459
|
+
value,
|
|
460
|
+
variant,
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
return (
|
|
464
|
+
<SliderPrimitive.Root
|
|
465
|
+
className={cn(
|
|
466
|
+
"app-no-drag data-horizontal:w-full data-vertical:h-full",
|
|
467
|
+
"[--slider-active-color:var(--foreground)] [--slider-track-color:color-mix(in_oklab,var(--muted-foreground)_38%,transparent)]",
|
|
468
|
+
"data-[disabled]:[--slider-active-color:var(--foreground)] data-[disabled]:[--slider-track-color:var(--foreground)]",
|
|
469
|
+
className,
|
|
470
|
+
)}
|
|
471
|
+
data-slot="slider"
|
|
472
|
+
data-variant={variant}
|
|
473
|
+
defaultValue={sliderValue.isDiscrete ? undefined : defaultValue}
|
|
474
|
+
value={sliderValue.resolvedValue}
|
|
475
|
+
min={min}
|
|
476
|
+
max={max}
|
|
477
|
+
disabled={disabled}
|
|
478
|
+
largeStep={sliderValue.rootLargeStep}
|
|
479
|
+
onBlurCapture={pointerDrag.handleBlurCapture}
|
|
480
|
+
onPointerCancelCapture={pointerDrag.handlePointerCancelCapture}
|
|
481
|
+
onPointerDownCapture={pointerDrag.handlePointerDownCapture}
|
|
482
|
+
onPointerUpCapture={pointerDrag.handlePointerUpCapture}
|
|
483
|
+
onValueChange={handleValueChange}
|
|
484
|
+
onValueCommitted={sliderValue.handleValueCommitted}
|
|
485
|
+
orientation={orientation}
|
|
486
|
+
step={sliderValue.rootStep}
|
|
487
|
+
thumbAlignment={thumbAlignment}
|
|
488
|
+
thumbCollisionBehavior="none"
|
|
489
|
+
{...props}
|
|
490
|
+
>
|
|
491
|
+
<SliderControlContent
|
|
492
|
+
count={sliderValue.values.length}
|
|
493
|
+
disabled={disabled}
|
|
494
|
+
getAriaLabel={getAriaLabel}
|
|
495
|
+
isDiscrete={sliderValue.isDiscrete}
|
|
496
|
+
isPointerDragging={pointerDrag.isPointerDragging}
|
|
497
|
+
markerCount={resolvedMarkerCount}
|
|
498
|
+
markerValues={markerValues}
|
|
499
|
+
max={max}
|
|
500
|
+
min={min}
|
|
501
|
+
onThumbDoubleClick={handleThumbDoubleClick}
|
|
502
|
+
orientation={orientation}
|
|
503
|
+
showFill={showFill}
|
|
504
|
+
/>
|
|
505
|
+
</SliderPrimitive.Root>
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export { SliderInteractionProvider } from "./slider-interaction";
|
|
510
|
+
export type { SliderInteractionChangeDetails } from "./slider-interaction";
|
|
511
|
+
export { Slider };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Switch as SwitchPrimitive } from "@base-ui/react/switch";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils";
|
|
6
|
+
|
|
7
|
+
function Switch({
|
|
8
|
+
className,
|
|
9
|
+
checkedThumbSide = "end",
|
|
10
|
+
size = "default",
|
|
11
|
+
...props
|
|
12
|
+
}: SwitchPrimitive.Root.Props & {
|
|
13
|
+
checkedThumbSide?: "start" | "end";
|
|
14
|
+
size?: "xs" | "sm" | "default";
|
|
15
|
+
}) {
|
|
16
|
+
return (
|
|
17
|
+
<SwitchPrimitive.Root
|
|
18
|
+
data-checked-thumb-side={checkedThumbSide}
|
|
19
|
+
data-slot="switch"
|
|
20
|
+
data-size={size}
|
|
21
|
+
className={cn(
|
|
22
|
+
"peer group/switch relative inline-flex shrink-0 cursor-pointer items-center rounded-full p-px transition-all outline-none after:absolute after:-inset-x-3 after:-inset-y-2 aria-invalid:ring aria-invalid:ring-[color:color-mix(in_oklab,var(--destructive)_20%,transparent)] data-[size=default]:h-4 data-[size=default]:w-[28px] data-[size=sm]:h-3.5 data-[size=sm]:w-[24px] data-[size=xs]:h-3 data-[size=xs]:w-5 dark:aria-invalid:ring-[color:color-mix(in_oklab,var(--destructive)_40%,transparent)] data-checked:bg-[color:var(--accent)] data-unchecked:bg-[color:color-mix(in_oklab,var(--input)_20%,transparent)] data-disabled:cursor-not-allowed data-disabled:opacity-50",
|
|
23
|
+
className,
|
|
24
|
+
)}
|
|
25
|
+
{...props}
|
|
26
|
+
>
|
|
27
|
+
<SwitchPrimitive.Thumb
|
|
28
|
+
data-slot="switch-thumb"
|
|
29
|
+
className="pointer-events-none block rounded-full bg-[color:var(--background)] ring-0 transition-transform group-data-[size=default]/switch:size-3.5 group-data-[size=sm]/switch:size-3 group-data-[size=xs]/switch:size-2.5 group-data-[checked-thumb-side=end]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[checked-thumb-side=end]/switch:data-unchecked:translate-x-0 group-data-[checked-thumb-side=start]/switch:data-checked:translate-x-0 group-data-[checked-thumb-side=start]/switch:data-unchecked:translate-x-[calc(100%-2px)] dark:bg-[color:var(--foreground)]"
|
|
30
|
+
/>
|
|
31
|
+
</SwitchPrimitive.Root>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { Switch };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
+
import { SHARED_INPUT_CONTROL_BASE_CLASS_NAME } from "../../lib/input-control-style";
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../lib/utils";
|
|
8
|
+
|
|
9
|
+
const textareaVariants = cva(
|
|
10
|
+
cn("flex field-sizing-content resize-none", SHARED_INPUT_CONTROL_BASE_CLASS_NAME),
|
|
11
|
+
{
|
|
12
|
+
variants: {
|
|
13
|
+
size: {
|
|
14
|
+
content: "min-h-0 px-2 py-2 text-sm/relaxed",
|
|
15
|
+
sm: "min-h-14 px-2 py-1.5 text-xs/relaxed",
|
|
16
|
+
default: "min-h-16 px-2 py-2 text-xs-plus/relaxed",
|
|
17
|
+
lg: "min-h-20 px-2.5 py-2.5 text-sm/relaxed",
|
|
18
|
+
xl: "min-h-24 px-3 py-3 text-base/relaxed",
|
|
19
|
+
},
|
|
20
|
+
variant: {
|
|
21
|
+
default: "",
|
|
22
|
+
"code-editor":
|
|
23
|
+
"relative z-10 min-h-0 overflow-x-auto overflow-y-hidden font-mono whitespace-pre text-xs/relaxed text-transparent caret-[color:var(--foreground)] selection:bg-[color:var(--accent)] selection:text-transparent",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: {
|
|
27
|
+
size: "default",
|
|
28
|
+
variant: "default",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const Textarea = React.forwardRef<
|
|
34
|
+
HTMLTextAreaElement,
|
|
35
|
+
React.ComponentProps<"textarea"> & VariantProps<typeof textareaVariants>
|
|
36
|
+
>(function Textarea({ className, size, variant, ...props }, ref) {
|
|
37
|
+
return (
|
|
38
|
+
<textarea
|
|
39
|
+
ref={ref}
|
|
40
|
+
data-size={size ?? "default"}
|
|
41
|
+
data-slot="textarea"
|
|
42
|
+
data-variant={variant ?? "default"}
|
|
43
|
+
className={cn(textareaVariants({ size, variant }), className)}
|
|
44
|
+
{...props}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export { Textarea, textareaVariants };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Toggle as TogglePrimitive } from "@base-ui/react/toggle";
|
|
5
|
+
import { ToggleGroup as ToggleGroupPrimitive } from "@base-ui/react/toggle-group";
|
|
6
|
+
import { type VariantProps } from "class-variance-authority";
|
|
7
|
+
|
|
8
|
+
import { cn } from "../../lib/utils";
|
|
9
|
+
import { toggleVariants } from "./toggle";
|
|
10
|
+
|
|
11
|
+
const ToggleGroupContext = React.createContext<
|
|
12
|
+
VariantProps<typeof toggleVariants> & {
|
|
13
|
+
spacing?: number;
|
|
14
|
+
orientation?: "horizontal" | "vertical";
|
|
15
|
+
}
|
|
16
|
+
>({
|
|
17
|
+
size: "default",
|
|
18
|
+
variant: "default",
|
|
19
|
+
spacing: 0,
|
|
20
|
+
orientation: "horizontal",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function getJoinedOutlineGroupClassName({
|
|
24
|
+
orientation,
|
|
25
|
+
spacing,
|
|
26
|
+
variant,
|
|
27
|
+
}: {
|
|
28
|
+
orientation: "horizontal" | "vertical";
|
|
29
|
+
spacing: number;
|
|
30
|
+
variant?: VariantProps<typeof toggleVariants>["variant"];
|
|
31
|
+
}): string {
|
|
32
|
+
if (spacing !== 0 || variant !== "outline") {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (orientation === "vertical") {
|
|
37
|
+
return "[&>[data-slot]]:relative [&>[data-slot]:has(+[data-slot])]:border-b-0 [&>[data-slot][aria-pressed=true]+[data-slot]]:border-t-[color:color-mix(in_oklab,var(--border)_10%,transparent)] [&>[data-slot][data-pressed]+[data-slot]]:border-t-[color:color-mix(in_oklab,var(--border)_10%,transparent)] [&>[data-slot][data-state=on]+[data-slot]]:border-t-[color:color-mix(in_oklab,var(--border)_10%,transparent)]";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return "[&>[data-slot]]:relative [&>[data-slot]:has(+[data-slot])]:border-r-0 [&>[data-slot][aria-pressed=true]+[data-slot]]:border-l-[color:color-mix(in_oklab,var(--border)_10%,transparent)] [&>[data-slot][data-pressed]+[data-slot]]:border-l-[color:color-mix(in_oklab,var(--border)_10%,transparent)] [&>[data-slot][data-state=on]+[data-slot]]:border-l-[color:color-mix(in_oklab,var(--border)_10%,transparent)]";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function ToggleGroup({
|
|
44
|
+
className,
|
|
45
|
+
variant,
|
|
46
|
+
size,
|
|
47
|
+
spacing = 0,
|
|
48
|
+
orientation = "horizontal",
|
|
49
|
+
children,
|
|
50
|
+
...props
|
|
51
|
+
}: ToggleGroupPrimitive.Props &
|
|
52
|
+
VariantProps<typeof toggleVariants> & {
|
|
53
|
+
spacing?: number;
|
|
54
|
+
orientation?: "horizontal" | "vertical";
|
|
55
|
+
}) {
|
|
56
|
+
const joinedOutlineGroupClassName = getJoinedOutlineGroupClassName({
|
|
57
|
+
orientation,
|
|
58
|
+
spacing,
|
|
59
|
+
variant,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<ToggleGroupPrimitive
|
|
64
|
+
data-slot="toggle-group"
|
|
65
|
+
data-variant={variant}
|
|
66
|
+
data-size={size}
|
|
67
|
+
data-spacing={spacing}
|
|
68
|
+
data-orientation={orientation}
|
|
69
|
+
style={{ "--gap": spacing } as React.CSSProperties}
|
|
70
|
+
className={cn(
|
|
71
|
+
"group/toggle-group flex w-fit flex-row items-center gap-[--spacing(var(--gap))] rounded-md data-[size=sm]:rounded-[min(var(--radius-md),8px)] data-vertical:flex-col data-vertical:items-stretch",
|
|
72
|
+
joinedOutlineGroupClassName,
|
|
73
|
+
className,
|
|
74
|
+
)}
|
|
75
|
+
{...props}
|
|
76
|
+
>
|
|
77
|
+
<ToggleGroupContext.Provider value={{ variant, size, spacing, orientation }}>
|
|
78
|
+
{children}
|
|
79
|
+
</ToggleGroupContext.Provider>
|
|
80
|
+
</ToggleGroupPrimitive>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function ToggleGroupItem({
|
|
85
|
+
className,
|
|
86
|
+
children,
|
|
87
|
+
variant = "default",
|
|
88
|
+
size = "default",
|
|
89
|
+
...props
|
|
90
|
+
}: TogglePrimitive.Props & VariantProps<typeof toggleVariants>) {
|
|
91
|
+
const context = React.useContext(ToggleGroupContext);
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<TogglePrimitive
|
|
95
|
+
data-slot="toggle-group-item"
|
|
96
|
+
data-variant={context.variant || variant}
|
|
97
|
+
data-size={context.size || size}
|
|
98
|
+
data-spacing={context.spacing}
|
|
99
|
+
className={cn(
|
|
100
|
+
"shrink-0 group-data-[spacing=0]/toggle-group:rounded-none group-data-[spacing=0]/toggle-group:px-2 focus:z-10 focus-visible:z-10 group-data-horizontal/toggle-group:data-[spacing=0]:first:rounded-l-md group-data-vertical/toggle-group:data-[spacing=0]:first:rounded-t-md group-data-horizontal/toggle-group:data-[spacing=0]:last:rounded-r-md group-data-vertical/toggle-group:data-[spacing=0]:last:rounded-b-md",
|
|
101
|
+
toggleVariants({
|
|
102
|
+
variant: context.variant || variant,
|
|
103
|
+
size: context.size || size,
|
|
104
|
+
}),
|
|
105
|
+
className,
|
|
106
|
+
)}
|
|
107
|
+
{...props}
|
|
108
|
+
>
|
|
109
|
+
{children}
|
|
110
|
+
</TogglePrimitive>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { ToggleGroup, ToggleGroupItem };
|