@webstudio-is/sdk-components-react-radix 0.90.0 → 0.92.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 (199) hide show
  1. package/lib/__generated__/accordion.props.js +6 -12
  2. package/lib/__generated__/checkbox.props.js +3 -6
  3. package/lib/__generated__/collapsible.props.js +4 -8
  4. package/lib/__generated__/dialog.props.js +8 -16
  5. package/lib/__generated__/label.props.js +2 -4
  6. package/lib/__generated__/navigation-menu.props.js +8 -16
  7. package/lib/__generated__/popover.props.js +4 -8
  8. package/lib/__generated__/radio-group.props.js +4 -8
  9. package/lib/__generated__/select.props.js +15 -19
  10. package/lib/__generated__/sheet.props.js +8 -16
  11. package/lib/__generated__/switch.props.js +3 -6
  12. package/lib/__generated__/tabs.props.js +5 -10
  13. package/lib/__generated__/tooltip.props.js +4 -8
  14. package/lib/accordion.js +7 -14
  15. package/{src/accordion.stories.tsx → lib/accordion.stories.js} +9 -12
  16. package/lib/accordion.ws.js +11 -22
  17. package/lib/checkbox.js +3 -6
  18. package/lib/checkbox.stories.js +19 -0
  19. package/lib/checkbox.ws.js +5 -10
  20. package/lib/collapsible.js +5 -10
  21. package/{src/collapsible.stories.tsx → lib/collapsible.stories.js} +9 -12
  22. package/lib/collapsible.ws.js +7 -14
  23. package/lib/components.js +13 -62
  24. package/lib/dialog.js +9 -18
  25. package/{src/dialog.stories.tsx → lib/dialog.stories.js} +9 -12
  26. package/lib/dialog.ws.js +17 -30
  27. package/lib/hooks.js +2 -4
  28. package/lib/label.js +2 -4
  29. package/lib/label.stories.js +19 -0
  30. package/lib/label.ws.js +3 -6
  31. package/lib/metas.js +55 -105
  32. package/lib/navigation-menu.js +9 -18
  33. package/{src/navigation-menu.stories.tsx → lib/navigation-menu.stories.js} +9 -12
  34. package/lib/navigation-menu.ws.js +16 -31
  35. package/lib/popover.js +5 -10
  36. package/{src/popover.stories.tsx → lib/popover.stories.js} +9 -12
  37. package/lib/popover.ws.js +7 -14
  38. package/lib/props-descriptions.js +2 -4
  39. package/lib/props.js +54 -103
  40. package/lib/radio-group.js +4 -8
  41. package/lib/radio-group.stories.js +19 -0
  42. package/lib/radio-group.ws.js +7 -14
  43. package/lib/select.js +10 -20
  44. package/{src/select.stories.tsx → lib/select.stories.js} +9 -12
  45. package/lib/select.ws.js +17 -34
  46. package/lib/sheet.js +9 -18
  47. package/{src/sheet.stories.tsx → lib/sheet.stories.js} +9 -12
  48. package/lib/sheet.ws.js +2 -4
  49. package/lib/switch.js +3 -6
  50. package/lib/switch.stories.js +19 -0
  51. package/lib/switch.ws.js +5 -10
  52. package/lib/tabs.js +6 -12
  53. package/{src/tabs.stories.tsx → lib/tabs.stories.js} +9 -12
  54. package/lib/tabs.ws.js +9 -18
  55. package/lib/theme/__generated__/tailwind-theme.js +517 -0
  56. package/lib/theme/styles.js +3 -6
  57. package/lib/theme/tailwind-classes.js +149 -301
  58. package/lib/theme/tailwind-colors.js +2 -4
  59. package/lib/tooltip.js +5 -10
  60. package/{src/tooltip.stories.tsx → lib/tooltip.stories.js} +9 -12
  61. package/lib/tooltip.ws.js +7 -14
  62. package/lib/types/__generated__/accordion.props.d.ts +1 -1
  63. package/lib/types/__generated__/checkbox.props.d.ts +1 -1
  64. package/lib/types/__generated__/collapsible.props.d.ts +1 -1
  65. package/lib/types/__generated__/dialog.props.d.ts +1 -1
  66. package/lib/types/__generated__/label.props.d.ts +1 -1
  67. package/lib/types/__generated__/navigation-menu.props.d.ts +1 -1
  68. package/lib/types/__generated__/popover.props.d.ts +1 -1
  69. package/lib/types/__generated__/radio-group.props.d.ts +1 -1
  70. package/lib/types/__generated__/select.props.d.ts +1 -1
  71. package/lib/types/__generated__/sheet.props.d.ts +1 -1
  72. package/lib/types/__generated__/switch.props.d.ts +1 -1
  73. package/lib/types/__generated__/tabs.props.d.ts +1 -1
  74. package/lib/types/__generated__/tooltip.props.d.ts +1 -1
  75. package/lib/types/accordion.d.ts +1 -1
  76. package/lib/types/sheet.d.ts +1 -1
  77. package/lib/types/theme/__generated__/tailwind-theme.d.ts +26 -0
  78. package/lib/types/theme/styles.d.ts +60 -60
  79. package/lib/types/theme/tailwind-classes.d.ts +33 -33
  80. package/package.json +20 -23
  81. package/lib/__generated__/button.props.js +0 -565
  82. package/lib/__generated__/input.props.js +0 -668
  83. package/lib/__generated__/textarea.props.js +0 -577
  84. package/lib/cjs/__generated__/accordion.props.js +0 -2645
  85. package/lib/cjs/__generated__/button.props.js +0 -585
  86. package/lib/cjs/__generated__/checkbox.props.js +0 -1103
  87. package/lib/cjs/__generated__/collapsible.props.js +0 -1050
  88. package/lib/cjs/__generated__/dialog.props.js +0 -2623
  89. package/lib/cjs/__generated__/input.props.js +0 -688
  90. package/lib/cjs/__generated__/label.props.js +0 -541
  91. package/lib/cjs/__generated__/navigation-menu.props.js +0 -2585
  92. package/lib/cjs/__generated__/popover.props.js +0 -582
  93. package/lib/cjs/__generated__/radio-group.props.js +0 -1647
  94. package/lib/cjs/__generated__/select.props.js +0 -3698
  95. package/lib/cjs/__generated__/sheet.props.js +0 -2642
  96. package/lib/cjs/__generated__/switch.props.js +0 -1103
  97. package/lib/cjs/__generated__/tabs.props.js +0 -2144
  98. package/lib/cjs/__generated__/textarea.props.js +0 -597
  99. package/lib/cjs/__generated__/tooltip.props.js +0 -593
  100. package/lib/cjs/accordion.js +0 -67
  101. package/lib/cjs/accordion.ws.js +0 -285
  102. package/lib/cjs/checkbox.js +0 -31
  103. package/lib/cjs/checkbox.ws.js +0 -174
  104. package/lib/cjs/collapsible.js +0 -53
  105. package/lib/cjs/collapsible.ws.js +0 -122
  106. package/lib/cjs/components.js +0 -82
  107. package/lib/cjs/dialog.js +0 -89
  108. package/lib/cjs/dialog.ws.js +0 -314
  109. package/lib/cjs/hooks.js +0 -43
  110. package/lib/cjs/label.js +0 -37
  111. package/lib/cjs/label.ws.js +0 -75
  112. package/lib/cjs/metas.js +0 -84
  113. package/lib/cjs/navigation-menu.js +0 -107
  114. package/lib/cjs/navigation-menu.ws.js +0 -514
  115. package/lib/cjs/package.json +0 -1
  116. package/lib/cjs/popover.js +0 -90
  117. package/lib/cjs/popover.ws.js +0 -142
  118. package/lib/cjs/props-descriptions.js +0 -56
  119. package/lib/cjs/props.js +0 -82
  120. package/lib/cjs/radio-group.js +0 -30
  121. package/lib/cjs/radio-group.ws.js +0 -191
  122. package/lib/cjs/select.js +0 -83
  123. package/lib/cjs/select.ws.js +0 -350
  124. package/lib/cjs/sheet.js +0 -96
  125. package/lib/cjs/sheet.ws.js +0 -257
  126. package/lib/cjs/switch.js +0 -27
  127. package/lib/cjs/switch.ws.js +0 -173
  128. package/lib/cjs/tabs.js +0 -59
  129. package/lib/cjs/tabs.ws.js +0 -196
  130. package/lib/cjs/theme/radix-common-types.js +0 -16
  131. package/lib/cjs/theme/styles.js +0 -96
  132. package/lib/cjs/theme/tailwind-classes.js +0 -819
  133. package/lib/cjs/theme/tailwind-colors.js +0 -45
  134. package/lib/cjs/theme/tailwind-theme.js +0 -46
  135. package/lib/cjs/tooltip.js +0 -87
  136. package/lib/cjs/tooltip.ws.js +0 -143
  137. package/lib/theme/radix-common-types.js +0 -0
  138. package/lib/theme/tailwind-theme.js +0 -16
  139. package/lib/types/__generated__/button.props.d.ts +0 -2
  140. package/lib/types/__generated__/input.props.d.ts +0 -2
  141. package/lib/types/__generated__/textarea.props.d.ts +0 -2
  142. package/lib/types/theme/radix-common-types.d.ts +0 -85
  143. package/lib/types/theme/tailwind-theme.d.ts +0 -72
  144. package/src/__generated__/accordion.props.ts +0 -2949
  145. package/src/__generated__/button.props.ts +0 -635
  146. package/src/__generated__/checkbox.props.ts +0 -1217
  147. package/src/__generated__/collapsible.props.ts +0 -1156
  148. package/src/__generated__/dialog.props.ts +0 -2923
  149. package/src/__generated__/input.props.ts +0 -748
  150. package/src/__generated__/label.props.ts +0 -585
  151. package/src/__generated__/navigation-menu.props.ts +0 -2882
  152. package/src/__generated__/popover.props.ts +0 -626
  153. package/src/__generated__/radio-group.props.ts +0 -1828
  154. package/src/__generated__/select.props.ts +0 -4130
  155. package/src/__generated__/sheet.props.ts +0 -2942
  156. package/src/__generated__/switch.props.ts +0 -1217
  157. package/src/__generated__/tabs.props.ts +0 -2386
  158. package/src/__generated__/textarea.props.ts +0 -645
  159. package/src/__generated__/tooltip.props.ts +0 -639
  160. package/src/accordion.tsx +0 -88
  161. package/src/accordion.ws.ts +0 -296
  162. package/src/checkbox.stories.ts +0 -22
  163. package/src/checkbox.tsx +0 -22
  164. package/src/checkbox.ws.ts +0 -154
  165. package/src/collapsible.tsx +0 -62
  166. package/src/collapsible.ws.ts +0 -115
  167. package/src/components.ts +0 -50
  168. package/src/dialog.tsx +0 -92
  169. package/src/dialog.ws.tsx +0 -318
  170. package/src/hooks.ts +0 -22
  171. package/src/label.stories.ts +0 -22
  172. package/src/label.tsx +0 -15
  173. package/src/label.ws.ts +0 -50
  174. package/src/metas.ts +0 -74
  175. package/src/navigation-menu.tsx +0 -130
  176. package/src/navigation-menu.ws.ts +0 -524
  177. package/src/popover.tsx +0 -96
  178. package/src/popover.ws.tsx +0 -128
  179. package/src/props-descriptions.ts +0 -43
  180. package/src/props.ts +0 -73
  181. package/src/radio-group.stories.ts +0 -22
  182. package/src/radio-group.tsx +0 -17
  183. package/src/radio-group.ws.ts +0 -178
  184. package/src/select.tsx +0 -112
  185. package/src/select.ws.ts +0 -349
  186. package/src/sheet.tsx +0 -79
  187. package/src/sheet.ws.tsx +0 -236
  188. package/src/switch.stories.ts +0 -22
  189. package/src/switch.tsx +0 -10
  190. package/src/switch.ws.ts +0 -146
  191. package/src/tabs.tsx +0 -64
  192. package/src/tabs.ws.ts +0 -198
  193. package/src/theme/radix-common-types.ts +0 -496
  194. package/src/theme/styles.ts +0 -76
  195. package/src/theme/tailwind-classes.ts +0 -1026
  196. package/src/theme/tailwind-colors.ts +0 -39
  197. package/src/theme/tailwind-theme.ts +0 -24
  198. package/src/tooltip.tsx +0 -95
  199. package/src/tooltip.ws.tsx +0 -130
