Code Monkey home page Code Monkey logo

select-pure's Introduction

SelectPure JavaScript component

npm version gzip size brotli size npm Build Status codecov

Installation

NPM

npm i select-pure --save

Yarn

yarn add select-pure

CDN

<script src="https://unpkg.com/select-pure@latest/dist/bundle.min.js"></script>

Usage

import SelectPure from "select-pure";

new SelectPure(element, config);

`element` // Required. Either selector or HTML node.
`config` // Required. Configuration object.

Configuration

Property Required Type Description
option true Array Collection of options to be rendered. Each option consists of value, label and optional property disabled. Properties for the single option object are listed below.
classNames false Object Object with custom classNames to be used inside select. In the next major version default classNames will be removed and this property will become required.
multiple false Boolean true if multiple options can be selected.
autocomplete false Boolean Adds autocomplete input. Disabled by default.
icon false String If specified - <i></i> will be inserted inside select-pure__selected-label. Works only with multiple option set to true.
inlineIcon false HMTLElement Custom cross icon for multiple select.
value false String | Array Initially selected value. If not provided - first option will be selected. If multiple is true -- Array should be provided.
placeholder false String Placeholder for cases when value is not selected by default.
onChange false Function Callback that returns value when option is being selected. Returns Array if multiple is true.

option

Properties of a single option passed to the options Array in configuration.

Property Required Type Description
value true String Value of an option.
label true String Label of an option.
disabled false Boolean true if option is disabled. false by default.

classNames

In the next major version default classNames will be removed and this property will become required.

Property Default value Description
select "select-pure__select" Wrapper div.
dropdownShown "select-pure__select--opened" Applied to the wrapper when dropdown is shown.
multiselect "select-pure__select--multiple" Applied to the wrapper if it's a multiselect.
label "select-pure__label" Label span.
placeholder "select-pure__placeholder" Placeholder span.
dropdown "select-pure__options" Options dropdown.
option "select-pure__option" Single option.
optionDisabled "select-pure__option--disabled" Single option.
autocompleteInput "select-pure__autocomplete" Autocomplete input
selectedLabel "select-pure__selected-label" Selected label for multiselect.
selectedOption "select-pure__option--selected" Applied to option when selected.
placeholderHidden "select-pure__placeholder--hidden" Hides placeholder when the value is selected.
optionHidden "select-pure__option--hidden" Hides options that does not match autocomplete input.

API

Method Description
value() Returns currently selected value.
reset() Resets currently selected value.

Structure

select-pure/
โ””โ”€โ”€ lib/
    โ””โ”€โ”€ select-pure.min.js

TODO

  • API method for updating select.
  • Mobile select support.
  • Drop support of default classNames (starting from 1.x.x versions).
  • Drop support of default icon, support only inline SVG instead. (starting from 1.x.x versions).

License

MIT

select-pure's People

Contributors

dudyn5ky1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.