UNPKG

@uiw/react-signature

Version:

A signature board component for react.

41 lines 1.78 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; var _excluded = ["children", "options", "defaultPoints"]; import React, { useReducer, forwardRef, useEffect } from 'react'; import { PointerContext, PointerDispatchContext, reducer } from "../store.js"; import { OptionContext, OptionDispatchContext, reducerOption, defaultOptions } from "../options.js"; import { Signature as Container } from "./Signature.js"; import { Paths } from "./Paths.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export * from 'perfect-freehand'; export * from "../utils.js"; export * from "../options.js"; export * from "../store.js"; var Signature = /*#__PURE__*/forwardRef((_ref, ref) => { var { children, options, defaultPoints } = _ref, props = _objectWithoutPropertiesLoose(_ref, _excluded); var [state, dispatch] = useReducer(reducer, Object.assign({}, defaultPoints)); var [stateOption, dispatchOption] = useReducer(reducerOption, Object.assign(_extends({}, defaultOptions), options)); useEffect(() => dispatchOption(_extends({}, options)), [options]); return /*#__PURE__*/_jsx(PointerContext.Provider, { value: state, children: /*#__PURE__*/_jsx(PointerDispatchContext.Provider, { value: dispatch, children: /*#__PURE__*/_jsx(OptionContext.Provider, { value: stateOption, children: /*#__PURE__*/_jsxs(OptionDispatchContext.Provider, { value: dispatchOption, children: [/*#__PURE__*/_jsx(Container, _extends({}, props, { ref: ref, children: children })), /*#__PURE__*/_jsx(Paths, {})] }) }) }) }); }); export default Signature;