UNPKG

@wordpress/components

Version:
92 lines (90 loc) 3.09 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/components/src/focal-point-picker/controls.tsx var controls_exports = {}; __export(controls_exports, { default: () => FocalPointPickerControls }); module.exports = __toCommonJS(controls_exports); var import_i18n = require("@wordpress/i18n"); var import_focal_point_picker_style = require("./styles/focal-point-picker-style"); var import_utils = require("./utils"); var import_jsx_runtime = require("react/jsx-runtime"); var TEXTCONTROL_MIN = 0; var TEXTCONTROL_MAX = 100; var noop = () => { }; function FocalPointPickerControls({ __nextHasNoMarginBottom, hasHelpText, onChange = noop, point = { x: 0.5, y: 0.5 } }) { const valueX = (0, import_utils.fractionToPercentage)(point.x); const valueY = (0, import_utils.fractionToPercentage)(point.y); const handleChange = (value, axis) => { if (value === void 0) { return; } const num = parseInt(value, 10); if (!isNaN(num)) { onChange({ ...point, [axis]: num / 100 }); } }; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_focal_point_picker_style.ControlWrapper, { className: "focal-point-picker__controls", __nextHasNoMarginBottom, hasHelpText, gap: 4, children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocalPointUnitControl, { label: (0, import_i18n.__)("Left"), "aria-label": (0, import_i18n.__)("Focal point left position"), value: [valueX, "%"].join(""), onChange: (next) => handleChange(next, "x"), dragDirection: "e" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocalPointUnitControl, { label: (0, import_i18n.__)("Top"), "aria-label": (0, import_i18n.__)("Focal point top position"), value: [valueY, "%"].join(""), onChange: (next) => handleChange(next, "y"), dragDirection: "s" })] }); } function FocalPointUnitControl(props) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_focal_point_picker_style.StyledUnitControl, { __next40pxDefaultSize: true, className: "focal-point-picker__controls-position-unit-control", labelPosition: "top", max: TEXTCONTROL_MAX, min: TEXTCONTROL_MIN, units: [{ value: "%", label: "%" }], ...props }); } //# sourceMappingURL=controls.js.map