UNPKG

@fruits-chain/react-native-xiaoshu

Version:
87 lines (83 loc) 3.23 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import isNil from 'lodash/isNil'; import React, { memo, isValidElement } from 'react'; import { Text, View, ScrollView } from 'react-native'; import Button from '../button'; import Divider from '../divider'; import { useSafeHeight } from '../hooks'; import Popup from '../popup/popup'; import PopupHeader from '../popup/popup-header'; import Theme from '../theme'; import { varCreator, styleCreator } from './style'; /** * ActionSheet 动作面板 * @description 底部弹起的模态面板,包含与当前情境相关的多个选项。 */ const ActionSheet = _ref => { let { actions, title, cancelText, description, safeAreaInsetTop, round = true, onCancel, onSelect, ...restProps } = _ref; const safeHeight = useSafeHeight({ top: safeAreaInsetTop }); const TOKENS = Theme.useThemeTokens(); const CV = Theme.createVar(TOKENS, varCreator); const STYLES = Theme.createStyle(CV, styleCreator); const isTitleDef = !isNil(title); const isCancelTextDef = !isNil(cancelText); const isDescriptionDef = !isNil(description); /** 描述文案 纯文字或自定义 JSX */ const descriptionJSX = isDescriptionDef ? /*#__PURE__*/isValidElement(description) ? description : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, { style: [STYLES.description, isTitleDef ? null : STYLES.description_alone], numberOfLines: 1 }, description), /*#__PURE__*/React.createElement(Divider, null)) : null; return /*#__PURE__*/React.createElement(Popup, _extends({}, restProps, { safeAreaInsetBottom: true, position: "bottom", round: round }), /*#__PURE__*/React.createElement(View, { style: { maxHeight: safeHeight } }, isTitleDef ? /*#__PURE__*/React.createElement(PopupHeader, { title: title, showClose: false }) : null, descriptionJSX, /*#__PURE__*/React.createElement(ScrollView, { bounces: false }, actions.map((item, index) => { return /*#__PURE__*/React.createElement(Button, { key: `${item.name}_${index}`, text: item.name, disabled: item.disabled, loading: item.loading, color: item.color || CV.action_sheet_text_color, type: "link", size: "xl", textStyle: STYLES.button_text, onPress: () => { if (!item.disabled && !item.loading) { onSelect === null || onSelect === void 0 ? void 0 : onSelect(item, index); } } }); })), isCancelTextDef ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, { style: STYLES.gap }), /*#__PURE__*/React.createElement(Button, { text: cancelText, type: "link", size: "xl", color: CV.action_sheet_text_color, textStyle: STYLES.button_text, onPress: onCancel })) : null)); }; export default /*#__PURE__*/memo(ActionSheet); //# sourceMappingURL=action-sheet.js.map