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: use style-layer-list for all layers based sections in style-panel (#3328)
Jaya Krishna Namburucfe222c37571
diff --git a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsxindex 1d89a74c2b..ff1febe808 100644--- a/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx@@ -30,7 +30,6 @@ const initialPropertyNames = new Set<StyleProperty>(["userSelect","pointerEvents","mixBlendMode",- "backdropFilter","cursor","opacity",]);diff --git a/apps/builder/app/builder/features/style-panel/sections/backdrop-filter/backdrop-filter.tsx b/apps/builder/app/builder/features/style-panel/sections/backdrop-filter/backdrop-filter.tsxindex 6bf2084128..54f1a78a75 100644--- a/apps/builder/app/builder/features/style-panel/sections/backdrop-filter/backdrop-filter.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/backdrop-filter/backdrop-filter.tsx@@ -1,10 +1,6 @@import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";import type { SectionProps } from "../shared/section";-import type {- FunctionValue,- StyleProperty,- TupleValue,-} from "@webstudio-is/css-engine";+import type { StyleProperty } from "@webstudio-is/css-engine";import { useState } from "react";import {SectionTitle,@@ -21,17 +17,17 @@ import { InfoCircleIcon, PlusIcon } from "@webstudio-is/icons";import { addLayer } from "../../style-layer-utils";import { parseFilter } from "@webstudio-is/css-data";import { LayersList } from "../../style-layers-list";-import { FilterLayer } from "../filter/filter-layer";+import { FilterSectionContent } from "../../shared/filter-content";export const properties = ["backdropFilter"] satisfies Array<StyleProperty>;const property: StyleProperty = properties[0];const label = "Backdrop Filters";-const INITIAL_BACKDROP_FILTER = "blur(0px)";+const initialBackdropFilter = "blur(0px)";export const Section = (props: SectionProps) => {const { currentStyle, deleteProperty } = props;- const [isOpen, setIsOpen] = useState(false);+ const [isOpen, setIsOpen] = useState(true);const value = currentStyle[property]?.value;const sectionStyleSource =value?.type === "unparsed" || value?.type === "guaranteedInvalid"@@ -54,7 +50,7 @@ export const Section = (props: SectionProps) => {onClick={() => {addLayer(property,- parseFilter(INITIAL_BACKDROP_FILTER),+ parseFilter(initialBackdropFilter),currentStyle,props.createBatchUpdate);@@ -80,39 +76,43 @@ export const Section = (props: SectionProps) => {}>{value?.type === "tuple" && value.value.length > 0 && (- <LayersList<FunctionValue, TupleValue>+ <LayersList{...props}property={property}- layers={value}- renderLayer={(layerProps) => (- <FilterLayer- {...layerProps}- key={layerProps.index}- label={label}- tooltip={- <Tooltip- variant="wrapped"- content={- <Flex gap="2" direction="column">- <Text variant="regularBold">{label}</Text>- <Text variant="monoBold">backdrop-filter</Text>- <Text>- Applies graphical effects like blur or color shift to- the area behind an element, for example:- <br />- <br />- <Text variant="monoBold">- {INITIAL_BACKDROP_FILTER}+ value={value}+ label={label}+ deleteProperty={deleteProperty}+ renderContent={(layerProps) => {+ if (layerProps.layer.type !== "function") {+ return <></>;+ }++ return (+ <FilterSectionContent+ {...layerProps}+ layer={layerProps.layer}+ tooltip={+ <Tooltip+ variant="wrapped"+ content={+ <Flex gap="2" direction="column">+ <Text variant="regularBold">{label}</Text>+ <Text variant="monoBold">filter</Text>+ <Text>+ Applies graphical effects like blur or color shift to+ the area behind an element+ <br /> <br />+ <Text variant="mono">{initialBackdropFilter}</Text></Text>- </Text>- </Flex>- }- >- <InfoCircleIcon />- </Tooltip>- }- />- )}+ </Flex>+ }+ >+ <InfoCircleIcon />+ </Tooltip>+ }+ />+ );+ }}/>)}</CollapsibleSectionRoot>diff --git a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsxindex ce7456dde8..ddb9b68094 100644--- a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx@@ -6,11 +6,7 @@ import {Text,} from "@webstudio-is/design-system";import { InfoCircleIcon, PlusIcon } from "@webstudio-is/icons";-import type {- LayersValue,- StyleProperty,- TupleValue,-} from "@webstudio-is/css-engine";+import type { StyleProperty } from "@webstudio-is/css-engine";import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";import { useState } from "react";import { getDots } from "../../shared/collapsible-section";@@ -20,13 +16,13 @@ import type { SectionProps } from "../shared/section";import { LayersList } from "../../style-layers-list";import { addLayer } from "../../style-layer-utils";import { parseShadow } from "@webstudio-is/css-data";-import { ShadowLayer } from "../../shared/shadow-layer";+import { ShadowContent } from "../../shared/shadow-content";export const properties = ["boxShadow"] satisfies Array<StyleProperty>;const property: StyleProperty = properties[0];const label = "Box Shadows";-const INITIAL_BOX_SHADOW = "0px 2px 5px 0px rgba(0, 0, 0, 0.2)";+const initialBoxShadow = "0px 2px 5px 0px rgba(0, 0, 0, 0.2)";export const Section = (props: SectionProps) => {const { currentStyle, deleteProperty } = props;@@ -45,14 +41,14 @@ export const Section = (props: SectionProps) => {onOpenChange={setIsOpen}trigger={<SectionTitle- dots={getDots(currentStyle, [property])}+ dots={getDots(currentStyle, properties)}suffix={<SectionTitleButtonprefix={<PlusIcon />}onClick={() => {addLayer(property,- parseShadow("boxShadow", INITIAL_BOX_SHADOW),+ parseShadow(property, initialBoxShadow),currentStyle,props.createBatchUpdate);@@ -77,16 +73,21 @@ export const Section = (props: SectionProps) => {}>{value?.type === "layers" && value.value.length > 0 && (- <LayersList<TupleValue, LayersValue>- property={property}- layers={value}+ <LayersList{...props}- renderLayer={(layersProps) => {+ property={property}+ value={value}+ label={label}+ deleteProperty={deleteProperty}+ renderContent={(layerProps) => {+ if (layerProps.layer.type !== "tuple") {+ return <></>;+ }+return (- <ShadowLayer- key={layersProps.index}- {...layersProps}- label={label}+ <ShadowContent+ {...layerProps}+ layer={layerProps.layer}tooltip={<Tooltipvariant="wrapped"@@ -94,9 +95,8 @@ export const Section = (props: SectionProps) => {<Text>Paste a box-shadow CSS code without the property name,for example:- <br />- <br />- <Text variant="monoBold">{INITIAL_BOX_SHADOW}</Text>+ <br /> <br />+ <Text variant="monoBold">{initialBoxShadow}</Text></Text>}>diff --git a/apps/builder/app/builder/features/style-panel/sections/filter/filter-layer.tsx b/apps/builder/app/builder/features/style-panel/sections/filter/filter-layer.tsxdeleted file mode 100644index 2601398bab..0000000000--- a/apps/builder/app/builder/features/style-panel/sections/filter/filter-layer.tsx+++ /dev/null@@ -1,50 +0,0 @@-import { FloatingPanel } from "~/builder/shared/floating-panel";-import type { LayerProps } from "../../style-layers-list";-import { FilterSectionContent } from "./filter-content";-import {- CssValueListItem,- Label,- SmallIconButton,-} from "@webstudio-is/design-system";-import { SubtractIcon } from "@webstudio-is/icons";-import { useMemo } from "react";-import { FunctionValue, toValue } from "@webstudio-is/css-engine";--export const FilterLayer = <T extends FunctionValue>(props: LayerProps<T>) => {- const { index, id, layer, isHighlighted, onDeleteLayer, label } = props;- const filter = useMemo(() => toValue(layer), [layer]);-- return (- <FloatingPanel- title={label}- content={- <FilterSectionContent- property={props.property}- index={index}- filter={filter}- onEditLayer={props.onEditLayer}- deleteProperty={props.deleteProperty}- tooltip={props.tooltip}- />- }- >- <CssValueListItem- id={id}- draggable={true}- active={isHighlighted}- index={index}- label={<Label truncate>{filter}</Label>}- buttons={- <>- <SmallIconButton- variant="destructive"- tabIndex={-1}- icon={<SubtractIcon />}- onClick={() => onDeleteLayer(index)}- />- </>- }- />- </FloatingPanel>- );-};diff --git a/apps/builder/app/builder/features/style-panel/sections/filter/filter.tsx b/apps/builder/app/builder/features/style-panel/sections/filter/filter.tsxindex 97a4dd233b..2d79f63d1c 100644--- a/apps/builder/app/builder/features/style-panel/sections/filter/filter.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/filter/filter.tsx@@ -12,22 +12,18 @@ import {import { getDots } from "../../shared/collapsible-section";import { PropertyName } from "../../shared/property-name";import { InfoCircleIcon, PlusIcon } from "@webstudio-is/icons";-import {- FunctionValue,- TupleValue,- type StyleProperty,-} from "@webstudio-is/css-engine";+import { type StyleProperty } from "@webstudio-is/css-engine";import { getStyleSource } from "../../shared/style-info";import { LayersList } from "../../style-layers-list";-import { FilterLayer } from "./filter-layer";import { addLayer } from "../../style-layer-utils";import { parseFilter } from "@webstudio-is/css-data";+import { FilterSectionContent } from "../../shared/filter-content";export const properties = ["filter"] satisfies Array<StyleProperty>;const property: StyleProperty = properties[0];const label = "Filters";-const INITIAL_FILTER = "blur(0px)";+const initialFilter = "blur(0px)";export const Section = (props: SectionProps) => {const { currentStyle, deleteProperty } = props;@@ -54,7 +50,7 @@ export const Section = (props: SectionProps) => {onClick={() => {addLayer(property,- parseFilter(INITIAL_FILTER),+ parseFilter(initialFilter),currentStyle,props.createBatchUpdate);@@ -80,37 +76,43 @@ export const Section = (props: SectionProps) => {}>{value?.type === "tuple" && value.value.length > 0 && (- <LayersList<FunctionValue, TupleValue>+ <LayersList{...props}property={property}- layers={value}- renderLayer={(layerProps) => (- <FilterLayer- {...layerProps}- key={layerProps.index}- label={label}- tooltip={- <Tooltip- variant="wrapped"- content={- <Flex gap="2" direction="column">- <Text variant="regularBold">{label}</Text>- <Text variant="monoBold">filter</Text>- <Text>- Applies graphical effects like blur or color shift to an- element, for example:- <br />- <br />- <Text variant="monoBold">{INITIAL_FILTER}</Text>- </Text>- </Flex>- }- >- <InfoCircleIcon />- </Tooltip>- }- />- )}+ value={value}+ label={label}+ deleteProperty={deleteProperty}+ renderContent={(layerProps) => {+ if (layerProps.layer.type !== "function") {+ return <></>;+ }++ return (+ <FilterSectionContent+ {...layerProps}+ layer={layerProps.layer}+ tooltip={+ <Tooltip+ variant="wrapped"+ content={+ <Flex gap="2" direction="column">+ <Text variant="regularBold">{label}</Text>+ <Text variant="monoBold">filter</Text>+ <Text>+ Applies graphical effects like blur or color shift to+ an element, for example:+ <br /> <br />+ <Text variant="mono">{initialFilter}</Text>+ </Text>+ </Flex>+ }+ >+ <InfoCircleIcon />+ </Tooltip>+ }+ />+ );+ }}/>)}</CollapsibleSectionRoot>diff --git a/apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.tsx b/apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.tsxindex 80868f201c..b3fe0c9b7c 100644--- a/apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.tsx@@ -1,10 +1,6 @@import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";import type { SectionProps } from "../shared/section";-import type {- LayersValue,- StyleProperty,- TupleValue,-} from "@webstudio-is/css-engine";+import type { StyleProperty } from "@webstudio-is/css-engine";import { useState } from "react";import {SectionTitle,@@ -20,17 +16,17 @@ import { getDots } from "../../shared/collapsible-section";import { PropertyName } from "../../shared/property-name";import { getStyleSource } from "../../shared/style-info";import { LayersList } from "../../style-layers-list";-import { ShadowLayer } from "../../shared/shadow-layer";+import { ShadowContent } from "../../shared/shadow-content";export const properties = ["textShadow"] satisfies Array<StyleProperty>;const property: StyleProperty = properties[0];const label = "Text Shadows";-const INITIAL_TEXT_SHADOW = "0px 2px 5px rgba(0, 0, 0, 0.2)";+const initialTextShadow = "0px 2px 5px rgba(0, 0, 0, 0.2)";export const Section = (props: SectionProps) => {const { currentStyle, createBatchUpdate, deleteProperty } = props;- const [isOpen, setIsOpen] = useState(false);+ const [isOpen, setIsOpen] = useState(true);const value = currentStyle[property]?.value;const sectionStyleSource =value?.type === "unparsed" || value?.type === "guaranteedInvalid"@@ -52,7 +48,7 @@ export const Section = (props: SectionProps) => {onClick={() => {addLayer(property,- parseShadow("textShadow", INITIAL_TEXT_SHADOW),+ parseShadow(property, initialTextShadow),currentStyle,createBatchUpdate);@@ -77,33 +73,39 @@ export const Section = (props: SectionProps) => {}>{value?.type === "layers" && value.value.length > 0 && (- <LayersList<TupleValue, LayersValue>- property={property}- layers={value}+ <LayersList{...props}- renderLayer={(layersProps) => (- <ShadowLayer- {...layersProps}- key={layersProps.index}- label={label}- tooltip={- <Tooltip- variant="wrapped"- content={- <Text>- Paste a text-shadow CSS code without the property name,- for example:- <br />- <br />- <Text variant="monoBold">{INITIAL_TEXT_SHADOW}</Text>- </Text>- }- >- <InfoCircleIcon />- </Tooltip>- }- />- )}+ property={property}+ value={value}+ label={label}+ deleteProperty={deleteProperty}+ renderContent={(layerProps) => {+ if (layerProps.layer.type !== "tuple") {+ return <></>;+ }++ return (+ <ShadowContent+ {...layerProps}+ layer={layerProps.layer}+ tooltip={+ <Tooltip+ variant="wrapped"+ content={+ <Text>+ Paste a text-shadow CSS code without the property name,+ for example:+ <br /> <br />+ <Text variant="monoBold">{initialTextShadow}</Text>+ </Text>+ }+ >+ <InfoCircleIcon />+ </Tooltip>+ }+ />+ );+ }}/>)}</CollapsibleSectionRoot>diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsxindex cc6074b8ac..f089356f60 100644--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx@@ -6,6 +6,7 @@ import {type TupleValue,KeywordValue,UnitValue,+ type StyleProperty,} from "@webstudio-is/css-engine";import {Flex,@@ -23,7 +24,6 @@ import {parseTransition,type ExtractedTransitionProperties,} from "@webstudio-is/css-data";-import { InfoCircleIcon } from "@webstudio-is/icons";import type {DeleteProperty,StyleUpdateOptions,@@ -35,22 +35,26 @@ import { CssValueInputContainer } from "../../shared/css-value-input";type TransitionContentProps = {index: number;+ property: StyleProperty;layer: TupleValue;- transition: string;+ propertyValue: string;+ tooltip: JSX.Element;onEditLayer: (index: number, layer: LayersValue) => void;deleteProperty: DeleteProperty;};export const TransitionContent = ({layer,- transition,- onEditLayer,index,+ tooltip,+ property: transitionPropertyKey,+ onEditLayer,+ propertyValue,deleteProperty,}: TransitionContentProps) => {const [intermediateValue, setIntermediateValue] = useState<IntermediateStyleValue | InvalidValue | undefined- >({ type: "intermediate", value: transition });+ >({ type: "intermediate", value: propertyValue });const { property, timing, delay, duration } =useMemo<ExtractedTransitionProperties>(@@ -212,20 +216,7 @@ export const TransitionContent = ({<Label><Flex align="center" gap="1">Code- <Tooltip- variant="wrapped"- content={- <Text>- Paste CSS code for a transition or part of a transition, for- example:- <br />- <br />- <Text variant="monoBold">opacity 200ms ease</Text>- </Text>- }- >- <InfoCircleIcon />- </Tooltip>+ {tooltip}</Flex></Label><TextArea@@ -249,7 +240,7 @@ export const TransitionContent = ({return;}- deleteProperty("transition", { isEphemeral: true });+ deleteProperty(transitionPropertyKey, { isEphemeral: true });setIntermediateValue(undefined);event.preventDefault();}diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-layer.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-layer.tsxdeleted file mode 100644index 15477f1fdb..0000000000--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-layer.tsx+++ /dev/null@@ -1,76 +0,0 @@-import { useMemo } from "react";-import {- CssValueListItem,- Label,- SmallIconButton,-} from "@webstudio-is/design-system";-import { SubtractIcon } from "@webstudio-is/icons";-import { FloatingPanel } from "~/builder/shared/floating-panel";-import { TransitionContent } from "./transition-content";-import type { LayerProps } from "../../style-layers-list";-import { TupleValue, toValue } from "@webstudio-is/css-engine";-import { findTimingFunctionFromValue } from "./transition-utils";--const useLayer = (layer: TupleValue) => {- return useMemo(() => {- const label: TupleValue = {- type: "tuple",- value: [],- };-- for (const prop of layer.value) {- if (prop.type === "keyword") {- label.value.push({- type: "keyword",- value: findTimingFunctionFromValue(prop.value) ?? prop.value,- });- } else {- label.value.push(prop);- }- }-- return { transition: toValue(layer), label: toValue(label) };- }, [layer]);-};--export const TransitionLayer = <T extends TupleValue>(props: LayerProps<T>) => {- const { id, index, layer, isHighlighted, onDeleteLayer, disabled } = props;- const properties = useLayer(layer);-- const { transition, label } = properties;-- return (- <FloatingPanel- title="Transition"- content={- <TransitionContent- index={index}- layer={layer}- transition={transition}- onEditLayer={props.onEditLayer}- deleteProperty={props.deleteProperty}- />- }- >- <CssValueListItem- id={id}- draggable- active={isHighlighted}- index={index}- label={<Label truncate>{label}</Label>}- hidden={disabled ?? layer?.hidden}- buttons={- <>- <SmallIconButton- variant="destructive"- tabIndex={-1}- disabled={disabled || layer?.hidden}- icon={<SubtractIcon />}- onClick={() => onDeleteLayer(index)}- />- </>- }- ></CssValueListItem>- </FloatingPanel>- );-};diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsxindex 6446ab9ae1..da9e3cab22 100644--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx@@ -128,6 +128,7 @@ export const TransitionProperty = ({<><Flex align="center"><Tooltip+ variant="wrapped"content={<Flex gap="2" direction="column"><Text variant="regularBold">Property</Text>@@ -135,9 +136,7 @@ export const TransitionProperty = ({transition-property</Text><Text>- Sets the CSS properties that will- <br />- be affected by the transition.+ Sets the CSS properties that will be affected by the transition.</Text></Flex>}diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-timing.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-timing.tsxindex b9dfd4ade7..7a10df0d18 100644--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-timing.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-timing.tsx@@ -47,6 +47,7 @@ export const TransitionTiming = ({<><Flex align="center"><Tooltip+ variant="wrapped"content={<Flex gap="2" direction="column"><Text variant="regularBold">Easing</Text>@@ -54,13 +55,8 @@ export const TransitionTiming = ({transition-timing-function</Text><Text>- Affects the look and feel of the- <br />- animation by varying the speed- <br />- of the transition at different- <br />- points in its duration.+ Affects the look and feel of the animation by varying the speed+ of the transition at different points in its duration.</Text></Flex>}diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsxindex 991f572b76..0fd4cec926 100644--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx@@ -1,8 +1,4 @@-import type {- LayersValue,- StyleProperty,- TupleValue,-} from "@webstudio-is/css-engine";+import type { StyleProperty } from "@webstudio-is/css-engine";import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";import type { SectionProps } from "../shared/section";import {@@ -10,24 +6,25 @@ import {SectionTitleButton,SectionTitleLabel,Tooltip,+ Text,} from "@webstudio-is/design-system";import { useState } from "react";import { getDots } from "../../shared/collapsible-section";import { getStyleSource } from "../../shared/style-info";-import { PlusIcon } from "@webstudio-is/icons";+import { InfoCircleIcon, PlusIcon } from "@webstudio-is/icons";import { PropertyName } from "../../shared/property-name";import { addLayer } from "../../style-layer-utils";import { parseTransition } from "@webstudio-is/css-data";import { LayersList } from "../../style-layers-list";-import { TransitionLayer } from "./transition-layer";import { $selectedOrLastStyleSourceSelector } from "~/shared/nano-states";import { useStore } from "@nanostores/react";+import { TransitionContent } from "./transition-content";export const properties = ["transition"] satisfies Array<StyleProperty>;const property: StyleProperty = properties[0];const label = "Transitions";-const INITIAL_TRANSITION = "opacity 200ms ease";+const initialTransition = "opacity 200ms ease";export const Section = (props: SectionProps) => {const { currentStyle, deleteProperty } = props;@@ -69,7 +66,7 @@ export const Section = (props: SectionProps) => {onClick={() => {addLayer(property,- parseTransition(INITIAL_TRANSITION),+ parseTransition(initialTransition),currentStyle,props.createBatchUpdate);@@ -95,17 +92,37 @@ export const Section = (props: SectionProps) => {}>{value?.type === "layers" && value.value.length > 0 && (- <LayersList<TupleValue, LayersValue>- property={property}- layers={value}+ <LayersList{...props}- renderLayer={(layerProps) => {+ property={property}+ value={value}+ label={label}+ deleteProperty={deleteProperty}+ renderContent={(layerProps) => {+ if (layerProps.layer.type !== "tuple") {+ return <></>;+ }+return (- <TransitionLayer+ <TransitionContent{...layerProps}- key={layerProps.index}layer={layerProps.layer}- disabled={isStyleInLocalState === false}+ tooltip={+ <Tooltip+ variant="wrapped"+ content={+ <Text>+ Paste CSS code for a transition or part of a transition,+ for example:+ <br />+ <br />+ <Text variant="monoBold">{initialTransition}</Text>+ </Text>+ }+ >+ <InfoCircleIcon />+ </Tooltip>+ }/>);}}diff --git a/apps/builder/app/builder/features/style-panel/sections/filter/filter-content.tsx b/apps/builder/app/builder/features/style-panel/shared/filter-content.tsxsimilarity index 88%rename from apps/builder/app/builder/features/style-panel/sections/filter/filter-content.tsxrename to apps/builder/app/builder/features/style-panel/shared/filter-content.tsxindex 42e683decd..462b98cb4d 100644--- a/apps/builder/app/builder/features/style-panel/sections/filter/filter-content.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/filter-content.tsx@@ -1,6 +1,6 @@import type {+ FunctionValue,InvalidValue,- LayersValue,StyleProperty,TupleValue,} from "@webstudio-is/css-engine";@@ -12,23 +12,24 @@ import {textVariants,} from "@webstudio-is/design-system";import { useState } from "react";-import type { IntermediateStyleValue } from "../../shared/css-value-input";+import type { IntermediateStyleValue } from "../shared/css-value-input";import { parseFilter } from "@webstudio-is/css-data";-import type { DeleteProperty } from "../../shared/use-style-data";+import type { DeleteProperty } from "../shared/use-style-data";type FilterContentProps = {index: number;- filter: string;property: StyleProperty;- onEditLayer: (index: number, layers: LayersValue | TupleValue) => void;- deleteProperty: DeleteProperty;+ layer: FunctionValue;+ propertyValue: string;tooltip: JSX.Element;+ onEditLayer: (index: number, layers: TupleValue) => void;+ deleteProperty: DeleteProperty;};export const FilterSectionContent = ({index,- filter,property,+ propertyValue,onEditLayer,deleteProperty,tooltip,@@ -86,7 +87,7 @@ export const FilterSectionContent = ({<TextArearows={3}name="description"- value={intermediateValue?.value ?? filter ?? ""}+ value={intermediateValue?.value ?? propertyValue ?? ""}css={{ minHeight: theme.spacing[14], ...textVariants.mono }}state={intermediateValue?.type === "invalid" ? "invalid" : undefined}onChange={handleChange}diff --git a/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx b/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsxindex 0794d9187c..951b2eadeb 100644--- a/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx+++ b/apps/builder/app/builder/features/style-panel/shared/shadow-content.tsx@@ -60,9 +60,9 @@ import type { DeleteProperty, SetProperty } from "../shared/use-style-data";type ShadowContentProps = {index: number;- layer: TupleValue;property: StyleProperty;- shadow: string;+ layer: TupleValue;+ propertyValue: string;tooltip: JSX.Element;onEditLayer: (index: number, layers: LayersValue) => void;deleteProperty: DeleteProperty;@@ -89,8 +89,8 @@ export const ShadowContent = ({layer,index,property,+ propertyValue,tooltip,- shadow,onEditLayer,deleteProperty,}: ShadowContentProps) => {@@ -98,9 +98,10 @@ export const ShadowContent = ({IntermediateStyleValue | InvalidValue | undefined>();const layerValues = useMemo<ExtractedShadowProperties>(() => {- setIntermediateValue({ type: "intermediate", value: shadow });+ setIntermediateValue({ type: "intermediate", value: propertyValue });return extractShadowProperties(layer);- }, [layer, shadow]);+ }, [layer, propertyValue]);+const { offsetX, offsetY, blur, spread, color, inset } = layerValues;const colorControlProp = color ?? {type: "rgb",@@ -315,11 +316,7 @@ export const ShadowContent = ({<Flex gap="2" direction="column"><Text variant="regularBold">Color</Text><Text variant="monoBold">color</Text>- <Text>- Sets the shadow color and- <br />- opacity.- </Text>+ <Text>Sets the shadow color and opacity.</Text></Flex>}>@@ -403,7 +400,7 @@ export const ShadowContent = ({<TextArearows={3}name="description"- value={intermediateValue?.value ?? shadow ?? ""}+ value={intermediateValue?.value ?? propertyValue ?? ""}css={{ minHeight: theme.spacing[14], ...textVariants.mono }}state={intermediateValue?.type === "invalid" ? "invalid" : undefined}onChange={handleChange}diff --git a/apps/builder/app/builder/features/style-panel/shared/shadow-layer.tsx b/apps/builder/app/builder/features/style-panel/shared/shadow-layer.tsxdeleted file mode 100644index 57e2f31e42..0000000000--- a/apps/builder/app/builder/features/style-panel/shared/shadow-layer.tsx+++ /dev/null@@ -1,112 +0,0 @@-import type { TupleValue } from "@webstudio-is/css-engine";-import {- Label,- SmallIconButton,- SmallToggleButton,- CssValueListItem,-} from "@webstudio-is/design-system";-import {- EyeconClosedIcon,- EyeconOpenIcon,- SubtractIcon,-} from "@webstudio-is/icons";-import { useMemo } from "react";-import { FloatingPanel } from "~/builder/shared/floating-panel";-import { colord, type RgbaColor } from "colord";-import { toValue } from "@webstudio-is/css-engine";-import { ColorThumb } from "../shared/color-thumb";-import type { LayerProps } from "../style-layers-list";-import { ShadowContent } from "./shadow-content";--const useLayer = (layer: TupleValue) => {- return useMemo(() => {- const name = [];- const shadow = [];- let color: RgbaColor | undefined;- for (const item of Object.values(layer.value)) {- if (item.type === "unit") {- const value = toValue(item);- name.push(value);- shadow.push(value);- }-- if (item.type === "rgb") {- color = colord(toValue(item)).toRgb();- shadow.push(toValue(item));- }-- if (item.type === "keyword") {- if (colord(item.value).isValid() === false) {- name.push(item.value);- } else {- color = colord(item.value).toRgb();- }- shadow.push(item.value);- }- }-- return { name: name.join(" "), shadow: shadow.join(" "), color };- }, [layer]);-};--export const ShadowLayer = <T extends TupleValue>(props: LayerProps<T>) => {- const {- index,- id,- layer,- isHighlighted,- onDeleteLayer,- onLayerHide,- label,- tooltip,- property,- } = props;- const properties = useLayer(layer);- const { name, shadow, color } = properties;-- return (- <FloatingPanel- title={label}- content={- <ShadowContent- index={index}- property={property}- shadow={shadow}- layer={layer}- tooltip={tooltip}- onEditLayer={props.onEditLayer}- deleteProperty={props.deleteProperty}- />- }- >- <CssValueListItem- id={id}- draggable={true}- active={isHighlighted}- index={index}- label={<Label truncate>{name}</Label>}- hidden={layer?.hidden}- thumbnail={<ColorThumb color={color} />}- buttons={- <>- <SmallToggleButton- variant="normal"- pressed={layer?.hidden}- disabled={false}- tabIndex={-1}- onPressedChange={() => onLayerHide(index)}- icon={layer?.hidden ? <EyeconClosedIcon /> : <EyeconOpenIcon />}- />- <SmallIconButton- variant="destructive"- tabIndex={-1}- disabled={layer.hidden}- icon={<SubtractIcon />}- onClick={() => onDeleteLayer(index)}- />- </>- }- />- </FloatingPanel>- );-};diff --git a/apps/builder/app/builder/features/style-panel/style-layer-utils.ts b/apps/builder/app/builder/features/style-panel/style-layer-utils.tsindex 58d3ebe900..1829c6e9bf 100644--- a/apps/builder/app/builder/features/style-panel/style-layer-utils.ts+++ b/apps/builder/app/builder/features/style-panel/style-layer-utils.ts@@ -77,16 +77,13 @@ export const addLayer = <T extends LayersValue | TupleValue>(}const existingValues = style[property]?.value;- // Transitions come's with a default property of tuple. Which needs to be overwritten- // Because, we handle transitions using layers in the project. So, we merge the values- // only if the existing value is a layer or the value is overwritten a layer is created.- if (- (property === "transition" || property === "boxShadow") &&- existingValues?.type === "layers"- ) {+ if (existingValues?.type === "layers") {value.value = [...value.value, ...existingValues.value] as T["value"];}+ // Transitions come's with a default property of tuple. Which needs to be overwritten+ // Because, we handle transitions, box-shadow and text-shadows etc using layers in the project.+ // So, we merge the values of the new layer with the existing layer is tuple and the property is filter or backdropFilterif ((property === "filter" || property === "backdropFilter") &&existingValues?.type === "tuple"diff --git a/apps/builder/app/builder/features/style-panel/style-layers-list.tsx b/apps/builder/app/builder/features/style-panel/style-layers-list.tsxindex 05f09310c7..e35b827c47 100644--- a/apps/builder/app/builder/features/style-panel/style-layers-list.tsx+++ b/apps/builder/app/builder/features/style-panel/style-layers-list.tsx@@ -1,11 +1,17 @@-import type {- LayersValue,- StyleProperty,- TupleValue,+import {+ toValue,+ type FunctionValue,+ type LayersValue,+ type StyleProperty,+ type TupleValue,} from "@webstudio-is/css-engine";import {CssValueListArrowFocus,+ CssValueListItem,Flex,+ Label,+ SmallIconButton,+ SmallToggleButton,useSortable,} from "@webstudio-is/design-system";import type { SectionProps } from "./sections";@@ -17,46 +23,74 @@ import {updateLayer,} from "./style-layer-utils";import { useMemo } from "react";-import type {- CreateBatchUpdate,- DeleteProperty,-} from "./shared/use-style-data";+import type { DeleteProperty } from "./shared/use-style-data";+import { FloatingPanel } from "~/builder/shared/floating-panel";+import {+ EyeconClosedIcon,+ EyeconOpenIcon,+ SubtractIcon,+} from "@webstudio-is/icons";+import { ColorThumb } from "./shared/color-thumb";+import { colord, type RgbaColor } from "colord";-export type LayerProps<LayerType> = {- id: string;- index: number;- property: StyleProperty;- layer: LayerType;- label: string;- tooltip: JSX.Element;- isHighlighted: boolean;+type LayerListProps = SectionProps & {disabled?: boolean;- onLayerHide: (index: number) => void;- onDeleteLayer: (index: number) => void;- onEditLayer: (index: number, layers: LayersValue | TupleValue) => void;- createBatchUpdate: CreateBatchUpdate;- deleteProperty: DeleteProperty;+ label: string;+ property: StyleProperty;+ value: TupleValue | LayersValue;+ renderContent: (props: {+ index: number;+ layer: TupleValue | FunctionValue;+ property: StyleProperty;+ propertyValue: string;+ onDeleteLayer: (index: number) => void;+ onEditLayer: (index: number, layers: TupleValue | LayersValue) => void;+ deleteProperty: DeleteProperty;+ }) => JSX.Element;};-type LayerListProperties<LayerType, PropertyValueType> = SectionProps & {- disabled?: boolean;- property: StyleProperty;- layers: PropertyValueType;- renderLayer: (props: LayerProps<LayerType>) => JSX.Element;+const extractPropertiesFromLayer = (layer: TupleValue | FunctionValue) => {+ if (layer.type === "function") {+ return { name: toValue(layer), value: toValue(layer), color: undefined };+ }++ const name = [];+ const shadow = [];+ let color: RgbaColor | undefined;+ for (const item of Object.values(layer.value)) {+ if (item.type === "unit") {+ const value = toValue(item);+ name.push(value);+ shadow.push(value);+ }++ if (item.type === "rgb") {+ color = colord(toValue(item)).toRgb();+ shadow.push(toValue(item));+ }++ if (item.type === "keyword") {+ if (colord(item.value).isValid() === false) {+ name.push(item.value);+ } else {+ color = colord(item.value).toRgb();+ }+ shadow.push(item.value);+ }+ }++ return { name: name.join(" "), value: shadow.join(" "), color };};-export const LayersList = <- LayerType,- PropertyValueType extends TupleValue | LayersValue,->({+export const LayersList = ({+ label,property,- layers,- disabled,+ value,currentStyle,- renderLayer,createBatchUpdate,+ renderContent,deleteProperty,-}: LayerListProperties<LayerType, PropertyValueType>) => {+}: LayerListProps) => {const layersCount = getLayerCount(property, currentStyle);const sortableItems = useMemo(@@ -76,47 +110,87 @@ export const LayersList = <});const handleDeleteLayer = (index: number) => {- return deleteLayer(property, index, layers, createBatchUpdate);+ return deleteLayer(property, index, value, createBatchUpdate);};const handleHideLayer = (index: number) => {- if (layers.type === "tuple") {+ if (value.type === "tuple") {return;}- return hideLayer(property, index, layers, createBatchUpdate);+ return hideLayer(property, index, value, createBatchUpdate);};- const onEditLayer = (index: number, newLayers: PropertyValueType) => {- return updateLayer<PropertyValueType>(- property,- newLayers,- layers,- index,- createBatchUpdate- );+ const onEditLayer = (index: number, newLayers: TupleValue | LayersValue) => {+ return updateLayer(property, newLayers, value, index, createBatchUpdate);};return (<CssValueListArrowFocus dragItemId={dragItemId}><Flex direction="column" ref={sortableRefCallback}>- {layers.value.map((layer, index) => {+ {value.value.map((layer, index) => {if (layer.type !== "tuple" && layer.type !== "function") {- return null;+ return;}const id = String(index);- return renderLayer({- id,- index,- layer,- disabled,- property,- isHighlighted: dragItemId === id,- onLayerHide: handleHideLayer,- onDeleteLayer: handleDeleteLayer,- createBatchUpdate,- deleteProperty,- onEditLayer,- } as LayerProps<LayerType>);+ const properties = extractPropertiesFromLayer(layer);+ const { name, value, color } = properties;++ return (+ <FloatingPanel+ key={index}+ title={label}+ content={renderContent({+ index,+ property,+ layer,+ onEditLayer,+ propertyValue: value,+ onDeleteLayer: handleDeleteLayer,+ deleteProperty,+ })}+ >+ <CssValueListItem+ id={id}+ draggable={true}+ active={dragItemId === id}+ index={index}+ label={<Label truncate>{name}</Label>}+ hidden={layer.type === "tuple" && layer?.hidden}+ thumbnail={+ property === "textShadow" || property === "boxShadow" ? (+ <ColorThumb color={color} />+ ) : undefined+ }+ buttons={+ <>+ {layer.type === "tuple" ? (+ <SmallToggleButton+ variant="normal"+ pressed={layer?.hidden}+ disabled={false}+ tabIndex={-1}+ onPressedChange={() => handleHideLayer(index)}+ icon={+ layer?.hidden ? (+ <EyeconClosedIcon />+ ) : (+ <EyeconOpenIcon />+ )+ }+ />+ ) : undefined}+ <SmallIconButton+ variant="destructive"+ tabIndex={-1}+ disabled={layer.type === "tuple" && layer.hidden}+ icon={<SubtractIcon />}+ onClick={() => handleDeleteLayer(index)}+ />+ </>+ }+ />+ </FloatingPanel>+ );})}{placementIndicator}</Flex>