@wordpress/components
Version:
UI components for WordPress.
170 lines (168 loc) • 6.48 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/components/src/custom-gradient-picker/index.tsx
var custom_gradient_picker_exports = {};
__export(custom_gradient_picker_exports, {
CustomGradientPicker: () => CustomGradientPicker,
default: () => custom_gradient_picker_default
});
module.exports = __toCommonJS(custom_gradient_picker_exports);
var import_i18n = require("@wordpress/i18n");
var import_angle_picker_control = __toESM(require("../angle-picker-control"));
var import_gradient_bar = __toESM(require("./gradient-bar"));
var import_flex = require("../flex");
var import_select_control = __toESM(require("../select-control"));
var import_v_stack = require("../v-stack");
var import_utils = require("./utils");
var import_serializer = require("./serializer");
var import_constants = require("./constants");
var import_custom_gradient_picker_styles = require("./styles/custom-gradient-picker-styles");
var import_jsx_runtime = require("react/jsx-runtime");
var GradientAnglePicker = ({
gradientAST,
hasGradient,
onChange
}) => {
var _gradientAST$orientat;
const angle = (_gradientAST$orientat = gradientAST?.orientation?.value) !== null && _gradientAST$orientat !== void 0 ? _gradientAST$orientat : import_constants.DEFAULT_LINEAR_GRADIENT_ANGLE;
const onAngleChange = (newAngle) => {
onChange((0, import_serializer.serializeGradient)({
...gradientAST,
orientation: {
type: "angular",
value: `${newAngle}`
}
}));
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_angle_picker_control.default, {
onChange: onAngleChange,
value: hasGradient ? angle : ""
});
};
var GradientTypePicker = ({
gradientAST,
hasGradient,
onChange
}) => {
const {
type
} = gradientAST;
const onSetLinearGradient = () => {
onChange((0, import_serializer.serializeGradient)({
...gradientAST,
orientation: gradientAST.orientation ? void 0 : import_constants.HORIZONTAL_GRADIENT_ORIENTATION,
type: "linear-gradient"
}));
};
const onSetRadialGradient = () => {
const {
orientation,
...restGradientAST
} = gradientAST;
onChange((0, import_serializer.serializeGradient)({
...restGradientAST,
type: "radial-gradient"
}));
};
const handleOnChange = (next) => {
if (next === "linear-gradient") {
onSetLinearGradient();
}
if (next === "radial-gradient") {
onSetRadialGradient();
}
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_select_control.default, {
__nextHasNoMarginBottom: true,
className: "components-custom-gradient-picker__type-picker",
label: (0, import_i18n.__)("Type"),
labelPosition: "top",
onChange: handleOnChange,
options: import_constants.GRADIENT_OPTIONS,
size: "__unstable-large",
value: hasGradient ? type : void 0
});
};
function CustomGradientPicker({
value,
onChange,
enableAlpha = true,
__experimentalIsRenderedInSidebar = false
}) {
const {
gradientAST,
hasGradient
} = (0, import_utils.getGradientAstWithDefault)(value);
const background = (0, import_utils.getLinearGradientRepresentation)(gradientAST);
const controlPoints = gradientAST.colorStops.map((colorStop) => {
return {
color: (0, import_utils.getStopCssColor)(colorStop),
// Although it's already been checked by `hasUnsupportedLength` in `getGradientAstWithDefault`,
// TypeScript doesn't know that `colorStop.length` is not undefined here.
// @ts-expect-error
position: parseInt(colorStop.length.value)
};
});
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_v_stack.VStack, {
spacing: 4,
className: "components-custom-gradient-picker",
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_gradient_bar.default, {
__experimentalIsRenderedInSidebar,
disableAlpha: !enableAlpha,
background,
hasGradient,
value: controlPoints,
onChange: (newControlPoints) => {
onChange((0, import_serializer.serializeGradient)((0, import_utils.getGradientAstWithControlPoints)(gradientAST, newControlPoints)));
}
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_flex.Flex, {
gap: 3,
className: "components-custom-gradient-picker__ui-line",
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_custom_gradient_picker_styles.SelectWrapper, {
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GradientTypePicker, {
gradientAST,
hasGradient,
onChange
})
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_custom_gradient_picker_styles.AccessoryWrapper, {
children: gradientAST.type === "linear-gradient" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GradientAnglePicker, {
gradientAST,
hasGradient,
onChange
})
})]
})]
});
}
var custom_gradient_picker_default = CustomGradientPicker;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CustomGradientPicker
});
//# sourceMappingURL=index.js.map