@wordpress/format-library
Version:
Format library for the WordPress editor.
44 lines (40 loc) • 869 B
JavaScript
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { toggleFormat } from '@wordpress/rich-text';
import {
RichTextToolbarButton,
RichTextShortcut,
} from '@wordpress/block-editor';
import { formatStrikethrough } from '@wordpress/icons';
const name = 'core/strikethrough';
const title = __( 'Strikethrough' );
export const strikethrough = {
name,
title,
tagName: 's',
className: null,
edit( { isActive, value, onChange, onFocus } ) {
function onClick() {
onChange( toggleFormat( value, { type: name, title } ) );
onFocus();
}
return (
<>
<RichTextShortcut
type="access"
character="d"
onUse={ onClick }
/>
<RichTextToolbarButton
icon={ formatStrikethrough }
title={ title }
onClick={ onClick }
isActive={ isActive }
role="menuitemcheckbox"
/>
</>
);
},
};