1.1.2 • Published 9 months ago

react-dropdown-ww v1.1.2

Weekly downloads
-
License
-
Repository
-
Last release
9 months ago

React-dropdown-ww

A simple dropdown with your mapped data.

You have several selection elements and you want your dropdown lists to maintain a certain consistency within your project?
This component allows you to supply your elements in a simple and autonomous way by injecting the data that you keep thanks to the props.

Installation

// With npm
npm install react-dropdown-ww --save

or

// With yarn
yarn add react-dropdown-ww

Importing

import { Dropdown } from "react-dropdown-ww"

Usage

import React, { useState } from "react"
import { Dropdown } from "react-dropdown-ww"

const App = () => {
  const [inputValue, setInputValue] = useState("")
  const handleChange = (e) => {
    setInputValue(e.target.value)
  }

  const flowers = [
  { value: "pivoine", label: "Pivoine" },
  { value: "dahlia", label: "Dahlia" },
  { value: "lilas", label: "Lilas" },
  { value: "oeillet", label: "Oeillet" },
  { value: "rosebranchue", label: "Rose Branchue" },
  { value: "symphorine", label: "Symphorine" },
    ]

    let options = flowers.map((flower) => (
    flower.label
    ))

  return (
    <div>
      <Dropdown
        label={"Title of your label"}
        title={"Title of your input dropdown"}
        name={"state"}
        state={inputValue}
        options={options}
        handleChange={handleChange}
      />
    </div>
  )
}

Documentation of props component

Here you can control the following props by providing values for them :

NameTypeExampleDescription
typestring"text"Type of input
labelstring"Types of flowers"Title of your label
titlestring"Choose your flowers"Title of your input dropdown
namestring"flowers"Name of select and label attribut ; htlmFor, id, name
isRequiredbooleantrueIf set, input type hidden would be added in the component with required prop as true/false
statefuncconst inputValue, setInputValue = useState("")Control the value of the search input (changing this will update the available options)
optionsarrayconst options = {}Specify the options the user can select from
handleChangefuncconst handleChange = (e) => {setInputValue(e.target.value)}Subscribe to change events

Author

Lucia Bourque