@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
76 lines (70 loc) • 2.85 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 isArray from 'lodash/isArray';
import noop from 'lodash/noop';
import React, { memo } from 'react';
import ActionSheet from '../action-sheet';
import { varCreator as varCreatorBlank } from '../blank/style';
import BottomBar from '../bottom-bar';
import Button from '../button';
import Locale from '../locale';
import Space from '../space';
import Theme from '../theme';
import { varCreator, styleCreator } from './style';
const ButtonBar = _ref => {
let {
alone = false,
buttons,
count = 4,
moreText,
blankSize = 'm',
children,
...restProps
} = _ref;
const locale = Locale.useLocale().ButtonBar;
const TOKENS = Theme.useThemeTokens();
const CV = Theme.createVar(TOKENS, varCreator);
const CV_BLANK = Theme.createVar(TOKENS, varCreatorBlank);
const STYLES = Theme.createStyle(CV, styleCreator);
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(_ref2 => {
var _restButtons$index$on, _restButtons$index;
let {
index
} = _ref2;
(_restButtons$index$on = (_restButtons$index = restButtons[index]).onPress) === null || _restButtons$index$on === void 0 ? void 0 : _restButtons$index$on.call(_restButtons$index);
}).catch(noop);
};
const defaultGap = CV_BLANK[`blank_size_${blankSize}`];
return /*#__PURE__*/React.createElement(BottomBar, _extends({}, restProps, {
style: [{
paddingHorizontal: defaultGap
}, STYLES.button_bar, alone ? STYLES.button_bar_alone : null]
}), isConfig ? /*#__PURE__*/React.createElement(Space, {
justify: "flex-end",
align: "center",
direction: "horizontal",
gapVertical: 0,
gapHorizontal: CV.button_bar_button_space
}, showMore ? /*#__PURE__*/React.createElement(Button, {
type: "link",
text: moreText || locale.moreText,
onPress: onPressMore
}) : null, bottomButtons.reverse().map((b, index) => {
return /*#__PURE__*/React.createElement(Button, _extends({
key: index
}, b, {
size: b.size || 'm',
style: b.style || STYLES.btn
}));
})) : children);
};
export default /*#__PURE__*/memo(ButtonBar);
//# sourceMappingURL=index.js.map