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.

experimental: migrate toggle group to style object model (#4063)

Bogdan Chadkin5d15ad78bf2b
diff --git a/apps/builder/app/builder/features/style-panel/controls/advanced-value-tooltip.tsx b/apps/builder/app/builder/features/style-panel/controls/advanced-value-tooltip.tsx
deleted file mode 100644
index a211b268c8..0000000000
--- a/apps/builder/app/builder/features/style-panel/controls/advanced-value-tooltip.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-import type { ReactNode } from "react";
-import { Box, Flex, Tooltip, rawTheme } from "@webstudio-is/design-system";
-import { AlertIcon } from "@webstudio-is/icons";
-import { declarationDescriptions } from "@webstudio-is/css-data";
-import type { StyleProperty } from "@webstudio-is/css-engine";
-import { TooltipContent } from "../shared/property-name";
-import { toKebabCase, toPascalCase } from "../shared/keyword-utils";
-import type { StyleInfo } from "../shared/style-info";
-import type { DeleteProperty } from "../shared/use-style-data";
-
-// Visual controls can't represent all CSS values and in that case we show it in the Advanced section.
-export const AdvancedValueTooltip = ({
- isAdvanced = false,
- children,
- property,
- value,
- currentStyle,
- deleteProperty,
-}: {
- isAdvanced?: boolean;
- children: ReactNode;
- property: StyleProperty;
- value: string;
- currentStyle: StyleInfo;
- deleteProperty: DeleteProperty;
-}) => {
- if (isAdvanced === false) {
- return children;
- }
- const content = (
- <TooltipContent
- scrollableContent={`${toKebabCase(property)}: ${value};`}
- description={
- <Flex gap="2" direction="column">
- {
- declarationDescriptions[
- `${property}:${value}` as keyof typeof declarationDescriptions
- ]
- }
- <Flex gap="1">
- <AlertIcon color={rawTheme.colors.backgroundAlertMain} /> This value
- was defined in the Advanced section.
- </Flex>
- </Flex>
- }
- title={toPascalCase(toKebabCase(property))}
- properties={[property]}
- style={currentStyle}
- onReset={() => {
- deleteProperty(property);
- }}
- />
- );
- return (
- <Tooltip content={content}>
- <Box>{children}</Box>
- </Tooltip>
- );
-};
diff --git a/apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx b/apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx
index 0e44413a65..fc3144c659 100644
--- a/apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/toggle-group/toggle-group-control.tsx
@@ -1,119 +1,175 @@
+import { useState, type ReactNode } from "react";
+import { declarationDescriptions } from "@webstudio-is/css-data";
import {
Flex,
+ rawTheme,
ToggleGroup,
ToggleGroupButton,
+ Tooltip,
} from "@webstudio-is/design-system";
-import { getStyleSource } from "../../shared/style-info";
-import { useState } from "react";
-import { PropertyTooltip } from "../../shared/property-name";
-import { toValue } from "@webstudio-is/css-engine";
-import type { ControlProps } from "..";
-import { AdvancedValueTooltip } from "../advanced-value-tooltip";
+import {
+ hyphenateProperty,
+ toValue,
+ type StyleProperty,
+} from "@webstudio-is/css-engine";
+import { humanizeString } from "~/shared/string-utils";
+import { useComputedStyles } from "../../shared/model";
+import { createBatchUpdate } from "../../shared/use-style-data";
+import {
+ getPriorityStyleValueSource,
+ PropertyInfo,
+} from "../../property-label";
+import { AlertIcon } from "@webstudio-is/icons";
-export type ToggleGroupControlProps = Omit<ControlProps, "items"> & {
- value?: string;
- items: {
- child: JSX.Element;
- title: string;
- description: string;
- value: string;
- propertyValues: string | string[];
- }[];
+export const ToggleGroupTooltip = ({
+ isOpen,
+ onOpenChange,
+ isSelected,
+ label,
+ code,
+ description,
+ properties,
+ isAdvanced,
+ children,
+}: {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ isSelected: boolean;
+ label?: string;
+ code?: string;
+ description: string;
+ properties: StyleProperty[];
isAdvanced?: boolean;
+ children: ReactNode;
+}) => {
+ const styles = useComputedStyles(properties);
+ const resetProperty = () => {
+ const batch = createBatchUpdate();
+ for (const property of properties) {
+ batch.deleteProperty(property);
+ }
+ batch.publish();
+ };
+ return (
+ <Tooltip
+ open={isOpen}
+ onOpenChange={onOpenChange}
+ // prevent closing tooltip on content click
+ onPointerDown={(event) => event.preventDefault()}
+ triggerProps={{
+ onClick: (event) => {
+ if (event.altKey) {
+ event.preventDefault();
+ resetProperty();
+ return;
+ }
+ },
+ }}
+ content={
+ <PropertyInfo
+ title={label ?? humanizeString(properties[0])}
+ code={code}
+ description={
+ <Flex gap="2" direction="column">
+ {description}
+ {isAdvanced && (
+ <Flex gap="1">
+ <AlertIcon color={rawTheme.colors.backgroundAlertMain} /> This
+ value was defined in the Advanced section.
+ </Flex>
+ )}
+ </Flex>
+ }
+ styles={isSelected ? styles : []}
+ onReset={() => {
+ resetProperty();
+ onOpenChange(false);
+ }}
+ />
+ }
+ >
+ {children}
+ </Tooltip>
+ );
};
export const ToggleGroupControl = ({
- currentStyle,
- property,
- items = [],
- setProperty,
- deleteProperty,
- value,
- isAdvanced,
-}: ToggleGroupControlProps) => {
- const styleSource = getStyleSource(currentStyle[property]);
- const currentValue = value ?? toValue(currentStyle[property]?.value);
-
+ label,
+ properties,
+ items,
+}: {
+ label?: string;
+ properties: [StyleProperty, ...StyleProperty[]];
+ items: Array<{
+ child: JSX.Element;
+ value: string;
+ description?: string;
+ }>;
+}) => {
+ const styles = useComputedStyles(properties);
+ const styleValueSource = getPriorityStyleValueSource(styles);
+ const selectedValue = toValue(
+ styles.find((styleDecl) => styleDecl.source.name !== "default")
+ ?.cascadedValue
+ );
+ const values = styles.map((styleDecl) => toValue(styleDecl.cascadedValue));
+ const isAdvanced =
+ // show value as advanced when value is not represent with buttons
+ items.some((item) => values.includes(item.value)) === false ||
+ // show value as advanced when longhands use inconsistent values
+ new Set(values).size > 1;
// Issue: The tooltip's grace area is too big and overlaps with nearby buttons,
// preventing the tooltip from changing when the buttons are hovered over in certain cases.
// To solve issue and allow tooltips to change on button hover,
// we close the button tooltip in the ToggleGroupButton.onMouseEnter handler.
// onMouseEnter used to preserve default hovering behavior on tooltip.
- const [openTootips, setOpenTooltips] = useState(() =>
- Array.from(items, () => false)
- );
-
- isAdvanced =
- isAdvanced ?? items.some((item) => item.value === currentValue) === false;
-
+ const [activeTooltip, setActiveTooltip] = useState<undefined | string>();
return (
- <AdvancedValueTooltip
- isAdvanced={isAdvanced}
- property={property}
- value={currentValue}
- currentStyle={currentStyle}
- deleteProperty={deleteProperty}
+ <ToggleGroup
+ color={styleValueSource}
+ type="single"
+ // trigger value change when value is advanced
+ // and need to change all at once
+ value={isAdvanced ? "" : selectedValue}
+ onValueChange={(value) => {
+ const batch = createBatchUpdate();
+ for (const property of properties) {
+ batch.setProperty(property)({ type: "keyword", value });
+ }
+ batch.publish();
+ }}
+ css={{ width: "fit-content" }}
>
- <ToggleGroup
- color={styleSource}
- type="single"
- value={currentValue}
- onValueChange={(value) => {
- setProperty(property)({ type: "keyword", value });
- }}
- css={{ width: "fit-content" }}
- >
- {items.map((item, index) => {
- const scrollableContent = Array.isArray(item.propertyValues)
- ? item.propertyValues.map((propertyValue) => (
- <div key={propertyValue}>{propertyValue}</div>
- ))
- : item.propertyValues;
- const handleReset = () => {
- if (item.value === currentValue) {
- deleteProperty(property);
- }
- };
- return (
- <PropertyTooltip
- key={item.value}
- open={openTootips[index]}
- onOpenChange={(open) => {
- setOpenTooltips((openTooltips) => {
- const newOpenTooltips = [...openTooltips];
- newOpenTooltips[index] = open;
- return newOpenTooltips;
- });
- }}
- title={item.title}
- scrollableContent={scrollableContent}
- description={item.description}
- properties={item.value === currentValue ? [property] : []}
- style={currentStyle}
- onReset={handleReset}
- >
- <ToggleGroupButton
- disabled={isAdvanced}
- onMouseEnter={() => {
- setOpenTooltips((openTooltips) => {
- return openTooltips.map((openTooltip, i) =>
- i !== index ? false : openTooltip
- );
- });
- }}
- value={item.value}
- onClick={(event) => {
- if (event.altKey) {
- handleReset();
- }
- }}
- >
- <Flex>{item.child}</Flex>
- </ToggleGroupButton>
- </PropertyTooltip>
- );
- })}
- </ToggleGroup>
- </AdvancedValueTooltip>
+ {items.map((item) => (
+ <ToggleGroupTooltip
+ key={item.value}
+ isOpen={item.value === activeTooltip}
+ onOpenChange={(isOpen) =>
+ setActiveTooltip(isOpen ? item.value : undefined)
+ }
+ isSelected={item.value === selectedValue}
+ isAdvanced={isAdvanced}
+ label={label}
+ code={properties
+ .map((property) => `${hyphenateProperty(property)}: ${item.value};`)
+ .join("\n")}
+ description={
+ item.description ??
+ declarationDescriptions[
+ `${properties[0]}:${item.value}` as keyof typeof declarationDescriptions
+ ]
+ }
+ properties={properties}
+ >
+ <ToggleGroupButton
+ aria-disabled={isAdvanced}
+ value={item.value}
+ onMouseEnter={() => setActiveTooltip(item.value)}
+ >
+ {item.child}
+ </ToggleGroupButton>
+ </ToggleGroupTooltip>
+ ))}
+ </ToggleGroup>
);
};
diff --git a/apps/builder/app/builder/features/style-panel/property-label.tsx b/apps/builder/app/builder/features/style-panel/property-label.tsx
index e208d2c476..15c3626e61 100644
--- a/apps/builder/app/builder/features/style-panel/property-label.tsx
+++ b/apps/builder/app/builder/features/style-panel/property-label.tsx
@@ -168,8 +168,8 @@ export const PropertyInfo = ({
);
};
-const getPriorityStyleSource = (
- styleSources: StyleValueSourceColor[]
+export const getPriorityStyleValueSource = (
+ styles: ComputedStyleDecl[]
): StyleValueSourceColor => {
const customOrder: StyleValueSourceColor[] = [
"overwritten",
@@ -178,6 +178,7 @@ const getPriorityStyleSource = (
"preset",
"default",
];
+ const styleSources = styles.map((styleDecl) => styleDecl.source.name);
for (const color of customOrder) {
if (styleSources.includes(color)) {
return color;
@@ -196,8 +197,7 @@ export const PropertyLabel = ({
properties: [StyleProperty, ...StyleProperty[]];
}) => {
const styles = useComputedStyles(properties);
- const colors = styles.map(({ source }) => source.name);
- const styleValueSourceColor = getPriorityStyleSource(colors);
+ const styleValueSourceColor = getPriorityStyleValueSource(styles);
const [isOpen, setIsOpen] = useState(false);
const resetProperty = () => {
const batch = createBatchUpdate();
@@ -255,8 +255,7 @@ export const PropertySectionLabel = ({
properties: [StyleProperty, ...StyleProperty[]];
}) => {
const styles = useComputedStyles(properties);
- const colors = styles.map(({ source }) => source.name);
- const styleValueSourceColor = getPriorityStyleSource(colors);
+ const styleValueSourceColor = getPriorityStyleValueSource(styles);
const [isOpen, setIsOpen] = useState(false);
const resetProperty = () => {
const batch = createBatchUpdate();
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
index b9980655f1..004de95f24 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
@@ -37,11 +37,11 @@ import {
} from "./background-layers";
import { FloatingPanelProvider } from "~/builder/shared/floating-panel";
import { BackgroundSize } from "./background-size";
-import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";
import { BackgroundGradient } from "./background-gradient";
import { BackgroundImage } from "./background-image";
import { BackgroundPosition } from "./background-position";
import { PropertyInlineLabel } from "../../property-label";
+import { ToggleGroupTooltip } from "../../controls/toggle-group/toggle-group-control";
type BackgroundContentProps = {
currentStyle: StyleInfo;
@@ -110,6 +110,86 @@ const Spacer = styled("div", {
height: theme.spacing[5],
});
+const BackgroundRepeat = (props: BackgroundContentProps) => {
+ const { currentStyle, setProperty } = props;
+ const items = [
+ {
+ child: <CrossSmallIcon />,
+ description:
+ "This value indicates that the background image will not be repeated and will appear only once.",
+ value: "no-repeat",
+ },
+ {
+ child: <RepeatGridIcon />,
+ description:
+ "This value indicates that the background image will be repeated both horizontally and vertically to fill the entire background area.",
+ value: "repeat",
+ },
+ {
+ child: <RepeatColumnIcon />,
+ description:
+ "This value indicates that the background image will be repeated only vertically.",
+ value: "repeat-y",
+ },
+ {
+ child: <RepeatRowIcon />,
+ description:
+ "This value indicates that the background image will be repeated only horizontally.",
+ value: "repeat-x",
+ },
+ ];
+ // Issue: The tooltip's grace area is too big and overlaps with nearby buttons,
+ // preventing the tooltip from changing when the buttons are hovered over in certain cases.
+ // To solve issue and allow tooltips to change on button hover,
+ // we close the button tooltip in the ToggleGroupButton.onMouseEnter handler.
+ // onMouseEnter used to preserve default hovering behavior on tooltip.
+ const [activeTooltip, setActiveTooltip] = useState<undefined | string>();
+ return (
+ <>
+ <PropertyInlineLabel
+ label="Repeat"
+ description={propertyDescriptions.backgroundRepeat}
+ properties={["backgroundRepeat"]}
+ />
+
+ <Flex css={{ justifySelf: "end" }}>
+ <ToggleGroup
+ type="single"
+ value={toValue(currentStyle.backgroundRepeat?.value)}
+ onValueChange={(value) => {
+ setProperty("backgroundRepeat")({
+ type: "keyword",
+ value,
+ });
+ }}
+ >
+ {items.map((item) => (
+ <ToggleGroupTooltip
+ key={item.value}
+ isOpen={item.value === activeTooltip}
+ onOpenChange={(isOpen) =>
+ setActiveTooltip(isOpen ? item.value : undefined)
+ }
+ isSelected={false}
+ label="Background Repeat"
+ code={`background-repeat: ${item.value};`}
+ description={item.description}
+ properties={["backgroundRepeat"]}
+ >
+ <ToggleGroupButton
+ value={item.value}
+ onMouseEnter={() => setActiveTooltip(item.value)}
+ >
+ {item.child}
+ </ToggleGroupButton>
+ </ToggleGroupTooltip>
+ ))}
+ </ToggleGroup>
+ </Flex>
+ </>
+ );
+};
+
export const BackgroundContent = (props: BackgroundContentProps) => {
const setProperty = safeSetProperty(props.setProperty);
const deleteProperty = safeDeleteProperty(props.deleteProperty);
@@ -218,58 +298,7 @@ export const BackgroundContent = (props: BackgroundContentProps) => {
align="center"
gap={2}
>
- {imageGradientToggle === "image" && (
- <>
- <PropertyInlineLabel
- label="Repeat"
- description={propertyDescriptions.backgroundRepeat}
- properties={["backgroundRepeat"]}
- />
-
- <Flex css={{ justifySelf: "end" }}>
- <ToggleGroupControl
- currentStyle={currentStyle}
- setProperty={setProperty}
- deleteProperty={deleteProperty}
- property="backgroundRepeat"
- items={[
- {
- child: <CrossSmallIcon />,
- title: "Background Repeat",
- description:
- "This value indicates that the background image will not be repeated and will appear only once.",
- value: "no-repeat",
- propertyValues: "background-repeat: no-repeat;",
- },
- {
- child: <RepeatGridIcon />,
- title: "Background Repeat",
- description:
- "This value indicates that the background image will be repeated both horizontally and vertically to fill the entire background area.",
- value: "repeat",
- propertyValues: "background-repeat: repeat;",
- },
- {
- child: <RepeatColumnIcon />,
- title: "Background Repeat",
- description:
- "This value indicates that the background image will be repeated only vertically.",
- value: "repeat-y",
- propertyValues: "background-repeat: repeat-y;",
- },
- {
- child: <RepeatRowIcon />,
- title: "Background Repeat",
- description:
- "This value indicates that the background image will be repeated only horizontally.",
- value: "repeat-x",
- propertyValues: "background-repeat: repeat-x;",
- },
- ]}
- />
- </Flex>
- </>
- )}
+ {imageGradientToggle === "image" && <BackgroundRepeat {...props} />}
<PropertyInlineLabel
label="Attachment"
diff --git a/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx b/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
index a8a69b590c..446f7a6239 100644
--- a/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx
@@ -1,7 +1,6 @@
import { toValue, type StyleProperty } from "@webstudio-is/css-engine";
import { Box, Grid } from "@webstudio-is/design-system";
import { styleConfigByName } from "../../shared/configs";
-import type { SectionProps } from "../shared/section";
import { rowCss } from "./utils";
import { PropertyLabel, PropertyValueTooltip } from "../../property-label";
import { ColorPicker } from "../../shared/color-picker";
@@ -17,7 +16,7 @@ export const properties = [
const { items } = styleConfigByName("borderTopColor");
-export const BorderColor = (_props: SectionProps) => {
+export const BorderColor = () => {
const styles = [
useComputedStyleDecl("borderTopColor"),
useComputedStyleDecl("borderRightColor"),
diff --git a/apps/builder/app/builder/features/style-panel/sections/borders/border-style.tsx b/apps/builder/app/builder/features/style-panel/sections/borders/border-style.tsx
index 13795f0e39..2c303305bb 100644
--- a/apps/builder/app/builder/features/style-panel/sections/borders/border-style.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/borders/border-style.tsx
@@ -6,18 +6,12 @@ import {
DottedBorderIcon,
SmallXIcon,
} from "@webstudio-is/icons";
-import type { SectionProps } from "../shared/section";
import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";
import {
declarationDescriptions,
propertyDescriptions,
} from "@webstudio-is/css-data";
-import {
- deleteAllProperties,
- setAllProperties,
- rowCss,
- isAdvancedValue,
-} from "./utils";
+import { rowCss } from "./utils";
import { PropertyLabel } from "../../property-label";
export const properties: [StyleProperty, ...StyleProperty[]] = [
@@ -27,60 +21,7 @@ export const properties: [StyleProperty, ...StyleProperty[]] = [
"borderBottomStyle",
];
-const items = [
- {
- child: <SmallXIcon />,
- title: "None",
- description: declarationDescriptions["borderBlockStyle:none"],
- value: "none",
- propertyValues: "border-style: none;",
- },
- {
- child: <DashBorderIcon />,
- title: "Solid",
- description: declarationDescriptions["borderBlockStyle:solid"],
- value: "solid",
- propertyValues: "border-style: solid;",
- },
- {
- child: <DashedBorderIcon />,
- title: "Dashed",
- description: declarationDescriptions["borderBlockStyle:dashed"],
- value: "dashed",
- propertyValues: "border-style: dashed;",
- },
- {
- child: <DottedBorderIcon />,
- title: "Dotted",
- description: declarationDescriptions["borderBlockStyle:dotted"],
- value: "dotted",
- propertyValues: "border-style: dotted;",
- },
-];
-
-export const BorderStyle = (
- props: Pick<
- SectionProps,
- "currentStyle" | "setProperty" | "deleteProperty" | "createBatchUpdate"
- >
-) => {
- // We do not use shorthand properties such as borderWidth or borderRadius in our code.
- // However, in the UI, we can display a single field, and in that case, we can use any property
- // from the shorthand property set and pass it instead.
- const firstPropertyName = properties[0];
-
- const deleteBorderProperties = deleteAllProperties(
- properties,
- props.createBatchUpdate
- );
-
- const setBorderProperties = setAllProperties(
- properties,
- props.createBatchUpdate
- )(firstPropertyName);
-
- const handleDelete = () => deleteBorderProperties(firstPropertyName);
-
+export const BorderStyle = () => {
return (
<Grid css={rowCss}>
<PropertyLabel
@@ -90,12 +31,30 @@ export const BorderStyle = (
/>
<Box css={{ gridColumn: `span 2`, justifySelf: "end" }}>
<ToggleGroupControl
- {...props}
- items={items}
- property={firstPropertyName}
- deleteProperty={handleDelete}
- setProperty={() => setBorderProperties}
- isAdvanced={isAdvancedValue(properties, props.currentStyle)}
+ label="Style"
+ properties={properties}
+ items={[
+ {
+ child: <SmallXIcon />,
+ description: declarationDescriptions["borderBlockStyle:none"],
+ value: "none",
+ },
+ {
+ child: <DashBorderIcon />,
+ description: declarationDescriptions["borderBlockStyle:solid"],
+ value: "solid",
+ },
+ {
+ child: <DashedBorderIcon />,
+ description: declarationDescriptions["borderBlockStyle:dashed"],
+ value: "dashed",
+ },
+ {
+ child: <DottedBorderIcon />,
+ description: declarationDescriptions["borderBlockStyle:dotted"],
+ value: "dotted",
+ },
+ ]}
/>
</Box>
</Grid>
diff --git a/apps/builder/app/builder/features/style-panel/sections/borders/borders.tsx b/apps/builder/app/builder/features/style-panel/sections/borders/borders.tsx
index e443f0e5ac..d8222d15f5 100644
--- a/apps/builder/app/builder/features/style-panel/sections/borders/borders.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/borders/borders.tsx
@@ -34,8 +34,8 @@ export const Section = (props: SectionProps) => {
properties={properties}
>
<Flex direction="column" gap={2}>
- <BorderStyle {...props} />
- <BorderColor {...props} />
+ <BorderStyle />
+ <BorderColor />
<BorderWidth {...props} />
<BorderRadius {...props} />
</Flex>
diff --git a/apps/builder/app/builder/features/style-panel/sections/borders/utils.ts b/apps/builder/app/builder/features/style-panel/sections/borders/utils.ts
index 54b5326d58..3d07721a13 100644
--- a/apps/builder/app/builder/features/style-panel/sections/borders/utils.ts
+++ b/apps/builder/app/builder/features/style-panel/sections/borders/utils.ts
@@ -1,11 +1,10 @@
import { theme, type CSS } from "@webstudio-is/design-system";
-import { toValue, type StyleProperty } from "@webstudio-is/css-engine";
+import type { StyleProperty } from "@webstudio-is/css-engine";
import type {
CreateBatchUpdate,
DeleteProperty,
SetProperty,
} from "../../shared/use-style-data";
-import type { StyleInfo } from "../../shared/style-info";
export const deleteAllProperties: (
styleProperties: readonly StyleProperty[],
@@ -40,19 +39,3 @@ export const rowCss: CSS = {
gridTemplateColumns: `1fr ${theme.spacing[20]} ${theme.spacing[12]}`,
gap: theme.spacing[5],
};
-
-export const isAdvancedValue = (
- properties: Array<StyleProperty>,
- currentStyle: StyleInfo
-) => {
- const values = properties.map((property) =>
- toValue(currentStyle[property]?.value)
- );
-
- // We can represent the value with a toggle group if all values are the same.
- return (
- values[0] !== values[1] ||
- values[0] !== values[2] ||
- values[0] !== values[3]
- );
-};
diff --git a/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx b/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
index 121b6c91d1..d69ed1cba6 100644
--- a/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
@@ -1,8 +1,17 @@
-import { Flex, Grid, theme } from "@webstudio-is/design-system";
+import {
+ Flex,
+ Grid,
+ theme,
+ ToggleGroup,
+ ToggleGroupButton,
+} from "@webstudio-is/design-system";
import { toValue } from "@webstudio-is/css-engine";
-import type { StyleProperty, StyleValue } from "@webstudio-is/css-engine";
+import type { StyleProperty } from "@webstudio-is/css-engine";
import type { SectionProps } from "../shared/section";
-import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";
+import {
+ ToggleGroupControl,
+ ToggleGroupTooltip,
+} from "../../controls/toggle-group/toggle-group-control";
import { TextControl } from "../../controls";
import {
SmallXIcon,
@@ -19,8 +28,14 @@ import {
} from "@webstudio-is/icons";
import { FloatingPanel } from "~/builder/shared/floating-panel";
import { CollapsibleSection } from "../../shared/collapsible-section";
-import { PropertyLabel } from "../../property-label";
+import {
+ getPriorityStyleValueSource,
+ PropertyLabel,
+} from "../../property-label";
import { propertyDescriptions } from "@webstudio-is/css-data";
+import { useState } from "react";
+import { useComputedStyleDecl, useComputedStyles } from "../../shared/model";
+import { createBatchUpdate, setProperty } from "../../shared/use-style-data";
export const properties = [
"flexShrink",
@@ -28,7 +43,7 @@ export const properties = [
"flexBasis",
"alignSelf",
"order",
-] satisfies Array<StyleProperty>;
+] satisfies [StyleProperty, ...StyleProperty[]];
export const Section = (props: SectionProps) => {
return (
@@ -38,15 +53,15 @@ export const Section = (props: SectionProps) => {
properties={properties}
>
<Flex css={{ flexDirection: "column", gap: theme.spacing[5] }}>
- <FlexChildSectionAlign {...props} />
- <FlexChildSectionSizing {...props} />
- <FlexChildSectionOrder {...props} />
+ <FlexChildSectionAlign />
+ <FlexChildSectionSizing />
+ <FlexChildSectionOrder />
</Flex>
</CollapsibleSection>
);
};
-const FlexChildSectionAlign = (props: SectionProps) => {
+const FlexChildSectionAlign = () => {
return (
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyLabel
@@ -55,55 +70,42 @@ const FlexChildSectionAlign = (props: SectionProps) => {
properties={["alignSelf"]}
/>
<ToggleGroupControl
- {...props}
- // We don't support "flex" shorthand and this control is manipulating 3 properties at once
- property="alignSelf"
+ label="Align"
+ properties={["alignSelf"]}
items={[
{
child: <SmallXIcon />,
- title: "Align",
description:
"The element's alignment is determined by its parent's align-items property.",
value: "auto",
- propertyValues: "align-self: auto;",
},
{
child: <ASStartIcon />,
- title: "Align",
description:
"The element is aligned at the start of the cross axis.",
value: "flex-start",
- propertyValues: "align-self: flex-start;",
},
{
child: <ASEndIcon />,
- title: "Align",
description: "The element is aligned at the end of the cross axis.",
value: "flex-end",
- propertyValues: "align-self: flex-end;",
},
{
child: <ASCenterIcon />,
- title: "Align",
description: "The element is centered along the cross axis.",
value: "center",
- propertyValues: "align-self: center;",
},
{
child: <ASStretchIcon />,
- title: "Align",
description:
"The element is stretched to fill the entire cross axis.",
value: "stretch",
- propertyValues: "align-self: stretch;",
},
{
child: <ASBaselineIcon />,
- title: "Align",
description:
"The element is aligned to the baseline of the parent.",
value: "baseline",
- propertyValues: "align-self: baseline;",
},
]}
/>
@@ -111,16 +113,69 @@ const FlexChildSectionAlign = (props: SectionProps) => {
);
};
-const FlexChildSectionSizing = (props: SectionProps) => {
- const { createBatchUpdate, currentStyle } = props;
- const setSizing = createBatchUpdate();
- const onReset = () => {
- setSizing.deleteProperty("flexGrow");
- setSizing.deleteProperty("flexShrink");
- setSizing.deleteProperty("flexBasis");
- setSizing.publish();
- };
+const getSizingValue = (flexGrow: string, flexShrink: string) => {
+ if (flexGrow === "0" && flexShrink === "0") {
+ return "none";
+ }
+ if (flexGrow === "1" && flexShrink === "0") {
+ return "grow";
+ }
+ if (flexGrow === "0" && flexShrink === "1") {
+ return "shrink";
+ }
+ return "";
+};
+const FlexChildSectionSizing = () => {
+ const styles = useComputedStyles(["flexGrow", "flexShrink", "flexBasis"]);
+ const [flexGrow, flexShrink, flexBasis] = styles;
+ const styleValueSource = getPriorityStyleValueSource(styles);
+ const selectedValue = getSizingValue(
+ toValue(flexGrow.cascadedValue),
+ toValue(flexShrink.cascadedValue)
+ );
+ const items = [
+ {
+ child: <SmallXIcon />,
+ description: "Don't grow or shrink",
+ value: "none",
+ codeLines: ["flex-grow: 0;", "flex-shrink: 0;"],
+ },
+ {
+ child: <GrowIcon />,
+ title: "Flex",
+ description:
+ "Item will expand to take up available space within a flex container if needed, but it will not shrink if there is limited space.",
+ value: "grow",
+ codeLines: ["flex-grow: 1;", "flex-shrink: 0;"],
+ },
+ {
+ child: <ShrinkIcon />,
+ title: "Flex",
+ description:
+ "Item will not grow to take up available space within a flex container, but it will shrink if there is limited space",
+ value: "shrink",
+ codeLines: ["flex-grow: 0;", "flex-shrink: 1;"],
+ },
+ {
+ child: <FlexChildSectionSizingPopover />,
+ title: "Flex",
+ description:
+ "More sizing options, set flex-basis, flex-grow, flex-shrink individually",
+ value: "",
+ codeLines: [
+ `flex-basis: ${toValue(flexBasis.cascadedValue)};`,
+ `flex-grow: ${toValue(flexGrow.cascadedValue)};`,
+ `flex-shrink: ${toValue(flexShrink.cascadedValue)};`,
+ ],
+ },
+ ];
+ // Issue: The tooltip's grace area is too big and overlaps with nearby buttons,
+ // preventing the tooltip from changing when the buttons are hovered over in certain cases.
+ // To solve issue and allow tooltips to change on button hover,
+ // we close the button tooltip in the ToggleGroupButton.onMouseEnter handler.
+ // onMouseEnter used to preserve default hovering behavior on tooltip.
+ const [activeTooltip, setActiveTooltip] = useState<undefined | string>();
return (
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyLabel
@@ -128,105 +183,66 @@ const FlexChildSectionSizing = (props: SectionProps) => {
description="Specifies the ability of a flex item to grow, shrink, or set its initial size within a flex container."
properties={["flexGrow", "flexShrink", "flexBasis"]}
/>
- <ToggleGroupControl
- {...props}
- // We don't support "flex" shorthand and this control is manipulating 3 properties at once
- property="flexGrow"
- deleteProperty={onReset}
- setProperty={() => {
- return (styleValue: StyleValue) => {
- if (styleValue.type !== "keyword") {
- // should not happen
- return;
- }
- switch (styleValue.value) {
- case "none": {
- setSizing.setProperty("flexGrow")({
- type: "unit",
- value: 0,
- unit: "number",
- });
- setSizing.setProperty("flexShrink")({
- type: "unit",
- value: 0,
- unit: "number",
- });
- setSizing.publish();
- break;
- }
- case "grow": {
- setSizing.setProperty("flexGrow")({
- type: "unit",
- value: 1,
- unit: "number",
- });
- setSizing.setProperty("flexShrink")({
- type: "unit",
- value: 0,
- unit: "number",
- });
- setSizing.publish();
- break;
- }
- case "shrink": {
- setSizing.setProperty("flexGrow")({
- type: "unit",
- value: 0,
- unit: "number",
- });
- setSizing.setProperty("flexShrink")({
- type: "unit",
- value: 1,
- unit: "number",
- });
- setSizing.publish();
- break;
- }
- }
- };
+
+ {/* We don't support "flex" shorthand and
+ this control is manipulating 3 properties at once */}
+ <ToggleGroup
+ color={styleValueSource}
+ type="single"
+ value={selectedValue}
+ onValueChange={(value) => {
+ const batch = createBatchUpdate();
+ let flexGrow: undefined | number;
+ let flexShrink: undefined | number;
+ if (value === "none") {
+ flexGrow = 0;
+ flexShrink = 0;
+ }
+ if (value === "grow") {
+ flexGrow = 1;
+ flexShrink = 0;
+ }
+ if (value === "shrink") {
+ flexGrow = 0;
+ flexShrink = 1;
+ }
+ if (flexGrow !== undefined && flexShrink !== undefined) {
+ batch.setProperty("flexGrow")({
+ type: "unit",
+ value: flexGrow,
+ unit: "number",
+ });
+ batch.setProperty("flexShrink")({
+ type: "unit",
+ value: flexShrink,
+ unit: "number",
+ });
+ }
+ batch.publish();
}}
- value={getSizingValue(
- toValue(currentStyle.flexGrow?.value),
- toValue(currentStyle.flexShrink?.value)
- )}
- items={[
- {
- child: <SmallXIcon />,
- title: "Flex",
- description: "Don't grow or shrink",
- value: "none",
- propertyValues: ["flex-grow: 0;", "flex-shrink: 0;"],
- },
- {
- child: <GrowIcon />,
- title: "Flex",
- description:
- "Item will expand to take up available space within a flex container if needed, but it will not shrink if there is limited space.",
- value: "grow",
- propertyValues: ["flex-grow: 1;", "flex-shrink: 0;"],
- },
- {
- child: <ShrinkIcon />,
- title: "Flex",
- description:
- "Item will not grow to take up available space within a flex container, but it will shrink if there is limited space",
- value: "shrink",
- propertyValues: ["flex-grow: 0;", "flex-shrink: 1;"],
- },
- {
- child: <FlexChildSectionSizingPopover />,
- title: "Flex",
- description:
- "More sizing options, set flex-basis, flex-grow, flex-shrink individually",
- value: "",
- propertyValues: [
- `flex-basis: ${toValue(currentStyle.flexBasis?.value)};`,
- `flex-grow: ${toValue(currentStyle.flexGrow?.value)};`,
- `flex-shrink: ${toValue(currentStyle.flexShrink?.value)};`,
- ],
- },
- ]}
- />
+ >
+ {items.map((item) => (
+ <ToggleGroupTooltip
+ key={item.value}
+ isOpen={item.value === activeTooltip}
+ onOpenChange={(isOpen) =>
+ setActiveTooltip(isOpen ? item.value : undefined)
+ }
+ isSelected={item.value === selectedValue}
+ label="Sizing"
+ code={item.codeLines.join("\n")}
+ description={item.description}
+ properties={["flexGrow", "flexShrink", "flexBasis"]}
+ >
+ <ToggleGroupButton
+ value={item.value}
+ onMouseEnter={() => setActiveTooltip(item.value)}
+ >
+ {item.child}
+ </ToggleGroupButton>
+ </ToggleGroupTooltip>
+ ))}
+ </ToggleGroup>
</Grid>
);
};
@@ -277,10 +293,41 @@ const FlexChildSectionSizingPopover = () => {
);
};
-const FlexChildSectionOrder = (props: SectionProps) => {
- const { setProperty, currentStyle } = props;
- const setOrder = setProperty("order");
-
+const FlexChildSectionOrder = () => {
+ const order = useComputedStyleDecl("order");
+ const selectedValue = toValue(order.cascadedValue);
+ const items = [
+ {
+ child: <SmallXIcon />,
+ description: "Don't change",
+ value: "0",
+ code: "order: 0;",
+ },
+ {
+ child: <OrderFirstIcon />,
+ description: "Make first",
+ value: "-1",
+ code: "order: -1;",
+ },
+ {
+ child: <OrderLastIcon />,
+ description: "Make last",
+ value: "1",
+ code: "order: 1;",
+ },
+ {
+ child: <FlexChildSectionOrderPopover />,
+ description: "Customize order",
+ value: "",
+ code: `order: ${selectedValue};`,
+ },
+ ];
+ // Issue: The tooltip's grace area is too big and overlaps with nearby buttons,
+ // preventing the tooltip from changing when the buttons are hovered over in certain cases.
+ // To solve issue and allow tooltips to change on button hover,
+ // we close the button tooltip in the ToggleGroupButton.onMouseEnter handler.
+ // onMouseEnter used to preserve default hovering behavior on tooltip.
+ const [activeTooltip, setActiveTooltip] = useState<undefined | string>();
return (
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyLabel
@@ -288,60 +335,47 @@ const FlexChildSectionOrder = (props: SectionProps) => {
description={propertyDescriptions.order}
properties={["order"]}
/>
- <ToggleGroupControl
- {...props}
- property="order"
- setProperty={() => {
- return (styleValue: StyleValue) => {
- if (styleValue.type !== "keyword") {
- // should not happen
- return;
- }
- switch (styleValue.value) {
- case "0":
- case "1":
- case "-1": {
- setOrder({
- type: "unit",
- value: Number(styleValue.value),
- unit: "number",
- });
- break;
- }
+ <ToggleGroup
+ color={order.source.name}
+ type="single"
+ value={selectedValue}
+ onValueChange={(value) => {
+ switch (value) {
+ case "0":
+ case "1":
+ case "-1": {
+ setProperty("order")({
+ type: "unit",
+ value: Number(value),
+ unit: "number",
+ });
+ break;
}
- };
+ }
}}
- items={[
- {
- child: <SmallXIcon />,
- title: "Order",
- description: "Dont't change",
- value: "0",
- propertyValues: "order: 0;",
- },
- {
- child: <OrderFirstIcon />,
- title: "Order",
- description: "Make first",
- value: "-1",
- propertyValues: "order: -1;",
- },
- {
- child: <OrderLastIcon />,
- title: "Order",
- description: "Make last",
- value: "1",
- propertyValues: "order: 1;",
- },
- {
- child: <FlexChildSectionOrderPopover />,
- title: "Order",
- description: "Customize order",
- value: "",
- propertyValues: `order: ${toValue(currentStyle.order?.value)};`,
- },
- ]}
- />
+ >
+ {items.map((item) => (
+ <ToggleGroupTooltip
+ key={item.value}
+ isOpen={item.value === activeTooltip}
+ onOpenChange={(isOpen) =>
+ setActiveTooltip(isOpen ? item.value : undefined)
+ }
+ isSelected={item.value === selectedValue}
+ label="Sizing"
+ code={item.code}
+ description={item.description}
+ properties={["flexGrow", "flexShrink", "flexBasis"]}
+ >
+ <ToggleGroupButton
+ value={item.value}
+ onMouseEnter={() => setActiveTooltip(item.value)}
+ >
+ {item.child}
+ </ToggleGroupButton>
+ </ToggleGroupTooltip>
+ ))}
+ </ToggleGroup>
</Grid>
);
};
@@ -369,16 +403,3 @@ const FlexChildSectionOrderPopover = () => {
</FloatingPanel>
);
};
-
-const getSizingValue = (flexGrow: string, flexShrink: string) => {
- if (flexGrow === "0" && flexShrink === "0") {
- return "none";
- }
- if (flexGrow === "1" && flexShrink === "0") {
- return "grow";
- }
- if (flexGrow === "0" && flexShrink === "1") {
- return "shrink";
- }
- return "";
-};
diff --git a/apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsx b/apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsx
index 27477602ea..ceb8260ac2 100644
--- a/apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsx
@@ -1,4 +1,3 @@
-import type { StyleProperty } from "@webstudio-is/css-engine";
import { Grid, theme, Box } from "@webstudio-is/design-system";
import {
DashBorderIcon,
@@ -6,50 +5,11 @@ import {
DottedBorderIcon,
SmallXIcon,
} from "@webstudio-is/icons";
-import type { SectionProps } from "../shared/section";
-import {
- declarationDescriptions,
- propertyDescriptions,
-} from "@webstudio-is/css-data";
-import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";
+import { propertyDescriptions } from "@webstudio-is/css-data";
import { PropertyLabel } from "../../property-label";
+import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";
-const property: StyleProperty = "outlineStyle";
-
-const items = [
- {
- child: <SmallXIcon />,
- title: "None",
- description: declarationDescriptions["outlineStyle:none"],
- value: "none",
- propertyValues: "outline-style: none;",
- },
- {
- child: <DashBorderIcon />,
- title: "Solid",
- description: declarationDescriptions["outlineStyle:solid"],
- value: "solid",
- propertyValues: "outline-style: solid;",
- },
- {
- child: <DashedBorderIcon />,
- title: "Dashed",
- description: declarationDescriptions["outlineStyle:dashed"],
- value: "dashed",
- propertyValues: "outline-style: dashed;",
- },
- {
- child: <DottedBorderIcon />,
- title: "Dotted",
- description: declarationDescriptions["outlineStyle:dotted"],
- value: "dotted",
- propertyValues: "outline-style: dotted;",
- },
-];
-
-export const OutlineStyle = (
- props: Pick<SectionProps, "currentStyle" | "setProperty" | "deleteProperty">
-) => {
+export const OutlineStyle = () => {
return (
<Grid
css={{
@@ -63,7 +23,16 @@ export const OutlineStyle = (
properties={["outlineStyle"]}
/>
<Box css={{ gridColumn: `span 2`, justifySelf: "end" }}>
- <ToggleGroupControl {...props} items={items} property={property} />{" "}
+ <ToggleGroupControl
+ label="Style"
+ properties={["outlineStyle"]}
+ items={[
+ { child: <SmallXIcon />, value: "none" },
+ { child: <DashBorderIcon />, value: "solid" },
+ { child: <DashedBorderIcon />, value: "dashed" },
+ { child: <DottedBorderIcon />, value: "dotted" },
+ ]}
+ />
</Box>
</Grid>
);
diff --git a/apps/builder/app/builder/features/style-panel/sections/outline/outline.tsx b/apps/builder/app/builder/features/style-panel/sections/outline/outline.tsx
index 2dec2e9bc6..f4ed7dd379 100644
--- a/apps/builder/app/builder/features/style-panel/sections/outline/outline.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/outline/outline.tsx
@@ -31,11 +31,7 @@ export const Section = (props: SectionProps) => {
properties={properties}
>
<Flex direction="column" gap={2}>
- <OutlineStyle
- currentStyle={currentStyle}
- setProperty={setProperty}
- deleteProperty={deleteProperty}
- />
+ <OutlineStyle />
{outlineStyle.value.value !== "none" && (
<>
<Grid
diff --git a/apps/builder/app/builder/features/style-panel/sections/size/size.tsx b/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
index f0ad82a58a..7b2678b6dc 100644
--- a/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
@@ -112,7 +112,6 @@ export const Section = ({
currentStyle,
setProperty,
deleteProperty,
- createBatchUpdate,
}: SectionProps) => {
return (
<CollapsibleSection
@@ -143,53 +142,33 @@ export const Section = ({
properties={["overflowX", "overflowY"]}
/>
<ToggleGroupControl
- property="overflowX"
- currentStyle={currentStyle}
- setProperty={() => (value) => {
- const batch = createBatchUpdate();
- batch.setProperty("overflowX")(value);
- batch.setProperty("overflowY")(value);
- batch.publish();
- }}
- deleteProperty={() => {
- const batch = createBatchUpdate();
- batch.deleteProperty("overflowX");
- batch.deleteProperty("overflowY");
- batch.publish();
- }}
+ label="Overflow"
+ properties={["overflowX", "overflowY"]}
items={[
{
child: <EyeconOpenIcon />,
- title: "Overflow",
description:
"Content is fully visible and extends beyond the container if it exceeds its size.",
value: "visible",
- propertyValues: "overflow-x: visible;\noverflow-y: visible;",
},
{
child: <EyeconClosedIcon />,
- title: "Overflow",
description:
"Content that exceeds the container's size is clipped and hidden without scrollbars.",
value: "hidden",
- propertyValues: "overflow-x: hidden;\noverflow-y: hidden;",
},
{
child: <ScrollIcon />,
- title: "Overflow",
description:
"Scrollbars are added to the container, allowing users to scroll and view the exceeding content.",
value: "scroll",
- propertyValues: "overflow-x: scroll;\noverflow-y: scroll;",
},
{
child: <AutoScrollIcon />,
- title: "Overflow",
description:
"Scrollbars are added to the container only when necessary, based on the content size.",
value: "auto",
- propertyValues: "overflow-x: auto;\noverflow-y: auto;",
},
]}
/>
diff --git a/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx b/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
index 945dc4ddb1..ad8b5d07ef 100644
--- a/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
@@ -7,7 +7,7 @@ import {
IconButton,
} from "@webstudio-is/design-system";
import { propertyDescriptions } from "@webstudio-is/css-data";
-import { toValue, type StyleProperty } from "@webstudio-is/css-engine";
+import type { StyleProperty } from "@webstudio-is/css-engine";
import type { SectionProps } from "../shared/section";
import {
ColorControl,
@@ -144,139 +144,99 @@ const TypographySectionSizing = () => {
};
export const TypographySectionAdvanced = (props: SectionProps) => {
- const { currentStyle } = props;
- const textAlignValue = toValue(currentStyle.textAlign?.value);
return (
<Grid gap="2" columns="2" align="end">
<ToggleGroupControl
- {...props}
- property="textAlign"
- value={
- // Convert to logical props
- textAlignValue === "left"
- ? "start"
- : textAlignValue === "right"
- ? "end"
- : textAlignValue
- }
+ properties={["textAlign"]}
items={[
{
child: <TextAlignLeftIcon />,
- title: "Text Align",
description: "Aligns the text based on the writing direction.",
value: "start",
- propertyValues: "text-align: start;",
},
{
child: <TextAlignCenterIcon />,
- title: "Text Align",
description: "Centers the text horizontally within its container.",
value: "center",
- propertyValues: "text-align: center;",
},
{
child: <TextAlignRightIcon />,
- title: "Text Align",
description: "Aligns the text based on the writing direction.",
value: "end",
- propertyValues: "text-align: end;",
},
{
child: <TextAlignJustifyIcon />,
- title: "Text Align",
description:
"Adjusts word spacing to align text to both the left and right edges of the container",
value: "justify",
- propertyValues: "text-align: justify;",
},
]}
/>
<ToggleGroupControl
- {...props}
- property="textDecorationLine"
+ properties={["textDecorationLine"]}
items={[
{
child: <CrossSmallIcon />,
- title: "Text Decoration Line",
description: "No decoration is applied to the text.",
value: "none",
- propertyValues: "text-decoration-line: none;",
},
{
- title: "Text Decoration Line",
child: <TextUnderlineIcon />,
- description: " Adds a horizontal line underneath the text.",
+ description: "Adds a horizontal line underneath the text.",
value: "underline",
- propertyValues: "text-decoration-line: underline;",
},
{
- title: "Text Decoration Line",
child: <TextStrikethroughIcon />,
description:
"Draws a horizontal line through the middle of the text.",
value: "line-through",
- propertyValues: "text-decoration-line: line-through;",
},
]}
/>
<ToggleGroupControl
- {...props}
- property="textTransform"
+ properties={["textTransform"]}
items={[
{
child: <CrossSmallIcon />,
- title: "Text Transform",
description:
"No transformation is applied to the text. The text appears as it is.",
value: "none",
- propertyValues: "text-transform: none;",
},
{
child: <TextUppercaseIcon />,
- title: "Text Transform",
description:
"Transforms the text to appear in all uppercase letters.",
value: "uppercase",
- propertyValues: "text-transform: uppercase;",
},
{
child: <TextCapitalizeIcon />,
- title: "Text Transform",
description:
"Transforms the first character of each word to uppercase, while the remaining characters are in lowercase.",
value: "capitalize",
- propertyValues: "text-transform: capitalize;",
},
{
child: <TextLowercaseIcon />,
- title: "Text Transform",
description:
" Transforms the text to appear in all lowercase letters.",
value: "lowercase",
- propertyValues: "text-transform: lowercase;",
},
]}
/>
<Grid align="end" gap="1" css={{ gridTemplateColumns: "3fr 1fr" }}>
<ToggleGroupControl
- {...props}
- property="fontStyle"
+ properties={["fontStyle"]}
items={[
{
child: <CrossSmallIcon />,
- title: "Font Style",
description:
"The default value. The text appears in a normal, upright style.",
value: "normal",
- propertyValues: "font-style: normal;",
},
{
child: <TextItalicIcon />,
- title: "Font Style",
description:
"The text appears in italic style, where it is slanted to the right.",
value: "italic",
- propertyValues: "font-style: italic;",
},
]}
/>
@@ -376,24 +336,19 @@ export const TypographySectionAdvancedPopover = (props: SectionProps) => {
properties={["direction"]}
/>
<ToggleGroupControl
- {...props}
- property="direction"
+ properties={["direction"]}
items={[
{
child: <TextDirectionLTRIcon />,
- title: "Direction",
description:
"Sets the text direction to left-to-right, which is the default for most languages.",
value: "ltr",
- propertyValues: "direction: ltr;",
},
{
child: <TextDirectionRTLIcon />,
- title: "Direction",
description:
"Sets the text direction to right-to-left, typically used for languages such as Arabic or Hebrew.",
value: "rtl",
- propertyValues: "direction: rtl;",
},
]}
/>
@@ -405,24 +360,19 @@ export const TypographySectionAdvancedPopover = (props: SectionProps) => {
properties={["hyphens"]}
/>
<ToggleGroupControl
- {...props}
- property="hyphens"
+ properties={["hyphens"]}
items={[
{
child: <CrossSmallIcon />,
- title: "Hyphens",
description:
"Disables hyphenation of words. Words will not be hyphenated even if they exceed the width of their container.",
value: "manual",
- propertyValues: "hyphens: none;",
},
{
child: <TextHyphenIcon />,
- title: "Hyphens",
description:
"Enables automatic hyphenation of words. The browser will hyphenate long words at appropriate points to fit within the width of their container.",
value: "auto",
- propertyValues: "hyphens: auto;",
},
]}
/>
@@ -434,24 +384,19 @@ export const TypographySectionAdvancedPopover = (props: SectionProps) => {
properties={["textOverflow"]}
/>
<ToggleGroupControl
- {...props}
- property="textOverflow"
+ properties={["textOverflow"]}
items={[
{
child: <CrossSmallIcon />,
- title: "Text Overflow",
description:
"The overflowing text is clipped and hidden without any indication.",
value: "clip",
- propertyValues: "text-overflow: clip;",
},
{
child: <TextTruncateIcon />,
- title: "Text Overflow",
description:
"The overflowing text is truncated with an ellipsis (...) to indicate that there is more content. To make the text-overflow: ellipsis property work, you need to set the following CSS properties: white-space: nowrap; overflow: hidden;",
value: "ellipsis",
- propertyValues: "text-overflow: ellipsis;",
},
]}
/>
diff --git a/apps/builder/app/builder/features/style-panel/shared/model.tsx b/apps/builder/app/builder/features/style-panel/shared/model.tsx
index cdca33597c..62693b47ed 100644
--- a/apps/builder/app/builder/features/style-panel/shared/model.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/model.tsx
@@ -110,7 +110,7 @@ const $model = computed(
}
);
-export const createComputedStyleDeclStore = (property: string) => {
+export const createComputedStyleDeclStore = (property: StyleProperty) => {
return computed(
[$model, $selectedInstanceSelector, $selectedOrLastStyleSourceSelector],
(model, instanceSelector, styleSourceSelector) => {