import React from 'react'; import { SelectControl } from '@wordpress/components'; import { Option } from '../../types/types'; /** * Type for SelectGroup */ type InlineSelectGroupArgs = { value: string | string[]; onChange: ( nextValue: string ) => void; options: Option[]; label: string; disabled: boolean; }; /** * Select component that supports OptGroup. * * @param {InlineSelectGroupArgs} args * @class */ const InlineSelectGroup = ( { value, onChange, options, label, disabled = false, }: InlineSelectGroupArgs ) => { return (
{ label && ( { label } ) } { options.map( ( option: Option, index ) => { if ( Array.isArray( option.value ) ) { const optGroupKey = option.id || `${ option.label }-${ index }`; return ( { option.value.map( ( groupedOption, groupedOptionIndex ) => { const key = groupedOption.id || `${ groupedOption.label }-${ groupedOption.value }-${ groupedOptionIndex }`; return ( ); } ) } ); } const key = option.id || `${ option.label }-${ option.value }-${ index }`; return ( ); } ) }
); }; export default InlineSelectGroup;