@transferwise/components 46.26.2 → 46.28.0
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/i18n/th.json +2 -2
- package/build/i18n/zh-CN.json +5 -5
- package/build/index.js +410 -645
- package/build/index.js.map +1 -1
- package/build/index.mjs +411 -646
- package/build/index.mjs.map +1 -1
- package/build/logo/svg/flag-platform-white.svg +1 -0
- package/build/logo/svg/flag-platform.svg +1 -0
- package/build/logo/svg/logo-platform-white.svg +1 -0
- package/build/logo/svg/logo-platform.svg +1 -0
- package/build/main.css +0 -16
- package/build/styles/logo/Logo.css +0 -16
- package/build/styles/main.css +0 -16
- package/build/types/alert/Alert.d.ts +47 -58
- package/build/types/alert/Alert.d.ts.map +1 -1
- package/build/types/alert/index.d.ts +2 -1
- package/build/types/alert/index.d.ts.map +1 -1
- package/build/types/button/Button.d.ts +7 -9
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts +1 -1
- package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts.map +1 -1
- package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts +1 -1
- package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts.map +1 -1
- package/build/types/common/propsValues/sentiment.d.ts +0 -1
- package/build/types/common/propsValues/sentiment.d.ts.map +1 -1
- package/build/types/dateLookup/DateLookup.d.ts +75 -28
- package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
- package/build/types/dateLookup/DateLookup.messages.d.ts +42 -63
- package/build/types/dateLookup/DateLookup.messages.d.ts.map +1 -1
- package/build/types/dateLookup/dateHeader/DateHeader.d.ts +9 -22
- package/build/types/dateLookup/dateHeader/DateHeader.d.ts.map +1 -1
- package/build/types/dateLookup/dateHeader/index.d.ts +1 -1
- package/build/types/dateLookup/dateHeader/index.d.ts.map +1 -1
- package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts +13 -31
- package/build/types/dateLookup/dateTrigger/DateTrigger.d.ts.map +1 -1
- package/build/types/dateLookup/dateTrigger/index.d.ts +1 -1
- package/build/types/dateLookup/dateTrigger/index.d.ts.map +1 -1
- package/build/types/dateLookup/dayCalendar/DayCalendar.d.ts +19 -2
- package/build/types/dateLookup/dayCalendar/DayCalendar.d.ts.map +1 -1
- package/build/types/dateLookup/dayCalendar/index.d.ts +1 -1
- package/build/types/dateLookup/dayCalendar/index.d.ts.map +1 -1
- package/build/types/dateLookup/dayCalendar/table/DayCalendarTable.d.ts +12 -2
- package/build/types/dateLookup/dayCalendar/table/DayCalendarTable.d.ts.map +1 -1
- package/build/types/dateLookup/dayCalendar/table/index.d.ts +1 -1
- package/build/types/dateLookup/dayCalendar/table/index.d.ts.map +1 -1
- package/build/types/dateLookup/getStartOfDay/getStartOfDay.d.ts +1 -1
- package/build/types/dateLookup/getStartOfDay/getStartOfDay.d.ts.map +1 -1
- package/build/types/dateLookup/getStartOfDay/index.d.ts +1 -1
- package/build/types/dateLookup/getStartOfDay/index.d.ts.map +1 -1
- package/build/types/dateLookup/index.d.ts +2 -1
- package/build/types/dateLookup/index.d.ts.map +1 -1
- package/build/types/dateLookup/monthCalendar/MonthCalendar.d.ts +17 -2
- package/build/types/dateLookup/monthCalendar/MonthCalendar.d.ts.map +1 -1
- package/build/types/dateLookup/monthCalendar/index.d.ts +1 -1
- package/build/types/dateLookup/monthCalendar/index.d.ts.map +1 -1
- package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts +10 -26
- package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -1
- package/build/types/dateLookup/monthCalendar/table/index.d.ts +1 -1
- package/build/types/dateLookup/monthCalendar/table/index.d.ts.map +1 -1
- package/build/types/dateLookup/yearCalendar/YearCalendar.d.ts +15 -2
- package/build/types/dateLookup/yearCalendar/YearCalendar.d.ts.map +1 -1
- package/build/types/dateLookup/yearCalendar/index.d.ts +1 -1
- package/build/types/dateLookup/yearCalendar/index.d.ts.map +1 -1
- package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts +10 -26
- package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts.map +1 -1
- package/build/types/dateLookup/yearCalendar/table/index.d.ts +1 -1
- package/build/types/dateLookup/yearCalendar/table/index.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inlineAlert/InlineAlert.d.ts +2 -4
- package/build/types/inlineAlert/InlineAlert.d.ts.map +1 -1
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/inputs/_BottomSheet.d.ts.map +1 -1
- package/build/types/inputs/_Popover.d.ts.map +1 -1
- package/build/types/instructionsList/InstructionsList.d.ts +1 -1
- package/build/types/instructionsList/InstructionsList.d.ts.map +1 -1
- package/build/types/logo/Logo.d.ts +1 -1
- package/build/types/logo/Logo.d.ts.map +1 -1
- package/build/types/logo/logoTypes.d.ts +2 -1
- package/build/types/logo/logoTypes.d.ts.map +1 -1
- package/build/types/markdown/Markdown.d.ts +1 -0
- package/build/types/markdown/Markdown.d.ts.map +1 -1
- package/build/types/statusIcon/StatusIcon.d.ts +1 -1
- package/build/types/statusIcon/StatusIcon.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/alert/{Alert.spec.js → Alert.spec.tsx} +43 -40
- package/src/alert/Alert.story.tsx +1 -2
- package/src/alert/Alert.tsx +218 -0
- package/src/alert/index.ts +2 -0
- package/src/button/Button.tsx +6 -10
- package/src/common/dateUtils/isWithinRange/isWithinRange.spec.ts +21 -0
- package/src/common/dateUtils/isWithinRange/isWithinRange.ts +2 -2
- package/src/common/dateUtils/moveToWithinRange/moveToWithinRange.ts +8 -4
- package/src/common/propsValues/sentiment.ts +0 -10
- package/src/dateLookup/DateLookup.state.spec.js +7 -0
- package/src/dateLookup/{DateLookup.story.js → DateLookup.story.tsx} +13 -14
- package/src/dateLookup/DateLookup.tests.story.tsx +70 -0
- package/src/dateLookup/{DateLookup.js → DateLookup.tsx} +115 -81
- package/src/dateLookup/dateHeader/{DateHeader.js → DateHeader.tsx} +15 -15
- package/src/dateLookup/dateTrigger/DateTrigger.spec.js +0 -22
- package/src/dateLookup/dateTrigger/{DateTrigger.js → DateTrigger.tsx} +15 -32
- package/src/dateLookup/dayCalendar/{DayCalendar.js → DayCalendar.tsx} +14 -21
- package/src/dateLookup/dayCalendar/table/{DayCalendarTable.js → DayCalendarTable.tsx} +26 -37
- package/src/dateLookup/getStartOfDay/{getStartOfDay.js → getStartOfDay.tsx} +1 -1
- package/src/dateLookup/index.ts +2 -0
- package/src/dateLookup/monthCalendar/{MonthCalendar.js → MonthCalendar.tsx} +19 -22
- package/src/dateLookup/monthCalendar/table/{MonthCalendarTable.js → MonthCalendarTable.tsx} +31 -30
- package/src/dateLookup/yearCalendar/{YearCalendar.js → YearCalendar.tsx} +18 -21
- package/src/dateLookup/yearCalendar/table/{YearCalendarTable.js → YearCalendarTable.tsx} +26 -28
- package/src/i18n/th.json +2 -2
- package/src/i18n/zh-CN.json +5 -5
- package/src/index.ts +2 -1
- package/src/inlineAlert/InlineAlert.spec.tsx +0 -7
- package/src/inlineAlert/InlineAlert.tsx +19 -47
- package/src/inputs/InputGroup.tsx +3 -3
- package/src/inputs/SelectInput.tsx +1 -0
- package/src/inputs/_BottomSheet.tsx +44 -54
- package/src/inputs/_Popover.tsx +20 -23
- package/src/instructionsList/InstructionsList.spec.tsx +5 -0
- package/src/instructionsList/InstructionsList.story.tsx +1 -0
- package/src/instructionsList/InstructionsList.tsx +3 -2
- package/src/logo/Logo.css +0 -16
- package/src/logo/Logo.js +27 -5
- package/src/logo/Logo.less +0 -16
- package/src/logo/Logo.spec.js +15 -1
- package/src/logo/__snapshots__/Logo.spec.js.snap +45 -71
- package/src/logo/logoTypes.ts +1 -0
- package/src/logo/svg/flag-platform-white.svg +1 -0
- package/src/logo/svg/flag-platform.svg +1 -0
- package/src/logo/svg/logo-platform-white.svg +1 -0
- package/src/logo/svg/logo-platform.svg +1 -0
- package/src/main.css +0 -16
- package/src/markdown/Markdown.spec.tsx +16 -0
- package/src/markdown/Markdown.tsx +6 -1
- package/src/statusIcon/StatusIcon.tsx +14 -14
- package/build/types/alert/withArrow/alertArrowPositions.d.ts +0 -9
- package/build/types/alert/withArrow/alertArrowPositions.d.ts.map +0 -1
- package/build/types/alert/withArrow/index.d.ts +0 -3
- package/build/types/alert/withArrow/index.d.ts.map +0 -1
- package/build/types/alert/withArrow/withArrow.d.ts +0 -11
- package/build/types/alert/withArrow/withArrow.d.ts.map +0 -1
- package/src/alert/Alert.js +0 -196
- package/src/alert/index.js +0 -1
- package/src/alert/withArrow/alertArrowPositions.ts +0 -9
- package/src/alert/withArrow/index.js +0 -2
- package/src/alert/withArrow/withArrow.js +0 -50
- package/src/alert/withArrow/withArrow.spec.js +0 -51
- package/src/dateLookup/index.js +0 -1
- /package/src/dateLookup/{DateLookup.messages.js → DateLookup.messages.ts} +0 -0
- /package/src/dateLookup/dateHeader/{index.js → index.ts} +0 -0
- /package/src/dateLookup/dateTrigger/{index.js → index.ts} +0 -0
- /package/src/dateLookup/dayCalendar/{index.js → index.ts} +0 -0
- /package/src/dateLookup/dayCalendar/table/{index.js → index.ts} +0 -0
- /package/src/dateLookup/getStartOfDay/{index.js → index.ts} +0 -0
- /package/src/dateLookup/monthCalendar/{index.js → index.ts} +0 -0
- /package/src/dateLookup/monthCalendar/table/{index.js → index.ts} +0 -0
- /package/src/dateLookup/yearCalendar/{index.js → index.ts} +0 -0
- /package/src/dateLookup/yearCalendar/table/{index.js → index.ts} +0 -0
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { formatDate } from '@transferwise/formatting';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import { PureComponent } from 'react';
|
|
4
|
-
import { injectIntl } from 'react-intl';
|
|
3
|
+
import { injectIntl, WrappedComponentProps } from 'react-intl';
|
|
5
4
|
|
|
6
5
|
import { getDayNames, isWithinRange } from '../../../common/dateUtils';
|
|
7
6
|
import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
|
|
8
7
|
import { getStartOfDay } from '../../getStartOfDay';
|
|
9
8
|
import TableLink from '../../tableLink';
|
|
10
9
|
|
|
11
|
-
const SHORT_DAY_FORMAT = { day: 'numeric' };
|
|
10
|
+
const SHORT_DAY_FORMAT: Intl.DateTimeFormatOptions = { day: 'numeric' };
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
interface DayCalendarTableProps extends WrappedComponentProps {
|
|
13
|
+
selectedDate: Date | null;
|
|
14
|
+
min: Date | null;
|
|
15
|
+
max: Date | null;
|
|
16
|
+
viewMonth: number;
|
|
17
|
+
viewYear: number;
|
|
18
|
+
onSelect: (date: Date) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class DayCalendarTable extends PureComponent<DayCalendarTableProps> {
|
|
14
22
|
getTableStructure = () => {
|
|
15
23
|
const { viewMonth, viewYear } = this.props;
|
|
16
24
|
let firstDayOfMonth = new Date(viewYear, viewMonth, 1).getDay();
|
|
@@ -20,13 +28,13 @@ class DayCalendarTable extends PureComponent {
|
|
|
20
28
|
}
|
|
21
29
|
const daysInMonth = new Date(viewYear, viewMonth + 1, 0).getDate();
|
|
22
30
|
|
|
23
|
-
let week = [];
|
|
24
|
-
const weeks = [];
|
|
31
|
+
let week: number[] = [];
|
|
32
|
+
const weeks: number[][] = [];
|
|
25
33
|
let i;
|
|
26
34
|
|
|
27
35
|
// Pad first week
|
|
28
36
|
for (i = 1; i < firstDayOfMonth; i += 1) {
|
|
29
|
-
week.push(
|
|
37
|
+
week.push(-1);
|
|
30
38
|
}
|
|
31
39
|
// Fill in days
|
|
32
40
|
for (i = 1; i <= daysInMonth; i += 1) {
|
|
@@ -39,7 +47,7 @@ class DayCalendarTable extends PureComponent {
|
|
|
39
47
|
if (week.length > 0) {
|
|
40
48
|
// Pad last week
|
|
41
49
|
for (i = week.length; i < 7; i += 1) {
|
|
42
|
-
week.push(
|
|
50
|
+
week.push(-1);
|
|
43
51
|
}
|
|
44
52
|
weeks.push(week);
|
|
45
53
|
}
|
|
@@ -50,29 +58,29 @@ class DayCalendarTable extends PureComponent {
|
|
|
50
58
|
daysShort = getDayNames(this.props.intl.locale, 'narrow');
|
|
51
59
|
daysLong = getDayNames(this.props.intl.locale, 'long');
|
|
52
60
|
|
|
53
|
-
selectDay = (day) => {
|
|
61
|
+
selectDay = (day: number) => {
|
|
54
62
|
const { viewMonth, viewYear, onSelect } = this.props;
|
|
55
63
|
onSelect(new Date(viewYear, viewMonth, day));
|
|
56
64
|
};
|
|
57
65
|
|
|
58
|
-
isDisabled = (day) => {
|
|
66
|
+
isDisabled = (day: number) => {
|
|
59
67
|
const { min, max, viewMonth, viewYear } = this.props;
|
|
60
68
|
const date = new Date(viewYear, viewMonth, day);
|
|
61
69
|
|
|
62
70
|
return !isWithinRange(date, min, max);
|
|
63
71
|
};
|
|
64
72
|
|
|
65
|
-
isActive = (day) => {
|
|
73
|
+
isActive = (day: number) => {
|
|
66
74
|
const { selectedDate, viewMonth, viewYear } = this.props;
|
|
67
75
|
return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
|
|
68
76
|
};
|
|
69
77
|
|
|
70
|
-
isToday = (day) => {
|
|
78
|
+
isToday = (day: number) => {
|
|
71
79
|
const { viewMonth, viewYear } = this.props;
|
|
72
80
|
return Number(getStartOfDay(new Date())) === Number(new Date(viewYear, viewMonth, day));
|
|
73
81
|
};
|
|
74
82
|
|
|
75
|
-
getAutofocusDay = (weeks) => {
|
|
83
|
+
getAutofocusDay = (weeks: number[][]) => {
|
|
76
84
|
const days = weeks.flatMap((week) => week);
|
|
77
85
|
return getFocusableTime({
|
|
78
86
|
isActive: this.isActive,
|
|
@@ -83,13 +91,9 @@ class DayCalendarTable extends PureComponent {
|
|
|
83
91
|
};
|
|
84
92
|
|
|
85
93
|
render() {
|
|
86
|
-
const {
|
|
87
|
-
viewMonth,
|
|
88
|
-
viewYear,
|
|
89
|
-
intl: { locale },
|
|
90
|
-
} = this.props;
|
|
94
|
+
const { viewMonth, viewYear, intl } = this.props;
|
|
91
95
|
const weeks = this.getTableStructure();
|
|
92
|
-
|
|
96
|
+
const autoFocusDay = this.getAutofocusDay(weeks);
|
|
93
97
|
return (
|
|
94
98
|
<table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
|
|
95
99
|
<thead>
|
|
@@ -119,17 +123,17 @@ class DayCalendarTable extends PureComponent {
|
|
|
119
123
|
<tr key={weekIndex}>
|
|
120
124
|
{week.map((day, dayIndex) => (
|
|
121
125
|
<td key={dayIndex} className={dayIndex > 4 ? 'weekend' : ''}>
|
|
122
|
-
{day && (
|
|
126
|
+
{day !== -1 && (
|
|
123
127
|
<TableLink
|
|
124
128
|
item={day}
|
|
125
129
|
type="day"
|
|
126
130
|
title={formatDate(
|
|
127
131
|
new Date(viewYear, viewMonth, day),
|
|
128
|
-
locale,
|
|
132
|
+
intl.locale,
|
|
129
133
|
SHORT_DAY_FORMAT,
|
|
130
134
|
)}
|
|
131
135
|
autofocus={day === autoFocusDay}
|
|
132
|
-
longTitle={formatDate(new Date(viewYear, viewMonth, day), locale)}
|
|
136
|
+
longTitle={formatDate(new Date(viewYear, viewMonth, day), intl.locale)}
|
|
133
137
|
active={this.isActive(day)}
|
|
134
138
|
disabled={this.isDisabled(day)}
|
|
135
139
|
today={this.isToday(day)}
|
|
@@ -147,19 +151,4 @@ class DayCalendarTable extends PureComponent {
|
|
|
147
151
|
}
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
DayCalendarTable.propTypes = {
|
|
151
|
-
selectedDate: PropTypes.instanceOf(Date),
|
|
152
|
-
min: PropTypes.instanceOf(Date),
|
|
153
|
-
max: PropTypes.instanceOf(Date),
|
|
154
|
-
viewMonth: PropTypes.number.isRequired,
|
|
155
|
-
viewYear: PropTypes.number.isRequired,
|
|
156
|
-
onSelect: PropTypes.func.isRequired,
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
DayCalendarTable.defaultProps = {
|
|
160
|
-
selectedDate: null,
|
|
161
|
-
min: null,
|
|
162
|
-
max: null,
|
|
163
|
-
};
|
|
164
|
-
|
|
165
154
|
export default injectIntl(DayCalendarTable);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// getStartOfDay(new Date('1995-01-01')) in Los Angeles returns 31 Dec 1994, but in
|
|
3
3
|
// in Singapore it is 1 Jan 1995.
|
|
4
4
|
// You might want to use/implement `getUTCStartOfDay` if you want it to be 1995 in any timezone
|
|
5
|
-
export function getStartOfDay(date) {
|
|
5
|
+
export function getStartOfDay(date: Date | null) {
|
|
6
6
|
if (!date) {
|
|
7
7
|
return null;
|
|
8
8
|
}
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { formatDate } from '@transferwise/formatting';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import { PureComponent } from 'react';
|
|
4
|
-
import { injectIntl } from 'react-intl';
|
|
3
|
+
import { injectIntl, WrappedComponentProps } from 'react-intl';
|
|
5
4
|
|
|
6
5
|
import messages from '../DateLookup.messages';
|
|
7
6
|
import DateHeader from '../dateHeader';
|
|
8
7
|
|
|
9
8
|
import MonthCalendarTable from './table';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
interface MonthCalendarProps extends WrappedComponentProps {
|
|
11
|
+
selectedDate: Date | null;
|
|
12
|
+
min: Date | null;
|
|
13
|
+
max: Date | null;
|
|
14
|
+
viewYear: number;
|
|
15
|
+
placeholder: string;
|
|
16
|
+
onSelect: () => void;
|
|
17
|
+
onLabelClick: () => void;
|
|
18
|
+
onViewDateUpdate: (date: { year?: number; month?: number }) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class MonthCalendar extends PureComponent<MonthCalendarProps> {
|
|
22
|
+
onMonthSelect = (month: number) => {
|
|
13
23
|
this.props.onViewDateUpdate({ month });
|
|
14
24
|
this.props.onSelect();
|
|
15
25
|
};
|
|
@@ -42,7 +52,11 @@ class MonthCalendar extends PureComponent {
|
|
|
42
52
|
onNextClick={this.selectNextYear}
|
|
43
53
|
/>
|
|
44
54
|
<MonthCalendarTable
|
|
45
|
-
{
|
|
55
|
+
selectedDate={selectedDate}
|
|
56
|
+
min={min}
|
|
57
|
+
max={max}
|
|
58
|
+
viewYear={viewYear}
|
|
59
|
+
placeholder={placeholder}
|
|
46
60
|
onSelect={this.onMonthSelect}
|
|
47
61
|
/>
|
|
48
62
|
</>
|
|
@@ -50,21 +64,4 @@ class MonthCalendar extends PureComponent {
|
|
|
50
64
|
}
|
|
51
65
|
}
|
|
52
66
|
|
|
53
|
-
MonthCalendar.propTypes = {
|
|
54
|
-
selectedDate: PropTypes.instanceOf(Date),
|
|
55
|
-
min: PropTypes.instanceOf(Date),
|
|
56
|
-
max: PropTypes.instanceOf(Date),
|
|
57
|
-
viewYear: PropTypes.number.isRequired,
|
|
58
|
-
placeholder: PropTypes.string.isRequired,
|
|
59
|
-
onSelect: PropTypes.func.isRequired,
|
|
60
|
-
onLabelClick: PropTypes.func.isRequired,
|
|
61
|
-
onViewDateUpdate: PropTypes.func.isRequired,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
MonthCalendar.defaultProps = {
|
|
65
|
-
selectedDate: null,
|
|
66
|
-
min: null,
|
|
67
|
-
max: null,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
67
|
export default injectIntl(MonthCalendar);
|
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
import { formatDate } from '@transferwise/formatting';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import { useIntl } from 'react-intl';
|
|
4
3
|
|
|
5
4
|
import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
|
|
6
5
|
import TableLink from '../../tableLink';
|
|
7
6
|
|
|
7
|
+
interface MonthCalendarTableProps {
|
|
8
|
+
selectedDate: Date | null;
|
|
9
|
+
min: Date | null;
|
|
10
|
+
max: Date | null;
|
|
11
|
+
viewYear: number;
|
|
12
|
+
placeholder: string;
|
|
13
|
+
onSelect: (date: number) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
const ROWS = 3;
|
|
9
17
|
const COLS = 4;
|
|
10
|
-
const MONTH_ONLY_FORMAT = { month: 'short' };
|
|
18
|
+
const MONTH_ONLY_FORMAT: Intl.DateTimeFormatOptions = { month: 'short' };
|
|
11
19
|
|
|
12
|
-
const MonthCalendarTable = ({
|
|
20
|
+
const MonthCalendarTable = ({
|
|
21
|
+
selectedDate,
|
|
22
|
+
min,
|
|
23
|
+
max,
|
|
24
|
+
viewYear,
|
|
25
|
+
placeholder,
|
|
26
|
+
onSelect,
|
|
27
|
+
}: MonthCalendarTableProps) => {
|
|
13
28
|
const { locale } = useIntl();
|
|
14
|
-
|
|
29
|
+
|
|
30
|
+
const getLink = (month: number) => {
|
|
15
31
|
return (
|
|
16
32
|
<TableLink
|
|
17
33
|
item={month}
|
|
@@ -26,17 +42,19 @@ const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onS
|
|
|
26
42
|
);
|
|
27
43
|
};
|
|
28
44
|
|
|
29
|
-
const isActive = (month) => {
|
|
30
|
-
return (
|
|
31
|
-
selectedDate &&
|
|
45
|
+
const isActive = (month: number) => {
|
|
46
|
+
return !!(
|
|
47
|
+
selectedDate &&
|
|
48
|
+
month === selectedDate.getMonth() &&
|
|
49
|
+
viewYear === selectedDate.getFullYear()
|
|
32
50
|
);
|
|
33
51
|
};
|
|
34
52
|
|
|
35
|
-
const isThisMonth = (month) => {
|
|
53
|
+
const isThisMonth = (month: number) => {
|
|
36
54
|
return viewYear === new Date().getFullYear() && month === new Date().getMonth();
|
|
37
55
|
};
|
|
38
56
|
|
|
39
|
-
const isDisabled = (month) => {
|
|
57
|
+
const isDisabled = (month: number) => {
|
|
40
58
|
const date = new Date(viewYear, month);
|
|
41
59
|
return !!(
|
|
42
60
|
(min && date < new Date(min.getFullYear(), min.getMonth())) ||
|
|
@@ -45,7 +63,7 @@ const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onS
|
|
|
45
63
|
};
|
|
46
64
|
|
|
47
65
|
const autofocusMonth = (() => {
|
|
48
|
-
const months =
|
|
66
|
+
const months = Array.from({ length: ROWS * COLS }, (_, index) => index);
|
|
49
67
|
return getFocusableTime({ isActive, isNow: isThisMonth, isDisabled, timeSpan: months });
|
|
50
68
|
})();
|
|
51
69
|
|
|
@@ -53,37 +71,20 @@ const MonthCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onS
|
|
|
53
71
|
<table className="table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0">
|
|
54
72
|
<thead className="sr-only">
|
|
55
73
|
<tr>
|
|
56
|
-
<th colSpan=
|
|
74
|
+
<th colSpan={COLS}>{placeholder}</th>
|
|
57
75
|
</tr>
|
|
58
76
|
</thead>
|
|
59
77
|
<tbody>
|
|
60
|
-
{
|
|
61
|
-
{[...new Array(ROWS)].map((row, rowIndex) => (
|
|
78
|
+
{Array.from({ length: ROWS }, (_, rowIndex) => (
|
|
62
79
|
<tr key={rowIndex}>
|
|
63
|
-
{
|
|
80
|
+
{Array.from({ length: COLS }, (_, colIndex) => (
|
|
64
81
|
<td key={colIndex}>{getLink(rowIndex * COLS + colIndex)}</td>
|
|
65
82
|
))}
|
|
66
83
|
</tr>
|
|
67
84
|
))}
|
|
68
|
-
{/* eslint-enable react/no-array-index-key */}
|
|
69
85
|
</tbody>
|
|
70
86
|
</table>
|
|
71
87
|
);
|
|
72
88
|
};
|
|
73
89
|
|
|
74
|
-
MonthCalendarTable.propTypes = {
|
|
75
|
-
selectedDate: PropTypes.instanceOf(Date),
|
|
76
|
-
min: PropTypes.instanceOf(Date),
|
|
77
|
-
max: PropTypes.instanceOf(Date),
|
|
78
|
-
viewYear: PropTypes.number.isRequired,
|
|
79
|
-
placeholder: PropTypes.string.isRequired,
|
|
80
|
-
onSelect: PropTypes.func.isRequired,
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
MonthCalendarTable.defaultProps = {
|
|
84
|
-
selectedDate: null,
|
|
85
|
-
min: null,
|
|
86
|
-
max: null,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
90
|
export default MonthCalendarTable;
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
1
|
import { PureComponent } from 'react';
|
|
3
|
-
import { injectIntl } from 'react-intl';
|
|
2
|
+
import { injectIntl, WrappedComponentProps } from 'react-intl';
|
|
4
3
|
|
|
5
4
|
import messages from '../DateLookup.messages';
|
|
6
5
|
import DateHeader from '../dateHeader';
|
|
7
6
|
|
|
8
7
|
import YearCalendarTable from './table';
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
interface YearCalendarProps extends WrappedComponentProps {
|
|
10
|
+
selectedDate: Date | null;
|
|
11
|
+
min: Date | null;
|
|
12
|
+
max: Date | null;
|
|
13
|
+
viewYear: number;
|
|
14
|
+
placeholder: string;
|
|
15
|
+
onSelect: () => void;
|
|
16
|
+
onViewDateUpdate: (date: { year: number }) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class YearCalendar extends PureComponent<YearCalendarProps> {
|
|
20
|
+
onYearSelect = (year: number) => {
|
|
12
21
|
this.props.onViewDateUpdate({ year });
|
|
13
22
|
this.props.onSelect();
|
|
14
23
|
};
|
|
@@ -38,7 +47,11 @@ class YearCalendar extends PureComponent {
|
|
|
38
47
|
onNextClick={this.selectNextYears}
|
|
39
48
|
/>
|
|
40
49
|
<YearCalendarTable
|
|
41
|
-
{
|
|
50
|
+
selectedDate={selectedDate}
|
|
51
|
+
min={min}
|
|
52
|
+
max={max}
|
|
53
|
+
viewYear={viewYear}
|
|
54
|
+
placeholder={placeholder}
|
|
42
55
|
onSelect={this.onYearSelect}
|
|
43
56
|
/>
|
|
44
57
|
</>
|
|
@@ -46,20 +59,4 @@ class YearCalendar extends PureComponent {
|
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
61
|
|
|
49
|
-
YearCalendar.propTypes = {
|
|
50
|
-
selectedDate: PropTypes.instanceOf(Date),
|
|
51
|
-
min: PropTypes.instanceOf(Date),
|
|
52
|
-
max: PropTypes.instanceOf(Date),
|
|
53
|
-
viewYear: PropTypes.number.isRequired,
|
|
54
|
-
placeholder: PropTypes.string.isRequired,
|
|
55
|
-
onSelect: PropTypes.func.isRequired,
|
|
56
|
-
onViewDateUpdate: PropTypes.func.isRequired,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
YearCalendar.defaultProps = {
|
|
60
|
-
selectedDate: null,
|
|
61
|
-
min: null,
|
|
62
|
-
max: null,
|
|
63
|
-
};
|
|
64
|
-
|
|
65
62
|
export default injectIntl(YearCalendar);
|
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import { formatDate } from '@transferwise/formatting';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
import { useIntl } from 'react-intl';
|
|
4
3
|
|
|
5
4
|
import { getFocusableTime } from '../../getFocusableTime/getFocusableTime';
|
|
6
5
|
import TableLink from '../../tableLink';
|
|
7
6
|
|
|
7
|
+
interface YearCalendarTableProps {
|
|
8
|
+
selectedDate: Date | null;
|
|
9
|
+
min: Date | null;
|
|
10
|
+
max: Date | null;
|
|
11
|
+
viewYear: number;
|
|
12
|
+
placeholder: string;
|
|
13
|
+
onSelect: (year: number) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
const ROWS = 5;
|
|
9
17
|
const COLS = 4;
|
|
10
|
-
const YEAR_ONLY_FORMAT = { year: 'numeric' };
|
|
18
|
+
const YEAR_ONLY_FORMAT: Intl.DateTimeFormatOptions = { year: 'numeric' };
|
|
11
19
|
|
|
12
|
-
const YearCalendarTable = ({
|
|
20
|
+
const YearCalendarTable = ({
|
|
21
|
+
selectedDate,
|
|
22
|
+
min,
|
|
23
|
+
max,
|
|
24
|
+
viewYear,
|
|
25
|
+
placeholder,
|
|
26
|
+
onSelect,
|
|
27
|
+
}: YearCalendarTableProps) => {
|
|
13
28
|
const { locale } = useIntl();
|
|
14
29
|
const startYear = viewYear - (viewYear % 20);
|
|
15
|
-
const getLink = (year) => {
|
|
30
|
+
const getLink = (year: number) => {
|
|
16
31
|
return (
|
|
17
32
|
<TableLink
|
|
18
33
|
item={year}
|
|
@@ -27,20 +42,20 @@ const YearCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSe
|
|
|
27
42
|
);
|
|
28
43
|
};
|
|
29
44
|
|
|
30
|
-
const isActive = (year) => {
|
|
45
|
+
const isActive = (year: number) => {
|
|
31
46
|
return !!(selectedDate && year === selectedDate.getFullYear());
|
|
32
47
|
};
|
|
33
48
|
|
|
34
|
-
const isThisYear = (year) => {
|
|
49
|
+
const isThisYear = (year: number) => {
|
|
35
50
|
return year === new Date().getFullYear();
|
|
36
51
|
};
|
|
37
52
|
|
|
38
|
-
const isDisabled = (year) => {
|
|
53
|
+
const isDisabled = (year: number) => {
|
|
39
54
|
return !!((min && year < min.getFullYear()) || (max && year > max.getFullYear()));
|
|
40
55
|
};
|
|
41
56
|
|
|
42
57
|
const autofocusYear = (() => {
|
|
43
|
-
const years =
|
|
58
|
+
const years = Array.from({ length: ROWS * COLS }, (_, index) => startYear + index);
|
|
44
59
|
return getFocusableTime({ isActive, isNow: isThisYear, isDisabled, timeSpan: years });
|
|
45
60
|
})();
|
|
46
61
|
|
|
@@ -48,37 +63,20 @@ const YearCalendarTable = ({ selectedDate, min, max, viewYear, placeholder, onSe
|
|
|
48
63
|
<table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
|
|
49
64
|
<thead className="sr-only">
|
|
50
65
|
<tr>
|
|
51
|
-
<th colSpan=
|
|
66
|
+
<th colSpan={COLS}>{placeholder}</th>
|
|
52
67
|
</tr>
|
|
53
68
|
</thead>
|
|
54
69
|
<tbody>
|
|
55
|
-
{
|
|
56
|
-
{[...new Array(ROWS)].map((row, rowIndex) => (
|
|
70
|
+
{Array.from({ length: ROWS }, (_, rowIndex) => (
|
|
57
71
|
<tr key={rowIndex}>
|
|
58
|
-
{
|
|
72
|
+
{Array.from({ length: COLS }, (_, colIndex) => (
|
|
59
73
|
<td key={colIndex}>{getLink(startYear + rowIndex * COLS + colIndex)}</td>
|
|
60
74
|
))}
|
|
61
75
|
</tr>
|
|
62
76
|
))}
|
|
63
|
-
{/* eslint-enable react/no-array-index-key */}
|
|
64
77
|
</tbody>
|
|
65
78
|
</table>
|
|
66
79
|
);
|
|
67
80
|
};
|
|
68
81
|
|
|
69
|
-
YearCalendarTable.propTypes = {
|
|
70
|
-
selectedDate: PropTypes.instanceOf(Date),
|
|
71
|
-
min: PropTypes.instanceOf(Date),
|
|
72
|
-
max: PropTypes.instanceOf(Date),
|
|
73
|
-
viewYear: PropTypes.number.isRequired,
|
|
74
|
-
placeholder: PropTypes.string.isRequired,
|
|
75
|
-
onSelect: PropTypes.func.isRequired,
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
YearCalendarTable.defaultProps = {
|
|
79
|
-
selectedDate: null,
|
|
80
|
-
min: null,
|
|
81
|
-
max: null,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
82
|
export default YearCalendarTable;
|
package/src/i18n/th.json
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
"neptune.ClearButton.ariaLabel": "ล้าง",
|
|
5
5
|
"neptune.CloseButton.ariaLabel": "ปิด",
|
|
6
6
|
"neptune.DateInput.day.label": "วัน",
|
|
7
|
-
"neptune.DateInput.day.placeholder": "
|
|
7
|
+
"neptune.DateInput.day.placeholder": "วัน",
|
|
8
8
|
"neptune.DateInput.month.label": "เดือน",
|
|
9
9
|
"neptune.DateInput.year.label": "ปี",
|
|
10
|
-
"neptune.DateInput.year.placeholder": "
|
|
10
|
+
"neptune.DateInput.year.placeholder": "ปี",
|
|
11
11
|
"neptune.DateLookup.day": "วัน",
|
|
12
12
|
"neptune.DateLookup.goTo20YearView": "ไปที่มุมมอง 20 ปี",
|
|
13
13
|
"neptune.DateLookup.month": "เดือน",
|
package/src/i18n/zh-CN.json
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
"neptune.ClearButton.ariaLabel": "清除",
|
|
5
5
|
"neptune.CloseButton.ariaLabel": "关闭",
|
|
6
6
|
"neptune.DateInput.day.label": "日",
|
|
7
|
-
"neptune.DateInput.day.placeholder": "
|
|
7
|
+
"neptune.DateInput.day.placeholder": "日",
|
|
8
8
|
"neptune.DateInput.month.label": "月",
|
|
9
9
|
"neptune.DateInput.year.label": "年",
|
|
10
|
-
"neptune.DateInput.year.placeholder": "
|
|
10
|
+
"neptune.DateInput.year.placeholder": "年",
|
|
11
11
|
"neptune.DateLookup.day": "日",
|
|
12
12
|
"neptune.DateLookup.goTo20YearView": "转到 20 年视图",
|
|
13
13
|
"neptune.DateLookup.month": "月",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"neptune.Info.ariaLabel": "更多信息",
|
|
21
21
|
"neptune.Link.opensInNewTab": "(在新标签页中打开)",
|
|
22
22
|
"neptune.MoneyInput.Select.placeholder": "请选择...",
|
|
23
|
-
"neptune.PhoneNumberInput.SelectInput.placeholder": "
|
|
23
|
+
"neptune.PhoneNumberInput.SelectInput.placeholder": "选择其中一项...",
|
|
24
24
|
"neptune.Select.searchPlaceholder": "搜索",
|
|
25
25
|
"neptune.SelectInput.noResultsFound": "找不到结果",
|
|
26
26
|
"neptune.Summary.statusDone": "已完成",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"neptune.Upload.csButtonText": "上传另一个文件?",
|
|
30
30
|
"neptune.Upload.csFailureText": "上传失败。请重试",
|
|
31
31
|
"neptune.Upload.csSuccessText": "上传完毕!",
|
|
32
|
-
"neptune.Upload.csTooLargeMessage": "
|
|
32
|
+
"neptune.Upload.csTooLargeMessage": "请提供一个小于 {maxSize} MB 的文件",
|
|
33
33
|
"neptune.Upload.csWrongTypeMessage": "不支持该文件类型,请试试其他文件",
|
|
34
34
|
"neptune.Upload.psButtonText": "取消",
|
|
35
35
|
"neptune.Upload.psProcessingText": "正在上传…",
|
|
36
36
|
"neptune.Upload.usButtonText": "或选择文件",
|
|
37
37
|
"neptune.Upload.usDropMessage": "拖放文件开始上传",
|
|
38
|
-
"neptune.Upload.usPlaceholder": "
|
|
38
|
+
"neptune.Upload.usPlaceholder": "拖放一个不超过 {maxSize} MB 的文件",
|
|
39
39
|
"neptune.UploadButton.allFileTypes": "所有文件类型",
|
|
40
40
|
"neptune.UploadButton.dropFiles": "拖放文件开始上传",
|
|
41
41
|
"neptune.UploadButton.instructions": "{fileTypes},小于 {size} MB",
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
export type { AccordionProps, AccordionItem } from './accordion';
|
|
5
5
|
export type { AvatarProps } from './avatar';
|
|
6
6
|
export type { ActionOptionProps } from './actionOption';
|
|
7
|
+
export type { AlertProps, AlertAction, AlertArrowPosition, AlertType } from './alert';
|
|
7
8
|
export type { BadgeProps } from './badge';
|
|
8
9
|
export type { CircularButtonProps } from './circularButton';
|
|
9
10
|
export type { DecisionProps } from './decision/Decision';
|
|
@@ -12,6 +13,7 @@ export type { InfoProps } from './info';
|
|
|
12
13
|
export type { SummaryProps } from './summary';
|
|
13
14
|
export type { InputProps } from './inputs/Input';
|
|
14
15
|
export type { DateInputProps } from './dateInput';
|
|
16
|
+
export type { DateLookupProps } from './dateLookup';
|
|
15
17
|
export type { InputWithDisplayFormatProps } from './inputWithDisplayFormat';
|
|
16
18
|
export type { InputGroupProps } from './inputs/InputGroup';
|
|
17
19
|
export type { LoaderProps } from './loader';
|
|
@@ -194,7 +196,6 @@ export { AvatarType } from './avatar';
|
|
|
194
196
|
export { InfoPresentation } from './info';
|
|
195
197
|
export { UploadStep } from './upload';
|
|
196
198
|
export { DecisionPresentation, DecisionType } from './decision';
|
|
197
|
-
export { AlertArrowPosition } from './alert/withArrow';
|
|
198
199
|
export { LogoType } from './logo';
|
|
199
200
|
export { FileType } from './common';
|
|
200
201
|
|
|
@@ -21,13 +21,6 @@ describe('InlineAlert', () => {
|
|
|
21
21
|
|
|
22
22
|
expect(component).toHaveClass('alert-neutral');
|
|
23
23
|
});
|
|
24
|
-
|
|
25
|
-
it('has a top left arrow', () => {
|
|
26
|
-
render(<InlineAlert>{message}</InlineAlert>);
|
|
27
|
-
const component = screen.getByRole('alert');
|
|
28
|
-
|
|
29
|
-
expect(component).toHaveClass('arrow');
|
|
30
|
-
});
|
|
31
24
|
});
|
|
32
25
|
|
|
33
26
|
describe('render with types', () => {
|
|
@@ -1,59 +1,31 @@
|
|
|
1
1
|
import { AlertCircle as AlertCircleIcon } from '@transferwise/icons';
|
|
2
|
-
import { useTheme } from '@wise/components-theming';
|
|
3
2
|
import classNames from 'classnames';
|
|
4
3
|
import { ReactNode } from 'react';
|
|
5
4
|
|
|
6
|
-
import withArrow, { AlertArrowPosition } from '../alert/withArrow';
|
|
7
5
|
import { Sentiment } from '../common';
|
|
8
|
-
import { SentimentString } from '../common/propsValues/sentiment';
|
|
9
6
|
|
|
10
7
|
export interface InlineAlertProps {
|
|
11
8
|
id?: string;
|
|
12
|
-
type?: Sentiment
|
|
9
|
+
type?: `${Sentiment}`;
|
|
13
10
|
className?: string;
|
|
14
11
|
children: ReactNode;
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const getAlertContents = ({
|
|
37
|
-
children,
|
|
38
|
-
className,
|
|
39
|
-
}: {
|
|
40
|
-
children: ReactNode;
|
|
41
|
-
className?: string;
|
|
42
|
-
}) => {
|
|
43
|
-
return (
|
|
44
|
-
<div
|
|
45
|
-
role="alert"
|
|
46
|
-
id={id}
|
|
47
|
-
className={classNames('alert alert-detach p-x-2 p-y-1', typeClass, className)}
|
|
48
|
-
>
|
|
49
|
-
{children}
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const AlertWithArrow = withArrow(getAlertContents, AlertArrowPosition.TOP_LEFT);
|
|
55
|
-
|
|
56
|
-
return <AlertWithArrow {...{ id, type, className, children }} />;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default InlineAlert;
|
|
14
|
+
export default function InlineAlert({
|
|
15
|
+
id,
|
|
16
|
+
type = 'neutral',
|
|
17
|
+
className,
|
|
18
|
+
children,
|
|
19
|
+
}: InlineAlertProps) {
|
|
20
|
+
const danger = type === 'negative' || type === 'error';
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
role="alert"
|
|
24
|
+
id={id}
|
|
25
|
+
className={classNames('alert alert-detach', `alert-${danger ? 'danger' : type}`, className)}
|
|
26
|
+
>
|
|
27
|
+
{danger && <AlertCircleIcon />}
|
|
28
|
+
<div>{children}</div>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
}
|