UNPKG

@fruits-chain/react-native-xiaoshu

Version:
79 lines (78 loc) • 2.44 kB
"use strict"; import isArray from 'lodash/isArray'; import noop from 'lodash/noop'; import React, { memo } from 'react'; import ActionSheet from "../action-sheet/index.js"; import { varCreator as varCreatorBlank } from "../blank/style.js"; import BottomBar from "../bottom-bar/index.js"; import Button from "../button/index.js"; import Locale from "../locale/index.js"; import Space from "../space/index.js"; import Theme from "../theme/index.js"; import { varCreator, styleCreator } from "./style.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const ButtonBar = ({ theme, alone = false, buttons, count = 4, moreText, blankSize = 'm', children, style, ...restProps }) => { const locale = Locale.useLocale().ButtonBar; const [CV, STYLES] = Theme.useStyle({ varCreator, styleCreator, theme }); const [CV_BLANK] = Theme.useStyle({ varCreator: varCreatorBlank }); const realButtons = (buttons || []).filter(item => !item.hidden); const isConfig = isArray(buttons); const showMore = realButtons.length > count; const bottomButtons = showMore ? realButtons.slice(0, count - 1) : realButtons; const onPressMore = () => { const restButtons = realButtons.slice(count - 1); ActionSheet({ actions: restButtons.map(item => item.text), cancelText: locale.labelActionSheetCancelText }).then(({ index }) => { restButtons[index].onPress?.(); }).catch(noop); }; const defaultGap = CV_BLANK[`blank_size_${blankSize}`]; if (isConfig && realButtons.length === 0) { return null; } return /*#__PURE__*/_jsx(BottomBar, { ...restProps, style: [{ paddingHorizontal: defaultGap }, STYLES.button_bar, alone ? STYLES.button_bar_alone : null, style], children: isConfig ? /*#__PURE__*/_jsxs(Space, { justify: "flex-end", align: "center", direction: "horizontal", gapHorizontal: CV.button_bar_button_space, children: [showMore ? /*#__PURE__*/_jsx(Button, { type: "link", text: moreText ?? locale.moreText, onPress: onPressMore }) : null, bottomButtons.reverse().map((b, index) => { return /*#__PURE__*/_jsx(Button, { ...b, size: b.size || 'm', style: b.style || STYLES.btn }, index); })] }) : children }); }; export default /*#__PURE__*/memo(ButtonBar); //# sourceMappingURL=button-bar.js.map