antd-mobile-taro-ui
Version:
以antd-mobile为设计标准,基于taro框架的微信小程序组件库
65 lines (62 loc) • 2.09 kB
JavaScript
import React from 'react';
import classNames from 'classnames';
import { withNativeProps } from 'antd-mobile/es/utils/native-props';
import { mergeProps } from 'antd-mobile/es/utils/with-default-props';
import { View, Text } from '@tarojs/components';
import { Divider } from '../divider/divider';
const classPrefix = `adm-footer`;
const defaultProps = {
label: '',
links: [],
content: '',
chips: []
};
export const Footer = p => {
const props = mergeProps(defaultProps, p);
const {
label,
links,
content,
chips,
onChipClick,
onLinkClick
} = props;
const clickChipItem = (item, index) => {
if ((chips === null || chips === void 0 ? void 0 : chips.length) && item.type === 'link') {
onChipClick === null || onChipClick === void 0 ? void 0 : onChipClick(item, index);
}
};
const clickLinkItem = (item, index, e) => {
if (onLinkClick) {
e.preventDefault();
onLinkClick(item, index);
}
};
return withNativeProps(props, React.createElement(View, {
className: classNames(classPrefix)
}, label && React.createElement(View, {
className: `${classPrefix}-label`
}, React.createElement(Divider, null, label)), links && links.length > 0 && React.createElement(View, {
className: `${classPrefix}-links`
}, links.map((link, index) => {
return React.createElement(React.Fragment, {
key: index
}, React.createElement(Text, {
onClick: event => clickLinkItem(link, index, event)
}, link.text), index !== links.length - 1 && React.createElement(Divider, {
direction: 'vertical'
}));
})), content && React.createElement(View, {
className: `${classPrefix}-content`
}, content), chips && chips.length > 0 && React.createElement(View, {
className: `${classPrefix}-chips`
}, chips.map((chip, index) => {
return React.createElement(View, {
key: index,
onClick: () => clickChipItem(chip, index),
className: classNames(`${classPrefix}-chip`, {
[`${classPrefix}-chip-link`]: chip.type === 'link'
})
}, chip.text);
}))));
};