1.0.2 • Published 12 months ago

spaccordion v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

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

OptionTypeDescriptionDefault Value
break_abovenumberWhen given a value it will destroy the spaccordion if the window gets wider than that numbernull
break_belownumberSame as break_above but it goes the other way. duhnull
durationnumberThe speed in milliseconds the animation will take300
auto_closebooleanIf set to true, spaccordion will automatically close any other open items when a new item is expanded.false
classesobjecteach 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.
1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago