1.24.0 • Published 12 months ago

react-dropdown-package v1.24.0

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

React Dropdown Package

A simple and customizable dropdown component for React applications.

npm npm License: MIT

Tech Stack

Component: React, TypeScript, TailwindCSS

Prerequisites

  • Node.js >= 14.0.0
  • npm >= 6.0.0
  • TypeScript >= 2.7
  • React >= 18.0.0

Installation

Install react-dropdown-package and required dependencies (typescript@>=2.7 fontawesome)

  npm install react-dropdown-package
  npm install typescript @fortawesome/react-fontawesome @fortawesome/free-solid-svg-icons

Usage

import React, { useState } from "react";
import Dropdown from "react-dropdown-package";
import "./your-custom-styles.css";

const options = [
  { value: "option1", label: "Option 1" },
  { value: "option2", label: "Option 2" },
  { value: "option3", label: "Option 3" },
];

const App = () => {
  const [selected, setSelected] = useState(options[0].value);

  const handleSelect = (selectedValue) => {
    setSelected(selectedValue);
    console.log(selectedValue);
  };

  return (
    <Dropdown
      options={options}
      selected={selected}
      onSelectedChange={handleSelect}
      placeholder="Please select an option"
      isDisabled={false}
      customClasses={{
        container: "my-dropdown",
        button: "my-toggle",
        list: "my-menu",
        listItem: "my-item",
        chevron: "my-chevron",
      }}
      buttonWidth={200} 
      listWidth={200}   
      buttonHeight={40} 
      listMaxHeight={200}  
      customIcons={{
        chevron: <MyCustomChevronIcon />
      }}
      onOpen={() => console.log('Dropdown opened')}
      onClose={() => console.log('Dropdown closed')}
    />
  );
};

export default App;

Props

Prop NameTypeDescription
optionsarrayThe options for the dropdown.
selectedstringThe currently selected value.
onSelectedChangefunctionFunction called when an option is selected.
placeholderstringDefault text displayed when nothing is selected.
isDisabledbooleanDisables the dropdown if true.
customClassesobjectCustom CSS classes for the component.
customIconsobjectCustom icons for the component.
onOpenfunctionFunction called when the dropdown is opened.
onClosefunctionFunction called when the dropdown is closed.
buttonWidthnumberWidth of the dropdown button in px (optional).
buttonHeightnumberHeight of the dropdown button in px(optional).
listWidthnumberWidth of the dropdown list in px (optional).
listMaxHeightnumberMax Height of the dropdown list in px (optional).

customClasses Object Structure

KeyTypeDescription
containerstringCSS class for the dropdown container.
buttonstringCSS class for the toggle button.
liststringCSS class for the dropdown menu.
listItemstringCSS class for the dropdown menu items.
chevronstringCSS class for the chevron icon.

customIcons Object Structure

KeyTypeDescription
chevronReactNodeCustom icon for the chevron.

Licence

This project is licensed under the MIT License. See the LICENSE file for more details

1.24.0

12 months ago

1.23.0

12 months ago

1.22.0

12 months ago

1.21.0

1 year ago

1.20.0

1 year ago

1.19.0

1 year ago

1.18.0

1 year ago

1.17.0

1 year ago

1.16.0

1 year ago

1.15.0

1 year ago

1.14.0

1 year ago

1.13.0

1 year ago

1.12.0

1 year ago

1.11.0

1 year ago

1.10.0

1 year ago

1.9.0

1 year ago

1.8.0

1 year ago

1.7.0

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago