55 */
66
77import React from 'react' ;
8+ import { PlainButton } from '../Button' ;
89import Line from './Line' ;
910import type { TimeSlice , SkillDataEntryType } from '../../flowTypes' ;
1011import './Timeline.scss' ;
@@ -19,33 +20,61 @@ type Props = {
1920 getPreviewer ?: Function
2021} ;
2122
22- const Timeline = ( { type = 'text' , color, text = '' , url = '' , duration = 0 , timeslices = [ ] , getPreviewer } : Props ) =>
23- < div className = { `buik-timeline buik-timeline-${ type } ` } >
24- { ( text || url ) &&
25- < div className = 'buik-timeline-label' >
26- { type === 'image'
27- ? < img alt = { text } title = { text } src = { url } />
28- : < span >
29- { text }
30- </ span > }
31- </ div > }
32- < div className = 'buik-timeline-wrapper' >
33- < div className = 'buik-timeline-line' />
34- { timeslices . map (
35- ( { start, end } : TimeSlice , index ) =>
36- /* eslint-disable react/no-array-index-key */
37- < Line
38- key = { index }
39- color = { color }
40- type = { type }
41- start = { start }
42- end = { end }
43- duration = { duration }
44- getPreviewer = { getPreviewer }
45- />
46- /* eslint-enable react/no-array-index-key */
47- ) }
23+ const Timeline = ( {
24+ type = 'text' ,
25+ color,
26+ text = '' ,
27+ url = '' ,
28+ duration = 0 ,
29+ timeslices = [ ] ,
30+ getPreviewer
31+ } : Props ) => {
32+ let nextTimeSliceIndex = 0 ;
33+ const startNextSegment = ( ) => {
34+ const viewer = getPreviewer ? getPreviewer ( ) : null ;
35+ if (
36+ viewer &&
37+ viewer . isLoaded ( ) &&
38+ ! viewer . isDestroyed ( ) &&
39+ typeof viewer . play === 'function' &&
40+ timeslices [ nextTimeSliceIndex ]
41+ ) {
42+ viewer . play ( timeslices [ nextTimeSliceIndex ] . start ) ;
43+ nextTimeSliceIndex = ( nextTimeSliceIndex + 1 ) % timeslices . length ;
44+ }
45+ } ;
46+
47+ return (
48+ < div className = { `buik-timeline buik-timeline-${ type } ` } >
49+ { ( text || url ) &&
50+ < div className = 'buik-timeline-label' >
51+ { type === 'image'
52+ ? < PlainButton onClick = { startNextSegment } >
53+ < img alt = { text } title = { text } src = { url } />
54+ </ PlainButton >
55+ : < span >
56+ { text }
57+ </ span > }
58+ </ div > }
59+ < div className = 'buik-timeline-wrapper' >
60+ < div className = 'buik-timeline-line' />
61+ { timeslices . map (
62+ ( { start, end } : TimeSlice , index ) =>
63+ /* eslint-disable react/no-array-index-key */
64+ < Line
65+ key = { index }
66+ color = { color }
67+ type = { type }
68+ start = { start }
69+ end = { end }
70+ duration = { duration }
71+ getPreviewer = { getPreviewer }
72+ />
73+ /* eslint-enable react/no-array-index-key */
74+ ) }
75+ </ div >
4876 </ div >
49- </ div > ;
77+ ) ;
78+ } ;
5079
5180export default Timeline ;
0 commit comments