UNPKG

@fruits-chain/react-native-xiaoshu

Version:
77 lines (74 loc) • 3.36 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 } from 'react'; import { View, Text, ScrollView, TouchableHighlight } from 'react-native'; import Badge from '../badge'; import { useControllableValue } from '../hooks'; import Loading from '../loading'; import Locale from '../locale'; import Result from '../result'; import ResultIconEmpty from '../result/icons/result-icon-empty'; import Theme from '../theme'; import { varCreator, styleCreator } from './style'; const Sidebar = _ref => { let { width = 88, loading, options, style, ...restProps } = _ref; const [value, onChange] = useControllableValue(restProps, { valuePropName: 'activeValue', defaultValuePropName: 'defaultActiveValue' }); const locale = Locale.useLocale().Sidebar; const TOKENS = Theme.useThemeTokens(); const CV = Theme.createVar(TOKENS, varCreator); const STYLES = Theme.createStyle(CV, styleCreator); const isEmpty = loading || options.length === 0; const curIndex = options.findIndex(o => o.value === value); return /*#__PURE__*/React.createElement(View, _extends({}, restProps, { style: [STYLES.sidebar, isEmpty ? null : STYLES.sidebar_active, { width }, style] }), /*#__PURE__*/React.createElement(ScrollView, { bounces: false, contentContainerStyle: isEmpty ? STYLES.scroll_view_empty : null }, loading ? /*#__PURE__*/React.createElement(Loading, { vertical: true }, locale.labelLoading) : null, !loading && options.length === 0 ? /*#__PURE__*/React.createElement(Result, { status: "warning", subtitle: locale.labelNoData, renderIcon: () => { return /*#__PURE__*/React.createElement(ResultIconEmpty, { width: 60, height: 60 }); } }) : null, !loading && options.length > 0 ? /*#__PURE__*/React.createElement(View, { style: STYLES.list }, options.map((item, index) => { const isActive = value === item.value; const isPrev = index + 1 === curIndex; const isNext = index - 1 === curIndex; const textJSX = /*#__PURE__*/React.createElement(Text, { style: [STYLES.item_text, isActive ? STYLES.item_text_active : STYLES.item_text_inactive, item.disabled ? STYLES.item_text_disabled : null] }, item.label); return /*#__PURE__*/React.createElement(TouchableHighlight, { key: item.value, underlayColor: CV.sidebar_item_underlay_color, onPress: () => { onChange(item.value); }, disabled: item.disabled, style: [STYLES.item, isActive ? null : STYLES.item_inactive, isPrev ? STYLES.item_prev : null, isNext ? STYLES.item_next : null] }, /*#__PURE__*/React.createElement(React.Fragment, null, isActive ? /*#__PURE__*/React.createElement(View, { style: STYLES.item_bar }) : null, /*#__PURE__*/React.createElement(View, { style: STYLES.item_inner }, !isNil(item.badge) ? /*#__PURE__*/React.createElement(Badge, item.badge, textJSX) : textJSX))); })) : null)); }; export default /*#__PURE__*/memo(Sidebar); //# sourceMappingURL=index.js.map