@wordpress/format-library
Version:
Format library for the WordPress editor.
64 lines (63 loc) • 1.56 kB
JavaScript
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { __ } from "@wordpress/i18n";
import { toggleFormat } from "@wordpress/rich-text";
import {
RichTextToolbarButton,
RichTextShortcut,
__unstableRichTextInputEvent,
privateApis as blockEditorPrivateApis
} from "@wordpress/block-editor";
import { formatBold } from "@wordpress/icons";
import { unlock } from "../lock-unlock";
const { essentialFormatKey } = unlock(blockEditorPrivateApis);
const name = "core/bold";
const title = __("Bold");
const bold = {
name,
title,
tagName: "strong",
className: null,
[essentialFormatKey]: true,
edit({ isActive, value, onChange, onFocus }) {
function onToggle() {
onChange(toggleFormat(value, { type: name, title }));
}
function onClick() {
onChange(toggleFormat(value, { type: name }));
onFocus();
}
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(
RichTextShortcut,
{
type: "primary",
character: "b",
onUse: onToggle
}
),
/* @__PURE__ */ jsx(
RichTextToolbarButton,
{
name: "bold",
icon: formatBold,
title,
onClick,
isActive,
shortcutType: "primary",
shortcutCharacter: "b"
}
),
/* @__PURE__ */ jsx(
__unstableRichTextInputEvent,
{
inputType: "formatBold",
onInput: onToggle
}
)
] });
}
};
export {
bold
};
//# sourceMappingURL=index.js.map