UNPKG

@uiw/react-signature

Version:

A signature board component for react.

46 lines 1.86 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; var _excluded = ["children", "options", "renderPath", "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, renderPath, defaultPoints } = _ref, props = _objectWithoutPropertiesLoose(_ref, _excluded); var [state, dispatch] = useReducer(reducer, Object.assign({}, defaultPoints)); var [stateOption, dispatchOption] = useReducer(reducerOption, Object.assign(_extends({}, defaultOptions, { renderPath }), options)); useEffect(() => dispatchOption(_extends({}, options, { renderPath })), [options, renderPath]); return /*#__PURE__*/_jsx(PointerContext.Provider, { value: state, children: /*#__PURE__*/_jsx(PointerDispatchContext.Provider, { value: dispatch, children: /*#__PURE__*/_jsxs(Container, _extends({}, props, { ref: ref, children: [/*#__PURE__*/_jsx(OptionContext.Provider, { value: stateOption, children: /*#__PURE__*/_jsx(OptionDispatchContext.Provider, { value: dispatchOption, children: /*#__PURE__*/_jsx(Paths, {}) }) }), children] })) }) }); }); export default Signature;