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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Merge tabs trigger and button into single component (#2162)
Bogdan Chadkinf1b2c9b2dc9f
diff --git a/packages/sdk-components-react-radix/src/tabs.tsx b/packages/sdk-components-react-radix/src/tabs.tsxindex 3033eb2166..36cf3ef515 100644--- a/packages/sdk-components-react-radix/src/tabs.tsx+++ b/packages/sdk-components-react-radix/src/tabs.tsx@@ -5,9 +5,7 @@ import {type ComponentPropsWithoutRef,type ForwardRefExoticComponent,type ComponentPropsWithRef,- type ReactNode,forwardRef,- Children,} from "react";import { Root, List, Trigger, Content } from "@radix-ui/react-tabs";import {@@ -22,28 +20,17 @@ export const Tabs: ForwardRefExoticComponent<export const TabsList = List;-/**- * We're not exposing the 'asChild' property for the Trigger.- * Instead, we're enforcing 'asChild=true' for the Trigger and making it style-less.- * This avoids situations where the Trigger inadvertently passes all styles to its child,- * which would prevent us from displaying styles properly in the builder.- */export const TabsTrigger = forwardRef<HTMLButtonElement,- { value: string; children: ReactNode }->(({ value, children, ...props }, ref) => {- const firstChild = Children.toArray(children)[0];+ ComponentPropsWithoutRef<typeof Trigger>+>(({ value, ...props }, ref) => {const index = getIndexWithinAncestorFromComponentProps(props);- return (- <Trigger ref={ref} value={value ?? index} asChild={true} {...props}>- {firstChild ?? <button>Add button</button>}- </Trigger>- );+ return <Trigger ref={ref} value={value ?? index} {...props} />;});export const TabsContent = forwardRef<HTMLDivElement,- Omit<ComponentPropsWithoutRef<typeof Content>, "asChild">+ ComponentPropsWithoutRef<typeof Content>>(({ value, ...props }, ref) => {const index = getIndexWithinAncestorFromComponentProps(props);return <Content ref={ref} value={value ?? index} {...props} />;diff --git a/packages/sdk-components-react-radix/src/tabs.ws.ts b/packages/sdk-components-react-radix/src/tabs.ws.tsindex a39e7dd834..fc31e6aaa7 100644--- a/packages/sdk-components-react-radix/src/tabs.ws.ts+++ b/packages/sdk-components-react-radix/src/tabs.ws.ts@@ -10,7 +10,7 @@ import type {WsComponentMeta,WsComponentPropsMeta,} from "@webstudio-is/react-sdk";-import { div } from "@webstudio-is/react-sdk/css-normalize";+import { button, div } from "@webstudio-is/react-sdk/css-normalize";import * as tc from "./theme/tailwind-classes";import {propsTabs,@@ -32,8 +32,11 @@ const presetStyle = {* Copyright (c) 2023 shadcn**/-// inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm-const tabsTriggerStyles: EmbedTemplateStyleDecl[] = [+// inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all+// focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2+// disabled:pointer-events-none disabled:opacity-50+// data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm+const tabsTriggerStyles = [tc.inlineFlex(),tc.items("center"),tc.justify("center"),@@ -104,26 +107,14 @@ export const metaTabs: WsComponentMeta = {{type: "instance",component: "TabsTrigger",- children: [- {- type: "instance",- component: "Button",- styles: tabsTriggerStyles,- children: [{ type: "text", value: "Account" }],- },- ],+ styles: tabsTriggerStyles,+ children: [{ type: "text", value: "Account" }],},{type: "instance",component: "TabsTrigger",- children: [- {- type: "instance",- component: "Button",- styles: tabsTriggerStyles,- children: [{ type: "text", value: "Password" }],- },- ],+ styles: tabsTriggerStyles,+ children: [{ type: "text", value: "Password" }],},],},@@ -162,6 +153,24 @@ export const metaTabsTrigger: WsComponentMeta = {requiredAncestors: ["TabsList"],invalidAncestors: ["TabsTrigger"],indexWithinAncestor: "Tabs",+ presetStyle: {+ button: [+ button,+ {+ property: "backgroundColor",+ value: { type: "keyword", value: "transparent" },+ } as const,+ {+ property: "backgroundImage",+ value: { type: "keyword", value: "none" },+ } as const,+ {+ property: "cursor",+ value: { type: "keyword", value: "pointer" },+ } as const,+ tc.border(0),+ ].flat(),+ },};export const metaTabsContent: WsComponentMeta = {