UNPKG

@wordpress/components

Version:
71 lines (70 loc) • 2.59 kB
import clsx from "clsx"; import { forwardRef } from "@wordpress/element"; import { __, isRTL } from "@wordpress/i18n"; import { Flex, FlexBlock } from "../flex/index.mjs"; import { Spacer } from "../spacer/index.mjs"; import NumberControl from "../number-control/index.mjs"; import InputControlPrefixWrapper from "../input-control/input-prefix-wrapper.mjs"; import InputControlSuffixWrapper from "../input-control/input-suffix-wrapper.mjs"; import AngleCircle from "./angle-circle.mjs"; import { jsx, jsxs } from "react/jsx-runtime"; // packages/components/src/angle-picker-control/index.tsx function UnforwardedAnglePickerControl(props, ref) { const { className, label = __("Angle"), onChange, value, ...restProps } = props; const handleOnNumberChange = (unprocessedValue) => { if (onChange === void 0) return; onChange(unprocessedValue !== void 0 && unprocessedValue !== "" ? parseInt(unprocessedValue, 10) : 0); }; const classes = clsx("components-angle-picker-control", className); const prefixOrSuffixProp = isRTL() ? { prefix: /* @__PURE__ */ jsx(InputControlPrefixWrapper, { children: "°" }) } : { suffix: /* @__PURE__ */ jsx(InputControlSuffixWrapper, { children: "°" }) }; return /* @__PURE__ */ jsxs(Flex, { ...restProps, ref, className: classes, gap: 2, children: [/* @__PURE__ */ jsx(FlexBlock, { children: /* @__PURE__ */ jsx(NumberControl, { label, className: "components-angle-picker-control__input-field", max: 360, min: 0, onChange: handleOnNumberChange, step: "1", value, spinControls: "none", ...prefixOrSuffixProp }) }), /* @__PURE__ */ jsx(Spacer, { marginBottom: "1", marginTop: "auto", children: /* @__PURE__ */ jsx(AngleCircle, { "aria-hidden": "true", value, onChange }) })] }); } /** * `AnglePickerControl` is a React component to render a UI that allows users to * pick an angle. Users can choose an angle in a visual UI with the mouse by * dragging an angle indicator inside a circle or by directly inserting the * desired angle in a text field. * * ```jsx * import { useState } from '@wordpress/element'; * import { AnglePickerControl } from '@wordpress/components'; * * function Example() { * const [ angle, setAngle ] = useState( 0 ); * return ( * <AnglePickerControl * value={ angle } * onChange={ setAngle } * /> * ); * } * ``` */ const AnglePickerControl = forwardRef(UnforwardedAnglePickerControl); AnglePickerControl.displayName = "AnglePickerControl"; export { AnglePickerControl, AnglePickerControl as default }; //# sourceMappingURL=index.mjs.map