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

spaccordion

v1.0.2

Published

a simple headless accordion

Downloads

3

Readme

Spaccordion

Setup

npm install spaccordion

Minimum Markup

The outermost parent needs a class of .spaccordion. Within it are the two parts we will need: the .spa_head and the .spa_content. The head is the always visible part where the button lives and the content is the part that will be toggled.

Within .spa_head you need a button with an attribute of aria-expanded="true|false". This is what what spaccordion will attach the even listener to and is used to determine the state of the item. That means if you want it open by default then set this to true. FYI the button does not need to be a direct child of .spa_head it just needs to be in there somewhere.

Optionally within .spa_head you can have something with a class of .spa_icon. This is meant for things like chevrons and all it does is rotate 180deg when the expanded state is true. This is optional and can go anywhere in .spa_head including the button.

.spa_content you can put pretty much whatever in there. I just wouldn't recommend doing any styling to the actual .spa_content div. if you need to style up the whole inside I would just wrap everything in another div and style that. Messing with things like display or sizing or even padding can mess everything up.

<div id="spaccordion_id" class="spaccordion">
	<div class="spa_item">
		<div class="spa_head">
			<button aria-expanded="false">Button Text</button>
		</div>

		<div class="spa_content">
			<p>This will all be hidden until the button is clicked</p>
		</div>
	</div>
</div>

Init With JS

Just copy this code and add your own id or HTMLElement directly and you are off to the races.

import Spaccordion from 'spaccordion'

const my_spaccordion = new Spaccordion(`#spaccordion_id`)

Options

You can add an optional options object as a second argument if you so choose.

import Spaccordion from 'spaccordion'

const my_spaccordion = new Spaccordion(`#spaccordion_id`, {
	break_above: 1000,
	break_below: 300,
	duration: 500,
	auto_close: true,
	classes: {
		head: 'new-head',
		content: 'new-content',
		item: 'new-item',
		icon: 'new-icon'
	}
})

Options

| Option | Type | Description | Default Value | | --- | ----------- | ------- | -- | | break_above | number | When given a value it will destroy the spaccordion if the window gets wider than that number | null | break_below | number | Same as break_above but it goes the other way. duh | null duration | number | The speed in milliseconds the animation will take | 300 auto_close | boolean | If set to true, spaccordion will automatically close any other open items when a new item is expanded. | false classes | object | each required class can be changed in case of conflicts or personal preference. You can change one or all or whatever you want. You do you. |