Skip to content

Commit 1d9a8fd

Browse files
property toggle group
1 parent 279c9e2 commit 1d9a8fd

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

Diff for: packages/editor-ui-property/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from "./property-input-checkbox";
66
export * from "./property-input-slider";
77
export * from "./property-input-color";
88
export * from "./property-input-select";
9+
export * from "./property-input-toggle-group";
910
export * from "./property-line";
1011
export * from "./property-lines";
1112
export * from "./layout";

Diff for: packages/editor-ui-property/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"@radix-ui/react-checkbox": "^1.0.4",
1515
"@radix-ui/react-icons": "^1.0.3",
1616
"@radix-ui/react-select": "^1.2.0",
17-
"@radix-ui/react-slider": "^0.0.11"
17+
"@radix-ui/react-slider": "^0.0.11",
18+
"@radix-ui/react-toggle-group": "^1.0.4"
1819
},
1920
"peerDependencies": {
2021
"@emotion/react": "^11.10.5",
@@ -26,6 +27,9 @@
2627
"@emotion/react": "^11.10.5",
2728
"@emotion/styled": "^11.10.5",
2829
"@types/react": "18.2.58",
29-
"react": "^18.2.0"
30+
"autoprefixer": "^10.0.1",
31+
"postcss": "^8",
32+
"react": "^18.2.0",
33+
"tailwindcss": "^3.3.0"
3034
}
3135
}

Diff for: packages/editor-ui-property/property-input-select/property-input-select.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface SelectInputProps {
1919
readonly?: boolean;
2020
disabled?: boolean;
2121

22-
onChange: (value: string) => void;
22+
onChange?: (value: string) => void;
2323
onClick?: () => void;
2424

2525
// aria
@@ -55,7 +55,7 @@ export function PropertySelectInput({
5555
<Select.Root
5656
onValueChange={(v) => {
5757
setValue(v);
58-
onChange(v);
58+
onChange?.(v);
5959
}}
6060
value={value}
6161
disabled={disabled}
@@ -70,7 +70,11 @@ export function PropertySelectInput({
7070
<ChevronDownIcon />
7171
</Select.Icon>
7272
</StyledTrigger>
73-
<Select.Portal>
73+
<Select.Portal
74+
style={{
75+
zIndex: 1000,
76+
}}
77+
>
7478
<SelectContent>
7579
<SelectScrollUpButton>
7680
<ChevronUpIcon />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./property-input-toggle-group";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from "react";
2+
import * as ToggleGroup from "@radix-ui/react-toggle-group";
3+
4+
export function PropertyInputToggleGroup({
5+
ariaLabel,
6+
defaultValue,
7+
value,
8+
options,
9+
onValueChange,
10+
}: {
11+
ariaLabel?: string;
12+
defaultValue?: string;
13+
value?: string;
14+
options?: {
15+
value: string;
16+
ariaLabel?: string;
17+
icon: React.ReactNode;
18+
}[];
19+
onValueChange?: (value: string) => void;
20+
}) {
21+
return (
22+
<ToggleGroup.Root
23+
className="flex gap-2"
24+
type="single"
25+
defaultValue={defaultValue}
26+
aria-label={ariaLabel}
27+
value={value}
28+
onValueChange={onValueChange}
29+
>
30+
{options?.map((option) => {
31+
return (
32+
<ToggleGroup.Item
33+
key={option.value}
34+
className="p-2 rounded-md data-[state='on']:bg-white/10"
35+
value={option.value}
36+
aria-label={option.ariaLabel}
37+
>
38+
{option.icon}
39+
</ToggleGroup.Item>
40+
);
41+
})}
42+
</ToggleGroup.Root>
43+
);
44+
}

0 commit comments

Comments
 (0)