UNPKG

@bytedance/mona-client-web

Version:

web for mona

38 lines 1.88 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import React, { useCallback, useRef, useState } from 'react'; import { useProps } from './hooks'; import PickerMask from './mask'; import PickerView from './pickerView'; var Picker = function (props) { var _a = useState(false), visible = _a[0], setVisible = _a[1]; var newProps = useProps(props); var pickerRef = useRef(newProps.value); var propsRef = useRef(newProps); var handleCancel = useCallback(function (e) { var _a, _b; setVisible(false); (_b = (_a = propsRef.current) === null || _a === void 0 ? void 0 : _a.onCancel) === null || _b === void 0 ? void 0 : _b.call(_a, __assign(__assign({}, e), { detail: { value: pickerRef.current.getData() } })); }, []); var handleConfirm = useCallback(function (e) { var _a, _b; setVisible(false); (_b = (_a = propsRef.current) === null || _a === void 0 ? void 0 : _a.onConfirm) === null || _b === void 0 ? void 0 : _b.call(_a, __assign(__assign({}, e), { detail: { value: pickerRef.current.getData() } })); }, []); return (React.createElement("div", null, React.createElement("div", { onTouchStart: function () { return !props.disabled && setVisible(true); } }, props.children, React.createElement(PickerMask, { visible: visible, onCancel: handleCancel, onConfirm: handleConfirm }, React.createElement(PickerView, __assign({ ref: pickerRef }, newProps)))))); }; export default Picker; //# sourceMappingURL=index.js.map