Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

refactor: rewrite popover and tooltip templates with jsx (#4696)

Bogdan Chadkin517c04850d23
diff --git a/packages/sdk-components-react-radix/src/dialog.template.tsx b/packages/sdk-components-react-radix/src/dialog.template.tsx
index 0dff771581..311f2cdaf8 100644
--- a/packages/sdk-components-react-radix/src/dialog.template.tsx
+++ b/packages/sdk-components-react-radix/src/dialog.template.tsx
@@ -25,6 +25,14 @@ import {
} from "./shared/theme";
import { getButtonStyle } from "./shared/styles";
+/**
+ * Styles source without animations:
+ * https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/dialog.tsx
+ *
+ * Attributions
+ * MIT License
+ * Copyright (c) 2023 shadcn
+ **/
export const meta: TemplateMeta = {
category: "radix",
description:
diff --git a/packages/sdk-components-react-radix/src/dialog.ws.ts b/packages/sdk-components-react-radix/src/dialog.ws.ts
index dba3fa1372..569b3b7eea 100644
--- a/packages/sdk-components-react-radix/src/dialog.ws.ts
+++ b/packages/sdk-components-react-radix/src/dialog.ws.ts
@@ -126,14 +126,6 @@ export const metaDialogClose: WsComponentMeta = {
},
};
-/**
- * Styles source without animations:
- * https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/dialog.tsx
- *
- * Attributions
- * MIT License
- * Copyright (c) 2023 shadcn
- **/
export const metaDialog: WsComponentMeta = {
type: "container",
constraints: [
diff --git a/packages/sdk-components-react-radix/src/popover.template.tsx b/packages/sdk-components-react-radix/src/popover.template.tsx
new file mode 100644
index 0000000000..4a87e4f68b
--- /dev/null
+++ b/packages/sdk-components-react-radix/src/popover.template.tsx
@@ -0,0 +1,58 @@
+import {
+ $,
+ css,
+ PlaceholderValue,
+ type TemplateMeta,
+} from "@webstudio-is/template";
+import { radix } from "./shared/proxy";
+import { getButtonStyle } from "./shared/styles";
+import {
+ borderRadius,
+ borderWidth,
+ boxShadow,
+ colors,
+ spacing,
+ width,
+ zIndex,
+} from "./shared/theme";
+
+/**
+ * Styles source without animations:
+ * https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/popover.tsx
+ *
+ * Attributions
+ * MIT License
+ * Copyright (c) 2023 shadcn
+ **/
+export const meta: TemplateMeta = {
+ category: "radix",
+ description: "Displays rich content in a portal, triggered by a button.",
+ order: 6,
+ template: (
+ <radix.Popover>
+ <radix.PopoverTrigger>
+ <$.Button ws:style={getButtonStyle("outline")}>
+ {new PlaceholderValue("Button")}
+ </$.Button>
+ </radix.PopoverTrigger>
+ <radix.PopoverContent
+ /**
+ * z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none
+ **/
+ ws:style={css`
+ z-index: ${zIndex[50]};
+ width: ${width[72]};
+ border-radius: ${borderRadius.md};
+ border: ${borderWidth.DEFAULT} solid ${colors.border};
+ background-color: ${colors.popover};
+ padding: ${spacing[4]};
+ color: ${colors.popoverForeground};
+ box-shadow: ${boxShadow.md};
+ outline: none;
+ `}
+ >
+ <$.Text>{new PlaceholderValue("The text you can edit")}</$.Text>
+ </radix.PopoverContent>
+ </radix.Popover>
+ ),
+};
diff --git a/packages/sdk-components-react-radix/src/popover.ws.ts b/packages/sdk-components-react-radix/src/popover.ws.ts
index 34bc643d17..9b8b44ae74 100644
--- a/packages/sdk-components-react-radix/src/popover.ws.ts
+++ b/packages/sdk-components-react-radix/src/popover.ws.ts
@@ -5,8 +5,6 @@ import {
type WsComponentPropsMeta,
} from "@webstudio-is/react-sdk";
import { div } from "@webstudio-is/sdk/normalize.css";
-import * as tc from "./theme/tailwind-classes";
-import { getButtonStyles } from "./theme/styles";
import {
propsPopover,
propsPopoverContent,
@@ -19,7 +17,6 @@ const presetStyle = {
// @todo add [data-state] to button and link
export const metaPopoverTrigger: WsComponentMeta = {
- category: "hidden",
type: "container",
icon: TriggerIcon,
stylable: false,
@@ -30,7 +27,6 @@ export const metaPopoverTrigger: WsComponentMeta = {
};
export const metaPopoverContent: WsComponentMeta = {
- category: "hidden",
type: "container",
presetStyle,
icon: ContentIcon,
@@ -40,17 +36,7 @@ export const metaPopoverContent: WsComponentMeta = {
},
};
-/**
- * Styles source without animations:
- * https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/popover.tsx
- *
- * Attributions
- * MIT License
- * Copyright (c) 2023 shadcn
- **/
export const metaPopover: WsComponentMeta = {
- category: "radix",
- order: 6,
type: "container",
constraints: [
{
@@ -64,59 +50,6 @@ export const metaPopover: WsComponentMeta = {
],
icon: PopoverIcon,
stylable: false,
- description: "Displays rich content in a portal, triggered by a button.",
- template: [
- {
- type: "instance",
- component: "Popover",
- props: [],
- children: [
- {
- type: "instance",
- component: "PopoverTrigger",
- children: [
- {
- type: "instance",
- component: "Button",
- styles: getButtonStyles("outline"),
- children: [{ type: "text", value: "Button", placeholder: true }],
- },
- ],
- },
- {
- type: "instance",
- component: "PopoverContent",
- /**
- * z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none
- **/
- styles: [
- tc.z(50),
- tc.w(72),
- tc.rounded("md"),
- tc.border(),
- tc.bg("popover"),
- tc.p(4),
- tc.text("popoverForeground"),
- tc.shadow("md"),
- tc.outline("none"),
- ].flat(),
- children: [
- {
- type: "instance",
- component: "Text",
- children: [
- {
- type: "text",
- value: "The text you can edit",
- placeholder: true,
- },
- ],
- },
- ],
- },
- ],
- },
- ],
};
export const propsMetaPopover: WsComponentPropsMeta = {
diff --git a/packages/sdk-components-react-radix/src/templates.ts b/packages/sdk-components-react-radix/src/templates.ts
index 787a28b60e..1a04131e38 100644
--- a/packages/sdk-components-react-radix/src/templates.ts
+++ b/packages/sdk-components-react-radix/src/templates.ts
@@ -6,3 +6,5 @@ export { meta as Switch } from "./switch.template";
export { meta as Checkbox } from "./checkbox.template";
export { meta as Collapsible } from "./collapsible.template";
export { meta as Accordion } from "./accordion.template";
+export { meta as Tooltip } from "./tooltip.template";
+export { meta as Popover } from "./popover.template";
diff --git a/packages/sdk-components-react-radix/src/tooltip.template.tsx b/packages/sdk-components-react-radix/src/tooltip.template.tsx
new file mode 100644
index 0000000000..bd9fcadae2
--- /dev/null
+++ b/packages/sdk-components-react-radix/src/tooltip.template.tsx
@@ -0,0 +1,59 @@
+import {
+ $,
+ css,
+ PlaceholderValue,
+ type TemplateMeta,
+} from "@webstudio-is/template";
+import { radix } from "./shared/proxy";
+import { getButtonStyle } from "./shared/styles";
+import {
+ borderRadius,
+ boxShadow,
+ colors,
+ fontSize,
+ fontSizeLineHeight,
+ spacing,
+ zIndex,
+} from "./shared/theme";
+
+/**
+ * Styles source without animations:
+ * https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/tooltip.tsx
+ *
+ * Attributions
+ * MIT License
+ * Copyright (c) 2023 shadcn
+ **/
+export const meta: TemplateMeta = {
+ category: "radix",
+ description:
+ "Displays content that is related to the trigger, when the trigger is hovered with the mouse or focused with the keyboard. You are reading an example of a tooltip right now.",
+ order: 7,
+ template: (
+ <radix.Tooltip>
+ <radix.TooltipTrigger>
+ <$.Button ws:style={getButtonStyle("outline")}>
+ {new PlaceholderValue("Button")}
+ </$.Button>
+ </radix.TooltipTrigger>
+ <radix.TooltipContent
+ /**
+ * z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md
+ **/
+ ws:style={css`
+ z-index: ${zIndex[50]};
+ overflow: hidden;
+ border-radius: ${borderRadius.md};
+ background-color: ${colors.popover};
+ padding: ${spacing[1.5]} ${spacing[3]};
+ font-size: ${fontSize.sm};
+ line-height: ${fontSizeLineHeight.sm};
+ color: ${colors.popoverForeground};
+ box-shadow: ${boxShadow.md};
+ `}
+ >
+ <$.Text>{new PlaceholderValue("The text you can edit")}</$.Text>
+ </radix.TooltipContent>
+ </radix.Tooltip>
+ ),
+};
diff --git a/packages/sdk-components-react-radix/src/tooltip.ws.ts b/packages/sdk-components-react-radix/src/tooltip.ws.ts
index 77bc8d46fb..17d334ad1e 100644
--- a/packages/sdk-components-react-radix/src/tooltip.ws.ts
+++ b/packages/sdk-components-react-radix/src/tooltip.ws.ts
@@ -5,13 +5,11 @@ import {
type WsComponentPropsMeta,
} from "@webstudio-is/react-sdk";
import { div } from "@webstudio-is/sdk/normalize.css";
-import * as tc from "./theme/tailwind-classes";
import {
propsTooltip,
propsTooltipContent,
propsTooltipTrigger,
} from "./__generated__/tooltip.props";
-import { getButtonStyles } from "./theme/styles";
const presetStyle = {
div,
@@ -19,7 +17,6 @@ const presetStyle = {
// @todo add [data-state] to button and link
export const metaTooltipTrigger: WsComponentMeta = {
- category: "hidden",
type: "container",
icon: TriggerIcon,
stylable: false,
@@ -30,7 +27,6 @@ export const metaTooltipTrigger: WsComponentMeta = {
};
export const metaTooltipContent: WsComponentMeta = {
- category: "hidden",
type: "container",
icon: ContentIcon,
presetStyle,
@@ -40,17 +36,7 @@ export const metaTooltipContent: WsComponentMeta = {
},
};
-/**
- * Styles source without animations:
- * https://github.com/shadcn-ui/ui/blob/main/apps/www/registry/default/ui/tooltip.tsx
- *
- * Attributions
- * MIT License
- * Copyright (c) 2023 shadcn
- **/
export const metaTooltip: WsComponentMeta = {
- category: "radix",
- order: 7,
type: "container",
constraints: [
{
@@ -64,61 +50,6 @@ export const metaTooltip: WsComponentMeta = {
],
icon: TooltipIcon,
stylable: false,
- description:
- "Displays content that is related to the trigger, when the trigger is hovered with the mouse or focused with the keyboard. You are reading an example of a tooltip right now.",
- template: [
- {
- type: "instance",
- component: "Tooltip",
- props: [],
- children: [
- {
- type: "instance",
- component: "TooltipTrigger",
- children: [
- {
- type: "instance",
- component: "Button",
- styles: getButtonStyles("outline"),
- children: [{ type: "text", value: "Button", placeholder: true }],
- },
- ],
- },
- {
- type: "instance",
- component: "TooltipContent",
- /**
- * z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md
- **/
- styles: [
- tc.z(50),
- tc.overflow("hidden"),
- tc.rounded("md"),
- tc.border(),
- tc.bg("popover"),
- tc.px(3),
- tc.py(1.5),
- tc.text("sm"),
- tc.text("popoverForeground"),
- tc.shadow("md"),
- ].flat(),
- children: [
- {
- type: "instance",
- component: "Text",
- children: [
- {
- type: "text",
- value: "The text you can edit",
- placeholder: true,
- },
- ],
- },
- ],
- },
- ],
- },
- ],
};
export const propsMetaTooltip: WsComponentPropsMeta = {