feat: switch && timeline && skeleton

pull/666/head
wangxueliang 2019-03-18 20:35:24 +08:00
parent 1af8349504
commit 1713581576
11 changed files with 64 additions and 21 deletions

View File

@ -12,7 +12,6 @@ export const SkeletonAvatarProps = PropTypes.shape(skeletonAvatarProps).loose;
const Avatar = { const Avatar = {
props: initDefaultProps(skeletonAvatarProps, { props: initDefaultProps(skeletonAvatarProps, {
prefixCls: 'ant-skeleton-avatar',
size: 'large', size: 'large',
}), }),
render() { render() {

View File

@ -12,9 +12,7 @@ const skeletonParagraphProps = {
export const SkeletonParagraphProps = PropTypes.shape(skeletonParagraphProps); export const SkeletonParagraphProps = PropTypes.shape(skeletonParagraphProps);
const Paragraph = { const Paragraph = {
props: initDefaultProps(skeletonParagraphProps, { props: skeletonParagraphProps,
prefixCls: 'ant-skeleton-paragraph',
}),
methods: { methods: {
getWidth(index) { getWidth(index) {
const { width, rows = 2 } = this; const { width, rows = 2 } = this;

View File

@ -9,9 +9,7 @@ const skeletonTitleProps = {
export const SkeletonTitleProps = PropTypes.shape(skeletonTitleProps); export const SkeletonTitleProps = PropTypes.shape(skeletonTitleProps);
const Title = { const Title = {
props: initDefaultProps(skeletonTitleProps, { props: skeletonTitleProps,
prefixCls: 'ant-skeleton-title',
}),
render() { render() {
const { prefixCls, width } = this.$props; const { prefixCls, width } = this.$props;
const zWidth = typeof width === 'number' ? `${width}px` : width; const zWidth = typeof width === 'number' ? `${width}px` : width;

View File

@ -16,6 +16,8 @@ const md = {
- 网络较慢需要长时间等待加载处理的情况下 - 网络较慢需要长时间等待加载处理的情况下
- 图文信息内容较多的列表/卡片中 - 图文信息内容较多的列表/卡片中
- 只适合用在第一次加载数据的场景
- 可以被 Spin 完全代替但是在可用的场景下可以比 Spin 提供更好的视觉效果和用户体验
## 代码演示`, ## 代码演示`,
us: `# Skeleton us: `# Skeleton
@ -25,6 +27,8 @@ const md = {
- When resource needs long time to load, like low network speed. - When resource needs long time to load, like low network speed.
- The component contains much information. Such as List or Card. - The component contains much information. Such as List or Card.
- Only works when loading data at first time.
- Could be replaced by Spin in all situation, but provide better user experience then spin if it works.
## Examples ## Examples
`, `,
}; };

View File

@ -1,6 +1,7 @@
import classNames from 'classnames'; import classNames from 'classnames';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { initDefaultProps, hasProp } from '../_util/props-util'; import { initDefaultProps, hasProp } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
import Avatar, { SkeletonAvatarProps } from './Avatar'; import Avatar, { SkeletonAvatarProps } from './Avatar';
import Title, { SkeletonTitleProps } from './Title'; import Title, { SkeletonTitleProps } from './Title';
import Paragraph, { SkeletonParagraphProps } from './Paragraph'; import Paragraph, { SkeletonParagraphProps } from './Paragraph';
@ -63,13 +64,25 @@ function getParagraphBasicProps(hasAvatar, hasTitle) {
const Skeleton = { const Skeleton = {
name: 'ASkeleton', name: 'ASkeleton',
props: initDefaultProps(SkeletonProps, { props: initDefaultProps(SkeletonProps, {
prefixCls: 'ant-skeleton',
avatar: false, avatar: false,
title: true, title: true,
paragraph: true, paragraph: true,
}), }),
inject: {
configProvider: { default: () => ({}) },
},
render() { render() {
const { loading, prefixCls, avatar, title, paragraph, active } = this.$props; const {
prefixCls: customizePrefixCls,
loading,
avatar,
title,
paragraph,
active,
} = this.$props;
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('skeleton', customizePrefixCls);
if (loading || !hasProp(this, 'loading')) { if (loading || !hasProp(this, 'loading')) {
const hasAvatar = !!avatar || avatar === ''; const hasAvatar = !!avatar || avatar === '';
const hasTitle = !!title; const hasTitle = !!title;
@ -80,6 +93,7 @@ const Skeleton = {
if (hasAvatar) { if (hasAvatar) {
const avatarProps = { const avatarProps = {
props: { props: {
prefixCls: `${prefixCls}-avatar`,
...getAvatarBasicProps(hasTitle, hasParagraph), ...getAvatarBasicProps(hasTitle, hasParagraph),
...getComponentProps(avatar), ...getComponentProps(avatar),
}, },
@ -99,6 +113,7 @@ const Skeleton = {
if (hasTitle) { if (hasTitle) {
const titleProps = { const titleProps = {
props: { props: {
prefixCls: `${prefixCls}-title`,
...getTitleBasicProps(hasAvatar, hasParagraph), ...getTitleBasicProps(hasAvatar, hasParagraph),
...getComponentProps(title), ...getComponentProps(title),
}, },
@ -112,6 +127,7 @@ const Skeleton = {
if (hasParagraph) { if (hasParagraph) {
const paragraphProps = { const paragraphProps = {
props: { props: {
prefixCls: `${prefixCls}-paragraph`,
...getParagraphBasicProps(hasAvatar, hasTitle), ...getParagraphBasicProps(hasAvatar, hasTitle),
...getComponentProps(paragraph), ...getComponentProps(paragraph),
}, },

View File

@ -2,6 +2,7 @@ import PropTypes from '../_util/vue-types';
import { initDefaultProps, getOptionProps } from '../_util/props-util'; import { initDefaultProps, getOptionProps } from '../_util/props-util';
import VcSteps from '../vc-steps'; import VcSteps from '../vc-steps';
import Icon from '../icon'; import Icon from '../icon';
import { ConfigConsumerProps } from '../config-provider';
const getStepsProps = (defaultProps = {}) => { const getStepsProps = (defaultProps = {}) => {
const props = { const props = {
@ -21,14 +22,19 @@ const getStepsProps = (defaultProps = {}) => {
const Steps = { const Steps = {
name: 'ASteps', name: 'ASteps',
props: getStepsProps({ props: getStepsProps({
prefixCls: 'ant-steps',
iconPrefix: 'ant',
current: 0, current: 0,
}), }),
inject: {
configProvider: { default: () => ({}) },
},
Step: { ...VcSteps.Step, name: 'AStep' }, Step: { ...VcSteps.Step, name: 'AStep' },
render() { render() {
const props = getOptionProps(this); const props = getOptionProps(this);
const { prefixCls } = props; const { prefixCls: customizePrefixCls, iconPrefix: customizeIconPrefixCls } = props;
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('steps', customizePrefixCls);
const iconPrefix = getPrefixCls('', customizeIconPrefixCls);
const icons = { const icons = {
finish: <Icon type="check" class={`${prefixCls}-finish-icon`} />, finish: <Icon type="check" class={`${prefixCls}-finish-icon`} />,
error: <Icon type="close" class={`${prefixCls}-error-icon`} />, error: <Icon type="close" class={`${prefixCls}-error-icon`} />,
@ -36,6 +42,8 @@ const Steps = {
const stepsProps = { const stepsProps = {
props: { props: {
icons, icons,
iconPrefix,
prefixCls,
...props, ...props,
}, },
on: this.$listeners, on: this.$listeners,

View File

@ -14,10 +14,10 @@
### Events ### Events
| Events Name | Description | Arguments | | Events Name | Description | Arguments |
| --- | --- | --- | | --- | --- | --- |
| change | a callback function, can be executed when the checked state is changing | Function(checked:Boolean) | | change | trigger when the checked state is changing | Function(checked: boolean, event: Event) | |
| click | trigger when clicked | Function(checked: boolean, event: Event) | |
## Methods ## Methods
| Name | Description | | Name | Description |
| ---- | ----------- | | ---- | ----------- |
| blur() | remove focus | | blur() | remove focus |

View File

@ -3,6 +3,7 @@ import { getOptionProps, getComponentFromProp } from '../_util/props-util';
import VcSwitch from '../vc-switch'; import VcSwitch from '../vc-switch';
import Wave from '../_util/wave'; import Wave from '../_util/wave';
import Icon from '../icon'; import Icon from '../icon';
import { ConfigConsumerProps } from '../config-provider';
const Switch = { const Switch = {
name: 'ASwitch', name: 'ASwitch',
@ -11,7 +12,7 @@ const Switch = {
event: 'change', event: 'change',
}, },
props: { props: {
prefixCls: PropTypes.string.def('ant-switch'), prefixCls: PropTypes.string,
// size=default and size=large are the same // size=default and size=large are the same
size: PropTypes.oneOf(['small', 'default', 'large']), size: PropTypes.oneOf(['small', 'default', 'large']),
disabled: PropTypes.bool, disabled: PropTypes.bool,
@ -23,6 +24,9 @@ const Switch = {
autoFocus: PropTypes.bool, autoFocus: PropTypes.bool,
loading: PropTypes.bool, loading: PropTypes.bool,
}, },
inject: {
configProvider: { default: () => ({}) },
},
methods: { methods: {
focus() { focus() {
this.$refs.refSwitchNode.focus(); this.$refs.refSwitchNode.focus();
@ -33,7 +37,10 @@ const Switch = {
}, },
render() { render() {
const { prefixCls, size, loading, disabled, ...restProps } = getOptionProps(this); const { prefixCls: customizePrefixCls, size, loading, disabled, ...restProps } = getOptionProps(this);
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('switch', customizePrefixCls);
const classes = { const classes = {
[`${prefixCls}-small`]: size === 'small', [`${prefixCls}-small`]: size === 'small',
[`${prefixCls}-loading`]: loading, [`${prefixCls}-loading`]: loading,

View File

@ -14,7 +14,8 @@
### 事件 ### 事件
| 事件名称 | 说明 | 回调参数 | | 事件名称 | 说明 | 回调参数 |
| --- | --- | --- | | --- | --- | --- |
| change | 变化时回调函数 | Function(checked:Boolean) | | change | 变化时回调函数 | Function(checked:Boolean, event: Event) |
| click | 点击时回调函数 | Function(checked: boolean, event: Event) | |
## 方法 ## 方法

View File

@ -9,6 +9,7 @@ import {
import { cloneElement } from '../_util/vnode'; import { cloneElement } from '../_util/vnode';
import TimelineItem from './TimelineItem'; import TimelineItem from './TimelineItem';
import Icon from '../icon'; import Icon from '../icon';
import { ConfigConsumerProps } from '../config-provider';
export const TimelineProps = { export const TimelineProps = {
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
@ -22,11 +23,16 @@ export const TimelineProps = {
export default { export default {
name: 'ATimeline', name: 'ATimeline',
props: initDefaultProps(TimelineProps, { props: initDefaultProps(TimelineProps, {
prefixCls: 'ant-timeline',
reverse: false, reverse: false,
}), }),
inject: {
configProvider: { default: () => ({}) },
},
render() { render() {
const { prefixCls, reverse, mode, ...restProps } = getOptionProps(this); const { prefixCls: customizePrefixCls, reverse, mode, ...restProps } = getOptionProps(this);
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
const pendingDot = getComponentFromProp(this, 'pendingDot'); const pendingDot = getComponentFromProp(this, 'pendingDot');
const pending = getComponentFromProp(this, 'pending'); const pending = getComponentFromProp(this, 'pending');
const pendingNode = typeof pending === 'boolean' ? null : pending; const pendingNode = typeof pending === 'boolean' ? null : pending;

View File

@ -1,6 +1,7 @@
import classNames from 'classnames'; import classNames from 'classnames';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { getOptionProps, initDefaultProps, getComponentFromProp } from '../_util/props-util'; import { getOptionProps, initDefaultProps, getComponentFromProp } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
export const TimeLineItemProps = { export const TimeLineItemProps = {
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
@ -12,12 +13,17 @@ export const TimeLineItemProps = {
export default { export default {
name: 'ATimelineItem', name: 'ATimelineItem',
props: initDefaultProps(TimeLineItemProps, { props: initDefaultProps(TimeLineItemProps, {
prefixCls: 'ant-timeline',
color: 'blue', color: 'blue',
pending: false, pending: false,
}), }),
inject: {
configProvider: { default: () => ({}) },
},
render() { render() {
const { prefixCls, color = '', pending } = getOptionProps(this); const { prefixCls: customizePrefixCls, color = '', pending } = getOptionProps(this);
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('timeline', customizePrefixCls);
const dot = getComponentFromProp(this, 'dot'); const dot = getComponentFromProp(this, 'dot');
const itemClassName = classNames({ const itemClassName = classNames({
[`${prefixCls}-item`]: true, [`${prefixCls}-item`]: true,