@webstudio-is/sdk-components-react-radix 0.87.0 → 0.88.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.
Files changed (182) hide show
  1. package/lib/__generated__/accordion.props.js +0 -5
  2. package/lib/__generated__/button.props.js +0 -21
  3. package/lib/__generated__/checkbox.props.js +850 -0
  4. package/lib/__generated__/collapsible.props.js +0 -2
  5. package/lib/__generated__/dialog.props.js +0 -11
  6. package/lib/__generated__/label.props.js +0 -1
  7. package/lib/__generated__/navigation-menu.props.js +2104 -0
  8. package/lib/__generated__/popover.props.js +0 -3
  9. package/lib/__generated__/radio-group.props.js +1282 -0
  10. package/lib/__generated__/select.props.js +2962 -0
  11. package/lib/__generated__/sheet.props.js +0 -11
  12. package/lib/__generated__/switch.props.js +850 -0
  13. package/lib/__generated__/tabs.props.js +428 -5
  14. package/lib/__generated__/tooltip.props.js +0 -2
  15. package/lib/accordion.js +11 -4
  16. package/lib/accordion.ws.js +87 -72
  17. package/lib/checkbox.js +13 -0
  18. package/lib/checkbox.ws.js +151 -0
  19. package/lib/cjs/__generated__/accordion.props.js +0 -5
  20. package/lib/cjs/__generated__/button.props.js +0 -21
  21. package/lib/cjs/__generated__/checkbox.props.js +870 -0
  22. package/lib/cjs/__generated__/collapsible.props.js +0 -2
  23. package/lib/cjs/__generated__/dialog.props.js +0 -11
  24. package/lib/cjs/__generated__/label.props.js +0 -1
  25. package/lib/cjs/__generated__/navigation-menu.props.js +2124 -0
  26. package/lib/cjs/__generated__/popover.props.js +0 -3
  27. package/lib/cjs/__generated__/radio-group.props.js +1302 -0
  28. package/lib/cjs/__generated__/select.props.js +2982 -0
  29. package/lib/cjs/__generated__/sheet.props.js +0 -11
  30. package/lib/cjs/__generated__/switch.props.js +870 -0
  31. package/lib/cjs/__generated__/tabs.props.js +428 -5
  32. package/lib/cjs/__generated__/tooltip.props.js +0 -2
  33. package/lib/cjs/accordion.js +11 -4
  34. package/lib/cjs/accordion.ws.js +85 -71
  35. package/lib/cjs/{textarea.js → checkbox.js} +9 -6
  36. package/lib/cjs/checkbox.ws.js +172 -0
  37. package/lib/cjs/collapsible.ws.js +4 -1
  38. package/lib/cjs/components.js +27 -14
  39. package/lib/cjs/dialog.ws.js +17 -17
  40. package/lib/cjs/hooks.js +5 -1
  41. package/lib/cjs/label.ws.js +1 -1
  42. package/lib/cjs/metas.js +29 -14
  43. package/lib/cjs/navigation-menu.js +107 -0
  44. package/lib/cjs/navigation-menu.ws.js +513 -0
  45. package/lib/cjs/popover.ws.js +12 -9
  46. package/lib/cjs/props.js +27 -14
  47. package/lib/cjs/{button.js → radio-group.js} +10 -8
  48. package/lib/cjs/radio-group.ws.js +188 -0
  49. package/lib/cjs/select.js +81 -0
  50. package/lib/cjs/select.ws.js +349 -0
  51. package/lib/cjs/sheet.ws.js +87 -176
  52. package/lib/cjs/{input.js → switch.js} +8 -9
  53. package/lib/cjs/switch.ws.js +171 -0
  54. package/lib/cjs/tabs.js +2 -3
  55. package/lib/cjs/tabs.ws.js +13 -18
  56. package/lib/cjs/theme/styles.js +100 -0
  57. package/lib/cjs/theme/tailwind-classes.js +125 -16
  58. package/lib/cjs/theme/tailwind-colors.js +1 -0
  59. package/lib/cjs/tooltip.ws.js +11 -8
  60. package/lib/collapsible.ws.js +4 -1
  61. package/lib/components.js +44 -22
  62. package/lib/dialog.ws.js +17 -17
  63. package/lib/hooks.js +5 -1
  64. package/lib/label.ws.js +1 -1
  65. package/lib/metas.js +58 -24
  66. package/lib/navigation-menu.js +85 -0
  67. package/lib/navigation-menu.ws.js +500 -0
  68. package/lib/popover.ws.js +12 -9
  69. package/lib/props.js +56 -24
  70. package/lib/radio-group.js +11 -0
  71. package/lib/radio-group.ws.js +170 -0
  72. package/lib/select.js +73 -0
  73. package/lib/select.ws.js +337 -0
  74. package/lib/sheet.ws.js +88 -194
  75. package/lib/switch.js +7 -0
  76. package/lib/switch.ws.js +143 -0
  77. package/lib/tabs.js +3 -5
  78. package/lib/tabs.ws.js +14 -19
  79. package/lib/theme/styles.js +70 -0
  80. package/lib/theme/tailwind-classes.js +125 -16
  81. package/lib/theme/tailwind-colors.js +1 -0
  82. package/lib/tooltip.ws.js +11 -8
  83. package/lib/types/__generated__/checkbox.props.d.ts +3 -0
  84. package/lib/types/__generated__/navigation-menu.props.d.ts +8 -0
  85. package/lib/types/__generated__/radio-group.props.d.ts +4 -0
  86. package/lib/types/__generated__/select.props.d.ts +9 -0
  87. package/lib/types/__generated__/switch.props.d.ts +3 -0
  88. package/lib/types/checkbox.d.ts +6 -0
  89. package/lib/types/checkbox.stories.d.ts +11 -0
  90. package/lib/types/checkbox.ws.d.ts +5 -0
  91. package/lib/types/components.d.ts +5 -4
  92. package/lib/types/metas.d.ts +6 -4
  93. package/lib/types/navigation-menu.d.ts +15 -0
  94. package/lib/types/navigation-menu.ws.d.ts +15 -0
  95. package/lib/types/props.d.ts +5 -4
  96. package/lib/types/radio-group.d.ts +5 -0
  97. package/lib/types/radio-group.stories.d.ts +9 -0
  98. package/lib/types/radio-group.ws.d.ts +7 -0
  99. package/lib/types/select.d.ts +12 -0
  100. package/lib/types/select.ws.d.ts +17 -0
  101. package/lib/types/sheet.ws.d.ts +2 -15
  102. package/lib/types/switch.d.ts +4 -0
  103. package/lib/types/switch.stories.d.ts +9 -0
  104. package/lib/types/switch.ws.d.ts +5 -0
  105. package/lib/types/tabs.d.ts +3 -12
  106. package/lib/types/theme/radix-common-types.d.ts +3 -2
  107. package/lib/types/theme/styles.d.ts +215 -0
  108. package/lib/types/theme/tailwind-classes.d.ts +16 -6
  109. package/lib/types/theme/tailwind-colors.d.ts +1 -0
  110. package/lib/types/theme/tailwind-theme.d.ts +1 -1
  111. package/package.json +12 -7
  112. package/src/__generated__/accordion.props.ts +0 -5
  113. package/src/__generated__/button.props.ts +0 -21
  114. package/src/__generated__/checkbox.props.ts +948 -0
  115. package/src/__generated__/collapsible.props.ts +0 -2
  116. package/src/__generated__/dialog.props.ts +0 -11
  117. package/src/__generated__/label.props.ts +0 -1
  118. package/src/__generated__/navigation-menu.props.ts +2349 -0
  119. package/src/__generated__/popover.props.ts +0 -3
  120. package/src/__generated__/radio-group.props.ts +1429 -0
  121. package/src/__generated__/select.props.ts +3304 -0
  122. package/src/__generated__/sheet.props.ts +0 -11
  123. package/src/__generated__/switch.props.ts +948 -0
  124. package/src/__generated__/tabs.props.ts +477 -4
  125. package/src/__generated__/tooltip.props.ts +0 -2
  126. package/src/accordion.tsx +14 -7
  127. package/src/accordion.ws.ts +85 -70
  128. package/src/{textarea.stories.ts → checkbox.stories.ts} +6 -11
  129. package/src/checkbox.tsx +22 -0
  130. package/src/checkbox.ws.ts +151 -0
  131. package/src/collapsible.ws.ts +4 -1
  132. package/src/components.ts +25 -12
  133. package/src/dialog.ws.tsx +15 -16
  134. package/src/hooks.ts +4 -0
  135. package/src/label.ws.ts +1 -1
  136. package/src/metas.ts +36 -12
  137. package/src/navigation-menu.stories.tsx +21 -0
  138. package/src/navigation-menu.tsx +130 -0
  139. package/src/navigation-menu.ws.ts +523 -0
  140. package/src/popover.ws.tsx +12 -9
  141. package/src/props.ts +35 -12
  142. package/src/{input.stories.ts → radio-group.stories.ts} +6 -15
  143. package/src/radio-group.tsx +17 -0
  144. package/src/radio-group.ws.ts +174 -0
  145. package/src/select.stories.tsx +21 -0
  146. package/src/select.tsx +107 -0
  147. package/src/select.ws.ts +347 -0
  148. package/src/sheet.ws.tsx +89 -209
  149. package/src/{button.stories.ts → switch.stories.ts} +6 -19
  150. package/src/switch.tsx +10 -0
  151. package/src/switch.ws.ts +143 -0
  152. package/src/tabs.tsx +4 -17
  153. package/src/tabs.ws.ts +17 -19
  154. package/src/theme/radix-common-types.ts +3 -2
  155. package/src/theme/styles.ts +80 -0
  156. package/src/theme/tailwind-classes.ts +150 -14
  157. package/src/theme/tailwind-colors.ts +1 -0
  158. package/src/tooltip.ws.tsx +11 -8
  159. package/lib/button.js +0 -8
  160. package/lib/button.ws.js +0 -133
  161. package/lib/cjs/button.ws.js +0 -160
  162. package/lib/cjs/input.ws.js +0 -103
  163. package/lib/cjs/textarea.ws.js +0 -98
  164. package/lib/input.js +0 -8
  165. package/lib/input.ws.js +0 -75
  166. package/lib/textarea.js +0 -8
  167. package/lib/textarea.ws.js +0 -70
  168. package/lib/types/button.d.ts +0 -7
  169. package/lib/types/button.stories.d.ts +0 -20
  170. package/lib/types/button.ws.d.ts +0 -7
  171. package/lib/types/input.d.ts +0 -2
  172. package/lib/types/input.stories.d.ts +0 -20
  173. package/lib/types/input.ws.d.ts +0 -3
  174. package/lib/types/textarea.d.ts +0 -2
  175. package/lib/types/textarea.stories.d.ts +0 -14
  176. package/lib/types/textarea.ws.d.ts +0 -3
  177. package/src/button.tsx +0 -25
  178. package/src/button.ws.ts +0 -155
  179. package/src/input.tsx +0 -12
  180. package/src/input.ws.ts +0 -78
  181. package/src/textarea.tsx +0 -12
  182. package/src/textarea.ws.ts +0 -74
