Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental: Advanced panel sorting and grouping #4842

Merged
merged 4 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ const AdvancedPropertyLabel = ({ property }: { property: StyleProperty }) => {
const styleDecl = useComputedStyleDecl(property);
const label = hyphenateProperty(property);
const description = propertyDescriptions[property];
const color =
styleDecl.source.name === "default" ? "code" : styleDecl.source.name;
const [isOpen, setIsOpen] = useState(false);
return (
<Tooltip
Expand Down Expand Up @@ -291,7 +289,13 @@ const AdvancedPropertyLabel = ({ property }: { property: StyleProperty }) => {
/>
}
>
<Label color={color} text="mono">
<Label
color={styleDecl.source.name}
text="mono"
css={{
backgroundColor: "transparent",
}}
>
{label}
</Label>
</Tooltip>
Expand Down Expand Up @@ -366,11 +370,11 @@ const AdvancedPropertyValue = ({
};

const initialProperties = new Set<StyleProperty>([
"userSelect",
"pointerEvents",
"mixBlendMode",
"cursor",
"mixBlendMode",
"opacity",
"pointerEvents",
"userSelect",
]);

const $advancedProperties = computed(
Expand Down Expand Up @@ -409,7 +413,7 @@ const $advancedProperties = computed(
baseProperties.add(property);
}
}
const advancedProperties = new Set<StyleProperty>(initialProperties);
const advancedProperties = new Set<StyleProperty>();
for (const { property, listed } of definedStyles) {
// In advanced mode we show all defined properties
if (settings.stylePanelMode === "advanced") {
Expand All @@ -421,7 +425,14 @@ const $advancedProperties = computed(
advancedProperties.add(property);
}
}
return Array.from(advancedProperties).reverse();
// In advanced mode we assume user knows the properties they need, so we don't need to show these.
// @todo we need to find a better place for them in any case
if (settings.stylePanelMode !== "advanced") {
for (const property of initialProperties) {
advancedProperties.add(property);
}
}
return Array.from(advancedProperties);
}
);

Expand Down
33 changes: 23 additions & 10 deletions apps/builder/app/builder/features/style-panel/shared/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,22 @@ export const getDefinedStyles = ({
styleSourceSelections: StyleSourceSelections;
styles: Styles;
}) => {
const definedStyles = new Set<{
property: StyleProperty;
listed?: boolean;
}>();
const inheritedStyleSources = new Set();
const instanceStyleSources = new Set();
const matchingBreakpoints = new Set(matchingBreakpointsArray);
const startingInstanceSelector = instancePath[0].instanceSelector;

type StyleDeclSubset = Pick<StyleDecl, "property" | "listed">;

const instanceStyles = new Set<StyleDeclSubset>();
const inheritedStyles = new Set<StyleDeclSubset>();
const presetStyles = new Set<StyleDeclSubset>();

for (const { instance } of instancePath) {
const meta = metas.get(instance.component);
for (const presetStyles of Object.values(meta?.presetStyle ?? {})) {
for (const styleDecl of presetStyles) {
definedStyles.add(styleDecl);
for (const preset of Object.values(meta?.presetStyle ?? {})) {
for (const styleDecl of preset) {
presetStyles.add(styleDecl);
}
}
const styleSources = styleSourceSelections.get(instance.id)?.values;
Expand All @@ -170,7 +173,7 @@ export const getDefinedStyles = ({
matchingBreakpoints.has(styleDecl.breakpointId) &&
instanceStyleSources.has(styleDecl.styleSourceId)
) {
definedStyles.add(styleDecl);
instanceStyles.add(styleDecl);
}
const inherited =
properties[styleDecl.property as keyof typeof properties]?.inherited ??
Expand All @@ -181,10 +184,20 @@ export const getDefinedStyles = ({
inheritedStyleSources.has(styleDecl.styleSourceId) &&
inherited
) {
definedStyles.add(styleDecl);
inheritedStyles.add(styleDecl);
}
}
return definedStyles;

// We are sorting by alphabet within each group.
const sortByProperty = (a: { property: string }, b: { property: string }) => {
return Intl.Collator().compare(a.property, b.property);
};

return new Set([
...Array.from(instanceStyles).sort(sortByProperty),
...Array.from(inheritedStyles).sort(sortByProperty),
...Array.from(presetStyles).sort(sortByProperty),
]);
};

export const $definedStyles = computed(
Expand Down
9 changes: 1 addition & 8 deletions packages/design-system/src/components/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const labelColors = [
"local",
"overwritten",
"remote",
"code",
"inactive",
] as const;

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

// https://github.com/webstudio-is/webstudio/issues/1271#issuecomment-1478436340
Expand Down Expand Up @@ -91,12 +90,6 @@ const StyledLabel = styled(RadixLabel, {
backgroundColor: theme.colors.backgroundRemoteHover,
},
},
code: {
color: theme.colors.foregroundLocalMain,
"&:hover": {
backgroundColor: theme.colors.backgroundHover,
},
},
// Example is collapsible section title label when section has no content.
inactive: {
color: theme.colors.foregroundTextSubtle,
Expand Down
7 changes: 0 additions & 7 deletions packages/design-system/src/components/nested-icon-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ const colors = {
backgroundHover: theme.colors.backgroundRemoteHover,
icon: theme.colors.foregroundRemoteMain,
},
code: {
border: "transparent",
background: "transparent",
backgroundHover: theme.colors.backgroundHover,
icon: theme.colors.foregroundIconMain,
},
inactive: {
border: "transparent",
background: "transparent",
Expand Down Expand Up @@ -82,7 +76,6 @@ const style = css({
local: perColorStyle("local"),
overwritten: perColorStyle("overwritten"),
remote: perColorStyle("remote"),
code: perColorStyle("code"),
inactive: perColorStyle("inactive"),
},
},
Expand Down
Loading