UNPKG

@fruits-chain/react-native-xiaoshu

Version:
53 lines (52 loc) • 1.97 kB
"use strict"; import isNil from 'lodash/isNil'; import React, { memo } from 'react'; import { View } from 'react-native'; import { formatDate } from "../date-picker-view/helper.js"; import { renderTextLikeJSX, getDefaultValue } from "../helpers/index.js"; import Locale from "../locale/index.js"; import Theme from "../theme/index.js"; import { useDescription } from "./context.js"; import Description from "./description.js"; import { varCreator, styleCreator } from "./style.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const DescriptionDateRange = ({ text, mode = 'Y-m', split, ...restProps }) => { const start = !isNil(text?.[0]) ? formatDate(mode, text[0]) : null; const end = !isNil(text?.[1]) ? formatDate(mode, text[1]) : null; const locale = Locale.useLocale().DescriptionDateRange; const [, STYLES] = Theme.useStyle({ varCreator, styleCreator, theme: restProps.theme }); const descriptionContext = useDescription(); const _contentTextStyle = getDefaultValue(restProps.contentTextStyle, descriptionContext.contentTextStyle); const _size = getDefaultValue(restProps.size, descriptionContext.size); const textSizeStyle = STYLES[`size_${_size}_text`]; const textStyles = [STYLES.content_text, textSizeStyle, restProps.bold ? { fontWeight: 'bold' } : null, restProps.color ? { color: restProps.color } : null, _contentTextStyle]; const line1JSX = renderTextLikeJSX([start, split ?? locale.split].join(' '), textStyles); const line2JSX = renderTextLikeJSX(end, textStyles); if (isNil(start) && isNil(end)) { return /*#__PURE__*/_jsx(Description, { ...restProps }); } return /*#__PURE__*/_jsx(Description, { ...restProps, children: /*#__PURE__*/_jsxs(View, { style: STYLES.content_date_range, children: [line1JSX, line2JSX] }) }); }; export default /*#__PURE__*/memo(DescriptionDateRange); //# sourceMappingURL=description-date-range.js.map