-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSingleDateViewer.tsx
More file actions
109 lines (99 loc) · 2.78 KB
/
Copy pathSingleDateViewer.tsx
File metadata and controls
109 lines (99 loc) · 2.78 KB
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
import type { DateInfo } from 'types/calendar';
import AttendeeTooltip from '@components/AttendeeTooltip';
import {
s_baseDateButton,
s_baseDateText,
s_dateContainer,
s_dateText,
} from '@components/MeetingCalendar/Date/Date.styles';
import { getDateInfo } from '@components/MeetingCalendar/Date/Date.utils';
import { formatAriaFullDate } from '@utils/a11y';
import Check from '@assets/images/attendeeCheck.svg';
import { s_additionalText, s_viewer } from './SingleDate.styles';
interface DateProps {
dateInfo: DateInfo;
today: Date;
isAvailable: boolean;
selectAttendee: string;
availableAttendees: string[] | undefined;
key: string;
}
export default function SingleDateViewer({
dateInfo,
today,
isAvailable,
selectAttendee,
availableAttendees,
}: DateProps) {
const { value, status } = dateInfo;
const {
date,
targetFullDate,
targetDayOfWeekKR,
isHoliday,
isToday,
isSaturday,
isSunday,
isPrevDate,
} = getDateInfo(value, today);
const additionalText = () => {
if (!availableAttendees) return '\u00A0';
if (selectAttendee === '' && availableAttendees) return `+${availableAttendees.length}`;
if (selectAttendee !== '' && availableAttendees) return <Check width={12} height={12} />;
};
const hasAttendeeTooltip = selectAttendee === '' && availableAttendees;
if (status !== 'current') return <div css={s_dateContainer}></div>;
return hasAttendeeTooltip ? (
<AttendeeTooltip attendeeNames={availableAttendees} position="top">
<div
css={[
s_dateContainer,
s_baseDateButton,
s_viewer,
s_dateText({
isDisabledDate: !isAvailable || isPrevDate,
isSelectedDate: false,
isToday,
isHoliday,
isSunday,
isSaturday,
}),
]}
role="text"
aria-hidden={!isAvailable}
aria-label={
isAvailable
? formatAriaFullDate(targetFullDate, targetDayOfWeekKR, availableAttendees)
: ''
}
>
<span css={s_baseDateText}>{date}</span>
<span css={s_additionalText}>{additionalText()}</span>
</div>
</AttendeeTooltip>
) : (
<div
css={[
s_dateContainer,
s_baseDateButton,
s_viewer,
s_dateText({
isDisabledDate: !isAvailable || isPrevDate,
isSelectedDate: false,
isToday,
isHoliday,
isSunday,
isSaturday,
}),
]}
role="text"
aria-hidden={!isAvailable}
aria-label={
isAvailable ? formatAriaFullDate(targetFullDate, targetDayOfWeekKR, availableAttendees) : ''
}
>
<span css={s_baseDateText}>{date}</span>
<span css={s_additionalText}>{additionalText()}</span>
</div>
);
}