@wordpress/block-library
Version:
Block library for the WordPress editor.
88 lines (87 loc) • 2.64 kB
JavaScript
// packages/block-library/src/pullquote/edit.js
import clsx from "clsx";
import { __ } from "@wordpress/i18n";
import {
AlignmentControl,
BlockControls,
RichText,
useBlockProps
} from "@wordpress/block-editor";
import { createBlock, getDefaultBlockName } from "@wordpress/blocks";
import { Platform } from "@wordpress/element";
import { Figure } from "./figure";
import { BlockQuote } from "./blockquote";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var isWebPlatform = Platform.OS === "web";
function PullQuoteEdit({
attributes,
setAttributes,
isSelected,
insertBlocksAfter
}) {
const { textAlign, citation, value } = attributes;
const blockProps = useBlockProps({
className: clsx({
[`has-text-align-${textAlign}`]: textAlign
})
});
const shouldShowCitation = !RichText.isEmpty(citation) || isSelected;
return /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(BlockControls, { group: "block", children: /* @__PURE__ */ jsx(
AlignmentControl,
{
value: textAlign,
onChange: (nextAlign) => {
setAttributes({ textAlign: nextAlign });
}
}
) }),
/* @__PURE__ */ jsx(Figure, { ...blockProps, children: /* @__PURE__ */ jsxs(BlockQuote, { children: [
/* @__PURE__ */ jsx(
RichText,
{
identifier: "value",
tagName: "p",
value,
onChange: (nextValue) => setAttributes({
value: nextValue
}),
"aria-label": __("Pullquote text"),
placeholder: (
// translators: placeholder text used for the quote
__("Add quote")
),
textAlign: "center"
}
),
shouldShowCitation && /* @__PURE__ */ jsx(
RichText,
{
identifier: "citation",
tagName: isWebPlatform ? "cite" : void 0,
style: { display: "block" },
value: citation,
"aria-label": __("Pullquote citation text"),
placeholder: (
// translators: placeholder text used for the citation
__("Add citation")
),
onChange: (nextCitation) => setAttributes({
citation: nextCitation
}),
className: "wp-block-pullquote__citation",
__unstableMobileNoFocusOnMount: true,
textAlign: "center",
__unstableOnSplitAtEnd: () => insertBlocksAfter(
createBlock(getDefaultBlockName())
)
}
)
] }) })
] });
}
var edit_default = PullQuoteEdit;
export {
edit_default as default
};
//# sourceMappingURL=edit.js.map