0.1.4 • Published 11 months ago

custom_dropdown_comp v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Dropdown

A simple dropdown library of React components created for Openclassroom project 14 of "Application developer - JavaScript React".

Installation

Run the following command:npm i custom_dropdown_comp

Basic Dropdown

textLabel

string

Pass the label text.

name

string

Pass the name that will be used in htmlFor on label element and in id & name on select.

data

arrayOf(object)

Pass an array of items to initialize the dropdown. The array contains name (required) and value (optional).

Component

export default function Dropdown({ textLabel, name, data }) {
  if (!data[0]) {
    return ''
  }
  return (
    <div className="select-wrapper">
      <label htmlFor={name}>{textLabel}</label>
      <select className={name} id={name} name={name}>
        {data.map((val) => (
              <option value={data[0].value ? val.value : val.name} key={data[0].value ? val.value : val.name}>
                {val.name}
              </option>
            ))
        }
      </select>
    </div>
  )
}

Usage

CodeSandbox - Try it out in the browser

import * as React from 'react'
import {render} from 'react-dom'
import Dropdown from 'custom_dropdown_comp'

const states = [
    {
        name: "Alabama",
        value: "AL"
    },
    {
        name: "Alaska",
        value: "AK"
    },
    {
        name: "American Samoa",
        value: "AS"
    },
    {
        name: "Arizona",
        value: "AZ"
    }
]

render(
<Dropdown textLabel="States" name="states" data={states} />,
  document.getElementById('root'),
)

Support

This package was created & tested in :

React - v18.2.0 React-dom - v18.2.0 react-scripts - v5.0.1 Prop-types - v15.8.1 Sass - v1.63.6

0.1.4

11 months ago

0.1.3

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

0.1.0

11 months ago