UNPKG

@appbuckets/react-ui

Version:
38 lines (35 loc) 943 B
import { __read } from 'tslib'; import * as React from 'react'; /** * Use this hook to get automatically the color picker value * and the handler function to attach to color picker. * Additionally function to force change will be returned * * @param initialValue */ function useColorPickerValue(initialValue) { // ---- // Internal State // ---- var _a = __read( React.useState( initialValue !== null && initialValue !== void 0 ? initialValue : '' ), 2 ), colorPickerValue = _a[0], setColorPickerValue = _a[1]; // ---- // Handler // ---- var handleColorPickerChange = React.useCallback(function (e, props) { var _a; /** Set new value */ setColorPickerValue((_a = props.color) !== null && _a !== void 0 ? _a : ''); }, []); // ---- // Hook Return // ---- return [colorPickerValue, handleColorPickerChange, setColorPickerValue]; } export { useColorPickerValue };