| 1 |
import { TextControl, SelectControl } from '@wordpress/components'; |
| 2 |
import { __ } from '@wordpress/i18n'; |
| 3 |
|
| 4 |
const UnitControl = ({ |
| 5 |
label, |
| 6 |
value, |
| 7 |
unit = 'px', |
| 8 |
onValueChange, |
| 9 |
onUnitChange, |
| 10 |
options = [ |
| 11 |
{ label: 'px', value: 'px' }, |
| 12 |
{ label: 'em', value: 'em' }, |
| 13 |
{ label: '%', value: '%' }, |
| 14 |
{ label: 'rem', value: 'rem' }, |
| 15 |
], |
| 16 |
style = {}, |
| 17 |
}) => { |
| 18 |
return ( |
| 19 |
<div className="unit-control" style={style}> |
| 20 |
<div style={{ display: 'flex' }}> |
| 21 |
<TextControl |
| 22 |
label={label} |
| 23 |
__nextHasNoMarginBottom |
| 24 |
type="number" |
| 25 |
value={value} |
| 26 |
onChange={onValueChange} |
| 27 |
style={{ |
| 28 |
flexGrow: 1, |
| 29 |
marginBottom: 0, |
| 30 |
}} |
| 31 |
/> |
| 32 |
<SelectControl |
| 33 |
label={__('Unit', 'top-10')} |
| 34 |
__nextHasNoMarginBottom |
| 35 |
value={unit} |
| 36 |
options={options} |
| 37 |
onChange={onUnitChange} |
| 38 |
style={{ width: 'max-content', marginBottom: 0 }} |
| 39 |
/> |
| 40 |
</div> |
| 41 |
</div> |
| 42 |
); |
| 43 |
}; |
| 44 |
|
| 45 |
export default UnitControl; |
| 46 |
|