@wordpress/components
Version:
UI components for WordPress.
60 lines (59 loc) • 1.66 kB
JavaScript
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import CustomSelectControl from '../custom-select-control';
import { isSimpleCssValue } from './utils';
import { jsx as _jsx } from "react/jsx-runtime";
const DEFAULT_OPTION = {
key: 'default',
name: __('Default'),
value: undefined
};
const FontSizePickerSelect = props => {
var _options$find;
const {
__next40pxDefaultSize,
fontSizes,
value,
size,
onChange
} = props;
const options = [DEFAULT_OPTION, ...fontSizes.map(fontSize => {
let hint;
if (isSimpleCssValue(fontSize.size)) {
hint = String(fontSize.size);
}
return {
key: fontSize.slug,
name: fontSize.name || fontSize.slug,
value: fontSize.size,
hint
};
})];
const selectedOption = (_options$find = options.find(option => option.value === value)) !== null && _options$find !== void 0 ? _options$find : DEFAULT_OPTION;
return /*#__PURE__*/_jsx(CustomSelectControl, {
__next40pxDefaultSize: __next40pxDefaultSize,
__shouldNotWarnDeprecated36pxSize: true,
className: "components-font-size-picker__select",
label: __('Font size'),
hideLabelFromVision: true,
describedBy: sprintf(
// translators: %s: Currently selected font size.
__('Currently selected font size: %s'), selectedOption.name),
options: options,
value: selectedOption,
showSelectedHint: true,
onChange: ({
selectedItem
}) => {
onChange(selectedItem.value);
},
size: size
});
};
export default FontSizePickerSelect;
//# sourceMappingURL=font-size-picker-select.js.map