@wordpress/block-editor
Version:
46 lines (44 loc) • 1.51 kB
JavaScript
import { createElement } from "@wordpress/element";
/**
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { formatStrikethrough, formatUnderline } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
const TEXT_DECORATIONS = [{
name: __('Underline'),
value: 'underline',
icon: formatUnderline
}, {
name: __('Strikethrough'),
value: 'line-through',
icon: formatStrikethrough
}];
/**
* Control to facilitate text decoration selections.
*
* @param {Object} props Component props.
* @param {string} props.value Currently selected text decoration.
* @param {Function} props.onChange Handles change in text decoration selection.
* @return {WPElement} Text decoration control.
*/
export default function TextDecorationControl({
value,
onChange
}) {
return createElement("fieldset", {
className: "block-editor-text-decoration-control"
}, createElement("legend", null, __('Decoration')), createElement("div", {
className: "block-editor-text-decoration-control__buttons"
}, TEXT_DECORATIONS.map(textDecoration => {
return createElement(Button, {
key: textDecoration.value,
icon: textDecoration.icon,
isSmall: true,
isPressed: textDecoration.value === value,
onClick: () => onChange(textDecoration.value === value ? undefined : textDecoration.value),
"aria-label": textDecoration.name
});
})));
}
//# sourceMappingURL=index.js.map