0.1.14 • Published 1 year ago

react-dropdown-picker v0.1.14

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

react-dropdown-picker

A customizable dropdown component for selecting options.

npm.io npm.io

Installation

npm install react-dropdown-picker  # using npm
yarn add react-dropdown-picker     # using yarn

Features

  • ✅Configurable via props.
  • ✅Stylable via css (or custom components).
  • ✅Best dropdown for small number of options.
    • ✔️ AM/PM
    • ✔️ Weekly/Monthly/Yearly
    • ✔️ Online/Offline
  • ✅Zero Dependency.
  • ✅Small bundle size.

Example Usage

import React, { useState } from 'react';
import CustomSelect from 'react-dropdown-picker';

const MyComponent = () => {
  const [selectedRange, setSelectedRange] = useState('1 W');

  const handleRangeChange = (range) => {
    setSelectedRange(range);
    console.log("Range: ", range);
  };

  const options = [
    { value: 7, label: '1 W' },
    { value: 14, label: '2 W' },
    { value: 21, label: '3 W' },
    { value: 30, label: '1 M' },
    { value: 180, label: '6 M' },
    { value: 365, label: '1 Y' }
  ];

  return (
    <div>
      <CustomSelect
        options={options}
        defaultOption={selectedRange}
        onSelect={handleRangeChange}
        width={30}
      />
    </div>
  );
};

export default MyComponent;

Props

NameTypeDefaultDescription
optionsarray[]An array of objects representing the options for the dropdown. Each object should have value and label properties.
defaultOptionstringThe default selected option label.
onSelectfunctionA function to be called when an option is selected. It receives the selected option's value as an argument.
widthnumberThe width of the dropdown in pixels.
zIndexnumber1The z-index of the dropdown.
isUpwardbooleanfalseDetermines whether the dropdown should open upward or downward.
selectedOptionStyleobjectCustom styles for the selected option.
dropdownItemStyleobjectCustom styles for the dropdown items.

selectedOptionStyle Properties

NameTypeDefaultDescription
backgroundColorstring'#BC7AF9'The background color of the selected option.
colorstring'#FFFFFF'The text color of the selected option.
fontSizestring'14px'The font size of the selected option.
fontWeightstring'bold'The font weight of the selected option.
borderRadiusstring'10px'The border radius of the selected option.
borderWidthstring'0.65px'The border width of the selected option.
borderColorstring'#BC7AF9'The border color of the selected option.

dropdownItemStyle Properties

NameTypeDefaultDescription
backgroundColorstring'#BC7AF9'The background color of the dropdown items.
colorstring'#FFFFFF'The text color of the dropdown items.
fontSizestring'14px'The font size of the dropdown items.
fontWeightstring'bold'The font weight of the dropdown items.
borderRadiusstring'10px'The border radius of the dropdown items.
borderWidthstring'0.65px'The border width of the dropdown items.
borderColorstring'#BC7AF9'The border color of the dropdown items.

Customization

import CustomSelect from 'react-dropdown-picker';
import React, { useState } from 'react';

const MyComponent = () => {
  const [selectedRange, setSelectedRange] = useState('1 W');

  const handleRangeChange = (range) => {
    setSelectedRange(range);
    console.log("Range: ", range);
  };

  const options = [
    { value: 7, label: '1 W' },
    { value: 14, label: '2 W' },
    { value: 21, label: '3 W' },
    { value: 30, label: '1 M' },
    { value: 180, label: '6 M' },
    { value: 365, label: '1 Y' }
  ];

  const selectedOptionStyle = {
    backgroundColor: '#BC7AF9',
    color: '#FFFFFF',
    fontSize: '14px',
    fontWeight: 'bold',
    borderRadius: '10px',
    borderWidth: '0.65px', 
    borderColor: '#BC7AF9', 
  };
  
  const dropdownItemStyle = {
    backgroundColor: '#BC7AF9',
    color: '#FFFFFF',
    fontSize: '14px',
    fontWeight: 'bold',
    borderRadius: '10px',
    borderWidth: '0.65px', 
    borderColor: '#BC7AF9', 
  };

  return (
    <div>
      <CustomSelect
        options={options}
        defaultOption={selectedRange}
        onSelect={handleRangeChange}
        width={30}
        zIndex={1}
        isUpward={true}
        selectedOptionStyle={selectedOptionStyle}
        dropdownItemStyle={dropdownItemStyle}
      />
    </div>
  );
};

export default MyComponent;

License

MIT

0.1.13

1 year ago

0.1.14

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago