|
1 | | -export const weekdayNames = { |
2 | | - 'en-GB': { |
3 | | - Sunday: { |
4 | | - long: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], |
5 | | - short: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], |
6 | | - }, |
7 | | - }, |
8 | | -}; |
9 | | - |
10 | | -/** |
11 | | - * Abstraction around calendar day DOM structure, |
12 | | - * allows for writing readable, 'DOM structure agnostic' tests |
13 | | - */ |
14 | | -export class DayObject { |
15 | | - constructor(dayEl) { |
16 | | - this.el = dayEl; |
17 | | - } |
18 | | - |
19 | | - /** |
20 | | - * Node references |
21 | | - */ |
22 | | - |
23 | | - get calendarShadowRoot() { |
24 | | - return this.el.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode; |
25 | | - } |
26 | | - |
27 | | - get cellEl() { |
28 | | - return this.el.parentElement; |
29 | | - } |
30 | | - |
31 | | - get buttonEl() { |
32 | | - return this.el; |
33 | | - } |
34 | | - |
35 | | - /** |
36 | | - * States |
37 | | - */ |
38 | | - |
39 | | - get isDisabled() { |
40 | | - return this.buttonEl.hasAttribute('disabled'); |
41 | | - } |
42 | | - |
43 | | - get isSelected() { |
44 | | - return this.buttonEl.hasAttribute('selected'); |
45 | | - } |
46 | | - |
47 | | - get isToday() { |
48 | | - return this.buttonEl.hasAttribute('today'); |
49 | | - } |
50 | | - |
51 | | - get isCentral() { |
52 | | - return this.buttonEl.getAttribute('tabindex') === '0'; |
53 | | - } |
54 | | - |
55 | | - get isFocused() { |
56 | | - this.calendarShadowRoot.activeElement; |
57 | | - this.buttonEl; |
58 | | - return this.calendarShadowRoot.activeElement === this.buttonEl; |
59 | | - } |
60 | | - |
61 | | - get monthday() { |
62 | | - return Number(this.buttonEl.textContent); |
63 | | - } |
64 | | - |
65 | | - /** |
66 | | - * Text |
67 | | - */ |
68 | | - |
69 | | - get weekdayNameShort() { |
70 | | - const weekdayEls = Array.from( |
71 | | - this.el.parentElement.parentElement.querySelectorAll('.calendar__day-cell'), |
72 | | - ); |
73 | | - const dayIndex = weekdayEls.indexOf(this.el.parentElement); |
74 | | - return weekdayNames['en-GB'].Sunday.short[dayIndex]; |
75 | | - } |
76 | | - |
77 | | - get weekdayNameLong() { |
78 | | - const weekdayEls = Array.from( |
79 | | - this.el.parentElement.parentElement.querySelectorAll('.calendar__day-cell'), |
80 | | - ); |
81 | | - const dayIndex = weekdayEls.indexOf(this.el.parentElement); |
82 | | - return weekdayNames['en-GB'].Sunday.long[dayIndex]; |
83 | | - } |
84 | | - |
85 | | - /** |
86 | | - * Other |
87 | | - */ |
88 | | - get cellIndex() { |
89 | | - return Array.from(this.cellEl.parentElement.children).indexOf(this.cellEl); |
90 | | - } |
91 | | -} |
| 1 | +import { DayObject } from './DayObject.js'; |
92 | 2 |
|
93 | 3 | /** |
94 | 4 | * Abstraction around calendar DOM structure, |
|
0 commit comments