From cafba3335201d78fdf971fbcc4da1a427e2fdf65 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Thu, 5 Sep 2024 19:14:07 +0200 Subject: [PATCH] refactor: migrate outline section to style object model (#4074) Ref https://github.com/webstudio-is/webstudio/issues/1536 https://github.com/webstudio-is/webstudio/issues/3399 - refactored outline section into single module for simplicity - replaced css value input container with text control - visually aligned color input and length inputs Screenshot 2024-09-05 at 16 44 37 Screenshot 2024-09-05 at 16 44 19 --- .../sections/outline/outline-offset.tsx | 54 ---------- .../sections/outline/outline-style.tsx | 39 ------- .../sections/outline/outline-width.tsx | 47 -------- .../style-panel/sections/outline/outline.tsx | 100 ++++++++++-------- 4 files changed, 57 insertions(+), 183 deletions(-) delete mode 100644 apps/builder/app/builder/features/style-panel/sections/outline/outline-offset.tsx delete mode 100644 apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsx delete mode 100644 apps/builder/app/builder/features/style-panel/sections/outline/outline-width.tsx 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.tsx deleted file mode 100644 index 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 -) => { - 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 ( - - - - - - ); -}; 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 deleted file mode 100644 index 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 ( - - - - , value: "none" }, - { child: , value: "solid" }, - { child: , value: "dashed" }, - { child: , value: "dotted" }, - ]} - /> - - - ); -}; 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.tsx deleted file mode 100644 index 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 -) => { - 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 ( - - - - - - ); -}; 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 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; -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 ( - - - {outlineStyle.value.value !== "none" && ( + + + + , value: "none" }, + { child: , value: "solid" }, + { child: , value: "dashed" }, + { child: , value: "dotted" }, + ]} + /> + + + {outlineStyleValue !== "none" && ( <> - - - - - - - - - - + + + + )} - + ); };