Skip to content

Commit fc91a7c

Browse files
committed
feat Timeline 组件 新增点击事件
1 parent d472ed0 commit fc91a7c

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

@types/timeline.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export interface IProps extends BaseComponent {
4646
* 每一项可设置以下参数 `content`, `bgColor`, `iconColor`, `icon`
4747
*/
4848
times?: TTimes[];
49+
/**
50+
* 时间轴点击事件
51+
*/
52+
onClick?: (index: number) => void
4953
}
5054

5155
export interface TimelineProps extends IProps {}

src/components/timeline/index.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@ export default function ClTimeline(props: IProps) {
1010
const iconColorClassName = color => (color ? TEXT_COLOR_LIST[color] : "");
1111
const iconClassName = icon => (icon ? `cuIcon-${icon}` : "");
1212
const bgColorClassName = color => (color ? BG_COLOR_LIST[color] : "");
13-
const items = times.map(item =>
13+
const onClick = (index: number) => {
14+
props.onClick && props.onClick(index);
15+
};
16+
const items = times.map((item, index) =>
1417
item.node ? (
15-
<View className="cu-time" key={generateId()}>
18+
<View
19+
className="cu-time"
20+
key={generateId()}
21+
onClick={() => {
22+
onClick(index);
23+
}}
24+
>
1625
{item.node}
1726
</View>
1827
) : (
@@ -21,6 +30,9 @@ export default function ClTimeline(props: IProps) {
2130
item.iconColor
2231
)} ${iconClassName(item.icon)}`}
2332
key={generateId()}
33+
onClick={() => {
34+
onClick(index);
35+
}}
2436
>
2537
<View className={`${bgColorClassName(item.bgColor)} content`}>
2638
<ClFlex justify="between" align="end">
@@ -47,3 +59,8 @@ export default function ClTimeline(props: IProps) {
4759
ClTimeline.options = {
4860
addGlobalClass: true
4961
};
62+
63+
ClTimeline.defaultProps = {
64+
times: [],
65+
onClick: () => {}
66+
} as IProps;

0 commit comments

Comments
 (0)