Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Timeline.Item.position (#16148) #16193

Merged
merged 3 commits into from Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions components/timeline/Timeline.tsx
Expand Up @@ -55,6 +55,18 @@ export default class Timeline extends React.Component<TimelineProps, any> {
? [pendingItem, ...React.Children.toArray(children).reverse()]
: [...React.Children.toArray(children), pendingItem];

const getPositionCls = (ele: React.ReactElement<any>, idx: number) => {
if (mode === 'alternate') {
if (ele.props.position === 'right') return `${prefixCls}-item-right`;
if (ele.props.position === 'left') return `${prefixCls}-item-left`;
return idx % 2 === 0 ? `${prefixCls}-item-left` : `${prefixCls}-item-right`;
}
if (mode === 'left') return `${prefixCls}-item-left`;
if (mode === 'right') return `${prefixCls}-item-right`;
if (ele.props.position === 'right') return `${prefixCls}-item-right`;
return '';
};

// Remove falsy items
const truthyItems = timeLineItems.filter(item => !!item);
const itemsCount = React.Children.count(truthyItems);
Expand All @@ -70,13 +82,7 @@ export default class Timeline extends React.Component<TimelineProps, any> {
: idx === itemsCount - 1
? lastCls
: '',
mode === 'alternate'
? idx % 2 === 0
? `${prefixCls}-item-left`
: `${prefixCls}-item-right`
: mode === 'right'
? `${prefixCls}-item-right`
: '',
getPositionCls(ele, idx),
]),
}),
);
Expand Down
3 changes: 3 additions & 0 deletions components/timeline/TimelineItem.tsx
Expand Up @@ -8,6 +8,7 @@ export interface TimeLineItemProps {
color?: string;
dot?: React.ReactNode;
pending?: boolean;
position?: string;
style?: React.CSSProperties;
}

Expand All @@ -20,6 +21,7 @@ const TimelineItem: React.SFC<TimeLineItemProps> = props => (
color = '',
children,
pending,
position,
dot,
...restProps
} = props;
Expand Down Expand Up @@ -58,6 +60,7 @@ const TimelineItem: React.SFC<TimeLineItemProps> = props => (
TimelineItem.defaultProps = {
color: 'blue',
pending: false,
position: '',
};

export default TimelineItem;
13 changes: 7 additions & 6 deletions components/timeline/index.en-US.md
Expand Up @@ -29,15 +29,16 @@ Timeline
| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| pending | Set the last ghost node's existence or its content | boolean\|string\|ReactNode | `false` |
| pendingDot | Set the dot of the last ghost node when pending is true | \|string\|ReactNode | `<Icon type="loading" />` |
| pendingDot | Set the dot of the last ghost node when pending is true | string\|ReactNode | `<Icon type="loading" />` |
| reverse | reverse nodes or not | boolean | false |
| mode | By sending `alternate` the timeline will distribute the nodes to the left and right. | `left` \| `alternate` \| `right` | `left` |
| mode | By sending `alternate` the timeline will distribute the nodes to the left and right. | `left` \| `alternate` \| `right` | - |

### Timeline.Item

Node of timeline

| Property | Description | Type | Default |
| -------- | ----------- | ---- | ------- |
| color | Set the circle's color to `blue`, `red`, `green` or other custom colors | string | `blue` |
| dot | Customize timeline dot | string\|ReactNode | - |
| Property | Description | Type | Default | Version |
| -------- | ----------- | ---- | ------- | ------- |
| color | Set the circle's color to `blue`, `red`, `green` or other custom colors | string | `blue` | |
| dot | Customize timeline dot | string\|ReactNode | - | |
| position | Customize node position | `left` \| `right` | - | 3.17.0 |
13 changes: 7 additions & 6 deletions components/timeline/index.zh-CN.md
Expand Up @@ -30,15 +30,16 @@ title: Timeline
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| pending | 指定最后一个幽灵节点是否存在或内容 | boolean\|string\|ReactNode | false |
| pendingDot | 当最后一个幽灵节点存在時,指定其时间图点 | \|string\|ReactNode | `<Icon type="loading" />` |
| pendingDot | 当最后一个幽灵节点存在時,指定其时间图点 | string\|ReactNode | `<Icon type="loading" />` |
| reverse | 节点排序 | boolean | false |
| mode | 通过设置 `mode` 可以改变时间轴和内容的相对位置 | `left` \| `alternate` \| `right` |
| mode | 通过设置 `mode` 可以改变时间轴和内容的相对位置 | `left` \| `alternate` \| `right` | - |

### Timeline.Item

时间轴的每一个节点。

| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| color | 指定圆圈颜色 `blue, red, green`,或自定义的色值 | string | blue |
| dot | 自定义时间轴点 | string\|ReactNode | - |
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| color | 指定圆圈颜色 `blue, red, green`,或自定义的色值 | string | blue | |
| dot | 自定义时间轴点 | string\|ReactNode | - | |
| position | 自定义节点位置 | `left` \| `right` | - | 3.17.0 |