UNPKG

@wordpress/format-library

Version:
55 lines (50 loc) 1.08 kB
/** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { toggleFormat } from '@wordpress/rich-text'; import { RichTextToolbarButton, RichTextShortcut, __unstableRichTextInputEvent, } from '@wordpress/block-editor'; import { formatBold } from '@wordpress/icons'; const name = 'core/bold'; const title = __( 'Bold' ); export const bold = { name, title, tagName: 'strong', className: null, edit( { isActive, value, onChange, onFocus } ) { function onToggle() { onChange( toggleFormat( value, { type: name, title } ) ); } function onClick() { onChange( toggleFormat( value, { type: name } ) ); onFocus(); } return ( <> <RichTextShortcut type="primary" character="b" onUse={ onToggle } /> <RichTextToolbarButton name="bold" icon={ formatBold } title={ title } onClick={ onClick } isActive={ isActive } shortcutType="primary" shortcutCharacter="b" /> <__unstableRichTextInputEvent inputType="formatBold" onInput={ onToggle } /> </> ); }, };