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

@collapsed/solid

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@collapsed/solid

![NPM Version](https://img.shields.io/npm/v/%40collapsed%2Fsolid) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40collapsed%2Fsolid)

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
0
Weekly downloads
 
Created
Source

@collapsed/solid

NPM Version npm bundle size

A Solid.js utility for creating accessible expand/collapse components. Animates the height using CSS transitions from 0 to auto.

Features

  • Handles the height of animations of your elements, auto included!
  • You control the UI - createCollapse provides the necessary props, you control the styles and the elements.
  • Accessible out of the box - no need to worry if your collapse/expand component is accessible, since this takes care of it for you!
  • No animation framework required! Simply powered by CSS animations
  • Written in TypeScript

Installation

npm install @collapsed/solid

Usage

import { createCollapse } from "@collapsed/solid";

export default function App() {
  const collapse = createCollapse();

  return (
    <main>
      <button {...collapse.getToggleProps()}>Toggle</button>
      <div {...collapse.getCollapseProps()}>
        {/* Content to be shown/hidden here */}
      </div>
    </main>
  );
}

Controlled Usage

import { createSignal } from "solid-js";
import { createCollapse } from "@collapsed/solid";

export default function App() {
  const [open, setOpen] = createSignal(false);
  const collapse = createCollapse({
    get isExpanded() {
      return open();
    },
  });

  return (
    <main>
      <button
        {...collapse.getToggleProps({
          onClick: () => setOpen((prevOpen) => prevOpen),
        })}
      >
        Toggle
      </button>
      <div {...collapse.getCollapseProps()}>
        {/* Content to be shown/hidden here */}
      </div>
    </main>
  );
}

API

createCollapse takes the following options:

interface CreateCollapseOptions {
  /** If true, the disclosure is expanded. */
  isExpanded?: boolean;
  /**
   * If true, the disclosure is expanded when it initially mounts.
   * @default false
   */
  initialExpanded?: boolean;
  /** Handler called when the disclosure expands or collapses */
  onExpandedChange?: (state: boolean) => void;
  /** Handler called at each stage of the animation. */
  onTransitionStateChange?: (
    state:
      | "expandStart"
      | "expanding"
      | "expandEnd"
      | "collapseStart"
      | "collapsing"
      | "collapseEnd",
  ) => void;
  getDisclosureElement: () => HTMLElement;
  /** Timing function for the transition */
  easing?: string;
  /**
   * Duration of the expand/collapse animation.
   * If 'auto', the duration will be calculated based on the height of the collapse element
   */
  duration?: "auto" | number;
  /** Height in pixels that the collapse element collapses to */
  collapsedHeight?: number;
}

And returns the following API:

interface CreateCollapseAPI {
  isExpanded: boolean;
  setExpanded: (updater: boolean | ((prev: boolean) => boolean)) => void;
  getToggleProps: <T extends HTMLElement>(
    props?: JSX.HTMLAttributes<T>,
  ) => JSX.HTMLAttributes<T>;
  getCollapseProps: <T extends HTMLElement>(
    props?: JSX.HTMLAttributes<T>,
  ) => JSX.HTMLAttributes<T>;
}

FAQs

Package last updated on 21 Jun 2024

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