/**
* External dependencies
*/
import { noop } from 'lodash';
import classnames from 'classnames';
// eslint-disable-next-line no-restricted-imports
import type { ChangeEvent } from 'react';
/**
* Internal dependencies
*/
import type { GeChiUIComponentProps } from '../ui/context';
import { UnitSelect, UnitLabel } from './styles/unit-control-styles';
import { CSS_UNITS, hasUnits } from './utils';
import type { UnitSelectControlProps } from './types';
export default function UnitSelectControl( {
className,
isUnitSelectTabbable: isTabbable = true,
onChange = noop,
size = 'default',
unit = 'px',
units = CSS_UNITS,
...props
}: GeChiUIComponentProps< UnitSelectControlProps, 'select', false > ) {
if ( ! units || ! hasUnits( units ) || units?.length === 1 ) {
return (
{ unit }
);
}
const handleOnChange = ( event: ChangeEvent< HTMLSelectElement > ) => {
const { value: unitValue } = event.target;
const data = units.find( ( option ) => option.value === unitValue );
onChange( unitValue, { event, data } );
};
const classes = classnames( 'components-unit-control__select', className );
return (
{ units.map( ( option ) => (
) ) }
);
}