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.

feat: Show the properties that are already applied on the node at the top of the transition property list. (#3992)

Jaya Krishna Namburu615cbd80843f
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
index 9ff7a45d41..69d97d7030 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
@@ -175,6 +175,7 @@ export const TransitionContent = ({
}}
>
<TransitionProperty
+ currentStyle={currentStyle}
property={property ?? properties.transitionProperty.initial}
onPropertySelection={handlePropertyUpdate}
/>
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
index c8c08b51c1..b24c555be1 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-property.tsx
@@ -1,4 +1,4 @@
-import { useState, useEffect } from "react";
+import { useState, useEffect, useMemo } from "react";
import {
animatableProperties,
commonTransitionProperties,
@@ -25,12 +25,15 @@ import {
} from "@webstudio-is/css-engine";
import { matchSorter } from "match-sorter";
import { setUnion } from "~/shared/shim";
+import { type StyleInfo } from "../../shared/style-info";
+import { getAnimatablePropertiesOnInstance } from "./transition-utils";
import { PropertyInlineLabel } from "../../property-label";
type AnimatableProperties = (typeof animatableProperties)[number];
type NameAndLabel = { name: string; label?: string };
type TransitionPropertyProps = {
property: StyleValue;
+ currentStyle: StyleInfo;
onPropertySelection: (params: {
property: KeywordValue | UnparsedValue;
}) => void;
@@ -38,17 +41,25 @@ type TransitionPropertyProps = {
const commonPropertiesSet = new Set(commonTransitionProperties);
-const properties = Array.from(
- setUnion(commonPropertiesSet, new Set(animatableProperties))
-);
-
export const TransitionProperty = ({
property,
+ currentStyle,
onPropertySelection,
}: TransitionPropertyProps) => {
const valueString = toValue(property);
const [inputValue, setInputValue] = useState<string>(valueString);
useEffect(() => setInputValue(valueString), [valueString]);
+ const propertiesDefinedOnInstanceSet = useMemo(
+ () => getAnimatablePropertiesOnInstance(currentStyle),
+ [currentStyle]
+ );
+
+ const properties = Array.from(
+ setUnion(
+ setUnion(propertiesDefinedOnInstanceSet, commonPropertiesSet),
+ new Set(animatableProperties)
+ )
+ );
const {
items,
@@ -68,12 +79,13 @@ export const TransitionProperty = ({
itemToString: (value) => value?.label || "",
onItemSelect: (prop) => saveAnimatableProperty(prop.name),
onInputChange: (value) => setInputValue(value ?? ""),
- /*
- We are splitting the items into two lists.
- But when users pass a input, the list is filtered and mixed together.
- The UI is still showing the lists as separated. But the items are mixed together in background.
- Since, first we show the common-properties followed by filtered-properties. We can use matchSorter to sort the items.
- */
+
+ // We are splitting the items into two lists.
+ // But when users pass a input, the list is filtered and mixed together.
+ // The UI is still showing the lists as separated. But the items are mixed together in background.
+ // Since, first we show the properties on instance and then common-properties
+ // followed by filtered-properties. We can use matchSorter to sort the items.
+
match: (search, itemsToFilter, itemToString) => {
if (search === "") {
return itemsToFilter;
@@ -91,6 +103,14 @@ export const TransitionProperty = ({
return 1;
}
+ // Keep the proeprties on instance at the top
+ if (propertiesDefinedOnInstanceSet.has(a.item.name)) {
+ return -1;
+ }
+ if (propertiesDefinedOnInstanceSet.has(b.item.name)) {
+ return 1;
+ }
+
// Keep the common properties at the top as well
if (commonPropertiesSet.has(a.item.name)) {
return -1;
@@ -109,12 +129,21 @@ export const TransitionProperty = ({
});
const commonProperties = items.filter(
- (item) => commonPropertiesSet.has(item.name) === true
+ (item) =>
+ commonPropertiesSet.has(item.name) === true &&
+ propertiesDefinedOnInstanceSet.has(item.name) === false
);
-
const filteredProperties = items.filter(
- (item) => commonPropertiesSet.has(item.name) === false
+ (item) =>
+ commonPropertiesSet.has(item.name) === false &&
+ propertiesDefinedOnInstanceSet.has(item.name) === false
);
+ const propertiesDefinedOnInstance: Array<NameAndLabel> = Array.from(
+ propertiesDefinedOnInstanceSet
+ ).map((item) => ({
+ name: item,
+ label: item,
+ }));
const saveAnimatableProperty = (propertyName: string) => {
if (isAnimatableProperty(propertyName) === false) {
@@ -126,17 +155,20 @@ export const TransitionProperty = ({
});
};
- const renderItem = (item: NameAndLabel, index: number) => (
- <ComboboxListboxItem
- {...getItemProps({
- item,
- index,
- })}
- selected={item.name === inputValue}
- >
- {item?.label ?? ""}
- </ComboboxListboxItem>
- );
+ const renderItem = (item: NameAndLabel, index: number) => {
+ return (
+ <ComboboxListboxItem
+ {...getItemProps({
+ item,
+ index,
+ })}
+ key={item.name}
+ selected={item.name === inputValue}
+ >
+ {item?.label ?? ""}
+ </ComboboxListboxItem>
+ );
+ };
return (
<>
@@ -167,19 +199,32 @@ export const TransitionProperty = ({
<ComboboxScrollArea>
{isOpen && (
<>
- <ComboboxLabel>Common</ComboboxLabel>
- {commonProperties.map(renderItem)}
+ {propertiesDefinedOnInstance.length > 0 && (
+ <>
+ <ComboboxLabel>Defined</ComboboxLabel>
+ {propertiesDefinedOnInstance.map((property, index) =>
+ renderItem(property, index)
+ )}
+ <ComboboxSeparator />
+ </>
+ )}
+
+ <ComboboxLabel role="option">Common</ComboboxLabel>
+ {commonProperties.map((property, index) =>
+ renderItem(
+ property,
+ propertiesDefinedOnInstance.length + index
+ )
+ )}
<ComboboxSeparator />
+
{filteredProperties.map((property, index) =>
- /*
- When rendered in two different lists.
- We will have two indexes start at '0'. Which leads to
- - The same focus might be repeated when highlighted.
- - Using findIndex within getItemProps might make the focus jump around,
- as it searches the entire list for items.
- This happens because the list isn't sorted in order but is divided when rendering.
- */
- renderItem(property, commonProperties.length + index)
+ renderItem(
+ property,
+ propertiesDefinedOnInstance.length +
+ commonProperties.length +
+ index
+ )
)}
</>
)}
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-utils.ts b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-utils.ts
index 97aa990139..3bcb277724 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-utils.ts
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-utils.ts
@@ -4,6 +4,8 @@ import {
type KeywordValue,
type LayersValue,
type UnitValue,
+ type StyleProperty,
+ hyphenateProperty,
} from "@webstudio-is/css-engine";
import type { StyleInfo } from "../../shared/style-info";
import type {
@@ -12,6 +14,7 @@ import type {
} from "../../shared/use-style-data";
import {
extractTransitionProperties,
+ isAnimatableProperty,
properties,
transitionLongHandProperties,
} from "@webstudio-is/css-data";
@@ -86,6 +89,30 @@ export const findTimingFunctionFromValue = (
);
};
+export const getAnimatablePropertiesOnInstance = (
+ currentStyle: StyleInfo
+): Set<string> => {
+ const properties: Set<string> = new Set();
+ let property: StyleProperty;
+ for (property in currentStyle) {
+ const value = currentStyle[property];
+ const prop = hyphenateProperty(property);
+
+ if (isAnimatableProperty(prop) === false) {
+ continue;
+ }
+
+ if (value?.local !== undefined) {
+ properties.add(prop);
+ }
+
+ if (value?.nextSource || value?.previousSource) {
+ properties.add(prop);
+ }
+ }
+ return properties;
+};
+
export const getTransitionProperties = (
currentyStyle: StyleInfo
): Record<TransitionProperty, LayersValue> => {
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
index d09d5c2d21..3c3cff8f8c 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
@@ -58,7 +58,7 @@ const getLayerLabel = ({
const propertyLayer =
getTransitionLayers(style, "transitionProperty")[index] ??
properties.transitionProperty.initial;
- const property = humanizeString(toValue({ ...propertyLayer, hidden: false }));
+ const property = toValue({ ...propertyLayer, hidden: false });
const duration = toValue(
getTransitionLayers(style, "transitionDuration")[index] ??
properties.transitionDuration.initial
@@ -73,7 +73,12 @@ const getLayerLabel = ({
getTransitionLayers(style, "transitionDelay")[index] ??
properties.transitionDelay.initial
);
- return `${property}: ${duration} ${humanizedTimingFunction} ${delay}`;
+
+ if (property === "transform") {
+ return `Transform (Rotate, Skew): ${duration} ${humanizedTimingFunction} ${delay}`;
+ }
+
+ return `${humanizeString(property)}: ${duration} ${humanizedTimingFunction} ${delay}`;
};
const defaultTransitionLayers: Record<TransitionProperty, LayerValueItem> = {
diff --git a/packages/design-system/src/components/menu.tsx b/packages/design-system/src/components/menu.tsx
index 09fe57c639..9c15b6f56c 100644
--- a/packages/design-system/src/components/menu.tsx
+++ b/packages/design-system/src/components/menu.tsx
@@ -29,6 +29,7 @@ export const labelCss = css(textVariants.titles, {
color: theme.colors.foregroundMain,
mx: theme.spacing[3],
padding: theme.spacing[3],
+ order: 1,
});
const indicatorSize = theme.spacing[9];
@@ -114,8 +115,10 @@ export const MenuItemButton = styled("button", menuItemCss, {
export const separatorCss = css({
height: 1,
+ minHeight: 1,
my: theme.spacing[3],
backgroundColor: theme.colors.borderMain,
+ order: 1,
});
const menuPadding = theme.spacing[3];