-
Notifications
You must be signed in to change notification settings - Fork 13
/
Timetable.stories.tsx
153 lines (146 loc) · 3.58 KB
/
Timetable.stories.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { ComponentMeta, ComponentStory } from "@storybook/react";
import format from "date-fns/format";
import { TimeTable } from "..";
import {
DayHeaderPreviewProps,
EventPreviewProps,
HourPreviewProps,
} from "./../types";
// @ts-expect-error Cannot find module './styles.module.css' or its corresponding type declarations.
import customClassNames from "./styles.module.css";
export default {
title: "Example/TimeTable",
component: TimeTable,
argTypes: {
events: {
monday: [
{
id: 1,
name: "Custom Event 1",
type: "error",
startTime: new Date("2018-02-23T11:30:00"),
endTime: new Date("2018-02-23T13:30:00"),
},
],
tuesday: [
{
id: 2,
name: "Custom Event 2",
type: "custom",
startTime: new Date("2018-02-22T12:30:00"),
endTime: new Date("2018-02-22T14:30:00"),
},
{
id: 3,
name: "Custom Event 3",
type: "custom",
startTime: new Date("2018-02-22T16:30:00"),
endTime: new Date("2018-02-22T18:45:00"),
},
],
wednesday: [],
thursday: [],
friday: [],
},
},
} as ComponentMeta<typeof TimeTable>;
const Template: ComponentStory<typeof TimeTable> = (args) => (
<TimeTable {...args} />
);
export const Primary = Template.bind({});
Primary.args = {
events: {
monday: [
{
id: 1,
name: "Custom Event 1",
type: "error",
startTime: new Date("2018-02-23T11:30:00"),
endTime: new Date("2018-02-23T13:30:00"),
},
],
tuesday: [
{
id: 2,
name: "Custom Event 2",
type: "custom",
startTime: new Date("2018-02-22T12:30:00"),
endTime: new Date("2018-02-22T14:30:00"),
},
{
id: 3,
name: "Custom Event 3",
type: "custom",
startTime: new Date("2018-02-22T16:30:00"),
endTime: new Date("2018-02-22T18:45:00"),
},
],
wednesday: [],
thursday: [],
friday: [],
},
style: { height: "500px" },
};
const DayHeaderPreview = ({
day,
rowHeight,
...otherProperties
}: DayHeaderPreviewProps) => {
return (
<div
{...otherProperties}
style={{ ...(otherProperties?.style || {}), height: `${rowHeight}px` }}
>
{day}
</div>
);
};
const HourPreview = ({ hour, ...otherProperties }: HourPreviewProps) => {
return (
<div
{...otherProperties}
className={`${otherProperties.className} ${customClassNames.my_custom_hour}`}
key={hour}
>
{hour}
</div>
);
};
const EventPreview = ({
event,
defaultAttributes,
classNames,
}: EventPreviewProps) => {
return (
<div
{...defaultAttributes}
style={{
...defaultAttributes.style,
background: event.type === "error" ? "#720000" : "#66B266",
}}
title={event.name}
key={event.id}
className={`${classNames.event}`}
>
<span className={classNames.event_info}>[ {event.name} ]</span>
<span className={classNames.event_info}>
{format(event.startTime, "HH:mm")} - {format(event.endTime, "HH:mm")}
</span>
</div>
);
};
export const Secondary = Template.bind({});
Secondary.storyName = "Customized: <renderEvent> and <renderHour>";
Secondary.args = {
...Primary.args,
timeLabel: "",
renderDayHeader: DayHeaderPreview,
renderEvent: EventPreview,
renderHour: HourPreview,
headerAttributes: {
className: customClassNames.my_custom_day_header,
},
bodyAttributes: {
className: customClassNames.my_custom_day_body,
},
};