@@ -2,6 +2,12 @@ import { TimeSpanBarProps, TimeSpanBar } from "../TimeSpanBar/TimeSpanBar";
22import { useState , useCallback , useEffect } from "react" ;
33import classes from "./TimeHistory.module.css" ;
44
5+ /**
6+ * Props for the TimeHistory component
7+ * @param historyItems Array of TimeSpanBarProps objects representing timeline items to display
8+ * @param visibleRange Optional date range to show initially. Defaults to 1961-1991
9+ * @param stepInYears Optional step size in years for scrolling. Defaults to 1
10+ */
511export interface TimeHistoryProps {
612 historyItems : TimeSpanBarProps [ ] ;
713 visibleRange ?: {
@@ -14,7 +20,7 @@ export interface TimeHistoryProps {
1420const TimeHistory = ( {
1521 historyItems,
1622 visibleRange : initialVisibleRange = {
17- start : new Date ( "1961 -01-01" ) ,
23+ start : new Date ( "1881 -01-01" ) ,
1824 end : new Date ( "1991-01-01" ) ,
1925 // Наша эра :)
2026 } ,
@@ -26,43 +32,8 @@ const TimeHistory = ({
2632 const startYear = visibleRange . start . getFullYear ( ) ;
2733 const yearWidth = 50 ; // px
2834
29- const rangeStep = 5 ; // years
30-
3135 return (
3236 < div className = { classes . component } >
33- < div className = { classes . controls } >
34- < button onClick = { ( ) => setVisibleRange ( initialVisibleRange ) } >
35- Reset
36- </ button >
37- < button
38- onClick = { ( ) =>
39- setVisibleRange ( ( prev ) => ( {
40- start : new Date (
41- prev . start . setFullYear ( prev . start . getFullYear ( ) - rangeStep )
42- ) ,
43- end : new Date (
44- prev . end . setFullYear ( prev . end . getFullYear ( ) - rangeStep )
45- ) ,
46- } ) )
47- }
48- >
49- { "<" } Back
50- </ button >
51- < button
52- onClick = { ( ) =>
53- setVisibleRange ( ( prev ) => ( {
54- start : new Date (
55- prev . start . setFullYear ( prev . start . getFullYear ( ) + rangeStep )
56- ) ,
57- end : new Date (
58- prev . end . setFullYear ( prev . end . getFullYear ( ) + rangeStep )
59- ) ,
60- } ) )
61- }
62- >
63- Forward { ">" }
64- </ button >
65- </ div >
6637 < div className = { classes . years } >
6738 { Array . from (
6839 {
@@ -88,27 +59,19 @@ const TimeHistory = ({
8859 { endYear }
8960 </ div >
9061 </ div >
91- < div className = { classes . currentFrame } >
92- < div className = { classes . items } >
93- { historyItems . map ( ( item , index ) => (
94- < div
95- className = { classes . item }
96- key = { index }
97- style = { {
98- left : `${
99- ( item . start . date . getFullYear ( ) - startYear ) * yearWidth
100- } px`,
101- width : `${
102- ( item . end ?. date ?. getFullYear ( ) -
103- item . start . date . getFullYear ( ) ) *
104- yearWidth
105- } px`,
106- } }
107- >
108- < TimeSpanBar { ...item } yearWidth = { yearWidth } />
109- </ div >
110- ) ) }
111- </ div >
62+
63+ < div className = { classes . items } >
64+ { historyItems . map ( ( item , index ) => (
65+ < div
66+ className = { classes . item }
67+ key = { index }
68+ style = { {
69+ left : ( item . start . date . getFullYear ( ) - startYear ) * yearWidth ,
70+ } }
71+ >
72+ < TimeSpanBar { ...item } yearWidth = { yearWidth } />
73+ </ div >
74+ ) ) }
11275 </ div >
11376 </ div >
11477 ) ;
0 commit comments