Skip to main content

DropDown

The DropDown component is used to create a customizable dropdown menu with selectable options. Below is a breakdown of the props and how the component works.

Import

import { DropDown } from 'pristineui';

Usage

/src/components/DropDown.jsx
import DropDown from 'pristineui';

const options = [
{ label: 'Select', value: 'select' },
{ label: 'Option 1', value: 'option-1' },
{ label: 'Option 2', value: 'option-2' },
{ label: 'Option 3', value: 'option-3' },
{ label: 'Option 4', value: 'option-4' },
{ label: 'Option 5', value: 'option-5' },
{ label: 'Option 6', value: 'option-6' },
];


const DropDown = () => {
const [selectedOption, setSelectedOption] = useState('select');

const handleChange = (value) => {
setSelectedOption(value);
console.log("Selected Option:", value);
};

return (
<DropDown
options={options}
defaultSelected={selectedOption}
onChange={handleChange}
className="rounded-sm"
backgroundColor="pink"
textColor="white"
/>
);
};

export default DropDown;

Props

Prop NameTypeDescriptionDefault
optionsArray<{ label: string, value: string }>List of options to display in the dropdown. The label is the text displayed to the user, and the value is the internal value.[]
defaultSelectedstringDefault option to be selected when the component loads.''
onChangefunction(value: string)Callback function triggered when the selected option changes.undefined
classNamestringOptional custom class to apply additional styles to the dropdown.''
backgroundColorstringCustom background color for the dropdown.transparent
textColorstringCustom text color for the dropdown options.black

Possible Option field:

const options = [
{ label: 'Select', value: 'select' },
{ label: 'Option 1', value: 'option-1' },
{ label: 'Option 2', value: 'option-2' },
{ label: 'Option 3', value: 'option-3' },
{ label: 'Option 4', value: 'option-4' },
{ label: 'Option 5', value: 'option-5' },
{ label: 'Option 6', value: 'option-6' },
];

Customization

You can further customize the Button using CSS classes and inline styles.