:mechanical_leg: Tiny and performant collapse component for SolidJS.

Overview

npm GitHub Workflow Status Language grade: JavaScript npm bundle size

Solid Collapse

Tiny and performant collapse component for SolidJS.

Demo and examples


Features

  • Pure dynamic CSS height transition, no javascript animations.
  • No hidden visibility or absolute positioning hacks, just a natural block/none display behavior.
  • Minimal API: Just pass a boolean value and you're ready to go.
  • Works within loops / async loops
  • Accordion-ready - See examples
  • Super lightweight, only 600B gzipped.

🧩 API

Props Description Type Default Required
value Readonly reactive value to control collapse boolean false
class Classname with your transition string ''
as Element tag to render instead of div string div

id, role and aria-labelledby are also supported.


🔨 Installation

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

🍭 Usage

1. In a CSS file:

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

You can find a complete list of CSS easings at easings.net.

2. In a component file:

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

const App = () => {
  const [isOpen, setIsOpen] = createSignal(false);

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

⚠️ Do not style the collapse itself! Instead, style the elements inside. The class added to collapse should only have the transition property set.


🌀 For loops, accordions

Please check the examples on the demo website.


😶 Caveats

  1. Assigning a ref to Collapse is not possible. If you need to access its DOM node, you can either:

    • Call document.getElementById inside an onMount callback
    • Assign a ref to its nearest child and access the parent
  2. Rendering Collapse inside a <details> element in order to get native assistive technologies support is not possible. The browser's default behavior will prevail over the component's one, preventing necessary styles injection and transitions. You will have to make your UI compliant by manually implementing ARIA practices according to your use case.


📀 License

MIT Licensed. Copyright (c) Simone Mastromattei 2022.

You might also like...

A form management library for SolidJS that is very lightweight and simple!

solform A form management library for SolidJS that is very lightweight and simple! Why solform Very easy, fast, lightweight and powerful! It has built

Nov 15, 2022

Solidex is a list of SolidJS ecosystem resources and packages.

Solidex is a list of SolidJS ecosystem resources and packages.

Solidex The following is a list of articles, packages and other resources that focus on the SolidJS ecosystem. Solidex is a platform for listing and m

Dec 18, 2022

A SolidJS starter template with solid-labels, solid-sfc and solid-styled

solid-sfc-styled-labels-starter This is a SolidJS starter template for easily setting up solid-sfc, solid-styled and solid-labels. Development Install

Mar 25, 2022

Unstyled, dev error overlays for SolidJS

Unstyled, dev error overlays for SolidJS

solid-error-overlay Unstyled, headless Error Overlay for SolidJS Install npm i solid-error-overlay yarn add solid-error-overlay pnpm add solid-error-o

Dec 29, 2022

A modern solidjs based UI library ~ it is very lightweight!

🚧 目前正在开发中,敬请期待~ cerises-ui 一个现代的基于 solidjs 的 UI 库~它是非常轻量级的! 官网:https://cerises-ui.edoc.wiki 目前计划组件 组件 说明 认领人 进度 Review & Unit Test Button、ButtonGroup

Jul 19, 2022

Utility to track the boundaries of html-elements in SolidJS

solid-boundaries Helps you to track the size and position of html-elements in solid-js. What does it do? See it in action here, or see it on CodeSandb

Jan 6, 2023

A SolidJS template built with Hope-UI

solid-hope-admin 名称 简介 solid JavaScript框架 hope-ui UI组件库 solid-app-router 路由 vite-plugin-pages 自动生成文件路由 query-string 解析URL地址 steeze-ui/solid-icon 图标 功能

Dec 13, 2022

A library of high-quality primitives that help you build accessible user interfaces with SolidJS.

Solid Aria A library of high-quality primitives that help you build accessible user interfaces with SolidJS. Primitives @solid-aria/primitives - Expor

Jan 7, 2023

Cache Solidjs resources by key (derived from the resource source)

Solid Cached Resource (Experimental) Create a solid resource attached to a cached state by a unique key. Heavily inspired by react-query, but for soli

Dec 31, 2022
Releases(v1.1.0)
  • v1.1.0(Nov 26, 2022)

    v1.1.0

    What's new

    • Solid Collapse now calculates the optimal duration according to your 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);
    }
    
    • onCollapsed, onExpanded callbacks are now available as props.

    What's improved

    • margin: 0, padding: 0 and border: 0 none are now always enforced on the collapse element.

    Update now: yarn add vue-collapsed@latest

    Source code(tar.gz)
    Source code(zip)
Owner
Simone
All frontend stuff
Simone
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A lightweight, performant, and simple-to-use wrapper component to stick section headers to the top when scrolling brings them to top

A lightweight, performant, and simple-to-use wrapper component to stick section headers to the top when scrolling brings them to top

Mayank 7 Jun 27, 2022
A lightweight SolidJS component for building interactive node-based diagrams and graphs.

Convert Your Ideas To Graphs With Solid Graph! Solid Graph A lightweight and minimal Solid component for building interactive graphs and node-based ed

Ali Sal 26 Dec 8, 2022
A lightweight SolidJS component for building interactive node-based diagrams and graphs.

Convert Your Ideas To A Simple And Excitig Journay With Odysea! Odysea A lightweight and minimal Solid component for building interactive graphs and n

Ali Sal 21 Aug 15, 2022
A low-feature, dependency-free and performant test runner inspired by Rust and Deno

minitest A low-feature, dependency-free and performant test runner inspired by Rust and Deno Simplicity: Use the mt test runner with the test function

Sondre Aasemoen 4 Nov 12, 2022
Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode characters, numbers, dates, etc.

fast-natural-order-by Lightweight (< 2.3kB gzipped) and performant natural sorting of arrays and collections by differentiating between unicode charac

Shelf 5 Nov 14, 2022
Performant WebSocket Server & Client

Socketich ?? Performant WebSocket server and persistent client powered by uWebSockets.js and PersistentWebSocket Install npm i @geut/socketich Usage S

GEUT 6 Aug 15, 2022
Quick T3 Stack with SvelteKit for rapid deployment of highly performant typesafe web apps.

create-t3svelte-app Just Build npx create-t3svelte-app Outline Get Building npm yarn More Info ?? Early Version Note Prisma Requirements Available Tem

Zach 85 Dec 26, 2022