-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCustomHeader.tsx
More file actions
102 lines (95 loc) · 2.34 KB
/
Copy pathCustomHeader.tsx
File metadata and controls
102 lines (95 loc) · 2.34 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
import styled from 'styled-components';
import { useMemo } from 'react';
import { Inline, Padbox } from '../../layout';
import IconButton from '../../ButtonV2/IconButton';
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];
const getYear = (date: Date) => date.getFullYear();
const getMonth = (date: Date) => months[date.getMonth()];
const MonthIndicator = styled.button`
border-radius: var(--sscds-radii-default);
border: 0;
background: transparent;
font-size: var(--sscds-font-size-elementlabel-md);
font-weight: var(--sscds-font-weight-elementlabel-strong);
line-height: var(--sscds-font-size-50);
transition: var(--sscds-action-transition),
transform 50ms var(--sscds-transition-fn);
&:hover {
background-color: var(--sscds-color-background-action-ghost-hover);
}
&:active {
transform: scale(0.98);
}
`;
type DatePickerCustomHeaderProps = {
decreaseMonth: () => void;
increaseMonth: () => void;
increaseYear: () => void;
decreaseYear: () => void;
toggleYearPicker: () => void;
date: Date;
// eslint-disable-next-line react/boolean-prop-naming
showYearPicker: boolean;
};
export const DatePickerCustomHeader = ({
decreaseMonth,
decreaseYear,
toggleYearPicker,
date,
increaseMonth,
increaseYear,
showYearPicker,
}: DatePickerCustomHeaderProps) => {
const [onClickLeft, onClickRight] = useMemo(() => {
return showYearPicker
? [decreaseYear, increaseYear]
: [decreaseMonth, increaseMonth];
}, [
showYearPicker,
decreaseMonth,
increaseMonth,
decreaseYear,
increaseYear,
]);
return (
<Inline
align="center"
gap="xs"
stretch={2}
style={{ marginBlockEnd: 'var(--sscds-space-4x)' }}
>
<IconButton
iconName="angle-left"
label="Go to previous month"
size="sm"
variant="ghost"
onClick={onClickLeft}
/>
<MonthIndicator onClick={() => toggleYearPicker()}>
<Padbox paddingSize="sm" paddingType="squish">{`${getMonth(
date,
)} ${getYear(date)}`}</Padbox>
</MonthIndicator>
<IconButton
iconName="angle-right"
label="Go to next month"
size="sm"
variant="ghost"
onClick={onClickRight}
/>
</Inline>
);
};