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.

Radix Button (#2097)

Ivan Starkov7a8fd3db49c9
diff --git a/apps/builder/app/builder/features/style-panel/sections/effects/effects.tsx b/apps/builder/app/builder/features/style-panel/sections/effects/effects.tsx
index af946dfdef..c05fa4af77 100644
--- a/apps/builder/app/builder/features/style-panel/sections/effects/effects.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/effects/effects.tsx
@@ -99,6 +99,18 @@ export const EffectsSection = ({
setProperty={setProperty}
deleteProperty={deleteProperty}
/>
+ <PropertyName
+ label={styleConfigByName("textUnderlineOffset").label}
+ properties={["textUnderlineOffset"]}
+ style={style}
+ onReset={() => deleteProperty("textUnderlineOffset")}
+ />
+ <TextControl
+ property={"textUnderlineOffset"}
+ currentStyle={style}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
</CollapsibleSection>
);
diff --git a/packages/react-sdk/src/component-renderer.tsx b/packages/react-sdk/src/component-renderer.tsx
index abe8e4f31a..5b01bda671 100644
--- a/packages/react-sdk/src/component-renderer.tsx
+++ b/packages/react-sdk/src/component-renderer.tsx
@@ -2,7 +2,10 @@ import type { ExoticComponent } from "react";
import type { Instance } from "@webstudio-is/project-build";
import { getStyleDeclKey } from "@webstudio-is/project-build";
import type { WsComponentMeta } from "./components/component-meta";
-import { generateDataFromEmbedTemplate } from "./embed-template";
+import {
+ WsEmbedTemplate,
+ generateDataFromEmbedTemplate,
+} from "./embed-template";
import { generateCssText } from "./css";
import { InstanceRoot, WebstudioComponent } from "./tree";
import {
@@ -18,23 +21,43 @@ export const renderComponentTemplate = ({
name,
metas: metasRecord,
components,
+ props,
}: {
name: Instance["component"];
metas: Record<string, WsComponentMeta>;
+ props?: Record<string, unknown>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
components: Record<string, ExoticComponent<any>>;
}) => {
const metas = new Map(Object.entries(metasRecord));
- const data = generateDataFromEmbedTemplate(
- metas.get(name)?.template ?? [
- {
- type: "instance",
- component: name,
- children: [],
- },
- ],
- "base"
- );
+
+ const template: WsEmbedTemplate = metas.get(name)?.template ?? [
+ {
+ type: "instance",
+ component: name,
+ children: [],
+ },
+ ];
+
+ if (template[0].type === "instance" && props !== undefined) {
+ template[0].props = Object.entries(props).map(([prop, value]) => {
+ if (typeof value === "string") {
+ return { type: "string", name: prop, value: value };
+ }
+
+ if (typeof value === "number") {
+ return { type: "number", name: prop, value: value };
+ }
+
+ if (typeof value === "boolean") {
+ return { type: "boolean", name: prop, value: value };
+ }
+ throw new Error(`Unsupported prop ${props} with value ${value}`);
+ });
+ }
+
+ const data = generateDataFromEmbedTemplate(template, "base");
+
const instances: [Instance["id"], Instance][] = [
[
"root",
@@ -49,6 +72,7 @@ export const renderComponentTemplate = ({
(instance) => [instance.id, instance] satisfies [Instance["id"], Instance]
),
];
+
return (
<>
<style>
diff --git a/packages/sdk-components-react-radix/.storybook/preview-body.html b/packages/sdk-components-react-radix/.storybook/preview-body.html
new file mode 100644
index 0000000000..26071f8c37
--- /dev/null
+++ b/packages/sdk-components-react-radix/.storybook/preview-body.html
@@ -0,0 +1,4 @@
+<script>
+ // For styling purposes
+ document.body.setAttribute("data-ws-component", "Body");
+</script>
diff --git a/packages/sdk-components-react-radix/src/__generated__/button.props.ts b/packages/sdk-components-react-radix/src/__generated__/button.props.ts
new file mode 100644
index 0000000000..226741dbe5
--- /dev/null
+++ b/packages/sdk-components-react-radix/src/__generated__/button.props.ts
@@ -0,0 +1,503 @@
+import type { PropMeta } from "@webstudio-is/generate-arg-types";
+
+export const props: Record<string, PropMeta> = {
+ about: { required: false, control: "text", type: "string" },
+ accessKey: { required: false, control: "text", type: "string" },
+ "aria-activedescendant": {
+ description:
+ "Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-atomic": {
+ description:
+ "Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-autocomplete": {
+ description:
+ "Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be\npresented if they are made.",
+ required: false,
+ control: "select",
+ type: "string",
+ options: ["list", "none", "inline", "both"],
+ },
+ "aria-braillelabel": {
+ description:
+ "Defines a string value that labels the current element, which is intended to be converted into Braille.\n@see aria-label.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-brailleroledescription": {
+ description:
+ "Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille.\n@see aria-roledescription.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-busy": { required: false, control: "boolean", type: "boolean" },
+ "aria-checked": {
+ description:
+ 'Indicates the current "checked" state of checkboxes, radio buttons, and other widgets.\n@see aria-pressed\n@see aria-selected.',
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-colcount": {
+ description:
+ "Defines the total number of columns in a table, grid, or treegrid.\n@see aria-colindex.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-colindex": {
+ description:
+ "Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid.\n@see aria-colcount\n@see aria-colspan.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-colindextext": {
+ description:
+ "Defines a human readable text alternative of aria-colindex.\n@see aria-rowindextext.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-colspan": {
+ description:
+ "Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid.\n@see aria-colindex\n@see aria-rowspan.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-controls": {
+ description:
+ "Identifies the element (or elements) whose contents or presence are controlled by the current element.\n@see aria-owns.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-current": {
+ description:
+ "Indicates the element that represents the current item within a container or set of related elements.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-describedby": {
+ description:
+ "Identifies the element (or elements) that describes the object.\n@see aria-labelledby",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-description": {
+ description:
+ "Defines a string value that describes or annotates the current element.\n@see related aria-describedby.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-details": {
+ description:
+ "Identifies the element that provides a detailed, extended description for the object.\n@see aria-describedby.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-disabled": {
+ description:
+ "Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable.\n@see aria-hidden\n@see aria-readonly.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-dropeffect": {
+ description:
+ "Indicates what functions can be performed when a dragged object is released on the drop target.\n@deprecated in ARIA 1.1",
+ required: false,
+ control: "select",
+ type: "string",
+ options: ["link", "none", "copy", "execute", "move", "popup"],
+ },
+ "aria-errormessage": {
+ description:
+ "Identifies the element that provides an error message for the object.\n@see aria-invalid\n@see aria-describedby.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-expanded": {
+ description:
+ "Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-flowto": {
+ description:
+ "Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion,\nallows assistive technology to override the general default of reading in document source order.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-grabbed": {
+ description:
+ 'Indicates an element\'s "grabbed" state in a drag-and-drop operation.\n@deprecated in ARIA 1.1',
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-haspopup": {
+ description:
+ "Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-hidden": {
+ description:
+ "Indicates whether the element is exposed to an accessibility API.\n@see aria-disabled.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-invalid": {
+ description:
+ "Indicates the entered value does not conform to the format expected by the application.\n@see aria-errormessage.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-keyshortcuts": {
+ description:
+ "Indicates keyboard shortcuts that an author has implemented to activate or give focus to an element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-label": {
+ description:
+ "Defines a string value that labels the current element.\n@see aria-labelledby.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-labelledby": {
+ description:
+ "Identifies the element (or elements) that labels the current element.\n@see aria-describedby.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-level": {
+ description:
+ "Defines the hierarchical level of an element within a structure.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-live": {
+ description:
+ "Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.",
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["off", "assertive", "polite"],
+ },
+ "aria-modal": {
+ description: "Indicates whether an element is modal when displayed.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-multiline": {
+ description:
+ "Indicates whether a text box accepts multiple lines of input or only a single line.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-multiselectable": {
+ description:
+ "Indicates that the user may select more than one item from the current selectable descendants.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-orientation": {
+ description:
+ "Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.",
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["horizontal", "vertical"],
+ },
+ "aria-owns": {
+ description:
+ "Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship\nbetween DOM elements where the DOM hierarchy cannot be used to represent the relationship.\n@see aria-controls.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-placeholder": {
+ description:
+ "Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value.\nA hint could be a sample value or a brief description of the expected format.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-posinset": {
+ description:
+ "Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.\n@see aria-setsize.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-pressed": {
+ description:
+ 'Indicates the current "pressed" state of toggle buttons.\n@see aria-checked\n@see aria-selected.',
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-readonly": {
+ description:
+ "Indicates that the element is not editable, but is otherwise operable.\n@see aria-disabled.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-relevant": {
+ description:
+ "Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified.\n@see aria-atomic.",
+ required: false,
+ control: "select",
+ type: "string",
+ options: [
+ "text",
+ "additions",
+ "additions removals",
+ "additions text",
+ "all",
+ "removals",
+ "removals additions",
+ "removals text",
+ "text additions",
+ "text removals",
+ ],
+ },
+ "aria-required": {
+ description:
+ "Indicates that user input is required on the element before a form may be submitted.",
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-roledescription": {
+ description:
+ "Defines a human-readable, author-localized description for the role of an element.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-rowcount": {
+ description:
+ "Defines the total number of rows in a table, grid, or treegrid.\n@see aria-rowindex.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-rowindex": {
+ description:
+ "Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid.\n@see aria-rowcount\n@see aria-rowspan.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-rowindextext": {
+ description:
+ "Defines a human readable text alternative of aria-rowindex.\n@see aria-colindextext.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ "aria-rowspan": {
+ description:
+ "Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid.\n@see aria-rowindex\n@see aria-colspan.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-selected": {
+ description:
+ 'Indicates the current "selected" state of various widgets.\n@see aria-checked\n@see aria-pressed.',
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ "aria-setsize": {
+ description:
+ "Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.\n@see aria-posinset.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-sort": {
+ description:
+ "Indicates if items in a table or grid are sorted in ascending or descending order.",
+ required: false,
+ control: "select",
+ type: "string",
+ options: ["none", "ascending", "descending", "other"],
+ },
+ "aria-valuemax": {
+ description: "Defines the maximum allowed value for a range widget.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-valuemin": {
+ description: "Defines the minimum allowed value for a range widget.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-valuenow": {
+ description:
+ "Defines the current value for a range widget.\n@see aria-valuetext.",
+ required: false,
+ control: "number",
+ type: "number",
+ },
+ "aria-valuetext": {
+ description:
+ "Defines the human readable text alternative of aria-valuenow for a range widget.",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ autoCapitalize: { required: false, control: "text", type: "string" },
+ autoCorrect: { required: false, control: "text", type: "string" },
+ autoFocus: { required: false, control: "boolean", type: "boolean" },
+ autoSave: { required: false, control: "text", type: "string" },
+ className: { required: false, control: "text", type: "string" },
+ color: { required: false, control: "color", type: "string" },
+ content: { required: false, control: "text", type: "string" },
+ contextMenu: { required: false, control: "text", type: "string" },
+ datatype: { required: false, control: "text", type: "string" },
+ defaultChecked: { required: false, control: "boolean", type: "boolean" },
+ dir: { required: false, control: "text", type: "string" },
+ disabled: { required: false, control: "boolean", type: "boolean" },
+ draggable: { required: false, control: "boolean", type: "boolean" },
+ form: { required: false, control: "text", type: "string" },
+ formAction: { required: false, control: "text", type: "string" },
+ formEncType: { required: false, control: "text", type: "string" },
+ formMethod: { required: false, control: "text", type: "string" },
+ formNoValidate: { required: false, control: "boolean", type: "boolean" },
+ formTarget: { required: false, control: "text", type: "string" },
+ hidden: { required: false, control: "boolean", type: "boolean" },
+ id: { required: false, control: "text", type: "string" },
+ inputMode: {
+ description:
+ "Hints at the type of data that might be entered by the user while editing the element or its contents\n@see https://html.spec.whatwg.org/multipage/interaction.html#input-modalities:-the-inputmode-attribute",
+ required: false,
+ control: "select",
+ type: "string",
+ options: [
+ "search",
+ "text",
+ "none",
+ "tel",
+ "url",
+ "email",
+ "numeric",
+ "decimal",
+ ],
+ },
+ is: {
+ description:
+ "Specify that a standard HTML element should behave like a defined custom built-in element\n@see https://html.spec.whatwg.org/multipage/custom-elements.html#attr-is",
+ required: false,
+ control: "text",
+ type: "string",
+ },
+ itemID: { required: false, control: "text", type: "string" },
+ itemProp: { required: false, control: "text", type: "string" },
+ itemRef: { required: false, control: "text", type: "string" },
+ itemScope: { required: false, control: "boolean", type: "boolean" },
+ itemType: { required: false, control: "text", type: "string" },
+ lang: { required: false, control: "text", type: "string" },
+ name: { required: false, control: "text", type: "string" },
+ nonce: { required: false, control: "text", type: "string" },
+ placeholder: { required: false, control: "text", type: "string" },
+ prefix: { required: false, control: "text", type: "string" },
+ property: { required: false, control: "text", type: "string" },
+ radioGroup: { required: false, control: "text", type: "string" },
+ rel: { required: false, control: "text", type: "string" },
+ resource: { required: false, control: "text", type: "string" },
+ results: { required: false, control: "number", type: "number" },
+ rev: { required: false, control: "text", type: "string" },
+ role: { required: false, control: "text", type: "string" },
+ security: { required: false, control: "text", type: "string" },
+ size: {
+ required: false,
+ control: "select",
+ type: "string",
+ defaultValue: "default",
+ options: ["default", "sm", "lg", "icon"],
+ },
+ slot: { required: false, control: "text", type: "string" },
+ spellCheck: { required: false, control: "boolean", type: "boolean" },
+ suppressContentEditableWarning: {
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ suppressHydrationWarning: {
+ required: false,
+ control: "boolean",
+ type: "boolean",
+ },
+ tabIndex: { required: false, control: "number", type: "number" },
+ title: { required: false, control: "text", type: "string" },
+ translate: {
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["yes", "no"],
+ },
+ type: {
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["button", "submit", "reset"],
+ },
+ typeof: { required: false, control: "text", type: "string" },
+ unselectable: {
+ required: false,
+ control: "radio",
+ type: "string",
+ options: ["on", "off"],
+ },
+ variant: {
+ required: false,
+ control: "select",
+ type: "string",
+ defaultValue: "default",
+ options: [
+ "link",
+ "default",
+ "destructive",
+ "outline",
+ "secondary",
+ "ghost",
+ ],
+ },
+ vocab: { required: false, control: "text", type: "string" },
+};
diff --git a/packages/sdk-components-react-radix/src/button.stories.ts b/packages/sdk-components-react-radix/src/button.stories.ts
new file mode 100644
index 0000000000..190596b225
--- /dev/null
+++ b/packages/sdk-components-react-radix/src/button.stories.ts
@@ -0,0 +1,35 @@
+import type { Meta, StoryObj } from "@storybook/react";
+import { renderComponentTemplate } from "@webstudio-is/react-sdk";
+import { Button as ButtonPrimitive } from "./button";
+import * as baseComponents from "@webstudio-is/sdk-components-react";
+import * as baseMetas from "@webstudio-is/sdk-components-react/metas";
+import * as radixComponents from "./components";
+import * as radixMetas from "./metas";
+
+export default {
+ title: "Components/Button",
+ component: ButtonPrimitive,
+ argTypes: {
+ variant: {
+ options: [
+ "default",
+ "destructive",
+ "outline",
+ "secondary",
+ "ghost",
+ "link",
+ ],
+ control: { type: "select" },
+ },
+ },
+} satisfies Meta<typeof ButtonPrimitive>;
+
+export const Button: StoryObj<typeof ButtonPrimitive> = {
+ render: (props) =>
+ renderComponentTemplate({
+ name: "Button",
+ props: { ...props },
+ components: { ...baseComponents, ...radixComponents },
+ metas: { ...baseMetas, ...radixMetas },
+ }),
+};
diff --git a/packages/sdk-components-react-radix/src/button.tsx b/packages/sdk-components-react-radix/src/button.tsx
new file mode 100644
index 0000000000..f649e1a975
--- /dev/null
+++ b/packages/sdk-components-react-radix/src/button.tsx
@@ -0,0 +1,25 @@
+/* eslint-disable react/display-name */
+// We can't use .displayName until this is merged https://github.com/styleguidist/react-docgen-typescript/pull/449
+
+import { forwardRef, type ComponentPropsWithoutRef } from "react";
+
+type ButtonVariants = {
+ variant:
+ | "default"
+ | "destructive"
+ | "outline"
+ | "secondary"
+ | "ghost"
+ | "link";
+
+ size: "default" | "sm" | "lg" | "icon";
+};
+
+export const Button = forwardRef<
+ HTMLButtonElement,
+ ComponentPropsWithoutRef<"button"> & ButtonVariants
+>(({ variant = "default", size = "default", ...props }, ref) => {
+ return (
+ <button ref={ref} data-size={size} data-variant={variant} {...props} />
+ );
+});
diff --git a/packages/sdk-components-react-radix/src/button.ws.ts b/packages/sdk-components-react-radix/src/button.ws.ts
new file mode 100644
index 0000000000..b0a6641889
--- /dev/null
+++ b/packages/sdk-components-react-radix/src/button.ws.ts
@@ -0,0 +1,152 @@
+import { ButtonElementIcon } from "@webstudio-is/icons/svg";
+import {
+ defaultStates,
+ type PresetStyle,
+ type WsComponentMeta,
+ type WsComponentPropsMeta,
+} from "@webstudio-is/react-sdk";
+import { button } from "@webstudio-is/react-sdk/css-normalize";
+import { props } from "./__generated__/button.props";
+import * as tc from "./theme/tailwind-classes";
+
+const presetStyle = {
+ button,
+} satisfies PresetStyle<"button">;
+
+export const meta: WsComponentMeta = {
+ category: "radix",
+ type: "container",
+ invalidAncestors: ["Button"],
+ label: "Button",
+ icon: ButtonElementIcon,
+ presetStyle,
+ states: [
+ ...defaultStates,
+ { selector: ":disabled", label: "Disabled" },
+ { selector: ":enabled", label: "Enabled" },
+
+ { selector: "[data-variant=default]", label: "Default" },
+ { selector: "[data-variant=default]:hover", label: "Default Hover" },
+
+ { selector: "[data-variant=destructive]", label: "Destructive" },
+ {
+ selector: "[data-variant=destructive]:hover",
+ label: "Destructive Hover",
+ },
+
+ { selector: "[data-variant=outline]", label: "Outline" },
+ { selector: "[data-variant=outline]:hover", label: "Outline Hover" },
+
+ { selector: "[data-variant=secondary]", label: "Secondary" },
+ { selector: "[data-variant=secondary]:hover", label: "Secondary Hover" },
+
+ { selector: "[data-variant=ghost]", label: "Ghost" },
+ { selector: "[data-variant=ghost]:hover", label: "Ghost Hover" },
+
+ { selector: "[data-variant=link]", label: "Link" },
+ { selector: "[data-variant=link]:hover", label: "Link Hover" },
+ ],
+ order: 1,
+ template: [
+ {
+ type: "instance",
+ component: "Button",
+ styles: [
+ // 'inline-flex items-center justify-center rounded-md text-sm font-medium
+ // ring-offset-background transition-colors
+ // focus-visible:outline-none focus-visible:ring-2
+ // focus-visible:ring-ring focus-visible:ring-offset-2
+ // disabled:pointer-events-none disabled:opacity-50'
+ tc.border(0),
+ tc.bg("transparent"),
+ tc.inlineFlex(),
+ tc.items("center"),
+ tc.justify("center"),
+ tc.rounded("md"),
+ tc.text("sm"),
+ tc.font("medium"),
+ tc.focusVisible(
+ [tc.outline("none"), tc.ring("ring", 2, "background", 2)].flat()
+ ),
+ tc.state(
+ [tc.pointerEvents("none"), tc.opacity(50)].flat(),
+ ":disabled"
+ ),
+
+ // VARIANT
+ // default: 'bg-primary text-primary-foreground hover:bg-primary/90',
+ tc.state(
+ [tc.bg("primary"), tc.text("primaryForeground")].flat(),
+ "[data-variant=default]"
+ ),
+ tc.state(
+ [[tc.bg("primary", 90)].flat()].flat(),
+ "[data-variant=default]:hover"
+ ),
+
+ // destructive:'bg-destructive text-destructive-foreground hover:bg-destructive/90',
+ tc.state(
+ [tc.bg("destructive"), tc.text("destructiveForeground")].flat(),
+ "[data-variant=destructive]"
+ ),
+ tc.state(
+ [[tc.bg("destructive", 90)].flat()].flat(),
+ "[data-variant=destructive]:hover"
+ ),
+
+ // outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
+ tc.state(
+ [tc.border(), tc.border("input"), tc.bg("background")].flat(),
+ "[data-variant=outline]"
+ ),
+ tc.state(
+ [[tc.bg("accent", 90), tc.text("accentForeground")].flat()].flat(),
+ "[data-variant=outline]:hover"
+ ),
+
+ // secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
+ tc.state(
+ [tc.bg("secondary"), tc.text("secondaryForeground")].flat(),
+ "[data-variant=secondary]"
+ ),
+ tc.state(
+ [[tc.bg("secondary", 80)].flat()].flat(),
+ "[data-variant=secondary]:hover"
+ ),
+
+ // ghost: 'hover:bg-accent hover:text-accent-foreground',
+ tc.state(
+ [[tc.bg("accent"), tc.text("accentForeground")].flat()].flat(),
+ "[data-variant=ghost]:hover"
+ ),
+
+ // link: 'text-primary underline-offset-4 hover:underline',
+ tc.state(
+ [tc.text("primary"), tc.underlineOffset(4)].flat(),
+ "[data-variant=link]"
+ ),
+ tc.state([[tc.underline()].flat()].flat(), "[data-variant=link]:hover"),
+
+ // SIZE
+ // default: 'h-10 px-4 py-2',
+ tc.state([tc.h(10), tc.px(4), tc.py(2)].flat(), "[data-size=default]"),
+
+ // sm: 'h-9 rounded-md px-3',
+ tc.state([tc.h(10), tc.px(3)].flat(), "[data-size=sm]"),
+
+ // lg: 'h-11 rounded-md px-8',
+ tc.state([tc.h(11), tc.px(8)].flat(), "[data-size=lg]"),
+
+ // icon: 'h-10 w-10',
+ tc.state([tc.h(10), tc.w(10)].flat(), "[data-size=icon]"),
+ ].flat(),
+
+ children: [{ type: "text", value: "Button you can edit" }],
+ },
+ ],
+};
+
+export const propsMeta: WsComponentPropsMeta = {
+ props,
+ initialProps: ["id", "type", "variant", "size", "aria-label"],
+};
diff --git a/packages/sdk-components-react-radix/src/components.ts b/packages/sdk-components-react-radix/src/components.ts
index 6ce74c7d57..34d13e5c48 100644
--- a/packages/sdk-components-react-radix/src/components.ts
+++ b/packages/sdk-components-react-radix/src/components.ts
@@ -24,3 +24,4 @@ export {
SheetDescription,
} from "./sheet";
export { Tabs, TabsList, TabsTrigger, TabsContent } from "./tabs";
+export { Button } from "./button";
diff --git a/packages/sdk-components-react-radix/src/metas.ts b/packages/sdk-components-react-radix/src/metas.ts
index ea68f42414..4d4a75264a 100644
--- a/packages/sdk-components-react-radix/src/metas.ts
+++ b/packages/sdk-components-react-radix/src/metas.ts
@@ -37,3 +37,4 @@ export {
metaTabsTrigger as TabsTrigger,
metaTabsContent as TabsContent,
} from "./tabs.ws";
+export { meta as Button } from "./button.ws";
diff --git a/packages/sdk-components-react-radix/src/props.ts b/packages/sdk-components-react-radix/src/props.ts
index 39cbeeac2b..6f7845e88a 100644
--- a/packages/sdk-components-react-radix/src/props.ts
+++ b/packages/sdk-components-react-radix/src/props.ts
@@ -37,3 +37,4 @@ export {
propsMetaTabsTrigger as TabsTrigger,
propsMetaTabsContent as TabsContent,
} from "./tabs.ws";
+export { propsMeta as Button } from "./button.ws";
diff --git a/packages/sdk-components-react-radix/src/theme/tailwind-classes.ts b/packages/sdk-components-react-radix/src/theme/tailwind-classes.ts
index 6652940ac3..7e573e5312 100644
--- a/packages/sdk-components-react-radix/src/theme/tailwind-classes.ts
+++ b/packages/sdk-components-react-radix/src/theme/tailwind-classes.ts
@@ -106,19 +106,47 @@ type NonNumeric<T extends string> = T extends `${infer Z extends number}`
: T;
export const border = (
- borderWidth?: StringEnumToNumeric<keyof EvaluatedDefaultTheme["borderWidth"]>
+ borderWidthOrColor?:
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["borderWidth"]>
+ | keyof EvaluatedDefaultTheme["colors"]
): EmbedTemplateStyleDecl[] => {
- const key = `${borderWidth ?? "DEFAULT"}` as const;
+ if (
+ typeof borderWidthOrColor === "number" ||
+ borderWidthOrColor === undefined
+ ) {
+ const key = `${borderWidthOrColor ?? "DEFAULT"}` as const;
- const valueString = theme("borderWidth")?.[key] ?? "1px";
+ const valueString = theme("borderWidth")?.[key] ?? "1px";
+
+ const value = parseCssValue("borderTopWidth", valueString);
+ return [
+ ...preflight(),
+ { property: "borderTopWidth", value },
+ { property: "borderRightWidth", value },
+ { property: "borderBottomWidth", value },
+ { property: "borderLeftWidth", value },
+ ];
+ }
+
+ const value = parseCssValue("color", theme("colors")[borderWidthOrColor]);
- const value = parseCssValue("borderTopWidth", valueString);
return [
- ...preflight(),
- { property: "borderTopWidth", value },
- { property: "borderRightWidth", value },
- { property: "borderBottomWidth", value },
- { property: "borderLeftWidth", value },
+ {
+ property: "borderTopColor",
+ value,
+ },
+ {
+ property: "borderRightColor",
+ value,
+ },
+ {
+ property: "borderBottomColor",
+ value,
+ },
+ {
+ property: "borderLeftColor",
+ value,
+ },
];
};
@@ -528,6 +556,32 @@ export const text = (
];
};
+export const underline = (): EmbedTemplateStyleDecl[] => {
+ return [
+ {
+ property: "textDecorationLine",
+ value: { type: "keyword", value: "underline" },
+ },
+ ];
+};
+
+export const underlineOffset = (
+ offset: StringEnumToNumeric<
+ keyof EvaluatedDefaultTheme["textUnderlineOffset"]
+ >
+): EmbedTemplateStyleDecl[] => {
+ const key = `${offset}` as const;
+ const valueString = theme("textUnderlineOffset")[key];
+ const value = parseCssValue("textUnderlineOffset", valueString);
+
+ return [
+ {
+ property: "textUnderlineOffset",
+ value,
+ },
+ ];
+};
+
const weights = {
thin: "100",
extralight: "200",
diff --git a/packages/sdk-components-react-radix/src/theme/tailwind-colors.ts b/packages/sdk-components-react-radix/src/theme/tailwind-colors.ts
index 220bdf3f06..bc9dd2eb54 100644
--- a/packages/sdk-components-react-radix/src/theme/tailwind-colors.ts
+++ b/packages/sdk-components-react-radix/src/theme/tailwind-colors.ts
@@ -19,6 +19,15 @@ export const colors = {
ring: "rgb(148, 163, 184)",
mutedForeground: "rgb(100, 116, 139)",
muted: `hsl(210 40% 96.1%)`,
+ primary: "rgb(15, 23, 42)",
+ primaryForeground: "hsl(210 40% 98%)",
+ destructive: "rgb(239, 68, 68)",
+ destructiveForeground: "rgb(248, 250, 252)",
+ accent: "rgb(241, 245, 249)",
+ accentForeground: "rgb(15, 23, 42)",
+ input: "rgb(226, 232, 240)",
+ secondary: "rgb(241, 245, 249)",
+ secondaryForeground: "rgb(15, 23, 42)",
} as const;
/*
@@ -26,20 +35,4 @@ export const colors = {
--card: 0 0% 100%;
--card-foreground: 222.2 84% 4.9%;
-
---input: 214.3 31.8% 91.4%;
-
---primary: 222.2 47.4% 11.2%;
---primary-foreground: 210 40% 98%;
-
---secondary: 210 40% 96.1%;
---secondary-foreground: 222.2 47.4% 11.2%;
-
---accent: 210 40% 96.1%;
---accent-foreground: 222.2 47.4% 11.2%;
-
---destructive: 0 84.2% 60.2%;
---destructive-foreground: 210 40% 98%;
-
---ring: 215 20.2% 65.1%;
*/