UNPKG

@wordpress/block-library

Version:
137 lines (136 loc) 4.47 kB
import { jsx, jsxs } from "react/jsx-runtime"; import { InspectorControls, useBlockProps } from "@wordpress/block-editor"; import { Disabled, RangeControl, ToggleControl, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem } from "@wordpress/components"; import ServerSideRender from "@wordpress/server-side-render"; import { __ } from "@wordpress/i18n"; import { useToolsPanelDropdownMenuProps } from "../utils/hooks"; const MIN_COMMENTS = 1; const MAX_COMMENTS = 100; function LatestComments({ attributes, setAttributes }) { const { commentsToShow, displayAvatar, displayDate, displayExcerpt } = attributes; const serverSideAttributes = { ...attributes, style: { ...attributes?.style, spacing: void 0 } }; const dropdownMenuProps = useToolsPanelDropdownMenuProps(); return /* @__PURE__ */ jsxs("div", { ...useBlockProps(), children: [ /* @__PURE__ */ jsx(InspectorControls, { children: /* @__PURE__ */ jsxs( ToolsPanel, { label: __("Settings"), resetAll: () => { setAttributes({ commentsToShow: 5, displayAvatar: true, displayDate: true, displayExcerpt: true }); }, dropdownMenuProps, children: [ /* @__PURE__ */ jsx( ToolsPanelItem, { hasValue: () => !displayAvatar, label: __("Display avatar"), onDeselect: () => setAttributes({ displayAvatar: true }), isShownByDefault: true, children: /* @__PURE__ */ jsx( ToggleControl, { __nextHasNoMarginBottom: true, label: __("Display avatar"), checked: displayAvatar, onChange: () => setAttributes({ displayAvatar: !displayAvatar }) } ) } ), /* @__PURE__ */ jsx( ToolsPanelItem, { hasValue: () => !displayDate, label: __("Display date"), onDeselect: () => setAttributes({ displayDate: true }), isShownByDefault: true, children: /* @__PURE__ */ jsx( ToggleControl, { __nextHasNoMarginBottom: true, label: __("Display date"), checked: displayDate, onChange: () => setAttributes({ displayDate: !displayDate }) } ) } ), /* @__PURE__ */ jsx( ToolsPanelItem, { hasValue: () => !displayExcerpt, label: __("Display excerpt"), onDeselect: () => setAttributes({ displayExcerpt: true }), isShownByDefault: true, children: /* @__PURE__ */ jsx( ToggleControl, { __nextHasNoMarginBottom: true, label: __("Display excerpt"), checked: displayExcerpt, onChange: () => setAttributes({ displayExcerpt: !displayExcerpt }) } ) } ), /* @__PURE__ */ jsx( ToolsPanelItem, { hasValue: () => commentsToShow !== 5, label: __("Number of comments"), onDeselect: () => setAttributes({ commentsToShow: 5 }), isShownByDefault: true, children: /* @__PURE__ */ jsx( RangeControl, { __nextHasNoMarginBottom: true, __next40pxDefaultSize: true, label: __("Number of comments"), value: commentsToShow, onChange: (value) => setAttributes({ commentsToShow: value }), min: MIN_COMMENTS, max: MAX_COMMENTS, required: true } ) } ) ] } ) }), /* @__PURE__ */ jsx(Disabled, { children: /* @__PURE__ */ jsx( ServerSideRender, { block: "core/latest-comments", attributes: serverSideAttributes, urlQueryArgs: { _locale: "site" } } ) }) ] }); } export { LatestComments as default }; //# sourceMappingURL=edit.js.map