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.

Add new label for style panel (#820)

Bogdan Chadkin846240abc826
diff --git a/.lostpixel/baseline/library-label--label.png b/.lostpixel/baseline/library-label--label.png
new file mode 100644
index 0000000000..3544d81a23
Binary files /dev/null and b/.lostpixel/baseline/library-label--label.png differ
diff --git a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
index 2e696f5b0b..d7c7031225 100644
--- a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
+++ b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
@@ -3,11 +3,12 @@ import { isFeatureEnabled } from "@webstudio-is/feature-flags";
import type { StyleProperty } from "@webstudio-is/css-data";
import { toValue } from "@webstudio-is/css-engine";
import {
+ theme,
Button,
Flex,
Box,
Text,
- DeprecatedLabel,
+ Label,
Tooltip,
Popover,
PopoverContent,
@@ -19,7 +20,6 @@ import { UndoIcon } from "@webstudio-is/icons";
import { utils } from "@webstudio-is/project";
import { useBreakpoints, useRootInstance } from "~/shared/nano-states";
import { type StyleInfo, type StyleSource, getStyleSource } from "./style-info";
-import { theme } from "@webstudio-is/design-system";
const PropertyPopoverContent = ({
properties,
@@ -145,29 +145,7 @@ export const PropertyName = ({
isFeatureEnabled("propertyReset") &&
(styleSource === "local" || styleSource === "remote");
- const labelElement = (
- <DeprecatedLabel
- css={{
- fontWeight: "inherit",
- padding: `calc(${theme.spacing[3]} / 2) ${theme.spacing[3]}`,
- borderRadius: theme.borderRadius[4],
- ...(styleSource === "local" && {
- color: theme.colors.blue11,
- backgroundColor: theme.colors.blue4,
- }),
- ...(styleSource === "remote" && {
- color: theme.colors.orange11,
- backgroundColor: theme.colors.orange4,
- }),
- ...(styleSource === "preset" && {
- color: theme.colors.hiContrast,
- }),
- }}
- htmlFor={property.toString()}
- >
- {label}
- </DeprecatedLabel>
- );
+ const labelElement = <Label color={styleSource}>{label}</Label>;
if (isPopoverEnabled) {
return (
diff --git a/apps/designer/app/designer/features/style-panel/shared/style-info.ts b/apps/designer/app/designer/features/style-panel/shared/style-info.ts
index f0462956be..65f2a99e94 100644
--- a/apps/designer/app/designer/features/style-panel/shared/style-info.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/style-info.ts
@@ -47,7 +47,7 @@ export type StyleInfo = {
[property in StyleProperty]?: StyleValueInfo;
};
-export type StyleSource = "local" | "remote" | "preset";
+export type StyleSource = "local" | "remote" | "preset" | "default";
export const getStyleSource = (
...styleValueInfos: (undefined | StyleValueInfo)[]
@@ -64,7 +64,7 @@ export const getStyleSource = (
return "remote";
}
}
- return "preset";
+ return "default";
};
const styleProperties = Object.keys(properties) as StyleProperty[];
diff --git a/packages/design-system/src/components/button.tsx b/packages/design-system/src/components/button.tsx
index 840bfd7ccc..e974b25a4b 100644
--- a/packages/design-system/src/components/button.tsx
+++ b/packages/design-system/src/components/button.tsx
@@ -1,6 +1,6 @@
/**
* Implementation of the "Button" component from:
- * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=0%3A1
+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=4%3A2709
*/
import React, { forwardRef, type Ref, type ComponentProps } from "react";
diff --git a/packages/design-system/src/components/label.stories.tsx b/packages/design-system/src/components/label.stories.tsx
new file mode 100644
index 0000000000..1f9ceb3811
--- /dev/null
+++ b/packages/design-system/src/components/label.stories.tsx
@@ -0,0 +1,71 @@
+import type { ReactNode } from "react";
+import type { ComponentStory } from "@storybook/react";
+import { Label } from "./label";
+
+export default {
+ title: "Library/Label",
+};
+
+const Section = ({
+ title,
+ children,
+}: {
+ title: string;
+ children: ReactNode;
+}) => (
+ <>
+ <h3 style={{ fontFamily: "sans-serif" }}>{title}</h3>
+ <div style={{ display: "flex", gap: 12 }}>{children}</div>
+ </>
+);
+
+const colors = ["default", "preset", "local", "remote"] as const;
+
+const LabelStory: ComponentStory<typeof Label> = ({
+ color,
+ disabled,
+ children,
+}) => {
+ return (
+ <>
+ <Section title="Configurable">
+ <Label color={color} disabled={disabled}>
+ {children}
+ </Label>
+ </Section>
+
+ <Section title="Colors">
+ {colors.map((color) => (
+ <Label key={color} color={color}>
+ {color}
+ </Label>
+ ))}
+ </Section>
+
+ <Section title="With checkbox">
+ <input id="checkbox1" type="checkbox"></input>
+ <Label htmlFor="checkbox1">Label text</Label>
+ </Section>
+
+ <Section title="Disabled">
+ <Label disabled={true}>Label text</Label>
+ <div>
+ <input id="checkbox2" type="checkbox" disabled={true}></input>
+ <Label htmlFor="checkbox2" disabled={true}>
+ Label text
+ </Label>
+ </div>
+ </Section>
+ </>
+ );
+};
+export { LabelStory as Label };
+
+LabelStory.argTypes = {
+ children: { defaultValue: "Label text", control: "text" },
+ color: {
+ defaultValue: "default",
+ control: { type: "inline-radio", options: colors },
+ },
+ disabled: { defaultValue: false, control: "boolean" },
+};
diff --git a/packages/design-system/src/components/label.tsx b/packages/design-system/src/components/label.tsx
new file mode 100644
index 0000000000..95db84c28f
--- /dev/null
+++ b/packages/design-system/src/components/label.tsx
@@ -0,0 +1,80 @@
+/**
+ * Implementation of the "Label" component from:
+ * https://www.figma.com/file/sfCE7iLS0k25qCxiifQNLE/%F0%9F%93%9A-Webstudio-Library?node-id=4%3A3274
+ */
+
+import type { LabelHTMLAttributes, ReactNode, Ref } from "react";
+import { forwardRef } from "react";
+import { typography } from "../__generated__/figma-design-tokens";
+import { styled, theme } from "../stitches.config";
+
+const StyledLabel = styled("label", typography.labelsSentenceCase, {
+ boxSizing: "border-box",
+ flexShrink: 0,
+ py: theme.spacing[2],
+ border: "1px solid transparent",
+ borderRadius: theme.borderRadius[3],
+
+ "&:focus-visible": {
+ outline: `2px solid ${theme.colors.blue10}`,
+ },
+
+ variants: {
+ color: {
+ default: {
+ color: theme.colors.foregroundMain,
+ "&[aria-disabled=true]": {
+ color: theme.colors.foregroundDisabled,
+ },
+ },
+ preset: {
+ px: theme.spacing[3],
+ backgroundColor: theme.colors.backgroundPresetMain,
+ borderColor: theme.colors.borderMain,
+ color: theme.colors.foregroundMain,
+ "&:hover": {
+ backgroundColor: theme.colors.backgroundPresetHover,
+ },
+ },
+ local: {
+ px: theme.spacing[3],
+ backgroundColor: theme.colors.backgroundSetMain,
+ borderColor: theme.colors.borderSetMain,
+ color: theme.colors.foregroundSetMain,
+ "&:hover": {
+ backgroundColor: theme.colors.backgroundSetHover,
+ },
+ },
+ remote: {
+ px: theme.spacing[3],
+ backgroundColor: theme.colors.backgroundInheritedMain,
+ borderColor: theme.colors.borderInheritedMain,
+ color: theme.colors.foregroundInheritedMain,
+ "&:hover": {
+ backgroundColor: theme.colors.backgroundInheritedHover,
+ },
+ },
+ },
+ },
+
+ defaultVariants: {
+ color: "default",
+ },
+});
+
+type Props = LabelHTMLAttributes<HTMLLabelElement> & {
+ color?: "default" | "preset" | "local" | "remote";
+ disabled?: boolean;
+ children: ReactNode;
+};
+
+export const Label = forwardRef((props: Props, ref: Ref<HTMLLabelElement>) => {
+ const { color, disabled, children, ...rest } = props;
+ return (
+ <StyledLabel ref={ref} color={color} aria-disabled={disabled} {...rest}>
+ {children}
+ </StyledLabel>
+ );
+});
+
+Label.displayName = "Label";
diff --git a/packages/design-system/src/index.ts b/packages/design-system/src/index.ts
index ee66842c28..9b45922c00 100644
--- a/packages/design-system/src/index.ts
+++ b/packages/design-system/src/index.ts
@@ -6,6 +6,7 @@ export { AccessibleIcon } from "@radix-ui/react-accessible-icon";
export * as Portal from "@radix-ui/react-portal";
export * from "@radix-ui/react-id";
export { DeprecatedLabel } from "./components/__DEPRECATED__/label";
+export { Label } from "./components/label";
export * from "./components/toggle-group";
export * from "./components/progress-radial";
export * from "./components/select";