@superdispatch/dates 0.21.8 → 0.21.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc.js +5 -0
- package/.turbo/turbo-version.log +26 -0
- package/package.json +58 -32
- package/pkg/README.md +10 -0
- package/{dist-types → pkg/dist-types}/index.d.ts +237 -237
- package/pkg/package.json +32 -0
- package/playroom.ts +10 -0
- package/src/__tests__/index.spec.ts +48 -0
- package/src/base-date-picker/BaseDatePicker.tsx +145 -0
- package/src/calendar/Calendar.playroom.tsx +28 -0
- package/src/calendar/Calendar.spec.tsx +531 -0
- package/src/calendar/Calendar.stories.tsx +50 -0
- package/src/calendar/Calendar.tsx +534 -0
- package/src/calendar/CalendarQuickSelection.tsx +34 -0
- package/src/calendar/InternalCalendarComponents.tsx +79 -0
- package/src/date-config/DateConfig.spec.tsx +23 -0
- package/src/date-config/DateConfig.tsx +60 -0
- package/src/date-field/DateField.playroom.tsx +21 -0
- package/src/date-field/DateField.spec.tsx +350 -0
- package/src/date-field/DateField.stories.tsx +47 -0
- package/src/date-field/DateField.tsx +155 -0
- package/src/date-range-field/DateRangeField.playroom.tsx +24 -0
- package/src/date-range-field/DateRangeField.spec.tsx +318 -0
- package/src/date-range-field/DateRangeField.stories.tsx +51 -0
- package/src/date-range-field/DateRangeField.tsx +277 -0
- package/src/date-time-utils/DateTimeUtils.spec.ts +652 -0
- package/src/date-time-utils/DateTimeUtils.ts +339 -0
- package/src/date-utils/DateUtils.spec.ts +234 -0
- package/src/date-utils/DateUtils.ts +333 -0
- package/src/formatted-date/FormattedDate.spec.tsx +103 -0
- package/src/formatted-date/FormattedDate.ts +42 -0
- package/src/formatted-relative-time/FormattedRelativeTime.spec.tsx +93 -0
- package/src/formatted-relative-time/FormattedRelativeTime.ts +60 -0
- package/src/index.ts +12 -0
- package/src/time-field/TimeField.playroom.tsx +21 -0
- package/src/time-field/TimeField.stories.tsx +35 -0
- package/src/time-field/TimeField.tsx +221 -0
- package/src/use-date-time/useDateTime.spec.ts +45 -0
- package/src/use-date-time/useDateTime.ts +31 -0
- package/src/use-date-time-range/useDateTimeRange.spec.ts +53 -0
- package/src/use-date-time-range/useDateTimeRange.ts +24 -0
- package/tsconfig.json +19 -0
- package/LICENSE +0 -21
- /package/{dist-node → pkg/dist-node}/index.js +0 -0
- /package/{dist-node → pkg/dist-node}/index.js.map +0 -0
- /package/{dist-src → pkg/dist-src}/base-date-picker/BaseDatePicker.js +0 -0
- /package/{dist-src → pkg/dist-src}/calendar/Calendar.js +0 -0
- /package/{dist-src → pkg/dist-src}/calendar/CalendarQuickSelection.js +0 -0
- /package/{dist-src → pkg/dist-src}/calendar/InternalCalendarComponents.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-config/DateConfig.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-field/DateField.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-range-field/DateRangeField.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-time-utils/DateTimeUtils.js +0 -0
- /package/{dist-src → pkg/dist-src}/date-utils/DateUtils.js +0 -0
- /package/{dist-src → pkg/dist-src}/formatted-date/FormattedDate.js +0 -0
- /package/{dist-src → pkg/dist-src}/formatted-relative-time/FormattedRelativeTime.js +0 -0
- /package/{dist-src → pkg/dist-src}/index.js +0 -0
- /package/{dist-src → pkg/dist-src}/time-field/TimeField.js +0 -0
- /package/{dist-src → pkg/dist-src}/use-date-time/useDateTime.js +0 -0
- /package/{dist-src → pkg/dist-src}/use-date-time-range/useDateTimeRange.js +0 -0
- /package/{dist-web → pkg/dist-web}/index.js +0 -0
- /package/{dist-web → pkg/dist-web}/index.js.map +0 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
import { Typography } from '@material-ui/core';
|
|
2
|
+
import {
|
|
3
|
+
mockDate,
|
|
4
|
+
renderComponent,
|
|
5
|
+
renderCSS,
|
|
6
|
+
} from '@superdispatch/ui-testutils';
|
|
7
|
+
import { EventType, fireEvent, screen } from '@testing-library/react';
|
|
8
|
+
import userEvent from '@testing-library/user-event';
|
|
9
|
+
import { DateObjectUnits, DateTime } from 'luxon';
|
|
10
|
+
import { setDefaultTimeZone } from '../date-config/DateConfig';
|
|
11
|
+
import {
|
|
12
|
+
DatePayload,
|
|
13
|
+
DateString,
|
|
14
|
+
NullableDateString,
|
|
15
|
+
} from '../date-time-utils/DateTimeUtils';
|
|
16
|
+
import {
|
|
17
|
+
Calendar,
|
|
18
|
+
CalendarDateEvent,
|
|
19
|
+
CalendarDayHighlightColor,
|
|
20
|
+
} from './Calendar';
|
|
21
|
+
import {
|
|
22
|
+
CalendarQuickSelection,
|
|
23
|
+
CalendarQuickSelectionItem,
|
|
24
|
+
} from './CalendarQuickSelection';
|
|
25
|
+
|
|
26
|
+
type MockCalendarDayEventHandler = jest.Mock<void, [CalendarDateEvent]>;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
mockDate();
|
|
30
|
+
setDefaultTimeZone('local');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('month', () => {
|
|
34
|
+
renderComponent(<Calendar />);
|
|
35
|
+
|
|
36
|
+
expect(screen.getByRole('heading')).toHaveTextContent('May 2019');
|
|
37
|
+
|
|
38
|
+
userEvent.click(screen.getByLabelText('Previous Month'));
|
|
39
|
+
|
|
40
|
+
expect(screen.getByRole('heading')).toHaveTextContent('April 2019');
|
|
41
|
+
|
|
42
|
+
userEvent.click(screen.getByLabelText('Next Month'));
|
|
43
|
+
|
|
44
|
+
expect(screen.getByRole('heading')).toHaveTextContent('May 2019');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('weeks', () => {
|
|
48
|
+
renderComponent(<Calendar />);
|
|
49
|
+
|
|
50
|
+
const [weeksRow] = screen.getAllByRole('row');
|
|
51
|
+
expect(weeksRow!.childNodes).toHaveLength(7);
|
|
52
|
+
expect(weeksRow!.childNodes[0]).toHaveTextContent('S');
|
|
53
|
+
expect(weeksRow!.childNodes[1]).toHaveTextContent('M');
|
|
54
|
+
expect(weeksRow!.childNodes[2]).toHaveTextContent('T');
|
|
55
|
+
expect(weeksRow!.childNodes[3]).toHaveTextContent('W');
|
|
56
|
+
expect(weeksRow!.childNodes[4]).toHaveTextContent('T');
|
|
57
|
+
expect(weeksRow!.childNodes[5]).toHaveTextContent('F');
|
|
58
|
+
expect(weeksRow!.childNodes[6]).toHaveTextContent('S');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('days', () => {
|
|
62
|
+
renderComponent(<Calendar />);
|
|
63
|
+
expect(screen.getByLabelText(/May 24 2019/)).toHaveTextContent('24');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test.each<
|
|
67
|
+
[
|
|
68
|
+
initialTime: NullableDateString,
|
|
69
|
+
...cases: Array<
|
|
70
|
+
[
|
|
71
|
+
offset: number,
|
|
72
|
+
expectedString: DateString,
|
|
73
|
+
expectedObject: DateObjectUnits,
|
|
74
|
+
]
|
|
75
|
+
>
|
|
76
|
+
]
|
|
77
|
+
>([
|
|
78
|
+
// Sets time to 00:00
|
|
79
|
+
[
|
|
80
|
+
undefined,
|
|
81
|
+
[-7, '2019-05-24T00:00:00.000-07:00', { hour: 0 }],
|
|
82
|
+
[-5, '2019-05-24T00:00:00.000-05:00', { hour: 0 }],
|
|
83
|
+
[-3, '2019-05-24T00:00:00.000-03:00', { hour: 0 }],
|
|
84
|
+
[7, '2019-05-24T00:00:00.000+07:00', { hour: 0 }],
|
|
85
|
+
[5, '2019-05-24T00:00:00.000+05:00', { hour: 0 }],
|
|
86
|
+
[3, '2019-05-24T00:00:00.000+03:00', { hour: 0 }],
|
|
87
|
+
],
|
|
88
|
+
|
|
89
|
+
// Gets time from 00:00Z
|
|
90
|
+
[
|
|
91
|
+
'0000-01-01T00:00:00.000Z',
|
|
92
|
+
[-7, '2019-05-24T17:00:00.000-07:00', { hour: 17 }],
|
|
93
|
+
[-5, '2019-05-24T19:00:00.000-05:00', { hour: 19 }],
|
|
94
|
+
[-3, '2019-05-24T21:00:00.000-03:00', { hour: 21 }],
|
|
95
|
+
[3, '2019-05-24T03:00:00.000+03:00', { hour: 3 }],
|
|
96
|
+
[5, '2019-05-24T05:00:00.000+05:00', { hour: 5 }],
|
|
97
|
+
[7, '2019-05-24T07:00:00.000+07:00', { hour: 7 }],
|
|
98
|
+
],
|
|
99
|
+
|
|
100
|
+
// Gets time from 5:00Z
|
|
101
|
+
[
|
|
102
|
+
'0000-01-01T05:00:00.000Z',
|
|
103
|
+
[-7, '2019-05-24T22:00:00.000-07:00', { hour: 22 }],
|
|
104
|
+
[-5, '2019-05-24T00:00:00.000-05:00', { hour: 0 }],
|
|
105
|
+
[-3, '2019-05-24T02:00:00.000-03:00', { hour: 2 }],
|
|
106
|
+
[3, '2019-05-24T08:00:00.000+03:00', { hour: 8 }],
|
|
107
|
+
[5, '2019-05-24T10:00:00.000+05:00', { hour: 10 }],
|
|
108
|
+
[7, '2019-05-24T12:00:00.000+07:00', { hour: 12 }],
|
|
109
|
+
],
|
|
110
|
+
|
|
111
|
+
// Gets time from 15:00Z
|
|
112
|
+
[
|
|
113
|
+
'0000-01-01T15:00:00.000Z',
|
|
114
|
+
[-7, '2019-05-24T08:00:00.000-07:00', { hour: 8 }],
|
|
115
|
+
[-5, '2019-05-24T10:00:00.000-05:00', { hour: 10 }],
|
|
116
|
+
[-3, '2019-05-24T12:00:00.000-03:00', { hour: 12 }],
|
|
117
|
+
[3, '2019-05-24T18:00:00.000+03:00', { hour: 18 }],
|
|
118
|
+
[5, '2019-05-24T20:00:00.000+05:00', { hour: 20 }],
|
|
119
|
+
[7, '2019-05-24T22:00:00.000+07:00', { hour: 22 }],
|
|
120
|
+
],
|
|
121
|
+
|
|
122
|
+
// Gets time from 20:00Z
|
|
123
|
+
[
|
|
124
|
+
'0000-01-01T20:00:00.000Z',
|
|
125
|
+
[-7, '2019-05-24T13:00:00.000-07:00', { hour: 13 }],
|
|
126
|
+
[-5, '2019-05-24T15:00:00.000-05:00', { hour: 15 }],
|
|
127
|
+
[-3, '2019-05-24T17:00:00.000-03:00', { hour: 17 }],
|
|
128
|
+
[3, '2019-05-24T23:00:00.000+03:00', { hour: 23 }],
|
|
129
|
+
[5, '2019-05-24T01:00:00.000+05:00', { hour: 1 }],
|
|
130
|
+
[7, '2019-05-24T03:00:00.000+07:00', { hour: 3 }],
|
|
131
|
+
],
|
|
132
|
+
])('initialTime(%p)', (initialTime, ...cases) => {
|
|
133
|
+
const view = renderComponent(<Calendar />);
|
|
134
|
+
|
|
135
|
+
for (const [offset, expectedString, expectedObject] of cases) {
|
|
136
|
+
setDefaultTimeZone(offset * 60);
|
|
137
|
+
|
|
138
|
+
const handlers: Partial<Record<EventType, jest.Mock>> = {
|
|
139
|
+
click: jest.fn(),
|
|
140
|
+
keyDown: jest.fn(),
|
|
141
|
+
mouseEnter: jest.fn(),
|
|
142
|
+
mouseLeave: jest.fn(),
|
|
143
|
+
mouseDown: jest.fn(),
|
|
144
|
+
mouseUp: jest.fn(),
|
|
145
|
+
touchEnd: jest.fn(),
|
|
146
|
+
touchStart: jest.fn(),
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
view.rerender(
|
|
150
|
+
<Calendar
|
|
151
|
+
key={offset /* force rerender on offset change */}
|
|
152
|
+
initialTime={initialTime}
|
|
153
|
+
onDayClick={handlers.click}
|
|
154
|
+
onDayKeyDown={handlers.keyDown}
|
|
155
|
+
onDayMouseEnter={handlers.mouseEnter}
|
|
156
|
+
onDayMouseLeave={handlers.mouseLeave}
|
|
157
|
+
onDayMouseDown={handlers.mouseDown}
|
|
158
|
+
onDayMouseUp={handlers.mouseUp}
|
|
159
|
+
onDayTouchEnd={handlers.touchEnd}
|
|
160
|
+
onDayTouchStart={handlers.touchStart}
|
|
161
|
+
/>,
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
for (const [event, handler] of Object.entries(handlers) as Array<
|
|
165
|
+
[EventType, MockCalendarDayEventHandler]
|
|
166
|
+
>) {
|
|
167
|
+
expect(handler).not.toHaveBeenCalled();
|
|
168
|
+
fireEvent[event](screen.getByLabelText(/May 24/));
|
|
169
|
+
expect(handler).toHaveBeenCalledTimes(1);
|
|
170
|
+
|
|
171
|
+
const [call] = handler.mock.calls;
|
|
172
|
+
|
|
173
|
+
expect(call).toHaveLength(1);
|
|
174
|
+
|
|
175
|
+
const [info] = call!;
|
|
176
|
+
|
|
177
|
+
expect(info.stringValue).toBe(expectedString);
|
|
178
|
+
expect(info.dateValue.toObject()).toEqual({
|
|
179
|
+
year: 2019,
|
|
180
|
+
month: 5,
|
|
181
|
+
day: 24,
|
|
182
|
+
minute: 0,
|
|
183
|
+
second: 0,
|
|
184
|
+
millisecond: 0,
|
|
185
|
+
...expectedObject,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('onDayClick', () => {
|
|
192
|
+
const onDayClick: MockCalendarDayEventHandler = jest.fn();
|
|
193
|
+
|
|
194
|
+
const now = DateTime.local().startOf('day');
|
|
195
|
+
renderComponent(
|
|
196
|
+
<Calendar
|
|
197
|
+
onDayClick={onDayClick}
|
|
198
|
+
selectedDays={({ dateValue }) => dateValue >= now}
|
|
199
|
+
/>,
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
expect(screen.getByLabelText(/May 23 2019/)).not.toHaveClass(
|
|
203
|
+
'SD-Calendar-selected',
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
for (let idx = 1; idx < now.day; idx++) {
|
|
207
|
+
const day = String(idx).padStart(2, '0');
|
|
208
|
+
const element = screen.getByLabelText(new RegExp(`May ${day} 2019`));
|
|
209
|
+
|
|
210
|
+
expect(element).not.toHaveClass('SD-Calendar-selected');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
for (let idx = now.day; idx <= now.daysInMonth; idx++) {
|
|
214
|
+
const day = String(idx).padStart(2, '0');
|
|
215
|
+
const element = screen.getByLabelText(new RegExp(`May ${day} 2019`));
|
|
216
|
+
|
|
217
|
+
expect(element).toHaveClass('SD-Calendar-selected');
|
|
218
|
+
|
|
219
|
+
userEvent.click(element);
|
|
220
|
+
|
|
221
|
+
expect(onDayClick).toHaveBeenCalledTimes(1);
|
|
222
|
+
|
|
223
|
+
const info = onDayClick.mock.calls[0]![0]!;
|
|
224
|
+
|
|
225
|
+
expect(info.stringValue).toBe(`2019-05-${day}T00:00:00.000-05:00`);
|
|
226
|
+
|
|
227
|
+
onDayClick.mockClear();
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('disabledDays', () => {
|
|
232
|
+
const onDayClick: MockCalendarDayEventHandler = jest.fn();
|
|
233
|
+
renderComponent(
|
|
234
|
+
<Calendar
|
|
235
|
+
onDayClick={onDayClick}
|
|
236
|
+
disabledDays={({ dateValue }) => dateValue.day === 24}
|
|
237
|
+
/>,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
expect(screen.getByLabelText(/May 24 2019/)).toHaveClass(
|
|
241
|
+
'SD-Calendar-disabled',
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
userEvent.click(screen.getByLabelText(/May 24 2019/));
|
|
245
|
+
|
|
246
|
+
expect(onDayClick).toHaveBeenCalledTimes(1);
|
|
247
|
+
|
|
248
|
+
const info = onDayClick.mock.calls[0]![0]!;
|
|
249
|
+
|
|
250
|
+
expect(info.disabled).toBe(true);
|
|
251
|
+
expect(info.selected).toBe(false);
|
|
252
|
+
expect(info.stringValue).toBe('2019-05-24T00:00:00.000-05:00');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('highlightedDays', () => {
|
|
256
|
+
const view = renderComponent(<Calendar />);
|
|
257
|
+
const highlights: CalendarDayHighlightColor[] = [
|
|
258
|
+
'blue',
|
|
259
|
+
'green',
|
|
260
|
+
'purple',
|
|
261
|
+
'red',
|
|
262
|
+
'teal',
|
|
263
|
+
'yellow',
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
function modifier({ dateValue }: DatePayload): boolean {
|
|
267
|
+
return dateValue.day === 24;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
for (const currentHighlight of highlights) {
|
|
271
|
+
view.rerender(
|
|
272
|
+
<Calendar highlightedDays={{ [currentHighlight]: modifier }} />,
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const day = screen.getByLabelText(/May 24 2019/);
|
|
276
|
+
|
|
277
|
+
for (const highlight of highlights) {
|
|
278
|
+
if (highlight === currentHighlight) {
|
|
279
|
+
// eslint-disable-next-line jest/no-conditional-expect
|
|
280
|
+
expect(day).toHaveClass(`SD-Calendar-${highlight}`);
|
|
281
|
+
} else {
|
|
282
|
+
// eslint-disable-next-line jest/no-conditional-expect
|
|
283
|
+
expect(day).not.toHaveClass(`SD-Calendar-${highlight}`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('footer', () => {
|
|
290
|
+
renderComponent(
|
|
291
|
+
<Calendar
|
|
292
|
+
footer={<Typography color="textSecondary">Footer helper text</Typography>}
|
|
293
|
+
/>,
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
expect(screen.getByText('Footer helper text')).toBeInTheDocument();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test('quickSelection', () => {
|
|
300
|
+
renderComponent(
|
|
301
|
+
<Calendar
|
|
302
|
+
quickSelection={
|
|
303
|
+
<CalendarQuickSelection>
|
|
304
|
+
<CalendarQuickSelectionItem>Today</CalendarQuickSelectionItem>
|
|
305
|
+
<CalendarQuickSelectionItem>Tomorrow</CalendarQuickSelectionItem>
|
|
306
|
+
<CalendarQuickSelectionItem>Yesterday</CalendarQuickSelectionItem>
|
|
307
|
+
</CalendarQuickSelection>
|
|
308
|
+
}
|
|
309
|
+
/>,
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
expect(screen.getByText('Today')).toBeInTheDocument();
|
|
313
|
+
expect(screen.getByText('Tomorrow')).toBeInTheDocument();
|
|
314
|
+
expect(screen.getByText('Yesterday')).toBeInTheDocument();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test('css', () => {
|
|
318
|
+
expect(renderCSS(<Calendar />, ['SD-Calendar'])).toMatchInlineSnapshot(`
|
|
319
|
+
.SD-Calendar-container {
|
|
320
|
+
display: inline-block;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.SD-Calendar-wrapper {
|
|
324
|
+
position: relative;
|
|
325
|
+
user-select: none;
|
|
326
|
+
flex-direction: row;
|
|
327
|
+
padding-bottom: 16px;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.SD-Calendar-wrapper:focus {
|
|
331
|
+
outline: none;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.SD-Calendar-navButtonPrev {
|
|
335
|
+
top: 12px;
|
|
336
|
+
left: 12px;
|
|
337
|
+
position: absolute;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.SD-Calendar-navButtonNext {
|
|
341
|
+
top: 12px;
|
|
342
|
+
right: 12px;
|
|
343
|
+
position: absolute;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
.SD-Calendar-months {
|
|
347
|
+
display: flex;
|
|
348
|
+
flex-wrap: wrap;
|
|
349
|
+
justify-content: center;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
.SD-Calendar-month {
|
|
353
|
+
margin: 16px 16px 0px 16px;
|
|
354
|
+
user-select: none;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.SD-Calendar-caption {
|
|
358
|
+
display: table-caption;
|
|
359
|
+
padding: 0px 8px;
|
|
360
|
+
text-align: center;
|
|
361
|
+
margin-bottom: 8px;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
.SD-Calendar-weekdays {
|
|
365
|
+
display: table-header-group;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.SD-Calendar-weekdaysRow {
|
|
369
|
+
margin: 8px 0px;
|
|
370
|
+
display: flex;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.SD-Calendar-weekday {
|
|
374
|
+
color: Color.Dark300;
|
|
375
|
+
width: 40px;
|
|
376
|
+
height: 40px;
|
|
377
|
+
margin: 1px;
|
|
378
|
+
display: flex;
|
|
379
|
+
align-items: center;
|
|
380
|
+
justify-content: center;
|
|
381
|
+
text-decoration: none;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.SD-Calendar-body {
|
|
385
|
+
display: flex;
|
|
386
|
+
flex-direction: column;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
.SD-Calendar-week {
|
|
390
|
+
display: flex;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
.SD-Calendar-day {
|
|
394
|
+
width: 40px;
|
|
395
|
+
height: 40px;
|
|
396
|
+
margin: 1px;
|
|
397
|
+
display: flex;
|
|
398
|
+
z-index: 1;
|
|
399
|
+
position: relative;
|
|
400
|
+
transition: color 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,
|
|
401
|
+
background-color 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
|
402
|
+
align-items: center;
|
|
403
|
+
border-radius: 4px;
|
|
404
|
+
justify-content: center;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
.SD-Calendar-day:before {
|
|
408
|
+
top: 0;
|
|
409
|
+
left: -1px;
|
|
410
|
+
right: -1px;
|
|
411
|
+
bottom: 0;
|
|
412
|
+
content: '';
|
|
413
|
+
z-index: -1;
|
|
414
|
+
position: absolute;
|
|
415
|
+
transition: background-color 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
|
416
|
+
background-color: Color.Transparent;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
.SD-Calendar-day:after {
|
|
420
|
+
top: 0;
|
|
421
|
+
left: 0;
|
|
422
|
+
right: 0;
|
|
423
|
+
bottom: 0;
|
|
424
|
+
content: '';
|
|
425
|
+
z-index: -1;
|
|
426
|
+
position: absolute;
|
|
427
|
+
transition: background-color 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
|
428
|
+
border-radius: 4px;
|
|
429
|
+
background-color: Color.Transparent;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
.SD-Calendar-day:hover,
|
|
433
|
+
.SD-Calendar-day:focus {
|
|
434
|
+
outline: none;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
.SD-Calendar-day.SD-Calendar-disabled {
|
|
438
|
+
color: Color.Dark100;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled) {
|
|
442
|
+
color: Color.Dark500;
|
|
443
|
+
cursor: pointer;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):active,
|
|
447
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled).SD-Calendar-selected {
|
|
448
|
+
color: Color.White;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):active:after,
|
|
452
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled).SD-Calendar-selected:after {
|
|
453
|
+
background-color: Color.Blue300;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-today {
|
|
457
|
+
color: Color.Blue300;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active):hover,
|
|
461
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active):focus {
|
|
462
|
+
background-color: Color.Silver100;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-blue {
|
|
466
|
+
color: Color.Blue500;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-green {
|
|
470
|
+
color: Color.Green500;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-purple {
|
|
474
|
+
color: Color.Purple500;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-red {
|
|
478
|
+
color: Color.Red500;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-teal {
|
|
482
|
+
color: Color.Teal500;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-yellow {
|
|
486
|
+
color: Color.Yellow500;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-yellow {
|
|
490
|
+
background-color: Color.Yellow50;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-teal {
|
|
494
|
+
background-color: Color.Teal50;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-red {
|
|
498
|
+
background-color: Color.Red50;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-purple {
|
|
502
|
+
background-color: Color.Purple50;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-green {
|
|
506
|
+
background-color: Color.Green50;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.SD-Calendar-day:not(.SD-Calendar-outside):not(.SD-Calendar-disabled):not(.SD-Calendar-selected):not(:active).SD-Calendar-blue {
|
|
510
|
+
background-color: Color.Blue50;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
.SD-Calendar-day.SD-Calendar-disabled.SD-Calendar-selected:not(.SD-Calendar-outside):after {
|
|
514
|
+
background-color: Color.Silver300;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
.SD-Calendar-day:last-child:before,
|
|
518
|
+
.SD-Calendar-day.SD-Calendar-lastDayOfMonth:before {
|
|
519
|
+
border-radius: 0px 4px 4px 0px;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
.SD-Calendar-day:first-child:before,
|
|
523
|
+
.SD-Calendar-day.SD-Calendar-firstDayOfMonth:before {
|
|
524
|
+
border-radius: 4px 0px 0px 4px;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.SD-Calendar-footer {
|
|
528
|
+
padding: 16px;
|
|
529
|
+
}
|
|
530
|
+
`);
|
|
531
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Typography } from '@material-ui/core';
|
|
2
|
+
import { Meta } from '@storybook/react';
|
|
3
|
+
import { Calendar } from './Calendar.playroom';
|
|
4
|
+
import {
|
|
5
|
+
CalendarQuickSelection,
|
|
6
|
+
CalendarQuickSelectionItem,
|
|
7
|
+
} from './CalendarQuickSelection';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: 'Dates/Calendar',
|
|
11
|
+
component: Calendar,
|
|
12
|
+
subcomponents: { CalendarQuickSelection, CalendarQuickSelectionItem },
|
|
13
|
+
} as Meta;
|
|
14
|
+
|
|
15
|
+
export const basic = () => <Calendar />;
|
|
16
|
+
|
|
17
|
+
export const disabledDays = () => (
|
|
18
|
+
<Calendar disabledDays={({ dateValue }) => dateValue.day % 2 === 0} />
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const highlightedDays = () => (
|
|
22
|
+
<Calendar
|
|
23
|
+
highlightedDays={{
|
|
24
|
+
blue: ({ dateValue }) => dateValue.day === 0 || dateValue.day === 6,
|
|
25
|
+
green: ({ dateValue }) => dateValue.day === 1,
|
|
26
|
+
purple: ({ dateValue }) => dateValue.day === 2,
|
|
27
|
+
red: ({ dateValue }) => dateValue.day === 3,
|
|
28
|
+
teal: ({ dateValue }) => dateValue.day === 4,
|
|
29
|
+
yellow: ({ dateValue }) => dateValue.day === 5,
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
export const footer = () => (
|
|
35
|
+
<Calendar
|
|
36
|
+
footer={<Typography color="textSecondary">Footer helper text</Typography>}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const quickSelection = () => (
|
|
41
|
+
<Calendar
|
|
42
|
+
quickSelection={
|
|
43
|
+
<CalendarQuickSelection>
|
|
44
|
+
<CalendarQuickSelectionItem>Today</CalendarQuickSelectionItem>
|
|
45
|
+
<CalendarQuickSelectionItem>Tomorrow</CalendarQuickSelectionItem>
|
|
46
|
+
<CalendarQuickSelectionItem>Yesterday</CalendarQuickSelectionItem>
|
|
47
|
+
</CalendarQuickSelection>
|
|
48
|
+
}
|
|
49
|
+
/>
|
|
50
|
+
);
|