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: Use ordinary range UI for scroll animations (#5152)

Ivan Starkov1ac1d46e0a62
diff --git a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx
index 75d099c951..606f2123b0 100644
--- a/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx
+++ b/apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx
@@ -422,15 +422,19 @@ export const AnimationPanelContent = ({
() => endRangeValue === undefined
);
- const timelineRangeDescriptions =
- type === "scroll" ? scrollTimelineRangeName : viewTimelineRangeName;
+ const isScrollAnimation = type === "scroll";
+
+ const timelineRangeDescriptions = isScrollAnimation
+ ? scrollTimelineRangeName
+ : viewTimelineRangeName;
const timelineRangeNames = Object.keys(timelineRangeDescriptions);
const isRangeEndEnabled = value.timing.duration === undefined;
- const animationSchema =
- type === "scroll" ? scrollAnimationSchema : viewAnimationSchema;
+ const animationSchema = isScrollAnimation
+ ? scrollAnimationSchema
+ : viewAnimationSchema;
const handleChange = (rawValue: unknown, isEphemeral: boolean) => {
if (rawValue === undefined) {
@@ -583,59 +587,61 @@ export const AnimationPanelContent = ({
<FieldLabel description="When the animation ends, based on how much of the subject is visible">
Range End
</FieldLabel>
- <ToggleGroup
- value={
- isAdvancedRangeEnd ? "advanced" : (endRangeValue ?? "advanced")
- }
- type="single"
- >
- {simplifiedEndRanges.map(
- ([toggleValue, icon, range, description], index) => (
- <Tooltip
- key={toggleValue}
- content={`The animation ends ${description}`}
- variant="wrapped"
- >
- <ToggleGroupButton
- disabled={
- !isRangeEndEnabled ||
- (!isAdvancedRangeStart && index < startRangeIndex)
- }
- value={toggleValue}
- onClick={() => {
- setIsAdvancedRangeEnd(false);
- handleChange(
- {
- ...value,
- timing: {
- ...value.timing,
- rangeStart: value.timing.rangeStart,
- rangeEnd: range,
- },
- },
- false
- );
- }}
+ {!isScrollAnimation && (
+ <ToggleGroup
+ value={
+ isAdvancedRangeEnd ? "advanced" : (endRangeValue ?? "advanced")
+ }
+ type="single"
+ >
+ {simplifiedEndRanges.map(
+ ([toggleValue, icon, range, description], index) => (
+ <Tooltip
+ key={toggleValue}
+ content={`The animation ends ${description}`}
+ variant="wrapped"
>
- {icon}
- </ToggleGroupButton>
- </Tooltip>
- )
- )}
-
- <Tooltip content="Set custom range">
- <ToggleGroupButton
- disabled={!isRangeEndEnabled}
- onClick={() => {
- setIsAdvancedRangeEnd(true);
- }}
- value="advanced"
- >
- <EllipsesIcon />
- </ToggleGroupButton>
- </Tooltip>
- </ToggleGroup>
- {isAdvancedRangeEnd && (
+ <ToggleGroupButton
+ disabled={
+ !isRangeEndEnabled ||
+ (!isAdvancedRangeStart && index < startRangeIndex)
+ }
+ value={toggleValue}
+ onClick={() => {
+ setIsAdvancedRangeEnd(false);
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ rangeStart: value.timing.rangeStart,
+ rangeEnd: range,
+ },
+ },
+ false
+ );
+ }}
+ >
+ {icon}
+ </ToggleGroupButton>
+ </Tooltip>
+ )
+ )}
+
+ <Tooltip content="Set custom range">
+ <ToggleGroupButton
+ disabled={!isRangeEndEnabled}
+ onClick={() => {
+ setIsAdvancedRangeEnd(true);
+ }}
+ value="advanced"
+ >
+ <EllipsesIcon />
+ </ToggleGroupButton>
+ </Tooltip>
+ </ToggleGroup>
+ )}
+ {(isScrollAnimation || isAdvancedRangeEnd) && (
<Grid
css={{
gridColumn: "2 / -1",
@@ -739,61 +745,63 @@ export const AnimationPanelContent = ({
Range Start
</FieldLabel>
- <ToggleGroup
- value={
- isAdvancedRangeStart
- ? "advanced"
- : (startRangeValue ?? "advanced")
- }
- type="single"
- >
- {simplifiedStartRanges.map(
- ([toggleValue, icon, range, description], index) => (
- <Tooltip
- key={toggleValue}
- content={`The animation starts ${description}`}
- variant="wrapped"
- >
- <ToggleGroupButton
+ {!isScrollAnimation && (
+ <ToggleGroup
+ value={
+ isAdvancedRangeStart
+ ? "advanced"
+ : (startRangeValue ?? "advanced")
+ }
+ type="single"
+ >
+ {simplifiedStartRanges.map(
+ ([toggleValue, icon, range, description], index) => (
+ <Tooltip
key={toggleValue}
- value={toggleValue}
- onClick={() => {
- setIsAdvancedRangeStart(false);
- handleChange(
- {
- ...value,
- timing: {
- ...value.timing,
- rangeStart: range,
- rangeEnd:
- endRangeIndex < index
- ? simplifiedEndRanges[index][2]
- : value.timing.rangeEnd,
- },
- },
- false
- );
- }}
+ content={`The animation starts ${description}`}
+ variant="wrapped"
>
- {icon}
- </ToggleGroupButton>
- </Tooltip>
- )
- )}
-
- <Tooltip content="Set custom range">
- <ToggleGroupButton
- onClick={() => {
- setIsAdvancedRangeStart(true);
- }}
- value="advanced"
- >
- <EllipsesIcon />
- </ToggleGroupButton>
- </Tooltip>
- </ToggleGroup>
-
- {isAdvancedRangeStart && (
+ <ToggleGroupButton
+ key={toggleValue}
+ value={toggleValue}
+ onClick={() => {
+ setIsAdvancedRangeStart(false);
+ handleChange(
+ {
+ ...value,
+ timing: {
+ ...value.timing,
+ rangeStart: range,
+ rangeEnd:
+ endRangeIndex < index
+ ? simplifiedEndRanges[index][2]
+ : value.timing.rangeEnd,
+ },
+ },
+ false
+ );
+ }}
+ >
+ {icon}
+ </ToggleGroupButton>
+ </Tooltip>
+ )
+ )}
+
+ <Tooltip content="Set custom range">
+ <ToggleGroupButton
+ onClick={() => {
+ setIsAdvancedRangeStart(true);
+ }}
+ value="advanced"
+ >
+ <EllipsesIcon />
+ </ToggleGroupButton>
+ </Tooltip>
+ </ToggleGroup>
+ )}
+
+ {(isScrollAnimation || isAdvancedRangeStart) && (
<Grid
css={{
gridColumn: "2 / -1",