diff --git a/.lostpixel/baseline/library-switch--switch.png b/.lostpixel/baseline/library-switch--switch.png new file mode 100644 index 0000000000..d543685f32 Binary files /dev/null and b/.lostpixel/baseline/library-switch--switch.png differ diff --git a/packages/design-system/src/components/switch.stories.tsx b/packages/design-system/src/components/switch.stories.tsx new file mode 100644 index 0000000000..15695a1ea8 --- /dev/null +++ b/packages/design-system/src/components/switch.stories.tsx @@ -0,0 +1,30 @@ +import { Switch } from "./switch"; +import { StorySection, StoryGrid } from "./storybook"; + +export default { + title: "Library/Switch", +}; + +const Story = () => { + return ( + <> + + + + + + + + + + + + + + + + + ); +}; + +export { Story as Switch }; diff --git a/packages/design-system/src/components/switch.tsx b/packages/design-system/src/components/switch.tsx index 8fab06370c..121a7a76ae 100644 --- a/packages/design-system/src/components/switch.tsx +++ b/packages/design-system/src/components/switch.tsx @@ -1,96 +1,77 @@ -import React from "react"; -import { styled, VariantProps, CSS } from "../stitches.config"; -import * as SwitchPrimitive from "@radix-ui/react-switch"; -import { theme } from "../stitches.config"; +/** + * Implementation of the "Switch" component from: + * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=1086%3A3430&t=WVRoENiFP3BSlQa7-0 + */ -const StyledThumb = styled(SwitchPrimitive.Thumb, { - position: "absolute", - left: 0, - width: 13, - height: 13, - backgroundColor: "white", +import { forwardRef, type ComponentProps, type Ref } from "react"; +import * as Primitive from "@radix-ui/react-switch"; +import { type CSS, css, theme } from "../stitches.config"; + +const padding = theme.spacing[1]; +const thumbOffset = `calc(${padding} + ${theme.spacing[2]})`; + +const switchStyles = css({ + all: "unset", // reset