1.0.1 • Published 6 years ago

react-fancy-select v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

react-fancy-select

Travis npm package

So you want a styled select box?

Your designer has supplied you with a awesome looking select / dropdown list, not knowing that we still can't style native selects nicely.

Solution

With react-fancy-select, you're provided a custom implementation of a select / dropdown that you can style as much as you like.

Installation

npm i react-fancy-select
yarn add react-fancy-select

Usage

import React from "react";
import FancySelect from "react-fancy-select";
import "react-fancy-select/lib/react-fancy-select.css";

const items = [{
  id: 0,
  value: 'Apple',
  text: 'Apple',
}, {
  id: 1,
  value: 'Orange',
  text: 'Orange',
}, {
  id: 2,
  value: 'Pear',
  text: 'Pear',
}];

const Component = () => (
    <FancySelect
        items={items}
        onSelection={(item) => alert(`You selected ${item.text}`)}
    />
);

Props

PropertyTypeDefaultDescription
itemsarrayundefinedarray of items
onSelectionfunctionundefinedcallback fires upon item selection with selected object as parameter
useNativebooleantrueif true, positions and hides a select element on top of the component on mobile devices to trigger native select
placeholderstringPlease select...placeholder text to display before selection
namestringnullname to give to select element if being used in a form for requests
defaultValuestringnullthe default selected value

Styling

PropertyDescription
.FancySelect__Controlthe visible select component wrapper
.FancySelect__Listthe dropdown list
.FancySelect__ListItemthe dropdown list items
.FancySelect__ListItem:hoverthe dropdown list items on hover
.FancySelect__ListItem--focusedthe dropdown list items on focus (with keyboard arrows)

Todo

  • Write additional tests.
  • In-depth browser testing.