UNPKG

mh-rn-component

Version:

135 lines (122 loc) 3.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _reactNative = require("react-native"); var _Overlay = _interopRequireDefault(require("../Overlay")); var _Button = _interopRequireDefault(require("../Button")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const Dialog = _ref => { let { show, zIndex, children, style, title, width = 360, message, messageAlign = "center", showConfirmButton = true, showCancelButton = true, confirmButtonText = "确认", confirmButtonColor = "#ee0a24", cancelButtonText = "取消", cancelButtonColor = "#333333", fontSizeButtonText = 16, overlay = true, closeOnClickOverlay = true, customButton, customTitle, ...rest } = _ref; const changeStatus = () => { rest.id ? rest.onChange(rest.id) : rest.onChange(false); }; const cancel = () => { rest.cancel && rest.cancel(); changeStatus(); }; const confirm = () => { rest.confirm && rest.confirm(); changeStatus(); }; return /*#__PURE__*/_react.default.createElement(_Overlay.default, { show: show, style: [rest.overlayStyle, !overlay && { backgroundColor: '' }], onChange: () => closeOnClickOverlay && changeStatus(), zIndex: zIndex }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableWithoutFeedback, null, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, null, /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: _reactNative.StyleSheet.flatten([styles.dialog, { width: width }, style]) }, customTitle ? customTitle() : title && /*#__PURE__*/_react.default.createElement(_reactNative.Text, { style: styles.title }, title), children ? children : /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: styles.content }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, { style: _reactNative.StyleSheet.flatten([styles.content_text, { textAlign: messageAlign }]) }, typeof message === "string" ? message : message())), !customButton && /*#__PURE__*/_react.default.createElement(_reactNative.View, { style: styles.dialog_confirm_button }, showCancelButton && /*#__PURE__*/_react.default.createElement(_Button.default, { onPress: cancel, textStyle: { fontSize: fontSizeButtonText, color: cancelButtonColor }, style: _reactNative.StyleSheet.flatten([{ width: showConfirmButton ? width / 2 : width, borderWidth: 0 }]) }, cancelButtonText), showConfirmButton && /*#__PURE__*/_react.default.createElement(_Button.default, { onPress: confirm, textStyle: { fontSize: fontSizeButtonText, color: confirmButtonColor }, style: _reactNative.StyleSheet.flatten([{ width: showCancelButton ? width / 2 : width, borderWidth: 0 }]) }, confirmButtonText)), customButton && customButton())))); }; const styles = _reactNative.StyleSheet.create({ dialog: { borderRadius: 10, backgroundColor: "#ffffff", paddingTop: 24, overflow: "hidden" }, title: { fontSize: 18, width: "100%", textAlign: 'center', fontWeight: '600', paddingLeft: 16, paddingRight: 16 }, content: { width: "100%", marginTop: 16, marginBottom: 16, paddingLeft: 16, paddingRight: 16 }, content_text: { fontSize: 16, textAlign: 'center' }, dialog_confirm_button: { flexDirection: 'row', alignItems: 'center', justifyContent: "center" } }); var _default = Dialog; exports.default = _default; //# sourceMappingURL=index.js.map