@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
80 lines (71 loc) • 2.65 kB
JavaScript
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 React, { memo } from 'react';
import { View } from 'react-native';
import { attachPropertiesToComponent, renderTextLikeJSX } from '../helpers';
import CrossOutline from '../icon/cross';
import SuccessOutline from '../icon/success';
import WarningOutline from '../icon/warning';
import Space from '../space';
import Theme from '../theme';
import IconBox from './icons/result-icon-box';
import IconEmpty from './icons/result-icon-empty';
import IconError from './icons/result-icon-error';
import IconWarning from './icons/result-icon-warning';
import { varCreator, styleCreator } from './style';
const renderStatusIcon = (status, size) => {
const props = {
size,
color: '#fff'
};
switch (status) {
case 'success':
return /*#__PURE__*/React.createElement(SuccessOutline, props);
case 'warning':
case 'info':
return /*#__PURE__*/React.createElement(WarningOutline, props);
case 'error':
return /*#__PURE__*/React.createElement(CrossOutline, props);
default:
return null;
}
};
/**
* Result结果
* @description 用于反馈一系列操作任务的处理结果。
*/
const Result = _ref => {
let {
subtitleTextStyle,
titleTextStyle,
title,
subtitle,
extra,
renderIcon,
status,
...restProps
} = _ref;
const TOKENS = Theme.useThemeTokens();
const CV = Theme.createVar(TOKENS, varCreator);
const STYLES = Theme.createStyle(CV, styleCreator);
const color = CV[`result_${status}_color`];
const iconSize = CV.result_icon_size / 4 * 3;
const iconJSX = renderIcon ? renderIcon(color, iconSize) : /*#__PURE__*/React.createElement(View, {
style: [STYLES.icon, {
backgroundColor: color
}]
}, renderStatusIcon(status, iconSize));
const titleJSX = renderTextLikeJSX(title, [STYLES.titleText, titleTextStyle]);
const subtitleJSX = renderTextLikeJSX(subtitle, [STYLES.subtitleText, subtitleTextStyle]);
return /*#__PURE__*/React.createElement(Space, _extends({}, restProps, {
justify: "center",
align: "center"
}), iconJSX, titleJSX, subtitleJSX, extra);
};
const ResultMemo = /*#__PURE__*/memo(Result);
export default attachPropertiesToComponent(ResultMemo, {
IconBox: IconBox,
IconEmpty: IconEmpty,
IconError: IconError,
IconWarning: IconWarning
});
//# sourceMappingURL=index.js.map