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.

experimental: Advanced section improvements (#3137)

Oleg Isonen44c275910f1a
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.tsx
index aec7100313..7ad85f34dd 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
@@ -20,19 +20,20 @@ import { Add } from "./add";
import { CollapsibleSection } from "../../shared/collapsible-section";
import { sectionsProperties } from "../sections";
import { toKebabCase } from "../../shared/keyword-utils";
+import type { DeleteProperty, SetProperty } from "../../shared/use-style-data";
const allPropertyNames = Object.keys(propertiesData).sort(
Intl.Collator().compare
) as Array<StyleProperty>;
-const initialPropertyNames: Array<StyleProperty> = [
+const initialPropertyNames = new Set<StyleProperty>([
"userSelect",
"pointerEvents",
"mixBlendMode",
"backdropFilter",
"cursor",
"opacity",
-];
+]);
const usePropertyNames = (currentStyle: StyleInfo) => {
const selectedInstanceSelector = useStore($selectedInstanceSelector);
@@ -57,9 +58,11 @@ const usePropertyNames = (currentStyle: StyleInfo) => {
}
return [
- ...Array.from(names).filter((name) => recent.current.has(name) === false),
...recent.current,
- ].reverse();
+ ...Array.from(names)
+ .filter((name) => recent.current.has(name) === false)
+ .reverse(),
+ ];
}, [styles, currentStyle]);
return { propertyNames, recentProperties: recent.current };
};
@@ -67,14 +70,22 @@ const usePropertyNames = (currentStyle: StyleInfo) => {
// Only here to keep the same section module interface
export const properties = [];
-export const Section = ({
- currentStyle,
- setProperty,
- deleteProperty,
-}: SectionProps) => {
+export const Section = ({ currentStyle, ...props }: SectionProps) => {
const [addingProp, setAddingProp] = useState<StyleProperty | "">();
const { propertyNames, recentProperties } = usePropertyNames(currentStyle);
-
+ const deleteProperty: DeleteProperty = (property, options) => {
+ if (options?.isEphemeral !== true) {
+ recentProperties.delete(property);
+ }
+ return props.deleteProperty(property, options);
+ };
+ const setProperty: SetProperty = (property) => {
+ setAddingProp(undefined);
+ if (propertyNames.includes(property) === false) {
+ recentProperties.add(property);
+ }
+ return props.setProperty(property);
+ };
return (
<CollapsibleSection
label="Advanced"
@@ -92,8 +103,6 @@ export const Section = ({
onSelect={(value) => {
if (value in propertiesData || value.startsWith("--")) {
const property = value as StyleProperty;
- recentProperties.add(property);
- setAddingProp(undefined);
setProperty(property)(
{ type: "guaranteedInvalid" },
{ listed: true }
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
index 1f982dfbfe..633468b045 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -14,6 +14,7 @@ import {
InputField,
handleNumericInputArrowKeys,
theme,
+ Flex,
} from "@webstudio-is/design-system";
import type {
KeywordValue,
@@ -443,6 +444,7 @@ export const CssValueInput = ({
const inputProps = getInputProps();
const [isUnitsOpen, unitSelectElement] = useUnitSelect({
+ size,
property,
value,
onChange: (unitOrKeyword) => {
@@ -619,13 +621,13 @@ export const CssValueInput = ({
const suffix =
showSuffix === false ? null : (
- <Box ref={suffixRef}>
+ <Flex align="center" ref={suffixRef}>
{isUnitValue
? unitSelectElement
: isKeywordValue
? keywordButtonElement
: null}
- </Box>
+ </Flex>
);
let description;
diff --git a/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx b/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
index 998615162f..d56e2e2f91 100644
--- a/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/css-value-input/unit-select.tsx
@@ -1,4 +1,4 @@
-import { useState, useMemo } from "react";
+import { useState, useMemo, type ComponentProps } from "react";
import * as SelectPrimitive from "@radix-ui/react-select";
import type { Unit } from "@webstudio-is/css-engine";
import {
@@ -25,6 +25,7 @@ export type UnitOption =
type UseUnitSelectType = {
property: string;
value: CssValueInputValue;
+ size: ComponentProps<typeof NestedInputButton>["size"];
onChange: (
value: { type: "unit"; value: Unit } | { type: "keyword"; value: string }
) => void;
@@ -34,6 +35,7 @@ type UseUnitSelectType = {
export const useUnitSelect = ({
property,
value,
+ size,
onChange,
onCloseAutoFocus,
}: UseUnitSelectType): [boolean, JSX.Element | null] => {
@@ -58,6 +60,7 @@ export const useUnitSelect = ({
const select = (
<UnitSelect
+ size={size}
value={unitOrKeyword}
label={unit ?? nestedSelectButtonUnitless}
options={options}
@@ -86,6 +89,7 @@ type UnitSelectProps = {
onOpenChange: (open: boolean) => void;
onCloseAutoFocus: (event: Event) => void;
open: boolean;
+ size: UseUnitSelectType["size"];
};
const UnitSelect = ({
@@ -96,6 +100,7 @@ const UnitSelect = ({
onOpenChange,
onCloseAutoFocus,
open,
+ size,
}: UnitSelectProps) => {
return (
<SelectPrimitive.Root
@@ -111,7 +116,7 @@ const UnitSelect = ({
open={open}
>
<SelectPrimitive.SelectTrigger asChild>
- <NestedInputButton tabIndex={-1}>
+ <NestedInputButton tabIndex={-1} size={size}>
<SelectPrimitive.Value>
{value === "number" ? nestedSelectButtonUnitless : label}
</SelectPrimitive.Value>
diff --git a/packages/design-system/src/components/nested-input-button.tsx b/packages/design-system/src/components/nested-input-button.tsx
index 02663795a0..b919adde6f 100644
--- a/packages/design-system/src/components/nested-input-button.tsx
+++ b/packages/design-system/src/components/nested-input-button.tsx
@@ -20,7 +20,6 @@ const style = css({
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
- height: theme.spacing[11],
whiteSpace: "pre", // to make nestedSelectButtonUnitless work as expected
"&:not(:has(svg))": {
paddingLeft: theme.spacing[2],
@@ -49,7 +48,16 @@ const style = css({
},
},
},
+ size: {
+ 1: {
+ height: theme.spacing[10],
+ },
+ 2: {
+ height: theme.spacing[11],
+ },
+ },
},
+ defaultVariants: { size: 1 },
});
export const NestedInputButton = forwardRef(
@@ -58,17 +66,25 @@ export const NestedInputButton = forwardRef(
css,
className,
children,
+ size,
...props
- }: ComponentProps<"button"> & { css?: CSS },
+ }: ComponentProps<"button"> & { css?: CSS; size?: "1" | "2" },
ref: Ref<HTMLButtonElement>
- ) => (
- <button
- className={style({ css, className, hasChildren: children !== undefined })}
- {...props}
- ref={ref}
- >
- {children ?? <ChevronDownIcon />}
- </button>
- )
+ ) => {
+ return (
+ <button
+ className={style({
+ css,
+ className,
+ hasChildren: children !== undefined,
+ size,
+ })}
+ {...props}
+ ref={ref}
+ >
+ {children ?? <ChevronDownIcon />}
+ </button>
+ );
+ }
);
NestedInputButton.displayName = "NestedInputButton";