Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

solid-collapse

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solid-collapse

Tiny and performant collapse component for SolidJS.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
494
decreased by-14.97%
Maintainers
1
Weekly downloads
 
Created
Source

npm GitHub Workflow Status npm bundle size

Solid Collapse

Tiny and performant collapse component for SolidJS.

Demo and examples


:jigsaw: API

PropDescriptionTypeDefaultRequired
valueBoolean value to control collapsebooleantrue:white_check_mark:
classClass with a (height)transition propertystring'':white_check_mark:
asElement tag to render instead of divstringdiv:x:
onExpandedCallback on expand transition completed.() => void() => {}:x:
onCollapsedCallback on collapse transition completed() => void() => {}:x:

id, role and aria-labelledby are also supported.


:hammer: Installation

yarn add solid-collapse
# npm i -S solid-collapse
# pnpm add solid-collapse

:lollipop: Usage

1. In a CSS file:

.my-transition {
  transition: height 300ms cubic-bezier(0.65, 0, 0.35, 1);
}

2. In a component file:

import { createSignal } from 'solid-js';
import { Collapse } from 'solid-collapse';

const App = () => {
  const [isExpanded, setIsExpanded] = createSignal(false);

  return (
    <div>
      <button onClick={() => setIsExpanded(!isExpanded())}>Expand me</button>
      <Collapse value={isExpanded()} class="my-transition">
        <p class="my-content-class">
          I am a bunch of collapsed text that wants to be expanded
        </p>
      </Collapse>
    </div>
  );
};

:clock1: Auto Duration

Solid Collapse automatically calculates the optimal duration according to the content height. You can opt-it by referencing the variable --sc-auto-duration in your transition property:

.my-transition {
  transition: height var(--sc-auto-duration) cubic-bezier(0.65, 0, 0.35, 1);
}

:cyclone: For loops, accordions

Please check the examples on the demo website.


:no_mouth: Caveats

  1. Assigning a ref to Collapse is not possible. If you need to access its DOM node, you can call document.getElementById inside an onMount callback.

  2. You will have to make your UI compliant by manually implementing ARIA practices. Don't worry any example shows how to do that.


:dvd: License

MIT Licensed. Copyright (c) Simone Mastromattei 2022.

Keywords

FAQs

Package last updated on 26 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc