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.

refactor: extract layer-list component and use it inside box-shadown (#2510)

Jaya Krishna Namburu1c81b5d3b92b
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.tsx
index 222781b93a..3496c02202 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
@@ -11,7 +11,8 @@ import { getDots } from "../../shared/collapsible-section";
import { PropertyName } from "../../shared/property-name";
import { getStyleSource } from "../../shared/style-info";
import type { RenderCategoryProps } from "../../style-sections";
-import { BoxShadowLayers } from "./box-shadow-layers";
+import { LayersList } from "../../style-layers-list";
+import { Layer } from "./box-shadow-layer";
import { addLayer } from "../../style-layer-utils";
import { parseBoxShadow } from "@webstudio-is/css-data";
@@ -64,7 +65,13 @@ export const BoxShadowsSection = (props: RenderCategoryProps) => {
}
>
{value?.type === "layers" && value.value.length > 0 && (
- <BoxShadowLayers layers={value} {...props} />
+ <LayersList
+ layers={value}
+ {...props}
+ renderLayer={(layersProps) => (
+ <Layer key={layersProps.index} {...layersProps} />
+ )}
+ />
)}
</CollapsibleSectionBase>
);
diff --git a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-layers.tsx b/apps/builder/app/builder/features/style-panel/style-layers-list.tsx
similarity index 61%
rename from apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-layers.tsx
rename to apps/builder/app/builder/features/style-panel/style-layers-list.tsx
index 8e0e0b6456..6db55eacf2 100644
--- a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-layers.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-layers-list.tsx
@@ -1,31 +1,46 @@
-import type { LayersValue, StyleProperty } from "@webstudio-is/css-engine";
+import type {
+ LayersValue,
+ StyleProperty,
+ TupleValue,
+} from "@webstudio-is/css-engine";
import {
CssValueListArrowFocus,
Flex,
useSortable,
} from "@webstudio-is/design-system";
-import type { RenderCategoryProps } from "../../style-sections";
-import { Layer } from "./box-shadow-layer";
+import type { RenderCategoryProps } from "./style-sections";
import {
deleteLayer,
getLayerCount,
hideLayer,
swapLayers,
updateLayer,
-} from "../../style-layer-utils";
+} from "./style-layer-utils";
import { useMemo } from "react";
+import type { CreateBatchUpdate } from "./shared/use-style-data";
-type BoxShadowLayerProperies = RenderCategoryProps & {
+type LayerListProperties = RenderCategoryProps & {
layers: LayersValue;
+ renderLayer: (props: {
+ id: string;
+ index: number;
+ layer: TupleValue;
+ isHighlighted: boolean;
+ onLayerHide: (index: number) => void;
+ onDeleteLayer: (index: number) => void;
+ createBatchUpdate: CreateBatchUpdate;
+ onEditLayer: (index: number, newLayers: LayersValue) => void;
+ }) => JSX.Element;
};
const property: StyleProperty = "boxShadow";
-export const BoxShadowLayers = ({
+export const LayersList = ({
layers,
currentStyle,
+ renderLayer,
createBatchUpdate,
-}: BoxShadowLayerProperies) => {
+}: LayerListProperties) => {
const layersCount = getLayerCount(property, currentStyle);
const sortableItems = useMemo(
@@ -64,19 +79,16 @@ export const BoxShadowLayers = ({
return null;
}
const id = String(index);
- return (
- <Layer
- key={index}
- id={id}
- index={index}
- layer={layer}
- isHighlighted={dragItemId === id}
- onLayerHide={handleHideLayer}
- onDeleteLayer={handleDeleteLayer}
- createBatchUpdate={createBatchUpdate}
- onEditLayer={onEditLayer}
- />
- );
+ return renderLayer({
+ id,
+ index,
+ layer,
+ isHighlighted: dragItemId === id,
+ onLayerHide: handleHideLayer,
+ onDeleteLayer: handleDeleteLayer,
+ createBatchUpdate,
+ onEditLayer,
+ });
})}
{placementIndicator}
</Flex>