Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
refactor: migrate outline section to style object model (#4074)
Bogdan Chadkincafba3335201
diff --git a/apps/builder/app/builder/features/style-panel/sections/outline/outline-offset.tsx b/apps/builder/app/builder/features/style-panel/sections/outline/outline-offset.tsxdeleted file mode 100644index 4d193bdba0..0000000000--- a/apps/builder/app/builder/features/style-panel/sections/outline/outline-offset.tsx+++ /dev/null@@ -1,54 +0,0 @@-import { propertyDescriptions } from "@webstudio-is/css-data";-import type { StyleProperty, UnitValue } from "@webstudio-is/css-engine";-import { Grid, theme } from "@webstudio-is/design-system";-import { CssValueInputContainer } from "../../shared/css-value-input";-import type { SectionProps } from "../shared/section";-import { styleConfigByName } from "../../shared/configs";-import { getStyleSource } from "../../shared/style-info";-import { PropertyLabel } from "../../property-label";--const property: StyleProperty = "outlineOffset";-const defaultOutlineOffsetValue: UnitValue = {- type: "unit",- value: 0,- unit: "number",-};--export const OutlineOffset = (- props: Pick<SectionProps, "currentStyle" | "setProperty" | "deleteProperty">-) => {- const { deleteProperty, setProperty, currentStyle } = props;- const outlineOffsetValue =- currentStyle[property]?.value ?? defaultOutlineOffsetValue;- const outlineOffsetStyleConfig = styleConfigByName(property);- const outlineOffsetWidthKeywords = outlineOffsetStyleConfig.items.map(- (item) => ({- type: "keyword" as const,- value: item.name,- })- );-- return (- <Grid- css={{- gridTemplateColumns: `1fr ${theme.spacing[20]}`,- }}- gap={2}- >- <PropertyLabel- label="Offset"- description={propertyDescriptions.outlineOffset}- properties={["outlineOffset"]}- />-- <CssValueInputContainer- property={property}- styleSource={getStyleSource(currentStyle[property])}- keywords={outlineOffsetWidthKeywords}- setValue={setProperty(property)}- deleteProperty={deleteProperty}- value={outlineOffsetValue}- />- </Grid>- );-};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.tsxdeleted file mode 100644index ceb8260ac2..0000000000--- a/apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsx+++ /dev/null@@ -1,39 +0,0 @@-import { Grid, theme, Box } from "@webstudio-is/design-system";-import {- DashBorderIcon,- DashedBorderIcon,- DottedBorderIcon,- SmallXIcon,-} from "@webstudio-is/icons";-import { propertyDescriptions } from "@webstudio-is/css-data";-import { PropertyLabel } from "../../property-label";-import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";--export const OutlineStyle = () => {- return (- <Grid- css={{- gridTemplateColumns: `1fr ${theme.spacing[20]} ${theme.spacing[12]}`,- }}- gap={2}- >- <PropertyLabel- label="Style"- description={propertyDescriptions.outlineStyle}- properties={["outlineStyle"]}- />- <Box css={{ gridColumn: `span 2`, justifySelf: "end" }}>- <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-width.tsx b/apps/builder/app/builder/features/style-panel/sections/outline/outline-width.tsxdeleted file mode 100644index 082e80b189..0000000000--- a/apps/builder/app/builder/features/style-panel/sections/outline/outline-width.tsx+++ /dev/null@@ -1,47 +0,0 @@-import { propertyDescriptions } from "@webstudio-is/css-data";-import type { StyleProperty } from "@webstudio-is/css-engine";-import { Grid, theme } from "@webstudio-is/design-system";-import type { SectionProps } from "../shared/section";-import { CssValueInputContainer } from "../../shared/css-value-input";-import { styleConfigByName } from "../../shared/configs";-import { getStyleSource } from "../../shared/style-info";-import { PropertyLabel } from "../../property-label";--const property: StyleProperty = "outlineWidth";--export const OutlineWidth = (- props: Pick<SectionProps, "currentStyle" | "setProperty" | "deleteProperty">-) => {- const { deleteProperty, setProperty, currentStyle } = props;- const outlineWidthValue = currentStyle[property]?.value;- const outlineStyleConfig = styleConfigByName(property);- const outlineStyleWidthKeywords = outlineStyleConfig.items.map((item) => ({- type: "keyword" as const,- value: item.name,- }));-- return (- <Grid- css={{- gridTemplateColumns: `1fr ${theme.spacing[20]}`,- }}- gap={2}- >- <PropertyLabel- label="Width"- description={propertyDescriptions.outlineWidth}- properties={["outlineWidth"]}- />-- <CssValueInputContainer- key={property}- property={property}- styleSource={getStyleSource(currentStyle[property])}- keywords={outlineStyleWidthKeywords}- setValue={setProperty(property)}- deleteProperty={deleteProperty}- value={outlineWidthValue}- />- </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.tsxindex 9c0f568e92..6c2e43d4b8 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@@ -1,13 +1,17 @@-import { Flex, Grid, theme, Box } from "@webstudio-is/design-system";+import { theme, Grid, Box } from "@webstudio-is/design-system";+import {+ DashBorderIcon,+ DashedBorderIcon,+ DottedBorderIcon,+ SmallXIcon,+} from "@webstudio-is/icons";import { propertyDescriptions } from "@webstudio-is/css-data";-import type { StyleProperty } from "@webstudio-is/css-engine";-import { ColorControl } from "../../controls";+import { toValue, type StyleProperty } from "@webstudio-is/css-engine";+import { ColorControl, TextControl } from "../../controls";import { StyleSection } from "../../shared/style-section";-import type { SectionProps } from "../shared/section";-import { OutlineStyle } from "./outline-style";-import { OutlineWidth } from "./outline-width";-import { OutlineOffset } from "./outline-offset";import { PropertyLabel } from "../../property-label";+import { useComputedStyleDecl } from "../../shared/model";+import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";export const properties = ["outlineStyle",@@ -16,50 +20,60 @@ export const properties = ["outlineOffset",] satisfies Array<StyleProperty>;-export const Section = (props: SectionProps) => {- const { currentStyle, setProperty, deleteProperty } = props;- const { outlineStyle } = currentStyle;-- if (outlineStyle?.value.type !== "keyword") {- return;- }+export const Section = () => {+ const outlineStyle = useComputedStyleDecl("outlineStyle");+ const outlineStyleValue = toValue(outlineStyle.cascadedValue);return (<StyleSection label="Outline" properties={properties}>- <Flex direction="column" gap={2}>- <OutlineStyle />- {outlineStyle.value.value !== "none" && (- <>- <Grid- css={{- gridTemplateColumns: `1fr ${theme.spacing[20]} ${theme.spacing[12]}`,- }}- gapX={2}- >- <PropertyLabel- label="Color"- description={propertyDescriptions.outlineColor}- properties={["outlineColor"]}- />- <Box css={{ gridColumn: `span 2` }}>- <ColorControl property="outlineColor" />- </Box>- </Grid>+ <Grid+ css={{+ // label gap (input gap expand)+ gridTemplateColumns: `1fr calc(${theme.spacing[20]} + ${theme.spacing[5]} + ${theme.spacing[12]})`,+ }}+ gap={2}+ >+ <PropertyLabel+ label="Style"+ description={propertyDescriptions.outlineStyle}+ properties={["outlineStyle"]}+ />+ <Box css={{ justifySelf: "end" }}>+ <ToggleGroupControl+ label="Style"+ properties={["outlineStyle"]}+ items={[+ { child: <SmallXIcon />, value: "none" },+ { child: <DashBorderIcon />, value: "solid" },+ { child: <DashedBorderIcon />, value: "dashed" },+ { child: <DottedBorderIcon />, value: "dotted" },+ ]}+ />+ </Box>- <OutlineWidth- currentStyle={currentStyle}- setProperty={setProperty}- deleteProperty={deleteProperty}+ {outlineStyleValue !== "none" && (+ <>+ <PropertyLabel+ label="Color"+ description={propertyDescriptions.outlineColor}+ properties={["outlineColor"]}/>-- <OutlineOffset- currentStyle={currentStyle}- setProperty={setProperty}- deleteProperty={deleteProperty}+ <ColorControl property="outlineColor" />+ <PropertyLabel+ label="Width"+ description={propertyDescriptions.outlineWidth}+ properties={["outlineWidth"]}+ />+ <TextControl property="outlineWidth" />+ <PropertyLabel+ label="Offset"+ description={propertyDescriptions.outlineOffset}+ properties={["outlineOffset"]}/>+ <TextControl property="outlineOffset" /></>)}- </Flex>+ </Grid></StyleSection>);};