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(Timeline): timelineitem add trigger on click #2545

Merged
merged 2 commits into from
Oct 18, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/timeline/TimelineItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useContext, useMemo } from 'react';
import classNames from 'classnames';
import omit from 'lodash/omit';
import { TdTimelineItemProps } from './type';
import { StyledProps } from '../common';
import useConfig from '../hooks/useConfig';
Expand All @@ -11,6 +12,7 @@ import Loading from '../loading';
export interface TimelineItemProps extends TdTimelineItemProps, StyledProps {
children?: React.ReactNode;
index?: number;
onClick?: (context: { e: React.MouseEvent<HTMLElement>; item: TdTimelineItemProps }) => void;
}

const DefaultTheme = ['default', 'primary', 'success', 'warning', 'error'];
Expand All @@ -27,6 +29,7 @@ const TimelineItem: React.FC<TimelineItemProps> = (props) => {
content,
label,
loading = false,
onClick,
} = props;
const { theme, reverse, itemsStatus, layout, globalAlign, mode } = useContext(TimelineContext);
const { classPrefix } = useConfig();
Expand Down Expand Up @@ -63,6 +66,10 @@ const TimelineItem: React.FC<TimelineItemProps> = (props) => {
return ele;
}, [dot, classPrefix]);

const handleClick = (e: React.MouseEvent<HTMLElement>) => {
onClick?.({ e, item: omit(props, ['children', 'index', 'onClick']) });
};

// 节点类名
const itemClassName = classNames(
{
Expand Down Expand Up @@ -91,7 +98,7 @@ const TimelineItem: React.FC<TimelineItemProps> = (props) => {
});

return (
<li className={itemClassName} style={style}>
<li className={itemClassName} style={style} onClick={handleClick}>
{mode === 'alternate' && label && <div className={labelClassName}>{label}</div>}
<div className={`${classPrefix}-timeline-item__wrapper`}>
<div className={dotClassName} style={{ borderColor: !DefaultTheme.includes(dotColor) && dotColor }}>
Expand Down
1 change: 1 addition & 0 deletions src/timeline/timeline.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ dotColor | String | primary | Typescript:`string` | N
label | TNode | - | Typescript:`string \| TNode`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N
labelAlign | String | - | options:left/right/top/bottom | N
loading | Boolean | - | Whether it is in the loading state | N
onClick | Function | | Typescript:`(context: { e: MouseEvent; item: TdTimelineItemProps }) => void` [TdTimelineItemProps 详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/timeline/type.ts) <br/> trigger on click. | N
1 change: 1 addition & 0 deletions src/timeline/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ dotColor | String | primary | 时间轴颜色,内置 `primary/warning/error/de
label | TNode | - | 标签文本内容,可完全自定义。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N
labelAlign | String | - | 标签信息相对于时间轴的位置,在 `mode='alternate'` 时生效,优先级高于 `Timeline.labelAlign`。可选项:left/right/top/bottom | N
loading | Boolean | - | 是否处在加载状态 | N
onClick | Function | | TS 类型:`(context: { e: MouseEvent; item: TdTimelineItemProps }) => void` [TdTimelineItemProps 详细类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/timeline/type.ts) <br/> 点击时触发。 | N
Loading