Jaccordion is a vanilla Javascript ES6 library with a simple API.
Jaccordion comes from the name, Jacob πΆ plus accordion
Visit https://giodelabarrera.github.io/jaccordion/ for view the storybook demo.
Using NPM scripts
start
- Run storybooktest
- Run testcoverage
- Run test coveragebuild
- Build library
npm install --save @giodelabarrera/jaccordion
UMD | ES Module | |
---|---|---|
Normal | jaccordion.js | jaccordion.esm.js |
Minified | jaccordion.min.js | --- |
Using <link>
<link rel="stylesheet" href="node_modules/@giodelabarrera/jaccordion/dist/css/jaccordion.min.css">
Using SASS @import
@import 'node_modules/@giodelabarrera/jaccordion/dist/sass/jaccordion'
<dl>
<dt>Section 1</dt>
<dd>
<p>Section 1 Content...</p>
</dd>
<dt>Section 2</dt>
<dd>
<p>Section 2 Content...</p>
</dd>
<dt>Section 3</dt>
<dd>
<p>Section 3 Content...</p>
</dd>
</dl>
Using <script>
<script src="node_modules/@giodelabarrera/jaccordion/dist/jaccordion.min.js"></script>
<script>
new Jaccordion(document.querySelector('dl')).mount()
</script>
Using ES Modules
import Jaccordion from '@giodelabarrera/jaccordion'
new Jaccordion(document.querySelector('dl')).mount()
- @default:
0
- @type:
Number
Identifier of the item that appears open by default
- @default:
false
- @type:
Boolean
Determines if there may be more than one item open
- @default:
[]
- @type:
Object[]
Entries to make items
- @default:
[object Object]
- @type:
Object
Object for make items by request
ajax: {
url: '',
processResults: function(data) {
return data
}
},
- @default:
[object Object]
- @type:
Object
Object with classes for styles
classes: {
root: 'jaccordion',
header: 'jaccordion__header',
opened: 'jaccordion__header--opened',
content: 'jaccordion__content'
}
Mount the accordion with your items. Add styles and bind events
Disable the accordion
Enable the accordion
- @param:
Number id
Toogle item (open or close)
- @param:
Number id
Indicates if a item is open
- @param:
Number id
Open item
- @param:
Number id
Close item
- @param:
Object entry
- @param:
Number entry.id
- @param:
String entry.header
- @param:
String entry.content
Append a item from entry
- @param:
Object entry
- @param:
Number entry.id
- @param:
String entry.header
- @param:
String entry.content
Prepend a item from entry
- @param:
Object entry
- @param:
Number entry.id
- @param:
String entry.header
- @param:
String entry.content
- @param:
Number referenceId
Append a item before of an item from entry
- @param:
Object entry
- @param:
Number entry.id
- @param:
String entry.header
- @param:
String entry.content
- @param:
Number referenceId
Append a item after of an item from entry
- @param:
Number id
Remove an item from id
- @param:
String event
- @param:
Function handler
Subscribe a handler to an event
Unmount the accordion. Remove styles and associated events
Jaccordion has events that occur during its methods. To add a certain behavior of your own in a certain phase you can do it using the method .on(event, handler)
.
const jaccordion = new Jaccordion(document.querySelector('dl'))
jaccordion.on('mount.after', () => {
console.log('Mount correctly!')
})
jaccordion.mount()
It is called before starting to mount the items
It is called once having mounted the items
Arguments:
{Object} item
It is called before opening the item
Arguments:
{Object} item
It is called after opening the item
Arguments:
{Object} item
It is called before closing the item
Arguments:
{Object} item
It is called after closing the item
Arguments:
{Object} item
It is called after adding new item
Arguments:
{Object} item
It is called after adding new item
Arguments:
{Object} item
It is called after adding new item
Arguments:
{Object} item
It is called after adding new item
Arguments:
{Object} item
It is called before removing the item
Arguments:
{Number} id
It is called after removing the item
It is called when it has finished unmounting
It is called before making ajax request
It is called after having finished the request of ajax
Giorgio de la Barrera https://github.com/giodelabarrera