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: Add css transitions (#2511)

Jaya Krishna Namburu60a6a7fbf296
diff --git a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-content.tsx b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-content.tsx
index 42c350cea5..219f1c6806 100644
--- a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-content.tsx
@@ -12,21 +12,18 @@ import {
import { InformationIcon } from "@webstudio-is/icons";
import { useState } from "react";
import type { RenderCategoryProps } from "../../style-sections";
+import type { IntermediateStyleValue } from "../../shared/css-value-input";
-type IntermediateValue = {
- type: "intermediate";
+type BoxShadowContentProps = {
+ index: number;
value: string;
+ onEditLayer: (index: number, layers: LayersValue) => void;
+ createBatchUpdate: RenderCategoryProps["createBatchUpdate"];
};
-const useContent = ({
- onEditLayer,
- index,
-}: {
- onEditLayer: (index: number, layers: LayersValue) => void;
- index: number;
-}) => {
+export const BoxShadowContent = (props: BoxShadowContentProps) => {
const [intermediateValue, setIntermediateValue] = useState<
- IntermediateValue | InvalidValue | undefined
+ IntermediateStyleValue | InvalidValue | undefined
>();
const handleChange = (value: string) => {
@@ -49,21 +46,9 @@ const useContent = ({
return;
}
- onEditLayer(index, layers);
+ props.onEditLayer(props.index, layers);
};
- return { handleChange, handleComplete, intermediateValue };
-};
-
-type BoxShadowContentProps = {
- index: number;
- value: string;
- onEditLayer: (index: number, layers: LayersValue) => void;
- createBatchUpdate: RenderCategoryProps["createBatchUpdate"];
-};
-
-export const BoxShadowContent = (props: BoxShadowContentProps) => {
- const { intermediateValue, handleChange, handleComplete } = useContent(props);
return (
<Flex
direction="column"
diff --git a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-layer.tsx b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-layer.tsx
index dfb9b7333e..6c26432ebe 100644
--- a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-layer.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadow-layer.tsx
@@ -1,4 +1,4 @@
-import type { LayersValue, TupleValue } from "@webstudio-is/css-engine";
+import type { TupleValue } from "@webstudio-is/css-engine";
import {
Label,
SmallIconButton,
@@ -13,10 +13,10 @@ import {
import { useMemo } from "react";
import { FloatingPanel } from "~/builder/shared/floating-panel";
import { BoxShadowContent } from "./box-shadow-content";
-import type { RenderCategoryProps } from "../../style-sections";
import { colord, type RgbaColor } from "colord";
import { toValue } from "@webstudio-is/css-engine";
import { ColorThumb } from "../../shared/color-thumb";
+import type { LayerProps } from "../../style-layers-list";
const useLayer = (layer: TupleValue) => {
return useMemo(() => {
@@ -49,17 +49,7 @@ const useLayer = (layer: TupleValue) => {
}, [layer]);
};
-export const Layer = (
- props: Pick<RenderCategoryProps, "createBatchUpdate"> & {
- id: string;
- index: number;
- layer: TupleValue;
- isHighlighted: boolean;
- onLayerHide: (index: number) => void;
- onDeleteLayer: (index: number) => void;
- onEditLayer: (index: number, layers: LayersValue) => void;
- }
-) => {
+export const Layer = (props: LayerProps) => {
const { index, id, layer, isHighlighted, onDeleteLayer, onLayerHide } = props;
const { name, shadow, color } = useLayer(layer);
@@ -95,6 +85,7 @@ export const Layer = (
<SmallIconButton
variant="destructive"
tabIndex={-1}
+ disabled={layer.hidden}
icon={<SubtractIcon />}
onClick={(event) => {
onDeleteLayer(index);
diff --git a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx
index 3496c02202..54df9770b8 100644
--- a/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/box-shadows/box-shadows.tsx
@@ -66,6 +66,7 @@ export const BoxShadowsSection = (props: RenderCategoryProps) => {
>
{value?.type === "layers" && value.value.length > 0 && (
<LayersList
+ property={property}
layers={value}
{...props}
renderLayer={(layersProps) => (
diff --git a/apps/builder/app/builder/features/style-panel/sections/index.ts b/apps/builder/app/builder/features/style-panel/sections/index.ts
index 0f1cc26dff..7fcb2a8252 100644
--- a/apps/builder/app/builder/features/style-panel/sections/index.ts
+++ b/apps/builder/app/builder/features/style-panel/sections/index.ts
@@ -11,3 +11,4 @@ export * from "./borders/borders";
export * from "./outline/outline";
export * from "./effects/effects";
export * from "./box-shadows/box-shadows";
+export * from "./transitions/transitions";
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
new file mode 100644
index 0000000000..31d1fe1fb2
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx
@@ -0,0 +1,76 @@
+import type { InvalidValue, LayersValue } from "@webstudio-is/css-engine";
+import {
+ Flex,
+ Label,
+ TextArea,
+ theme,
+ textVariants,
+} from "@webstudio-is/design-system";
+import { useState } from "react";
+import { parseTransition } from "@webstudio-is/css-data";
+import type { CreateBatchUpdate } from "../../shared/use-style-data";
+import type { IntermediateStyleValue } from "../../shared/css-value-input";
+
+type TransitionContentProps = {
+ index: number;
+ value: string;
+ onEditLayer: (index: number, layer: LayersValue) => void;
+ createBatchUpdate: CreateBatchUpdate;
+};
+
+export const TransitionContent = (props: TransitionContentProps) => {
+ const [intermediateValue, setIntermediateValue] = useState<
+ IntermediateStyleValue | InvalidValue | undefined
+ >();
+
+ const handleChange = (value: string) => {
+ setIntermediateValue({
+ type: "intermediate",
+ value,
+ });
+ };
+
+ const handleComplete = () => {
+ if (intermediateValue === undefined) {
+ return;
+ }
+ const layers = parseTransition(intermediateValue.value);
+ if (layers.type === "invalid") {
+ setIntermediateValue({
+ type: "invalid",
+ value: intermediateValue.value,
+ });
+ return;
+ }
+
+ props.onEditLayer(props.index, layers);
+ setIntermediateValue(undefined);
+ };
+
+ return (
+ <Flex
+ direction="column"
+ css={{
+ px: theme.spacing[5],
+ py: theme.spacing[5],
+ gap: theme.spacing[3],
+ minWidth: theme.spacing[30],
+ }}
+ >
+ <Label>Code</Label>
+ <TextArea
+ rows={3}
+ name="description"
+ css={{ minHeight: theme.spacing[14], ...textVariants.mono }}
+ value={intermediateValue?.value ?? props.value ?? ""}
+ onChange={handleChange}
+ onKeyDown={(event) => {
+ if (event.key === "Enter") {
+ handleComplete();
+ event.preventDefault();
+ }
+ }}
+ />
+ </Flex>
+ );
+};
diff --git a/apps/builder/app/builder/features/style-panel/sections/transitions/transition-layer.tsx b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-layer.tsx
new file mode 100644
index 0000000000..c4c622881f
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transition-layer.tsx
@@ -0,0 +1,73 @@
+import { useMemo } from "react";
+import {
+ CssValueListItem,
+ Label,
+ SmallIconButton,
+} from "@webstudio-is/design-system";
+import { SubtractIcon } from "@webstudio-is/icons";
+import type { TupleValue } from "@webstudio-is/css-engine";
+import { FloatingPanel } from "~/builder/shared/floating-panel";
+import { TransitionContent } from "./transition-content";
+import type { LayerProps } from "../../style-layers-list";
+
+const useLayer = (layer: TupleValue) => {
+ return useMemo(() => {
+ const name: string[] = [];
+
+ for (const item of Object.values(layer.value)) {
+ if (item.type === "keyword") {
+ name.push(item.value);
+ }
+
+ if (item.type === "unit") {
+ name.push(`${item.value}${item.unit}`);
+ }
+ }
+
+ return {
+ name: name.join(" "),
+ transition: name.join(" "),
+ };
+ }, [layer]);
+};
+
+export const Layer = (props: LayerProps) => {
+ const { id, index, layer, isHighlighted, onDeleteLayer, disabled } = props;
+ const { name, transition } = useLayer(layer);
+
+ return (
+ <FloatingPanel
+ title="Transitions"
+ content={
+ <TransitionContent
+ index={index}
+ value={transition}
+ onEditLayer={props.onEditLayer}
+ createBatchUpdate={props.createBatchUpdate}
+ />
+ }
+ >
+ <CssValueListItem
+ id={id}
+ active={isHighlighted}
+ index={index}
+ label={<Label truncate>{name}</Label>}
+ hidden={disabled ?? layer?.hidden}
+ buttons={
+ <>
+ <SmallIconButton
+ variant="destructive"
+ tabIndex={-1}
+ disabled={disabled || layer?.hidden}
+ icon={<SubtractIcon />}
+ onClick={(event) => {
+ onDeleteLayer(index);
+ event.preventDefault();
+ }}
+ />
+ </>
+ }
+ ></CssValueListItem>
+ </FloatingPanel>
+ );
+};
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
new file mode 100644
index 0000000000..3cb21a58f9
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/transitions/transitions.tsx
@@ -0,0 +1,104 @@
+import type { StyleProperty } from "@webstudio-is/css-engine";
+import { CollapsibleSectionBase } from "~/builder/shared/collapsible-section";
+import type { RenderCategoryProps } from "../../style-sections";
+import {
+ SectionTitle,
+ SectionTitleButton,
+ SectionTitleLabel,
+ Tooltip,
+} from "@webstudio-is/design-system";
+import { useState } from "react";
+import { getDots } from "../../shared/collapsible-section";
+import { getStyleSource } from "../../shared/style-info";
+import { PlusIcon } from "@webstudio-is/icons";
+import { PropertyName } from "../../shared/property-name";
+import { addLayer } from "../../style-layer-utils";
+import { parseTransition } from "@webstudio-is/css-data";
+import { LayersList } from "../../style-layers-list";
+import { Layer } from "./transition-layer";
+import { selectedOrLastStyleSourceSelectorStore } from "~/shared/nano-states";
+import { useStore } from "@nanostores/react";
+import { isFeatureEnabled } from "@webstudio-is/feature-flags";
+
+const property: StyleProperty = "transition";
+const label = "Transitions";
+
+export const TransitionSection = (props: RenderCategoryProps) => {
+ const { currentStyle, deleteProperty } = props;
+ const [isOpen, setIsOpen] = useState(true);
+ const layersStyleSource = getStyleSource(currentStyle[property]);
+ const value = currentStyle[property]?.value;
+
+ const selectedOrLastStyleSourceSelector = useStore(
+ selectedOrLastStyleSourceSelectorStore
+ );
+
+ const isStyleInLocalState =
+ selectedOrLastStyleSourceSelector &&
+ selectedOrLastStyleSourceSelector.state === undefined;
+
+ if (isFeatureEnabled("transitions") === false) {
+ return null;
+ }
+
+ return (
+ <CollapsibleSectionBase
+ fullWidth
+ label={label}
+ isOpen={isOpen}
+ onOpenChange={setIsOpen}
+ trigger={
+ <SectionTitle
+ dots={getDots(currentStyle, [property])}
+ suffix={
+ <Tooltip content={"Transitions can only be added in local state"}>
+ <SectionTitleButton
+ disabled={isStyleInLocalState === false}
+ prefix={<PlusIcon />}
+ onClick={() => {
+ addLayer(
+ property,
+ // Using default transition value
+ parseTransition("opacity 200ms ease 0s"),
+ currentStyle,
+ props.createBatchUpdate
+ );
+ setIsOpen(true);
+ }}
+ />
+ </Tooltip>
+ }
+ >
+ <PropertyName
+ title={label}
+ style={currentStyle}
+ properties={[property]}
+ label={
+ <SectionTitleLabel color={layersStyleSource}>
+ {label}
+ </SectionTitleLabel>
+ }
+ onReset={() => deleteProperty(property)}
+ />
+ </SectionTitle>
+ }
+ >
+ {value?.type === "layers" && value.value.length > 0 && (
+ <LayersList
+ property={property}
+ layers={value}
+ {...props}
+ renderLayer={(layerProps) => {
+ return (
+ <Layer
+ key={layerProps.index}
+ {...layerProps}
+ disabled={isStyleInLocalState === false}
+ />
+ );
+ }}
+ />
+ )}
+ </CollapsibleSectionBase>
+ );
+};
diff --git a/apps/builder/app/builder/features/style-panel/style-layers-list.tsx b/apps/builder/app/builder/features/style-panel/style-layers-list.tsx
index 6db55eacf2..5d0a96c9a4 100644
--- a/apps/builder/app/builder/features/style-panel/style-layers-list.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-layers-list.tsx
@@ -19,24 +19,29 @@ import {
import { useMemo } from "react";
import type { CreateBatchUpdate } from "./shared/use-style-data";
+export type LayerProps = {
+ id: string;
+ index: number;
+ layer: TupleValue;
+ isHighlighted: boolean;
+ disabled?: boolean;
+ onLayerHide: (index: number) => void;
+ onDeleteLayer: (index: number) => void;
+ onEditLayer: (index: number, layers: LayersValue) => void;
+ createBatchUpdate: CreateBatchUpdate;
+};
+
type LayerListProperties = RenderCategoryProps & {
+ disabled?: boolean;
+ property: StyleProperty;
layers: LayersValue;
- renderLayer: (props: {
- id: string;
- index: number;
- layer: TupleValue;
- isHighlighted: boolean;
- onLayerHide: (index: number) => void;
- onDeleteLayer: (index: number) => void;
- createBatchUpdate: CreateBatchUpdate;
- onEditLayer: (index: number, newLayers: LayersValue) => void;
- }) => JSX.Element;
+ renderLayer: (props: LayerProps) => JSX.Element;
};
-const property: StyleProperty = "boxShadow";
-
export const LayersList = ({
+ property,
layers,
+ disabled,
currentStyle,
renderLayer,
createBatchUpdate,
@@ -73,7 +78,7 @@ export const LayersList = ({
return (
<CssValueListArrowFocus dragItemId={dragItemId}>
- <Flex direction="column" gap={2} ref={sortableRefCallback}>
+ <Flex direction="column" ref={sortableRefCallback}>
{layers.value.map((layer, index) => {
if (layer.type !== "tuple") {
return null;
@@ -83,6 +88,7 @@ export const LayersList = ({
id,
index,
layer,
+ disabled,
isHighlighted: dragItemId === id,
onLayerHide: handleHideLayer,
onDeleteLayer: handleDeleteLayer,
diff --git a/apps/builder/app/builder/features/style-panel/style-sections.tsx b/apps/builder/app/builder/features/style-panel/style-sections.tsx
index 76fbb4ca9c..44ae66d9ac 100644
--- a/apps/builder/app/builder/features/style-panel/style-sections.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-sections.tsx
@@ -25,6 +25,7 @@ import {
EffectsSection,
BoxShadowsSection,
ListItemSection,
+ TransitionSection,
} from "./sections";
export const categories = [
@@ -41,6 +42,7 @@ export const categories = [
"boxShadows",
"outline",
"effects",
+ "transitions",
] as const;
export type Category = (typeof categories)[number];
@@ -154,4 +156,5 @@ export const sections: Record<
outline: OutlineSection,
effects: EffectsSection,
boxShadows: BoxShadowsSection,
+ transitions: TransitionSection,
};
diff --git a/packages/css-data/bin/mdn-data.ts b/packages/css-data/bin/mdn-data.ts
index 107f5d4439..c71dfe14d6 100755
--- a/packages/css-data/bin/mdn-data.ts
+++ b/packages/css-data/bin/mdn-data.ts
@@ -229,10 +229,38 @@ const filteredProperties: FilteredProperties = (() => {
const ignoreProperties = ["all", "-webkit-line-clamp", "--*"];
let property: Property;
const result = {} as FilteredProperties;
+
+ /*
+ A transition is a shorthand property that represents the combination of the other four properties.
+ Typically, we exclude shorthand properties when using the expanded ones.
+ However, in this case, the transition property in the designs allows users to set all transition values at once.
+ Therefore, we need to make this property available from the generated list.
+
+ The initial properties for transition is
+ config.initial = [
+ 'transition-delay',
+ 'transition-duration',
+ 'transition-property',
+ 'transition-timing-function'
+ ]
+
+ We replace it with the defaults of the rest of the four properties
+ "all 0s ease 0s"
+ */
+
+ const supportedComplexProperties: Record<string, string> = {
+ transition: "all 0s ease 0s",
+ };
+
for (property in properties) {
const config = properties[property];
const isSupportedStatus =
config.status === "standard" || config.status === "experimental";
+
+ if (property in supportedComplexProperties) {
+ config.initial = supportedComplexProperties[property];
+ }
+
if (
isSupportedStatus === false ||
// Skipping the complex values, since we want to use the expanded once.
diff --git a/packages/css-data/src/__generated__/keyword-values.ts b/packages/css-data/src/__generated__/keyword-values.ts
index 84dd183bcd..f763610df4 100644
--- a/packages/css-data/src/__generated__/keyword-values.ts
+++ b/packages/css-data/src/__generated__/keyword-values.ts
@@ -5147,6 +5147,20 @@ export const keywordValues = {
"unset",
],
transformStyle: ["flat", "preserve-3d", "initial", "inherit", "unset"],
+ transition: [
+ "none",
+ "all",
+ "linear",
+ "ease",
+ "ease-in",
+ "ease-out",
+ "ease-in-out",
+ "step-start",
+ "step-end",
+ "initial",
+ "inherit",
+ "unset",
+ ],
transitionDelay: ["initial", "inherit", "unset"],
transitionDuration: ["initial", "inherit", "unset"],
transitionProperty: ["none", "all", "initial", "inherit", "unset"],
diff --git a/packages/css-data/src/__generated__/properties.ts b/packages/css-data/src/__generated__/properties.ts
index 7bf7e74be0..7e34b4be37 100644
--- a/packages/css-data/src/__generated__/properties.ts
+++ b/packages/css-data/src/__generated__/properties.ts
@@ -3500,6 +3500,35 @@ export const properties = {
popularity: 0.11068509,
appliesTo: "transformableElements",
},
+ transition: {
+ unitGroups: ["time"],
+ inherited: false,
+ initial: {
+ type: "tuple",
+ value: [
+ {
+ type: "keyword",
+ value: "all",
+ },
+ {
+ type: "unit",
+ unit: "s",
+ value: 0,
+ },
+ {
+ type: "keyword",
+ value: "ease",
+ },
+ {
+ type: "unit",
+ unit: "s",
+ value: 0,
+ },
+ ],
+ },
+ popularity: 0.78355592,
+ appliesTo: "allElementsAndPseudos",
+ },
transitionDelay: {
unitGroups: ["time"],
inherited: false,
diff --git a/packages/css-data/src/property-parsers/__snapshots__/transition.test.ts.snap b/packages/css-data/src/property-parsers/__snapshots__/transition.test.ts.snap
new file mode 100644
index 0000000000..222563aec7
--- /dev/null
+++ b/packages/css-data/src/property-parsers/__snapshots__/transition.test.ts.snap
@@ -0,0 +1,129 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`parseTransition parse value and returns multiple valid layers:
+ {
+ "type": "layers",
+ "value": [
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "color"
+ },
+ {
+ "type": "unit",
+ "value": 0.2,
+ "unit": "s"
+ }
+ ]
+ },
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "text-shadow"
+ },
+ {
+ "type": "unit",
+ "value": 0.2,
+ "unit": "s"
+ }
+ ]
+ }
+ ]
+ } 1`] = `
+{
+ "type": "layers",
+ "value": [
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "color",
+ },
+ {
+ "type": "unit",
+ "unit": "s",
+ "value": 0.2,
+ },
+ ],
+ },
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "text-shadow",
+ },
+ {
+ "type": "unit",
+ "unit": "s",
+ "value": 0.2,
+ },
+ ],
+ },
+ ],
+}
+`;
+
+exports[`parseTransition parse value and returns valid layer:
+ {
+ "type": "layers",
+ "value": [
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "opacity"
+ },
+ {
+ "type": "unit",
+ "value": 200,
+ "unit": "ms"
+ },
+ {
+ "type": "keyword",
+ "value": "ease"
+ },
+ {
+ "type": "unit",
+ "value": 0,
+ "unit": "s"
+ }
+ ]
+ }
+ ]
+ } 1`] = `
+{
+ "type": "layers",
+ "value": [
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "opacity",
+ },
+ {
+ "type": "unit",
+ "unit": "ms",
+ "value": 200,
+ },
+ {
+ "type": "keyword",
+ "value": "ease",
+ },
+ {
+ "type": "unit",
+ "unit": "s",
+ "value": 0,
+ },
+ ],
+ },
+ ],
+}
+`;
diff --git a/packages/css-data/src/property-parsers/index.ts b/packages/css-data/src/property-parsers/index.ts
index 795a8f57c2..22ff946341 100644
--- a/packages/css-data/src/property-parsers/index.ts
+++ b/packages/css-data/src/property-parsers/index.ts
@@ -1,2 +1,3 @@
export * from "./background";
export * from "./box-shadow";
+export * from "./transition";
diff --git a/packages/css-data/src/property-parsers/transition.test.ts b/packages/css-data/src/property-parsers/transition.test.ts
new file mode 100644
index 0000000000..bc2a813e46
--- /dev/null
+++ b/packages/css-data/src/property-parsers/transition.test.ts
@@ -0,0 +1,83 @@
+import { describe, expect, test } from "@jest/globals";
+
+import { parseTransition } from "./transition";
+
+describe("parseTransition", () => {
+ test("parses value and returns invalid when used a invalid color", () => {
+ expect(parseTransition(`10px 10px 5px foo`)).toMatchInlineSnapshot(`
+ {
+ "type": "invalid",
+ "value": "10px 10px 5px foo",
+ }
+ `);
+ });
+
+ test("parse value and returns multiple valid layers", () => {
+ expect(parseTransition("color .2s, text-shadow .2s")).toMatchSnapshot(`
+ {
+ "type": "layers",
+ "value": [
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "color"
+ },
+ {
+ "type": "unit",
+ "value": 0.2,
+ "unit": "s"
+ }
+ ]
+ },
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "text-shadow"
+ },
+ {
+ "type": "unit",
+ "value": 0.2,
+ "unit": "s"
+ }
+ ]
+ }
+ ]
+ }`);
+ });
+
+ test("parse value and returns valid layer", () => {
+ expect(parseTransition("opacity 200ms ease 0s")).toMatchSnapshot(`
+ {
+ "type": "layers",
+ "value": [
+ {
+ "type": "tuple",
+ "value": [
+ {
+ "type": "keyword",
+ "value": "opacity"
+ },
+ {
+ "type": "unit",
+ "value": 200,
+ "unit": "ms"
+ },
+ {
+ "type": "keyword",
+ "value": "ease"
+ },
+ {
+ "type": "unit",
+ "value": 0,
+ "unit": "s"
+ }
+ ]
+ }
+ ]
+ }`);
+ });
+});
diff --git a/packages/css-data/src/property-parsers/transition.ts b/packages/css-data/src/property-parsers/transition.ts
new file mode 100644
index 0000000000..71ff94a717
--- /dev/null
+++ b/packages/css-data/src/property-parsers/transition.ts
@@ -0,0 +1,100 @@
+import * as csstree from "css-tree";
+import type {
+ InvalidValue,
+ LayersValue,
+ TupleValue,
+ TupleValueItem,
+ Unit,
+} from "@webstudio-is/css-engine";
+
+const cssTreeTryParseValue = (input: string) => {
+ try {
+ const ast = csstree.parse(input, { context: "value" });
+ return ast;
+ } catch {
+ return undefined;
+ }
+};
+
+export const parseTransition = (
+ transition: string
+): LayersValue | InvalidValue => {
+ let tokenStream = transition.trim();
+ tokenStream = tokenStream.endsWith(";")
+ ? tokenStream.slice(0, -1)
+ : tokenStream;
+
+ const cleanupKeywords = ["transition:"];
+
+ for (const cleanupKeyword of cleanupKeywords) {
+ tokenStream = tokenStream.startsWith(cleanupKeyword)
+ ? tokenStream.slice(cleanupKeyword.length).trim()
+ : tokenStream;
+ }
+
+ const cssAst = cssTreeTryParseValue(tokenStream);
+
+ if (cssAst === undefined) {
+ return {
+ type: "invalid",
+ value: transition,
+ };
+ }
+
+ const parsed = csstree.lexer.matchProperty("transition", cssAst);
+ if (parsed.error) {
+ return {
+ type: "invalid",
+ value: transition,
+ };
+ }
+
+ const layers: TupleValue[] = [];
+
+ csstree.walk(cssAst, (node) => {
+ if (node.type === "Value") {
+ const children = node.children;
+ let layer: csstree.CssNode[] = [];
+
+ for (const child of children) {
+ layer.push(child);
+
+ if (child.type === "Operator" || children.last === child) {
+ const transition: TupleValueItem[] = [];
+
+ for (let index = 0; index < layer.length; index++) {
+ const item = layer[index];
+ if (item.type === "Identifier") {
+ transition.push({
+ type: "keyword",
+ value: item.name,
+ });
+ }
+
+ if (item.type === "Dimension") {
+ transition.push({
+ type: "unit",
+ value: Number(item.value),
+ unit: item.unit as Unit,
+ });
+ }
+ }
+
+ layers.push({
+ type: "tuple",
+ value: transition,
+ });
+ layer = [];
+ continue;
+ }
+ }
+ }
+ });
+
+ return layers.length > 0
+ ? {
+ type: "layers",
+ value: layers,
+ }
+ : { type: "invalid", value: transition };
+};
diff --git a/packages/css-engine/src/__generated__/types.ts b/packages/css-engine/src/__generated__/types.ts
index d8e32b8ada..feceaba6b7 100644
--- a/packages/css-engine/src/__generated__/types.ts
+++ b/packages/css-engine/src/__generated__/types.ts
@@ -336,6 +336,7 @@ export type Property =
| "transformBox"
| "transformOrigin"
| "transformStyle"
+ | "transition"
| "transitionDelay"
| "transitionDuration"
| "transitionProperty"
diff --git a/packages/feature-flags/src/flags.ts b/packages/feature-flags/src/flags.ts
index 16696844e2..a94f8fd2a7 100644
--- a/packages/feature-flags/src/flags.ts
+++ b/packages/feature-flags/src/flags.ts
@@ -5,3 +5,4 @@ export const displayContents = false;
export const adminRole = false;
export const ai = true;
export const aiRadixComponents = false;
+export const transitions = false;