0.0.41 • Published 6 years ago

selecton v0.0.41

Weekly downloads
11
License
BSD-3-Clause
Repository
github
Last release
6 years ago

selecton.js logo Selecton.js combines a search bar and a drop-down menu with nested child lists. It helps you to display hierarchical order within your drop-down menus. Selecton.js is completely object-based, meaning that all values are represented as objects. See example here.

Installing

If you use npm, npm install selecton. You can also download the latest release. Otherwise use unpkg to get the latest release. For example:

<script src="https://unpkg.com/selecton/build/selecton.js"></script>

For a specific version:

<script src="https://unpkg.com/selecton@version/build/selecton.js"></script>

For the minified version:

<script src="https://unpkg.com/selecton@version/build/selecton.min.js"></script>

For the css:

<link rel="stylesheet" type="text/css" href="https://unpkg.com/selecton@version/build/css/selecton-light.min.css">
<link rel="stylesheet" type="text/css" href="https://unpkg.com/selecton@version/build/css/selecton-dark.min.css">

Note: dark and light means on what background they appear better. If you want to change the styles, you should clone the repo and take a look at the sccs folder.

Import

import {default as Selecton} from 'selecton';

Build

Clone or download the repository. Run npm install to install all dependencies. To manipule the css and to make changes to the source code run npm run watch and gulp (in different tabs).

Quick-start

<!-- add css -->
<link rel="stylesheet" type="text/css" href="selecton.css" />

<!-- add container -->
<div id="selecton-container"></div>

<!-- add selecton.js -->
<script src="selecton.js"></script>

<script>
    // declare data
    var data = [{key:'A'}, {key:'B'}, {key:'C'}];

    // define order of items in the input field (optional)
    var data = ['B', 'A', 'C'];

    // create new selecton instance and pass the config as an object
    var selecton = new Selecton({
        el: '#selecton-container'
    });

    // pass the data and the order to selecton
    selecton.update(data, order);

    // listen for changes
    selecton.on('change', function(data){
        console.log(data); // only the selected items, alternatively use selecton.getData()
    });
</script>

Configuration and options

Constructor config

configdescriptionrequiredtypedefault
el css selector of element in which selecton will appearstring
keywhich property is used to bind the datafunctionfunction(d){ return d.key; }
renderInputItemrender input itemfunctionfunction(d){ return d.key; }
renderDropdownItemrender drop-down itemfunctionfunction(d){ return d.key; }
opendrop-down opens up on startbooleanfalse
showHierachyButtonshow hierarchy button in input itembooleantrue
showRemoveButtonshow remove button in input itembooleantrue

Item properties

propertydescriptionrequiredtypedefault
key this key is used to bind the the data to the DOM-element. this key has to be unique within the parent.string
colorif color is specified, the color is used to colorize the input itemstring'#1e90ff'
selectableselectable decides if the item is click-able and search-ablebooleantrue
closeddoes not show up on startbooleantrue
selectedindicated if the item is selectedbooleanfalse

The following properties are used internally by selecton.js and should not be overwritten:

propertydescriptiontype
_depth_depth level in hierarchynumber
_parent_key of parentstring
_search_search string to highlight search matchstring
_temporarilyHighlighted_property to highlight item temporarilyboolean

Methods

Each selecton instance comes with some useful methods:

selecton.update() updates the the input and the drop-down menu

selecton.on('change', callback) Listen for changes

selecton.on('keyup', callback) Listen for keyup event

selecton.getData() returns the whole data set with the computed values as objects

selecton.getSelectedItems() returns the selected items as objects

Dependencies

Selecton.js uses d3-selection for the data-binding and d3-drag for the dragging.

Browser support

Chrome, Safari, Firefox, IE11+

0.0.41

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago

0.0.38

6 years ago

0.0.37

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.32

6 years ago

0.0.31

6 years ago

0.0.30

6 years ago

0.0.29

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago