@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,437 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { QuestionIcon } from "@phosphor-icons/react";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
FieldLabel,
|
|
7
|
+
PrimitiveArrowIcon,
|
|
8
|
+
ScrollFade,
|
|
9
|
+
Tooltip,
|
|
10
|
+
TooltipContent,
|
|
11
|
+
TooltipTrigger,
|
|
12
|
+
} from "../primitives";
|
|
13
|
+
import { cn } from "../../lib/utils";
|
|
14
|
+
|
|
15
|
+
type ControlFieldLabelActionContextValue = {
|
|
16
|
+
action: React.ReactNode;
|
|
17
|
+
label: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type ControlFieldLabelHelpContextValue = {
|
|
21
|
+
help: string;
|
|
22
|
+
label: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const ControlFieldLabelActionContext =
|
|
26
|
+
React.createContext<ControlFieldLabelActionContextValue | null>(null);
|
|
27
|
+
const ControlFieldLabelHelpContext =
|
|
28
|
+
React.createContext<ControlFieldLabelHelpContextValue | null>(null);
|
|
29
|
+
|
|
30
|
+
export const panelSectionSurfaceClassName = [
|
|
31
|
+
"flex flex-col pt-2 pb-6 first:border-t-0 data-[toolcraft-section-actions]:first:border-t",
|
|
32
|
+
"border-t border-[color:color-mix(in_oklab,var(--border)_8%,transparent)]",
|
|
33
|
+
"transition-colors duration-150 ease-out hover:bg-[color:color-mix(in_oklab,var(--foreground)_3%,transparent)]",
|
|
34
|
+
].join(" ");
|
|
35
|
+
|
|
36
|
+
export function ControlSection({
|
|
37
|
+
children,
|
|
38
|
+
className,
|
|
39
|
+
...props
|
|
40
|
+
}: React.HTMLAttributes<HTMLElement>): React.JSX.Element {
|
|
41
|
+
return (
|
|
42
|
+
<section
|
|
43
|
+
{...props}
|
|
44
|
+
className={cn(
|
|
45
|
+
panelSectionSurfaceClassName,
|
|
46
|
+
"group/control-section gap-[14px]",
|
|
47
|
+
className,
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</section>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function ControlList({
|
|
56
|
+
children,
|
|
57
|
+
className,
|
|
58
|
+
}: {
|
|
59
|
+
children: React.ReactNode;
|
|
60
|
+
className?: string;
|
|
61
|
+
}): React.JSX.Element {
|
|
62
|
+
return (
|
|
63
|
+
<div
|
|
64
|
+
className={cn("flex min-w-0 flex-col gap-[14px]", className)}
|
|
65
|
+
data-control-list=""
|
|
66
|
+
>
|
|
67
|
+
{children}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function ControlInlineGroup({
|
|
73
|
+
children,
|
|
74
|
+
className,
|
|
75
|
+
columns = 2,
|
|
76
|
+
kind = "default",
|
|
77
|
+
style,
|
|
78
|
+
...props
|
|
79
|
+
}: React.HTMLAttributes<HTMLDivElement> & {
|
|
80
|
+
columns?: number;
|
|
81
|
+
kind?: "default" | "slider" | "toggleParameter";
|
|
82
|
+
}): React.JSX.Element {
|
|
83
|
+
const gridTemplateColumns =
|
|
84
|
+
kind === "toggleParameter"
|
|
85
|
+
? "auto minmax(0, 1fr)"
|
|
86
|
+
: `repeat(${Math.max(1, Math.floor(columns))}, minmax(0, 1fr))`;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<div
|
|
90
|
+
{...props}
|
|
91
|
+
className={cn(
|
|
92
|
+
"grid min-w-0",
|
|
93
|
+
kind === "slider" ? "gap-4" : "gap-2",
|
|
94
|
+
kind === "toggleParameter" && "items-end",
|
|
95
|
+
className,
|
|
96
|
+
)}
|
|
97
|
+
data-control-layout="inline"
|
|
98
|
+
data-control-layout-columns={columns}
|
|
99
|
+
data-control-layout-group=""
|
|
100
|
+
data-control-layout-kind={kind}
|
|
101
|
+
style={{
|
|
102
|
+
...style,
|
|
103
|
+
gridTemplateColumns,
|
|
104
|
+
}}
|
|
105
|
+
>
|
|
106
|
+
{children}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function ControlSectionHeader({
|
|
112
|
+
action,
|
|
113
|
+
collapsed = false,
|
|
114
|
+
collapsible = false,
|
|
115
|
+
children,
|
|
116
|
+
onCollapsedChange,
|
|
117
|
+
}: {
|
|
118
|
+
action?: React.ReactNode;
|
|
119
|
+
collapsed?: boolean;
|
|
120
|
+
collapsible?: boolean;
|
|
121
|
+
children: React.ReactNode;
|
|
122
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
123
|
+
}): React.JSX.Element {
|
|
124
|
+
const titleText = getControlSectionHeaderText(children);
|
|
125
|
+
const collapseLabel = collapsed
|
|
126
|
+
? `Expand ${titleText} section`
|
|
127
|
+
: `Collapse ${titleText} section`;
|
|
128
|
+
const toggleCollapsed = React.useCallback(() => {
|
|
129
|
+
if (!collapsible) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
onCollapsedChange?.(!collapsed);
|
|
134
|
+
}, [collapsed, collapsible, onCollapsedChange]);
|
|
135
|
+
|
|
136
|
+
function handleKeyDown(event: React.KeyboardEvent<HTMLDivElement>): void {
|
|
137
|
+
if (!collapsible || (event.key !== "Enter" && event.key !== " ")) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
toggleCollapsed();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function stopHeaderToggle(event: React.SyntheticEvent): void {
|
|
146
|
+
event.stopPropagation();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div
|
|
151
|
+
aria-expanded={collapsible ? !collapsed : undefined}
|
|
152
|
+
aria-label={collapsible ? collapseLabel : undefined}
|
|
153
|
+
className={cn(
|
|
154
|
+
"flex h-9 min-w-0 items-center justify-between gap-2 px-3",
|
|
155
|
+
collapsible && "cursor-pointer select-none",
|
|
156
|
+
)}
|
|
157
|
+
data-collapsed={collapsible ? String(collapsed) : undefined}
|
|
158
|
+
data-collapsible={collapsible ? "" : undefined}
|
|
159
|
+
data-slot="control-section-header"
|
|
160
|
+
onClick={collapsible ? toggleCollapsed : undefined}
|
|
161
|
+
onKeyDown={handleKeyDown}
|
|
162
|
+
role={collapsible ? "button" : undefined}
|
|
163
|
+
tabIndex={collapsible ? 0 : undefined}
|
|
164
|
+
>
|
|
165
|
+
<div className="flex min-w-0 items-center gap-1 has-data-[icon-active=true]:[&_[data-slot=panel-title]]:text-[color:var(--link)]">
|
|
166
|
+
{children}
|
|
167
|
+
</div>
|
|
168
|
+
{action || collapsible ? (
|
|
169
|
+
<div
|
|
170
|
+
className="inline-flex shrink-0 items-center gap-1"
|
|
171
|
+
onClick={stopHeaderToggle}
|
|
172
|
+
onKeyDown={stopHeaderToggle}
|
|
173
|
+
onPointerDown={stopHeaderToggle}
|
|
174
|
+
>
|
|
175
|
+
{action}
|
|
176
|
+
{collapsible ? (
|
|
177
|
+
<Tooltip>
|
|
178
|
+
<TooltipTrigger
|
|
179
|
+
render={
|
|
180
|
+
<Button
|
|
181
|
+
aria-expanded={!collapsed}
|
|
182
|
+
aria-label={collapseLabel}
|
|
183
|
+
data-control-section-collapse-button=""
|
|
184
|
+
onClick={toggleCollapsed}
|
|
185
|
+
size="icon-sm"
|
|
186
|
+
type="button"
|
|
187
|
+
variant="ghost"
|
|
188
|
+
/>
|
|
189
|
+
}
|
|
190
|
+
>
|
|
191
|
+
<PrimitiveArrowIcon direction={collapsed ? "down" : "up"} />
|
|
192
|
+
</TooltipTrigger>
|
|
193
|
+
<TooltipContent side="top">{collapseLabel}</TooltipContent>
|
|
194
|
+
</Tooltip>
|
|
195
|
+
) : null}
|
|
196
|
+
</div>
|
|
197
|
+
) : null}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function getControlSectionHeaderText(children: React.ReactNode): string {
|
|
203
|
+
const text = getReactNodeText(children).trim();
|
|
204
|
+
|
|
205
|
+
return text.length > 0 ? text : "section";
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function getReactNodeText(node: React.ReactNode): string {
|
|
209
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
210
|
+
return String(node);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!React.isValidElement<{ children?: React.ReactNode }>(node)) {
|
|
214
|
+
if (Array.isArray(node)) {
|
|
215
|
+
return node.map(getReactNodeText).join("");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return "";
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return getReactNodeText(node.props.children);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function ControlItem({
|
|
225
|
+
allowCompoundDividers = false,
|
|
226
|
+
children,
|
|
227
|
+
compoundDividerPlacement = "both",
|
|
228
|
+
flush = false,
|
|
229
|
+
}: {
|
|
230
|
+
allowCompoundDividers?: boolean;
|
|
231
|
+
children: React.ReactNode;
|
|
232
|
+
compoundDividerPlacement?: "both" | "bottom";
|
|
233
|
+
flush?: boolean;
|
|
234
|
+
}): React.JSX.Element {
|
|
235
|
+
const showCompoundTopDivider = compoundDividerPlacement === "both";
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<div
|
|
239
|
+
className={cn(
|
|
240
|
+
"min-w-0",
|
|
241
|
+
!flush && "px-3",
|
|
242
|
+
allowCompoundDividers &&
|
|
243
|
+
"has-data-[control-section-divider=compound]:relative has-data-[control-section-divider=compound]:pb-[18px] has-data-[control-section-divider=compound]:after:absolute has-data-[control-section-divider=compound]:after:bottom-0 has-data-[control-section-divider=compound]:after:h-px has-data-[control-section-divider=compound]:after:bg-[color:color-mix(in_oklab,var(--border)_8%,transparent)]",
|
|
244
|
+
allowCompoundDividers &&
|
|
245
|
+
showCompoundTopDivider &&
|
|
246
|
+
"has-data-[control-section-divider=compound]:pt-[18px] has-data-[control-section-divider=compound]:before:absolute has-data-[control-section-divider=compound]:before:top-0 has-data-[control-section-divider=compound]:before:h-px has-data-[control-section-divider=compound]:before:bg-[color:color-mix(in_oklab,var(--border)_8%,transparent)]",
|
|
247
|
+
allowCompoundDividers &&
|
|
248
|
+
(flush
|
|
249
|
+
? "has-data-[control-section-divider=compound]:after:inset-x-0"
|
|
250
|
+
: "has-data-[control-section-divider=compound]:after:inset-x-3"),
|
|
251
|
+
allowCompoundDividers &&
|
|
252
|
+
showCompoundTopDivider &&
|
|
253
|
+
(flush
|
|
254
|
+
? "has-data-[control-section-divider=compound]:before:inset-x-0"
|
|
255
|
+
: "has-data-[control-section-divider=compound]:before:inset-x-3"),
|
|
256
|
+
)}
|
|
257
|
+
data-control-item-compound-divider-placement={
|
|
258
|
+
allowCompoundDividers ? compoundDividerPlacement : undefined
|
|
259
|
+
}
|
|
260
|
+
data-control-item-compound-context={allowCompoundDividers ? "" : undefined}
|
|
261
|
+
>
|
|
262
|
+
{children}
|
|
263
|
+
</div>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function PanelTitle({
|
|
268
|
+
children,
|
|
269
|
+
}: {
|
|
270
|
+
children: React.ReactNode;
|
|
271
|
+
}): React.JSX.Element {
|
|
272
|
+
return (
|
|
273
|
+
<p
|
|
274
|
+
className="m-0 text-2xs leading-none font-semibold text-[color:color-mix(in_oklab,var(--foreground)_75%,transparent)] uppercase transition-colors duration-150 ease-out"
|
|
275
|
+
data-slot="panel-title"
|
|
276
|
+
>
|
|
277
|
+
{children}
|
|
278
|
+
</p>
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type ControlFieldLabelProps = React.ComponentProps<typeof FieldLabel> & {
|
|
283
|
+
textClassName?: string;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export function ControlFieldLabelActionProvider({
|
|
287
|
+
action,
|
|
288
|
+
children,
|
|
289
|
+
label,
|
|
290
|
+
}: ControlFieldLabelActionContextValue & {
|
|
291
|
+
children: React.ReactNode;
|
|
292
|
+
}): React.JSX.Element {
|
|
293
|
+
return (
|
|
294
|
+
<ControlFieldLabelActionContext.Provider value={{ action, label }}>
|
|
295
|
+
{children}
|
|
296
|
+
</ControlFieldLabelActionContext.Provider>
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function ControlFieldLabelHelpProvider({
|
|
301
|
+
children,
|
|
302
|
+
help,
|
|
303
|
+
label,
|
|
304
|
+
}: ControlFieldLabelHelpContextValue & {
|
|
305
|
+
children: React.ReactNode;
|
|
306
|
+
}): React.JSX.Element {
|
|
307
|
+
return (
|
|
308
|
+
<ControlFieldLabelHelpContext.Provider value={{ help, label }}>
|
|
309
|
+
{children}
|
|
310
|
+
</ControlFieldLabelHelpContext.Provider>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export function useControlFieldLabelAction(
|
|
315
|
+
label: string | undefined,
|
|
316
|
+
): React.ReactNode {
|
|
317
|
+
const context = React.useContext(ControlFieldLabelActionContext);
|
|
318
|
+
|
|
319
|
+
return context && context.label === label ? context.action : null;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export function useControlFieldLabelHelp(
|
|
323
|
+
label: string | undefined,
|
|
324
|
+
): string | null {
|
|
325
|
+
const context = React.useContext(ControlFieldLabelHelpContext);
|
|
326
|
+
|
|
327
|
+
return context && context.label === label ? context.help : null;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function ControlFieldLabel({
|
|
331
|
+
children,
|
|
332
|
+
className,
|
|
333
|
+
textClassName,
|
|
334
|
+
title: titleProp,
|
|
335
|
+
...props
|
|
336
|
+
}: ControlFieldLabelProps): React.JSX.Element {
|
|
337
|
+
const title = getControlFieldLabelTitle(children);
|
|
338
|
+
const displayChildren = getControlFieldLabelDisplayChildren(children, title);
|
|
339
|
+
const labelAction = useControlFieldLabelAction(title);
|
|
340
|
+
const labelHelp = useControlFieldLabelHelp(title);
|
|
341
|
+
|
|
342
|
+
return (
|
|
343
|
+
<span
|
|
344
|
+
className={cn(
|
|
345
|
+
"group/keyframe-control-label inline-flex min-w-0 max-w-full items-center gap-0 has-data-[icon-active=true]:[&_[data-slot=template-field-label-text]]:text-[color:var(--link)] has-data-[icon-active=true]:[&_[data-slot=template-field-label-text]]:opacity-100",
|
|
346
|
+
className,
|
|
347
|
+
)}
|
|
348
|
+
data-control-field-label=""
|
|
349
|
+
data-slot="field-label"
|
|
350
|
+
>
|
|
351
|
+
<FieldLabel
|
|
352
|
+
className="min-w-0 max-w-full gap-0"
|
|
353
|
+
title={titleProp ?? title}
|
|
354
|
+
{...props}
|
|
355
|
+
>
|
|
356
|
+
<ScrollFade
|
|
357
|
+
className="no-scrollbar min-w-0 max-w-full"
|
|
358
|
+
containerClassName="min-w-0 max-w-full"
|
|
359
|
+
preset="compact"
|
|
360
|
+
side="right"
|
|
361
|
+
watch={[title ?? ""]}
|
|
362
|
+
>
|
|
363
|
+
<span
|
|
364
|
+
className={cn(
|
|
365
|
+
"block whitespace-nowrap opacity-60",
|
|
366
|
+
textClassName,
|
|
367
|
+
"min-w-max",
|
|
368
|
+
)}
|
|
369
|
+
data-slot="template-field-label-text"
|
|
370
|
+
title={title}
|
|
371
|
+
>
|
|
372
|
+
{displayChildren}
|
|
373
|
+
</span>
|
|
374
|
+
</ScrollFade>
|
|
375
|
+
</FieldLabel>
|
|
376
|
+
{labelHelp ? (
|
|
377
|
+
<Tooltip>
|
|
378
|
+
<TooltipTrigger
|
|
379
|
+
render={
|
|
380
|
+
<button
|
|
381
|
+
aria-label={`${title ?? "Control"} help`}
|
|
382
|
+
className="ml-[3px] inline-flex size-3.5 shrink-0 items-center justify-center rounded-full text-[color:color-mix(in_oklab,var(--foreground)_40%,transparent)] transition-colors duration-150 ease-out hover:text-[color:color-mix(in_oklab,var(--foreground)_60%,transparent)] focus-visible:outline-none"
|
|
383
|
+
data-control-field-help=""
|
|
384
|
+
type="button"
|
|
385
|
+
/>
|
|
386
|
+
}
|
|
387
|
+
>
|
|
388
|
+
<QuestionIcon className="size-3.5" weight="fill" />
|
|
389
|
+
</TooltipTrigger>
|
|
390
|
+
<TooltipContent className="max-w-[240px] whitespace-normal text-left" side="top">
|
|
391
|
+
{labelHelp}
|
|
392
|
+
</TooltipContent>
|
|
393
|
+
</Tooltip>
|
|
394
|
+
) : null}
|
|
395
|
+
{labelAction}
|
|
396
|
+
</span>
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function getControlFieldLabelTitle(
|
|
401
|
+
children: React.ReactNode,
|
|
402
|
+
): string | undefined {
|
|
403
|
+
const textParts = React.Children.toArray(children).map((child) => {
|
|
404
|
+
if (typeof child === "string" || typeof child === "number") {
|
|
405
|
+
return String(child);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return null;
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
if (!textParts.length || textParts.some((part) => part === null)) {
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const title = textParts.join("").trim();
|
|
416
|
+
|
|
417
|
+
return title || undefined;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function getControlFieldLabelDisplayChildren(
|
|
421
|
+
children: React.ReactNode,
|
|
422
|
+
title: string | undefined,
|
|
423
|
+
): React.ReactNode {
|
|
424
|
+
if (!title || React.Children.count(children) !== 1) {
|
|
425
|
+
return children;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const [child] = React.Children.toArray(children);
|
|
429
|
+
|
|
430
|
+
if (typeof child !== "string" && typeof child !== "number") {
|
|
431
|
+
return children;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const displayTitle = title.replace(/\s+\([^)]{1,80}\)\s*$/u, "").trim();
|
|
435
|
+
|
|
436
|
+
return displayTitle || title;
|
|
437
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { ReactElement, ReactNode } from "react";
|
|
4
|
+
import {
|
|
5
|
+
ArrowCounterClockwiseIcon,
|
|
6
|
+
CheckIcon,
|
|
7
|
+
CopySimpleIcon,
|
|
8
|
+
DownloadSimpleIcon,
|
|
9
|
+
EraserIcon,
|
|
10
|
+
ExportIcon,
|
|
11
|
+
MagicWandIcon,
|
|
12
|
+
ShuffleIcon,
|
|
13
|
+
} from "@phosphor-icons/react";
|
|
14
|
+
|
|
15
|
+
import { Button, Field } from "../../primitives";
|
|
16
|
+
import { ControlFieldLabel } from "../../control-layout";
|
|
17
|
+
import { cn } from "../../../lib/utils";
|
|
18
|
+
|
|
19
|
+
export type ActionControlIconName =
|
|
20
|
+
| "check"
|
|
21
|
+
| "copy"
|
|
22
|
+
| "download"
|
|
23
|
+
| "download-simple"
|
|
24
|
+
| "eraser"
|
|
25
|
+
| "export"
|
|
26
|
+
| "rotate-ccw"
|
|
27
|
+
| "shuffle"
|
|
28
|
+
| "wand-sparkles";
|
|
29
|
+
|
|
30
|
+
const actionIconComponents = {
|
|
31
|
+
check: CheckIcon,
|
|
32
|
+
copy: CopySimpleIcon,
|
|
33
|
+
download: DownloadSimpleIcon,
|
|
34
|
+
"download-simple": DownloadSimpleIcon,
|
|
35
|
+
eraser: EraserIcon,
|
|
36
|
+
export: ExportIcon,
|
|
37
|
+
"rotate-ccw": ArrowCounterClockwiseIcon,
|
|
38
|
+
shuffle: ShuffleIcon,
|
|
39
|
+
"wand-sparkles": MagicWandIcon,
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
export type ActionControlObjectOption = {
|
|
43
|
+
children?: ReactNode;
|
|
44
|
+
label?: string;
|
|
45
|
+
value: string;
|
|
46
|
+
icon?: ActionControlIconName | ReactElement;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type ActionControlOption = string | ActionControlObjectOption;
|
|
50
|
+
|
|
51
|
+
function getActionValue(action: ActionControlOption): string {
|
|
52
|
+
return typeof action === "string" ? action : action.value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getActionContent(action: ActionControlOption): ReactNode {
|
|
56
|
+
if (typeof action === "string") {
|
|
57
|
+
return action;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return action.children ?? action.label ?? action.value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function getActionIcon(action: ActionControlOption): ReactNode {
|
|
64
|
+
if (typeof action === "string" || action.icon == null) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof action.icon !== "string") {
|
|
69
|
+
return action.icon;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const Icon = actionIconComponents[action.icon];
|
|
73
|
+
|
|
74
|
+
return <Icon data-icon="inline-start" />;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function getActionAriaLabel(
|
|
78
|
+
action: ActionControlOption,
|
|
79
|
+
content: ReactNode,
|
|
80
|
+
): string | undefined {
|
|
81
|
+
if (typeof content === "string") {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return typeof action === "string" ? action : (action.label ?? action.value);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export type ActionsControlProps = {
|
|
89
|
+
actions: readonly ActionControlOption[];
|
|
90
|
+
name: string;
|
|
91
|
+
onAction?: (value: string) => void;
|
|
92
|
+
showLabel?: boolean;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export function ActionsControl({
|
|
96
|
+
actions,
|
|
97
|
+
name,
|
|
98
|
+
onAction,
|
|
99
|
+
showLabel = true,
|
|
100
|
+
}: ActionsControlProps): React.JSX.Element {
|
|
101
|
+
return (
|
|
102
|
+
<Field
|
|
103
|
+
aria-label={showLabel ? undefined : name}
|
|
104
|
+
className="h-fit min-w-0 flex-wrap items-center justify-between gap-y-2!"
|
|
105
|
+
orientation="horizontal"
|
|
106
|
+
>
|
|
107
|
+
{showLabel ? (
|
|
108
|
+
<ControlFieldLabel className="min-w-0" textClassName="min-w-0 truncate">
|
|
109
|
+
{name}
|
|
110
|
+
</ControlFieldLabel>
|
|
111
|
+
) : null}
|
|
112
|
+
<div
|
|
113
|
+
className={cn(
|
|
114
|
+
"flex max-w-full shrink-0 flex-wrap items-center justify-start gap-1.5",
|
|
115
|
+
showLabel && "ml-auto",
|
|
116
|
+
)}
|
|
117
|
+
>
|
|
118
|
+
{actions.map((action) => {
|
|
119
|
+
const actionContent = getActionContent(action);
|
|
120
|
+
const actionValue = getActionValue(action);
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<Button
|
|
124
|
+
aria-label={getActionAriaLabel(action, actionContent)}
|
|
125
|
+
key={actionValue}
|
|
126
|
+
onClick={() => onAction?.(actionValue)}
|
|
127
|
+
size="sm"
|
|
128
|
+
type="button"
|
|
129
|
+
variant="outline"
|
|
130
|
+
>
|
|
131
|
+
{getActionIcon(action)}
|
|
132
|
+
{actionContent}
|
|
133
|
+
</Button>
|
|
134
|
+
);
|
|
135
|
+
})}
|
|
136
|
+
</div>
|
|
137
|
+
</Field>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { Button, Field } from "../../primitives";
|
|
6
|
+
import { ControlFieldLabel } from "../../control-layout";
|
|
7
|
+
import {
|
|
8
|
+
hoverImportantSelectedItemBorderClassName,
|
|
9
|
+
hoverImportantSelectedItemSurfaceClassName,
|
|
10
|
+
importantSelectedItemBorderClassName,
|
|
11
|
+
importantSelectedItemSurfaceClassName,
|
|
12
|
+
} from "../../primitives/selection-state";
|
|
13
|
+
import { cn } from "../../../lib/utils";
|
|
14
|
+
|
|
15
|
+
export type AnchorGridValue =
|
|
16
|
+
| "bottom-center"
|
|
17
|
+
| "bottom-left"
|
|
18
|
+
| "bottom-right"
|
|
19
|
+
| "center"
|
|
20
|
+
| "center-left"
|
|
21
|
+
| "center-right"
|
|
22
|
+
| "top-center"
|
|
23
|
+
| "top-left"
|
|
24
|
+
| "top-right";
|
|
25
|
+
|
|
26
|
+
export type AnchorGridControlProps = {
|
|
27
|
+
name: string;
|
|
28
|
+
onValueChange?: (value: AnchorGridValue) => void;
|
|
29
|
+
value?: AnchorGridValue;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const anchorOptions = [
|
|
33
|
+
"top-left",
|
|
34
|
+
"top-center",
|
|
35
|
+
"top-right",
|
|
36
|
+
"center-left",
|
|
37
|
+
"center",
|
|
38
|
+
"center-right",
|
|
39
|
+
"bottom-left",
|
|
40
|
+
"bottom-center",
|
|
41
|
+
"bottom-right",
|
|
42
|
+
] as const satisfies readonly AnchorGridValue[];
|
|
43
|
+
|
|
44
|
+
const anchorLabels = {
|
|
45
|
+
"bottom-center": "Bottom Center",
|
|
46
|
+
"bottom-left": "Bottom Left",
|
|
47
|
+
"bottom-right": "Bottom Right",
|
|
48
|
+
center: "Center",
|
|
49
|
+
"center-left": "Center Left",
|
|
50
|
+
"center-right": "Center Right",
|
|
51
|
+
"top-center": "Top Center",
|
|
52
|
+
"top-left": "Top Left",
|
|
53
|
+
"top-right": "Top Right",
|
|
54
|
+
} as const satisfies Record<AnchorGridValue, string>;
|
|
55
|
+
|
|
56
|
+
export function AnchorGridControl({
|
|
57
|
+
name,
|
|
58
|
+
onValueChange,
|
|
59
|
+
value = "center",
|
|
60
|
+
}: AnchorGridControlProps): React.JSX.Element {
|
|
61
|
+
const [currentValue, setCurrentValue] = React.useState(value);
|
|
62
|
+
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
setCurrentValue(value);
|
|
65
|
+
}, [value]);
|
|
66
|
+
|
|
67
|
+
function updateValue(nextValue: AnchorGridValue): void {
|
|
68
|
+
setCurrentValue(nextValue);
|
|
69
|
+
onValueChange?.(nextValue);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<Field className="min-w-0 !gap-2">
|
|
74
|
+
<ControlFieldLabel>{name}</ControlFieldLabel>
|
|
75
|
+
<div className="grid w-full grid-cols-3 gap-1.5">
|
|
76
|
+
{anchorOptions.map((option) => (
|
|
77
|
+
<Button
|
|
78
|
+
aria-label={anchorLabels[option]}
|
|
79
|
+
aria-pressed={currentValue === option}
|
|
80
|
+
className={cn(
|
|
81
|
+
"h-9 w-full rounded-lg !bg-[color:color-mix(in_oklab,var(--input)_5%,transparent)] px-0 transition-[background-color,border-color,box-shadow,transform] duration-150 ease-out hover:!bg-[color:color-mix(in_oklab,var(--input)_5%,transparent)] active:scale-[0.98] active:!bg-[color:color-mix(in_oklab,var(--input)_10%,transparent)]",
|
|
82
|
+
currentValue === option && [
|
|
83
|
+
importantSelectedItemBorderClassName,
|
|
84
|
+
importantSelectedItemSurfaceClassName,
|
|
85
|
+
hoverImportantSelectedItemBorderClassName,
|
|
86
|
+
hoverImportantSelectedItemSurfaceClassName,
|
|
87
|
+
],
|
|
88
|
+
)}
|
|
89
|
+
key={option}
|
|
90
|
+
onClick={() => updateValue(option)}
|
|
91
|
+
type="button"
|
|
92
|
+
variant="outline"
|
|
93
|
+
>
|
|
94
|
+
<span
|
|
95
|
+
aria-hidden="true"
|
|
96
|
+
className={cn(
|
|
97
|
+
"pointer-events-none inline-flex size-2 rounded-full bg-[color:color-mix(in_oklab,var(--foreground)_18%,transparent)] transition-[background-color,border-color,box-shadow,transform] duration-150 ease-out",
|
|
98
|
+
currentValue === option &&
|
|
99
|
+
"scale-110 bg-[color:var(--foreground)]",
|
|
100
|
+
)}
|
|
101
|
+
/>
|
|
102
|
+
</Button>
|
|
103
|
+
))}
|
|
104
|
+
</div>
|
|
105
|
+
</Field>
|
|
106
|
+
);
|
|
107
|
+
}
|