UNPKG

antd-mobile-taro-ui

Version:

以antd-mobile为设计标准,基于taro框架的微信小程序组件库

74 lines (70 loc) 2.92 kB
import { __awaiter } from "tslib"; import React from 'react'; import { mergeProps } from 'antd-mobile/es/utils/with-default-props'; import classNames from 'classnames'; import { View, Image } from '@tarojs/components'; import { DialogActionButton } from './dialog-action-button'; import AutoCenter from '../auto-center'; import CenterPopup from '../center-popup'; const defaultProps = { actions: [], closeOnAction: false, closeOnMaskClick: false }; export const Dialog = p => { const props = mergeProps(defaultProps, p); const element = React.createElement(React.Fragment, null, !!props.image && React.createElement(View, { className: cls('image-container') }, React.createElement(Image, { src: props.image, mode: 'widthFix' })), !!props.header && React.createElement(View, { className: cls('header') }, React.createElement(AutoCenter, null, props.header)), !!props.title && React.createElement(View, { className: cls('title') }, props.title), React.createElement(View, { className: classNames(cls('content'), !props.content && cls('content-empty')) }, typeof props.content === 'string' ? React.createElement(AutoCenter, null, props.content) : props.content), React.createElement(View, { className: cls('footer') }, props.actions.map((row, index) => { const actions = Array.isArray(row) ? row : [row]; return React.createElement(View, { className: cls('action-row'), key: index }, actions.map((action, index) => React.createElement(DialogActionButton, { key: action.key, action: action, onAction: () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; yield Promise.all([(_a = action.onClick) === null || _a === void 0 ? void 0 : _a.call(action), (_b = props.onAction) === null || _b === void 0 ? void 0 : _b.call(props, action, index)]); if (props.closeOnAction) { (_c = props.onClose) === null || _c === void 0 ? void 0 : _c.call(props); } }) }))); }))); return React.createElement(CenterPopup, { className: classNames(cls(), props.className), style: props.style, afterClose: props.afterClose, afterShow: props.afterShow, onMaskClick: props.closeOnMaskClick ? () => { var _a; (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props); } : undefined, visible: props.visible, bodyStyle: props.bodyStyle, bodyClassName: classNames(cls('body'), props.image && cls('with-image'), props.bodyClassName), maskStyle: props.maskStyle, maskClassName: props.maskClassName, stopPropagation: props.stopPropagation, disableBodyScroll: props.disableBodyScroll, destroyOnClose: props.destroyOnClose, forceRender: props.forceRender, role: 'dialog', "aria-label": props['aria-label'] }, element); }; function cls(name = '') { return `adm-dialog${name && '-'}${name}`; }