@transferwise/components 0.0.0-experimental-e05dfa3 → 0.0.0-experimental-7905c27
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/build/index.esm.js +102 -164
- package/build/index.esm.js.map +1 -1
- package/build/index.js +104 -166
- package/build/index.js.map +1 -1
- package/build/main.css +1 -1
- package/build/styles/dateLookup/DateLookup.css +1 -1
- package/build/styles/header/Header.css +1 -1
- package/build/styles/main.css +1 -1
- package/build/types/dateInput/DateInput.d.ts +2 -0
- package/build/types/dateInput/DateInput.d.ts.map +1 -1
- package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
- package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts +1 -1
- package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -1
- package/build/types/dateLookup/tableLink/TableLink.d.ts +2 -16
- package/build/types/dateLookup/tableLink/TableLink.d.ts.map +1 -1
- package/build/types/dateLookup/tableLink/index.d.ts +1 -1
- package/build/types/dateLookup/tableLink/index.d.ts.map +1 -1
- package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts.map +1 -1
- package/build/types/select/Select.d.ts.map +1 -1
- package/build/types/test-utils/window-mock.d.ts +1 -0
- package/build/types/test-utils/window-mock.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dateInput/DateInput.js +13 -7
- package/src/dateInput/DateInput.spec.js +12 -136
- package/src/dateInput/DateInput.story.tsx +49 -2
- package/src/dateLookup/DateLookup.css +1 -1
- package/src/dateLookup/DateLookup.js +3 -16
- package/src/dateLookup/DateLookup.keyboardEvents.spec.js +0 -12
- package/src/dateLookup/DateLookup.less +49 -46
- package/src/dateLookup/DateLookup.story.js +7 -8
- package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -14
- package/src/dateLookup/dayCalendar/table/DayCalendarTable.spec.js +0 -25
- package/src/dateLookup/monthCalendar/table/MonthCalendarTable.js +20 -33
- package/src/dateLookup/monthCalendar/table/MonthCalendarTable.spec.js +0 -33
- package/src/dateLookup/tableLink/TableLink.js +70 -0
- package/src/dateLookup/yearCalendar/table/YearCalendarTable.js +11 -33
- package/src/dateLookup/yearCalendar/table/YearCalendarTable.spec.js +0 -26
- package/src/header/Header.css +1 -1
- package/src/header/Header.less +0 -5
- package/src/inputs/SelectInput.spec.tsx +3 -27
- package/src/main.css +1 -1
- package/src/phoneNumberInput/PhoneNumberInput.spec.js +4 -20
- package/src/select/Select.js +3 -0
- package/src/test-utils/window-mock.ts +11 -0
- package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts +0 -2
- package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts.map +0 -1
- package/src/dateLookup/getFocusableTime/getFocusable.spec.js +0 -38
- package/src/dateLookup/getFocusableTime/getFocusableTime.tsx +0 -28
- package/src/dateLookup/tableLink/TableLink.tsx +0 -80
- /package/src/dateLookup/tableLink/{index.ts → index.js} +0 -0
|
@@ -9,24 +9,12 @@
|
|
|
9
9
|
text-align: center;
|
|
10
10
|
table-layout: fixed;
|
|
11
11
|
|
|
12
|
-
> thead > tr > th:nth-child(7n+6),
|
|
13
|
-
> thead > tr > th:nth-child(7n+7),
|
|
14
|
-
> tbody > tr > td:nth-child(7n+6) button,
|
|
15
|
-
> tbody > tr > td:nth-child(7n+7) button {
|
|
16
|
-
color: var(--color-content-secondary);
|
|
17
|
-
font-weight: var(--font-weight-regular);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
12
|
> tbody > tr > td {
|
|
21
13
|
padding: var(--size-4);
|
|
22
14
|
@media (--screen-400-zoom) {
|
|
23
15
|
padding: 0;
|
|
24
16
|
}
|
|
25
17
|
|
|
26
|
-
&:has(.tw-date-lookup-day-option) {
|
|
27
|
-
padding: 1px;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
18
|
button {
|
|
31
19
|
width: 100%;
|
|
32
20
|
padding: var(--size-4) 0;
|
|
@@ -38,34 +26,37 @@
|
|
|
38
26
|
border-radius: var(--radius-small);
|
|
39
27
|
background-color: transparent;
|
|
40
28
|
font-weight: var(--font-weight-semi-bold);
|
|
41
|
-
color: var(--color-content-primary);
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
line-height: var(--size-40);
|
|
47
|
-
width: var(--size-40);
|
|
48
|
-
padding: 0;
|
|
49
|
-
display: inline-flex;
|
|
50
|
-
align-items: center;
|
|
51
|
-
justify-content: center;
|
|
52
|
-
|
|
53
|
-
&.today {
|
|
54
|
-
text-decoration: underline;
|
|
55
|
-
text-decoration-thickness: 2px;
|
|
56
|
-
text-underline-offset: 4px;
|
|
57
|
-
}
|
|
30
|
+
&:not(.disabled, :disabled).active {
|
|
31
|
+
color: #fff;
|
|
32
|
+
background-color: var(--color-interactive-accent-active);
|
|
58
33
|
}
|
|
59
|
-
}
|
|
60
34
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
35
|
+
&:not(.disabled, :disabled):hover {
|
|
36
|
+
color: #fff;
|
|
37
|
+
background-color: var(--color-interactive-accent-hover);
|
|
38
|
+
}
|
|
65
39
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
40
|
+
.np-theme-personal & {
|
|
41
|
+
color: var(--color-content-primary);
|
|
42
|
+
|
|
43
|
+
&:not(.disabled, :disabled).active {
|
|
44
|
+
color: var(--color-interactive-control);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&:not(.disabled, :disabled):hover {
|
|
48
|
+
color: var(--color-interactive-control);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
> thead > tr > th:nth-child(7n+6),
|
|
54
|
+
> thead > tr > th:nth-child(7n+7),
|
|
55
|
+
> tbody > tr > td:nth-child(7n+6) button,
|
|
56
|
+
> tbody > tr > td:nth-child(7n+7) button {
|
|
57
|
+
.np-theme-personal & {
|
|
58
|
+
color: var(--color-content-secondary);
|
|
59
|
+
font-weight: var(--font-weight-regular);
|
|
69
60
|
}
|
|
70
61
|
}
|
|
71
62
|
|
|
@@ -73,15 +64,9 @@
|
|
|
73
64
|
text-decoration: none;
|
|
74
65
|
}
|
|
75
66
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.tw-date-lookup-header-current-container {
|
|
80
|
-
display: inline;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.tw-date-lookup-header-current {
|
|
84
|
-
font-weight: var(--font-weight-bold);
|
|
67
|
+
.np-theme-personal & {
|
|
68
|
+
background-color: inherit;
|
|
69
|
+
}
|
|
85
70
|
}
|
|
86
71
|
|
|
87
72
|
.np-theme-personal {
|
|
@@ -98,9 +83,27 @@
|
|
|
98
83
|
td {
|
|
99
84
|
border: none;
|
|
100
85
|
}
|
|
86
|
+
|
|
87
|
+
.tw-date-lookup-header-current-container {
|
|
88
|
+
display: inline-block;
|
|
101
89
|
|
|
102
|
-
|
|
90
|
+
.tw-date-lookup-header-current {
|
|
91
|
+
color: var(--color-content-primary);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.tw-date-lookup-day-option {
|
|
96
|
+
height: var(--size-32);
|
|
97
|
+
line-height: var(--size-32);
|
|
98
|
+
display: inline-flex;
|
|
99
|
+
align-items: center;
|
|
100
|
+
justify-content: center;
|
|
103
101
|
color: var(--color-content-primary);
|
|
104
102
|
}
|
|
103
|
+
|
|
104
|
+
.tw-date-lookup-day-option.active {
|
|
105
|
+
background-color: var(--color-interactive-accent);
|
|
106
|
+
color: var(--color-interactive-primary);
|
|
107
|
+
}
|
|
105
108
|
}
|
|
106
109
|
}
|
|
@@ -13,8 +13,6 @@ export default {
|
|
|
13
13
|
|
|
14
14
|
let theFuture = new Date();
|
|
15
15
|
theFuture.setDate(theFuture.getDate() + 10);
|
|
16
|
-
let thePast = new Date();
|
|
17
|
-
thePast.setDate(thePast.getDate() - 10);
|
|
18
16
|
|
|
19
17
|
export const Basic = () => {
|
|
20
18
|
const [value, setValue] = useState(null);
|
|
@@ -24,13 +22,16 @@ export const Basic = () => {
|
|
|
24
22
|
const placeholder = text('placeholder', 'placeholder');
|
|
25
23
|
const size = select('size', Object.values(Size), Size.MEDIUM);
|
|
26
24
|
|
|
25
|
+
const minvalue = date('minvalue', new Date());
|
|
26
|
+
const maxvalue = date('maxvalue', theFuture);
|
|
27
27
|
const clearable = boolean('clearable', false);
|
|
28
28
|
|
|
29
29
|
return (
|
|
30
30
|
<DateLookup
|
|
31
31
|
disabled={disabled}
|
|
32
32
|
label={label}
|
|
33
|
-
|
|
33
|
+
max={new Date(maxvalue)}
|
|
34
|
+
min={new Date(minvalue)}
|
|
34
35
|
monthFormat={monthFormat}
|
|
35
36
|
placeholder={placeholder}
|
|
36
37
|
size={size}
|
|
@@ -41,11 +42,9 @@ export const Basic = () => {
|
|
|
41
42
|
);
|
|
42
43
|
};
|
|
43
44
|
|
|
44
|
-
Basic.play =
|
|
45
|
-
// testing focus state on keyboard nav
|
|
45
|
+
Basic.play = ({ canvasElement }) => {
|
|
46
46
|
const canvas = within(canvasElement);
|
|
47
|
-
userEvent.
|
|
48
|
-
userEvent.keyboard('{space}');
|
|
47
|
+
userEvent.click(canvas.getByRole('button'));
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
export const Basic400Zoom = storyConfig(
|
|
@@ -61,7 +60,7 @@ export const RightAligned = () => {
|
|
|
61
60
|
const placeholder = text('placeholder', 'placeholder');
|
|
62
61
|
const size = select('size', Object.values(Size), Size.MEDIUM);
|
|
63
62
|
|
|
64
|
-
const minvalue = date('minvalue',
|
|
63
|
+
const minvalue = date('minvalue', new Date());
|
|
65
64
|
const maxvalue = date('maxvalue', theFuture);
|
|
66
65
|
const clearable = boolean('clearable', false);
|
|
67
66
|
|
|
@@ -4,7 +4,6 @@ import { PureComponent } from 'react';
|
|
|
4
4
|
import { injectIntl } from 'react-intl';
|
|
5
5
|
|
|
6
6
|
import { getDayNames, isWithinRange } from '../../../common/dateUtils';
|
|
7
|
-
import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
|
|
8
7
|
import { getStartOfDay } from '../../getStartOfDay';
|
|
9
8
|
import TableLink from '../../tableLink';
|
|
10
9
|
|
|
@@ -66,16 +65,6 @@ class DayCalendarTable extends PureComponent {
|
|
|
66
65
|
return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
|
|
67
66
|
};
|
|
68
67
|
|
|
69
|
-
isToday = (day) => {
|
|
70
|
-
const { viewMonth, viewYear } = this.props;
|
|
71
|
-
return +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
getAutofocusDay = (weeks) => {
|
|
75
|
-
const days = weeks.flatMap((week) => week);
|
|
76
|
-
return getFocusableTime(this.isActive, this.isToday, this.isDisabled, days);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
68
|
render() {
|
|
80
69
|
const {
|
|
81
70
|
viewMonth,
|
|
@@ -83,7 +72,6 @@ class DayCalendarTable extends PureComponent {
|
|
|
83
72
|
intl: { locale },
|
|
84
73
|
} = this.props;
|
|
85
74
|
const weeks = this.getTableStructure();
|
|
86
|
-
let autoFocusDay = this.getAutofocusDay(weeks, viewMonth, viewYear);
|
|
87
75
|
return (
|
|
88
76
|
<table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
|
|
89
77
|
<thead>
|
|
@@ -115,11 +103,10 @@ class DayCalendarTable extends PureComponent {
|
|
|
115
103
|
locale,
|
|
116
104
|
SHORT_DAY_FORMAT,
|
|
117
105
|
)}
|
|
118
|
-
autofocus={day === autoFocusDay}
|
|
119
106
|
longTitle={formatDate(new Date(viewYear, viewMonth, day), locale)}
|
|
120
107
|
active={this.isActive(day)}
|
|
121
108
|
disabled={this.isDisabled(day)}
|
|
122
|
-
today={
|
|
109
|
+
today={+getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day)}
|
|
123
110
|
onClick={this.selectDay}
|
|
124
111
|
/>
|
|
125
112
|
)}
|
|
@@ -117,31 +117,6 @@ describe('DayCalendarTable', () => {
|
|
|
117
117
|
expect(props.onSelect).toHaveBeenCalledWith(new Date(2018, 11, 1));
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
-
it('sets autofocus to true when 5 is the selected day', () => {
|
|
121
|
-
component.setProps({ selectedDate: new Date(2018, 11, 5) });
|
|
122
|
-
expect(getTableLinkAt(4).prop('autofocus')).toBe(true);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('does not set autofocus to true when 5 is the selected day but not the right month', () => {
|
|
126
|
-
component.setProps({ selectedDate: new Date(2018, 10, 5) });
|
|
127
|
-
expect(getTableLinkAt(4).prop('autofocus')).toBe(false);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('does not set autofocus to true when 5 is the selected day but not the right year', () => {
|
|
131
|
-
component.setProps({ selectedDate: new Date(2017, 11, 5) });
|
|
132
|
-
expect(getTableLinkAt(4).prop('autofocus')).toBe(false);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('sets autofocus to true when selected date is null and current day is visible', () => {
|
|
136
|
-
const today = new Date();
|
|
137
|
-
component.setProps({
|
|
138
|
-
selectedDate: today,
|
|
139
|
-
viewMonth: today.getMonth(),
|
|
140
|
-
viewYear: today.getFullYear(),
|
|
141
|
-
});
|
|
142
|
-
expect(component.find(TableLink).find({ today: true }).prop('autofocus')).toBe(true);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
120
|
const getTableLinkAt = (i) => component.find(TableLink).at(i);
|
|
146
121
|
const getTableDataAt = (i) => component.find('tbody td').at(i);
|
|
147
122
|
});
|
|
@@ -2,40 +2,33 @@ import { formatDate } from '@transferwise/formatting';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
4
|
|
|
5
|
-
import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
|
|
6
5
|
import TableLink from '../../tableLink';
|
|
7
6
|
|
|
8
7
|
const ROWS = 3;
|
|
9
8
|
const COLS = 4;
|
|
10
|
-
const
|
|
9
|
+
const MONTH_ONLY_FORMAY = { month: 'short' };
|
|
11
10
|
|
|
12
|
-
const MonthCalendarTable = ({
|
|
11
|
+
const MonthCalendarTable = ({
|
|
12
|
+
selectedDate: selected,
|
|
13
|
+
min,
|
|
14
|
+
max,
|
|
15
|
+
viewYear,
|
|
16
|
+
placeholder,
|
|
17
|
+
onSelect,
|
|
18
|
+
}) => {
|
|
13
19
|
const { locale } = useIntl();
|
|
14
|
-
const getLink = (month) => {
|
|
15
|
-
return (
|
|
16
|
-
<TableLink
|
|
17
|
-
item={month}
|
|
18
|
-
type="month"
|
|
19
|
-
title={formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAT)}
|
|
20
|
-
active={isSelected(month)}
|
|
21
|
-
disabled={isDisabled(month)}
|
|
22
|
-
today={viewYear === new Date().getFullYear() && month === new Date().getMonth()}
|
|
23
|
-
autofocus={autofocusMonth === month}
|
|
24
|
-
onClick={onSelect}
|
|
25
|
-
/>
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const isSelected = (month) => {
|
|
30
|
-
return (
|
|
31
|
-
selectedDate && month === selectedDate.getMonth() && viewYear === selectedDate.getFullYear()
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const isThisMonth = (month) => {
|
|
36
|
-
return viewYear === new Date().getFullYear() && month === new Date().getMonth();
|
|
37
|
-
};
|
|
38
20
|
|
|
21
|
+
const getLink = (month) => (
|
|
22
|
+
<TableLink
|
|
23
|
+
item={month}
|
|
24
|
+
type="month"
|
|
25
|
+
title={formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAY)}
|
|
26
|
+
active={!!(selected && month === selected.getMonth() && viewYear === selected.getFullYear())}
|
|
27
|
+
disabled={isDisabled(month)}
|
|
28
|
+
today={viewYear === new Date().getFullYear() && month === new Date().getMonth()}
|
|
29
|
+
onClick={onSelect}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
39
32
|
const isDisabled = (month) => {
|
|
40
33
|
const date = new Date(viewYear, month);
|
|
41
34
|
return !!(
|
|
@@ -43,12 +36,6 @@ const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onS
|
|
|
43
36
|
(max && date > new Date(max.getFullYear(), max.getMonth()))
|
|
44
37
|
);
|
|
45
38
|
};
|
|
46
|
-
|
|
47
|
-
const autofocusMonth = (() => {
|
|
48
|
-
const months = [...new Array(ROWS * COLS)].map((_, index) => index);
|
|
49
|
-
return getFocusableTime(isSelected, isThisMonth, isDisabled, months);
|
|
50
|
-
})();
|
|
51
|
-
|
|
52
39
|
return (
|
|
53
40
|
<table className="table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0">
|
|
54
41
|
<thead className="sr-only">
|
|
@@ -82,39 +82,6 @@ describe('MonthCalendarTable', () => {
|
|
|
82
82
|
expect(component.find('.sr-only').text()).toBe('Enter date..');
|
|
83
83
|
});
|
|
84
84
|
|
|
85
|
-
it('sets autofocus to true when June is the selected month', () => {
|
|
86
|
-
component.setProps({ selectedDate: new Date(2018, 5, 1) });
|
|
87
|
-
expect(getTableLinkAt(5).prop('autofocus')).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('does not set autofocus to true when June is the selected month but not the right year', () => {
|
|
91
|
-
component.setProps({ selectedDate: new Date(2017, 5, 1) });
|
|
92
|
-
expect(getTableLinkAt(5).prop('autofocus')).toBe(false);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('sets autofocus to true when selected date is null and current month is visible', () => {
|
|
96
|
-
const today = new Date();
|
|
97
|
-
component.setProps({
|
|
98
|
-
selectedDate: null,
|
|
99
|
-
viewYear: today.getFullYear(),
|
|
100
|
-
viewMonth: today.getMonth(),
|
|
101
|
-
});
|
|
102
|
-
expect(getTableLink().find({ today: true }).prop('autofocus')).toBe(true);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('sets autofocus to true on the second month when the first month is disabled', () => {
|
|
106
|
-
component.setProps({
|
|
107
|
-
selectedDate: null,
|
|
108
|
-
viewYear: 2022,
|
|
109
|
-
min: new Date(2022, 1, 28),
|
|
110
|
-
viewMonth: 0,
|
|
111
|
-
isDisabled: (month) => month === 0,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
expect(getTableLinkAt(0).prop('autofocus')).toBe(false);
|
|
115
|
-
expect(getTableLinkAt(1).prop('autofocus')).toBe(true);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
85
|
const getTableLinkAt = (i) => component.find('[title="MonthName"]').at(i);
|
|
119
86
|
const getTableLink = () => component.find('[title="MonthName"]');
|
|
120
87
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import { PureComponent } from 'react';
|
|
3
|
+
import { injectIntl } from 'react-intl';
|
|
4
|
+
|
|
5
|
+
import messages from '../DateLookup.messages';
|
|
6
|
+
|
|
7
|
+
class TableLink extends PureComponent {
|
|
8
|
+
onClick = (event) => {
|
|
9
|
+
event.preventDefault();
|
|
10
|
+
if (!this.props.disabled) {
|
|
11
|
+
this.props.onClick(this.props.item);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
|
|
16
|
+
if (active) {
|
|
17
|
+
return `${longTitle || title}, ${formatMessage(messages.selected)} ${formatMessage(
|
|
18
|
+
messages[type],
|
|
19
|
+
)}`;
|
|
20
|
+
}
|
|
21
|
+
return longTitle || title;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
render() {
|
|
25
|
+
const {
|
|
26
|
+
item,
|
|
27
|
+
type,
|
|
28
|
+
title,
|
|
29
|
+
longTitle,
|
|
30
|
+
active,
|
|
31
|
+
disabled,
|
|
32
|
+
today,
|
|
33
|
+
intl: { formatMessage },
|
|
34
|
+
} = this.props;
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<button
|
|
38
|
+
type="button"
|
|
39
|
+
className={`tw-date-lookup-${type}-option ${active ? 'active' : ''} ${
|
|
40
|
+
today ? 'today' : ''
|
|
41
|
+
} np-text-body-default-bold`}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
aria-label={this.calculateAriaLabel(longTitle, title, active, type, formatMessage)}
|
|
44
|
+
aria-pressed={active}
|
|
45
|
+
onClick={this.onClick}
|
|
46
|
+
>
|
|
47
|
+
{title || item}
|
|
48
|
+
</button>
|
|
49
|
+
</>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
TableLink.propTypes = {
|
|
55
|
+
item: PropTypes.number.isRequired, // day (1-31), month (0-11) or year (2018 etc)
|
|
56
|
+
type: PropTypes.oneOf(['day', 'month', 'year']).isRequired,
|
|
57
|
+
title: PropTypes.string,
|
|
58
|
+
longTitle: PropTypes.string,
|
|
59
|
+
active: PropTypes.bool.isRequired,
|
|
60
|
+
disabled: PropTypes.bool.isRequired,
|
|
61
|
+
today: PropTypes.bool.isRequired,
|
|
62
|
+
onClick: PropTypes.func.isRequired,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
TableLink.defaultProps = {
|
|
66
|
+
title: null,
|
|
67
|
+
longTitle: null,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export default injectIntl(TableLink);
|
|
@@ -2,7 +2,6 @@ import { formatDate } from '@transferwise/formatting';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { useIntl } from 'react-intl';
|
|
4
4
|
|
|
5
|
-
import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
|
|
6
5
|
import TableLink from '../../tableLink';
|
|
7
6
|
|
|
8
7
|
const ROWS = 5;
|
|
@@ -12,38 +11,17 @@ const YEAR_ONLY_FORMAT = { year: 'numeric' };
|
|
|
12
11
|
const YearCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSelect }) => {
|
|
13
12
|
const { locale } = useIntl();
|
|
14
13
|
const startYear = viewYear - (viewYear % 20);
|
|
15
|
-
const getLink = (year) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const isSelected = (year) => {
|
|
31
|
-
return selectedDate && year === selectedDate.getFullYear();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const isThisYear = (year) => {
|
|
35
|
-
return year === new Date().getFullYear();
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const isDisabled = (year) => {
|
|
39
|
-
return !!((min && year < min.getFullYear()) || (max && year > max.getFullYear()));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const autofocusYear = (() => {
|
|
43
|
-
const years = [...new Array(ROWS * COLS)].map((_, index) => startYear + index);
|
|
44
|
-
return getFocusableTime(isSelected, isThisYear, isDisabled, years);
|
|
45
|
-
})();
|
|
46
|
-
|
|
14
|
+
const getLink = (year) => (
|
|
15
|
+
<TableLink
|
|
16
|
+
item={year}
|
|
17
|
+
type="year"
|
|
18
|
+
title={formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT)}
|
|
19
|
+
active={!!(selectedDate && year === selectedDate.getFullYear())}
|
|
20
|
+
disabled={!!((min && year < min.getFullYear()) || (max && year > max.getFullYear()))}
|
|
21
|
+
today={year === new Date().getFullYear()}
|
|
22
|
+
onClick={onSelect}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
47
25
|
return (
|
|
48
26
|
<table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
|
|
49
27
|
<thead className="sr-only">
|
|
@@ -90,32 +90,6 @@ describe('YearCalendarTable', () => {
|
|
|
90
90
|
expect(component.find('.sr-only').text()).toBe('Enter date..');
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
it('sets autofocus to true when 2002 is the selected year', () => {
|
|
94
|
-
component.setProps({ selectedDate: new Date(2002, 5, 1) });
|
|
95
|
-
expect(getTableLinkAt(2).prop('autofocus')).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('sets autofocus to true when selected year is null and current year is visible', () => {
|
|
99
|
-
const today = new Date();
|
|
100
|
-
component.setProps({
|
|
101
|
-
selectedDate: null,
|
|
102
|
-
viewYear: today.getFullYear(),
|
|
103
|
-
});
|
|
104
|
-
expect(getTableLink().find({ today: true }).prop('autofocus')).toBe(true);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('sets autofocus to true on the second year when the first year is disabled', () => {
|
|
108
|
-
component.setProps({
|
|
109
|
-
selectedDate: null,
|
|
110
|
-
viewYear: 2000,
|
|
111
|
-
min: new Date(2001, 1, 1),
|
|
112
|
-
isDisabled: (month) => month === 0,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(getTableLinkAt(0).prop('autofocus')).toBe(false);
|
|
116
|
-
expect(getTableLinkAt(1).prop('autofocus')).toBe(true);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
93
|
const getTableLinkAt = (i) => component.find('[type="year"]').at(i);
|
|
120
94
|
const getTableLink = () => component.find('[type="year"]');
|
|
121
95
|
});
|
package/src/header/Header.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.np-header{align-items:flex-end;border-bottom:1px solid #0000001a;border-bottom:1px solid var(--color-border-neutral);display:flex;justify-content:space-between;margin-bottom:8px;margin-bottom:var(--size-8);max-width:100%;padding:8px 0;padding:var(--size-8) 0}.np-header__title{color:#5d7079;color:var(--color-content-secondary)}.np-theme-personal .np-header{-moz-column-gap:24px;column-gap:24px;-moz-column-gap:var(--size-24);column-gap:var(--size-24)}.np-theme-personal .np-header__button{margin-inline:-16px;margin-inline:calc(var(--size-16)*-1);margin-bottom:-4px;margin-bottom:calc(var(--size-4)*-1)}
|
|
1
|
+
.np-header{align-items:flex-end;border-bottom:1px solid #0000001a;border-bottom:1px solid var(--color-border-neutral);display:flex;justify-content:space-between;margin-bottom:8px;margin-bottom:var(--size-8);max-width:100%;padding:8px 0;padding:var(--size-8) 0}.np-header__title{color:#5d7079;color:var(--color-content-secondary)}.np-theme-personal .np-header{-moz-column-gap:24px;column-gap:24px;-moz-column-gap:var(--size-24);column-gap:var(--size-24)}.np-theme-personal .np-header__button{margin-inline:-16px;margin-inline:calc(var(--size-16)*-1);margin-bottom:-4px;margin-bottom:calc(var(--size-4)*-1)}
|
package/src/header/Header.less
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
import { act, screen, within } from '@testing-library/react';
|
|
2
2
|
import userEvent, { specialChars } from '@testing-library/user-event';
|
|
3
3
|
|
|
4
|
-
import { render } from '../test-utils';
|
|
4
|
+
import { render, mockMatchMedia, mockResizeObserver } from '../test-utils';
|
|
5
5
|
|
|
6
6
|
import { SelectInput } from './SelectInput';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
value: jest.fn((query: string) => {
|
|
11
|
-
const matches = /^\(min-width: ([0-9]+)px\)$/.exec(query);
|
|
12
|
-
const minWidth = matches != null ? Number(matches[1]) : undefined;
|
|
13
|
-
return {
|
|
14
|
-
matches: minWidth != null ? window.innerWidth >= minWidth : false,
|
|
15
|
-
media: query,
|
|
16
|
-
onchange: null,
|
|
17
|
-
addListener: jest.fn(), // deprecated
|
|
18
|
-
removeListener: jest.fn(), // deprecated
|
|
19
|
-
addEventListener: jest.fn(),
|
|
20
|
-
removeEventListener: jest.fn(),
|
|
21
|
-
dispatchEvent: jest.fn(),
|
|
22
|
-
};
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
Object.defineProperty(window, 'ResizeObserver', {
|
|
27
|
-
writable: true,
|
|
28
|
-
value: jest.fn(() => ({
|
|
29
|
-
observe: jest.fn(),
|
|
30
|
-
unobserve: jest.fn(),
|
|
31
|
-
disconnect: jest.fn(),
|
|
32
|
-
})),
|
|
33
|
-
});
|
|
8
|
+
mockMatchMedia();
|
|
9
|
+
mockResizeObserver();
|
|
34
10
|
|
|
35
11
|
describe('SelectInput', () => {
|
|
36
12
|
it('renders placeholder', () => {
|