package/src/sheet.ws.tsx CHANGED
@@ -1,106 +1,7 @@
1
- import {
2
- HamburgerMenuIcon,
3
- TriggerIcon,
4
- ContentIcon,
5
- OverlayIcon,
6
- HeadingIcon,
7
- TextIcon,
8
- ButtonElementIcon,
9
- } from "@webstudio-is/icons/svg";
10
- import {
11
- type PresetStyle,
12
- type WsComponentMeta,
13
- type WsComponentPropsMeta,
14
- } from "@webstudio-is/react-sdk";
1
+ import { HamburgerMenuIcon } from "@webstudio-is/icons/svg";
2
+ import type { WsComponentMeta } from "@webstudio-is/react-sdk";
15
3
  import * as tc from "./theme/tailwind-classes";
16
- import {
17
- propsSheet,
18
- propsSheetContent,
19
- propsSheetTrigger,
20
- propsSheetOverlay,
21
- propsSheetClose,
22
- propsSheetTitle,
23
- propsSheetDescription,
24
- } from "./__generated__/sheet.props";
25
- import { div, nav, button, h2, p } from "@webstudio-is/react-sdk/css-normalize";
26
- import type { SheetContent } from "./sheet";
27
- import type { ComponentProps } from "react";
28
- import { template as buttonTemplate } from "./button.ws";
29
-
30
- type ContentTags = NonNullable<ComponentProps<typeof SheetContent>["tag"]>;
31
-
32
- const contentPresetStyle = {
33
- div,
34
- nav,
35
- } satisfies PresetStyle<ContentTags>;
36
-
37
- const presetStyle = {
38
- div,
39
- } satisfies PresetStyle<"div">;
40
-
41
- const buttonPresetStyle = {
42
- button,
43
- } satisfies PresetStyle<"button">;
44
-
45
- const titlePresetStyle = {
46
- h2,
47
- } satisfies PresetStyle<"h2">;
48
-
49
- const descriptionPresetStyle = {
50
- p,
51
- } satisfies PresetStyle<"p">;
52
-
53
- // @todo add [data-state] to button and link
54
- export const metaSheetTrigger: WsComponentMeta = {
55
- category: "hidden",
56
- type: "container",
57
- icon: TriggerIcon,
58
- stylable: false,
59
- detachable: false,
60
- };
61
-
62
- export const metaSheetContent: WsComponentMeta = {
63
- category: "hidden",
64
- type: "container",
65
- icon: ContentIcon,
66
- detachable: false,
67
- presetStyle: contentPresetStyle,
68
- states: [
69
- { selector: "[data-side=top]", label: "Top Side" },
70
- { selector: "[data-side=right]", label: "Right Side" },
71
- { selector: "[data-side=bottom]", label: "Bottom Side" },
72
- { selector: "[data-side=left]", label: "Left Side" },
73
- ],
74
- };
75
-
76
- export const metaSheetOverlay: WsComponentMeta = {
77
- category: "hidden",
78
- type: "container",
79
- presetStyle,
80
- icon: OverlayIcon,
81
- detachable: false,
82
- };
83
-
84
- export const metaSheetTitle: WsComponentMeta = {
85
- category: "hidden",
86
- type: "container",
87
- presetStyle: titlePresetStyle,
88
- icon: HeadingIcon,
89
- };
90
-
91
- export const metaSheetDescription: WsComponentMeta = {
92
- category: "hidden",
93
- type: "container",
94
- presetStyle: descriptionPresetStyle,
95
- icon: TextIcon,
96
- };
97
-
98
- export const metaSheetClose: WsComponentMeta = {
99
- category: "hidden",
100
- type: "container",
101
- presetStyle: buttonPresetStyle,
102
- icon: ButtonElementIcon,
103
- };
4
+ import { getButtonStyles } from "./theme/styles";
104
5
 