package/src/accordion.tsx DELETED
@@ -1,88 +0,0 @@
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 ComponentPropsWithoutRef,
6
- type ForwardRefExoticComponent,
7
- type ComponentPropsWithRef,
8
- forwardRef,
9
- } from "react";
10
- import {
11
- Root,
12
- Item,
13
- Header,
14
- Trigger,
15
- Content,
16
- } from "@radix-ui/react-accordion";
17
- import {
18
- getClosestInstance,
19
- getIndexWithinAncestorFromComponentProps,
20
- type Hook,
21
- } from "@webstudio-is/react-sdk";
22
-
23
- export const Accordion = forwardRef<
24
- HTMLDivElement,
25
- Omit<
26
- ComponentPropsWithoutRef<typeof Root>,
27
- "type" | "asChild" | "defaultValue" | "value" | "onValueChange"
28
- > & {
29
- value: string;
30
- onValueChange: (value: string) => void;
31
- }
32
- >((props, ref) => {
33
- return <Root ref={ref} type="single" {...props} />;
34
- });
35
-
36
- export const AccordionItem = forwardRef<
37
- HTMLDivElement,
38
- Omit<ComponentPropsWithoutRef<typeof Item>, "asChild">
39
- >(({ value, ...props }, ref) => {
40
- const index = getIndexWithinAncestorFromComponentProps(props);
41
- return <Item ref={ref} value={value ?? index} {...props} />;
42
- });
43
-
44
- export const AccordionHeader: ForwardRefExoticComponent<
45
- Omit<ComponentPropsWithRef<typeof Header>, "asChild">
46
- > = Header;
47
-
48
- export const AccordionTrigger: ForwardRefExoticComponent<
49
- Omit<ComponentPropsWithRef<typeof Trigger>, "asChild">
50
- > = Trigger;
51
-
52
- export const AccordionContent: ForwardRefExoticComponent<
53
- Omit<ComponentPropsWithRef<typeof Content>, "asChild">
54
- > = Content;
55
-
56
- /* BUILDER HOOKS */
57
-
58
- const namespace = "@webstudio-is/sdk-components-react-radix";
59
-
60
- // For each AccordionContent component within the selection,
61
- // we identify its closest parent Accordion component
62
- // and update its open prop bound to variable.
63
- export const hooksAccordion: Hook = {
64
- onNavigatorSelect: (context, event) => {
65
- for (const instance of event.instancePath) {
66
- if (instance.component === `${namespace}:AccordionContent`) {
67
- const accordion = getClosestInstance(
68
- event.instancePath,
69
- instance,
70
- `${namespace}:Accordion`
71
- );
72
- const item = getClosestInstance(
73
- event.instancePath,
74
- instance,
75
- `${namespace}:AccordionItem`
76
- );
77
- if (accordion && item) {
78
- const itemValue =
79
- context.getPropValue(item.id, "value") ??
80
- context.indexesWithinAncestors.get(item.id)?.toString();
81
- if (itemValue) {
82
- context.setPropVariable(accordion.id, "value", itemValue);
83
- }
84
- }
85
- }
86
- }
87
- },
88
- };
@@ -1,296 +0,0 @@
1
- import {
2
- AccordionIcon,
3
- ItemIcon,
4
- HeaderIcon,
5
- TriggerIcon,
6
- ContentIcon,
7
- ChevronDownIcon,
8
- } from "@webstudio-is/icons/svg";
9
- import {
10
- defaultStates,
11
- type EmbedTemplateStyleDecl,
12
- type PresetStyle,
13
- type WsComponentMeta,
14
- type WsComponentPropsMeta,
15
- type WsEmbedTemplate,
16
- } from "@webstudio-is/react-sdk";
17
- import { div, h3, button } from "@webstudio-is/react-sdk/css-normalize";
18
- import * as tc from "./theme/tailwind-classes";
19
- import { buttonReset } from "./theme/styles";
20
- import {
21
- propsAccordion,
22
- propsAccordionItem,
23
- propsAccordionHeader,
24
- propsAccordionTrigger,
25
- propsAccordionContent,
26
- } from "./__generated__/accordion.props";
27
-
28
- const presetStyle = {
29
- div,
30
- } satisfies PresetStyle<"div">;
31
-
32
- /**
33
- * Styles source without animations:
34
- * https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/accordion.tsx
35
- *
36
- * Attributions
37
- * MIT License
38
- * Copyright (c) 2023 shadcn
39
- **/
40
-
41
- // border-b
42
- const accordionItemStyles: EmbedTemplateStyleDecl[] = [tc.borderB()].flat();
43
-
44
- const createAccordionTrigger = ({
45
- children,
46
- }: {
47
- children: WsEmbedTemplate;
48
- }): WsEmbedTemplate[number] => ({
49
- type: "instance",
50
- component: "AccordionHeader",
51
- // flex
52
- styles: [tc.flex()].flat(),
53
- children: [
54
- {
55
- type: "instance",
56
- component: "AccordionTrigger",
57
- // flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180
58
- styles: [
59
- tc.flex(),
60
- tc.flex(1),
61
- tc.items("center"),
62
- tc.justify("between"),
63
- tc.py(4),
64
- tc.font("medium"),
65
- tc.hover([tc.underline()].flat()),
66
- tc.property("--accordion-trigger-icon-transform", "0deg"),
67
- tc.state(
68
- [tc.property("--accordion-trigger-icon-transform", "180deg")],
69
- "[data-state=open]"
70
- ),
71
- ].flat(),
72
- children: [
73
- {
74
- type: "instance",
75
- component: "Text",
76
- children,
77
- },
78
- {
79
- type: "instance",
80
- component: "Box",
81
- label: "Icon Container",
82
- // h-4 w-4 shrink-0 transition-transform duration-200
83
- styles: [
84
- tc.property("rotate", "--accordion-trigger-icon-transform"),
85
- tc.h(4),
86
- tc.w(4),
87
- tc.shrink(0),
88
- tc.transition("all"),
89
- tc.duration(200),
90
- ].flat(),
91
- children: [
92
- {
93
- type: "instance",
94
- component: "HtmlEmbed",
95
- label: "Chevron Icon",
96
- props: [
97
- {
98
- type: "string",
99
- name: "code",
100
- value: ChevronDownIcon,
101
- },
102
- ],
103
- children: [],
104
- },
105
- ],
106
- },
107
- ],
108
- },
109
- ],
110
- });
111
-
112
- // overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down
113
- // pb-4 pt-0
114
- const accordionContentStyles: EmbedTemplateStyleDecl[] = [
115
- tc.overflow("hidden"),
116
- tc.text("sm"),
117
- // transition does not work with display: none
118
- // tc.transition("all"),
119
- tc.pb(4),
120
- ].flat();
121
-
122
- export const metaAccordion: WsComponentMeta = {
123
- category: "radix",
124
- order: 3,
125
- type: "container",
126
- icon: AccordionIcon,
127
- presetStyle,
128
- description:
129
- "A vertically stacked set of interactive headings that each reveal an associated section of content. Clicking on the heading will open the item and close other items.",
130
- template: [
131
- {
132
- type: "instance",
133
- component: "Accordion",
134
- dataSources: {
135
- accordionValue: { type: "variable", initialValue: "0" },
136
- },
137
- props: [
138
- { type: "boolean", name: "collapsible", value: true },
139
- { type: "dataSource", name: "value", dataSourceName: "accordionValue" },
140
- {
141
- name: "onValueChange",
142
- type: "action",
143
- value: [
144
- {
145
- type: "execute",
146
- args: ["value"],
147
- code: `accordionValue = value`,
148
- },
149
- ],
150
- },
151
- ],
152
- children: [
153
- {
154
- type: "instance",
155
- component: "AccordionItem",
156
- styles: accordionItemStyles,
157
- children: [
158
- createAccordionTrigger({
159
- children: [{ type: "text", value: "Is it accessible?" }],
160
- }),
161
- {
162
- type: "instance",
163
- component: "AccordionContent",
164
- styles: accordionContentStyles,
165
- children: [
166
- {
167
- type: "text",
168
- value: "Yes. It adheres to the WAI-ARIA design pattern.",
169
- },
170
- ],
171
- },
172
- ],
173
- },
174
-
175
- {
176
- type: "instance",
177
- component: "AccordionItem",
178
- styles: accordionItemStyles,
179
- children: [
180
- createAccordionTrigger({
181
- children: [{ type: "text", value: "Is it styled?" }],
182
- }),
183
- {
184
- type: "instance",
185
- component: "AccordionContent",
186
- styles: accordionContentStyles,
187
- children: [
188
- {
189
- type: "text",
190
- value:
191
- "Yes. It comes with default styles that matches the other components' aesthetic.",
192
- },
193
- ],
194
- },
195
- ],
196
- },
197
-
198
- {
199
- type: "instance",
200
- component: "AccordionItem",
201
- styles: accordionItemStyles,
202
- children: [
203
- createAccordionTrigger({
204
- children: [{ type: "text", value: "Is it animated?" }],
205
- }),
206
- {
207
- type: "instance",
208
- component: "AccordionContent",
209
- styles: accordionContentStyles,
210
- children: [
211
- {
212
- type: "text",
213
- value:
214
- "Yes. It's animated by default, but you can disable it if you prefer.",
215
- },
216
- ],
217
- },
218
- ],
219
- },
220
- ],
221
- },
222
- ],
223
- };
224
-
225
- export const metaAccordionItem: WsComponentMeta = {
226
- category: "hidden",
227
- type: "container",
228
- label: "Item",
229
- icon: ItemIcon,
230
- requiredAncestors: ["Accordion"],
231
- indexWithinAncestor: "Accordion",
232
- presetStyle,
233
- };
234
-
235
- export const metaAccordionHeader: WsComponentMeta = {
236
- category: "hidden",
237
- type: "container",
238
- label: "Item Header",
239
- icon: HeaderIcon,
240
- requiredAncestors: ["AccordionItem"],
241
- detachable: false,
242
- presetStyle: {
243
- h3: [h3, tc.my(0)].flat(),
244
- },
245
- };
246
-
247
- export const metaAccordionTrigger: WsComponentMeta = {
248
- category: "hidden",
249
- type: "container",
250
- label: "Item Trigger",
251
- icon: TriggerIcon,
252
- requiredAncestors: ["AccordionHeader"],
253
- detachable: false,
254
- states: [
255
- ...defaultStates,
256
- {
257
- category: "component-states",
258
- label: "Open",
259
- selector: "[data-state=open]",
260
- },
261
- ],
262
- presetStyle: {
263
- button: [button, buttonReset].flat(),
264
- },
265
- };
266
-
267
- export const metaAccordionContent: WsComponentMeta = {
268
- category: "hidden",
269
- type: "container",
270
- label: "Item Content",
271
- icon: ContentIcon,
272
- requiredAncestors: ["AccordionItem"],
273
- detachable: false,
274
- presetStyle,
275
- };
276
-
277
- export const propsMetaAccordion: WsComponentPropsMeta = {
278
- props: propsAccordion,
279
- initialProps: ["value", "collapsible"],
280
- };
281
-
282
- export const propsMetaAccordionItem: WsComponentPropsMeta = {
283
- props: propsAccordionItem,
284
- };
285
-
286
- export const propsMetaAccordionHeader: WsComponentPropsMeta = {
287
- props: propsAccordionHeader,
288
- };
289
-
290
- export const propsMetaAccordionTrigger: WsComponentPropsMeta = {
291
- props: propsAccordionTrigger,
292
- };
293
-
294
- export const propsMetaAccordionContent: WsComponentPropsMeta = {
295
- props: propsAccordionContent,
296
- };
@@ -1,22 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/react";
2
- import { renderComponentTemplate } from "@webstudio-is/react-sdk";
3
- import * as baseComponents from "@webstudio-is/sdk-components-react";
4
- import * as baseMetas from "@webstudio-is/sdk-components-react/metas";
5
- import * as radixComponents from "./components";
6
- import * as radixMetas from "./metas";
7
- import { Checkbox as CheckboxPrimitive } from "./checkbox";
8
-
9
- export default {
10
- title: "Components/Checkbox",
11
- component: CheckboxPrimitive,
12
- } satisfies Meta<typeof CheckboxPrimitive>;
13
-
14
- export const Checkbox: StoryObj<typeof CheckboxPrimitive> = {
15
- render: (props) =>
16
- renderComponentTemplate({
17
- name: "Checkbox",
18
- props: { ...props },
19
- components: { ...baseComponents, ...radixComponents },
20
- metas: { ...baseMetas, ...radixMetas },
21
- }),
22
- };
package/src/checkbox.tsx DELETED
@@ -1,22 +0,0 @@
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
- forwardRef,
8
- } from "react";
9
- import { Root, Indicator } from "@radix-ui/react-checkbox";
10
-
11
- export const Checkbox = forwardRef<
12
- HTMLButtonElement,
13
- // radix checked has complex named type which cannot be parsed
14
- // cast to boolean
15
- Omit<ComponentPropsWithRef<typeof Root>, "checked"> & { checked: boolean }
16
- >((props, ref) => {
17
- return <Root ref={ref} {...props} />;
18
- });
19
-
20
- export const CheckboxIndicator: ForwardRefExoticComponent<
21
- ComponentPropsWithRef<typeof Indicator>
22
- > = Indicator;
@@ -1,154 +0,0 @@
1
- import {
2
- CheckMarkIcon,
3
- CheckboxCheckedIcon,
4
- TriggerIcon,
5
- } from "@webstudio-is/icons/svg";
6
- import {
7
- defaultStates,
8
- type WsComponentMeta,
9
- type WsComponentPropsMeta,
10
- } from "@webstudio-is/react-sdk";
11
- import { button, span } from "@webstudio-is/react-sdk/css-normalize";
12
- import * as tc from "./theme/tailwind-classes";
13
- import { buttonReset } from "./theme/styles";
14
- import {
15
- propsCheckbox,
16
- propsCheckboxIndicator,
17
- } from "./__generated__/checkbox.props";
18
-
19
- export const metaCheckbox: WsComponentMeta = {
20
- category: "radix",
21
- order: 101,
22
- type: "container",
23
- icon: CheckboxCheckedIcon,
24
- description:
25
- "Use within a form to allow your users to toggle between checked and not checked. Group checkboxes by matching their “Name” properties. Unlike radios, any number of checkboxes in a group can be checked.",
26
- states: [
27
- ...defaultStates,
28
- {
29
- label: "Checked",
30
- selector: "[data-state=checked]",
31
- category: "component-states",
32
- },
33
- {
34
- label: "Unchecked",
35
- selector: "[data-state=unchecked]",
36
- category: "component-states",
37
- },
38
- ],
39
- presetStyle: {
40
- button: [button, buttonReset].flat(),
41
- },
42
- template: [
43
- {
44
- type: "instance",
45
- component: "Label",
46
- label: "Checkbox Field",
47
- styles: [tc.flex(), tc.gap(2), tc.items("center")].flat(),
48
- children: [
49
- {
50
- type: "instance",
51
- component: "Checkbox",
52
- dataSources: {
53
- checkboxChecked: { type: "variable", initialValue: false },
54
- },
55
- props: [
56
- {
57
- name: "checked",
58
- type: "dataSource",
59
- dataSourceName: "checkboxChecked",
60
- },
61
- {
62
- name: "onCheckedChange",
63
- type: "action",
64
- value: [
65
- {
66
- type: "execute",
67
- args: ["checked"],
68
- code: `checkboxChecked = checked`,
69
- },
70
- ],
71
- },
72
- ],
73
- // peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background
74
- // focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2
75
- // disabled:cursor-not-allowed disabled:opacity-50
76
- // data-[state=checked]:bg-primary
77
- // data-[state=checked]:text-primary-foreground",
78
- styles: [
79
- // We are not supporting peer like styles yet
80
- tc.h(4),
81
- tc.w(4),
82
- tc.shrink(0),
83
- tc.rounded("sm"),
84
- tc.border(),
85
- tc.border("primary"),
86
- tc.focusVisible(
87
- [tc.outline("none"), tc.ring("ring", 2, "background", 2)].flat()
88
- ),
89
- tc.disabled([tc.cursor("not-allowed"), tc.opacity(50)].flat()),
90
- tc.state(
91
- [tc.bg("primary"), tc.text("primaryForeground")].flat(),
92
- "[data-state=checked]"
93
- ),
94
- ].flat(),
95
- children: [
96
- {
97
- type: "instance",
98
- component: "CheckboxIndicator",
99
- // flex items-center justify-center text-current
100
- styles: [
101
- tc.flex(),
102
- tc.items("center"),
103
- tc.justify("center"),
104
- tc.text("current"),
105
- ].flat(),
106
- children: [
107
- {
108
- type: "instance",
109
- component: "HtmlEmbed",
110
- label: "Indicator Icon",
111
- props: [
112
- {
113
- type: "string",
114
- name: "code",
115
- value: CheckMarkIcon,
116
- },
117
- ],
118
- children: [],
119
- },
120
- ],
121
- },
122
- ],
123
- },
124
- {
125
- type: "instance",
126
- component: "Text",
127
- label: "Checkbox Label",
128
- props: [{ name: "tag", type: "string", value: "span" }],
129
- children: [{ type: "text", value: "Checkbox" }],
130
- },
131
- ],
132
- },
133
- ],
134
- };
135
-
136
- export const metaCheckboxIndicator: WsComponentMeta = {
137
- category: "hidden",
138
- type: "container",
139
- detachable: false,
140
- icon: TriggerIcon,
141
- states: defaultStates,
142
- presetStyle: {
143
- span,
144
- },
145
- };
146
-
147
- export const propsMetaCheckbox: WsComponentPropsMeta = {
148
- props: propsCheckbox,
149
- initialProps: ["id", "checked", "name", "required"],
150
- };
151
-
152
- export const propsMetaCheckboxIndicator: WsComponentPropsMeta = {
153
- props: propsCheckboxIndicator,
154
- };
@@ -1,62 +0,0 @@
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 ReactNode,
6
- type ForwardRefExoticComponent,
7
- type ComponentPropsWithRef,
8
- forwardRef,
9
- Children,
10
- } from "react";
11
- import { Root, Trigger, Content } from "@radix-ui/react-collapsible";
12
- import { type Hook, getClosestInstance } from "@webstudio-is/react-sdk";
13
-
14
- export const Collapsible: ForwardRefExoticComponent<
15
- Omit<ComponentPropsWithRef<typeof Root>, "defaultOpen" | "asChild">
16
- > = Root;
17
-
18
- /**
19
- * We're not exposing the 'asChild' property for the Trigger.
20
- * Instead, we're enforcing 'asChild=true' for the Trigger and making it style-less.
21
- * This avoids situations where the Trigger inadvertently passes all styles to its child,
22
- * which would prevent us from displaying styles properly in the builder.
23
- */
24
- export const CollapsibleTrigger = forwardRef<
25
- HTMLButtonElement,
26
- { children: ReactNode }
27
- >(({ children, ...props }, ref) => {
28
- const firstChild = Children.toArray(children)[0];
29
- return (
30
- <Trigger asChild={true} ref={ref} {...props}>
31
- {firstChild ?? <button>Add button</button>}
32
- </Trigger>
33
- );
34
- });
35
-
36
- export const CollapsibleContent: ForwardRefExoticComponent<
37
- Omit<ComponentPropsWithRef<typeof Content>, "asChild">
38
- > = Content;
39
-
40
- /* BUILDER HOOKS */
41
-
42
- const namespace = "@webstudio-is/sdk-components-react-radix";
43
-
44
- // For each CollapsibleContent component within the selection,
45
- // we identify its closest parent Collapsible component
46
- // and update its open prop bound to variable.
47
- export const hooksCollapsible: Hook = {
48
- onNavigatorSelect: (context, event) => {
49
- for (const instance of event.instancePath) {
50
- if (instance.component === `${namespace}:CollapsibleContent`) {
51
- const collapsible = getClosestInstance(
52
- event.instancePath,
53
- instance,
54
- `${namespace}:Collapsible`
55
- );
56
- if (collapsible) {
57
- context.setPropVariable(collapsible.id, "open", true);
58
- }
59
- }
60
- }
61
- },
62
- };