| 1 |
/** |
| 2 |
* Defines the props structure for FilterSelect. |
| 3 |
* |
| 4 |
* @since 3.10.0 |
| 5 |
*/ |
| 6 |
interface FilterSelectProps { |
| 7 |
defaultValue?: string; |
| 8 |
items: [value: string, label: string][]; |
| 9 |
onChange: ( event: React.ChangeEvent<HTMLSelectElement> ) => void; |
| 10 |
} |
| 11 |
|
| 12 |
/** |
| 13 |
* Returns a select element according to the passed props. |
| 14 |
* |
| 15 |
* @since 3.10.0 |
| 16 |
* |
| 17 |
* @param {FilterSelectProps} props The component's props. |
| 18 |
* |
| 19 |
* @return {JSX.Element} The JSX Element. |
| 20 |
*/ |
| 21 |
export const Select = ( |
| 22 |
{ defaultValue, items, onChange }: FilterSelectProps |
| 23 |
): JSX.Element => { |
| 24 |
return ( |
| 25 |
<select onChange={ onChange } value={ defaultValue }> |
| 26 |
{ items.map( ( item ) => ( |
| 27 |
<option |
| 28 |
key={ item[ 0 ] } |
| 29 |
value={ item[ 0 ] }>{ item[ 1 ] } |
| 30 |
</option> |
| 31 |
) ) } |
| 32 |
</select> |
| 33 |
); |
| 34 |
}; |
| 35 |
|