UNPKG

@fruits-chain/react-native-xiaoshu

Version:
110 lines (107 loc) 4.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _iconsReactNative = require("@fruits-chain/icons-react-native"); var _color = _interopRequireDefault(require("color")); var _isNil = _interopRequireDefault(require("lodash/isNil")); var _noop = _interopRequireDefault(require("lodash/noop")); var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _index = require("../helpers/index.js"); var _index2 = require("../hooks/index.js"); var _index3 = _interopRequireDefault(require("../theme/index.js")); var _style = require("./style.js"); var _jsxRuntime = require("react/jsx-runtime"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const getModeIcon = mode => { switch (mode) { case 'closeable': return _iconsReactNative.CrossOutline; default: return _iconsReactNative.ArrowRightOutline; } }; /** * 通知栏 */ const NoticeBar = ({ theme, message, messageTextStyle, status = 'warning', mode, bordered = false, color, backgroundColor, iconColor, wrapable = false, square = true, size = 'm', renderLeftIcon, renderRightIcon, onPressClose, // TouchableWithoutFeedback 相关属性 style, ...restProps }) => { const onPressClosePersistFn = (0, _index2.usePersistFn)(onPressClose || _noop.default); const [CV, STYLES] = _index3.default.useStyle({ varCreator: _style.varCreator, styleCreator: _style.styleCreator, theme }); const [visible, setVisible] = (0, _react.useState)(true); const textColor = CV[`notice_bar_${status}_text_color`] || CV.notice_bar_warning_text_color; const barBackgroundColor = (0, _react.useMemo)(() => (0, _color.default)(textColor).lightness(CV.notice_bar_background_color_lightness).hex(), [CV.notice_bar_background_color_lightness, textColor]); // 修正数据 color = (0, _index.getDefaultValue)(color, textColor); backgroundColor = (0, _index.getDefaultValue)(backgroundColor, barBackgroundColor); iconColor = (0, _index.getDefaultValue)(iconColor, color); const noticeBarStyles = [STYLES.notice_bar, STYLES[`notice_bar_${size}`], { backgroundColor, borderRadius: square ? 0 : CV.notice_bar_border_radius, borderColor: color, borderWidth: bordered ? 1 : 0 }, style]; const ModeIcon = getModeIcon(mode); const leftIconJSX = renderLeftIcon?.(iconColor, CV.notice_bar_icon_size); const rightIconJSX = renderRightIcon?.(iconColor, CV.notice_bar_icon_size); const messageJSX = (0, _index.renderTextLikeJSX)(message, [STYLES.text, { color, marginLeft: !(0, _isNil.default)(leftIconJSX) ? CV.notice_bar_icon_margin_horizontal : 0, marginRight: !(0, _isNil.default)(rightIconJSX) || mode ? CV.notice_bar_icon_margin_horizontal : 0 }, messageTextStyle], { numberOfLines: wrapable ? undefined : 1 }); const onPressModeIcon = (0, _react.useCallback)(() => { if (mode === 'closeable') { setVisible(false); onPressClosePersistFn(); } }, [mode, onPressClosePersistFn]); const touchableProps = (0, _index.pickTouchablePropsField)(restProps); const viewProps = (0, _index.omitTouchablePropsField)(restProps); if (visible) { return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableWithoutFeedback, { ...touchableProps, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { ...viewProps, style: noticeBarStyles, children: [leftIconJSX, messageJSX, rightIconJSX, mode ? /*#__PURE__*/(0, _jsxRuntime.jsx)(ModeIcon, { testID: "NOTICE_BAR_ICON", color: iconColor, size: CV.notice_bar_icon_size, onPress: onPressModeIcon, pointerEvents: mode === 'closeable' ? 'auto' : 'none' }) : null] }) }); } return null; }; var _default = exports.default = /*#__PURE__*/(0, _react.memo)(NoticeBar); //# sourceMappingURL=notice-bar.js.map