@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
107 lines (104 loc) • 5.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _isNil = _interopRequireDefault(require("lodash/isNil"));
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _index = require("../helpers/index.js");
var _index2 = _interopRequireDefault(require("../theme/index.js"));
var _context = require("./context.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 Description = ({
theme,
colon,
contentStyle,
contentTextStyle,
labelStyle,
labelTextStyle,
labelWidth,
layout,
size,
numberOfLines,
justify,
align,
label,
text,
hidden = false,
bold = false,
color,
addonBefore,
addonAfter,
renderLabel,
render,
empty,
showEmpty,
children,
style,
...restProps
}) => {
const [, STYLES] = _index2.default.useStyle({
varCreator: _style.varCreator,
styleCreator: _style.styleCreator,
theme
});
const descriptionContext = (0, _context.useDescription)();
// 整理默认值
const _colon = (0, _index.getDefaultValue)(colon, descriptionContext.colon);
const _contentStyle = (0, _index.getDefaultValue)(contentStyle, descriptionContext.contentStyle);
const _contentTextStyle = (0, _index.getDefaultValue)(contentTextStyle, descriptionContext.contentTextStyle);
const _labelStyle = (0, _index.getDefaultValue)(labelStyle, descriptionContext.labelStyle);
const _labelTextStyle = (0, _index.getDefaultValue)(labelTextStyle, descriptionContext.labelTextStyle);
const _labelWidth = (0, _index.getDefaultValue)(labelWidth, descriptionContext.labelWidth);
const _layout = (0, _index.getDefaultValue)(layout, descriptionContext.layout);
const _size = (0, _index.getDefaultValue)(size, descriptionContext.size);
const _justify = (0, _index.getDefaultValue)(justify, descriptionContext.justify);
const _align = (0, _index.getDefaultValue)(align, descriptionContext.align);
const _numberOfLines = (0, _index.getDefaultValue)(numberOfLines, descriptionContext.numberOfLines);
const _empty = (0, _index.getDefaultValue)(empty, descriptionContext.empty);
const _showEmpty = (0, _index.getDefaultValue)(showEmpty, descriptionContext.showEmpty);
const colonStr = _colon ? ':' : '';
const textSizeStyle = STYLES[`size_${_size}_text`];
const flexDirection = _layout === 'horizontal' ? 'row' : 'column';
const labelJSX = !(0, _isNil.default)(renderLabel) ? renderLabel(colonStr) : !(0, _isNil.default)(label) ? (0, _index.renderTextLikeJSX)(`${label}${colonStr}`, [STYLES.label_text, textSizeStyle, _labelTextStyle]) : null;
const renderText = node => (0, _index.renderTextLikeJSX)(node, [STYLES.content_text, textSizeStyle, bold ? {
fontWeight: 'bold'
} : null, color ? {
color
} : null, _contentTextStyle], {
numberOfLines: _numberOfLines
});
const contentJSX = /*#__PURE__*/(0, _react.isValidElement)(children) ? children : renderText(!(0, _isNil.default)(text) ? text : children);
// 判断是否渲染空数据占位符
const renderContentJSX = ((0, _isNil.default)(contentJSX) || text === '' || children === '') && _showEmpty ? renderText(_empty) : contentJSX;
const renderJSX = !(0, _isNil.default)(render) ? render(renderContentJSX, addonBefore, addonAfter) : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
children: [addonBefore, renderContentJSX, addonAfter]
});
if (hidden) {
return null;
}
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
...restProps,
style: [{
flexDirection,
justifyContent: _justify,
alignItems: _align
}, style],
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: [!(0, _isNil.default)(_labelWidth) ? {
width: _labelWidth
} : null, _labelStyle],
children: labelJSX
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: [STYLES.content, _contentStyle],
children: renderJSX
})]
});
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(Description);
//# sourceMappingURL=description.js.map