105
6
  /**
106
7
  * Styles source without animations:
@@ -110,17 +11,17 @@ export const metaSheetClose: WsComponentMeta = {
110
11
  * MIT License
111
12
  * Copyright (c) 2023 shadcn
112
13
  **/
113
- export const metaSheet: WsComponentMeta = {
14
+ export const meta: WsComponentMeta = {
114
15
  category: "radix",
115
-
16
+ order: 1,
116
17
  type: "container",
117
18
  icon: HamburgerMenuIcon,
118
- order: 15,
119
19
  stylable: false,
120
20
  template: [
121
21
  {
122
22
  type: "instance",
123
- component: "Sheet",
23
+ component: "Dialog",
24
+ label: "Sheet",
124
25
  dataSources: {
125
26
  sheetOpen: { type: "variable", initialValue: false },
126
27
  },
@@ -141,32 +42,35 @@ export const metaSheet: WsComponentMeta = {
141
42
  children: [
142
43
  {
143
44
  type: "instance",
144
- component: "SheetTrigger",
145
- children: buttonTemplate({
146
- props: [
147
- { name: "variant", type: "string", value: "ghost" },
148
- { name: "size", type: "string", value: "icon" },
149
- ],
150
- children: [
151
- {
152
- type: "instance",
153
- component: "HtmlEmbed",
154
- label: "Hamburger Menu Svg",
155
- props: [
156
- {
157
- type: "string",
158
- name: "code",
159
- value: HamburgerMenuIcon,
160
- },
161
- ],
162
- children: [],
163
- },
164
- ],
165
- }),
45
+ component: "DialogTrigger",
46
+ label: "Sheet Trigger",
47
+ children: [
48
+ {
49
+ type: "instance",
50
+ component: "Button",
51
+ styles: getButtonStyles("ghost", "icon"),
52
+ children: [
53
+ {
54
+ type: "instance",
55
+ component: "HtmlEmbed",
56
+ label: "Hamburger Menu Svg",
57
+ props: [
58
+ {
59
+ type: "string",
60
+ name: "code",
61
+ value: HamburgerMenuIcon,
62
+ },
63
+ ],
64
+ children: [],
65
+ },
66
+ ],
67
+ },
68
+ ],
166
69
  },
167
70
  {
168
71
  type: "instance",
169
- component: "SheetOverlay",
72
+ component: "DialogOverlay",
73
+ label: "Sheet Overlay",
170
74
  /**
171
75
  * fixed inset-0 z-50 bg-background/80 backdrop-blur-sm
172
76
  * flex
@@ -185,7 +89,8 @@ export const metaSheet: WsComponentMeta = {
185
89
  children: [
186
90
  {
187
91
  type: "instance",
188
- component: "SheetContent",
92
+ component: "DialogContent",
93
+ label: "Sheet Content",
189
94
  /**
190
95
  * fixed w-full z-50
191
96
  * grid gap-4 max-w-lg
@@ -203,73 +108,82 @@ export const metaSheet: WsComponentMeta = {
203
108
  tc.p(6),
204
109
  tc.shadow("lg"),
205
110
  tc.relative(),
206
- tc.state(
207
- [tc.mr("auto"), tc.maxW("sm"), tc.grow()].flat(),
208
- "[data-side=left]"
209
- ),
210
- tc.state(
211
- [tc.ml("auto"), tc.maxW("sm"), tc.grow()].flat(),
212
- "[data-side=right]"
213
- ),
214
- tc.state([tc.mb("auto")].flat(), "[data-side=top]"),
215
- tc.state([tc.mt("auto")].flat(), "[data-side=bottom]"),
111
+ // side=left
112
+ tc.mr("auto"),
113
+ tc.maxW("sm"),
114
+ tc.grow(),
216
115
  ].flat(),
217
116
  children: [
218
117
  {
219
118
  type: "instance",
220
119
  component: "Box",
221
- label: "Sheet Header",
222
- styles: [tc.flex(), tc.flex("col"), tc.gap(1)].flat(),
120
+ label: "Navigation",
121
+ props: [
122
+ { name: "tag", type: "string", value: "nav" },
123
+ { name: "role", type: "string", value: "navigation" },
124
+ ],
223
125
  children: [
224
126
  {
225
127
  type: "instance",
226
- component: "SheetTitle",
227
- /**
228
- * text-lg leading-none tracking-tight
229
- **/
230
- styles: [
231
- tc.my(0),
232
- tc.leading("none"),
233
- tc.text("lg"),
234
- tc.tracking("tight"),
235
- ].flat(),
128
+ component: "Box",
129
+ label: "Sheet Header",
130
+ styles: [tc.flex(), tc.flex("col"), tc.gap(1)].flat(),
236
131
  children: [
237
132
  {
238
- type: "text",
239
- value: "Sheet Title",
133
+ type: "instance",
134
+ component: "DialogTitle",
135
+ label: "Sheet Title",
136
+ /**
137
+ * text-lg leading-none tracking-tight
138
+ **/
139
+ styles: [
140
+ tc.my(0),
141
+ tc.leading("none"),
142
+ tc.text("lg"),
143
+ tc.tracking("tight"),
144
+ ].flat(),
145
+ children: [
146
+ {
147
+ type: "text",
148
+ value: "Sheet Title",
149
+ },
150
+ ],
151
+ },
152
+ {
153
+ type: "instance",
154
+ component: "DialogDescription",
155
+ label: "Sheet Description",
156
+ /**
157
+ * text-sm text-muted-foreground
158
+ **/
159
+ styles: [
160
+ tc.my(0),
161
+ tc.text("sm"),
162
+ tc.text("mutedForeground"),
163
+ ].flat(),
164
+ children: [
165
+ {
166
+ type: "text",
167
+ value: "Sheet description text you can edit",
168
+ },
169
+ ],
240
170
  },
241
171
  ],
242
172
  },
173
+
243
174
  {
244
175
  type: "instance",
245
- component: "SheetDescription",
246
- /**
247
- * text-sm text-muted-foreground
248
- **/
249
- styles: [
250
- tc.my(0),
251
- tc.text("sm"),
252
- tc.text("mutedForeground"),
253
- ].flat(),
176
+ component: "Text",
254
177
  children: [
255
- {
256
- type: "text",
257
- value: "sheet description text you can edit",
258
- },
178
+ { type: "text", value: "The text you can edit" },
259
179
  ],
260
180
  },
261
181
  ],
262
182
  },
263
-
264
- {
265
- type: "instance",
266
- component: "Text",
267
- children: [{ type: "text", value: "The text you can edit" }],
268
- },
269
-
270
183
  {
271
184
  type: "instance",
272
- component: "SheetClose",
185
+ component: "DialogClose",
186
+ label: "Close Button",
273
187
  /**
274
188
  * absolute right-4 top-4
275
189
  * rounded-sm opacity-70
@@ -304,37 +218,3 @@ export const metaSheet: WsComponentMeta = {
304
218
  },
305
219
  ],
306
220
  };
307
-
308
- export const propsMetaSheet: WsComponentPropsMeta = {
309
- props: propsSheet,
310
- initialProps: ["open", "modal"],
311
- };
312
-
313
- export const propsMetaSheetTrigger: WsComponentPropsMeta = {
314
- props: propsSheetTrigger,
315
- };
316
-
317
- export const propsMetaSheetContent: WsComponentPropsMeta = {
318
- props: propsSheetContent,
319
- initialProps: ["side", "role", "tag"],
320
- };
321
-
322
- export const propsMetaSheetOverlay: WsComponentPropsMeta = {
323
- props: propsSheetOverlay,
324
- initialProps: [],
325
- };
326
-
327
- export const propsMetaSheetClose: WsComponentPropsMeta = {
328
- props: propsSheetClose,
329
- initialProps: [],
330
- };
331
-
332
- export const propsMetaSheetTitle: WsComponentPropsMeta = {
333
- props: propsSheetTitle,
334
- initialProps: [],
335
- };
336
-
337
- export const propsMetaSheetDescription: WsComponentPropsMeta = {
338
- props: propsSheetDescription,
339
- initialProps: [],
340
- };
@@ -1,33 +1,20 @@
1
1
  import type { Meta, StoryObj } from "@storybook/react";
2
2
  import { renderComponentTemplate } from "@webstudio-is/react-sdk";
3
- import { Button as ButtonPrimitive } from "./button";
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 { Switch as SwitchPrimitive } from "./switch";
8
8
 
9
9
  export default {
10
- title: "Components/Button",
11
- component: ButtonPrimitive,
12
- argTypes: {
13
- variant: {
14
- options: [
15
- "default",
16
- "destructive",
17
- "outline",
18
- "secondary",
19
- "ghost",
20
- "link",
21
- ],
22
- control: { type: "select" },
23
- },
24
- },
25
- } satisfies Meta<typeof ButtonPrimitive>;
10
+ title: "Components/Switch",
11
+ component: SwitchPrimitive,
12
+ } satisfies Meta<typeof SwitchPrimitive>;
26
13
 
27
- export const Button: StoryObj<typeof ButtonPrimitive> = {
14
+ export const Switch: StoryObj<typeof SwitchPrimitive> = {
28
15
  render: (props) =>
29
16
  renderComponentTemplate({
30
- name: "Button",
17
+ name: "Switch",
31
18
  props: { ...props },
32
19
  components: { ...baseComponents, ...radixComponents },
33
20
  metas: { ...baseMetas, ...radixMetas },
package/src/switch.tsx ADDED
@@ -0,0 +1,10 @@
1
+ import type { ForwardRefExoticComponent, ComponentPropsWithRef } from "react";
2
+ import { Root, Thumb } from "@radix-ui/react-switch";
3
+
4
+ export const Switch: ForwardRefExoticComponent<
5
+ ComponentPropsWithRef<typeof Root>
6
+ > = Root;
7
+
8
+ export const SwitchThumb: ForwardRefExoticComponent<
9
+ ComponentPropsWithRef<typeof Thumb>
10
+ > = Thumb;
@@ -0,0 +1,143 @@
1
+ import { SwitchIcon, TriggerIcon } from "@webstudio-is/icons/svg";
2
+ import {
3
+ defaultStates,
4
+ type WsComponentMeta,
5
+ type WsComponentPropsMeta,
6
+ } from "@webstudio-is/react-sdk";
7
+ import { button, span } from "@webstudio-is/react-sdk/css-normalize";
8
+ import * as tc from "./theme/tailwind-classes";
9
+ import { buttonReset } from "./theme/styles";
10
+ import { propsSwitch, propsSwitchThumb } from "./__generated__/switch.props";
11
+
12
+ export const metaSwitch: WsComponentMeta = {
13
+ category: "radix",
14
+ order: 11,
15
+ type: "container",
16
+ icon: SwitchIcon,
17
+ states: [
18
+ ...defaultStates,
19
+ {
20
+ label: "Checked",
21
+ selector: "[data-state=checked]",
22
+ category: "component-states",
23
+ },
24
+ {
25
+ label: "Unchecked",
26
+ selector: "[data-state=unchecked]",
27
+ category: "component-states",
28
+ },
29
+ ],
30
+ presetStyle: {
31
+ button: [button, buttonReset].flat(),
32
+ },
33
+ template: [
34
+ {
35
+ type: "instance",
36
+ component: "Switch",
37
+ dataSources: {
38
+ switchChecked: { type: "variable", initialValue: false },
39
+ },
40
+ props: [
41
+ {
42
+ name: "checked",
43
+ type: "dataSource",
44
+ dataSourceName: "switchChecked",
45
+ },
46
+ {
47
+ name: "onCheckedChange",
48
+ type: "action",
49
+ value: [
50
+ {
51
+ type: "execute",
52
+ args: ["checked"],
53
+ code: `switchChecked = checked`,
54
+ },
55
+ ],
56
+ },
57
+ ],
58
+ // peer inline-flex h-[24px] w-[44px] shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors
59
+ // focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background
60
+ // disabled:cursor-not-allowed disabled:opacity-50
61
+ // data-[state=checked]:bg-primary
62
+ // data-[state=unchecked]:bg-input
63
+ styles: [
64
+ // We are not supporting peer like styles yet
65
+ tc.inlineFlex(),
66
+ tc.property("height", "24px"),
67
+ tc.property("width", "44px"),
68
+ tc.shrink(0),
69
+ tc.cursor("pointer"),
70
+ tc.items("center"),
71
+ tc.rounded("full"),
72
+ tc.border(2),
73
+ tc.border("transparent"),
74
+ tc.transition("all"),
75
+ tc.focusVisible(
76
+ [tc.outline("none"), tc.ring("ring", 2, "background", 2)].flat()
77
+ ),
78
+ tc.disabled([tc.cursor("not-allowed"), tc.opacity(50)].flat()),
79
+ tc.state([tc.bg("primary")].flat(), "[data-state=checked]"),
80
+ tc.state([tc.bg("input")].flat(), "[data-state=unchecked]"),
81
+ ].flat(),
82
+ children: [
83
+ {
84
+ type: "instance",
85
+ component: "SwitchThumb",
86
+ // pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform
87
+ // data-[state=checked]:translate-x-5
88
+ // data-[state=unchecked]:translate-x-0
89
+ styles: [
90
+ tc.pointerEvents("none"),
91
+ tc.block(),
92
+ tc.h(5),
93
+ tc.w(5),
94
+ tc.rounded("full"),
95
+ tc.bg("background"),
96
+ tc.shadow("lg"),
97
+ tc.transition("transform"),
98
+ tc.state(
99
+ [tc.property("transform", "translateX(20px)")].flat(),
100
+ "[data-state=checked]"
101
+ ),
102
+ tc.state(
103
+ [tc.property("transform", "translateX(0px)")].flat(),
104
+ "[data-state=unchecked]"
105
+ ),
106
+ ].flat(),
107
+ children: [],
108
+ },
109
+ ],
110
+ },
111
+ ],
112
+ };
113
+
114
+ export const metaSwitchThumb: WsComponentMeta = {
115
+ category: "hidden",
116
+ type: "container",
117
+ icon: TriggerIcon,
118
+ states: [
119
+ ...defaultStates,
120
+ {
121
+ label: "Checked",
122
+ selector: "[data-state=checked]",
123
+ category: "component-states",
124
+ },
125
+ {
126
+ label: "Unchecked",
127
+ selector: "[data-state=unchecked]",
128
+ category: "component-states",
129
+ },
130
+ ],
131
+ presetStyle: {
132
+ span,
133
+ },
134
+ };
135
+
136
+ export const propsMetaSwitch: WsComponentPropsMeta = {
137
+ props: propsSwitch,
138
+ initialProps: ["id", "checked", "name", "required"],
139
+ };
140
+
141
+ export const propsMetaSwitchThumb: WsComponentPropsMeta = {
142
+ props: propsSwitchThumb,
143
+ };
package/src/tabs.tsx CHANGED
@@ -5,9 +5,7 @@ import {
5
5
  type ComponentPropsWithoutRef,
6
6
  type ForwardRefExoticComponent,
7
7
  type ComponentPropsWithRef,
8
- type ReactNode,
9
8
  forwardRef,
10
- Children,
11
9
  } from "react";
12
10
  import { Root, List, Trigger, Content } from "@radix-ui/react-tabs";
13
11
  import {
@@ -22,28 +20,17 @@ export const Tabs: ForwardRefExoticComponent<
22
20
 
23
21
  export const TabsList = List;
24
22
 
25
- /**
26
- * We're not exposing the 'asChild' property for the Trigger.
27
- * Instead, we're enforcing 'asChild=true' for the Trigger and making it style-less.
28
- * This avoids situations where the Trigger inadvertently passes all styles to its child,
29
- * which would prevent us from displaying styles properly in the builder.
30
- */
31
23
  export const TabsTrigger = forwardRef<
32
24
  HTMLButtonElement,
33
- { value: string; children: ReactNode }
34
- >(({ value, children, ...props }, ref) => {
35
- const firstChild = Children.toArray(children)[0];
25
+ ComponentPropsWithoutRef<typeof Trigger>
26
+ >(({ value, ...props }, ref) => {
36
27
  const index = getIndexWithinAncestorFromComponentProps(props);
37
- return (
38
- <Trigger ref={ref} value={value ?? index} asChild={true} {...props}>
39
- {firstChild ?? <button>Add button</button>}
40
- </Trigger>
41
- );
28
+ return <Trigger ref={ref} value={value ?? index} {...props} />;
42
29
  });
43
30
 
44
31
  export const TabsContent = forwardRef<
45
32
  HTMLDivElement,
46
- Omit<ComponentPropsWithoutRef<typeof Content>, "asChild">
33
+ ComponentPropsWithoutRef<typeof Content>
47
34
  >(({ value, ...props }, ref) => {
48
35
  const index = getIndexWithinAncestorFromComponentProps(props);
49
36
  return <Content ref={ref} value={value ?? index} {...props} />;
package/src/tabs.ws.ts CHANGED
@@ -10,8 +10,9 @@ import type {
10
10
  WsComponentMeta,
11
11
  WsComponentPropsMeta,
12
12
  } from "@webstudio-is/react-sdk";
13
- import { div } from "@webstudio-is/react-sdk/css-normalize";
13
+ import { button, div } from "@webstudio-is/react-sdk/css-normalize";
14
14
  import * as tc from "./theme/tailwind-classes";
15
+ import { buttonReset } from "./theme/styles";
15
16
  import {
16
17
  propsTabs,
17
18
  propsTabsList,
@@ -32,8 +33,11 @@ const presetStyle = {
32
33
  * Copyright (c) 2023 shadcn
33
34
  **/
34
35
 
35
- // inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm
36
- const tabsTriggerStyles: EmbedTemplateStyleDecl[] = [
36
+ // inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all
37
+ // focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2
38
+ // disabled:pointer-events-none disabled:opacity-50
39
+ // data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm
40
+ const tabsTriggerStyles = [
37
41
  tc.inlineFlex(),
38
42
  tc.items("center"),
39
43
  tc.justify("center"),
@@ -64,6 +68,7 @@ const tabsContentStyles: EmbedTemplateStyleDecl[] = [
64
68
 
65
69
  export const metaTabs: WsComponentMeta = {
66
70
  category: "radix",
71
+ order: 2,
67
72
  type: "container",
68
73
  icon: TabsIcon,
69
74
  presetStyle,
@@ -103,26 +108,14 @@ export const metaTabs: WsComponentMeta = {
103
108
  {
104
109
  type: "instance",
105
110
  component: "TabsTrigger",
106
- children: [
107
- {
108
- type: "instance",
109
- component: "Button",
110
- styles: tabsTriggerStyles,
111
- children: [{ type: "text", value: "Account" }],
112
- },
113
- ],
111
+ styles: tabsTriggerStyles,
112
+ children: [{ type: "text", value: "Account" }],
114
113
  },
115
114
  {
116
115
  type: "instance",
117
116
  component: "TabsTrigger",
118
- children: [
119
- {
120
- type: "instance",
121
- component: "Button",
122
- styles: tabsTriggerStyles,
123
- children: [{ type: "text", value: "Password" }],
124
- },
125
- ],
117
+ styles: tabsTriggerStyles,
118
+ children: [{ type: "text", value: "Password" }],
126
119
  },
127
120
  ],
128
121
  },
@@ -161,6 +154,10 @@ export const metaTabsTrigger: WsComponentMeta = {
161
154
  requiredAncestors: ["TabsList"],
162
155
  invalidAncestors: ["TabsTrigger"],
163
156
  indexWithinAncestor: "Tabs",
157
+ label: "Tab Trigger",
158
+ presetStyle: {
159
+ button: [button, buttonReset].flat(),
160
+ },
164
161
  };
165
162
 
166
163
  export const metaTabsContent: WsComponentMeta = {
@@ -170,6 +167,7 @@ export const metaTabsContent: WsComponentMeta = {
170
167
  requiredAncestors: ["Tabs"],
171
168
  indexWithinAncestor: "Tabs",
172
169
  presetStyle,
170
+ label: "Tab Content",
173
171
  };
174
172
 
175
173
  export const propsMetaTabs: WsComponentPropsMeta = {