@wordpress/components
Version:
UI components for WordPress.
72 lines (64 loc) • 1.81 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import { createElement } from "@wordpress/element";
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { StyledUnitControl, ControlWrapper } from './styles/focal-point-picker-style';
import { fractionToPercentage } from './utils';
const TEXTCONTROL_MIN = 0;
const TEXTCONTROL_MAX = 100;
const noop = () => {};
export default function FocalPointPickerControls(_ref) {
let {
__nextHasNoMarginBottom,
hasHelpText,
onChange = noop,
point = {
x: 0.5,
y: 0.5
}
} = _ref;
const valueX = fractionToPercentage(point.x);
const valueY = fractionToPercentage(point.y);
const handleChange = (value, axis) => {
if (value === undefined) return;
const num = parseInt(value, 10);
if (!isNaN(num)) {
onChange({ ...point,
[axis]: num / 100
});
}
};
return createElement(ControlWrapper, {
className: "focal-point-picker__controls",
__nextHasNoMarginBottom: __nextHasNoMarginBottom,
hasHelpText: hasHelpText
}, createElement(FocalPointUnitControl, {
label: __('Left'),
value: [valueX, '%'].join(''),
onChange: next => handleChange(next, 'x'),
dragDirection: "e"
}), createElement(FocalPointUnitControl, {
label: __('Top'),
value: [valueY, '%'].join(''),
onChange: next => handleChange(next, 'y'),
dragDirection: "s"
}));
}
function FocalPointUnitControl(props) {
return createElement(StyledUnitControl, _extends({
className: "focal-point-picker__controls-position-unit-control",
labelPosition: "top",
max: TEXTCONTROL_MAX,
min: TEXTCONTROL_MIN,
units: [{
value: '%',
label: '%'
}]
}, props));
}
//# sourceMappingURL=controls.js.map