@webstudio-is/sdk-components-react-radix 0.83.0 → 0.85.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__/dialog.props.js +2120 -0
- package/lib/__generated__/popover.props.js +468 -0
- package/lib/__generated__/sheet.props.js +2159 -0
- package/lib/__generated__/tabs.props.js +1286 -0
- package/lib/__generated__/tooltip.props.js +478 -0
- package/lib/cjs/__generated__/dialog.props.js +2140 -0
- package/lib/cjs/__generated__/popover.props.js +488 -0
- package/lib/cjs/__generated__/sheet.props.js +2179 -0
- package/lib/cjs/__generated__/tabs.props.js +1306 -0
- package/lib/cjs/__generated__/tooltip.props.js +498 -0
- package/lib/cjs/collapsible.js +34 -4
- package/lib/cjs/collapsible.ws.js +14 -9
- package/lib/cjs/components.js +30 -1
- package/lib/cjs/dialog.js +57 -0
- package/lib/cjs/dialog.ws.js +311 -0
- package/lib/cjs/hooks.js +25 -0
- package/lib/cjs/metas.js +30 -1
- package/lib/cjs/popover.js +58 -0
- package/lib/cjs/popover.ws.js +141 -0
- package/lib/cjs/props.js +30 -1
- package/lib/cjs/sheet.js +63 -0
- package/lib/cjs/sheet.ws.js +317 -0
- package/lib/cjs/tabs.js +41 -0
- package/lib/cjs/tabs.ws.js +213 -0
- package/lib/cjs/theme/radix-common-types.js +16 -0
- package/lib/cjs/theme/tailwind-classes.js +547 -0
- package/lib/cjs/theme/tailwind-colors.js +35 -0
- package/lib/cjs/theme/tailwind-theme.js +46 -0
- package/lib/cjs/tooltip.js +55 -0
- package/lib/cjs/tooltip.ws.js +142 -0
- package/lib/collapsible.js +35 -7
- package/lib/collapsible.ws.js +19 -10
- package/lib/components.js +46 -1
- package/lib/dialog.js +30 -0
- package/lib/dialog.ws.js +298 -0
- package/lib/hooks.js +5 -0
- package/lib/metas.js +59 -1
- package/lib/popover.js +31 -0
- package/lib/popover.ws.js +116 -0
- package/lib/props.js +59 -1
- package/lib/sheet.js +35 -0
- package/lib/sheet.ws.js +304 -0
- package/lib/tabs.js +24 -0
- package/lib/tabs.ws.js +193 -0
- package/lib/theme/radix-common-types.js +0 -0
- package/lib/theme/tailwind-classes.js +527 -0
- package/lib/theme/tailwind-colors.js +15 -0
- package/lib/theme/tailwind-theme.js +16 -0
- package/lib/tooltip.js +28 -0
- package/lib/tooltip.ws.js +117 -0
- package/lib/types/__generated__/dialog.props.d.ts +8 -0
- package/lib/types/__generated__/popover.props.d.ts +4 -0
- package/lib/types/__generated__/sheet.props.d.ts +8 -0
- package/lib/types/__generated__/tabs.props.d.ts +5 -0
- package/lib/types/__generated__/tooltip.props.d.ts +4 -0
- package/lib/types/collapsible.d.ts +4 -3
- package/lib/types/components.d.ts +5 -0
- package/lib/types/dialog.d.ts +25 -0
- package/lib/types/dialog.ws.d.ts +23 -0
- package/lib/types/hooks.d.ts +2 -0
- package/lib/types/metas.d.ts +5 -0
- package/lib/types/popover.d.ts +21 -0
- package/lib/types/popover.ws.d.ts +15 -0
- package/lib/types/props.d.ts +5 -0
- package/lib/types/sheet.d.ts +15 -0
- package/lib/types/sheet.ws.d.ts +23 -0
- package/lib/types/tabs.d.ts +15 -0
- package/lib/types/tabs.ws.d.ts +9 -0
- package/lib/types/theme/radix-common-types.d.ts +84 -0
- package/lib/types/theme/tailwind-classes.d.ts +83 -0
- package/lib/types/theme/tailwind-colors.d.ts +21 -0
- package/lib/types/theme/tailwind-theme.d.ts +72 -0
- package/lib/types/tooltip.d.ts +21 -0
- package/lib/types/tooltip.ws.d.ts +15 -0
- package/package.json +23 -6
- package/src/__generated__/dialog.props.ts +2363 -0
- package/src/__generated__/popover.props.ts +515 -0
- package/src/__generated__/sheet.props.ts +2402 -0
- package/src/__generated__/tabs.props.ts +1434 -0
- package/src/__generated__/tooltip.props.ts +526 -0
- package/src/collapsible.stories.tsx +21 -0
- package/src/collapsible.tsx +44 -21
- package/src/collapsible.ws.ts +21 -10
- package/src/components.ts +21 -0
- package/src/dialog.tsx +66 -0
- package/src/dialog.ws.tsx +315 -0
- package/src/hooks.ts +4 -0
- package/src/metas.ts +34 -0
- package/src/popover.tsx +70 -0
- package/src/popover.ws.tsx +127 -0
- package/src/props.ts +34 -0
- package/src/sheet.stories.tsx +21 -0
- package/src/sheet.tsx +40 -0
- package/src/sheet.ws.tsx +326 -0
- package/src/tabs.stories.tsx +21 -0
- package/src/tabs.tsx +46 -0
- package/src/tabs.ws.ts +211 -0
- package/src/theme/radix-common-types.ts +495 -0
- package/src/theme/tailwind-classes.ts +695 -0
- package/src/theme/tailwind-colors.ts +45 -0
- package/src/theme/tailwind-theme.ts +24 -0
- package/src/tooltip.tsx +69 -0
- package/src/tooltip.ws.tsx +128 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { PopoverIcon, TriggerIcon, ContentIcon } from "@webstudio-is/icons/svg";
|
|
2
|
+
import {
|
|
3
|
+
type PresetStyle,
|
|
4
|
+
type WsComponentMeta,
|
|
5
|
+
type WsComponentPropsMeta,
|
|
6
|
+
} from "@webstudio-is/react-sdk";
|
|
7
|
+
import * as tc from "./theme/tailwind-classes";
|
|
8
|
+
import {
|
|
9
|
+
propsPopover,
|
|
10
|
+
propsPopoverContent,
|
|
11
|
+
propsPopoverTrigger,
|
|
12
|
+
} from "./__generated__/popover.props";
|
|
13
|
+
import { div } from "@webstudio-is/react-sdk/css-normalize";
|
|
14
|
+
|
|
15
|
+
const presetStyle = {
|
|
16
|
+
div,
|
|
17
|
+
} satisfies PresetStyle<"div">;
|
|
18
|
+
|
|
19
|
+
// @todo add [data-state] to button and link
|
|
20
|
+
export const metaPopoverTrigger: WsComponentMeta = {
|
|
21
|
+
category: "hidden",
|
|
22
|
+
invalidAncestors: [],
|
|
23
|
+
type: "container",
|
|
24
|
+
label: "Popover Trigger",
|
|
25
|
+
icon: TriggerIcon,
|
|
26
|
+
stylable: false,
|
|
27
|
+
detachable: false,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const metaPopoverContent: WsComponentMeta = {
|
|
31
|
+
category: "hidden",
|
|
32
|
+
invalidAncestors: [],
|
|
33
|
+
type: "container",
|
|
34
|
+
presetStyle,
|
|
35
|
+
label: "Popover Content",
|
|
36
|
+
icon: ContentIcon,
|
|
37
|
+
detachable: false,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Styles source without animations:
|
|
42
|
+
* https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/popover.tsx
|
|
43
|
+
*
|
|
44
|
+
* Attributions
|
|
45
|
+
* MIT License
|
|
46
|
+
* Copyright (c) 2023 shadcn
|
|
47
|
+
**/
|
|
48
|
+
export const metaPopover: WsComponentMeta = {
|
|
49
|
+
category: "radix",
|
|
50
|
+
invalidAncestors: [],
|
|
51
|
+
type: "container",
|
|
52
|
+
label: "Popover",
|
|
53
|
+
icon: PopoverIcon,
|
|
54
|
+
order: 15,
|
|
55
|
+
stylable: false,
|
|
56
|
+
template: [
|
|
57
|
+
{
|
|
58
|
+
type: "instance",
|
|
59
|
+
component: "Popover",
|
|
60
|
+
dataSources: {
|
|
61
|
+
// We don't have support for boolean or undefined, instead of binding on open we bind on a string
|
|
62
|
+
isOpen: { type: "variable", initialValue: "initial" },
|
|
63
|
+
},
|
|
64
|
+
props: [
|
|
65
|
+
{
|
|
66
|
+
type: "dataSource",
|
|
67
|
+
name: "isOpen",
|
|
68
|
+
dataSourceName: "isOpen",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
children: [
|
|
72
|
+
{
|
|
73
|
+
type: "instance",
|
|
74
|
+
component: "PopoverTrigger",
|
|
75
|
+
props: [],
|
|
76
|
+
children: [
|
|
77
|
+
{
|
|
78
|
+
type: "instance",
|
|
79
|
+
component: "Button",
|
|
80
|
+
children: [{ type: "text", value: "Button" }],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: "instance",
|
|
86
|
+
component: "PopoverContent",
|
|
87
|
+
props: [],
|
|
88
|
+
/**
|
|
89
|
+
* z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none
|
|
90
|
+
**/
|
|
91
|
+
styles: [
|
|
92
|
+
tc.z(50),
|
|
93
|
+
tc.w(72),
|
|
94
|
+
tc.rounded("md"),
|
|
95
|
+
tc.border(),
|
|
96
|
+
tc.bg("popover"),
|
|
97
|
+
tc.p(4),
|
|
98
|
+
tc.text("popoverForeground"),
|
|
99
|
+
tc.shadow("md"),
|
|
100
|
+
tc.outline("none"),
|
|
101
|
+
].flat(),
|
|
102
|
+
children: [
|
|
103
|
+
{
|
|
104
|
+
type: "instance",
|
|
105
|
+
component: "Text",
|
|
106
|
+
children: [{ type: "text", value: "The text you can edit" }],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const propsMetaPopover: WsComponentPropsMeta = {
|
|
116
|
+
props: propsPopover,
|
|
117
|
+
initialProps: ["isOpen", "modal"],
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const propsMetaPopoverTrigger: WsComponentPropsMeta = {
|
|
121
|
+
props: propsPopoverTrigger,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const propsMetaPopoverContent: WsComponentPropsMeta = {
|
|
125
|
+
props: propsPopoverContent,
|
|
126
|
+
initialProps: ["side", "sideOffset", "align", "alignOffset"],
|
|
127
|
+
};
|
package/src/props.ts
CHANGED
|
@@ -3,3 +3,37 @@ export {
|
|
|
3
3
|
propsMetaCollapsibleTrigger as CollapsibleTrigger,
|
|
4
4
|
propsMetaCollapsibleContent as CollapsibleContent,
|
|
5
5
|
} from "./collapsible.ws";
|
|
6
|
+
export {
|
|
7
|
+
propsMetaDialog as Dialog,
|
|
8
|
+
propsMetaDialogTrigger as DialogTrigger,
|
|
9
|
+
propsMetaDialogOverlay as DialogOverlay,
|
|
10
|
+
propsMetaDialogContent as DialogContent,
|
|
11
|
+
propsMetaDialogClose as DialogClose,
|
|
12
|
+
propsMetaDialogTitle as DialogTitle,
|
|
13
|
+
propsMetaDialogDescription as DialogDescription,
|
|
14
|
+
} from "./dialog.ws";
|
|
15
|
+
export {
|
|
16
|
+
propsMetaPopover as Popover,
|
|
17
|
+
propsMetaPopoverTrigger as PopoverTrigger,
|
|
18
|
+
propsMetaPopoverContent as PopoverContent,
|
|
19
|
+
} from "./popover.ws";
|
|
20
|
+
export {
|
|
21
|
+
propsMetaTooltip as Tooltip,
|
|
22
|
+
propsMetaTooltipTrigger as TooltipTrigger,
|
|
23
|
+
propsMetaTooltipContent as TooltipContent,
|
|
24
|
+
} from "./tooltip.ws";
|
|
25
|
+
export {
|
|
26
|
+
propsMetaSheet as Sheet,
|
|
27
|
+
propsMetaSheetTrigger as SheetTrigger,
|
|
28
|
+
propsMetaSheetOverlay as SheetOverlay,
|
|
29
|
+
propsMetaSheetContent as SheetContent,
|
|
30
|
+
propsMetaSheetClose as SheetClose,
|
|
31
|
+
propsMetaSheetTitle as SheetTitle,
|
|
32
|
+
propsMetaSheetDescription as SheetDescription,
|
|
33
|
+
} from "./sheet.ws";
|
|
34
|
+
export {
|
|
35
|
+
propsMetaTabs as Tabs,
|
|
36
|
+
propsMetaTabsList as TabsList,
|
|
37
|
+
propsMetaTabsTrigger as TabsTrigger,
|
|
38
|
+
propsMetaTabsContent as TabsContent,
|
|
39
|
+
} from "./tabs.ws";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { renderComponentTemplate } from "@webstudio-is/react-sdk";
|
|
3
|
+
import { Sheet as SheetPrimitive } from "./sheet";
|
|
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/Sheet",
|
|
11
|
+
component: SheetPrimitive,
|
|
12
|
+
} satisfies Meta<typeof SheetPrimitive>;
|
|
13
|
+
|
|
14
|
+
export const Sheet: StoryObj<typeof SheetPrimitive> = {
|
|
15
|
+
render: () =>
|
|
16
|
+
renderComponentTemplate({
|
|
17
|
+
name: "Sheet",
|
|
18
|
+
components: { ...baseComponents, ...radixComponents },
|
|
19
|
+
metas: { ...baseMetas, ...radixMetas },
|
|
20
|
+
}),
|
|
21
|
+
};
|
package/src/sheet.tsx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
forwardRef,
|
|
3
|
+
type ElementRef,
|
|
4
|
+
type ComponentPropsWithoutRef,
|
|
5
|
+
} from "react";
|
|
6
|
+
import * as Dialog from "./dialog";
|
|
7
|
+
|
|
8
|
+
export const Sheet = Dialog.Dialog;
|
|
9
|
+
export const SheetTrigger = Dialog.DialogTrigger;
|
|
10
|
+
export const SheetOverlay = Dialog.DialogOverlay;
|
|
11
|
+
export const SheetClose = Dialog.DialogClose;
|
|
12
|
+
export const SheetTitle = Dialog.DialogTitle;
|
|
13
|
+
export const SheetDescription = Dialog.DialogDescription;
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line react/display-name
|
|
16
|
+
export const SheetContent = forwardRef<
|
|
17
|
+
ElementRef<"div">,
|
|
18
|
+
ComponentPropsWithoutRef<typeof Dialog.DialogContent> & {
|
|
19
|
+
tag?: "div" | "nav";
|
|
20
|
+
side?: "top" | "right" | "bottom" | "left";
|
|
21
|
+
}
|
|
22
|
+
>(
|
|
23
|
+
(
|
|
24
|
+
{ tag = "nav", side = "left", role = "navigation", children, ...props },
|
|
25
|
+
ref
|
|
26
|
+
) => {
|
|
27
|
+
// Do not do this at args like { tag: Tag = "nav" }, generate-arg-types will not find defaultValue in that case
|
|
28
|
+
const Tag = tag;
|
|
29
|
+
return (
|
|
30
|
+
<Dialog.DialogContent
|
|
31
|
+
asChild={true}
|
|
32
|
+
data-side={side}
|
|
33
|
+
role={role}
|
|
34
|
+
{...props}
|
|
35
|
+
>
|
|
36
|
+
<Tag ref={ref}>{children}</Tag>
|
|
37
|
+
</Dialog.DialogContent>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
);
|
package/src/sheet.ws.tsx
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
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";
|
|
15
|
+
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
|
+
|
|
29
|
+
type ContentTags = NonNullable<ComponentProps<typeof SheetContent>["tag"]>;
|
|
30
|
+
|
|
31
|
+
const contentPresetStyle = {
|
|
32
|
+
div,
|
|
33
|
+
nav,
|
|
34
|
+
} satisfies PresetStyle<ContentTags>;
|
|
35
|
+
|
|
36
|
+
const presetStyle = {
|
|
37
|
+
div,
|
|
38
|
+
} satisfies PresetStyle<"div">;
|
|
39
|
+
|
|
40
|
+
const buttonPresetStyle = {
|
|
41
|
+
button,
|
|
42
|
+
} satisfies PresetStyle<"button">;
|
|
43
|
+
|
|
44
|
+
const titlePresetStyle = {
|
|
45
|
+
h2,
|
|
46
|
+
} satisfies PresetStyle<"h2">;
|
|
47
|
+
|
|
48
|
+
const descriptionPresetStyle = {
|
|
49
|
+
p,
|
|
50
|
+
} satisfies PresetStyle<"p">;
|
|
51
|
+
|
|
52
|
+
// @todo add [data-state] to button and link
|
|
53
|
+
export const metaSheetTrigger: WsComponentMeta = {
|
|
54
|
+
category: "hidden",
|
|
55
|
+
type: "container",
|
|
56
|
+
label: "Sheet Trigger",
|
|
57
|
+
icon: TriggerIcon,
|
|
58
|
+
stylable: false,
|
|
59
|
+
detachable: false,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const metaSheetContent: WsComponentMeta = {
|
|
63
|
+
category: "hidden",
|
|
64
|
+
type: "container",
|
|
65
|
+
label: "Sheet Content",
|
|
66
|
+
icon: ContentIcon,
|
|
67
|
+
detachable: false,
|
|
68
|
+
presetStyle: contentPresetStyle,
|
|
69
|
+
states: [
|
|
70
|
+
{ selector: "[data-side=top]", label: "Top Side" },
|
|
71
|
+
{ selector: "[data-side=right]", label: "Right Side" },
|
|
72
|
+
{ selector: "[data-side=bottom]", label: "Bottom Side" },
|
|
73
|
+
{ selector: "[data-side=left]", label: "Left Side" },
|
|
74
|
+
],
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const metaSheetOverlay: WsComponentMeta = {
|
|
78
|
+
category: "hidden",
|
|
79
|
+
type: "container",
|
|
80
|
+
presetStyle,
|
|
81
|
+
label: "Sheet Overlay",
|
|
82
|
+
icon: OverlayIcon,
|
|
83
|
+
detachable: false,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const metaSheetTitle: WsComponentMeta = {
|
|
87
|
+
category: "hidden",
|
|
88
|
+
type: "container",
|
|
89
|
+
presetStyle: titlePresetStyle,
|
|
90
|
+
label: "Sheet Title",
|
|
91
|
+
icon: HeadingIcon,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const metaSheetDescription: WsComponentMeta = {
|
|
95
|
+
category: "hidden",
|
|
96
|
+
type: "container",
|
|
97
|
+
presetStyle: descriptionPresetStyle,
|
|
98
|
+
label: "Sheet Description",
|
|
99
|
+
icon: TextIcon,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const metaSheetClose: WsComponentMeta = {
|
|
103
|
+
category: "hidden",
|
|
104
|
+
type: "container",
|
|
105
|
+
presetStyle: buttonPresetStyle,
|
|
106
|
+
label: "Sheet Close",
|
|
107
|
+
icon: ButtonElementIcon,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Styles source without animations:
|
|
112
|
+
* https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/sheet.tsx
|
|
113
|
+
*
|
|
114
|
+
* Attributions
|
|
115
|
+
* MIT License
|
|
116
|
+
* Copyright (c) 2023 shadcn
|
|
117
|
+
**/
|
|
118
|
+
export const metaSheet: WsComponentMeta = {
|
|
119
|
+
category: "radix",
|
|
120
|
+
|
|
121
|
+
type: "container",
|
|
122
|
+
label: "Sheet",
|
|
123
|
+
icon: HamburgerMenuIcon,
|
|
124
|
+
order: 15,
|
|
125
|
+
stylable: false,
|
|
126
|
+
template: [
|
|
127
|
+
{
|
|
128
|
+
type: "instance",
|
|
129
|
+
component: "Sheet",
|
|
130
|
+
dataSources: {
|
|
131
|
+
// We don't have support for boolean or undefined, instead of binding on open we bind on a string
|
|
132
|
+
isOpen: { type: "variable", initialValue: "initial" },
|
|
133
|
+
},
|
|
134
|
+
props: [
|
|
135
|
+
{
|
|
136
|
+
type: "dataSource",
|
|
137
|
+
name: "isOpen",
|
|
138
|
+
dataSourceName: "isOpen",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
children: [
|
|
142
|
+
{
|
|
143
|
+
type: "instance",
|
|
144
|
+
component: "SheetTrigger",
|
|
145
|
+
children: [
|
|
146
|
+
{
|
|
147
|
+
type: "instance",
|
|
148
|
+
component: "Button",
|
|
149
|
+
children: [{ type: "text", value: "Button" }],
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
type: "instance",
|
|
155
|
+
component: "SheetOverlay",
|
|
156
|
+
/**
|
|
157
|
+
* fixed inset-0 z-50 bg-background/80 backdrop-blur-sm
|
|
158
|
+
* flex
|
|
159
|
+
**/
|
|
160
|
+
styles: [
|
|
161
|
+
tc.fixed(),
|
|
162
|
+
tc.inset(0),
|
|
163
|
+
tc.z(50),
|
|
164
|
+
tc.bg("background", 80),
|
|
165
|
+
tc.backdropBlur("sm"),
|
|
166
|
+
// To allow positioning Content
|
|
167
|
+
tc.flex(),
|
|
168
|
+
tc.flex("col"),
|
|
169
|
+
tc.overflow("auto"),
|
|
170
|
+
].flat(),
|
|
171
|
+
children: [
|
|
172
|
+
{
|
|
173
|
+
type: "instance",
|
|
174
|
+
component: "SheetContent",
|
|
175
|
+
/**
|
|
176
|
+
* fixed w-full z-50
|
|
177
|
+
* grid gap-4 max-w-lg
|
|
178
|
+
* m-auto
|
|
179
|
+
* border bg-background p-6 shadow-lg
|
|
180
|
+
**/
|
|
181
|
+
styles: [
|
|
182
|
+
tc.w("full"),
|
|
183
|
+
tc.z(50),
|
|
184
|
+
tc.flex(),
|
|
185
|
+
tc.flex("col"),
|
|
186
|
+
tc.gap(4),
|
|
187
|
+
tc.border(),
|
|
188
|
+
tc.bg("background"),
|
|
189
|
+
tc.p(6),
|
|
190
|
+
tc.shadow("lg"),
|
|
191
|
+
tc.relative(),
|
|
192
|
+
tc.state(
|
|
193
|
+
[tc.mr("auto"), tc.maxW("sm"), tc.grow()].flat(),
|
|
194
|
+
"[data-side=left]"
|
|
195
|
+
),
|
|
196
|
+
tc.state(
|
|
197
|
+
[tc.ml("auto"), tc.maxW("sm"), tc.grow()].flat(),
|
|
198
|
+
"[data-side=right]"
|
|
199
|
+
),
|
|
200
|
+
tc.state([tc.mb("auto")].flat(), "[data-side=top]"),
|
|
201
|
+
tc.state([tc.mt("auto")].flat(), "[data-side=bottom]"),
|
|
202
|
+
].flat(),
|
|
203
|
+
children: [
|
|
204
|
+
{
|
|
205
|
+
type: "instance",
|
|
206
|
+
component: "Box",
|
|
207
|
+
label: "Sheet Header",
|
|
208
|
+
styles: [tc.flex(), tc.flex("col"), tc.gap(1)].flat(),
|
|
209
|
+
children: [
|
|
210
|
+
{
|
|
211
|
+
type: "instance",
|
|
212
|
+
component: "SheetTitle",
|
|
213
|
+
/**
|
|
214
|
+
* text-lg leading-none tracking-tight
|
|
215
|
+
**/
|
|
216
|
+
styles: [
|
|
217
|
+
tc.my(0),
|
|
218
|
+
tc.leading("none"),
|
|
219
|
+
tc.text("lg"),
|
|
220
|
+
tc.tracking("tight"),
|
|
221
|
+
].flat(),
|
|
222
|
+
children: [
|
|
223
|
+
{
|
|
224
|
+
type: "text",
|
|
225
|
+
value: "Sheet Title",
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
type: "instance",
|
|
231
|
+
component: "SheetDescription",
|
|
232
|
+
/**
|
|
233
|
+
* text-sm text-muted-foreground
|
|
234
|
+
**/
|
|
235
|
+
styles: [
|
|
236
|
+
tc.my(0),
|
|
237
|
+
tc.text("sm"),
|
|
238
|
+
tc.text("mutedForeground"),
|
|
239
|
+
].flat(),
|
|
240
|
+
children: [
|
|
241
|
+
{
|
|
242
|
+
type: "text",
|
|
243
|
+
value: "sheet description text you can edit",
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
{
|
|
251
|
+
type: "instance",
|
|
252
|
+
component: "Text",
|
|
253
|
+
children: [{ type: "text", value: "The text you can edit" }],
|
|
254
|
+
},
|
|
255
|
+
|
|
256
|
+
{
|
|
257
|
+
type: "instance",
|
|
258
|
+
component: "SheetClose",
|
|
259
|
+
/**
|
|
260
|
+
* absolute right-4 top-4
|
|
261
|
+
* rounded-sm opacity-70
|
|
262
|
+
* ring-offset-background
|
|
263
|
+
* hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2
|
|
264
|
+
* flex items-center justify-center h-4 w-4
|
|
265
|
+
**/
|
|
266
|
+
styles: [
|
|
267
|
+
tc.absolute(),
|
|
268
|
+
tc.right(4),
|
|
269
|
+
tc.top(4),
|
|
270
|
+
tc.rounded("sm"),
|
|
271
|
+
tc.opacity(70),
|
|
272
|
+
tc.flex(),
|
|
273
|
+
tc.items("center"),
|
|
274
|
+
tc.justify("center"),
|
|
275
|
+
tc.h(4),
|
|
276
|
+
tc.w(4),
|
|
277
|
+
tc.border(0),
|
|
278
|
+
tc.bg("transparent"),
|
|
279
|
+
tc.outline("none"),
|
|
280
|
+
tc.hover(tc.opacity(100)),
|
|
281
|
+
tc.focus(tc.ring("ring", 2, "background", 2)),
|
|
282
|
+
].flat(),
|
|
283
|
+
children: [{ type: "text", value: "✕" }],
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
],
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
export const propsMetaSheet: WsComponentPropsMeta = {
|
|
295
|
+
props: propsSheet,
|
|
296
|
+
initialProps: ["isOpen", "modal"],
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
export const propsMetaSheetTrigger: WsComponentPropsMeta = {
|
|
300
|
+
props: propsSheetTrigger,
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
export const propsMetaSheetContent: WsComponentPropsMeta = {
|
|
304
|
+
props: propsSheetContent,
|
|
305
|
+
initialProps: ["side", "role", "tag"],
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export const propsMetaSheetOverlay: WsComponentPropsMeta = {
|
|
309
|
+
props: propsSheetOverlay,
|
|
310
|
+
initialProps: [],
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
export const propsMetaSheetClose: WsComponentPropsMeta = {
|
|
314
|
+
props: propsSheetClose,
|
|
315
|
+
initialProps: [],
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export const propsMetaSheetTitle: WsComponentPropsMeta = {
|
|
319
|
+
props: propsSheetTitle,
|
|
320
|
+
initialProps: [],
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export const propsMetaSheetDescription: WsComponentPropsMeta = {
|
|
324
|
+
props: propsSheetDescription,
|
|
325
|
+
initialProps: [],
|
|
326
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { renderComponentTemplate } from "@webstudio-is/react-sdk";
|
|
3
|
+
import { Tabs as TabsPrimitive } from "./tabs";
|
|
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/Tabs",
|
|
11
|
+
component: TabsPrimitive,
|
|
12
|
+
} satisfies Meta<typeof TabsPrimitive>;
|
|
13
|
+
|
|
14
|
+
export const Tabs: StoryObj<typeof TabsPrimitive> = {
|
|
15
|
+
render: () =>
|
|
16
|
+
renderComponentTemplate({
|
|
17
|
+
name: "Tabs",
|
|
18
|
+
components: { ...baseComponents, ...radixComponents },
|
|
19
|
+
metas: { ...baseMetas, ...radixMetas },
|
|
20
|
+
}),
|
|
21
|
+
};
|
package/src/tabs.tsx
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
type ReactNode,
|
|
9
|
+
forwardRef,
|
|
10
|
+
Children,
|
|
11
|
+
} from "react";
|
|
12
|
+
import { Root, List, Trigger, Content } from "@radix-ui/react-tabs";
|
|
13
|
+
import { getIndexWithinAncestorFromComponentProps } from "@webstudio-is/react-sdk";
|
|
14
|
+
|
|
15
|
+
export const Tabs: ForwardRefExoticComponent<
|
|
16
|
+
Omit<ComponentPropsWithRef<typeof Root>, "asChild" | "defaultValue">
|
|
17
|
+
> = Root;
|
|
18
|
+
|
|
19
|
+
export const TabsList = List;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* We're not exposing the 'asChild' property for the Trigger.
|
|
23
|
+
* Instead, we're enforcing 'asChild=true' for the Trigger and making it style-less.
|
|
24
|
+
* This avoids situations where the Trigger inadvertently passes all styles to its child,
|
|
25
|
+
* which would prevent us from displaying styles properly in the builder.
|
|
26
|
+
*/
|
|
27
|
+
export const TabsTrigger = forwardRef<
|
|
28
|
+
HTMLButtonElement,
|
|
29
|
+
{ value: string; children: ReactNode }
|
|
30
|
+
>(({ value, children, ...props }, ref) => {
|
|
31
|
+
const firstChild = Children.toArray(children)[0];
|
|
32
|
+
const index = getIndexWithinAncestorFromComponentProps(props);
|
|
33
|
+
return (
|
|
34
|
+
<Trigger ref={ref} value={value ?? index} asChild={true} {...props}>
|
|
35
|
+
{firstChild ?? <button>Add button</button>}
|
|
36
|
+
</Trigger>
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export const TabsContent = forwardRef<
|
|
41
|
+
HTMLDivElement,
|
|
42
|
+
Omit<ComponentPropsWithoutRef<typeof Content>, "asChild">
|
|
43
|
+
>(({ value, ...props }, ref) => {
|
|
44
|
+
const index = getIndexWithinAncestorFromComponentProps(props);
|
|
45
|
+
return <Content ref={ref} value={value ?? index} {...props} />;
|
|
46
|
+
});
|