npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-collapsible

v0.3.0

Published

A collection of high-level Svelte components designed for expanding and collapsing content.

Downloads

2,382

Readme

Svelte Collapsible

A collection of high-level Svelte components designed for expanding and collapsing content. Check out the demos ...

Demo - Accordion

Demo - Basic Card

Demo - Styled Cards

Install

npm install svelte-collapsible

Collapsible Card

A collapsible card is a single, simple component that takes two slots. When a user clicks on the header slot, the body slot expands to open or shut.

<script>
    import { CollapsibleCard } from 'svelte-collapsible'
</script>

<CollapsibleCard>
    <h2 slot='header'>Header</h2>
    <p slot='body'>Body</p>
</CollapsibleCard>

Accordion

The accordion is a collection of collapsible items where at most a single item is expanded at any time. When a new item opens, it simultaneously closes any other open item. The component uses keys on the items to keep track of which one is currently open.

<script>
    import { Accordion, AccordionItem } from 'svelte-collapsible'
</script>

<Accordion>
    <AccordionItem key='a'>
        <h2 slot='header'>Header</h2>
        <p slot='body'>Body</p> 
    </AccordionItem>
    <AccordionItem key='b'>
        <h2 slot='header'>Header</h2>
        <p slot='body'>Body</p> 
    </AccordionItem>
</Accordion>

If you need to know which item is currently in the open state, you can bind to the key prop on the Accordion component. It will be null when all items are closed, or the value of associated key when an item is opened. You can also use this feature to set which item should be open when mounted.

<script>
    let key = 'a'
</script>

<Accordion bind:key>
</Accordion>

If you need control of the selected item, you can use the key prop and the on:change event to manage the state of the component externally.

You can modify the duration and easing (see CSS transition-timing-function for available options) of the collapsible section using component props.

<script>
    const duration = 0.5 // seconds
    const easing = 'linear'
</script>

<Accordion { duration } { easing } />
<CollapsibleCard { duration } { easing } />

Motivation

These elements are designed to be drop-in, ready to go, with JS functionality and some styling built-in. They are built on top of the low-level svelte-collapse action. If you need more control and flexibility, you can use this action directly to design your own collapsible components.