UNPKG

@bytedance/mona-client-web

Version:

web for mona

54 lines 2.58 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 } from 'react'; import ReactDOM from 'react-dom'; import { Masking } from '../Masking'; import { hide } from '../util'; import './index.module.less'; export var MONA_WEB_ACTION_SHEET = 'mona-web-action-sheet'; export function ActionSheet(props) { var _a; var handleItem = useCallback(function (tapIndex) { var _a, _b; var errMsg = { errMsg: 'showActionSheet:ok', tapIndex: tapIndex, }; (_a = props === null || props === void 0 ? void 0 : props.success) === null || _a === void 0 ? void 0 : _a.call(props, errMsg); (_b = props === null || props === void 0 ? void 0 : props.complete) === null || _b === void 0 ? void 0 : _b.call(props, errMsg); hide(MONA_WEB_ACTION_SHEET); }, [props]); return (React.createElement(React.Fragment, null, React.createElement("div", { className: "mona-web-action-sheet-body" }, (_a = props.itemList) === null || _a === void 0 ? void 0 : _a.map(function (item, idx) { return (React.createElement("div", { key: item, onClick: function () { return handleItem(idx); }, className: "mona-web-action-sheet-item" }, item)); })), React.createElement(Masking, { onHandle: function () { return hide(MONA_WEB_ACTION_SHEET); } }))); } function confirm(props) { var container = document.createElement('div'); container.id = MONA_WEB_ACTION_SHEET; function render() { document.body.append(container); ReactDOM.render(React.createElement(ActionSheet, __assign({}, props)), container); } render(); } export function webShowActionSheet(options) { var _a, _b; if (Array.isArray(options === null || options === void 0 ? void 0 : options.itemList) && options.itemList) { confirm(options); } else { var errMsg = 'showActionSheet:fail'; (_a = options === null || options === void 0 ? void 0 : options.fail) === null || _a === void 0 ? void 0 : _a.call(options, { errMsg: errMsg }); (_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(options, { errMsg: errMsg }); } } //# sourceMappingURL=index.js.map