Skip to content

Commit 730d73e

Browse files
committed
reusable css editor
1 parent 238e300 commit 730d73e

File tree

8 files changed

+580
-493
lines changed

8 files changed

+580
-493
lines changed

apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx

Lines changed: 22 additions & 482 deletions
Large diffs are not rendered by default.

apps/builder/app/builder/features/style-panel/sections/advanced/copy-paste-menu.tsx renamed to apps/builder/app/builder/features/style-panel/shared/css-editor/copy-paste-menu.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@ import {
1313
toValue,
1414
type StyleMap,
1515
} from "@webstudio-is/css-engine";
16-
import { useStore } from "@nanostores/react";
17-
import { $advancedStylesLonghands } from "./stores";
1816

1917
export const copyAttribute = "data-declaration";
2018

2119
export const CopyPasteMenu = ({
2220
children,
2321
properties,
22+
styleMap,
2423
onPaste,
2524
}: {
2625
children: ReactNode;
2726
properties: Array<string>;
27+
styleMap: StyleMap;
2828
onPaste: (cssText: string) => void;
2929
}) => {
30-
const advancedStylesLonghands = useStore($advancedStylesLonghands);
3130
const lastClickedProperty = useRef<string>();
3231

3332
const handlePaste = () => {
@@ -38,7 +37,7 @@ export const CopyPasteMenu = ({
3837
// We want to only copy properties that are currently in front of the user.
3938
// That includes search or any future filters.
4039
const currentStyleMap: StyleMap = new Map();
41-
for (const [property, value] of advancedStylesLonghands) {
40+
for (const [property, value] of styleMap) {
4241
const isEmpty = toValue(value) === "";
4342
if (properties.includes(property) && isEmpty === false) {
4443
currentStyleMap.set(hyphenateProperty(property), value);
@@ -55,7 +54,7 @@ export const CopyPasteMenu = ({
5554
if (property === undefined) {
5655
return;
5756
}
58-
const value = advancedStylesLonghands.get(property);
57+
const value = styleMap.get(property);
5958

6059
if (value === undefined) {
6160
return;

apps/builder/app/builder/features/style-panel/sections/advanced/advanced.stories.tsx renamed to apps/builder/app/builder/features/style-panel/shared/css-editor/css-editor.stories.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { getStyleDeclKey, type StyleDecl } from "@webstudio-is/sdk";
22
import { registerContainers } from "~/shared/sync";
3-
import { Section } from "./advanced";
3+
import { CssEditor as CssEditorComponent } from "./css-editor";
44
import {
55
$breakpoints,
66
$instances,
77
$selectedBreakpointId,
88
$styles,
99
$styleSourceSelections,
1010
} from "~/shared/nano-states";
11-
import { setProperty } from "../../shared/use-style-data";
11+
import { setProperty } from "../use-style-data";
1212
import { $awareness } from "~/shared/awareness";
1313

1414
const backgroundImage: StyleDecl = {
@@ -42,11 +42,24 @@ setProperty("accentColor")({ type: "keyword", value: "red" });
4242
setProperty("alignContent")({ type: "keyword", value: "normal" });
4343
setProperty("opacity")({ type: "unit", unit: "number", value: 11.2 });
4444

45-
export const Advanced = () => {
46-
return <Section />;
45+
export const CssEditor = () => {
46+
const styleMap = new Map([
47+
["backgroundImage", backgroundImage.value],
48+
["accentColor", { type: "keyword", value: "red" }],
49+
["alignContent", { type: "keyword", value: "normal" }],
50+
["opacity", { type: "unit", unit: "number", value: 11.2 }],
51+
]);
52+
return (
53+
<CssEditorComponent
54+
styleMap={styleMap}
55+
deleteProperty={() => undefined}
56+
setProperty={() => () => undefined}
57+
insertProperties={() => undefined}
58+
/>
59+
);
4760
};
4861

4962
export default {
50-
title: "Style Panel/Advanced",
51-
component: Advanced,
63+
title: "Style Panel",
64+
component: CssEditor,
5265
};

0 commit comments

Comments
 (0)