import React, { useRef } from "react"; import { useQuantityButtonAnimation } from "../../components/useQuantityButtonAnimation"; import { Toggle } from "../../components/Toggle"; import { RangeSlider } from "../../components/RangeSlider"; import { CustomSelect } from "../../components/CustomSelect"; import { HighlightableField } from "../../components/HighlightableField"; import type { BaseTabProps } from "../types"; import type { Settings } from "../../types"; export const QUANTITY_ANIMATION_OPTIONS = [ { value: "none", label: "None" }, { value: "scale", label: "Scale" }, { value: "bounce", label: "Bounce" }, { value: "pulse", label: "Pulse" }, { value: "rotate", label: "Rotate" }, { value: "wiggle", label: "Wiggle" }, { value: "squeeze", label: "Squeeze" }, { value: "swing", label: "Swing" }, { value: "jello", label: "Jello" }, { value: "tada", label: "Tada" }, { value: "rubberband", label: "Rubberband" }, { value: "magnetic", label: "Magnetic" }, { value: "bloom", label: "Bloom" }, { value: "sheen", label: "Sheen" }, { value: "pop", label: "Pop" }, { value: "glow", label: "Glow" }, { value: "tilt", label: "Tilt" }, ]; /** * Quantity button animation preview that respects the trigger settings. * Bound through the storefront runtime binder so every advertised mode * (scale included) previews with the real hover/click class contract. */ function AnimatedQuantityButton({ animation, direction, children, adminColor, ariaLabel, animateOnHover = true, animateOnClick = false, }: { animation: string; direction: "plus" | "minus"; children: React.ReactNode; adminColor: string; ariaLabel: string; animateOnHover?: boolean; animateOnClick?: boolean; }) { const buttonRef = useRef(null); const playClick = useQuantityButtonAnimation(buttonRef, { type: animation, direction, animateOnHover, animateOnClick, }); const previewColor = direction === "minus" ? `color-mix(in srgb, ${adminColor} 75%, #000)` : adminColor; return (
); } export interface QuantityAnimationsSectionProps extends BaseTabProps { navigateToField?: (target: { id: string; tabId: string; subTab?: string; }) => void; } export function QuantityAnimationsSection({ settings, setSettings, adminColor, navigateToField, }: QuantityAnimationsSectionProps) { const useCustomQuantityButtons = Boolean(settings.quantity_custom_buttons); const previewQuantityAnimateOnHover = settings.quantity_animate_on_hover !== false; const previewQuantityAnimateOnClick = Boolean( settings.quantity_animate_on_click, ); const quantityAnimationOptions = QUANTITY_ANIMATION_OPTIONS.map( (option) => option.value, ); return (

Quantity Animations

Configure animations for quantity selector +/- buttons.

{useCustomQuantityButtons && (

Quantity Animation Previews

{quantityAnimationOptions.map((anim) => { return (
+ −
{anim}
); })}

Focus, hover, or click the buttons to see the animation effects.

)} {!useCustomQuantityButtons ? (

Custom Quantity Buttons Required: Enable custom quantity buttons to access quantity animations.

) : ( <>
setSettings({ ...settings, quantity_animation_type: value as Settings["quantity_animation_type"], }) } options={QUANTITY_ANIMATION_OPTIONS} />

Controls the animation when +/- buttons are clicked in the quantity selector.

{settings.quantity_animation_type && settings.quantity_animation_type !== "none" && (

Animation Triggers

setSettings({ ...settings, quantity_animate_on_hover: checked, }) } label="Animate on Hover" description="Trigger animation when user hovers over quantity buttons." /> setSettings({ ...settings, quantity_animate_on_click: checked, }) } label="Animate on Click" description="Trigger animation when user clicks quantity buttons." />
)}
setSettings({ ...settings, disable_quantity_animations_on_mobile: checked, }) } label="Disable Quantity Animations on Mobile" description="Reduces motion for quantity controls on mobile devices for better performance." /> {!!settings.disable_quantity_animations_on_mobile && (
setSettings({ ...settings, mobile_cutoff: val }) } />
)}
)}
); }