react-free-dropdown
Version:
Easy custom dropdown list with React
81 lines (64 loc) ⢠3.98 kB
Markdown
<div align="center">
<img src="./public/RFDD_logo.png" alt="react free fropdown logo" />
</div>
<h1 align="center">react-free-dropdown <small><sup>(RFDD)</sup></small></h1>
<div align="center">
**Easy custom** dropdown list with [`React`](https://facebook.github.io/react/)
[](https://github.com/flamingotiger/react-free-dropdown/actions)
[](https://www.npmjs.com/package/react-free-dropdown)
[](https://packagephobia.now.sh/result?p=react-free-dropdown)
[](http://npm-stat.com/charts.html?package=react-free-dropdown)
</div>
## Get Started š¦
`react-free-dropdown` install the package.
```shell
npm install react-free-dropdown
```
## Usage š
```javascript jsx
import React from 'react';
import { Rfdd, RfddOption } from 'react-free-dropdown';
const App = () => {
const [value, setValue] = React.useState('');
return (<>
<Rfdd onChange={optionValue => setValue(optionValue)}>
<RfddOption value="Apple">Apple</RfddOption>
<RfddOption value="Grape">Grape</RfddOption>
</Rfdd>
<p>{value}</p>
</>);
}
export default App;
```
## Rfdd Property ā·
| Property | Type | Descriptions | Example |
| ------------- | ------------- | ------------- | ------------- |
| selectClassName | `string` | select className | `selectClassName="select-classname"` |
| selectStyle | `React.CSSProperties` | select component style | `selectStyle={{border: '1px solid red'}}` |
| optionClassName | `string` | option className | `optionClassName="option-classname"` |
| optionStyle | `string` | all option custom style | `optionStyle='border: 1px solid red;'` |
| style | `React.CSSProperties` | dropdown wrapper style | `style={{border: '1px solid red'}}` |
| className | `string` | dropdown wrapper className | `className="wrapper-classname"` |
| focusStyle | `React.CSSProperties` | if focus use style | `focusStyle={{border: '1px solid red'}}` |
| value | `string` | selected value | `value={value}` |
| children | `React.ReactElement<RfddOptionType, 'RfddOption'>[]` | only use RfddOption component | `<RfddOption>option</RfddOption>`|
| onChange | `(value: string) => void` | change value function | `onChange={(optionValue) => setValue(optionValue)}`|
| mode | `light` or `dark` | light or dark mode | `mode='dark'`|
| hoverStyle | `string` | custom hover style | `hoverStyle='border: 1px solid red;'` |
| icon | `any` | usage import image `import image from './example.png'` | `icon={image}` |
| hiddenIcon | `boolean` | hidden icon | `hiddenIcon={true}` |
| placeholder | `string` | setting placeholder | `placeholder='area'` |
| listStyle | `string` | ul list style | `listStyle='max-height:200px'` |
| optionOnClick | `() => void` | all option onClick | `optionOnClick={() => console.log('onClick')}`|
## RfddOption Property š
| Property | Type | Descriptions | Example |
| ------------- | ------------- | ------------- | ------------- |
| value | `string` | option value | `value='option-value'`|
| style | `React.CSSProperties` | must be entered as camelcase | `style={{ border: '1px solid red' }}`|
| className | `string` | must be entered as camelcase | `className="class-name"`|
| children | `React.ReactNode` | option children | `option text or <div>option Element</div>`|
| hoverStyle | `string` | each option custom hover style | `hoverStyle='border: 1px solid red;'` |
| onClick | `() => void` | onChange before active function | `onClick={() => console.log('onClick')}` |
## Preview š

š[Play the example](https://react-free-dropdown.netlify.com/?path=/story/drop-down-basic--light-mode)