| 1 |
import { __ } from "@wordpress/i18n"; |
| 2 |
import { registerFormatType, toggleFormat } from "@wordpress/rich-text"; |
| 3 |
import { RichTextToolbarButton } from "@wordpress/block-editor"; |
| 4 |
|
| 5 |
const FORMAT_NAME = "betterdocs/highlight"; |
| 6 |
|
| 7 |
const highlightIcon = ( |
| 8 |
<svg width="20" height="20" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> |
| 9 |
<path d="M5 18l3.5-3.5 6-6L18 12l-7 7H5v-1zm10.5-13.5l3 3-2 2-3-3 2-2z" fill="currentColor" /> |
| 10 |
</svg> |
| 11 |
); |
| 12 |
|
| 13 |
const Edit = ({ isActive, value, onChange }) => ( |
| 14 |
<RichTextToolbarButton |
| 15 |
icon={highlightIcon} |
| 16 |
title={__("Highlight", "betterdocs")} |
| 17 |
onClick={() => onChange(toggleFormat(value, { type: FORMAT_NAME }))} |
| 18 |
isActive={isActive} |
| 19 |
/> |
| 20 |
); |
| 21 |
|
| 22 |
registerFormatType(FORMAT_NAME, { |
| 23 |
title: __("Highlight", "betterdocs"), |
| 24 |
tagName: "span", |
| 25 |
className: "highlight", |
| 26 |
edit: Edit, |
| 27 |
}); |
| 28 |
|