@wordpress/components
Version:
UI components for WordPress.
43 lines (42 loc) • 1.28 kB
JavaScript
/**
* WordPress dependencies
*/
import { useMergeRefs } from '@wordpress/compose';
import { forwardRef, useRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import { ControlWithError } from '../control-with-error';
import RangeControl from '../../range-control';
import { jsx as _jsx } from "react/jsx-runtime";
const UnforwardedValidatedRangeControl = ({
required,
customValidator,
onChange,
markWhenOptional,
...restProps
}, forwardedRef) => {
const validityTargetRef = useRef(null);
const mergedRefs = useMergeRefs([forwardedRef, validityTargetRef]);
const valueRef = useRef(restProps.value);
return /*#__PURE__*/_jsx(ControlWithError, {
required: required,
markWhenOptional: markWhenOptional,
customValidator: () => {
return customValidator?.(valueRef.current);
},
getValidityTarget: () => validityTargetRef.current,
children: /*#__PURE__*/_jsx(RangeControl, {
__next40pxDefaultSize: true,
__nextHasNoMarginBottom: true,
ref: mergedRefs,
onChange: value => {
valueRef.current = value;
onChange?.(value);
},
...restProps
})
});
};
export const ValidatedRangeControl = forwardRef(UnforwardedValidatedRangeControl);
//# sourceMappingURL=range-control.js.map