antd-mobile-taro-ui
Version:
以antd-mobile为设计标准,基于taro框架的微信小程序组件库
27 lines (25 loc) • 899 B
JavaScript
import React, { memo } from 'react';
import { withNativeProps } from 'antd-mobile/es/utils/native-props';
import classNames from 'classnames';
import { mergeProps } from 'antd-mobile/es/utils/with-default-props';
import { View } from '@tarojs/components';
const classPrefix = `adm-page-indicator`;
const defaultProps = {
color: 'primary',
direction: 'horizontal'
};
export const PageIndicator = memo(p => {
const props = mergeProps(defaultProps, p);
const dots = [];
for (let i = 0; i < props.total; i++) {
dots.push(React.createElement(View, {
key: i,
className: classNames(`${classPrefix}-dot`, {
[`${classPrefix}-dot-active`]: props.current === i
})
}));
}
return withNativeProps(props, React.createElement(View, {
className: classNames(classPrefix, `${classPrefix}-${props.direction}`, `${classPrefix}-color-${props.color}`)
}, dots));
});