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
improve story variant coverage and fix TS errors
Oleg Isonen211f4e9b2dc1
diff --git a/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.stories.tsx b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.stories.tsxindex 87a5eb727a..e9a50f6075 100644--- a/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.stories.tsx+++ b/apps/builder/app/builder/features/keyboard-shortcuts-dialog/keyboard-shortcuts-dialog.stories.tsx@@ -2,7 +2,7 @@ import type { Meta } from "@storybook/react";import { useEffect } from "react";import { subscribeCommands } from "~/builder/shared/commands";import {- KeyboardShortcutsDialog,+ KeyboardShortcutsDialog as KeyboardShortcutsDialogComponent,openKeyboardShortcutsDialog,} from "./keyboard-shortcuts-dialog";@@ -13,7 +13,7 @@ export default {title: "Keyboard Shortcuts Dialog",} satisfies Meta;-export const KeyboardShortcuts = () => {+export const KeyboardShortcutsDialog = () => {useEffect(openKeyboardShortcutsDialog, []);- return <KeyboardShortcutsDialog />;+ return <KeyboardShortcutsDialogComponent />;};diff --git a/apps/builder/app/builder/features/style-panel/sections/position/inset-layout.stories.tsx b/apps/builder/app/builder/features/style-panel/sections/position/inset-layout.stories.tsxindex 57cc927e68..6299b42af8 100644--- a/apps/builder/app/builder/features/style-panel/sections/position/inset-layout.stories.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/position/inset-layout.stories.tsx@@ -1,21 +1,70 @@import type { Meta } from "@storybook/react";-import { InsetLayout } from "./inset-layout";-import { Grid, theme, Text } from "@webstudio-is/design-system";+import { InsetLayout as InsetLayoutComponent } from "./inset-layout";+import { Flex, Grid, Text, theme } from "@webstudio-is/design-system";+import type { CssProperty } from "@webstudio-is/css-engine";-const Cell = () => (- <Text variant={"spaceSectionValueText"}>auto{/*1.275​rem*/}</Text>+const Cell = ({ label = "auto" }: { label?: string }) => (+ <Text variant={"spaceSectionValueText"}>{label}</Text>);-export const InsetLayoutComponent = () => (- <Grid css={{ width: theme.spacing[22], height: theme.spacing[18] }}>- <InsetLayout- renderCell={() => <Cell />}- getActiveProperties={() => []}- onHover={(hoverProps) => {- console.info(hoverProps);- }}- />- </Grid>+export const InsetLayout = () => (+ <Flex direction="column" gap="3" css={{ width: theme.sizes.sidebarWidth }}>+ <Text variant="labels">Default (no active properties)</Text>+ <Grid css={{ height: theme.spacing[18] }}>+ <InsetLayoutComponent+ renderCell={() => <Cell />}+ getActiveProperties={() => []}+ onHover={() => {}}+ />+ </Grid>++ <Text variant="labels">Single side active (top)</Text>+ <Grid css={{ height: theme.spacing[18] }}>+ <InsetLayoutComponent+ renderCell={(property) => (+ <Cell label={property === "top" ? "10px" : "auto"} />+ )}+ getActiveProperties={() => ["top"] as CssProperty[]}+ onHover={() => {}}+ />+ </Grid>++ <Text variant="labels">Opposing pair active (left + right)</Text>+ <Grid css={{ height: theme.spacing[18] }}>+ <InsetLayoutComponent+ renderCell={(property) => {+ if (property === "left") {+ return <Cell label="20%" />;+ }+ if (property === "right") {+ return <Cell label="5rem" />;+ }+ return <Cell />;+ }}+ getActiveProperties={() => ["left", "right"] as CssProperty[]}+ onHover={() => {}}+ />+ </Grid>++ <Text variant="labels">All sides active</Text>+ <Grid css={{ height: theme.spacing[18] }}>+ <InsetLayoutComponent+ renderCell={(property) => {+ const values: Record<string, string> = {+ top: "0px",+ right: "123.27rem",+ bottom: "auto",+ left: "-20%",+ };+ return <Cell label={values[property] ?? "auto"} />;+ }}+ getActiveProperties={() =>+ ["top", "right", "bottom", "left"] as CssProperty[]+ }+ onHover={() => {}}+ />+ </Grid>+ </Flex>);export default {diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-badge.stories.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-badge.stories.tsxindex 502d8c2663..3ac708a09c 100644--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-badge.stories.tsx+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-badge.stories.tsx@@ -1,21 +1,42 @@import type { StoryFn } from "@storybook/react";-import { Flex } from "@webstudio-is/design-system";-import { StyleSourceBadge } from "./style-source-badge";+import { Box, Flex, Text, theme } from "@webstudio-is/design-system";+import { StyleSourceBadge as StyleSourceBadgeComponent } from "./style-source-badge";export default {title: "Style Panel/Style Source Badge",- component: StyleSourceBadge,+ component: StyleSourceBadgeComponent,};-export const All: StoryFn<typeof StyleSourceBadge> = () => {- return (- <Flex gap="1">- <StyleSourceBadge source="tag" variant="small">- Tag- </StyleSourceBadge>- <StyleSourceBadge source="token" variant="small">- Token- </StyleSourceBadge>+export const StyleSourceBadge: StoryFn<+ typeof StyleSourceBadgeComponent+> = () => (+ <Box css={{ width: theme.sizes.sidebarWidth }}>+ <Flex direction="column" gap="3">+ <Text variant="labels">All source variants</Text>+ <Flex gap="1" wrap="wrap">+ <StyleSourceBadgeComponent source="local" variant="small">+ Local+ </StyleSourceBadgeComponent>+ <StyleSourceBadgeComponent source="token" variant="small">+ Token+ </StyleSourceBadgeComponent>+ <StyleSourceBadgeComponent source="tag" variant="small">+ Tag+ </StyleSourceBadgeComponent>+ <StyleSourceBadgeComponent source="breakpoint" variant="small">+ Breakpoint+ </StyleSourceBadgeComponent>+ <StyleSourceBadgeComponent source="instance" variant="small">+ Instance+ </StyleSourceBadgeComponent>+ </Flex>++ <Text variant="labels">Long label (truncation)</Text>+ <Flex gap="1">+ <StyleSourceBadgeComponent source="token" variant="small">+ Very long token name that should be truncated+ </StyleSourceBadgeComponent>+ </Flex></Flex>- );-};+ </Box>+);diff --git a/apps/builder/app/builder/shared/asset-manager/asset-manager.stories.tsx b/apps/builder/app/builder/shared/asset-manager/asset-manager.stories.tsxindex f4cd2e1963..6efecbcf46 100644--- a/apps/builder/app/builder/shared/asset-manager/asset-manager.stories.tsx+++ b/apps/builder/app/builder/shared/asset-manager/asset-manager.stories.tsx@@ -1,5 +1,5 @@import type { Meta, StoryObj } from "@storybook/react";-import { AssetManager } from "./asset-manager";+import { AssetManager as AssetManagerComponent } from "./asset-manager";import {ALLOWED_FILE_TYPES,IMAGE_EXTENSIONS,@@ -37,7 +37,7 @@ const createMockAssets = (): Asset[] => {export default {title: "Asset Manager",- component: AssetManager,+ component: AssetManagerComponent,} satisfies Meta;const AssetManagerStory = () => {@@ -48,11 +48,11 @@ const AssetManagerStory = () => {return (<div style={{ width: 400, display: "flex" }}>- <AssetManager />+ <AssetManagerComponent /></div>);};-export const AllFileTypes: StoryObj = {+export const AssetManager: StoryObj = {render: () => <AssetManagerStory />,};diff --git a/packages/design-system/src/components/component-card.stories.tsx b/packages/design-system/src/components/component-card.stories.tsxindex 694c17f6a5..cc9ee6c8c9 100644--- a/packages/design-system/src/components/component-card.stories.tsx+++ b/packages/design-system/src/components/component-card.stories.tsx@@ -3,62 +3,81 @@ import { StorySection } from "./storybook";import { ComponentCard as ComponentCardComponent } from "./component-card";import { TooltipProvider } from "./tooltip";import { Grid } from "./grid";+import { Text } from "./text";export default {title: "Component Card",};-export const ComponentCard = () => {- return (- <TooltipProvider>- <StorySection title="States">- <Grid css={{ gridTemplateColumns: "repeat(3, 70px)" }} gap="2">- <ComponentCardComponent icon={<BoxIcon />} label="Box" tabIndex={1} />- <ComponentCardComponent- icon={<BoxIcon />}- label="Box"- state="hover"- tabIndex={1}- />- <ComponentCardComponent- icon={<BoxIcon />}- label="Box"- state="selected"- tabIndex={1}- />- <ComponentCardComponent- icon={<BoxIcon />}- label="Box"- state="disabled"- tabIndex={1}- />- </Grid>- </StorySection>- <StorySection title="Labels">- <Grid gap="2" css={{ gridTemplateColumns: "repeat(3, 70px)" }}>- <ComponentCardComponent- icon={<BoxIcon />}- label="Single"- tabIndex={1}- />- <ComponentCardComponent- icon={<BoxIcon />}- label="Too many words too many"- tabIndex={1}- />- <ComponentCardComponent- icon={<BoxIcon />}- label="Manylongwordstotruncate Manylongwordstotruncate"- tabIndex={1}- />- <ComponentCardComponent- icon={<BoxIcon />}- label="Truncatedlongword"- tabIndex={1}- />- </Grid>- </StorySection>- </TooltipProvider>- );-};-ComponentCard.storyName = "Component Card";+export const ComponentCard = () => (+ <TooltipProvider>+ <StorySection title="States">+ <Grid css={{ gridTemplateColumns: "repeat(4, 70px)" }} gap="2">+ <Text variant="labels">default</Text>+ <Text variant="labels">hover</Text>+ <Text variant="labels">selected</Text>+ <Text variant="labels">disabled</Text>+ <ComponentCardComponent icon={<BoxIcon />} label="Box" tabIndex={0} />+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Box"+ state="hover"+ tabIndex={0}+ />+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Box"+ state="selected"+ tabIndex={0}+ />+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Box"+ state="disabled"+ tabIndex={0}+ />+ </Grid>+ </StorySection>+ <StorySection title="Labels">+ <Grid gap="2" css={{ gridTemplateColumns: "repeat(4, 70px)" }}>+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Single"+ tabIndex={0}+ />+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Too many words too many"+ tabIndex={0}+ />+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Manylongwordstotruncate Manylongwordstotruncate"+ tabIndex={0}+ />+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Truncatedlongword"+ tabIndex={0}+ />+ </Grid>+ </StorySection>+ <StorySection title="With description tooltip">+ <Grid gap="2" css={{ gridTemplateColumns: "repeat(2, 70px)" }}>+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Box"+ description="A generic container element"+ tabIndex={0}+ />+ <ComponentCardComponent+ icon={<BoxIcon />}+ label="Box"+ description="Tooltip disabled"+ disableTooltip+ tabIndex={0}+ />+ </Grid>+ </StorySection>+ </TooltipProvider>+);diff --git a/packages/design-system/src/components/enhanced-tooltip.stories.tsx b/packages/design-system/src/components/enhanced-tooltip.stories.tsxindex 90cb6a34fd..c9b1f486d0 100644--- a/packages/design-system/src/components/enhanced-tooltip.stories.tsx+++ b/packages/design-system/src/components/enhanced-tooltip.stories.tsx@@ -1,18 +1,72 @@-import { EnhancedTooltip, EnhancedTooltipProvider } from "./enhanced-tooltip";+import {+ EnhancedTooltip as EnhancedTooltipComponent,+ EnhancedTooltipProvider,+} from "./enhanced-tooltip";import { Flex } from "./flex";+import { Text } from "./text";import { InputField } from "./input-field";+import { StorySection } from "./storybook";+import { Button } from "./button";export default {title: "Enhanced Tooltip",- component: EnhancedTooltip,+ component: EnhancedTooltipComponent,};-export const Simple = () => (+export const EnhancedTooltip = () => (<EnhancedTooltipProvider>- <Flex css={{ padding: 40 }}>- <EnhancedTooltip content="Hello world" defaultOpen>- <InputField />- </EnhancedTooltip>- </Flex>+ <StorySection title="Default (open)">+ <Flex css={{ padding: 40 }}>+ <EnhancedTooltipComponent content="Hello world" defaultOpen>+ <InputField />+ </EnhancedTooltipComponent>+ </Flex>+ </StorySection>++ <StorySection title="With JSX content">+ <Flex css={{ padding: 40 }}>+ <EnhancedTooltipComponent+ content={+ <Flex direction="column" gap="1">+ <Text variant="labels">Tooltip title</Text>+ <Text variant="small" color="moreSubtle">+ Additional description text+ </Text>+ </Flex>+ }+ defaultOpen+ >+ <InputField placeholder="Hover me" />+ </EnhancedTooltipComponent>+ </Flex>+ </StorySection>++ <StorySection title="Side placements">+ <Flex gap="6" css={{ padding: 60 }}>+ <EnhancedTooltipComponent content="Top" side="top" defaultOpen>+ <Button>Top</Button>+ </EnhancedTooltipComponent>+ <EnhancedTooltipComponent content="Right" side="right" defaultOpen>+ <Button>Right</Button>+ </EnhancedTooltipComponent>+ <EnhancedTooltipComponent content="Bottom" side="bottom" defaultOpen>+ <Button>Bottom</Button>+ </EnhancedTooltipComponent>+ <EnhancedTooltipComponent content="Left" side="left" defaultOpen>+ <Button>Left</Button>+ </EnhancedTooltipComponent>+ </Flex>+ </StorySection>++ <StorySection title="Custom delay">+ <Flex css={{ padding: 40 }}>+ <EnhancedTooltipComponent+ content="Shows after 500ms"+ delayDuration={500}+ >+ <InputField placeholder="Short delay (500ms)" />+ </EnhancedTooltipComponent>+ </Flex>+ </StorySection></EnhancedTooltipProvider>);diff --git a/packages/design-system/src/components/kbd.stories.tsx b/packages/design-system/src/components/kbd.stories.tsxindex e82e7c61b8..16dbbfefce 100644--- a/packages/design-system/src/components/kbd.stories.tsx+++ b/packages/design-system/src/components/kbd.stories.tsx@@ -1,9 +1,95 @@-import { Kbd } from "./kbd";+import { Kbd as KbdComponent } from "./kbd";+import { Flex } from "./flex";+import { Text } from "./text";+import { StorySection, StoryGrid } from "./storybook";export default {title: "Kbd",};-const KbdStory = () => <Kbd value={["meta", "z"]} />;+export const Kbd = () => (+ <>+ <StorySection title="Colors">+ <StoryGrid>+ <Flex direction="column" gap="1">+ <Text variant="labels">subtle (default)</Text>+ <KbdComponent value={["meta", "z"]} />+ </Flex>+ <Flex direction="column" gap="1">+ <Text variant="labels">moreSubtle</Text>+ <KbdComponent value={["meta", "z"]} color="moreSubtle" />+ </Flex>+ <Flex direction="column" gap="1">+ <Text variant="labels">contrast</Text>+ <KbdComponent value={["meta", "z"]} color="contrast" />+ </Flex>+ </StoryGrid>+ </StorySection>-export { KbdStory as Kbd };+ <StorySection title="Variant">+ <StoryGrid>+ <Flex direction="column" gap="1">+ <Text variant="labels">default</Text>+ <KbdComponent value={["meta", "c"]} />+ </Flex>+ <Flex direction="column" gap="1">+ <Text variant="labels">regular</Text>+ <KbdComponent value={["meta", "c"]} variant="regular" />+ </Flex>+ </StoryGrid>+ </StorySection>++ <StorySection title="Key combinations">+ <Flex direction="column" gap="2">+ <Flex gap="3" align="center">+ <Text variant="labels" css={{ width: 120 }}>+ Undo+ </Text>+ <KbdComponent value={["meta", "z"]} />+ </Flex>+ <Flex gap="3" align="center">+ <Text variant="labels" css={{ width: 120 }}>+ Redo+ </Text>+ <KbdComponent value={["meta", "shift", "z"]} />+ </Flex>+ <Flex gap="3" align="center">+ <Text variant="labels" css={{ width: 120 }}>+ Delete+ </Text>+ <KbdComponent value={["backspace"]} />+ </Flex>+ <Flex gap="3" align="center">+ <Text variant="labels" css={{ width: 120 }}>+ Enter+ </Text>+ <KbdComponent value={["enter"]} />+ </Flex>+ <Flex gap="3" align="center">+ <Text variant="labels" css={{ width: 120 }}>+ Tab+ </Text>+ <KbdComponent value={["tab"]} />+ </Flex>+ <Flex gap="3" align="center">+ <Text variant="labels" css={{ width: 120 }}>+ Alt + click+ </Text>+ <KbdComponent value={["alt", "click"]} />+ </Flex>+ <Flex gap="3" align="center">+ <Text variant="labels" css={{ width: 120 }}>+ Click+ </Text>+ <KbdComponent value={["click"]} />+ </Flex>+ <Flex gap="3" align="center">+ <Text variant="labels" css={{ width: 120 }}>+ Single key+ </Text>+ <KbdComponent value={["d"]} />+ </Flex>+ </Flex>+ </StorySection>+ </>+);diff --git a/packages/design-system/src/components/search-field.stories.tsx b/packages/design-system/src/components/search-field.stories.tsxindex 36edefc26a..b3a76288e4 100644--- a/packages/design-system/src/components/search-field.stories.tsx+++ b/packages/design-system/src/components/search-field.stories.tsx@@ -1,6 +1,7 @@import { Flex } from "./flex";import { Text } from "./text";import { SearchField as SearchFieldComponent } from "./search-field";+import { StorySection } from "./storybook";export default {title: "Search Field",@@ -8,10 +9,18 @@ export default {};export const SearchField = () => (- <Flex direction="column" gap="3" css={{ width: 240 }}>- <Text variant="labels">Empty</Text>- <SearchFieldComponent />- <Text variant="labels">With value</Text>- <SearchFieldComponent value="somevalue" title="Search" />- </Flex>+ <>+ <StorySection title="States">+ <Flex direction="column" gap="3" css={{ width: 240 }}>+ <Text variant="labels">Empty</Text>+ <SearchFieldComponent placeholder="Search…" />+ <Text variant="labels">With value</Text>+ <SearchFieldComponent value="somevalue" title="Search" />+ <Text variant="labels">Auto focus</Text>+ <SearchFieldComponent autoFocus placeholder="Focused on mount" />+ <Text variant="labels">Disabled</Text>+ <SearchFieldComponent disabled placeholder="Disabled" />+ </Flex>+ </StorySection>+ </>);diff --git a/packages/design-system/src/components/separator.stories.tsx b/packages/design-system/src/components/separator.stories.tsxindex 355b317f56..0a15e4cc86 100644--- a/packages/design-system/src/components/separator.stories.tsx+++ b/packages/design-system/src/components/separator.stories.tsx@@ -1,9 +1,28 @@-import { Separator } from "./separator";+import { Separator as SeparatorComponent } from "./separator";+import { Flex } from "./flex";+import { Text } from "./text";+import { StorySection } from "./storybook";export default {title: "Separator",};-const SeparatorStory = () => <Separator />;+export const Separator = () => (+ <>+ <StorySection title="Horizontal (default)">+ <Flex direction="column" gap="2" css={{ width: 200 }}>+ <Text>Above</Text>+ <SeparatorComponent />+ <Text>Below</Text>+ </Flex>+ </StorySection>-export { SeparatorStory as Separator };+ <StorySection title="Vertical">+ <Flex gap="2" align="center" css={{ height: 40 }}>+ <Text>Left</Text>+ <SeparatorComponent orientation="vertical" />+ <Text>Right</Text>+ </Flex>+ </StorySection>+ </>+);diff --git a/packages/design-system/src/components/text.stories.tsx b/packages/design-system/src/components/text.stories.tsxindex 475c90370c..16358ddf74 100644--- a/packages/design-system/src/components/text.stories.tsx+++ b/packages/design-system/src/components/text.stories.tsx@@ -1,20 +1,68 @@-import { textVariants, Text } from "./text";-import { StorySection } from "./storybook";+import { textVariants, Text as TextComponent } from "./text";+import { StorySection, StoryGrid } from "./storybook";+import { Flex } from "./flex";const variants = Object.keys(textVariants) as (keyof typeof textVariants)[];-const Story = () => (+const colors = [+ "main",+ "contrast",+ "subtle",+ "moreSubtle",+ "disabled",+ "success",+ "destructive",+] as const;++export const Text = () => (<>- {variants.map((variant) => (- <StorySection withBorder key={variant} title={variant}>- <Text variant={variant}>- The quick brown fox jumps over the lazy dog- </Text>- </StorySection>- ))}+ <StorySection title="Variants">+ {variants.map((variant) => (+ <StorySection withBorder key={variant} title={variant}>+ <TextComponent variant={variant}>+ The quick brown fox jumps over the lazy dog+ </TextComponent>+ </StorySection>+ ))}+ </StorySection>++ <StorySection title="Colors">+ <StoryGrid>+ {colors.map((color) => (+ <TextComponent key={color} color={color}>+ {color}+ </TextComponent>+ ))}+ </StoryGrid>+ </StorySection>++ <StorySection title="Alignment">+ <Flex direction="column" gap="2" css={{ width: 300 }}>+ <TextComponent align="left">Left aligned</TextComponent>+ <TextComponent align="center">Center aligned</TextComponent>+ <TextComponent align="right">Right aligned</TextComponent>+ </Flex>+ </StorySection>++ <StorySection title="Truncate">+ <Flex direction="column" gap="2" css={{ width: 200 }}>+ <TextComponent truncate>+ This is a very long text that should be truncated at the container+ edge+ </TextComponent>+ <TextComponent>+ This is a very long text that should NOT be truncated and will wrap+ </TextComponent>+ </Flex>+ </StorySection>++ <StorySection title="User select">+ <TextComponent userSelect="none">+ This text cannot be selected (userSelect: none)+ </TextComponent>+ </StorySection></>);-export { Story as Text };export default {title: "Text",