Skip to content

Commit 4c48c21

Browse files
authored
experimental: Advanced panel sorting and grouping (#4842)
#4816 ## Description 1. We want to group entries by origin 2. We want to sort by alphabet ## Steps for reproduction 1. click button 3. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 0eaf5c3 commit 4c48c21

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

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

+19-8
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ const AdvancedPropertyLabel = ({ property }: { property: StyleProperty }) => {
260260
const styleDecl = useComputedStyleDecl(property);
261261
const label = hyphenateProperty(property);
262262
const description = propertyDescriptions[property];
263-
const color =
264-
styleDecl.source.name === "default" ? "code" : styleDecl.source.name;
265263
const [isOpen, setIsOpen] = useState(false);
266264
return (
267265
<Tooltip
@@ -291,7 +289,13 @@ const AdvancedPropertyLabel = ({ property }: { property: StyleProperty }) => {
291289
/>
292290
}
293291
>
294-
<Label color={color} text="mono">
292+
<Label
293+
color={styleDecl.source.name}
294+
text="mono"
295+
css={{
296+
backgroundColor: "transparent",
297+
}}
298+
>
295299
{label}
296300
</Label>
297301
</Tooltip>
@@ -366,11 +370,11 @@ const AdvancedPropertyValue = ({
366370
};
367371

368372
const initialProperties = new Set<StyleProperty>([
369-
"userSelect",
370-
"pointerEvents",
371-
"mixBlendMode",
372373
"cursor",
374+
"mixBlendMode",
373375
"opacity",
376+
"pointerEvents",
377+
"userSelect",
374378
]);
375379

376380
const $advancedProperties = computed(
@@ -409,7 +413,7 @@ const $advancedProperties = computed(
409413
baseProperties.add(property);
410414
}
411415
}
412-
const advancedProperties = new Set<StyleProperty>(initialProperties);
416+
const advancedProperties = new Set<StyleProperty>();
413417
for (const { property, listed } of definedStyles) {
414418
// In advanced mode we show all defined properties
415419
if (settings.stylePanelMode === "advanced") {
@@ -421,7 +425,14 @@ const $advancedProperties = computed(
421425
advancedProperties.add(property);
422426
}
423427
}
424-
return Array.from(advancedProperties).reverse();
428+
// In advanced mode we assume user knows the properties they need, so we don't need to show these.
429+
// @todo we need to find a better place for them in any case
430+
if (settings.stylePanelMode !== "advanced") {
431+
for (const property of initialProperties) {
432+
advancedProperties.add(property);
433+
}
434+
}
435+
return Array.from(advancedProperties);
425436
}
426437
);
427438

apps/builder/app/builder/features/style-panel/shared/model.tsx

+23-10
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,22 @@ export const getDefinedStyles = ({
139139
styleSourceSelections: StyleSourceSelections;
140140
styles: Styles;
141141
}) => {
142-
const definedStyles = new Set<{
143-
property: StyleProperty;
144-
listed?: boolean;
145-
}>();
146142
const inheritedStyleSources = new Set();
147143
const instanceStyleSources = new Set();
148144
const matchingBreakpoints = new Set(matchingBreakpointsArray);
149145
const startingInstanceSelector = instancePath[0].instanceSelector;
146+
147+
type StyleDeclSubset = Pick<StyleDecl, "property" | "listed">;
148+
149+
const instanceStyles = new Set<StyleDeclSubset>();
150+
const inheritedStyles = new Set<StyleDeclSubset>();
151+
const presetStyles = new Set<StyleDeclSubset>();
152+
150153
for (const { instance } of instancePath) {
151154
const meta = metas.get(instance.component);
152-
for (const presetStyles of Object.values(meta?.presetStyle ?? {})) {
153-
for (const styleDecl of presetStyles) {
154-
definedStyles.add(styleDecl);
155+
for (const preset of Object.values(meta?.presetStyle ?? {})) {
156+
for (const styleDecl of preset) {
157+
presetStyles.add(styleDecl);
155158
}
156159
}
157160
const styleSources = styleSourceSelections.get(instance.id)?.values;
@@ -170,7 +173,7 @@ export const getDefinedStyles = ({
170173
matchingBreakpoints.has(styleDecl.breakpointId) &&
171174
instanceStyleSources.has(styleDecl.styleSourceId)
172175
) {
173-
definedStyles.add(styleDecl);
176+
instanceStyles.add(styleDecl);
174177
}
175178
const inherited =
176179
properties[styleDecl.property as keyof typeof properties]?.inherited ??
@@ -181,10 +184,20 @@ export const getDefinedStyles = ({
181184
inheritedStyleSources.has(styleDecl.styleSourceId) &&
182185
inherited
183186
) {
184-
definedStyles.add(styleDecl);
187+
inheritedStyles.add(styleDecl);
185188
}
186189
}
187-
return definedStyles;
190+
191+
// We are sorting by alphabet within each group.
192+
const sortByProperty = (a: { property: string }, b: { property: string }) => {
193+
return Intl.Collator().compare(a.property, b.property);
194+
};
195+
196+
return new Set([
197+
...Array.from(instanceStyles).sort(sortByProperty),
198+
...Array.from(inheritedStyles).sort(sortByProperty),
199+
...Array.from(presetStyles).sort(sortByProperty),
200+
]);
188201
};
189202

190203
export const $definedStyles = computed(

packages/design-system/src/components/label.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export const labelColors = [
1515
"local",
1616
"overwritten",
1717
"remote",
18-
"code",
1918
"inactive",
2019
] as const;
2120

@@ -34,7 +33,7 @@ const StyledLabel = styled(RadixLabel, {
3433
px: theme.spacing[2],
3534
border: "1px solid transparent",
3635
borderRadius: theme.borderRadius[3],
37-
transition: "200ms color, 200ms background-color",
36+
transition: "150ms color, 150ms background-color",
3837
color: theme.colors.foregroundMain,
3938

4039
// https://github.com/webstudio-is/webstudio/issues/1271#issuecomment-1478436340
@@ -91,12 +90,6 @@ const StyledLabel = styled(RadixLabel, {
9190
backgroundColor: theme.colors.backgroundRemoteHover,
9291
},
9392
},
94-
code: {
95-
color: theme.colors.foregroundLocalMain,
96-
"&:hover": {
97-
backgroundColor: theme.colors.backgroundHover,
98-
},
99-
},
10093
// Example is collapsible section title label when section has no content.
10194
inactive: {
10295
color: theme.colors.foregroundTextSubtle,

packages/design-system/src/components/nested-icon-label.tsx

-7
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ const colors = {
3838
backgroundHover: theme.colors.backgroundRemoteHover,
3939
icon: theme.colors.foregroundRemoteMain,
4040
},
41-
code: {
42-
border: "transparent",
43-
background: "transparent",
44-
backgroundHover: theme.colors.backgroundHover,
45-
icon: theme.colors.foregroundIconMain,
46-
},
4741
inactive: {
4842
border: "transparent",
4943
background: "transparent",
@@ -82,7 +76,6 @@ const style = css({
8276
local: perColorStyle("local"),
8377
overwritten: perColorStyle("overwritten"),
8478
remote: perColorStyle("remote"),
85-
code: perColorStyle("code"),
8679
inactive: perColorStyle("inactive"),
8780
},
8881
},

0 commit comments

Comments
 (0)