0.2.7 • Published 1 year ago

@coopdigital/component-searchable-dropdown v0.2.7

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

Searchable Dropdown

A Co-op styled searchable dropdown (aka combobox) React component built using Downshift.

Installation

Install via npm or yarn:

npm install @coopdigital/component-searchable-dropdown

yarn add @coopdigital/component-searchable-dropdown

Prerequisites

You must have the Co-op foundations and foundations-forms css packages installed in your project. You will also need React 17 or higher.

@import "@coopdigital/foundations/dist/vars/vars.css";
@import "@coopdigital/foundations/dist/foundations.css";
@import "@coopdigital/foundations-forms/dist/forms.css";

Importing

@import "@coopdigital/component-searchable-dropdown/dist/styles.css";
import { SearchableDropdown } from "@coopdigital/component-searchable-dropdown";

Basic Usage

<SearchableDropdown
  label="My favourite animal is a..."
  id="animals"
  options={["Cat", "Dog", "Frog", "Panda", "Sloth"]}
/>

Required props

These props are required for the component to render:

proptypedescription
labelstringText for the associated element label.
idstringA unique identifier for the element.
optionsarrayArray of strings to use for option values

Additional props

The component can be further customised using the props below:

proptypedescriptiondefault
classNamestringAdditional class (or classes) to append to the outer coop-c-combobox element-
compactboolReduces the input font size to 1remfalse
noResultsstringString to display when no matching options are foundNo relevant options
onSelectfuncCallback function when an option is selected, receives the selected value as its only parameter-
placeholderstringPlaceholder text to display when no option is selected-
styleobjectCSS object with inline styles to be added to the outer coop-c-combobox element-

Kitchen sink

<SearchableDropdown
  label="My favourite animal is a..."
  id="animals"
  options={["Cat", "Dog", "Frog", "Panda", "Sloth"]}
  className="additional-class another-class"
  compact
  placeholder="Select option"
  onSelect={(value) => {
    console.log(value);
  }}
  style={{ width: "300px" }}
/>

License

Copyright (c) 2022 Co-operative Group Limited. Licensed MIT.