@webstudio-is/sdk-components-react-radix 0.82.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/LICENSE +661 -0
- package/README.md +4 -0
- package/lib/__generated__/collapsible.props.js +840 -0
- package/lib/cjs/__generated__/collapsible.props.js +860 -0
- package/lib/cjs/collapsible.js +37 -0
- package/lib/cjs/collapsible.ws.js +120 -0
- package/lib/cjs/components.js +26 -0
- package/lib/cjs/metas.js +26 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/props.js +26 -0
- package/lib/collapsible.js +22 -0
- package/lib/collapsible.ws.js +104 -0
- package/lib/components.js +10 -0
- package/lib/metas.js +10 -0
- package/lib/props.js +10 -0
- package/lib/types/__generated__/collapsible.props.d.ts +4 -0
- package/lib/types/collapsible.d.ts +14 -0
- package/lib/types/collapsible.ws.d.ts +7 -0
- package/lib/types/components.d.ts +1 -0
- package/lib/types/metas.d.ts +1 -0
- package/lib/types/props.d.ts +1 -0
- package/package.json +62 -0
- package/src/__generated__/collapsible.props.ts +937 -0
- package/src/collapsible.tsx +53 -0
- package/src/collapsible.ws.ts +106 -0
- package/src/components.ts +5 -0
- package/src/metas.ts +5 -0
- package/src/props.ts +5 -0
|
@@ -0,0 +1,53 @@
|
|
|
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 {
|
|
13
|
+
type WebstudioAttributes,
|
|
14
|
+
splitPropsWithWebstudioAttributes,
|
|
15
|
+
} from "@webstudio-is/react-sdk";
|
|
16
|
+
|
|
17
|
+
export const Collapsible: ForwardRefExoticComponent<
|
|
18
|
+
Omit<ComponentPropsWithRef<typeof Root>, "defaultOpen" | "asChild">
|
|
19
|
+
> = Root;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* CollapsibleTrigger is HTML-less components.
|
|
23
|
+
* To make them work in our system, we wrap their attributes with a div that has a display: contents property.
|
|
24
|
+
*
|
|
25
|
+
* These divs function like fragments, with all web studio-related attributes attached to them.
|
|
26
|
+
*/
|
|
27
|
+
const displayContentsStyle = { display: "contents" };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* We're not exposing the 'asChild' property for the Trigger.
|
|
31
|
+
* Instead, we're enforcing 'asChild=true' for the Trigger and making it style-less.
|
|
32
|
+
* This avoids situations where the Trigger inadvertently passes all styles to its child,
|
|
33
|
+
* which would prevent us from displaying styles properly in the builder.
|
|
34
|
+
*/
|
|
35
|
+
export const CollapsibleTrigger = forwardRef<
|
|
36
|
+
HTMLDivElement,
|
|
37
|
+
WebstudioAttributes & { children: ReactNode }
|
|
38
|
+
>(({ children, ...props }, ref) => {
|
|
39
|
+
const firstChild = Children.toArray(children)[0];
|
|
40
|
+
const [webstudioAttributes, restProps] =
|
|
41
|
+
splitPropsWithWebstudioAttributes(props);
|
|
42
|
+
return (
|
|
43
|
+
<div ref={ref} style={displayContentsStyle} {...webstudioAttributes}>
|
|
44
|
+
<Trigger asChild={true} {...restProps}>
|
|
45
|
+
{firstChild ?? <button>Add button</button>}
|
|
46
|
+
</Trigger>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export const CollapsibleContent: ForwardRefExoticComponent<
|
|
52
|
+
Omit<ComponentPropsWithRef<typeof Content>, "asChild">
|
|
53
|
+
> = Content;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { RadioUncheckedIcon, RadioCheckedIcon } from "@webstudio-is/icons/svg";
|
|
2
|
+
import type {
|
|
3
|
+
WsComponentMeta,
|
|
4
|
+
WsComponentPropsMeta,
|
|
5
|
+
} from "@webstudio-is/react-sdk";
|
|
6
|
+
import {
|
|
7
|
+
propsCollapsible,
|
|
8
|
+
propsCollapsibleContent,
|
|
9
|
+
propsCollapsibleTrigger,
|
|
10
|
+
} from "./__generated__/collapsible.props";
|
|
11
|
+
|
|
12
|
+
export const metaCollapsible: WsComponentMeta = {
|
|
13
|
+
category: "radix",
|
|
14
|
+
type: "container",
|
|
15
|
+
label: "Collapsible",
|
|
16
|
+
icon: RadioUncheckedIcon,
|
|
17
|
+
template: [
|
|
18
|
+
{
|
|
19
|
+
type: "instance",
|
|
20
|
+
component: "Collapsible",
|
|
21
|
+
props: [
|
|
22
|
+
{
|
|
23
|
+
name: "open",
|
|
24
|
+
type: "boolean",
|
|
25
|
+
value: false,
|
|
26
|
+
dataSourceRef: {
|
|
27
|
+
type: "variable",
|
|
28
|
+
name: "collapsibleOpen",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "onOpenChange",
|
|
33
|
+
type: "action",
|
|
34
|
+
value: [
|
|
35
|
+
{
|
|
36
|
+
type: "execute",
|
|
37
|
+
args: ["open"],
|
|
38
|
+
code: `collapsibleOpen = open`,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
children: [
|
|
44
|
+
{
|
|
45
|
+
type: "instance",
|
|
46
|
+
component: "CollapsibleTrigger",
|
|
47
|
+
children: [
|
|
48
|
+
{
|
|
49
|
+
type: "instance",
|
|
50
|
+
component: "Button",
|
|
51
|
+
children: [{ type: "text", value: "Click to toggle content" }],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: "instance",
|
|
57
|
+
component: "CollapsibleContent",
|
|
58
|
+
children: [
|
|
59
|
+
{
|
|
60
|
+
type: "instance",
|
|
61
|
+
component: "Text",
|
|
62
|
+
children: [{ type: "text", value: "Collapsible Content" }],
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const metaCollapsibleTrigger: WsComponentMeta = {
|
|
72
|
+
category: "hidden",
|
|
73
|
+
type: "container",
|
|
74
|
+
label: "Collapsible Trigger",
|
|
75
|
+
icon: RadioCheckedIcon,
|
|
76
|
+
stylable: false,
|
|
77
|
+
detachable: false,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const metaCollapsibleContent: WsComponentMeta = {
|
|
81
|
+
category: "hidden",
|
|
82
|
+
type: "container",
|
|
83
|
+
label: "Collapsible Content",
|
|
84
|
+
icon: RadioCheckedIcon,
|
|
85
|
+
detachable: false,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const propsMetaCollapsible: WsComponentPropsMeta = {
|
|
89
|
+
props: {
|
|
90
|
+
...propsCollapsible,
|
|
91
|
+
onOpenChange: {
|
|
92
|
+
type: "action",
|
|
93
|
+
control: "action",
|
|
94
|
+
required: false,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
initialProps: ["open", "onOpenChange"],
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const propsMetaCollapsibleTrigger: WsComponentPropsMeta = {
|
|
101
|
+
props: propsCollapsibleTrigger,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const propsMetaCollapsibleContent: WsComponentPropsMeta = {
|
|
105
|
+
props: propsCollapsibleContent,
|
|
106
|
+
};
|
package/src/metas.ts
ADDED