Skip to content

useToggleMotion

@hua-labs/hua/motion

bash
npm install @hua-labs/hua
tsx
import { useToggleMotion } from "@hua-labs/hua/framework";

tsx
const { ref, style, isVisible, toggle } = useToggleMotion();

return (
  <>
    <button onClick={toggle}>Toggle</button>
    <div ref={ref} style={style}>
      {isVisible ? 'Visible content' : 'Hidden'}
    </div>
  </>
);

durationnumber300Animation duration in milliseconds
delaynumber0Delay before animation starts
easingstring"ease-in-out"CSS easing function

refRefObject<T | null>Ref to attach to element
styleCSSPropertiesDeclarative animated style (opacity, translateY, scale, transition)
isVisiblebooleanCurrent visibility state
isAnimatingbooleanWhether animation is in progress
progressnumberAnimation progress (0 or 1)
toggle() => voidToggle between show/hide
show() => voidShow the element (translateY + scale in)
hide() => voidHide the element (translateY + scale out)
start() => voidStart the show animation
stop() => voidStop current animation
reset() => voidReset to initial hidden state