@webstudio-is/sdk-components-react-radix 0.87.1 → 0.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/__generated__/accordion.props.js +605 -114
- package/lib/__generated__/button.props.js +158 -47
- package/lib/__generated__/checkbox.props.js +1083 -0
- package/lib/__generated__/collapsible.props.js +234 -44
- package/lib/__generated__/dialog.props.js +611 -121
- package/lib/__generated__/input.props.js +264 -47
- package/lib/__generated__/label.props.js +123 -23
- package/lib/__generated__/navigation-menu.props.js +2565 -0
- package/lib/__generated__/popover.props.js +129 -28
- package/lib/__generated__/radio-group.props.js +1627 -0
- package/lib/__generated__/select.props.js +3678 -0
- package/lib/__generated__/sheet.props.js +591 -121
- package/lib/__generated__/switch.props.js +1083 -0
- package/lib/__generated__/tabs.props.js +906 -68
- package/lib/__generated__/textarea.props.js +177 -31
- package/lib/__generated__/tooltip.props.js +131 -29
- package/lib/accordion.js +11 -4
- package/lib/accordion.ws.js +88 -72
- package/lib/checkbox.js +13 -0
- package/lib/checkbox.ws.js +153 -0
- package/lib/cjs/__generated__/accordion.props.js +605 -114
- package/lib/cjs/__generated__/button.props.js +158 -47
- package/lib/cjs/__generated__/checkbox.props.js +1103 -0
- package/lib/cjs/__generated__/collapsible.props.js +234 -44
- package/lib/cjs/__generated__/dialog.props.js +611 -121
- package/lib/cjs/__generated__/input.props.js +264 -47
- package/lib/cjs/__generated__/label.props.js +123 -23
- package/lib/cjs/__generated__/navigation-menu.props.js +2585 -0
- package/lib/cjs/__generated__/popover.props.js +129 -28
- package/lib/cjs/__generated__/radio-group.props.js +1647 -0
- package/lib/cjs/__generated__/select.props.js +3698 -0
- package/lib/cjs/__generated__/sheet.props.js +591 -121
- package/lib/cjs/__generated__/switch.props.js +1103 -0
- package/lib/cjs/__generated__/tabs.props.js +906 -68
- package/lib/cjs/__generated__/textarea.props.js +177 -31
- package/lib/cjs/__generated__/tooltip.props.js +131 -29
- package/lib/cjs/accordion.js +11 -4
- package/lib/cjs/accordion.ws.js +86 -71
- package/lib/cjs/{textarea.js → checkbox.js} +9 -6
- package/lib/cjs/checkbox.ws.js +174 -0
- package/lib/cjs/collapsible.ws.js +5 -1
- package/lib/cjs/components.js +27 -14
- package/lib/cjs/dialog.ws.js +18 -17
- package/lib/cjs/hooks.js +5 -1
- package/lib/cjs/label.ws.js +2 -1
- package/lib/cjs/metas.js +29 -14
- package/lib/cjs/navigation-menu.js +107 -0
- package/lib/cjs/navigation-menu.ws.js +514 -0
- package/lib/cjs/popover.ws.js +13 -9
- package/lib/cjs/props-descriptions.js +56 -0
- package/lib/cjs/props.js +27 -14
- package/lib/cjs/{button.js → radio-group.js} +10 -8
- package/lib/cjs/radio-group.ws.js +191 -0
- package/lib/cjs/select.js +83 -0
- package/lib/cjs/select.ws.js +350 -0
- package/lib/cjs/sheet.ws.js +88 -176
- package/lib/cjs/{input.js → switch.js} +8 -9
- package/lib/cjs/switch.ws.js +173 -0
- package/lib/cjs/tabs.js +2 -3
- package/lib/cjs/tabs.ws.js +14 -18
- package/lib/cjs/theme/styles.js +100 -0
- package/lib/cjs/theme/tailwind-classes.js +125 -16
- package/lib/cjs/theme/tailwind-colors.js +1 -0
- package/lib/cjs/tooltip.ws.js +12 -8
- package/lib/collapsible.ws.js +5 -1
- package/lib/components.js +44 -22
- package/lib/dialog.ws.js +18 -17
- package/lib/hooks.js +5 -1
- package/lib/label.ws.js +2 -1
- package/lib/metas.js +58 -24
- package/lib/navigation-menu.js +85 -0
- package/lib/navigation-menu.ws.js +501 -0
- package/lib/popover.ws.js +13 -9
- package/lib/props-descriptions.js +36 -0
- package/lib/props.js +56 -24
- package/lib/radio-group.js +11 -0
- package/lib/radio-group.ws.js +173 -0
- package/lib/select.js +75 -0
- package/lib/select.ws.js +338 -0
- package/lib/sheet.ws.js +89 -194
- package/lib/switch.js +7 -0
- package/lib/switch.ws.js +145 -0
- package/lib/tabs.js +3 -5
- package/lib/tabs.ws.js +15 -19
- package/lib/theme/styles.js +70 -0
- package/lib/theme/tailwind-classes.js +125 -16
- package/lib/theme/tailwind-colors.js +1 -0
- package/lib/tooltip.ws.js +12 -8
- package/lib/types/__generated__/checkbox.props.d.ts +3 -0
- package/lib/types/__generated__/navigation-menu.props.d.ts +8 -0
- package/lib/types/__generated__/radio-group.props.d.ts +4 -0
- package/lib/types/__generated__/select.props.d.ts +9 -0
- package/lib/types/__generated__/switch.props.d.ts +3 -0
- package/lib/types/checkbox.d.ts +6 -0
- package/lib/types/checkbox.stories.d.ts +11 -0
- package/lib/types/checkbox.ws.d.ts +5 -0
- package/lib/types/components.d.ts +5 -4
- package/lib/types/metas.d.ts +6 -4
- package/lib/types/navigation-menu.d.ts +15 -0
- package/lib/types/navigation-menu.ws.d.ts +15 -0
- package/lib/types/props-descriptions.d.ts +29 -0
- package/lib/types/props.d.ts +5 -4
- package/lib/types/radio-group.d.ts +5 -0
- package/lib/types/radio-group.stories.d.ts +9 -0
- package/lib/types/radio-group.ws.d.ts +7 -0
- package/lib/types/select.d.ts +14 -0
- package/lib/types/select.ws.d.ts +17 -0
- package/lib/types/sheet.ws.d.ts +2 -15
- package/lib/types/switch.d.ts +4 -0
- package/lib/types/switch.stories.d.ts +9 -0
- package/lib/types/switch.ws.d.ts +5 -0
- package/lib/types/tabs.d.ts +3 -12
- package/lib/types/theme/radix-common-types.d.ts +3 -2
- package/lib/types/theme/styles.d.ts +215 -0
- package/lib/types/theme/tailwind-classes.d.ts +16 -6
- package/lib/types/theme/tailwind-colors.d.ts +1 -0
- package/lib/types/theme/tailwind-theme.d.ts +1 -1
- package/package.json +12 -7
- package/src/__generated__/accordion.props.ts +675 -108
- package/src/__generated__/button.props.ts +177 -45
- package/src/__generated__/checkbox.props.ts +1217 -0
- package/src/__generated__/collapsible.props.ts +261 -42
- package/src/__generated__/dialog.props.ts +682 -115
- package/src/__generated__/input.props.ts +292 -44
- package/src/__generated__/label.props.ts +137 -22
- package/src/__generated__/navigation-menu.props.ts +2882 -0
- package/src/__generated__/popover.props.ts +142 -24
- package/src/__generated__/radio-group.props.ts +1828 -0
- package/src/__generated__/select.props.ts +4130 -0
- package/src/__generated__/sheet.props.ts +657 -110
- package/src/__generated__/switch.props.ts +1217 -0
- package/src/__generated__/tabs.props.ts +1019 -67
- package/src/__generated__/textarea.props.ts +195 -30
- package/src/__generated__/tooltip.props.ts +145 -25
- package/src/accordion.tsx +14 -7
- package/src/accordion.ws.ts +87 -70
- package/src/{textarea.stories.ts → checkbox.stories.ts} +6 -11
- package/src/checkbox.tsx +22 -0
- package/src/checkbox.ws.ts +154 -0
- package/src/collapsible.ws.ts +6 -1
- package/src/components.ts +25 -12
- package/src/dialog.ws.tsx +17 -16
- package/src/hooks.ts +4 -0
- package/src/label.ws.ts +3 -1
- package/src/metas.ts +36 -12
- package/src/navigation-menu.stories.tsx +21 -0
- package/src/navigation-menu.tsx +130 -0
- package/src/navigation-menu.ws.ts +524 -0
- package/src/popover.ws.tsx +13 -9
- package/src/props-descriptions.ts +43 -0
- package/src/props.ts +35 -12
- package/src/{input.stories.ts → radio-group.stories.ts} +6 -15
- package/src/radio-group.tsx +17 -0
- package/src/radio-group.ws.ts +178 -0
- package/src/select.stories.tsx +21 -0
- package/src/select.tsx +112 -0
- package/src/select.ws.ts +349 -0
- package/src/sheet.ws.tsx +91 -209
- package/src/{button.stories.ts → switch.stories.ts} +6 -19
- package/src/switch.tsx +10 -0
- package/src/switch.ws.ts +146 -0
- package/src/tabs.tsx +4 -17
- package/src/tabs.ws.ts +19 -19
- package/src/theme/radix-common-types.ts +3 -2
- package/src/theme/styles.ts +80 -0
- package/src/theme/tailwind-classes.ts +150 -14
- package/src/theme/tailwind-colors.ts +1 -0
- package/src/tooltip.ws.tsx +13 -8
- package/lib/button.js +0 -8
- package/lib/button.ws.js +0 -133
- package/lib/cjs/button.ws.js +0 -160
- package/lib/cjs/input.ws.js +0 -103
- package/lib/cjs/textarea.ws.js +0 -98
- package/lib/input.js +0 -8
- package/lib/input.ws.js +0 -75
- package/lib/textarea.js +0 -8
- package/lib/textarea.ws.js +0 -70
- package/lib/types/button.d.ts +0 -7
- package/lib/types/button.stories.d.ts +0 -20
- package/lib/types/button.ws.d.ts +0 -7
- package/lib/types/input.d.ts +0 -2
- package/lib/types/input.stories.d.ts +0 -20
- package/lib/types/input.ws.d.ts +0 -3
- package/lib/types/textarea.d.ts +0 -2
- package/lib/types/textarea.stories.d.ts +0 -14
- package/lib/types/textarea.ws.d.ts +0 -3
- package/src/button.tsx +0 -25
- package/src/button.ws.ts +0 -155
- package/src/input.tsx +0 -12
- package/src/input.ws.ts +0 -78
- package/src/textarea.tsx +0 -12
- package/src/textarea.ws.ts +0 -74
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
2
|
import { renderComponentTemplate } from "@webstudio-is/react-sdk";
|
|
3
|
-
import { Input as InputPrimitive } from "./input";
|
|
4
3
|
import * as baseComponents from "@webstudio-is/sdk-components-react";
|
|
5
4
|
import * as baseMetas from "@webstudio-is/sdk-components-react/metas";
|
|
6
5
|
import * as radixComponents from "./components";
|
|
7
6
|
import * as radixMetas from "./metas";
|
|
7
|
+
import { RadioGroup as RadioGroupPrimitive } from "./radio-group";
|
|
8
8
|
|
|
9
9
|
export default {
|
|
10
|
-
title: "Components/
|
|
11
|
-
component:
|
|
12
|
-
|
|
13
|
-
placeholder: {
|
|
14
|
-
type: "string",
|
|
15
|
-
},
|
|
16
|
-
type: {
|
|
17
|
-
options: ["text", "file"],
|
|
18
|
-
control: { type: "select" },
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
} satisfies Meta<typeof InputPrimitive>;
|
|
10
|
+
title: "Components/RadioGroup",
|
|
11
|
+
component: RadioGroupPrimitive,
|
|
12
|
+
} satisfies Meta<typeof RadioGroupPrimitive>;
|
|
22
13
|
|
|
23
|
-
export const
|
|
14
|
+
export const RadioGroup: StoryObj<typeof RadioGroupPrimitive> = {
|
|
24
15
|
render: (props) =>
|
|
25
16
|
renderComponentTemplate({
|
|
26
|
-
name: "
|
|
17
|
+
name: "RadioGroup",
|
|
27
18
|
props: { ...props },
|
|
28
19
|
components: { ...baseComponents, ...radixComponents },
|
|
29
20
|
metas: { ...baseMetas, ...radixMetas },
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ForwardRefExoticComponent,
|
|
3
|
+
type ComponentPropsWithRef,
|
|
4
|
+
} from "react";
|
|
5
|
+
import { Root, Item, Indicator } from "@radix-ui/react-radio-group";
|
|
6
|
+
|
|
7
|
+
export const RadioGroup: ForwardRefExoticComponent<
|
|
8
|
+
ComponentPropsWithRef<typeof Root>
|
|
9
|
+
> = Root;
|
|
10
|
+
|
|
11
|
+
export const RadioGroupItem: ForwardRefExoticComponent<
|
|
12
|
+
ComponentPropsWithRef<typeof Item>
|
|
13
|
+
> = Item;
|
|
14
|
+
|
|
15
|
+
export const RadioGroupIndicator: ForwardRefExoticComponent<
|
|
16
|
+
ComponentPropsWithRef<typeof Indicator>
|
|
17
|
+
> = Indicator;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ItemIcon,
|
|
3
|
+
RadioCheckedIcon,
|
|
4
|
+
RadioDotIcon,
|
|
5
|
+
TriggerIcon,
|
|
6
|
+
} from "@webstudio-is/icons/svg";
|
|
7
|
+
import {
|
|
8
|
+
defaultStates,
|
|
9
|
+
WsEmbedTemplate,
|
|
10
|
+
type WsComponentMeta,
|
|
11
|
+
type WsComponentPropsMeta,
|
|
12
|
+
} from "@webstudio-is/react-sdk";
|
|
13
|
+
import { button, div, span } from "@webstudio-is/react-sdk/css-normalize";
|
|
14
|
+
import * as tc from "./theme/tailwind-classes";
|
|
15
|
+
import { buttonReset } from "./theme/styles";
|
|
16
|
+
import {
|
|
17
|
+
propsRadioGroup,
|
|
18
|
+
propsRadioGroupIndicator,
|
|
19
|
+
propsRadioGroupItem,
|
|
20
|
+
} from "./__generated__/radio-group.props";
|
|
21
|
+
|
|
22
|
+
const createRadioGroupItem = ({
|
|
23
|
+
value,
|
|
24
|
+
label,
|
|
25
|
+
}: {
|
|
26
|
+
value: string;
|
|
27
|
+
label: string;
|
|
28
|
+
}): WsEmbedTemplate[number] => ({
|
|
29
|
+
type: "instance",
|
|
30
|
+
component: "Label",
|
|
31
|
+
// flex items-center space-x-2
|
|
32
|
+
styles: [tc.flex(), tc.items("center"), tc.gap(2)].flat(),
|
|
33
|
+
children: [
|
|
34
|
+
{
|
|
35
|
+
type: "instance",
|
|
36
|
+
component: "RadioGroupItem",
|
|
37
|
+
props: [{ name: "value", type: "string", value }],
|
|
38
|
+
// aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background
|
|
39
|
+
// focus:outline-none
|
|
40
|
+
// focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2
|
|
41
|
+
// disabled:cursor-not-allowed disabled:opacity-50
|
|
42
|
+
styles: [
|
|
43
|
+
tc.aspect("square"),
|
|
44
|
+
tc.h(4),
|
|
45
|
+
tc.w(4),
|
|
46
|
+
tc.rounded("full"),
|
|
47
|
+
tc.border(),
|
|
48
|
+
tc.border("primary"),
|
|
49
|
+
tc.text("primary"),
|
|
50
|
+
tc.focusVisible(
|
|
51
|
+
[tc.outline("none"), tc.ring("ring", 2, "background", 2)].flat()
|
|
52
|
+
),
|
|
53
|
+
tc.disabled([tc.cursor("not-allowed"), tc.opacity(50)].flat()),
|
|
54
|
+
].flat(),
|
|
55
|
+
children: [
|
|
56
|
+
{
|
|
57
|
+
type: "instance",
|
|
58
|
+
component: "RadioGroupIndicator",
|
|
59
|
+
children: [
|
|
60
|
+
{
|
|
61
|
+
type: "instance",
|
|
62
|
+
component: "HtmlEmbed",
|
|
63
|
+
label: "Indicator Icon",
|
|
64
|
+
props: [
|
|
65
|
+
{
|
|
66
|
+
type: "string",
|
|
67
|
+
name: "code",
|
|
68
|
+
value: RadioDotIcon,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
children: [],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
type: "instance",
|
|
79
|
+
component: "Text",
|
|
80
|
+
children: [{ type: "text", value: label }],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const metaRadioGroup: WsComponentMeta = {
|
|
86
|
+
category: "radix",
|
|
87
|
+
order: 100,
|
|
88
|
+
type: "container",
|
|
89
|
+
description:
|
|
90
|
+
"A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time.",
|
|
91
|
+
icon: RadioCheckedIcon,
|
|
92
|
+
states: [
|
|
93
|
+
...defaultStates,
|
|
94
|
+
{
|
|
95
|
+
label: "Checked",
|
|
96
|
+
selector: "[data-state=checked]",
|
|
97
|
+
category: "component-states",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
label: "Unchecked",
|
|
101
|
+
selector: "[data-state=unchecked]",
|
|
102
|
+
category: "component-states",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
presetStyle: {
|
|
106
|
+
div,
|
|
107
|
+
},
|
|
108
|
+
template: [
|
|
109
|
+
{
|
|
110
|
+
type: "instance",
|
|
111
|
+
component: "RadioGroup",
|
|
112
|
+
dataSources: {
|
|
113
|
+
radioGroupValue: { type: "variable", initialValue: "" },
|
|
114
|
+
},
|
|
115
|
+
// grid gap-2
|
|
116
|
+
styles: [tc.flex(), tc.flex("col"), tc.gap(2)].flat(),
|
|
117
|
+
props: [
|
|
118
|
+
{
|
|
119
|
+
type: "dataSource",
|
|
120
|
+
name: "value",
|
|
121
|
+
dataSourceName: "radioGroupValue",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "onValueChange",
|
|
125
|
+
type: "action",
|
|
126
|
+
value: [
|
|
127
|
+
{
|
|
128
|
+
type: "execute",
|
|
129
|
+
args: ["value"],
|
|
130
|
+
code: `radioGroupValue = value`,
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
children: [
|
|
136
|
+
createRadioGroupItem({ value: "default", label: "Default" }),
|
|
137
|
+
createRadioGroupItem({ value: "comfortable", label: "Comfortable" }),
|
|
138
|
+
createRadioGroupItem({ value: "compact", label: "Compact" }),
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const metaRadioGroupItem: WsComponentMeta = {
|
|
145
|
+
category: "hidden",
|
|
146
|
+
type: "container",
|
|
147
|
+
requiredAncestors: ["RadioGroup"],
|
|
148
|
+
icon: ItemIcon,
|
|
149
|
+
states: defaultStates,
|
|
150
|
+
presetStyle: {
|
|
151
|
+
button: [button, buttonReset].flat(),
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const metaRadioGroupIndicator: WsComponentMeta = {
|
|
156
|
+
category: "hidden",
|
|
157
|
+
type: "container",
|
|
158
|
+
detachable: false,
|
|
159
|
+
icon: TriggerIcon,
|
|
160
|
+
states: defaultStates,
|
|
161
|
+
presetStyle: {
|
|
162
|
+
span,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const propsMetaRadioGroup: WsComponentPropsMeta = {
|
|
167
|
+
props: propsRadioGroup,
|
|
168
|
+
initialProps: ["id", "value", "name", "required"],
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export const propsMetaRadioGroupItem: WsComponentPropsMeta = {
|
|
172
|
+
props: propsRadioGroupItem,
|
|
173
|
+
initialProps: ["value"],
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export const propsMetaRadioGroupIndicator: WsComponentPropsMeta = {
|
|
177
|
+
props: propsRadioGroupIndicator,
|
|
178
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { renderComponentTemplate } from "@webstudio-is/react-sdk";
|
|
3
|
+
import { Select as SelectPrimitive } from "./select";
|
|
4
|
+
import * as baseComponents from "@webstudio-is/sdk-components-react";
|
|
5
|
+
import * as baseMetas from "@webstudio-is/sdk-components-react/metas";
|
|
6
|
+
import * as radixComponents from "./components";
|
|
7
|
+
import * as radixMetas from "./metas";
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: "Components/Select",
|
|
11
|
+
component: SelectPrimitive,
|
|
12
|
+
} satisfies Meta<typeof SelectPrimitive>;
|
|
13
|
+
|
|
14
|
+
export const Select: StoryObj<typeof SelectPrimitive> = {
|
|
15
|
+
render: () =>
|
|
16
|
+
renderComponentTemplate({
|
|
17
|
+
name: "Select",
|
|
18
|
+
components: { ...baseComponents, ...radixComponents },
|
|
19
|
+
metas: { ...baseMetas, ...radixMetas },
|
|
20
|
+
}),
|
|
21
|
+
};
|
package/src/select.tsx
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* eslint-disable react/display-name */
|
|
2
|
+
// We can't use .displayName until this is merged https://github.com/styleguidist/react-docgen-typescript/pull/449
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type ForwardRefExoticComponent,
|
|
6
|
+
type ComponentPropsWithRef,
|
|
7
|
+
type ComponentPropsWithoutRef,
|
|
8
|
+
forwardRef,
|
|
9
|
+
} from "react";
|
|
10
|
+
import {
|
|
11
|
+
Root,
|
|
12
|
+
Value,
|
|
13
|
+
Trigger,
|
|
14
|
+
Content,
|
|
15
|
+
Item,
|
|
16
|
+
ItemIndicator,
|
|
17
|
+
ItemText,
|
|
18
|
+
Portal,
|
|
19
|
+
Viewport,
|
|
20
|
+
} from "@radix-ui/react-select";
|
|
21
|
+
import { type Hook, getClosestInstance } from "@webstudio-is/react-sdk";
|
|
22
|
+
|
|
23
|
+
// wrap in forwardRef because Root is functional component without ref
|
|
24
|
+
export const Select = forwardRef<
|
|
25
|
+
HTMLDivElement,
|
|
26
|
+
ComponentPropsWithoutRef<typeof Root>
|
|
27
|
+
>(({ value, ...props }, _ref) => {
|
|
28
|
+
// radix consider empty string as empty value since this change but not released yet
|
|
29
|
+
// https://github.com/radix-ui/primitives/commit/a3dadb0a825524dd60629d426538dac74930791a
|
|
30
|
+
if (value === "") {
|
|
31
|
+
value = undefined;
|
|
32
|
+
}
|
|
33
|
+
return <Root value={value} {...props} />;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export const SelectTrigger: ForwardRefExoticComponent<
|
|
37
|
+
ComponentPropsWithRef<typeof Trigger>
|
|
38
|
+
> = Trigger;
|
|
39
|
+
|
|
40
|
+
export const SelectValue = forwardRef<
|
|
41
|
+
HTMLDivElement,
|
|
42
|
+
Omit<ComponentPropsWithoutRef<typeof Value>, "placeholder"> & {
|
|
43
|
+
placeholder?: string;
|
|
44
|
+
}
|
|
45
|
+
>((props, ref) => {
|
|
46
|
+
return <Value ref={ref} {...props} />;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const SelectContent = forwardRef<
|
|
50
|
+
HTMLDivElement,
|
|
51
|
+
Omit<ComponentPropsWithoutRef<typeof Content>, "position" | "side">
|
|
52
|
+
>((props, ref) => {
|
|
53
|
+
return (
|
|
54
|
+
<Portal>
|
|
55
|
+
<Content ref={ref} {...props} position="popper" />
|
|
56
|
+
</Portal>
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const SelectViewport: ForwardRefExoticComponent<
|
|
61
|
+
ComponentPropsWithRef<typeof Viewport>
|
|
62
|
+
> = Viewport;
|
|
63
|
+
|
|
64
|
+
export const SelectItem: ForwardRefExoticComponent<
|
|
65
|
+
ComponentPropsWithRef<typeof Item>
|
|
66
|
+
> = Item;
|
|
67
|
+
|
|
68
|
+
export const SelectItemIndicator: ForwardRefExoticComponent<
|
|
69
|
+
ComponentPropsWithRef<typeof ItemIndicator>
|
|
70
|
+
> = ItemIndicator;
|
|
71
|
+
|
|
72
|
+
export const SelectItemText: ForwardRefExoticComponent<
|
|
73
|
+
ComponentPropsWithRef<typeof ItemText>
|
|
74
|
+
> = ItemText;
|
|
75
|
+
|
|
76
|
+
/* BUILDER HOOKS */
|
|
77
|
+
|
|
78
|
+
const namespace = "@webstudio-is/sdk-components-react-radix";
|
|
79
|
+
|
|
80
|
+
// For each SelectContent component within the selection,
|
|
81
|
+
// we identify its closest parent Select component
|
|
82
|
+
// and update its open prop bound to variable.
|
|
83
|
+
export const hooksSelect: Hook = {
|
|
84
|
+
onNavigatorUnselect: (context, event) => {
|
|
85
|
+
for (const instance of event.instancePath) {
|
|
86
|
+
if (instance.component === `${namespace}:SelectContent`) {
|
|
87
|
+
const select = getClosestInstance(
|
|
88
|
+
event.instancePath,
|
|
89
|
+
instance,
|
|
90
|
+
`${namespace}:Select`
|
|
91
|
+
);
|
|
92
|
+
if (select) {
|
|
93
|
+
context.setPropVariable(select.id, "open", false);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
onNavigatorSelect: (context, event) => {
|
|
99
|
+
for (const instance of event.instancePath) {
|
|
100
|
+
if (instance.component === `${namespace}:SelectContent`) {
|
|
101
|
+
const select = getClosestInstance(
|
|
102
|
+
event.instancePath,
|
|
103
|
+
instance,
|
|
104
|
+
`${namespace}:Select`
|
|
105
|
+
);
|
|
106
|
+
if (select) {
|
|
107
|
+
context.setPropVariable(select.id, "open", true);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
};
|