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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
experimental: move advanced animation config to popover (#5124)
Bogdan Chadkinf167b3e6d70f
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsxindex f52e0700e2..e185468ac0 100644--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx@@ -1,4 +1,5 @@-import { useState } from "react";+import isEqual from "fast-deep-equal";+import { forwardRef, useState, type ComponentProps } from "react";import {Grid,theme,@@ -11,9 +12,9 @@ import {ToggleGroupButton,Text,Switch,+ FloatingPanel,+ IconButton,} from "@webstudio-is/design-system";-import { useIds } from "~/shared/form-utils";-import type { PropAndMeta } from "../use-props-logic";import type {AnimationAction,AnimationActionScroll,@@ -24,9 +25,11 @@ import {insetUnitValueSchema,RANGE_UNITS,} from "@webstudio-is/sdk";-import { ArrowDownIcon, ArrowRightIcon } from "@webstudio-is/icons";-import { AnimationsSelect } from "./animations-select";-import { SubjectSelect } from "./subject-select";+import {+ ArrowDownIcon,+ ArrowRightIcon,+ EllipsesIcon,+} from "@webstudio-is/icons";import { toValue, type StyleValue } from "@webstudio-is/css-engine";import {CssValueInput,@@ -34,6 +37,9 @@ import {} from "~/builder/features/style-panel/shared/css-value-input";import { humanizeString } from "~/shared/string-utils";import { FieldLabel } from "../../property-label";+import type { PropAndMeta } from "../use-props-logic";+import { AnimationsSelect } from "./animations-select";+import { SubjectSelect } from "./subject-select";const animationTypeDescription: Record<AnimationAction["type"], string> = {scroll:@@ -44,7 +50,7 @@ const animationTypeDescription: Record<AnimationAction["type"], string> = {const insetDescription ="Adjusts the animation’s start/end position relative to the scrollport. Positive values move it inward (delaying start or hastening end), while negative values move it outward (starting animation before visibility or continuing after disappearance).";-const animationTypes: AnimationAction["type"][] = Object.keys(+const animationTypes = Object.keys(animationTypeDescription) as AnimationAction["type"][];@@ -116,11 +122,9 @@ const unitOptions = RANGE_UNITS.map((unit) => ({}));const InsetValueInput = ({- id,value,onChange,}: {- id: string;value: InsetUnitValue;onChange: ((value: undefined, isEphemeral: true) => void) &((value: InsetUnitValue, isEphemeral: boolean) => void);@@ -147,7 +151,6 @@ const InsetValueInput = ({return (<CssValueInput- id={id}styleSource="default"value={value}/* marginLeft to allow negative values */@@ -200,6 +203,162 @@ const animationSources = Object.keys(animationSourceDescriptions) as NonNullable<AnimationActionScroll["source"]>[];+const AnimationConfig = ({+ value,+ onChange,+}: {+ value: AnimationAction;+ onChange: ((value: AnimationAction, isEphemeral: boolean) => void) &+ ((value: undefined, isEphemeral: true) => void);+}) => {+ return (+ <Grid gap={2} css={{ padding: theme.panel.padding }}>+ <Grid gap={1} align="center" columns={2}>+ <FieldLabel description="Type of the timeline defines how the animation is triggered.">+ Type+ </FieldLabel>+ <Select+ options={animationTypes}+ getLabel={humanizeString}+ value={value.type}+ getDescription={(animationType) => (+ <Box css={{ width: theme.spacing[28] }}>+ {animationTypeDescription[animationType]}+ </Box>+ )}+ onChange={(typeValue) =>+ onChange({ ...value, type: typeValue, animations: [] }, false)+ }+ />+ </Grid>++ <Grid gap={1} align="center" columns={2}>+ <FieldLabel description="Axis determines whether an animation progresses based on an element’s visibility along the horizontal or vertical direction.">+ Axis+ </FieldLabel>+ <ToggleGroup+ css={{ justifySelf: "end" }}+ type="single"+ value={convertAxisToXY(value.axis ?? ("y" as const))}+ onValueChange={(axis: keyof typeof animationAxisDescription) =>+ onChange({ ...value, axis: convertAxisToXY(axis) }, false)+ }+ >+ {Object.entries(animationAxisDescription).map(+ ([key, { icon, label, description }]) => (+ <Tooltip+ key={key}+ variant="wrapped"+ content={+ <Grid gap={1}>+ <Text variant={"titles"}>{label}</Text>+ <Text>{description}</Text>+ </Grid>+ }+ >+ <ToggleGroupButton value={key}>{icon}</ToggleGroupButton>+ </Tooltip>+ )+ )}+ </ToggleGroup>+ </Grid>++ {value.type === "scroll" && (+ <Grid gap={1} align="center" columns={2}>+ <FieldLabel description="The scroll source is the element whose scrolling behavior drives the animation's progress.">+ Scroll Source+ </FieldLabel>+ <Select+ options={animationSources}+ getLabel={humanizeString}+ value={value.source ?? "nearest"}+ getDescription={(animationSource) => (+ <Box css={{ width: theme.spacing[28] }}>+ {animationSourceDescriptions[animationSource]}+ </Box>+ )}+ onChange={(source) => onChange({ ...value, source }, false)}+ />+ </Grid>+ )}++ {value.type === "view" && (+ <Grid gap={1} align="center" columns={2}>+ <FieldLabel description="The subject is the element whose visibility determines the animation’s progress.">+ Subject+ </FieldLabel>+ <SubjectSelect value={value} onChange={onChange} />+ </Grid>+ )}++ {value.type === "view" && (+ <Grid gap={1} align={"center"} css={{ gridTemplateColumns: "1fr 1fr" }}>+ <FieldLabel description={insetDescription}>+ {value.axis === "inline" || value.axis === "x"+ ? "Left Inset"+ : "Top Inset"}+ </FieldLabel>+ <FieldLabel description={insetDescription}>+ {value.axis === "inline" || value.axis === "x"+ ? "Right Inset"+ : "Bottom Inset"}+ </FieldLabel>+ <InsetValueInput+ value={value.insetStart ?? { type: "keyword", value: "auto" }}+ onChange={(insetStart, isEphemeral) => {+ if (insetStart === undefined) {+ onChange(undefined, true);+ return;+ }+ onChange({ ...value, insetStart }, isEphemeral);+ }}+ />+ <InsetValueInput+ value={value.insetEnd ?? { type: "keyword", value: "auto" }}+ onChange={(insetEnd, isEphemeral) => {+ if (insetEnd === undefined) {+ onChange(undefined, true);+ return;+ }+ onChange({ ...value, insetEnd }, isEphemeral);+ }}+ />+ </Grid>+ )}+ </Grid>+ );+};++const AnimationConfigButton = forwardRef<+ HTMLButtonElement,+ Omit<ComponentProps<typeof IconButton>, "value" | "onChange"> & {+ value: AnimationAction;+ onChange: ((value: AnimationAction, isEphemeral: boolean) => void) &+ ((value: undefined, isEphemeral: true) => void);+ }+>(({ value, onChange, ...props }, ref) => {+ const { animations: defaultAnimations, ...defaultValue } = defaultActionValue;+ const { animations, ...newValue } = value;+ return (+ <Tooltip content="Advanced transform options">+ <IconButton+ {...props}+ ref={ref}+ variant={isEqual(defaultValue, newValue) ? "default" : "local"}+ onClick={(event) => {+ if (event.altKey) {+ onChange(defaultActionValue, false);+ return;+ }+ props.onClick?.(event);+ }}+ >+ <EllipsesIcon />+ </IconButton>+ </Tooltip>+ );+});+export const AnimationSection = ({animationAction,onChange,@@ -214,15 +373,6 @@ export const AnimationSection = ({) => boolean | undefined;selectedBreakpointId: string;}) => {- const fieldIds = useIds([- "type",- "subject",- "source",- "insetStart",- "insetEnd",- "debug",- ] as const);-const { prop } = animationAction;const value: AnimationAction =@@ -245,180 +395,27 @@ export const AnimationSection = ({return (<Grid css={{ paddingBottom: theme.panel.paddingBlock }}>- <Grid- gap={2}- align={"center"}- css={{- gridTemplateColumns: "1fr auto",- padding: theme.panel.paddingInline,- }}- >- <FieldLabel description="Even if its off, you can preview the animation by selecting the item in the instance.">- Run on canvas- </FieldLabel>- <Tooltip content={value.isPinned ? "Off" : "On"}>- <Switch- checked={value.isPinned ?? false}- onCheckedChange={(isPinned) => {- handleChange({ ...value, isPinned }, false);- }}- />- </Tooltip>- </Grid>-- <Separator />-- <Box css={{ height: theme.panel.paddingBlock }} />- <Grid gap={2} css={{ paddingInline: theme.panel.paddingInline }}>- <Grid gap={1} align={"center"} css={{ gridTemplateColumns: "1fr 1fr" }}>- <FieldLabel description="Type of the timeline defines how the animation is triggered.">- Type+ <Grid gap={2} css={{ padding: theme.panel.paddingInline }}>+ <Grid gap={2} align="center" css={{ gridTemplateColumns: "1fr auto" }}>+ <FieldLabel description="Even if its off, you can preview the animation by selecting the item in the instance.">+ Run on canvas</FieldLabel>- <Select- id={fieldIds.type}- options={animationTypes}- getLabel={humanizeString}- value={value.type}- getDescription={(animationType: AnimationAction["type"]) => (- <Box css={{ width: theme.spacing[28] }}>- {animationTypeDescription[animationType]}- </Box>- )}- onChange={(typeValue) => {- handleChange(- { ...value, type: typeValue, animations: [] },- false- );- }}- />- </Grid>-- <Grid gap={1} align={"center"} css={{ gridTemplateColumns: "1fr 1fr" }}>- <FieldLabel description="Axis determines whether an animation progresses based on an element’s visibility along the horizontal or vertical direction.">- Axis- </FieldLabel>- <ToggleGroup- css={{ justifySelf: "end" }}- type="single"- value={convertAxisToXY(value.axis ?? ("y" as const))}- onValueChange={(axis: keyof typeof animationAxisDescription) => {- handleChange({ ...value, axis: convertAxisToXY(axis) }, false);- }}- >- {Object.entries(animationAxisDescription).map(- ([key, { icon, label, description }]) => (- <Tooltip- key={key}- variant="wrapped"- content={- <Grid gap={1}>- <Text variant={"titles"}>{label}</Text>- <Text>{description}</Text>- </Grid>- }- >- <ToggleGroupButton value={key}>{icon}</ToggleGroupButton>- </Tooltip>- )- )}- </ToggleGroup>- </Grid>-- {value.type === "scroll" && (- <Grid- gap={1}- align={"center"}- css={{ gridTemplateColumns: "1fr 1fr" }}- >- <FieldLabel description="The scroll source is the element whose scrolling behavior drives the animation's progress.">- Scroll Source- </FieldLabel>- <Select- id={fieldIds.source}- options={animationSources}- getLabel={humanizeString}- value={value.source ?? "nearest"}- getDescription={(- animationSource: NonNullable<AnimationActionScroll["source"]>- ) => (- <Box css={{ width: theme.spacing[28] }}>- {animationSourceDescriptions[animationSource]}- </Box>- )}- onChange={(source) => {- handleChange({ ...value, source }, false);- }}- />- </Grid>- )}-- {value.type === "view" && (- <Grid- gap={1}- align={"center"}- css={{ gridTemplateColumns: "1fr 1fr" }}- >- <FieldLabel description="The subject is the element whose visibility determines the animation’s progress.">- Subject- </FieldLabel>- <SubjectSelect- id={fieldIds.subject}- value={value}- onChange={handleChange}- />- </Grid>- )}-- {value.type === "view" && (- <Grid- gap={1}- align={"center"}- css={{ gridTemplateColumns: "1fr 1fr" }}- >- <FieldLabel description={insetDescription}>- {value.axis === "inline" || value.axis === "x"- ? "Left Inset"- : "Top Inset"}- </FieldLabel>- <FieldLabel description={insetDescription}>- {value.axis === "inline" || value.axis === "x"- ? "Right Inset"- : "Bottom Inset"}- </FieldLabel>- <InsetValueInput- id={fieldIds.insetStart}- value={value.insetStart ?? { type: "keyword", value: "auto" }}- onChange={(insetStart, isEphemeral) => {- if (insetStart === undefined) {- handleChange(undefined, isEphemeral);- return;- }-- handleChange({ ...value, insetStart }, isEphemeral);+ <Tooltip content={value.isPinned ? "Off" : "On"}>+ <Switch+ checked={value.isPinned ?? false}+ onCheckedChange={(isPinned) => {+ handleChange({ ...value, isPinned }, false);}}/>- <InsetValueInput- id={fieldIds.insetEnd}- value={value.insetEnd ?? { type: "keyword", value: "auto" }}- onChange={(insetEnd, isEphemeral) => {- if (insetEnd === undefined) {- handleChange(undefined, isEphemeral);- return;- }-- handleChange({ ...value, insetEnd }, isEphemeral);- }}- />- </Grid>- )}+ </Tooltip>+ </Grid>- <Grid gap={1} align={"center"} css={{ gridTemplateColumns: "2fr 1fr" }}>+ <Grid gap={2} align="center" css={{ gridTemplateColumns: "1fr auto" }}><FieldLabel description="Debug mode shows animation progress on canvas in design mode only.">Debug</FieldLabel><Switchcss={{ justifySelf: "end" }}- id={fieldIds.debug}checked={value.debug ?? false}onCheckedChange={(debug) => {handleChange({ ...value, debug }, false);@@ -426,8 +423,22 @@ export const AnimationSection = ({/></Grid></Grid>++ <Separator />+<Grid gap={2}><AnimationsSelect+ action={+ <FloatingPanel+ title="Advanced Animation"+ placement="bottom"+ content={+ <AnimationConfig value={value} onChange={handleChange} />+ }+ >+ <AnimationConfigButton value={value} onChange={handleChange} />+ </FloatingPanel>+ }value={value}onChange={handleChange}isAnimationEnabled={isAnimationEnabled}diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsxindex ad07b651ab..720d8ebf18 100644--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsx+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsx@@ -1,4 +1,4 @@-import { useState, useMemo } from "react";+import { useState, useMemo, type ReactNode } from "react";import {theme,DropdownMenu,@@ -21,6 +21,7 @@ import {SectionTitleButton,SectionTitle,SectionTitleLabel,+ Flex,} from "@webstudio-is/design-system";import {EyeClosedIcon,@@ -35,7 +36,6 @@ import type {} from "@webstudio-is/sdk";import { newScrollAnimations } from "./new-scroll-animations";import { newViewAnimations } from "./new-view-animations";-import { useIds } from "~/shared/form-utils";import { AnimationPanelContent } from "./animation-panel-content";import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";@@ -48,6 +48,7 @@ const newAnimationsPerType: {};type AnimationsSelectProps = {+ action?: ReactNode;value: AnimationAction;onChange: ((value: unknown, isEphemeral: boolean) => void) &((value: undefined, isEphemeral: true) => void);@@ -60,13 +61,12 @@ type AnimationsSelectProps = {const floatingPanelOffset = { alignmentAxis: -100 };export const AnimationsSelect = ({+ action,value,onChange,isAnimationEnabled,selectedBreakpointId,}: AnimationsSelectProps) => {- const fieldIds = useIds(["addAnimation"] as const);-const [newAnimationHint, setNewAnimationHint] = useState<string | undefined>(undefined);@@ -101,63 +101,63 @@ export const AnimationsSelect = ({<SectionTitlecollapsible={false}suffix={- <DropdownMenu>- <DropdownMenuTrigger asChild>- <SectionTitleButton- prefix={<PlusIcon />}- tabIndex={0}- id={fieldIds.addAnimation}- />- </DropdownMenuTrigger>- <DropdownMenuContent- sideOffset={Number.parseFloat(rawTheme.spacing[5])}- css={{ width: theme.spacing[25] }}- >- {newAnimations.map((animation, index) => (- <DropdownMenuItem- key={index}- onSelect={() => {- handleChange(- {- ...value,- animations: value.animations.concat(animation),- },- false- );- }}- onFocus={() => setNewAnimationHint(animation.description)}- onBlur={() => setNewAnimationHint(undefined)}- >- {animation.name}- </DropdownMenuItem>- ))}+ <Flex gap="1" align="center">+ {action}+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <SectionTitleButton prefix={<PlusIcon />} tabIndex={0} />+ </DropdownMenuTrigger>+ <DropdownMenuContent+ sideOffset={Number.parseFloat(rawTheme.spacing[5])}+ css={{ width: theme.spacing[25] }}+ >+ {newAnimations.map((animation, index) => (+ <DropdownMenuItem+ key={index}+ onSelect={() => {+ handleChange(+ {+ ...value,+ animations: value.animations.concat(animation),+ },+ false+ );+ }}+ onFocus={() => setNewAnimationHint(animation.description)}+ onBlur={() => setNewAnimationHint(undefined)}+ >+ {animation.name}+ </DropdownMenuItem>+ ))}- <DropdownMenuSeparator />+ <DropdownMenuSeparator />- <DropdownMenuItem css={{ display: "grid" }} hint>- {newAnimations.map(({ description }, index) => (+ <DropdownMenuItem css={{ display: "grid" }} hint>+ {newAnimations.map(({ description }, index) => (+ <Box+ css={{+ gridColumn: "1",+ gridRow: "1",+ visibility: "hidden",+ }}+ key={index}+ >+ {description}+ </Box>+ ))}<Boxcss={{gridColumn: "1",gridRow: "1",- visibility: "hidden",}}- key={index}>- {description}+ {newAnimationHint ??+ "Add new or select existing animation"}</Box>- ))}- <Box- css={{- gridColumn: "1",- gridRow: "1",- }}- >- {newAnimationHint ?? "Add new or select existing animation"}- </Box>- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ </Flex>}><SectionTitleLabel>Animations</SectionTitleLabel>diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsxindex 067f7859d9..c635e79f88 100644--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsx+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/subject-select.tsx@@ -74,12 +74,10 @@ const initSubjects = () => {export const SubjectSelect = ({value,onChange,- id,}: {value: AnimationAction;onChange: ((value: AnimationAction, isEphemeral: boolean) => void) &((value: undefined, isEphemeral: true) => void);- id: string;}) => {const [subjects] = useState(() => initSubjects());@@ -89,7 +87,6 @@ export const SubjectSelect = ({return (<Select- id={id}options={subjects.map((subject) => subject.value)}value={value.subject ?? "self"}getLabel={(subject) =>diff --git a/packages/sdk-components-animation/private-src b/packages/sdk-components-animation/private-srcindex 19489d0c2d..0ed6ac0869 160000--- a/packages/sdk-components-animation/private-src+++ b/packages/sdk-components-animation/private-src@@ -1 +1 @@-Subproject commit 19489d0c2dbe6d8596e262d1e8e4173aff407556+Subproject commit 0ed6ac0869eb315433c6f0f6724c9f4ab19ff43a