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.

Update Select and Textarea (#1207)

Roman Pominov47d35ace8f17
diff --git a/apps/builder/app/builder/features/props-panel/controls/color.tsx b/apps/builder/app/builder/features/props-panel/controls/color.tsx
index 2dfefb4a23..41489dca55 100644
--- a/apps/builder/app/builder/features/props-panel/controls/color.tsx
+++ b/apps/builder/app/builder/features/props-panel/controls/color.tsx
@@ -1,4 +1,4 @@
-import { TextField, useId } from "@webstudio-is/design-system";
+import { TextField, theme, useId } from "@webstudio-is/design-system";
import {
type ControlProps,
getLabel,
@@ -39,7 +39,7 @@ export const ColorControl = ({
localValue.save();
}
}}
- css={{ width: 120 }}
+ css={{ width: theme.spacing[22] }}
/>
</HorizontalLayout>
);
diff --git a/apps/builder/app/builder/features/props-panel/controls/number.tsx b/apps/builder/app/builder/features/props-panel/controls/number.tsx
index d96b4e3a1c..8e2db3200d 100644
--- a/apps/builder/app/builder/features/props-panel/controls/number.tsx
+++ b/apps/builder/app/builder/features/props-panel/controls/number.tsx
@@ -1,4 +1,4 @@
-import { TextField, useId } from "@webstudio-is/design-system";
+import { TextField, theme, useId } from "@webstudio-is/design-system";
import {
type ControlProps,
getLabel,
@@ -48,7 +48,7 @@ export const NumberControl = ({
localValue.save();
}
}}
- css={{ width: 98 }}
+ css={{ width: theme.spacing[21] }}
/>
</HorizontalLayout>
);
diff --git a/apps/builder/app/builder/features/props-panel/controls/select.tsx b/apps/builder/app/builder/features/props-panel/controls/select.tsx
index 15f9f351ff..eab5e8c842 100644
--- a/apps/builder/app/builder/features/props-panel/controls/select.tsx
+++ b/apps/builder/app/builder/features/props-panel/controls/select.tsx
@@ -1,4 +1,5 @@
import { Flex, theme, useId, Select } from "@webstudio-is/design-system";
+import { humanizeString } from "~/shared/string-utils";
import { type ControlProps, getLabel, VerticalLayout } from "../shared";
export const SelectControl = ({
@@ -24,8 +25,9 @@ export const SelectControl = ({
id={id}
value={prop?.value}
options={options}
+ getLabel={humanizeString}
onChange={(value) => onChange({ type: "string", value })}
- css={{ flexGrow: 1 }}
+ fullWidth
/>
</Flex>
</VerticalLayout>
diff --git a/apps/builder/app/builder/features/props-panel/controls/text.tsx b/apps/builder/app/builder/features/props-panel/controls/text.tsx
index cc6027ea67..f4ed46c1f0 100644
--- a/apps/builder/app/builder/features/props-panel/controls/text.tsx
+++ b/apps/builder/app/builder/features/props-panel/controls/text.tsx
@@ -42,15 +42,12 @@ const AsInput = ({
localValue.save();
}
}}
- css={{ width: 120 }}
+ css={{ width: theme.spacing[22] }}
/>
</HorizontalLayout>
);
};
-// @todo: TextArea should support `rows` prop
-const TEXTAREA_LINE_HEIGHT = 16;
-
const AsTextarea = ({
label,
id,
@@ -60,7 +57,6 @@ const AsTextarea = ({
rows,
}: ImplementationProps & { rows: number }) => {
const localValue = useLocalValue(value, onChange);
- const height = rows * TEXTAREA_LINE_HEIGHT;
return (
<VerticalLayout label={label} id={id} onDelete={onDelete}>
@@ -70,7 +66,7 @@ const AsTextarea = ({
value={localValue.value}
onChange={(event) => localValue.set(event.target.value)}
onBlur={localValue.save}
- css={{ flexGrow: 1, height, minHeight: height }}
+ rows={rows ?? 1}
/>
</Flex>
</VerticalLayout>
diff --git a/apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx b/apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx
index 17b4dacdb7..fb7d8e2ae3 100644
--- a/apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/font-weight/font-weight-control.tsx
@@ -4,7 +4,6 @@ import { toValue } from "@webstudio-is/css-engine";
import { useMemo } from "react";
import { useAssets } from "~/builder/shared/assets";
import type { ControlProps } from "../../style-sections";
-import { theme } from "@webstudio-is/design-system";
import { isSupportedFontWeight } from "./is-supported-font-weight";
type FontWeightItem = {
@@ -103,17 +102,6 @@ export const FontWeightControl = ({
setValue(selected.weight);
}
}}
- ghost
- css={{
- // @todo this shouldn't be in design system by default
- gap: `calc(${theme.spacing[3]} / 2)`,
- paddingLeft: `calc(${theme.spacing[10]} / 2)`,
- height: `calc(${theme.spacing[11]} + ${theme.spacing[3]})`,
- boxShadow: `inset 0 0 0 1px ${theme.colors.slate7}`,
- textTransform: "capitalize",
- fontWeight: "inherit",
- "&:hover": { background: "none" },
- }}
/>
);
};
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
index 4d44e587bf..19a4875164 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
@@ -10,7 +10,7 @@ import {
SelectContent,
TextFieldIconButton,
styled,
- deprecatedTextStyles,
+ deprecatedTextStyle,
} from "@webstudio-is/design-system";
import { ChevronDownIcon, ChevronUpIcon } from "@webstudio-is/icons";
@@ -83,7 +83,7 @@ export const useUnitSelect = ({
return [isOpen, select];
};
-const StyledTrigger = styled(TextFieldIconButton, deprecatedTextStyles, {
+const StyledTrigger = styled(TextFieldIconButton, deprecatedTextStyle, {
px: 3,
});
diff --git a/apps/builder/app/builder/shared/floating-panel/floating-panel.tsx b/apps/builder/app/builder/shared/floating-panel/floating-panel.tsx
index 199763e5f3..d48bbbfd18 100644
--- a/apps/builder/app/builder/shared/floating-panel/floating-panel.tsx
+++ b/apps/builder/app/builder/shared/floating-panel/floating-panel.tsx
@@ -60,7 +60,7 @@ type FloatingPanelProps = {
onOpenChange?: (isOpen: boolean) => void;
};
-const contentStyles = css({ width: theme.spacing[30] });
+const contentStyle = css({ width: theme.spacing[30] });
export const FloatingPanel = ({
title,
@@ -82,7 +82,7 @@ export const FloatingPanel = ({
sideOffset={sideOffset}
side="left"
align="start"
- className={contentStyles()}
+ className={contentStyle()}
>
{content}
<FloatingPanelPopoverTitle>{title}</FloatingPanelPopoverTitle>
diff --git a/packages/design-system/src/components/__DEPRECATED__/popover.tsx b/packages/design-system/src/components/__DEPRECATED__/popover.tsx
index dbc3b29565..58499fa70f 100644
--- a/packages/design-system/src/components/__DEPRECATED__/popover.tsx
+++ b/packages/design-system/src/components/__DEPRECATED__/popover.tsx
@@ -2,7 +2,7 @@ import React from "react";
import { CrossLargeIcon } from "@webstudio-is/icons";
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { Box } from "../box";
-import { panelStyles } from "../panel";
+import { panelStyle } from "../panel";
import { Flex } from "../flex";
import { DeprecatedIconButton } from "./icon-button";
import { DeprecatedText2 } from "./text2";
@@ -18,7 +18,7 @@ export const DeprecatedPopover = ({ children, ...props }: PopoverProps) => {
return <PopoverPrimitive.Root {...props}>{children}</PopoverPrimitive.Root>;
};
-const StyledContent = styled(PopoverPrimitive.Content, panelStyles, {
+const StyledContent = styled(PopoverPrimitive.Content, panelStyle, {
backgroundColor: "white",
minWidth: 200,
minHeight: theme.spacing[13],
diff --git a/packages/design-system/src/components/__DEPRECATED__/text2.tsx b/packages/design-system/src/components/__DEPRECATED__/text2.tsx
index fc166396cf..2456d53de1 100644
--- a/packages/design-system/src/components/__DEPRECATED__/text2.tsx
+++ b/packages/design-system/src/components/__DEPRECATED__/text2.tsx
@@ -1,6 +1,6 @@
import { css, styled, theme } from "../../stitches.config";
-export const deprecatedTextStyles = css({
+export const deprecatedTextStyle = css({
// Reset
margin: 0,
lineHeight: 1,
@@ -96,4 +96,4 @@ export const deprecatedTextStyles = css({
/**
* For use as a standalone, single-line text element. If you need a multiline element - use Paragraph.
*/
-export const DeprecatedText2 = styled("div", deprecatedTextStyles);
+export const DeprecatedText2 = styled("div", deprecatedTextStyle);
diff --git a/packages/design-system/src/components/checkbox.tsx b/packages/design-system/src/components/checkbox.tsx
index 29be5400cd..af44774ddf 100644
--- a/packages/design-system/src/components/checkbox.tsx
+++ b/packages/design-system/src/components/checkbox.tsx
@@ -12,7 +12,7 @@ import {
} from "@webstudio-is/icons";
import { type CSS, css, theme, styled } from "../stitches.config";
-const checkboxStyles = css({
+const checkboxStyle = css({
all: "unset", // reset <button>
width: theme.spacing[9],
@@ -48,7 +48,7 @@ const checkboxStyles = css({
},
});
-const iconStyles = css({ position: "relative" });
+const iconStyle = css({ position: "relative" });
const iconByState = {
checked: CheckboxCheckedFilledIcon,
@@ -69,7 +69,7 @@ const Button = forwardRef(
const Icon = iconByState[props["data-state"] ?? "unchecked"];
return (
<button {...props} ref={ref}>
- <Icon className={iconStyles()} />
+ <Icon className={iconStyle()} />
</button>
);
}
@@ -86,7 +86,7 @@ export const Checkbox = forwardRef(
ref: Ref<HTMLButtonElement>
) => (
<Primitive.Root
- className={checkboxStyles({ className, css })}
+ className={checkboxStyle({ className, css })}
{...props}
ref={ref}
asChild
diff --git a/packages/design-system/src/components/css-value-list-item.stories.tsx b/packages/design-system/src/components/css-value-list-item.stories.tsx
index 6e56c3adca..ec25ab5ae8 100644
--- a/packages/design-system/src/components/css-value-list-item.stories.tsx
+++ b/packages/design-system/src/components/css-value-list-item.stories.tsx
@@ -186,3 +186,4 @@ export const Declarative = (props: {
</Panel>
);
};
+Declarative.storyName = "CSS Value List Item";
diff --git a/packages/design-system/src/components/dialog.stories.tsx b/packages/design-system/src/components/dialog.stories.tsx
index 934e42eb84..59cc9e8716 100644
--- a/packages/design-system/src/components/dialog.stories.tsx
+++ b/packages/design-system/src/components/dialog.stories.tsx
@@ -14,11 +14,11 @@ export default {
title: "Library/Floating Panel/Dialog",
};
-const bodyStyles = css({
+const bodyStyle = css({
padding: theme.spacing[9],
});
-const descriptionStyles = css(textVariants.regular, {
+const descriptionStyle = css(textVariants.regular, {
marginTop: 0,
marginBottom: theme.spacing[9],
});
@@ -35,9 +35,9 @@ const DialogDemo = () => (
<Button>Open</Button>
</DialogTrigger>
<DialogContent>
- <div className={bodyStyles()}>
+ <div className={bodyStyle()}>
<DialogDescription asChild>
- <p className={descriptionStyles()}>This is a description</p>
+ <p className={descriptionStyle()}>This is a description</p>
</DialogDescription>
<div className={buttonsStyle()}>
<DialogClose asChild>
diff --git a/packages/design-system/src/components/dialog.tsx b/packages/design-system/src/components/dialog.tsx
index 9f6c2978bc..1c8de5a63a 100644
--- a/packages/design-system/src/components/dialog.tsx
+++ b/packages/design-system/src/components/dialog.tsx
@@ -2,7 +2,7 @@ import React, { type ReactNode, type ComponentProps, type Ref } from "react";
import * as Primitive from "@radix-ui/react-dialog";
import { css, theme, keyframes, type CSS } from "../stitches.config";
import { Title } from "./title";
-import { floatingPanelStyles, CloseButton, TitleSlot } from "./floating-panel";
+import { floatingPanelStyle, CloseButton, TitleSlot } from "./floating-panel";
export const Dialog = Primitive.Root;
export const DialogTrigger = Primitive.Trigger;
@@ -27,9 +27,9 @@ export const DialogContent = React.forwardRef(
) => {
return (
<Primitive.Portal>
- <Primitive.Overlay className={overlayStyles()} />
+ <Primitive.Overlay className={overlayStyle()} />
<Primitive.Content
- className={contentStyles({ className, css })}
+ className={contentStyle({ className, css })}
{...props}
ref={forwardedRef}
>
@@ -56,7 +56,7 @@ export const DialogTitle = ({
</Primitive.Close>
}
>
- <Primitive.Title className={titleStyles()}>{children}</Primitive.Title>
+ <Primitive.Title className={titleStyle()}>{children}</Primitive.Title>
</Title>
</TitleSlot>
);
@@ -68,7 +68,7 @@ const overlayShow = keyframes({
from: { opacity: 0 },
to: { opacity: 1 },
});
-const overlayStyles = css({
+const overlayStyle = css({
backgroundColor: "rgba(17, 24, 28, 0.66)",
position: "fixed",
inset: 0,
@@ -79,7 +79,7 @@ const contentShow = keyframes({
from: { opacity: 0, transform: "translate(-50%, -48%) scale(0.96)" },
to: { opacity: 1, transform: "translate(-50%, -50%) scale(1)" },
});
-const contentStyles = css(floatingPanelStyles, {
+const contentStyle = css(floatingPanelStyle, {
position: "fixed",
top: "50%",
left: "50%",
@@ -91,7 +91,7 @@ const contentStyles = css(floatingPanelStyles, {
animation: `${contentShow} 150ms ${theme.easing.easeOut}`,
});
-const titleStyles = css({
+const titleStyle = css({
// Resetting H2 styles (Primitive.Title is H2)
all: "unset",
});
diff --git a/packages/design-system/src/components/floating-panel-popover.stories.tsx b/packages/design-system/src/components/floating-panel-popover.stories.tsx
index 545a747a8a..35f07dc3c6 100644
--- a/packages/design-system/src/components/floating-panel-popover.stories.tsx
+++ b/packages/design-system/src/components/floating-panel-popover.stories.tsx
@@ -13,11 +13,11 @@ export default {
title: "Library/Floating Panel/Popover",
};
-const bodyStyles = css({
+const bodyStyle = css({
padding: theme.spacing[9],
});
-const descriptionStyles = css(textVariants.regular, {
+const descriptionStyle = css(textVariants.regular, {
marginTop: 0,
marginBottom: theme.spacing[9],
});
@@ -34,8 +34,8 @@ const PopoverDemo = () => (
<Button>Open</Button>
</FloatingPanelPopoverTrigger>
<FloatingPanelPopoverContent>
- <div className={bodyStyles()}>
- <p className={descriptionStyles()}>This is a description</p>
+ <div className={bodyStyle()}>
+ <p className={descriptionStyle()}>This is a description</p>
<div className={buttonsStyle()}>
<FloatingPanelPopoverClose asChild>
<Button color="ghost">Cancel</Button>
diff --git a/packages/design-system/src/components/floating-panel-popover.tsx b/packages/design-system/src/components/floating-panel-popover.tsx
index 4378c4f140..acb89eec3a 100644
--- a/packages/design-system/src/components/floating-panel-popover.tsx
+++ b/packages/design-system/src/components/floating-panel-popover.tsx
@@ -2,11 +2,11 @@ import React, { type ComponentProps, type Ref, type ReactNode } from "react";
import * as Primitive from "@radix-ui/react-popover";
import { css, theme, type CSS } from "../stitches.config";
import { Title } from "./title";
-import { floatingPanelStyles, CloseButton, TitleSlot } from "./floating-panel";
+import { floatingPanelStyle, CloseButton, TitleSlot } from "./floating-panel";
export const FloatingPanelPopover = Primitive.Root;
-const contentStyles = css(floatingPanelStyles, {
+const contentStyle = css(floatingPanelStyle, {
minWidth: theme.spacing[28],
maxWidth: "max-content",
maxHeight: "80vh",
@@ -27,7 +27,7 @@ export const FloatingPanelPopoverContent = React.forwardRef(
<Primitive.Content
sideOffset={4}
collisionPadding={4}
- className={contentStyles({ className, css })}
+ className={contentStyle({ className, css })}
{...props}
ref={ref}
>
diff --git a/packages/design-system/src/components/floating-panel.tsx b/packages/design-system/src/components/floating-panel.tsx
index df6daf3ba5..d97e06bb65 100644
--- a/packages/design-system/src/components/floating-panel.tsx
+++ b/packages/design-system/src/components/floating-panel.tsx
@@ -9,7 +9,7 @@ import { css, theme } from "../stitches.config";
import { Button } from "./button";
import { Separator } from "./separator";
-export const floatingPanelStyles = css({
+export const floatingPanelStyle = css({
border: `1px solid ${theme.colors.borderMain}`,
boxShadow: theme.shadows.menuDropShadow,
background: theme.colors.backgroundPanel,
@@ -23,13 +23,13 @@ export const floatingPanelStyles = css({
},
});
-const titleSlotStyles = css({
+const titleSlotStyle = css({
// We put title at the bottom in DOM to make the close button last in the TAB order
// But visually we want it to be first
order: -1,
});
export const TitleSlot = ({ children }: { children: ReactNode }) => (
- <div className={titleSlotStyles()}>
+ <div className={titleSlotStyle()}>
{children}
<Separator />
</div>
diff --git a/packages/design-system/src/components/label.tsx b/packages/design-system/src/components/label.tsx
index bf49a9fec6..bb94c3c497 100644
--- a/packages/design-system/src/components/label.tsx
+++ b/packages/design-system/src/components/label.tsx
@@ -8,6 +8,8 @@ import { forwardRef } from "react";
import { textVariants } from "./text";
import { styled, theme } from "../stitches.config";
+export const labelColors = ["default", "preset", "local", "remote"] as const;
+
const StyledLabel = styled("label", textVariants.labelsSentenceCase, {
boxSizing: "border-box",
flexShrink: 0,
@@ -73,7 +75,7 @@ const StyledLabel = styled("label", textVariants.labelsSentenceCase, {
});
type Props = ComponentProps<typeof StyledLabel> & {
- color?: "default" | "preset" | "local" | "remote";
+ color?: (typeof labelColors)[number];
disabled?: boolean;
truncate?: boolean;
children: ReactNode;
diff --git a/packages/design-system/src/components/nested-icon-label.stories.tsx b/packages/design-system/src/components/nested-icon-label.stories.tsx
new file mode 100644
index 0000000000..44a5b5f9cb
--- /dev/null
+++ b/packages/design-system/src/components/nested-icon-label.stories.tsx
@@ -0,0 +1,43 @@
+import { NestedIconLabel } from "./nested-icon-label";
+import { labelColors } from "./label";
+import { RowGapIcon } from "@webstudio-is/icons";
+import { StorySection, StoryGrid } from "./storybook";
+
+export default {
+ title: "Library/Nested Icon Label",
+};
+
+export const Demo = () => {
+ return (
+ <>
+ <StorySection title="Default">
+ <StoryGrid horizontal>
+ {labelColors.map((color) => (
+ <NestedIconLabel key={color} color={color}>
+ <RowGapIcon />
+ </NestedIconLabel>
+ ))}
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Hover">
+ <StoryGrid horizontal>
+ {labelColors.map((color) => (
+ <NestedIconLabel key={color} color={color} hover>
+ <RowGapIcon />
+ </NestedIconLabel>
+ ))}
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Disabled">
+ <StoryGrid horizontal>
+ {labelColors.map((color) => (
+ <NestedIconLabel key={color} color={color} disabled>
+ <RowGapIcon />
+ </NestedIconLabel>
+ ))}
+ </StoryGrid>
+ </StorySection>
+ </>
+ );
+};
+Demo.storyName = "Nested Icon Label";
diff --git a/packages/design-system/src/components/nested-icon-label.tsx b/packages/design-system/src/components/nested-icon-label.tsx
new file mode 100644
index 0000000000..d5fa0ff2a5
--- /dev/null
+++ b/packages/design-system/src/components/nested-icon-label.tsx
@@ -0,0 +1,91 @@
+/**
+ * Implementation of the "Nested Icon Label" component from:
+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=148-3161
+ */
+
+import { forwardRef, type ComponentProps, type Ref } from "react";
+import { type CSS, css, theme } from "../stitches.config";
+import type { labelColors } from "./label";
+
+const colors = {
+ default: {
+ border: "transparent",
+ background: "transparent",
+ backgroundHover: theme.colors.backgroundHover,
+ icon: theme.colors.foregroundIconMain,
+ },
+ preset: {
+ border: theme.colors.borderMain,
+ background: theme.colors.backgroundPresetMain,
+ backgroundHover: theme.colors.backgroundPresetHover,
+ icon: theme.colors.foregroundIconMain,
+ },
+ local: {
+ border: theme.colors.borderSetMain,
+ background: theme.colors.backgroundSetMain,
+ backgroundHover: theme.colors.backgroundSetHover,
+ icon: theme.colors.foregroundSetMain,
+ },
+ remote: {
+ border: theme.colors.borderInheritedMain,
+ background: theme.colors.backgroundInheritedMain,
+ backgroundHover: theme.colors.backgroundInheritedHover,
+ icon: theme.colors.foregroundInheritedMain,
+ },
+} as const;
+
+const perColorStyle = (color: (typeof labelColors)[number]) => ({
+ "&:not([data-state=disabled])": {
+ color: colors[color].icon,
+ borderColor: colors[color].border,
+ background: colors[color].background,
+ },
+ "&:not([data-state=disabled]):hover, &[data-state=hover]": {
+ background: colors[color].backgroundHover,
+ },
+ "&[data-state=disabled]": {
+ color: theme.colors.foregroundDisabled,
+ },
+});
+
+const style = css({
+ display: "flex",
+ width: theme.spacing[11],
+ height: theme.spacing[11],
+ boxSizing: "border-box",
+ alignItems: "center",
+ justifyContent: "center",
+ borderRadius: theme.borderRadius[2],
+ border: "1px solid transparent",
+ variants: {
+ color: {
+ default: perColorStyle("default"),
+ preset: perColorStyle("preset"),
+ local: perColorStyle("local"),
+ remote: perColorStyle("remote"),
+ },
+ },
+ defaultVariants: { color: "default" },
+});
+
+type Props = ComponentProps<"label"> & {
+ css?: CSS;
+ color?: (typeof labelColors)[number];
+ disabled?: boolean;
+ hover?: boolean;
+};
+
+export const NestedIconLabel = forwardRef(
+ (
+ { css, className, color, disabled, hover, ...props }: Props,
+ ref: Ref<HTMLLabelElement>
+ ) => (
+ <label
+ {...props}
+ className={style({ css, className, color })}
+ data-state={disabled ? "disabled" : hover ? "hover" : undefined}
+ ref={ref}
+ />
+ )
+);
+NestedIconLabel.displayName = "NestedIconLabel";
diff --git a/packages/design-system/src/components/panel.tsx b/packages/design-system/src/components/panel.tsx
index 01e74d5e31..daa7210f12 100644
--- a/packages/design-system/src/components/panel.tsx
+++ b/packages/design-system/src/components/panel.tsx
@@ -1,11 +1,11 @@
import { css, styled } from "../stitches.config";
import { theme } from "../stitches.config";
-export const panelStyles = css({
+export const panelStyle = css({
overflow: "auto",
backgroundColor: theme.colors.slate4,
borderRadius: theme.borderRadius[4],
boxShadow: `0px 2px 7px rgba(0, 0, 0, 0.1), 0px 5px 17px rgba(0, 0, 0, 0.15), inset 0 0 1px 1px ${theme.colors.slate1}, 0 0 0 1px ${theme.colors.slate7}`,
});
-export const Panel = styled("div", panelStyles);
+export const Panel = styled("div", panelStyle);
diff --git a/packages/design-system/src/components/popover.tsx b/packages/design-system/src/components/popover.tsx
index 00460f1fee..bf66c4ec06 100644
--- a/packages/design-system/src/components/popover.tsx
+++ b/packages/design-system/src/components/popover.tsx
@@ -5,7 +5,7 @@ import { Separator } from "./separator";
export const Popover = Primitive.Root;
-const contentStyles = css({
+const contentStyle = css({
border: `1px solid ${theme.colors.borderMain}`,
boxShadow: `${theme.shadows.menuDropShadow}, inset 0 0 0 1px ${theme.colors.borderMenuInner}`,
background: theme.colors.backgroundMenu,
@@ -52,7 +52,7 @@ export const PopoverContent = React.forwardRef(
<Primitive.Content
sideOffset={4}
collisionPadding={4}
- className={contentStyles({ className, css })}
+ className={contentStyle({ className, css })}
{...props}
ref={ref}
>
diff --git a/packages/design-system/src/components/primitives/small-button.tsx b/packages/design-system/src/components/primitives/small-button.tsx
index 5a4dd28da6..5803845dfc 100644
--- a/packages/design-system/src/components/primitives/small-button.tsx
+++ b/packages/design-system/src/components/primitives/small-button.tsx
@@ -55,7 +55,7 @@ const perVariantStyle = (variant: (typeof smallButtonVariants)[number]) => ({
},
});
-const styles = css({
+const style = css({
all: "unset",
width: theme.spacing[9],
height: theme.spacing[9],
@@ -90,7 +90,7 @@ export const SmallButton = forwardRef(
return (
<button
{...restProps}
- className={styles({ css, className, variant })}
+ className={style({ css, className, variant })}
ref={ref}
>
{children}
diff --git a/packages/design-system/src/components/radio.tsx b/packages/design-system/src/components/radio.tsx
index 47a501abd8..5ced72c702 100644
--- a/packages/design-system/src/components/radio.tsx
+++ b/packages/design-system/src/components/radio.tsx
@@ -10,7 +10,7 @@ import { type CSS, css, theme } from "../stitches.config";
export { CheckboxAndLabel as RadioAndLabel } from "./checkbox";
-const itemStyles = css({
+const itemStyle = css({
all: "unset", // reset <button>
width: theme.spacing[9],
height: theme.spacing[9],
@@ -45,7 +45,7 @@ const itemStyles = css({
},
});
-const iconStyles = css({ position: "relative" });
+const iconStyle = css({ position: "relative" });
// We need this component basicslly just to get access to "data-state".
// We could render both icons and hide one using CSS,
@@ -59,9 +59,9 @@ const Button = forwardRef(
) => (
<button {...props} ref={ref}>
{props["data-state"] === "checked" ? (
- <RadioCheckedIcon className={iconStyles()} />
+ <RadioCheckedIcon className={iconStyle()} />
) : (
- <RadioUncheckedIcon className={iconStyles()} />
+ <RadioUncheckedIcon className={iconStyle()} />
)}
</button>
)
@@ -78,7 +78,7 @@ export const Radio = forwardRef(
ref: Ref<HTMLButtonElement>
) => (
<Primitive.Item
- className={itemStyles({ className, css })}
+ className={itemStyle({ className, css })}
{...props}
ref={ref}
asChild
diff --git a/packages/design-system/src/components/select-button.stories.tsx b/packages/design-system/src/components/select-button.stories.tsx
new file mode 100644
index 0000000000..717407d9b7
--- /dev/null
+++ b/packages/design-system/src/components/select-button.stories.tsx
@@ -0,0 +1,94 @@
+import { NestedIconLabel } from "./nested-icon-label";
+import { SelectButton } from "./select-button";
+import { RowGapIcon } from "@webstudio-is/icons";
+import { StorySection, StoryGrid } from "./storybook";
+
+export default {
+ title: "Library/Select Button",
+};
+
+const iconLabel = (
+ <NestedIconLabel color="local">
+ <RowGapIcon />
+ </NestedIconLabel>
+);
+
+export const Demo = () => {
+ return (
+ <>
+ <StorySection title="Closed">
+ <StoryGrid horizontal>
+ <SelectButton data-placeholder>No value</SelectButton>
+ <SelectButton prefix={iconLabel} data-placeholder>
+ No value
+ </SelectButton>
+ <SelectButton>With value</SelectButton>
+ <SelectButton prefix={iconLabel}>With value</SelectButton>
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Open">
+ <StoryGrid horizontal>
+ <SelectButton data-placeholder data-state="open">
+ No value
+ </SelectButton>
+ <SelectButton prefix={iconLabel} data-placeholder data-state="open">
+ No value
+ </SelectButton>
+ <SelectButton data-state="open">With value</SelectButton>
+ <SelectButton prefix={iconLabel} data-state="open">
+ With value
+ </SelectButton>
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Disabled">
+ <StoryGrid horizontal>
+ <SelectButton disabled data-placeholder>
+ No value
+ </SelectButton>
+ <SelectButton
+ disabled
+ prefix={
+ <NestedIconLabel color="local" disabled>
+ <RowGapIcon />
+ </NestedIconLabel>
+ }
+ data-placeholder
+ >
+ No value
+ </SelectButton>
+ <SelectButton disabled>With value</SelectButton>
+ <SelectButton
+ disabled
+ prefix={
+ <NestedIconLabel color="local" disabled>
+ <RowGapIcon />
+ </NestedIconLabel>
+ }
+ >
+ With value
+ </SelectButton>
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Full width">
+ <StoryGrid css={{ width: 120 }}>
+ <SelectButton fullWidth>Some very long text</SelectButton>
+ <SelectButton fullWidth prefix={iconLabel}>
+ Some very long text
+ </SelectButton>
+ <SelectButton fullWidth>Short</SelectButton>
+ <SelectButton fullWidth prefix={iconLabel}>
+ Short
+ </SelectButton>
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Focused (initialy)">
+ <StoryGrid horizontal>
+ <SelectButton prefix={iconLabel} autoFocus>
+ With value
+ </SelectButton>
+ </StoryGrid>
+ </StorySection>
+ </>
+ );
+};
+Demo.storyName = "Select Button";
diff --git a/packages/design-system/src/components/select-button.tsx b/packages/design-system/src/components/select-button.tsx
new file mode 100644
index 0000000000..f6d6c6009f
--- /dev/null
+++ b/packages/design-system/src/components/select-button.tsx
@@ -0,0 +1,87 @@
+/**
+ * Implementation of the "Select Button" component from:
+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=4-3263
+ *
+ * Primarily intended to be used as Trigger in <Select>.
+ * Implemented separately in case we'll need it as a trigger for something else.
+ */
+
+import {
+ forwardRef,
+ type Ref,
+ type ComponentProps,
+ type ReactNode,
+} from "react";
+import { textVariants } from "./text";
+import { theme, css, type CSS } from "../stitches.config";
+import { ChevronDownIcon } from "@webstudio-is/icons";
+import { cssVars } from "@webstudio-is/css-vars";
+
+const chevronColor = cssVars.define("chevron-color");
+const chevronStyle = css({ color: cssVars.use(chevronColor) });
+
+const style = css({
+ all: "unset", // reset <button>
+ height: theme.spacing[12],
+ boxSizing: "border-box",
+ display: "flex",
+ alignItems: "center",
+ background: theme.colors.backgroundControls,
+ border: `1px solid ${theme.colors.borderMain}`,
+ borderRadius: theme.borderRadius[4],
+ paddingRight: theme.spacing[1],
+ paddingLeft: theme.spacing[1],
+ color: theme.colors.foregroundMain,
+ [chevronColor]: theme.colors.foregroundSubtle,
+ "&[data-placeholder]:not([data-state=open], :hover, :disabled)": {
+ color: theme.colors.foregroundSubtle,
+ },
+ "&:hover:not(:disabled), &[data-state=open]": {
+ [chevronColor]: theme.colors.foregroundMain,
+ },
+ "&:disabled": {
+ background: theme.colors.backgroundInputDisabled,
+ color: theme.colors.foregroundDisabled,
+ [chevronColor]: theme.colors.borderMain,
+ },
+ "&:focus-visible": {
+ borderColor: theme.colors.borderFocus,
+ outline: `1px solid ${theme.colors.borderFocus}`,
+ },
+ variants: {
+ fullWidth: { true: { width: "100%" } },
+ },
+});
+
+const textStyle = css(textVariants.regular, {
+ overflow: "hidden",
+ textOverflow: "ellipsis",
+ whiteSpace: "nowrap",
+ flex: 1,
+ paddingRight: theme.spacing[2],
+ paddingLeft: theme.spacing[3],
+});
+
+type Props = Omit<ComponentProps<"button">, "prefix"> & {
+ fullWidth?: boolean;
+ css?: CSS;
+ prefix?: ReactNode; // primarily for <NestedIconLabel>
+};
+
+export const SelectButton = forwardRef(
+ (
+ { prefix, children, css, className, fullWidth, ...rest }: Props,
+ ref: Ref<HTMLButtonElement>
+ ) => (
+ <button
+ {...rest}
+ className={style({ css, className, fullWidth })}
+ ref={ref}
+ >
+ {prefix}
+ <span className={textStyle()}>{children}</span>
+ <ChevronDownIcon className={chevronStyle()} />
+ </button>
+ )
+);
+SelectButton.displayName = "SelectButton";
diff --git a/packages/design-system/src/components/select.stories.tsx b/packages/design-system/src/components/select.stories.tsx
index 1548c76a42..ef934b2bad 100644
--- a/packages/design-system/src/components/select.stories.tsx
+++ b/packages/design-system/src/components/select.stories.tsx
@@ -1,5 +1,7 @@
import type { ComponentStory } from "@storybook/react";
+import { RowGapIcon } from "@webstudio-is/icons";
import React from "react";
+import { NestedIconLabel } from "./nested-icon-label";
import { Select, SelectOption } from "./select";
export default {
@@ -14,24 +16,43 @@ export const Simple: ComponentStory<typeof Select> = () => {
);
};
-export const Ghost: ComponentStory<typeof Select> = () => {
+export const Placeholder: ComponentStory<typeof Select> = () => {
return (
<Select
- name="fruit"
+ placeholder="Select fruit"
options={["Apple", "Banana", "Orange"]}
- defaultValue="Apple"
- ghost
/>
);
};
+export const Disabled: ComponentStory<typeof Select> = () => {
+ return <Select disabled options={["Apple", "Banana", "Orange"]} />;
+};
+
export const FullWidth: ComponentStory<typeof Select> = () => {
+ return (
+ <div style={{ width: 200 }}>
+ <Select
+ name="fruit"
+ options={["Apple", "Banana", "Orange Orange Orange Orange Orange"]}
+ defaultValue="Apple"
+ fullWidth
+ />
+ </div>
+ );
+};
+
+export const WithNestedLabelIcon: ComponentStory<typeof Select> = () => {
return (
<Select
+ prefix={
+ <NestedIconLabel>
+ <RowGapIcon />
+ </NestedIconLabel>
+ }
name="fruit"
options={["Apple", "Banana", "Orange"]}
defaultValue="Apple"
- fullWidth
/>
);
};
diff --git a/packages/design-system/src/components/select.tsx b/packages/design-system/src/components/select.tsx
index f1b17265f1..ecf49c08a2 100644
--- a/packages/design-system/src/components/select.tsx
+++ b/packages/design-system/src/components/select.tsx
@@ -1,4 +1,4 @@
-import * as SelectPrimitive from "@radix-ui/react-select";
+import * as Primitive from "@radix-ui/react-select";
import React, { ReactNode, Ref, type ComponentProps } from "react";
import {
menuCss,
@@ -8,75 +8,23 @@ import {
separatorCss,
MenuCheckedIcon,
} from "./menu";
-import { ChevronDownIcon, ChevronUpIcon } from "@webstudio-is/icons";
+import { SelectButton } from "./select-button";
import { styled, theme } from "../stitches.config";
+import { ChevronDownIcon, ChevronUpIcon } from "@webstudio-is/icons";
-const StyledTrigger = styled(SelectPrimitive.Trigger, {
- all: "unset",
- display: "inline-flex",
- alignItems: "center",
- justifyContent: "space-between",
- fontVariantNumeric: "tabular-nums",
- gap: theme.spacing[5],
- flexShrink: 0,
- borderRadius: theme.borderRadius[4],
- backgroundColor: theme.colors.loContrast,
- color: theme.colors.hiContrast,
- boxShadow: `inset 0 0 0 1px ${theme.colors.slate7}`,
- height: 28, // @todo waiting for the sizing scale
- px: theme.spacing[5],
- fontSize: theme.deprecatedFontSize[3],
- "&:focus": {
- boxShadow: `inset 0px 0px 0px 1px ${theme.colors.blue8}, 0px 0px 0px 1px ${theme.colors.blue8}`,
- },
- paddingRight: 0,
- paddingLeft: theme.spacing[5],
- textTransform: "capitalize",
- fontWeight: "inherit",
-
- variants: {
- ghost: {
- true: {
- backgroundColor: "transparent",
- boxShadow: "none",
- },
- },
- fullWidth: {
- true: {
- width: "100%",
- },
- },
- },
-});
-
-const StyledValue = styled("span", {
- whiteSpace: "nowrap",
- textOverflow: "ellipsis",
- overflow: "hidden",
- flexGrow: 0,
-});
-
-const StyledIcon = styled(SelectPrimitive.Icon, {
- display: "inline-flex",
- alignItems: "center",
- justifyContent: "center",
- height: "100%",
- padding: `${theme.spacing[2]} ${theme.spacing[2]} ${theme.spacing[2]} 0px`,
-});
-
-export const SelectContent = styled(SelectPrimitive.Content, menuCss);
+export const SelectContent = styled(Primitive.Content, menuCss);
-export const SelectViewport = SelectPrimitive.Viewport;
+export const SelectViewport = Primitive.Viewport;
-export const SelectLabel = styled(SelectPrimitive.Label, labelCss);
+export const SelectLabel = styled(Primitive.Label, labelCss);
-export const SelectSeparator = styled(SelectPrimitive.Separator, separatorCss);
+export const SelectSeparator = styled(Primitive.Separator, separatorCss);
-export const SelectGroup = SelectPrimitive.Group;
+export const SelectGroup = Primitive.Group;
-const StyledItem = styled(SelectPrimitive.Item, itemCss);
+const StyledItem = styled(Primitive.Item, itemCss);
-const StyledIndicator = styled(SelectPrimitive.ItemIndicator, itemIndicatorCss);
+const StyledIndicator = styled(Primitive.ItemIndicator, itemIndicatorCss);
const scrollButtonStyles = {
display: "flex",
@@ -88,12 +36,12 @@ const scrollButtonStyles = {
};
export const SelectScrollUpButton = styled(
- SelectPrimitive.ScrollUpButton,
+ Primitive.ScrollUpButton,
scrollButtonStyles
);
export const SelectScrollDownButton = styled(
- SelectPrimitive.ScrollDownButton,
+ Primitive.ScrollDownButton,
scrollButtonStyles
);
@@ -104,7 +52,7 @@ const SelectItemBase = (
return (
<StyledItem {...props} withIndicator ref={forwardedRef}>
<StyledIndicator>{icon}</StyledIndicator>
- <SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
+ <Primitive.ItemText>{children}</Primitive.ItemText>
</StyledItem>
);
};
@@ -117,10 +65,13 @@ export const SelectItem = React.forwardRef(SelectItemBase);
export type SelectOption = string;
-export type SelectProps<Option = SelectOption> = Omit<
- ComponentProps<typeof StyledTrigger>,
- "onChange" | "value" | "defaultValue"
-> & {
+type TriggerPassThroughProps = Omit<
+ ComponentProps<typeof Primitive.Trigger>,
+ "onChange" | "value" | "defaultValue" | "asChild" | "prefix"
+> &
+ Omit<ComponentProps<typeof SelectButton>, "onChange">;
+
+export type SelectProps<Option = SelectOption> = TriggerPassThroughProps & {
options: Option[];
defaultValue?: Option;
value?: Option;
@@ -146,12 +97,13 @@ const SelectBase = (
getValue = (option) => option,
name,
children,
+ prefix,
...props
}: SelectProps,
forwardedRef: Ref<HTMLButtonElement>
) => {
return (
- <SelectPrimitive.Root
+ <Primitive.Root
name={name}
value={value}
defaultValue={defaultValue}
@@ -159,15 +111,12 @@ const SelectBase = (
open={open}
onOpenChange={onOpenChange}
>
- <StyledTrigger ref={forwardedRef} {...props}>
- <SelectPrimitive.Value asChild>
- <StyledValue>{value ? getLabel(value) : placeholder}</StyledValue>
- </SelectPrimitive.Value>
- <StyledIcon>
- <ChevronDownIcon />
- </StyledIcon>
- </StyledTrigger>
- <SelectPrimitive.Portal>
+ <Primitive.Trigger ref={forwardedRef} {...props} asChild>
+ <SelectButton prefix={prefix}>
+ <Primitive.Value placeholder={placeholder} />
+ </SelectButton>
+ </Primitive.Trigger>
+ <Primitive.Portal>
<SelectContent>
<SelectScrollUpButton>
<ChevronUpIcon />
@@ -188,8 +137,8 @@ const SelectBase = (
<ChevronDownIcon />
</SelectScrollDownButton>
</SelectContent>
- </SelectPrimitive.Portal>
- </SelectPrimitive.Root>
+ </Primitive.Portal>
+ </Primitive.Root>
);
};
diff --git a/packages/design-system/src/components/switch.tsx b/packages/design-system/src/components/switch.tsx
index 121a7a76ae..c4e4f6390b 100644
--- a/packages/design-system/src/components/switch.tsx
+++ b/packages/design-system/src/components/switch.tsx
@@ -10,7 +10,7 @@ import { type CSS, css, theme } from "../stitches.config";
const padding = theme.spacing[1];
const thumbOffset = `calc(${padding} + ${theme.spacing[2]})`;
-const switchStyles = css({
+const switchStyle = css({
all: "unset", // reset <button>
boxSizing: "content-box",
width: theme.spacing[11],
@@ -42,7 +42,7 @@ const switchStyles = css({
},
});
-const thumbStyles = css({
+const thumbStyle = css({
width: theme.spacing[6],
height: theme.spacing[6],
borderRadius: theme.borderRadius.round,
@@ -66,11 +66,11 @@ export const Switch = forwardRef(
ref: Ref<HTMLButtonElement>
) => (
<Primitive.Root
- className={switchStyles({ className, css })}
+ className={switchStyle({ className, css })}
{...props}
ref={ref}
>
- <Primitive.Thumb className={thumbStyles()} />
+ <Primitive.Thumb className={thumbStyle()} />
</Primitive.Root>
)
);
diff --git a/packages/design-system/src/components/text-area.stories.tsx b/packages/design-system/src/components/text-area.stories.tsx
new file mode 100644
index 0000000000..dfbcb0dd15
--- /dev/null
+++ b/packages/design-system/src/components/text-area.stories.tsx
@@ -0,0 +1,55 @@
+import { TextArea } from "./text-area";
+import { StorySection, StoryGrid } from "./storybook";
+
+export default {
+ title: "Library/Text Area",
+};
+
+const exampleValue =
+ "This is an example value of a text area. It's long enough to show how it wraps.";
+
+export const Demo = () => {
+ return (
+ <>
+ <StorySection title="Empty">
+ <StoryGrid css={{ width: 200 }}>
+ <TextArea placeholder="Enter value..." />
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="With value">
+ <StoryGrid css={{ width: 200 }}>
+ <TextArea value={exampleValue} />
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Invalid">
+ <StoryGrid css={{ width: 200 }}>
+ <TextArea value={exampleValue} state="invalid" />
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Disabled">
+ <StoryGrid css={{ width: 200 }}>
+ <TextArea value={exampleValue} disabled />
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Disabled invalid">
+ <StoryGrid css={{ width: 200 }}>
+ <TextArea value={exampleValue} state="invalid" disabled />
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Focused (initialy)">
+ <StoryGrid css={{ width: 200 }}>
+ <TextArea value={exampleValue} autoFocus />
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Rows test">
+ <StoryGrid css={{ width: 200 }}>
+ <TextArea value={exampleValue} rows={1} />
+ </StoryGrid>
+ </StorySection>
+ <StorySection title="Width test">
+ <TextArea value={exampleValue} css={{ width: "250px" }} />
+ </StorySection>
+ </>
+ );
+};
+Demo.storyName = "Text Area";
diff --git a/packages/design-system/src/components/text-area.tsx b/packages/design-system/src/components/text-area.tsx
index 14d77b9f90..8e5bbd47ca 100644
--- a/packages/design-system/src/components/text-area.tsx
+++ b/packages/design-system/src/components/text-area.tsx
@@ -1,93 +1,80 @@
-import { styled, theme } from "../stitches.config";
+/**
+ * Implementation of the "Text Area" component from:
+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=4-3389
+ */
+
+import { type ComponentProps, forwardRef, Ref } from "react";
+import { type CSS, css, theme } from "../stitches.config";
import { textVariants } from "./text";
-export const TextArea = styled("textarea", {
- // Reset
- appearance: "none",
- borderWidth: "0",
- margin: "0",
- outline: "none",
- padding: theme.spacing[3],
- WebkitTapHighlightColor: "rgba(0,0,0,0)",
- backgroundColor: theme.colors.loContrast,
- boxShadow: `inset 0 0 0 1px ${theme.colors.muted}`,
- color: theme.colors.hiContrast,
- fontVariantNumeric: "tabular-nums",
- position: "relative",
- minHeight: 80,
- resize: "vertical",
+const LINE_HEIGHT = 16;
+const PADDING_TOP = 6;
+const PADDING_BOTTOM = 4;
+const BORDER = 1;
- "&:focus": {
- boxShadow: `inset 0px 0px 0px 1px ${theme.colors.blue8}, 0px 0px 0px 1px ${theme.colors.blue8}`,
- zIndex: "1",
- },
+const style = css(textVariants.regular, {
+ lineHeight: `${LINE_HEIGHT}px`,
+ color: theme.colors.foregroundMain,
+ borderRadius: theme.borderRadius[4],
+ border: `${BORDER}px solid ${theme.colors.borderMain}`,
+ background: theme.colors.backgroundControls,
+ paddingRight: theme.spacing[4],
+ paddingLeft: theme.spacing[3],
+ paddingTop: PADDING_TOP,
+ paddingBottom: PADDING_BOTTOM,
+ boxSizing: "border-box",
+ width: "100%",
+ resize: "vertical",
"&::placeholder": {
- color: theme.colors.slate9,
+ color: theme.colors.foregroundSubtle,
},
"&:disabled": {
- pointerEvents: "none",
- backgroundColor: theme.colors.slate2,
- color: theme.colors.slate8,
- cursor: "not-allowed",
- resize: "none",
- "&::placeholder": {
- color: theme.colors.slate7,
- },
+ color: theme.colors.foregroundDisabled,
+ background: theme.colors.backgroundInputDisabled,
},
- "&:read-only": {
- backgroundColor: theme.colors.slate2,
- "&:focus": {
- boxShadow: `inset 0px 0px 0px 1px ${theme.colors.slate7}`,
- },
+ "&:focus-visible": {
+ borderColor: theme.colors.borderFocus,
+ outline: `1px solid ${theme.colors.borderFocus}`,
},
-
variants: {
- size: {
- "1": {
- borderRadius: theme.borderRadius[4],
- padding: theme.spacing[4],
- ...textVariants.regular,
- },
- "2": {
- borderRadius: theme.borderRadius[4],
- fontSize: theme.deprecatedFontSize[3],
- lineHeight: theme.deprecatedLineHeight[4],
- px: theme.spacing[3],
- },
- "3": {
- borderRadius: theme.borderRadius[6],
- fontSize: theme.deprecatedFontSize[4],
- lineHeight: "23px",
- px: theme.spacing[5],
- },
- },
state: {
invalid: {
- boxShadow: `inset 0 0 0 1px ${theme.colors.red7}`,
- "&:focus": {
- boxShadow: `inset 0px 0px 0px 1px ${theme.colors.red8}, 0px 0px 0px 1px ${theme.colors.red8}`,
+ color: theme.colors.foregroundDestructive,
+ "&:not(:disabled):not(:focus-visible)": {
+ borderColor: theme.colors.borderDestructiveMain,
},
},
- valid: {
- boxShadow: `inset 0 0 0 1px ${theme.colors.green7}`,
- "&:focus": {
- boxShadow: `inset 0px 0px 0px 1px ${theme.colors.green8}, 0px 0px 0px 1px ${theme.colors.green8}`,
- },
- },
- },
- cursor: {
- default: {
- cursor: "default",
- "&:focus": {
- cursor: "text",
- },
- },
- text: {
- cursor: "text",
- },
},
},
- defaultVariants: {
- size: "1",
- },
});
+
+type Props = ComponentProps<"textarea"> & {
+ css?: CSS;
+ rows?: number;
+ state?: "invalid";
+};
+
+export const TextArea = forwardRef(
+ (
+ { css, className, rows = 3, state, ...props }: Props,
+ ref: Ref<HTMLTextAreaElement>
+ ) => {
+ // We could use `box-sizing:content-box` to avoid dealing with paddings and border here
+ // But then, the user of the component will not be able to set `width` reliably
+ const height =
+ rows * LINE_HEIGHT + PADDING_TOP + PADDING_BOTTOM + BORDER * 2;
+
+ return (
+ <textarea
+ className={style({
+ css: { height, minHeight: height, ...css },
+ state,
+ className,
+ })}
+ ref={ref}
+ {...props}
+ />
+ );
+ }
+);
+TextArea.displayName = "TextArea";
diff --git a/packages/design-system/src/components/text.ts b/packages/design-system/src/components/text.ts
index 88cec0012f..f04d78132c 100644
--- a/packages/design-system/src/components/text.ts
+++ b/packages/design-system/src/components/text.ts
@@ -3,7 +3,7 @@ import { typography as textVariants } from "../__generated__/figma-design-tokens
export { textVariants };
-export const textStyles = css({
+export const textStyle = css({
margin: 0, // in case it's used with <p>
variants: {
variant: textVariants,
@@ -39,4 +39,4 @@ export const textStyles = css({
defaultVariants: { variant: "regular" },
});
-export const Text = styled("div", textStyles);
+export const Text = styled("div", textStyle);
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.tsx
index c90c64154e..100b589157 100644
--- a/packages/design-system/src/components/two-rows-icon-button-container.tsx
+++ b/packages/design-system/src/components/two-rows-icon-button-container.tsx
@@ -6,7 +6,7 @@
import { forwardRef, type ReactNode, type Ref } from "react";
import { css, theme, type CSS } from "../stitches.config";
-const curveStyles = css({
+const curveStyle = css({
fill: theme.colors.borderMain,
alignSelf: "start",
variants: { rotated: { true: { transform: "rotate(90deg)" } } },
@@ -18,13 +18,13 @@ const Curve = ({ rotated }: { rotated?: boolean }) => (
height="10"
viewBox="0 0 10 10"
xmlns="http://www.w3.org/2000/svg"
- className={curveStyles({ rotated })}
+ className={curveStyle({ rotated })}
>
<path d="M10 10V6C10 2.68629 7.31371 0 4 0H0V1H4C6.76142 1 9 3.23858 9 6V10H10Z" />
</svg>
);
-const styles = css({
+const style = css({
display: "flex",
flexDirection: "column",
width: 19,
@@ -45,7 +45,7 @@ export const TwoRowsIconButtonContainer = forwardRef(
},
ref: Ref<HTMLDivElement>
) => (
- <div ref={ref} className={styles({ className, css })}>
+ <div ref={ref} className={style({ className, css })}>
<Curve />
{children}
<Curve rotated />
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index 0e33c6276f..eb5eb84cb9 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -8,7 +8,7 @@ export * from "./components/title";
export * from "./components/separator";
export * from "./components/button";
export * from "./components/label";
-export * from "./components/select"; // menu is aligned, but trigger is not
+export * from "./components/select";
export * from "./components/combobox";
export * from "./components/dropdown-menu";
export * from "./components/icon-button"; // mostly aligned, but needs a demo and to use tokens
@@ -24,6 +24,10 @@ export * from "./components/list-position-indicator";
export * from "./components/position-grid";
export * from "./components/small-toggle-button";
export * from "./components/css-value-list-item";
+export * from "./components/nested-icon-label";
+export * from "./components/text-area";
+export * from "./components/radio";
+export * from "./components/checkbox";
// Not aligned
@@ -33,7 +37,6 @@ export { AccessibleIcon } from "@radix-ui/react-accessible-icon";
export * from "./components/toggle-group";
export * from "./components/progress-radial";
export * from "./components/text-field";
-export * from "./components/text-area";
export { SearchField } from "./components/search-field";
export { Tabs, TabsContent, TabsList, TabsTrigger } from "./components/tabs";
export {
@@ -53,8 +56,6 @@ export {
export { Link } from "./components/link";
export { Panel } from "./components/panel";
export * from "./components/slider";
-export * from "./components/radio";
-export * from "./components/checkbox";
export * from "./components/avatar";
export * from "./components/icon-button-with-menu";
export * from "./components/tree";