3.0.0 • Published 5 years ago

react-styled-select v3.0.0

Weekly downloads
739
License
UNLICENSED
Repository
github
Last release
5 years ago

Issues License Build Status NPM

react-styled-select

Up to date with react/react-dom 16.2.0 and styled-components 4.1.1

ATTENTION: Work in Progress (sorry about that!)

This project was built with styled-components and is a "rethink" of the awesome project react-select. But what the differences between react-select and this project?

  • Lightweight!
  • It don`t force you to load any external css.
  • Works with css-modules concept and not with global class names. Here has a good discussion about this problem (here).
  • CSS Variables: Very easy to customize for your need.
  • Shadow DOM: If you has or had problems with input fields globally stylized you can "encapsulate" your component using this awesome feature.

Installation

npm install react-styled-select --save

Demo

http://agutoli.github.io/

Example Usage

import React from 'react'
import Select from 'react-styled-select'

class MyComp extends React.Component {
  render() {
    const options = [
      { label: "One", value: 1},
      { label: "Two", value: 2},
    ]
    return (
      <Select
        options={options}
        onOpen={myOpenFunc}
        onChange={myChangeFunc}
        classes={{
          selectValue: 'my-custom-value',
          selectArrow: 'my-custom-arrow'
        }}
      />
    )
  }
}

Opptions

PropertyTypeDefaultDescription
classesobjectundefinedYou can specify className for each element. Possible values: selectArrow, selectArrowZone, selectClear, selectClearZone, selectControl, selectInput, selectInputField, selectMenu, selectMenuOuter, selectMultiValueWrapper, selectOption, selectPlaceholder, selectValue, selectValueLabel
clearableboolfalseshould it be possible to reset value
disabledboolfalsedisables every events over the component
multiboolfalsemulti values support
virtualizedboolfalse(NEW) efficiently rendering large lists options
virtualizedMaxHeightnumber198(NEW) height of option menu
virtualizedOptionHeightnumber38(NEW) Height of each options
searchablebooltruewhether to enable searching feature or not
placeholderstringSelect...The short hint is displayed in the input field before the user enters a value
loadOptionsfunctionundefinedfunction that returns a promise or calls a callback with the options: function(input, [callback])
classNamestringundefinedRoot element className
valueanyundefinedIf you want to specify a pre selected value
optionsarray[]List of values. Ex. [{"label": "Foo", value: "foo"}]
onOpenfunctionundefinedIt calls when open outer menu
onChangefunctionundefinedIt calls when change selected value
onValueClickfunctionundefinedIt calls when click over a option value
closeMenuOnSelectfunctionundefinedIt calls when click over a option value
onInputClearfunctionundefinedIt calls when input is cleared
valueRendererfunctionundefinedfunction which returns a custom way to render the value selected function (option) {}
optionRendererfunctionundefinedfunction which returns a custom way to render the options in the menu (option) {}

Async options (NEW)

Very similar with react-select API.

var getOptions = function(input, callback) {
  setTimeout(function() {
    callback(null, {
      options: [
        { value: 'one', label: 'One' },
        { value: 'two', label: 'Two' }
      ]
    });
  }, 500);
};

<Select.Async
    loadOptions={getOptions}
/>

Custom appearance with CSS Variebles

Multi Select (NEW)

npm.io

Default

npm.io

Customized

npm.io

  • Your react file ex. MyForm.jsx
class MyForm extends React.Component {
  render() {
    return(){
      <Select className="dark-theme" options={[...]} />
    }
  }
}
  • Your project CSS file ex. mysite.css
.dark-theme {
  --styled-select-placeholder__color: #999;
  --styled-select__color: white;
  --styled-select__background-color: #555;
  --styled-select__border-color: black;
  --styled-select__border-width: 3px;
  --styled-select__border-radius: 5px;

  --styled-select-menu-outer__margin: 10px 0 0 0;
  --styled-select-menu-outer__padding: 0;
  --styled-select-menu-outer__background-color: #555;
  --styled-select-menu-outer__border-color: black;
  --styled-select-menu-outer__border-style: solid;
  --styled-select-menu-outer__border-width: 3px;

  --styled-select-option__background-color: #444;

  --styled-select-option__color--focused: #eee;
  --styled-select-option__background-color--focused: #333;

  --styled-select-option__color--selected: #eee;
  --styled-select-option__background-color--selected: #444;
}

Available CSS variables

Inspiration

This project was based on react-select.

Collaborators

Special thanks to:

License

The MIT License (MIT)

Copyright (c) 2017-2018 Bruno Agutoli

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3.0.0

5 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

1.0.3-beta

7 years ago

1.0.2-beta

7 years ago

1.0.1-beta

7 years ago

1.0.0-beta

7 years ago

2.2.6-beta

7 years ago

2.2.5-beta

7 years ago

2.2.3-beta

8 years ago

2.2.2-beta

8 years ago

2.2.1-beta

8 years ago

2.2.0-beta

8 years ago

2.1.2-alpha

8 years ago

2.1.1-alpha

8 years ago

2.1.0-alpha

8 years ago

2.0.1-alpha

8 years ago

2.0.0-alpha

8 years ago

0.0.17-alpha

8 years ago

0.0.16-alpha

8 years ago

0.0.15-alpha

8 years ago

0.0.14-alpha

8 years ago

0.0.13-alpha

8 years ago

0.0.12-alpha

8 years ago

0.0.11-alpha

8 years ago

0.0.10-alpha

8 years ago

0.0.9-alpha

8 years ago

0.0.8-alpha

8 years ago

0.0.7-alpha

8 years ago

0.0.6-alpha

8 years ago

0.0.5-alpha

8 years ago

0.0.4-alpha

8 years ago

0.0.3-alpha

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago