File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff 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
5155export interface TimelineProps extends IProps { }
Original file line number Diff line number Diff 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) {
4759ClTimeline . options = {
4860 addGlobalClass : true
4961} ;
62+
63+ ClTimeline . defaultProps = {
64+ times : [ ] ,
65+ onClick : ( ) => { }
66+ } as IProps ;
You can’t perform that action at this time.
0 commit comments