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
Two Rows Small Icon Button Container & Small Icon Button (#987)
Roman Pominov582d71bf36be
diff --git a/.lostpixel/baseline/library-small-icon-button--small-icon-button.png b/.lostpixel/baseline/library-small-icon-button--small-icon-button.pngnew file mode 100644index 0000000000..84c5f300beBinary files /dev/null and b/.lostpixel/baseline/library-small-icon-button--small-icon-button.png differdiff --git a/.lostpixel/baseline/library-two-rows-small-icon-button-container--two-rows-small-icon-button-container.png b/.lostpixel/baseline/library-two-rows-small-icon-button-container--two-rows-small-icon-button-container.pngnew file mode 100644index 0000000000..9d5f376341Binary files /dev/null and b/.lostpixel/baseline/library-two-rows-small-icon-button-container--two-rows-small-icon-button-container.png differdiff --git a/packages/design-system/.storybook/preview.js b/packages/design-system/.storybook/preview.jsindex ea510da300..c644259b63 100644--- a/packages/design-system/.storybook/preview.js+++ b/packages/design-system/.storybook/preview.js@@ -1,4 +1,5 @@import "@webstudio-is/storybook-config/setup-fonts";+import { color } from "../src/__generated__/figma-design-tokens";export const parameters = {actions: { argTypesRegex: "^on[A-Z].*" },@@ -8,4 +9,15 @@ export const parameters = {date: /Date$/,},},+ backgrounds: {+ default: "White",+ values: [+ { name: "White", value: "#ffffff" },+ { name: "Black", value: "#000000" },+ { name: "Panel", value: color.backgroundPanel },+ { name: "Maintenance Dark", value: color.maintenanceDark },+ { name: "Maintenance Medium", value: color.maintenanceMedium },+ { name: "Maintenance Light", value: color.maintenanceLight },+ ],+ },};diff --git a/packages/design-system/src/components/small-icon-button.stories.tsx b/packages/design-system/src/components/small-icon-button.stories.tsxnew file mode 100644index 0000000000..c591d2ab4d--- /dev/null+++ b/packages/design-system/src/components/small-icon-button.stories.tsx@@ -0,0 +1,93 @@+import { type ComponentProps } from "react";+import { MenuIcon, CrossIcon, TrashIcon } from "@webstudio-is/icons";+import {+ SmallIconButton,+ smallIconButtonStates,+ smallIconButtonVariants,+} from "./small-icon-button";+import { StorySection, StoryGrid } from "./storybook";++const iconsMap = {+ "<MenuIcon>": <MenuIcon />,+ "<CrossIcon>": <CrossIcon />,+ "<TrashIcon>": <TrashIcon />,+} as const;++export const Demo = ({+ icon,+ ...rest+}: Omit<ComponentProps<typeof SmallIconButton>, "icon"> & {+ icon: keyof typeof iconsMap;+}) => (+ <>+ <StorySection title="Configurable">+ <SmallIconButton icon={iconsMap[icon]} {...rest} />+ </StorySection>++ <StorySection title="Variants & States">+ <StoryGrid>+ {smallIconButtonVariants.map((variant) => (+ <StoryGrid horizontal key={variant}>+ {smallIconButtonStates.map((state) => (+ <SmallIconButton+ key={state}+ title={`${variant} ${state}`}+ icon={<TrashIcon />}+ state={state}+ variant={variant}+ />+ ))}+ </StoryGrid>+ ))}+ </StoryGrid>+ </StorySection>++ <StorySection title="Focus">+ <StoryGrid>+ {smallIconButtonVariants.map((variant) => (+ <StoryGrid horizontal key={variant}>+ {smallIconButtonStates.map((state) => (+ <SmallIconButton+ key={state}+ title={`${variant} ${state}`}+ icon={<TrashIcon />}+ state={state}+ variant={variant}+ focused+ />+ ))}+ </StoryGrid>+ ))}+ </StoryGrid>+ </StorySection>+ </>+);++Demo.argTypes = {+ icon: {+ defaultValue: "<MenuIcon>",+ control: { type: "inline-radio", options: Object.keys(iconsMap) },+ },+ variant: {+ defaultValue: "normal",+ control: { type: "inline-radio", options: smallIconButtonVariants },+ },+ state: {+ defaultValue: "auto",+ control: { type: "inline-radio", options: smallIconButtonStates },+ },+ focused: {+ defaultValue: false,+ control: { type: "boolean" },+ },+};++Demo.storyName = "Small Icon Button";++export default {+ title: "Library/Small Icon Button",+ parameters: {+ // to make the variant=contrast visible+ backgrounds: { default: "Maintenance Medium" },+ },+};diff --git a/packages/design-system/src/components/small-icon-button.tsx b/packages/design-system/src/components/small-icon-button.tsxnew file mode 100644index 0000000000..282ddcc75e--- /dev/null+++ b/packages/design-system/src/components/small-icon-button.tsx@@ -0,0 +1,113 @@+/**+ * Implementation of the "Small Icon Button" component from:+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=4%3A3171+ */++import {+ forwardRef,+ type Ref,+ type ComponentProps,+ type ReactNode,+} from "react";+import { css, theme, type CSS } from "../stitches.config";++export const smallIconButtonVariants = [+ "normal",+ "contrast",+ "destructive",+] as const;++export const smallIconButtonStates = ["auto", "default", "hover"] as const;++const defaultColors = {+ normal: theme.colors.foregroundSubtle,+ destructive: theme.colors.foregroundSubtle,+ contrast: theme.colors.foregroundContrastMain,+};++const hoverColors = {+ normal: theme.colors.foregroundMain,+ destructive: theme.colors.foregroundDestructive,+ contrast: theme.colors.foregroundContrastMain,+};++const focusColors = {+ normal: theme.colors.borderFocus,+ destructive: theme.colors.borderFocus,+ contrast: theme.colors.borderContrast,+};++const perVariantStyle = (variant: typeof smallIconButtonVariants[number]) => ({+ "&[data-state=auto], &[data-state=default]": {+ color: defaultColors[variant],+ },+ "&[data-state=auto]:hover, &[data-state=hover]": {+ color: hoverColors[variant],+ },+ "&[data-focused=true], &:focus-visible": {+ borderRadius: theme.borderRadius[3],+ outline: `2px solid ${focusColors[variant]}`,+ },+});++const styles = css({+ all: "unset",+ width: theme.spacing[9],+ height: theme.spacing[9],+ variants: {+ variant: {+ normal: perVariantStyle("normal"),+ contrast: perVariantStyle("contrast"),+ destructive: perVariantStyle("destructive"),+ },+ },+});++type Props = {+ icon: ReactNode;+ variant?: typeof smallIconButtonVariants[number];+ state?: typeof smallIconButtonStates[number];+ focused?: boolean;+ css?: CSS;++ // might be set when <SmallIconButton> is asChild+ "data-state"?: string;+} & Omit<ComponentProps<"button">, "children">;++export const SmallIconButton = forwardRef(+ (+ {+ state,+ focused,+ variant,+ icon,+ css,+ className,+ "data-state": dataState,+ ...restProps+ }: Props,+ ref: Ref<HTMLButtonElement>+ ) => {+ // when button is used as a trigger for something that opens+ // <SomeTrigger asChild><SmallIconButton /></SomeTrigger>+ let finalState = dataState === "open" ? "hover" : undefined;++ // "state" wins over "data-state"+ if (state !== undefined) {+ finalState = state;+ }++ return (+ <button+ {...restProps}+ className={styles({ css, className, variant })}+ data-state={finalState ?? "auto"}+ data-focused={focused}+ ref={ref}+ >+ {icon}+ </button>+ );+ }+);+SmallIconButton.displayName = "SmallIconButton";diff --git a/packages/design-system/src/components/two-rows-icon-button-container.stories.tsx b/packages/design-system/src/components/two-rows-icon-button-container.stories.tsxnew file mode 100644index 0000000000..7a57ea338a--- /dev/null+++ b/packages/design-system/src/components/two-rows-icon-button-container.stories.tsx@@ -0,0 +1,15 @@+import { TwoRowsIconButtonContainer } from "./two-rows-icon-button-container";+import { SmallIconButton } from "./small-icon-button";+import { TrashIcon } from "@webstudio-is/icons";++export const Demo = () => (+ <TwoRowsIconButtonContainer>+ <SmallIconButton variant="destructive" icon={<TrashIcon />} />+ </TwoRowsIconButtonContainer>+);++Demo.storyName = "Two Rows Small Icon Button Container";++export default {+ title: "Library/Two Rows Small Icon Button Container",+};diff --git a/packages/design-system/src/components/two-rows-icon-button-container.tsx b/packages/design-system/src/components/two-rows-icon-button-container.tsxnew file mode 100644index 0000000000..c90c64154e--- /dev/null+++ b/packages/design-system/src/components/two-rows-icon-button-container.tsx@@ -0,0 +1,55 @@+/**+ * Implementation of the "Two Rows Small Icon Button Container" component from:+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=1844%3A5860+ */++import { forwardRef, type ReactNode, type Ref } from "react";+import { css, theme, type CSS } from "../stitches.config";++const curveStyles = css({+ fill: theme.colors.borderMain,+ alignSelf: "start",+ variants: { rotated: { true: { transform: "rotate(90deg)" } } },+});++const Curve = ({ rotated }: { rotated?: boolean }) => (+ <svg+ width="10"+ height="10"+ viewBox="0 0 10 10"+ xmlns="http://www.w3.org/2000/svg"+ className={curveStyles({ rotated })}+ >+ <path d="M10 10V6C10 2.68629 7.31371 0 4 0H0V1H4C6.76142 1 9 3.23858 9 6V10H10Z" />+ </svg>+);++const styles = css({+ display: "flex",+ flexDirection: "column",+ width: 19,+ gap: theme.spacing[3],+ alignItems: "center",+});++export const TwoRowsIconButtonContainer = forwardRef(+ (+ {+ children,+ className,+ css,+ }: {+ children?: ReactNode;+ css?: CSS;+ className?: string;+ },+ ref: Ref<HTMLDivElement>+ ) => (+ <div ref={ref} className={styles({ className, css })}>+ <Curve />+ {children}+ <Curve rotated />+ </div>+ )+);+TwoRowsIconButtonContainer.displayName = "TwoRowsIconButtonContainer";