-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathItch.tsx
88 lines (79 loc) · 2.23 KB
/
Itch.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from "react";
import moment from "moment";
import Timeline from "../src";
import type { TimelineGroupBase, TimelineItemBase } from "../src/types";
import "../src/Timeline.scss";
const groups: TimelineGroupBase[] = [];
for (let id = 0; id < 2000; id++) {
groups.push({ id: id.toString(), title: `Group ${id}` });
}
const items: TimelineItemBase[] = [];
type RelativeTimeWindow = {
startOffset: number;
duration: number;
};
const rowDefinitions: RelativeTimeWindow[][] = [
[
{
startOffset: -2,
duration: 1,
},
{
startOffset: 0,
duration: 2,
},
{
startOffset: 3,
duration: 2,
},
],
[
{
startOffset: -1,
duration: 4,
},
{
startOffset: 4,
duration: 3,
},
],
];
const _baseDate = moment().startOf("hour");
// Moment objects are mutable, use a factory to get mutable copy of the base date...
const getBaseDate = () => moment(_baseDate);
for (let group = 0; group < groups.length; group++) {
const rowDefinition = rowDefinitions[group % rowDefinitions.length];
for (let item = 0; item < rowDefinition.length; item++) {
const itemDefinition = rowDefinition[item];
const start = getBaseDate().add(itemDefinition.startOffset, "hour");
// Moment objects are mutable, create a clone.
const end = moment(start).add(itemDefinition.duration, "hour");
items.push({
id: `${group}-${item}`,
group: group.toString(),
title: `Group ${group} / Item ${item}`,
startTime: start.valueOf(),
endTime: end.valueOf(),
});
}
}
/**
* Primary UI component for user interaction
*/
export const Itch = ({}: {
/* Empty */
}): JSX.Element => {
return (
<div style={{ height: "100vh" }}>
<Timeline
groups={groups}
items={items}
defaultTimeStart={getBaseDate().add(-12, "hour")}
defaultTimeEnd={getBaseDate().add(12, "hour")}
lineHeight={42}
itemHeight={34}
stackItems
/>
</div>
);
};