1.1.3 • Published 1 year ago

@gabrieljmj/react-selector v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@gabrieljmj/react-selector

Custom select input for React with search field.

NPM JavaScript Style Guide GitHub

Install

npm install --save @gabrieljmj/react-selector

Preview

Click here to see a preview.

Usage

import { useState } from 'react'
import Selector from '@gabrieljmj/react-selector'
import '@gabrieljmj/react-selector/dist/index.css' // Include styles

export default function MyApp() {
  const [color, setColor] = useState(undefined);
  const options = [
    { value: 'red', label: 'Red' },
    { value: 'black', label: 'Black' },
    { value: 'green', label: 'Green' },
  ];

  const handleSubmit = (e) => {
      // ...
  };

  return (
    <form onSubmit={hanldeSubmit}>
        <Selector
          label="Pick a color"
          options={options}
          value={color}
          onChange={setColor}
          htmlInputAttributes={{
            name: 'color',
          }}
        />

        <button type="submit">Save</button>
    </form>
  );
}

Props

PropDefault valueRequiredTypeDescription
containerPropsempty objectfalseobjectContainer element extra props.
searchInputPropsempty objectfalseobjectSearch input element extra properties.
classNameundefinedfalsestringClass name for selector header.
disabledfalsefalsebooleanDisable selector
fullWidthfalsefalsebooleanAdds CSS property to ocupy 100% of parent element width
htmlInputPropsempty objectfalseobjectNative hidden HTML select props.
label-falsestringSelector label that appears when nothing is selected.
noResultMessageSearch...falsestringMessage that shows up when nothing is returned from search
onChange-falsefunctionOn change value handler. Receives value as unique property.
options-truearrayList of selector options.
value-truestringnumberSelected value. "No value" is represented by undefined
arrowIcons{ up: undefined, down: undefined }falseobjectChange arrow icons. Pass react nodes to up and down properties.
strictComparisontruefalsebooleanEnables strict values comparison (===). Enabled by default.

License

MIT © gabrieljmj

1.1.3

1 year ago

1.1.1

2 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago