Giter Site home page Giter Site logo

dropdown_library's Introduction

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"
    },
    {
        name: "Arkansas",
        value: "AR"
    },
    {
        name: "California",
        value: "CA"
    },
    {
        name: "Colorado",
        value: "CO"
    },
    {
        name: "Connecticut",
        value: "CT"
    }
]

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

dropdown_library's People

Contributors

tempetflamer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.