solid-transition-size
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published
Solid Transition Size

SolidJS utility which makes it possible to transition the width and height of elements that don't have a fixed size applied.

Features

  • Works with any CSS transition configuration
  • Specify which dimension to observe (width, height, or both)
  • Uses a ResizeObserver to detect changes in the size of the element

Usage

The utility returns two signals: transitioning and transitionSize. transitioning can be used to know when the transition is happening, and transitionSize returns the fixed size of the element while transitioning. You have to use it to style the element you want to transition.

import createTransitionSize from 'solid-transition-size';

For a very simple example we can take the <details> element and transition the height when it is toggled:

const Details = () => {
  const [ref, setRef] = createSignal<HTMLElement | null>(null)
  const { transitionSize } = createTransitionSize({
    element: ref,
    dimension: 'height',
  })

  const height = () => {
    if (!transitionSize()) return undefined
    return transitionSize() + 'px'
  }

  return (
    <details
      ref={setRef}
      class="transition-[height]"
      style={{
        height: height(),
      }}
    >
      <summary>Show detail</summary>
      Detail
    </details>
  )
}

Further Reading

This utility is from the maintainers of corvu, a collection of unstyled, accessible and customizable UI primitives for SolidJS. It is also documented in the corvu docs under Transition Size.

Package Sidebar

Install

npm i solid-transition-size

Weekly Downloads

215

Version

0.1.1

License

MIT

Unpacked Size

9.03 kB

Total Files

5

Last publish

Collaborators

  • giyomoon