UNPKG

@wordpress/block-library

Version:
154 lines (152 loc) 5.06 kB
/** * External dependencies */ import clsx from 'clsx'; /** * WordPress dependencies */ import { AlignmentControl, BlockControls, InspectorControls, useBlockProps, Warning, HeadingLevelDropdown } from '@wordpress/block-editor'; import { ToggleControl, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem } from '@wordpress/components'; import { __, _x, sprintf } from '@wordpress/i18n'; /** * Internal dependencies */ import { useArchiveLabel } from './use-archive-label'; import { useToolsPanelDropdownMenuProps } from '../utils/hooks'; import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; const SUPPORTED_TYPES = ['archive', 'search']; export default function QueryTitleEdit({ attributes: { type, level, levelOptions, textAlign, showPrefix, showSearchTerm }, setAttributes }) { const { archiveTypeLabel, archiveNameLabel } = useArchiveLabel(); const dropdownMenuProps = useToolsPanelDropdownMenuProps(); const TagName = `h${level}`; const blockProps = useBlockProps({ className: clsx('wp-block-query-title__placeholder', { [`has-text-align-${textAlign}`]: textAlign }) }); if (!SUPPORTED_TYPES.includes(type)) { return /*#__PURE__*/_jsx("div", { ...blockProps, children: /*#__PURE__*/_jsx(Warning, { children: __('Provided type is not supported.') }) }); } let titleElement; if (type === 'archive') { let title; if (archiveTypeLabel) { if (showPrefix) { if (archiveNameLabel) { title = sprintf(/* translators: 1: Archive type title e.g: "Category", 2: Label of the archive e.g: "Shoes" */ _x('%1$s: %2$s', 'archive label'), archiveTypeLabel, archiveNameLabel); } else { title = sprintf(/* translators: %s: Archive type title e.g: "Category", "Tag"... */ __('%s: Name'), archiveTypeLabel); } } else if (archiveNameLabel) { title = archiveNameLabel; } else { title = sprintf(/* translators: %s: Archive type title e.g: "Category", "Tag"... */ __('%s name'), archiveTypeLabel); } } else { title = showPrefix ? __('Archive type: Name') : __('Archive title'); } titleElement = /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(InspectorControls, { children: /*#__PURE__*/_jsx(ToolsPanel, { label: __('Settings'), resetAll: () => setAttributes({ showPrefix: true }), dropdownMenuProps: dropdownMenuProps, children: /*#__PURE__*/_jsx(ToolsPanelItem, { hasValue: () => !showPrefix, label: __('Show archive type in title'), onDeselect: () => setAttributes({ showPrefix: true }), isShownByDefault: true, children: /*#__PURE__*/_jsx(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Show archive type in title'), onChange: () => setAttributes({ showPrefix: !showPrefix }), checked: showPrefix }) }) }) }), /*#__PURE__*/_jsx(TagName, { ...blockProps, children: title })] }); } if (type === 'search') { titleElement = /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx(InspectorControls, { children: /*#__PURE__*/_jsx(ToolsPanel, { label: __('Settings'), resetAll: () => setAttributes({ showSearchTerm: true }), dropdownMenuProps: dropdownMenuProps, children: /*#__PURE__*/_jsx(ToolsPanelItem, { hasValue: () => !showSearchTerm, label: __('Show search term in title'), onDeselect: () => setAttributes({ showSearchTerm: true }), isShownByDefault: true, children: /*#__PURE__*/_jsx(ToggleControl, { __nextHasNoMarginBottom: true, label: __('Show search term in title'), onChange: () => setAttributes({ showSearchTerm: !showSearchTerm }), checked: showSearchTerm }) }) }) }), /*#__PURE__*/_jsx(TagName, { ...blockProps, children: showSearchTerm ? __('Search results for: “search term”') : __('Search results') })] }); } return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsxs(BlockControls, { group: "block", children: [/*#__PURE__*/_jsx(HeadingLevelDropdown, { value: level, options: levelOptions, onChange: newLevel => setAttributes({ level: newLevel }) }), /*#__PURE__*/_jsx(AlignmentControl, { value: textAlign, onChange: nextAlign => { setAttributes({ textAlign: nextAlign }); } })] }), titleElement] }); } //# sourceMappingURL=edit.js.map