3.1.0 • Published 7 years ago
sortboard v3.1.0
Sortboard
An small library for easy sorting and filtering of elements.
Sortboard is small library for sorting and filtering HTML elements which uses CSS3 matrix() and scale() transform functions. It supports RegEx filters and it's responsive by default.
:tada: View demo on Codepen
Install
yarn add sortboard --devnpm install sortboard --save-devThe UMD build is also available on unpkg.
<script src="https://unpkg.com/sortboard/src/sortboard.umd.min.js"></script>You can use the library via window.sortboard
Usage
Define some list. For example an ul with li child elements, then set your filters in each li element with the data-filter attribute. It can add several filters by element separated by whitespace.
Typescript:
import { sortboard, Sortboard, Listener } from 'sortboard'
const sb = sortboard({
container: '#mylist',
selector: 'li'
})
const onEvent: Listener = () => console.log('ok!')
sb.on('filter', onEvent)
sb.filter('programing front-end')
// Or filter using a RegEx
sb.filter(/(webdesign|illustration)/)Markup:
<ul id="mylist">
<li data-filter="programing"></li>
<li data-filter="programing back-end"></li>
<li data-filter="programing front-end UX"></li>
<li data-filter="graphic-design illustration"></li>
<li data-filter="webdesign front-end"></li>
<li data-filter="graphic-design printing"></li>
</ul>API
Options
- container : The container of elements.
- selector : The query selector for each element.
- gutter : The margin for each element defined in pixels. Default is
10pixels. - resetFilterValue : The reset filter value used by
reset()method. Default isall. - hiddenClass : Class name for hidden elements. Default is
.sortboard-hiddenclass name. - matchedClass : Class name for matched elements. Default is
.sortboard-matchedclass name.
Methods
- filter( string | RegExp ) : It's string or
RegExpregular expresion pattern to filter. Which should match todata-filterattribute for each element to searching. - reset() : Reset the elements which uses
resetFilterValueoption for resetting. - sort() : Sort the element positions in the container. Sort method is called after the
filter()method and in each trigger ofwindow.resizeevent.
Events
filter
Trigger when filter is completed.
Passed params:
- matchedElements: An
arraywith all matched elements. - restElements: An
arraywith the rest (not matched) elements. - filterValue: A
stringwith the current filter value used.
sb.on('filter', (matchedElements, restElements, filterValue) => {})sort
Trigger when sort is completed.
sb.on('sort', () => {})Development
yarn startContributions
Feel free to send some pull request or issue.
License
MIT license
© 2014-present José Luis Quintana