@wordpress/block-library
Version:
Block library for the WordPress editor.
162 lines (158 loc) • 5.8 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = QueryTitleEdit;
var _clsx = _interopRequireDefault(require("clsx"));
var _blockEditor = require("@wordpress/block-editor");
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _useArchiveLabel = require("./use-archive-label");
var _hooks = require("../utils/hooks");
var _jsxRuntime = require("react/jsx-runtime");
/**
* External dependencies
*/
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
const SUPPORTED_TYPES = ['archive', 'search'];
function QueryTitleEdit({
attributes: {
type,
level,
levelOptions,
textAlign,
showPrefix,
showSearchTerm
},
setAttributes
}) {
const {
archiveTypeLabel,
archiveNameLabel
} = (0, _useArchiveLabel.useArchiveLabel)();
const dropdownMenuProps = (0, _hooks.useToolsPanelDropdownMenuProps)();
const TagName = `h${level}`;
const blockProps = (0, _blockEditor.useBlockProps)({
className: (0, _clsx.default)('wp-block-query-title__placeholder', {
[`has-text-align-${textAlign}`]: textAlign
})
});
if (!SUPPORTED_TYPES.includes(type)) {
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
...blockProps,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.Warning, {
children: (0, _i18n.__)('Provided type is not supported.')
})
});
}
let titleElement;
if (type === 'archive') {
let title;
if (archiveTypeLabel) {
if (showPrefix) {
if (archiveNameLabel) {
title = (0, _i18n.sprintf)(/* translators: 1: Archive type title e.g: "Category", 2: Label of the archive e.g: "Shoes" */
(0, _i18n._x)('%1$s: %2$s', 'archive label'), archiveTypeLabel, archiveNameLabel);
} else {
title = (0, _i18n.sprintf)(/* translators: %s: Archive type title e.g: "Category", "Tag"... */
(0, _i18n.__)('%s: Name'), archiveTypeLabel);
}
} else if (archiveNameLabel) {
title = archiveNameLabel;
} else {
title = (0, _i18n.sprintf)(/* translators: %s: Archive type title e.g: "Category", "Tag"... */
(0, _i18n.__)('%s name'), archiveTypeLabel);
}
} else {
title = showPrefix ? (0, _i18n.__)('Archive type: Name') : (0, _i18n.__)('Archive title');
}
titleElement = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanel, {
label: (0, _i18n.__)('Settings'),
resetAll: () => setAttributes({
showPrefix: true
}),
dropdownMenuProps: dropdownMenuProps,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanelItem, {
hasValue: () => !showPrefix,
label: (0, _i18n.__)('Show archive type in title'),
onDeselect: () => setAttributes({
showPrefix: true
}),
isShownByDefault: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToggleControl, {
__nextHasNoMarginBottom: true,
label: (0, _i18n.__)('Show archive type in title'),
onChange: () => setAttributes({
showPrefix: !showPrefix
}),
checked: showPrefix
})
})
})
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(TagName, {
...blockProps,
children: title
})]
});
}
if (type === 'search') {
titleElement = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.InspectorControls, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanel, {
label: (0, _i18n.__)('Settings'),
resetAll: () => setAttributes({
showSearchTerm: true
}),
dropdownMenuProps: dropdownMenuProps,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalToolsPanelItem, {
hasValue: () => !showSearchTerm,
label: (0, _i18n.__)('Show search term in title'),
onDeselect: () => setAttributes({
showSearchTerm: true
}),
isShownByDefault: true,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToggleControl, {
__nextHasNoMarginBottom: true,
label: (0, _i18n.__)('Show search term in title'),
onChange: () => setAttributes({
showSearchTerm: !showSearchTerm
}),
checked: showSearchTerm
})
})
})
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(TagName, {
...blockProps,
children: showSearchTerm ? (0, _i18n.__)('Search results for: “search term”') : (0, _i18n.__)('Search results')
})]
});
}
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_blockEditor.BlockControls, {
group: "block",
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.HeadingLevelDropdown, {
value: level,
options: levelOptions,
onChange: newLevel => setAttributes({
level: newLevel
})
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.AlignmentControl, {
value: textAlign,
onChange: nextAlign => {
setAttributes({
textAlign: nextAlign
});
}
})]
}), titleElement]
});
}
//# sourceMappingURL=edit.js.map
;