@transferwise/components 0.0.0-experimental-749d29d → 0.0.0-experimental-a26af76
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/dateLookup/DateLookup.js +165 -26
- package/build/dateLookup/DateLookup.js.map +1 -1
- package/build/{calendarInput/CalendarInput.messages.js → dateLookup/DateLookup.messages.js} +1 -1
- package/build/dateLookup/DateLookup.messages.js.map +1 -0
- package/build/{calendarInput/CalendarInput.messages.mjs → dateLookup/DateLookup.messages.mjs} +1 -1
- package/build/dateLookup/DateLookup.messages.mjs.map +1 -0
- package/build/dateLookup/DateLookup.mjs +166 -27
- package/build/dateLookup/DateLookup.mjs.map +1 -1
- package/build/{calendarInput → dateLookup}/dateHeader/DateHeader.js +4 -4
- package/build/dateLookup/dateHeader/DateHeader.js.map +1 -0
- package/build/{calendarInput → dateLookup}/dateHeader/DateHeader.mjs +1 -1
- package/build/dateLookup/dateHeader/DateHeader.mjs.map +1 -0
- package/build/{calendarInput → dateLookup}/dayCalendar/DayCalendar.js +2 -2
- package/build/dateLookup/dayCalendar/DayCalendar.js.map +1 -0
- package/build/{calendarInput → dateLookup}/dayCalendar/DayCalendar.mjs +1 -1
- package/build/dateLookup/dayCalendar/DayCalendar.mjs.map +1 -0
- package/build/dateLookup/dayCalendar/table/DayCalendarTable.js.map +1 -0
- package/build/dateLookup/dayCalendar/table/DayCalendarTable.mjs.map +1 -0
- package/build/dateLookup/getFocusableTime/getFocusableTime.js.map +1 -0
- package/build/dateLookup/getFocusableTime/getFocusableTime.mjs.map +1 -0
- package/build/dateLookup/getStartOfDay/getStartOfDay.js.map +1 -0
- package/build/dateLookup/getStartOfDay/getStartOfDay.mjs.map +1 -0
- package/build/{calendarInput → dateLookup}/monthCalendar/MonthCalendar.js +2 -2
- package/build/dateLookup/monthCalendar/MonthCalendar.js.map +1 -0
- package/build/{calendarInput → dateLookup}/monthCalendar/MonthCalendar.mjs +1 -1
- package/build/dateLookup/monthCalendar/MonthCalendar.mjs.map +1 -0
- package/build/dateLookup/monthCalendar/table/MonthCalendarTable.js.map +1 -0
- package/build/dateLookup/monthCalendar/table/MonthCalendarTable.mjs.map +1 -0
- package/build/{calendarInput → dateLookup}/tableLink/TableLink.js +2 -2
- package/build/dateLookup/tableLink/TableLink.js.map +1 -0
- package/build/{calendarInput → dateLookup}/tableLink/TableLink.mjs +1 -1
- package/build/dateLookup/tableLink/TableLink.mjs.map +1 -0
- package/build/{calendarInput → dateLookup}/yearCalendar/YearCalendar.js +2 -2
- package/build/dateLookup/yearCalendar/YearCalendar.js.map +1 -0
- package/build/{calendarInput → dateLookup}/yearCalendar/YearCalendar.mjs +1 -1
- package/build/dateLookup/yearCalendar/YearCalendar.mjs.map +1 -0
- package/build/dateLookup/yearCalendar/table/YearCalendarTable.js.map +1 -0
- package/build/dateLookup/yearCalendar/table/YearCalendarTable.mjs.map +1 -0
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build/index.mjs +0 -1
- package/build/index.mjs.map +1 -1
- package/build/main.css +603 -649
- package/build/sentimentSurface/SentimentSurface.js +9 -2
- package/build/sentimentSurface/SentimentSurface.js.map +1 -1
- package/build/sentimentSurface/SentimentSurface.mjs +9 -2
- package/build/sentimentSurface/SentimentSurface.mjs.map +1 -1
- package/build/styles/css/neptune.css +11 -11
- package/build/styles/dateLookup/DateLookup.css +90 -0
- package/build/styles/less/legacy-variables.less +1 -1
- package/build/styles/less/neptune-tokens.less +2 -2
- package/build/styles/main.css +603 -649
- package/build/styles/props/custom-media.css +1 -1
- package/build/styles/props/neptune-tokens.css +1 -1
- package/build/styles/sentimentSurface/SentimentSurface.css +325 -337
- package/build/styles/styles/less/neptune.css +11 -11
- package/build/types/dateLookup/DateLookup.d.ts +25 -2
- package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
- package/build/types/{calendarInput/CalendarInput.messages.d.ts → dateLookup/DateLookup.messages.d.ts} +1 -1
- package/build/types/dateLookup/DateLookup.messages.d.ts.map +1 -0
- package/build/types/dateLookup/dateHeader/DateHeader.d.ts.map +1 -0
- package/build/types/dateLookup/dateHeader/index.d.ts.map +1 -0
- package/build/types/dateLookup/dayCalendar/DayCalendar.d.ts.map +1 -0
- package/build/types/dateLookup/dayCalendar/index.d.ts.map +1 -0
- package/build/types/dateLookup/dayCalendar/table/DayCalendarTable.d.ts.map +1 -0
- package/build/types/dateLookup/dayCalendar/table/index.d.ts.map +1 -0
- package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts.map +1 -0
- package/build/types/dateLookup/getStartOfDay/getStartOfDay.d.ts.map +1 -0
- package/build/types/dateLookup/getStartOfDay/index.d.ts.map +1 -0
- package/build/types/dateLookup/monthCalendar/MonthCalendar.d.ts.map +1 -0
- package/build/types/dateLookup/monthCalendar/index.d.ts.map +1 -0
- package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -0
- package/build/types/dateLookup/monthCalendar/table/index.d.ts.map +1 -0
- package/build/types/dateLookup/tableLink/TableLink.d.ts.map +1 -0
- package/build/types/dateLookup/tableLink/index.d.ts.map +1 -0
- package/build/types/dateLookup/yearCalendar/YearCalendar.d.ts.map +1 -0
- package/build/types/dateLookup/yearCalendar/index.d.ts.map +1 -0
- package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts.map +1 -0
- package/build/types/dateLookup/yearCalendar/table/index.d.ts.map +1 -0
- package/build/types/index.d.ts +0 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/sentimentSurface/SentimentSurface.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/criticalBanner/CriticalCommsBanner.test.tsx +1 -1
- package/src/dateLookup/DateLookup.css +90 -0
- package/src/dateLookup/DateLookup.less +91 -0
- package/src/dateLookup/DateLookup.tsx +157 -30
- package/src/{calendarInput → dateLookup}/dateHeader/DateHeader.tsx +1 -1
- package/src/{calendarInput → dateLookup}/dayCalendar/DayCalendar.tsx +1 -1
- package/src/{calendarInput → dateLookup}/monthCalendar/MonthCalendar.tsx +1 -1
- package/src/{calendarInput → dateLookup}/tableLink/TableLink.tsx +1 -1
- package/src/{calendarInput → dateLookup}/yearCalendar/YearCalendar.tsx +1 -1
- package/src/index.ts +0 -2
- package/src/main.css +603 -649
- package/src/main.less +0 -1
- package/src/sentimentSurface/SentimentSurface.css +325 -337
- package/src/sentimentSurface/SentimentSurface.docs.mdx +2 -0
- package/src/sentimentSurface/SentimentSurface.less +2 -322
- package/src/sentimentSurface/SentimentSurface.story.tsx +4 -0
- package/src/sentimentSurface/SentimentSurface.test.story.tsx +1 -5
- package/src/sentimentSurface/SentimentSurface.test.tsx +84 -3
- package/src/sentimentSurface/SentimentSurface.tsx +10 -2
- package/src/styles/less/neptune.css +11 -11
- package/build/calendarInput/CalendarInput.js +0 -154
- package/build/calendarInput/CalendarInput.js.map +0 -1
- package/build/calendarInput/CalendarInput.messages.js.map +0 -1
- package/build/calendarInput/CalendarInput.messages.mjs.map +0 -1
- package/build/calendarInput/CalendarInput.mjs +0 -150
- package/build/calendarInput/CalendarInput.mjs.map +0 -1
- package/build/calendarInput/dateHeader/DateHeader.js.map +0 -1
- package/build/calendarInput/dateHeader/DateHeader.mjs.map +0 -1
- package/build/calendarInput/dayCalendar/DayCalendar.js.map +0 -1
- package/build/calendarInput/dayCalendar/DayCalendar.mjs.map +0 -1
- package/build/calendarInput/dayCalendar/table/DayCalendarTable.js.map +0 -1
- package/build/calendarInput/dayCalendar/table/DayCalendarTable.mjs.map +0 -1
- package/build/calendarInput/getFocusableTime/getFocusableTime.js.map +0 -1
- package/build/calendarInput/getFocusableTime/getFocusableTime.mjs.map +0 -1
- package/build/calendarInput/getStartOfDay/getStartOfDay.js.map +0 -1
- package/build/calendarInput/getStartOfDay/getStartOfDay.mjs.map +0 -1
- package/build/calendarInput/monthCalendar/MonthCalendar.js.map +0 -1
- package/build/calendarInput/monthCalendar/MonthCalendar.mjs.map +0 -1
- package/build/calendarInput/monthCalendar/table/MonthCalendarTable.js.map +0 -1
- package/build/calendarInput/monthCalendar/table/MonthCalendarTable.mjs.map +0 -1
- package/build/calendarInput/tableLink/TableLink.js.map +0 -1
- package/build/calendarInput/tableLink/TableLink.mjs.map +0 -1
- package/build/calendarInput/yearCalendar/YearCalendar.js.map +0 -1
- package/build/calendarInput/yearCalendar/YearCalendar.mjs.map +0 -1
- package/build/calendarInput/yearCalendar/table/YearCalendarTable.js.map +0 -1
- package/build/calendarInput/yearCalendar/table/YearCalendarTable.mjs.map +0 -1
- package/build/styles/calendarInput/CalendarInput.css +0 -83
- package/build/types/calendarInput/CalendarInput.d.ts +0 -12
- package/build/types/calendarInput/CalendarInput.d.ts.map +0 -1
- package/build/types/calendarInput/CalendarInput.messages.d.ts.map +0 -1
- package/build/types/calendarInput/dateHeader/DateHeader.d.ts.map +0 -1
- package/build/types/calendarInput/dateHeader/index.d.ts.map +0 -1
- package/build/types/calendarInput/dayCalendar/DayCalendar.d.ts.map +0 -1
- package/build/types/calendarInput/dayCalendar/index.d.ts.map +0 -1
- package/build/types/calendarInput/dayCalendar/table/DayCalendarTable.d.ts.map +0 -1
- package/build/types/calendarInput/dayCalendar/table/index.d.ts.map +0 -1
- package/build/types/calendarInput/getFocusableTime/getFocusableTime.d.ts.map +0 -1
- package/build/types/calendarInput/getStartOfDay/getStartOfDay.d.ts.map +0 -1
- package/build/types/calendarInput/getStartOfDay/index.d.ts.map +0 -1
- package/build/types/calendarInput/index.d.ts +0 -3
- package/build/types/calendarInput/index.d.ts.map +0 -1
- package/build/types/calendarInput/monthCalendar/MonthCalendar.d.ts.map +0 -1
- package/build/types/calendarInput/monthCalendar/index.d.ts.map +0 -1
- package/build/types/calendarInput/monthCalendar/table/MonthCalendarTable.d.ts.map +0 -1
- package/build/types/calendarInput/monthCalendar/table/index.d.ts.map +0 -1
- package/build/types/calendarInput/tableLink/TableLink.d.ts.map +0 -1
- package/build/types/calendarInput/tableLink/index.d.ts.map +0 -1
- package/build/types/calendarInput/yearCalendar/YearCalendar.d.ts.map +0 -1
- package/build/types/calendarInput/yearCalendar/index.d.ts.map +0 -1
- package/build/types/calendarInput/yearCalendar/table/YearCalendarTable.d.ts.map +0 -1
- package/build/types/calendarInput/yearCalendar/table/index.d.ts.map +0 -1
- package/src/calendarInput/CalendarInput.css +0 -83
- package/src/calendarInput/CalendarInput.less +0 -79
- package/src/calendarInput/CalendarInput.story.tsx +0 -64
- package/src/calendarInput/CalendarInput.tsx +0 -163
- package/src/calendarInput/index.ts +0 -2
- /package/build/{calendarInput → dateLookup}/dayCalendar/table/DayCalendarTable.js +0 -0
- /package/build/{calendarInput → dateLookup}/dayCalendar/table/DayCalendarTable.mjs +0 -0
- /package/build/{calendarInput → dateLookup}/getFocusableTime/getFocusableTime.js +0 -0
- /package/build/{calendarInput → dateLookup}/getFocusableTime/getFocusableTime.mjs +0 -0
- /package/build/{calendarInput → dateLookup}/getStartOfDay/getStartOfDay.js +0 -0
- /package/build/{calendarInput → dateLookup}/getStartOfDay/getStartOfDay.mjs +0 -0
- /package/build/{calendarInput → dateLookup}/monthCalendar/table/MonthCalendarTable.js +0 -0
- /package/build/{calendarInput → dateLookup}/monthCalendar/table/MonthCalendarTable.mjs +0 -0
- /package/build/{calendarInput → dateLookup}/yearCalendar/table/YearCalendarTable.js +0 -0
- /package/build/{calendarInput → dateLookup}/yearCalendar/table/YearCalendarTable.mjs +0 -0
- /package/build/types/{calendarInput → dateLookup}/dateHeader/DateHeader.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/dateHeader/index.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/dayCalendar/DayCalendar.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/dayCalendar/index.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/dayCalendar/table/DayCalendarTable.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/dayCalendar/table/index.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/getFocusableTime/getFocusableTime.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/getStartOfDay/getStartOfDay.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/getStartOfDay/index.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/monthCalendar/MonthCalendar.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/monthCalendar/index.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/monthCalendar/table/MonthCalendarTable.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/monthCalendar/table/index.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/tableLink/TableLink.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/tableLink/index.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/yearCalendar/YearCalendar.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/yearCalendar/index.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/yearCalendar/table/YearCalendarTable.d.ts +0 -0
- /package/build/types/{calendarInput → dateLookup}/yearCalendar/table/index.d.ts +0 -0
- /package/src/{calendarInput/CalendarInput.messages.ts → dateLookup/DateLookup.messages.ts} +0 -0
- /package/src/{calendarInput → dateLookup}/dateHeader/index.ts +0 -0
- /package/src/{calendarInput → dateLookup}/dayCalendar/index.ts +0 -0
- /package/src/{calendarInput → dateLookup}/dayCalendar/table/DayCalendarTable.tsx +0 -0
- /package/src/{calendarInput → dateLookup}/dayCalendar/table/index.ts +0 -0
- /package/src/{calendarInput → dateLookup}/getFocusableTime/getFocusable.test.ts +0 -0
- /package/src/{calendarInput → dateLookup}/getFocusableTime/getFocusableTime.tsx +0 -0
- /package/src/{calendarInput → dateLookup}/getStartOfDay/getStartOfDay.test.js +0 -0
- /package/src/{calendarInput → dateLookup}/getStartOfDay/getStartOfDay.tsx +0 -0
- /package/src/{calendarInput → dateLookup}/getStartOfDay/index.ts +0 -0
- /package/src/{calendarInput → dateLookup}/monthCalendar/index.ts +0 -0
- /package/src/{calendarInput → dateLookup}/monthCalendar/table/MonthCalendarTable.tsx +0 -0
- /package/src/{calendarInput → dateLookup}/monthCalendar/table/index.ts +0 -0
- /package/src/{calendarInput → dateLookup}/tableLink/index.ts +0 -0
- /package/src/{calendarInput → dateLookup}/yearCalendar/index.ts +0 -0
- /package/src/{calendarInput → dateLookup}/yearCalendar/table/YearCalendarTable.tsx +0 -0
- /package/src/{calendarInput → dateLookup}/yearCalendar/table/index.ts +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { clsx } from 'clsx';
|
|
2
2
|
import { createRef, PureComponent, KeyboardEvent } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import { Breakpoint } from '@transferwise/neptune-tokens';
|
|
4
|
+
|
|
4
5
|
import {
|
|
5
6
|
Size,
|
|
6
7
|
MonthFormat,
|
|
@@ -9,10 +10,15 @@ import {
|
|
|
9
10
|
type SizeMedium,
|
|
10
11
|
type SizeLarge,
|
|
11
12
|
} from '../common';
|
|
13
|
+
import { isWithinRange, moveToWithinRange, returnDateView } from '../common/dateUtils';
|
|
12
14
|
import ResponsivePanel from '../common/responsivePanel';
|
|
13
15
|
import { WithInputAttributesProps, withInputAttributes } from '../inputs/contexts';
|
|
14
16
|
import { OverlayIdProvider } from '../provider/overlay/OverlayIdProvider';
|
|
15
17
|
import DateTrigger from './dateTrigger';
|
|
18
|
+
import DayCalendar from './dayCalendar';
|
|
19
|
+
import { getStartOfDay } from './getStartOfDay';
|
|
20
|
+
import MonthCalendar from './monthCalendar';
|
|
21
|
+
import YearCalendar from './yearCalendar';
|
|
16
22
|
|
|
17
23
|
export interface DateLookupProps {
|
|
18
24
|
id?: string;
|
|
@@ -34,8 +40,15 @@ export interface DateLookupProps {
|
|
|
34
40
|
type DateLookupPropsWithInputAttributes = DateLookupProps & Partial<WithInputAttributesProps>;
|
|
35
41
|
|
|
36
42
|
interface DateLookupState {
|
|
43
|
+
selectedDate: Date | null;
|
|
37
44
|
originalDate: Date | null;
|
|
45
|
+
min: Date | null;
|
|
46
|
+
max: Date | null;
|
|
47
|
+
viewMonth: number;
|
|
48
|
+
viewYear: number;
|
|
38
49
|
open: boolean;
|
|
50
|
+
mode: 'day' | 'month' | 'year';
|
|
51
|
+
isMobile: boolean;
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
class DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateLookupState> {
|
|
@@ -55,29 +68,64 @@ class DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateL
|
|
|
55
68
|
} satisfies Partial<DateLookupPropsWithInputAttributes>;
|
|
56
69
|
|
|
57
70
|
element = createRef<HTMLDivElement>();
|
|
71
|
+
dropdown = createRef<HTMLDivElement>();
|
|
58
72
|
|
|
59
73
|
constructor(props: DateLookup['props']) {
|
|
60
74
|
super(props);
|
|
75
|
+
const dateView = returnDateView(props.value, props.min, props.max);
|
|
61
76
|
this.state = {
|
|
77
|
+
selectedDate: getStartOfDay(props.value),
|
|
62
78
|
originalDate: null,
|
|
79
|
+
min: getStartOfDay(props.min),
|
|
80
|
+
max: getStartOfDay(props.max),
|
|
81
|
+
viewMonth: dateView.getMonth(),
|
|
82
|
+
viewYear: dateView.getFullYear(),
|
|
63
83
|
open: false,
|
|
84
|
+
mode: 'day',
|
|
85
|
+
isMobile: false,
|
|
64
86
|
};
|
|
65
87
|
}
|
|
66
88
|
|
|
89
|
+
static getDerivedStateFromProps(props: DateLookup['props'], state: DateLookupState) {
|
|
90
|
+
const propsSelected = getStartOfDay(props.value);
|
|
91
|
+
const propsMin = getStartOfDay(props.min);
|
|
92
|
+
const propsMax = getStartOfDay(props.max);
|
|
93
|
+
const hasSelectedChanged = state.selectedDate?.getTime() !== propsSelected?.getTime();
|
|
94
|
+
const hasMinChanged = state.min?.getTime() !== propsMin?.getTime();
|
|
95
|
+
const hasMaxChanged = state.max?.getTime() !== propsMax?.getTime();
|
|
96
|
+
if (hasSelectedChanged || hasMinChanged || hasMaxChanged) {
|
|
97
|
+
const selectedDate = hasSelectedChanged ? propsSelected : state.selectedDate;
|
|
98
|
+
const min = hasMinChanged ? propsMin : state.min;
|
|
99
|
+
const max = hasMaxChanged ? propsMax : state.max;
|
|
100
|
+
if (selectedDate && !isWithinRange(selectedDate, min, max)) {
|
|
101
|
+
props.onChange(moveToWithinRange(selectedDate, min, max));
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
const viewDateThatIsWithinRange: Date = returnDateView(selectedDate, min, max);
|
|
105
|
+
const viewMonth = viewDateThatIsWithinRange.getMonth();
|
|
106
|
+
const viewYear = viewDateThatIsWithinRange.getFullYear();
|
|
107
|
+
return { selectedDate, min, max, viewMonth, viewYear };
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
67
112
|
componentDidUpdate(previousProps: DateLookupPropsWithInputAttributes) {
|
|
68
113
|
if (this.props.value?.getTime() !== previousProps.value?.getTime() && this.state.open) {
|
|
69
114
|
this.focusOn('.active');
|
|
70
115
|
}
|
|
116
|
+
const mediaQuery = window.matchMedia(`(max-width: ${Breakpoint.SMALL}px)`);
|
|
117
|
+
this.setState({ isMobile: mediaQuery.matches });
|
|
71
118
|
}
|
|
72
119
|
|
|
73
120
|
componentWillUnmount() {
|
|
121
|
+
// Prevents memory leak by cleaning state.
|
|
74
122
|
this.setState = () => {};
|
|
75
123
|
}
|
|
76
124
|
|
|
77
125
|
open = () => {
|
|
78
126
|
const { onFocus } = this.props;
|
|
79
127
|
|
|
80
|
-
this.setState({ open: true });
|
|
128
|
+
this.setState({ open: true, mode: 'day' });
|
|
81
129
|
if (onFocus) {
|
|
82
130
|
onFocus();
|
|
83
131
|
}
|
|
@@ -103,13 +151,36 @@ class DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateL
|
|
|
103
151
|
const { open, originalDate } = this.state;
|
|
104
152
|
switch (event.key) {
|
|
105
153
|
case 'ArrowLeft':
|
|
154
|
+
if (open) {
|
|
155
|
+
this.adjustDate(-1, -1, -1);
|
|
156
|
+
} else {
|
|
157
|
+
this.open();
|
|
158
|
+
}
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
break;
|
|
106
161
|
case 'ArrowUp':
|
|
162
|
+
if (open) {
|
|
163
|
+
this.adjustDate(-7, -4, -4);
|
|
164
|
+
} else {
|
|
165
|
+
this.open();
|
|
166
|
+
}
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
break;
|
|
107
169
|
case 'ArrowRight':
|
|
170
|
+
if (open) {
|
|
171
|
+
this.adjustDate(1, 1, 1);
|
|
172
|
+
} else {
|
|
173
|
+
this.open();
|
|
174
|
+
}
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
break;
|
|
108
177
|
case 'ArrowDown':
|
|
109
|
-
if (
|
|
178
|
+
if (open) {
|
|
179
|
+
this.adjustDate(7, 4, 4);
|
|
180
|
+
} else {
|
|
110
181
|
this.open();
|
|
111
|
-
event.preventDefault();
|
|
112
182
|
}
|
|
183
|
+
event.preventDefault();
|
|
113
184
|
break;
|
|
114
185
|
case 'Escape':
|
|
115
186
|
if (originalDate !== null) {
|
|
@@ -123,6 +194,27 @@ class DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateL
|
|
|
123
194
|
}
|
|
124
195
|
};
|
|
125
196
|
|
|
197
|
+
adjustDate = (daysToAdd: number, monthsToAdd: number, yearsToAdd: number) => {
|
|
198
|
+
const { selectedDate, min, max, mode, originalDate } = this.state;
|
|
199
|
+
if (originalDate === null) {
|
|
200
|
+
this.setState({ originalDate: selectedDate });
|
|
201
|
+
}
|
|
202
|
+
let date: Date | null;
|
|
203
|
+
if (selectedDate) {
|
|
204
|
+
date = new Date(
|
|
205
|
+
mode === 'year' ? selectedDate.getFullYear() + yearsToAdd : selectedDate.getFullYear(),
|
|
206
|
+
mode === 'month' ? selectedDate.getMonth() + monthsToAdd : selectedDate.getMonth(),
|
|
207
|
+
mode === 'day' ? selectedDate.getDate() + daysToAdd : selectedDate.getDate(),
|
|
208
|
+
);
|
|
209
|
+
} else {
|
|
210
|
+
date = getStartOfDay(new Date());
|
|
211
|
+
}
|
|
212
|
+
date &&= moveToWithinRange(date, min, max);
|
|
213
|
+
if (date?.getTime() !== selectedDate?.getTime()) {
|
|
214
|
+
this.props.onChange(date);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
126
218
|
focusOn = (preferredElement: string, fallbackElement?: string) => {
|
|
127
219
|
const element = this.element.current?.querySelector(preferredElement) as HTMLElement | null;
|
|
128
220
|
if (element) {
|
|
@@ -132,36 +224,71 @@ class DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateL
|
|
|
132
224
|
}
|
|
133
225
|
};
|
|
134
226
|
|
|
135
|
-
|
|
136
|
-
this.setState(
|
|
137
|
-
(
|
|
138
|
-
|
|
139
|
-
return { originalDate };
|
|
140
|
-
},
|
|
141
|
-
() => {
|
|
142
|
-
this.props.onChange(date);
|
|
143
|
-
},
|
|
144
|
-
);
|
|
227
|
+
switchMode = (mode: 'day' | 'month' | 'year') => {
|
|
228
|
+
this.setState({ mode }, () => {
|
|
229
|
+
this.focusOn('.active', '.today');
|
|
230
|
+
});
|
|
145
231
|
};
|
|
146
232
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
233
|
+
switchToDays = () => this.switchMode('day');
|
|
234
|
+
|
|
235
|
+
switchToMonths = () => this.switchMode('month');
|
|
236
|
+
|
|
237
|
+
switchToYears = () => this.switchMode('year');
|
|
238
|
+
|
|
239
|
+
handleSelectedDateUpdate = (selectedDate: Date) => {
|
|
240
|
+
this.setState({ selectedDate }, () => {
|
|
241
|
+
this.props.onChange(selectedDate);
|
|
242
|
+
this.close();
|
|
243
|
+
this.focusOn('.btn');
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
handleViewDateUpdate = ({ month = this.state.viewMonth, year = this.state.viewYear }) => {
|
|
248
|
+
this.setState({ viewMonth: month, viewYear: year });
|
|
151
249
|
};
|
|
152
250
|
|
|
153
251
|
getCalendar = () => {
|
|
154
|
-
const {
|
|
252
|
+
const { selectedDate, min, max, viewMonth, viewYear, mode, isMobile } = this.state;
|
|
253
|
+
const { placeholder, monthFormat } = this.props;
|
|
155
254
|
return (
|
|
156
|
-
<div className=
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
255
|
+
<div className={clsx({ 'p-a-1': !isMobile })}>
|
|
256
|
+
{mode === 'day' && (
|
|
257
|
+
<DayCalendar
|
|
258
|
+
selectedDate={selectedDate}
|
|
259
|
+
min={min}
|
|
260
|
+
max={max}
|
|
261
|
+
viewMonth={viewMonth}
|
|
262
|
+
viewYear={viewYear}
|
|
263
|
+
monthFormat={monthFormat}
|
|
264
|
+
onSelect={this.handleSelectedDateUpdate}
|
|
265
|
+
onLabelClick={this.switchToYears}
|
|
266
|
+
onViewDateUpdate={this.handleViewDateUpdate}
|
|
267
|
+
/>
|
|
268
|
+
)}
|
|
269
|
+
{mode === 'month' && (
|
|
270
|
+
<MonthCalendar
|
|
271
|
+
selectedDate={selectedDate}
|
|
272
|
+
min={min}
|
|
273
|
+
max={max}
|
|
274
|
+
viewYear={viewYear}
|
|
275
|
+
placeholder={placeholder}
|
|
276
|
+
onSelect={this.switchToDays}
|
|
277
|
+
onLabelClick={this.switchToYears}
|
|
278
|
+
onViewDateUpdate={this.handleViewDateUpdate}
|
|
279
|
+
/>
|
|
280
|
+
)}
|
|
281
|
+
{mode === 'year' && (
|
|
282
|
+
<YearCalendar
|
|
283
|
+
selectedDate={selectedDate}
|
|
284
|
+
min={min}
|
|
285
|
+
max={max}
|
|
286
|
+
viewYear={viewYear}
|
|
287
|
+
placeholder={placeholder}
|
|
288
|
+
onSelect={this.switchToMonths}
|
|
289
|
+
onViewDateUpdate={this.handleViewDateUpdate}
|
|
290
|
+
/>
|
|
291
|
+
)}
|
|
165
292
|
</div>
|
|
166
293
|
);
|
|
167
294
|
};
|
|
@@ -172,7 +299,7 @@ class DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateL
|
|
|
172
299
|
};
|
|
173
300
|
|
|
174
301
|
render() {
|
|
175
|
-
const { open } = this.state;
|
|
302
|
+
const { selectedDate, open } = this.state;
|
|
176
303
|
|
|
177
304
|
const {
|
|
178
305
|
inputAttributes,
|
|
@@ -202,7 +329,7 @@ class DateLookup extends PureComponent<DateLookupPropsWithInputAttributes, DateL
|
|
|
202
329
|
<DateTrigger
|
|
203
330
|
id={id}
|
|
204
331
|
ariaLabelledBy={ariaLabelledBy}
|
|
205
|
-
selectedDate={
|
|
332
|
+
selectedDate={selectedDate}
|
|
206
333
|
size={size}
|
|
207
334
|
placeholder={placeholder}
|
|
208
335
|
label={label}
|
|
@@ -4,7 +4,7 @@ import { useIntl } from 'react-intl';
|
|
|
4
4
|
import { Typography } from '../../common';
|
|
5
5
|
import { useLayout } from '../../common/hooks';
|
|
6
6
|
import Title from '../../title';
|
|
7
|
-
import messages from '../
|
|
7
|
+
import messages from '../DateLookup.messages';
|
|
8
8
|
import Button from '../../button/Button';
|
|
9
9
|
import { ChevronDown, ChevronLeft, ChevronRight } from '@transferwise/icons';
|
|
10
10
|
import IconButton from '../../iconButton';
|
|
@@ -3,7 +3,7 @@ import { PureComponent } from 'react';
|
|
|
3
3
|
import { injectIntl, WrappedComponentProps } from 'react-intl';
|
|
4
4
|
|
|
5
5
|
import { MonthFormat } from '../../common';
|
|
6
|
-
import messages from '../
|
|
6
|
+
import messages from '../DateLookup.messages';
|
|
7
7
|
import DateHeader from '../dateHeader';
|
|
8
8
|
|
|
9
9
|
import DayCalendarTable from './table';
|
|
@@ -2,7 +2,7 @@ import { formatDate } from '@transferwise/formatting';
|
|
|
2
2
|
import { PureComponent } from 'react';
|
|
3
3
|
import { injectIntl, WrappedComponentProps } from 'react-intl';
|
|
4
4
|
|
|
5
|
-
import messages from '../
|
|
5
|
+
import messages from '../DateLookup.messages';
|
|
6
6
|
import DateHeader from '../dateHeader';
|
|
7
7
|
|
|
8
8
|
import MonthCalendarTable from './table';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PureComponent } from 'react';
|
|
2
2
|
import { injectIntl, WrappedComponentProps } from 'react-intl';
|
|
3
3
|
|
|
4
|
-
import messages from '../
|
|
4
|
+
import messages from '../DateLookup.messages';
|
|
5
5
|
import DateHeader from '../dateHeader';
|
|
6
6
|
|
|
7
7
|
import YearCalendarTable from './table';
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,6 @@ export type {
|
|
|
29
29
|
export type { BottomSheetProps } from './common/bottomSheet';
|
|
30
30
|
export type { DateInputProps } from './dateInput';
|
|
31
31
|
export type { DateLookupProps } from './dateLookup';
|
|
32
|
-
export type { CalendarInputProps } from './calendarInput';
|
|
33
32
|
export type { DecisionProps } from './decision/Decision';
|
|
34
33
|
export type { DefinitionListProps, DefinitionListDefinition } from './definitionList';
|
|
35
34
|
export type { DimmerProps } from './dimmer';
|
|
@@ -164,7 +163,6 @@ export { default as CriticalCommsBanner } from './criticalBanner';
|
|
|
164
163
|
export type { CriticalCommsBannerProps } from './criticalBanner';
|
|
165
164
|
export { default as DateInput } from './dateInput';
|
|
166
165
|
export { default as DateLookup } from './dateLookup';
|
|
167
|
-
export { default as CalendarInput } from './calendarInput';
|
|
168
166
|
export { default as Decision } from './decision';
|
|
169
167
|
export { default as DefinitionList } from './definitionList';
|
|
170
168
|
export { default as Dimmer } from './dimmer';
|