Props
Name of the Prop | Type of the prop | Default | Usage |
---|---|---|---|
options | Array | Renders options in the Filter component | |
placeholder | String | Sets the placeholder for the Filter component | |
hoverColor | String | #0d66d6 | Changes the highlighted colour of the selected option |
className | String | Class-name for filter field container. | |
inputClassName | String | Class-name for the input element. | |
dropdownListClassName | String | Class-name for the dropdown list. | |
onSubmit | Function | This is callback function which provides the filtered values when the filter component is submitted. | |
optionsListMaxHeight | number | 200 | Sets the maximum height of the options list container. |
style | CSS Properties | This prop is used to style the Filter component. | |
customFilterIcon | ReactNode | This prop enables you to set custom filter-icon in the left side of the filter component. | |
customClearIcon | ReactNode | This prop enables you to set custom clear-icon. | |
editable | Boolean | true | You can make the filter field as non-editable by setting this prop to false. |
onClear | Function | This is callback function which is called when the filters are cleared. |
Usage
Example-1
Example for the props - options , placeholder.
options is the required prop to be passed to the Filter component.
import React, { useState } from 'react'import Filter from 'react-searchable-filter'import 'react-searchable-filter/dist/index.css'const App = () => {const options = [{filterBy: 'status',values: ['finished', 'not-finished', 'pending'],description: 'filter by status'},{filterBy: 'age',values: ['30', '25', '18', '22'],description: 'filter by age'},{filterBy: 'username',description: 'filter by username',values: ['John', 'Albert', 'Robert']}]return (<div><Filter options={options} placeholder='Filter Users' /></div>)}
Example-2
- Example for props - className, style, inputClassName, dropdownListClassName and hoverColor.
.filter-component {width:'300px'height:'80px'}
import React, { useState } from 'react'import Filter from 'react-searchable-filter'import 'react-searchable-filter/dist/index.css'import './index.css'import options from '../path/where/options/present'const App = () => {return (<div><Filteroptions={options}className='filter-component'inputClassName='filter-field-input'dropdownListClassName='dropdown-list'style={{ margin: '10px' }}hoverColor='teal'/></div>)}
Example-3
- Example for the prop - onSubmit and onClear
import React, { useState } from 'react'import Filter, { onSubmitFiltersType } from 'react-searchable-filter'import 'react-searchable-filter/dist/index.css'import options from '../path/where/options/present'const App = () => {const [selectedFilters, setSelectedFilters] = useState([])const submitHandler = (filters: onSubmitFiltersType) => {setSelectedFilters(filters)}const clearFilters = () => {setSelectedFilters([])}return (<div><Filteroptions={options}onSubmit={submitHandler}onClear={clearFilters}/></div>)}
Example-4
- Example for the props - customFilterIcon, customClearIcon
import React, { useState } from 'react'import Filter from 'react-searchable-filter'import 'react-searchable-filter/dist/index.css'import { FaFilter } from 'react-icons/fa'import { AiFillCloseCircle } from 'react-icons/ai'import options from '../path/where/options/present'const App = () => {return (<div><Filteroptions={options}customFilterIcon={<FaFilter />}customClearIcon={<AiFillCloseCircle />}/></div>)}
Example-5
- Example for the prop - editable and optionsListMaxHeight
import React, { useState } from 'react'import Filter from 'react-searchable-filter'import 'react-searchable-filter/dist/index.css'import options from '../path/where/options/present'const App = () => {return (<div><Filter options={options} editable={false} optionsMaxHeight={300} /></div>)}