@wordpress/block-library
Version:
Block library for the WordPress editor.
90 lines (84 loc) • 2.43 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = QueryTotalEdit;
var _blockEditor = require("@wordpress/block-editor");
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _icons = require("./icons");
var _jsxRuntime = require("react/jsx-runtime");
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
function QueryTotalEdit({
attributes,
setAttributes
}) {
const {
displayType
} = attributes;
// Block properties and classes.
const blockProps = (0, _blockEditor.useBlockProps)();
const getButtonPositionIcon = () => {
switch (displayType) {
case 'total-results':
return _icons.resultsFound;
case 'range-display':
return _icons.displayingResults;
}
};
const buttonPositionControls = [{
role: 'menuitemradio',
title: (0, _i18n.__)('Total results'),
isActive: displayType === 'total-results',
icon: _icons.resultsFound,
onClick: () => {
setAttributes({
displayType: 'total-results'
});
}
}, {
role: 'menuitemradio',
title: (0, _i18n.__)('Range display'),
isActive: displayType === 'range-display',
icon: _icons.displayingResults,
onClick: () => {
setAttributes({
displayType: 'range-display'
});
}
}];
// Controls for the block.
const controls = /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.BlockControls, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarGroup, {
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToolbarDropdownMenu, {
icon: getButtonPositionIcon(),
label: (0, _i18n.__)('Change display type'),
controls: buttonPositionControls
})
})
});
// Render output based on the selected display type.
const renderDisplay = () => {
if (displayType === 'total-results') {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
children: (0, _i18n.__)('12 results found')
});
}
if (displayType === 'range-display') {
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
children: (0, _i18n.__)('Displaying 1 – 10 of 12')
});
}
return null;
};
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
...blockProps,
children: [controls, renderDisplay()]
});
}
//# sourceMappingURL=edit.js.map
;