New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

selecton

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selecton

Selecton.js combines a searchbar and a dropdown menu with nested child lists.

  • 0.0.41
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
42
decreased by-17.65%
Maintainers
1
Weekly downloads
 
Created
Source

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+

Keywords

FAQs

Package last updated on 26 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc