@wordpress/block-editor
Version:
176 lines (174 loc) • 7.12 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/block-editor/src/components/colors-gradients/control.js
var control_exports = {};
__export(control_exports, {
default: () => control_default
});
module.exports = __toCommonJS(control_exports);
var import_clsx = __toESM(require("clsx"));
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_use_settings = require("../use-settings");
var import_lock_unlock = require("../../lock-unlock");
var import_jsx_runtime = require("react/jsx-runtime");
var { Tabs } = (0, import_lock_unlock.unlock)(import_components.privateApis);
var colorsAndGradientKeys = [
"colors",
"disableCustomColors",
"gradients",
"disableCustomGradients"
];
var TAB_IDS = { color: "color", gradient: "gradient" };
function ColorGradientControlInner({
colors,
gradients,
disableCustomColors,
disableCustomGradients,
__experimentalIsRenderedInSidebar,
className,
label,
onColorChange,
onGradientChange,
colorValue,
gradientValue,
clearable,
showTitle = true,
enableAlpha,
headingLevel
}) {
const canChooseAColor = onColorChange && (colors && colors.length > 0 || !disableCustomColors);
const canChooseAGradient = onGradientChange && (gradients && gradients.length > 0 || !disableCustomGradients);
if (!canChooseAColor && !canChooseAGradient) {
return null;
}
const tabPanels = {
[TAB_IDS.color]: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.ColorPalette,
{
value: colorValue,
onChange: canChooseAGradient ? (newColor) => {
onColorChange(newColor);
onGradientChange();
} : onColorChange,
...{ colors, disableCustomColors },
__experimentalIsRenderedInSidebar,
clearable,
enableAlpha,
headingLevel
}
),
[TAB_IDS.gradient]: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.GradientPicker,
{
value: gradientValue,
onChange: canChooseAColor ? (newGradient) => {
onGradientChange(newGradient);
onColorChange();
} : onGradientChange,
...{ gradients, disableCustomGradients },
__experimentalIsRenderedInSidebar,
clearable,
headingLevel
}
)
};
const renderPanelType = (type) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-color-gradient-control__panel", children: tabPanels[type] });
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_components.BaseControl,
{
__nextHasNoMarginBottom: true,
className: (0, import_clsx.default)(
"block-editor-color-gradient-control",
className
),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("fieldset", { className: "block-editor-color-gradient-control__fieldset", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { spacing: 1, children: [
showTitle && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-color-gradient-control__color-indicator", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.BaseControl.VisualLabel, { children: label }) }) }),
canChooseAColor && canChooseAGradient && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
Tabs,
{
defaultTabId: gradientValue ? TAB_IDS.gradient : !!canChooseAColor && TAB_IDS.color,
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Tabs.TabList, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.Tab, { tabId: TAB_IDS.color, children: (0, import_i18n.__)("Color") }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tabs.Tab, { tabId: TAB_IDS.gradient, children: (0, import_i18n.__)("Gradient") })
] }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
Tabs.TabPanel,
{
tabId: TAB_IDS.color,
className: "block-editor-color-gradient-control__panel",
focusable: false,
children: tabPanels.color
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
Tabs.TabPanel,
{
tabId: TAB_IDS.gradient,
className: "block-editor-color-gradient-control__panel",
focusable: false,
children: tabPanels.gradient
}
)
]
}
) }),
!canChooseAGradient && renderPanelType(TAB_IDS.color),
!canChooseAColor && renderPanelType(TAB_IDS.gradient)
] }) })
}
);
}
function ColorGradientControlSelect(props) {
const [colors, gradients, customColors, customGradients] = (0, import_use_settings.useSettings)(
"color.palette",
"color.gradients",
"color.custom",
"color.customGradient"
);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
ColorGradientControlInner,
{
colors,
gradients,
disableCustomColors: !customColors,
disableCustomGradients: !customGradients,
...props
}
);
}
function ColorGradientControl(props) {
if (colorsAndGradientKeys.every((key) => props.hasOwnProperty(key))) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ColorGradientControlInner, { ...props });
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ColorGradientControlSelect, { ...props });
}
var control_default = ColorGradientControl;
//# sourceMappingURL=control.js.map