@transferwise/components 46.13.0 → 46.15.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/index.esm.js +246 -525
- package/build/index.esm.js.map +1 -1
- package/build/index.js +222 -501
- package/build/index.js.map +1 -1
- package/build/main.css +6 -82
- package/build/styles/decision/Decision.css +6 -82
- package/build/styles/main.css +6 -82
- package/build/types/actionButton/ActionButton.d.ts +1 -1
- package/build/types/body/Body.d.ts +1 -1
- package/build/types/common/Option/Option.d.ts.map +1 -1
- package/build/types/common/RadioButton/RadioButton.d.ts +10 -34
- package/build/types/common/RadioButton/RadioButton.d.ts.map +1 -1
- package/build/types/common/RadioButton/index.d.ts +1 -1
- package/build/types/common/RadioButton/index.d.ts.map +1 -1
- package/build/types/common/commonProps.d.ts +1 -1
- package/build/types/common/commonProps.d.ts.map +1 -1
- package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts +1 -1
- package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts.map +1 -1
- package/build/types/common/dateUtils/getDayNames/index.d.ts +1 -1
- package/build/types/common/dateUtils/getDayNames/index.d.ts.map +1 -1
- package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts +1 -1
- package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts.map +1 -1
- package/build/types/common/dateUtils/getMonthNames/index.d.ts +1 -1
- package/build/types/common/dateUtils/getMonthNames/index.d.ts.map +1 -1
- package/build/types/common/dateUtils/index.d.ts +6 -6
- package/build/types/common/dateUtils/index.d.ts.map +1 -1
- package/build/types/common/dateUtils/isDateValid/index.d.ts +1 -1
- package/build/types/common/dateUtils/isDateValid/index.d.ts.map +1 -1
- package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts +2 -2
- package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts.map +1 -1
- package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts +1 -1
- package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts.map +1 -1
- package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts +1 -1
- package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts.map +1 -1
- package/build/types/common/dateUtils/isWithinRange/index.d.ts +1 -1
- package/build/types/common/dateUtils/isWithinRange/index.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/index.d.ts +1 -1
- package/build/types/common/dateUtils/moveToWithinRange/index.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/panel/Panel.d.ts +1 -1
- package/build/types/common/responsivePanel/ResponsivePanel.d.ts +1 -1
- package/build/types/dateInput/DateInput.d.ts +30 -41
- package/build/types/dateInput/DateInput.d.ts.map +1 -1
- package/build/types/dateInput/DateInput.messages.d.ts +24 -33
- package/build/types/dateInput/DateInput.messages.d.ts.map +1 -1
- package/build/types/dateInput/index.d.ts +2 -2
- package/build/types/dateInput/index.d.ts.map +1 -1
- package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts +1 -1
- package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts.map +1 -1
- package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts +1 -1
- package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts.map +1 -1
- package/build/types/dateInput/utils/index.d.ts +1 -2
- package/build/types/dateInput/utils/index.d.ts.map +1 -1
- package/build/types/dateLookup/DateLookup.d.ts +1 -0
- package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
- package/build/types/decision/Decision.d.ts +39 -52
- package/build/types/decision/Decision.d.ts.map +1 -1
- package/build/types/decision/index.d.ts +1 -2
- package/build/types/decision/index.d.ts.map +1 -1
- package/build/types/dimmer/Dimmer.d.ts +1 -1
- package/build/types/index.d.ts +5 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/promoCard/PromoCard.d.ts +1 -2
- package/build/types/promoCard/PromoCard.d.ts.map +1 -1
- package/build/types/radio/Radio.d.ts +10 -21
- package/build/types/radio/Radio.d.ts.map +1 -1
- package/build/types/radio/index.d.ts +2 -2
- package/build/types/radio/index.d.ts.map +1 -1
- package/build/types/radioGroup/RadioGroup.d.ts +10 -26
- package/build/types/radioGroup/RadioGroup.d.ts.map +1 -1
- package/build/types/radioGroup/index.d.ts +2 -1
- package/build/types/radioGroup/index.d.ts.map +1 -1
- package/build/types/radioOption/RadioOption.d.ts +15 -23
- package/build/types/radioOption/RadioOption.d.ts.map +1 -1
- package/build/types/radioOption/index.d.ts +2 -1
- package/build/types/radioOption/index.d.ts.map +1 -1
- package/build/types/select/searchBox/SearchBox.d.ts +1 -1
- package/package.json +1 -1
- package/src/common/Option/Option.tsx +0 -1
- package/src/common/RadioButton/RadioButton.tsx +43 -0
- package/src/common/commonProps.ts +1 -1
- package/src/common/dateUtils/getDayNames/getDayNames.spec.js +2 -2
- package/src/common/dateUtils/getDayNames/{getDayNames.js → getDayNames.ts} +5 -2
- package/src/common/dateUtils/getMonthNames/getMonthNames.spec.js +9 -8
- package/src/common/dateUtils/getMonthNames/{getMonthNames.js → getMonthNames.ts} +5 -3
- package/src/common/dateUtils/isDateValid/{isDateValid.spec.js → isDateValid.spec.ts} +1 -1
- package/src/common/dateUtils/isDateValid/isDateValid.ts +13 -0
- package/src/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.spec.js +3 -7
- package/src/common/dateUtils/isMonthAndYearFormat/{isMonthAndYearFormat.js → isMonthAndYearFormat.ts} +1 -1
- package/src/common/dateUtils/isWithinRange/{isWithinRange.spec.js → isWithinRange.spec.ts} +0 -10
- package/src/common/dateUtils/isWithinRange/{isWithinRange.js → isWithinRange.ts} +1 -1
- package/src/common/dateUtils/moveToWithinRange/{moveToWithinRange.js → moveToWithinRange.ts} +2 -2
- package/src/dateInput/DateInput.spec.js +7 -56
- package/src/dateInput/DateInput.story.tsx +11 -8
- package/src/dateInput/{DateInput.js → DateInput.tsx} +116 -123
- package/src/dateInput/index.ts +2 -0
- package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.js → convertToLocalMidnight.ts} +1 -1
- package/src/dateInput/utils/{index.js → index.ts} +0 -1
- package/src/dateLookup/DateLookup.js +12 -1
- package/src/dateLookup/DateLookup.testingLibrary.spec.js +12 -1
- package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -0
- package/src/decision/Decision.css +6 -82
- package/src/decision/Decision.less +3 -41
- package/src/decision/Decision.spec.js +56 -61
- package/src/decision/{Decision.story.js → Decision.story.tsx} +5 -5
- package/src/decision/Decision.tsx +133 -0
- package/src/decision/index.ts +1 -0
- package/src/index.ts +5 -0
- package/src/main.css +6 -82
- package/src/promoCard/PromoCard.tsx +1 -2
- package/src/radio/{Radio.story.js → Radio.story.tsx} +0 -3
- package/src/radio/{Radio.js → Radio.tsx} +18 -28
- package/src/radio/index.ts +2 -0
- package/src/radioGroup/RadioGroup.spec.js +24 -26
- package/src/radioGroup/{RadioGroup.story.js → RadioGroup.story.tsx} +0 -3
- package/src/radioGroup/RadioGroup.tsx +39 -0
- package/src/radioGroup/index.ts +2 -0
- package/src/radioOption/RadioOption.spec.js +4 -4
- package/src/radioOption/{RadioOption.story.js → RadioOption.story.tsx} +4 -4
- package/src/radioOption/RadioOption.tsx +60 -0
- package/src/radioOption/index.ts +2 -0
- package/src/tile/Tile.js +1 -1
- package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts +0 -6
- package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts.map +0 -1
- package/build/types/dateInput/utils/explodeDate/index.d.ts +0 -2
- package/build/types/dateInput/utils/explodeDate/index.d.ts.map +0 -1
- package/build/types/decision/decisionEnums.d.ts +0 -9
- package/build/types/decision/decisionEnums.d.ts.map +0 -1
- package/build/types/sizeSwapper/SizeSwapper.d.ts +0 -3
- package/build/types/sizeSwapper/SizeSwapper.d.ts.map +0 -1
- package/build/types/sizeSwapper/index.d.ts +0 -2
- package/build/types/sizeSwapper/index.d.ts.map +0 -1
- package/src/common/RadioButton/RadioButton.js +0 -41
- package/src/common/dateUtils/isDateValid/isDateValid.js +0 -6
- package/src/dateInput/index.js +0 -3
- package/src/dateInput/utils/explodeDate/explodeDate.js +0 -7
- package/src/dateInput/utils/explodeDate/explodeDate.spec.js +0 -11
- package/src/dateInput/utils/explodeDate/index.js +0 -1
- package/src/decision/Decision.js +0 -148
- package/src/decision/decisionEnums.ts +0 -11
- package/src/decision/index.js +0 -2
- package/src/radio/index.js +0 -3
- package/src/radioGroup/RadioGroup.js +0 -66
- package/src/radioGroup/index.js +0 -1
- package/src/radioOption/RadioOption.js +0 -81
- package/src/radioOption/index.js +0 -1
- package/src/sizeSwapper/SizeSwapper.js +0 -69
- package/src/sizeSwapper/SizeSwapper.spec.js +0 -100
- package/src/sizeSwapper/SizeSwapper.story.js +0 -34
- package/src/sizeSwapper/index.js +0 -1
- /package/src/common/RadioButton/{RadioButton.spec.js → RadioButton.spec.tsx} +0 -0
- /package/src/common/RadioButton/__snapshots__/{RadioButton.spec.js.snap → RadioButton.spec.tsx.snap} +0 -0
- /package/src/common/RadioButton/{index.js → index.ts} +0 -0
- /package/src/common/dateUtils/getDayNames/{index.js → index.ts} +0 -0
- /package/src/common/dateUtils/getMonthNames/{index.js → index.ts} +0 -0
- /package/src/common/dateUtils/{index.js → index.ts} +0 -0
- /package/src/common/dateUtils/isDateValid/{index.js → index.ts} +0 -0
- /package/src/common/dateUtils/isMonthAndYearFormat/{index.js → index.ts} +0 -0
- /package/src/common/dateUtils/isWithinRange/{index.js → index.ts} +0 -0
- /package/src/common/dateUtils/moveToWithinRange/{index.js → index.ts} +0 -0
- /package/src/dateInput/{DateInput.messages.js → DateInput.messages.ts} +0 -0
- /package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.spec.js → convertToLocalMidnight.spec.ts} +0 -0
- /package/src/dateInput/utils/convertToLocalMidnight/{index.js → index.ts} +0 -0
- /package/src/radio/{Radio.rtl.spec.js → Radio.rtl.spec.tsx} +0 -0
- /package/src/radio/__snapshots__/{Radio.rtl.spec.js.snap → Radio.rtl.spec.tsx.snap} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
|
|
3
|
+
export interface RadioButtonProps<T extends string | number = string> {
|
|
4
|
+
id?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
onChange?: (value: T | '') => void;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
value?: T | '';
|
|
10
|
+
readOnly?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default function RadioButton<T extends string | number = string>({
|
|
14
|
+
id,
|
|
15
|
+
value = '',
|
|
16
|
+
name,
|
|
17
|
+
checked,
|
|
18
|
+
onChange,
|
|
19
|
+
disabled,
|
|
20
|
+
readOnly,
|
|
21
|
+
}: RadioButtonProps<T>) {
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<input
|
|
25
|
+
type="radio"
|
|
26
|
+
className="sr-only"
|
|
27
|
+
id={id}
|
|
28
|
+
value={value}
|
|
29
|
+
name={name}
|
|
30
|
+
checked={checked}
|
|
31
|
+
disabled={disabled || readOnly}
|
|
32
|
+
onChange={() => {
|
|
33
|
+
if (!checked) {
|
|
34
|
+
onChange?.(value);
|
|
35
|
+
}
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
<span className={classNames('tw-radio-button', { checked, disabled: disabled || readOnly })}>
|
|
39
|
+
<span className="tw-radio-check" />
|
|
40
|
+
</span>
|
|
41
|
+
</>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -6,11 +6,11 @@ jest.mock('@transferwise/formatting', () => ({
|
|
|
6
6
|
|
|
7
7
|
describe('getDayNames', () => {
|
|
8
8
|
it('returns all weekdays', () => {
|
|
9
|
-
expect(getDayNames()).toHaveLength(7);
|
|
9
|
+
expect(getDayNames('en')).toHaveLength(7);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
it('starts with Monday and ends with Sunday', () => {
|
|
13
|
-
const days = getDayNames();
|
|
13
|
+
const days = getDayNames('en');
|
|
14
14
|
expect(days[0]).toBe(1);
|
|
15
15
|
expect(days[days.length - 1]).toBe(0);
|
|
16
16
|
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { formatDate } from '@transferwise/formatting';
|
|
2
2
|
|
|
3
|
-
export function getDayNames(
|
|
4
|
-
|
|
3
|
+
export function getDayNames(
|
|
4
|
+
locale: string,
|
|
5
|
+
format: Intl.DateTimeFormatOptions['weekday'] = 'short',
|
|
6
|
+
) {
|
|
7
|
+
const days: string[] = [];
|
|
5
8
|
const date = new Date(2018, 0, 1); // 2018 started with Monday
|
|
6
9
|
while (days.length < 7) {
|
|
7
10
|
days.push(formatDate(date, locale, { weekday: format }));
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { getMonthNames } from '
|
|
2
|
-
|
|
3
|
-
jest.mock('@transferwise/formatting', () => ({
|
|
4
|
-
formatDate: (month) => month.getMonth(),
|
|
5
|
-
}));
|
|
1
|
+
import { getMonthNames } from './getMonthNames';
|
|
6
2
|
|
|
7
3
|
describe('getMonthNames', () => {
|
|
8
4
|
it('returns all months', () => {
|
|
@@ -10,8 +6,13 @@ describe('getMonthNames', () => {
|
|
|
10
6
|
});
|
|
11
7
|
|
|
12
8
|
it('starts with January and ends with December', () => {
|
|
13
|
-
const months = getMonthNames();
|
|
14
|
-
expect(months[0]).toBe(
|
|
15
|
-
expect(months
|
|
9
|
+
const months = getMonthNames('en', 'long');
|
|
10
|
+
expect(months[0]).toBe('January');
|
|
11
|
+
expect(months.at(-1)).toBe('December');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('gets localized month names', () => {
|
|
15
|
+
const months = getMonthNames('fr', 'long');
|
|
16
|
+
expect(months[0]).toBe('janvier');
|
|
16
17
|
});
|
|
17
18
|
});
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { formatDate } from '@transferwise/formatting';
|
|
2
2
|
|
|
3
|
-
export const getMonthNames = (
|
|
4
|
-
|
|
3
|
+
export const getMonthNames = (
|
|
4
|
+
locale: string,
|
|
5
|
+
format: Intl.DateTimeFormatOptions['month'] = 'long',
|
|
6
|
+
): string[] => {
|
|
7
|
+
const months: string[] = [];
|
|
5
8
|
const date = new Date(2018, 0, 1);
|
|
6
9
|
const monthFormat = { month: format };
|
|
7
10
|
while (months.length < 12) {
|
|
8
11
|
months.push(formatDate(date, locale, monthFormat));
|
|
9
12
|
date.setMonth(date.getMonth() + 1);
|
|
10
13
|
}
|
|
11
|
-
|
|
12
14
|
return months;
|
|
13
15
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const isDateValid = (date: Date | string | null) => {
|
|
2
|
+
if (date === null) {
|
|
3
|
+
return false;
|
|
4
|
+
} else if (date instanceof Date) {
|
|
5
|
+
return validDateObject(date);
|
|
6
|
+
} else {
|
|
7
|
+
return validDateString(date);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const validDateString = (dateString: string) => validDateObject(new Date(dateString));
|
|
12
|
+
|
|
13
|
+
const validDateObject = (dateObject: Date) => !isNaN(dateObject.getTime());
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { isMonthAndYearFormat } from '
|
|
1
|
+
import { isMonthAndYearFormat } from '..';
|
|
2
2
|
|
|
3
3
|
describe('isDateValid', () => {
|
|
4
|
-
it('should return false if day is provided', () => {
|
|
4
|
+
it('should return false if day is provided as string', () => {
|
|
5
5
|
expect(isMonthAndYearFormat('1998-02-04')).toBe(false);
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
it('should return true if day is not provided', () => {
|
|
8
|
+
it('should return true if day is not provided as string', () => {
|
|
9
9
|
expect(isMonthAndYearFormat('1998-02')).toBe(true);
|
|
10
10
|
});
|
|
11
|
-
|
|
12
|
-
it('should return false if argument provided is not a string', () => {
|
|
13
|
-
expect(isMonthAndYearFormat([])).toBe(false);
|
|
14
|
-
});
|
|
15
11
|
});
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { isWithinRange } from '..';
|
|
2
2
|
|
|
3
3
|
describe('isWithinRange', () => {
|
|
4
|
-
it('returns true when no dates are provided', () => {
|
|
5
|
-
expect(isWithinRange()).toBe(true);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it('returns true when no min and max', () => {
|
|
9
|
-
expect(isWithinRange(new Date())).toBe(true);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
4
|
it('returns true when date is between min and max', () => {
|
|
13
5
|
const date = new Date('1995-12-20');
|
|
14
6
|
const min = new Date('1995-12-19');
|
|
@@ -27,7 +19,6 @@ describe('isWithinRange', () => {
|
|
|
27
19
|
const date = new Date('1995-12-20');
|
|
28
20
|
const min = new Date('1995-12-21');
|
|
29
21
|
const max = new Date('1995-12-22');
|
|
30
|
-
expect(isWithinRange(date, min)).toBe(false);
|
|
31
22
|
expect(isWithinRange(date, min, max)).toBe(false);
|
|
32
23
|
});
|
|
33
24
|
|
|
@@ -35,7 +26,6 @@ describe('isWithinRange', () => {
|
|
|
35
26
|
const date = new Date('1995-12-23');
|
|
36
27
|
const min = new Date('1995-12-20');
|
|
37
28
|
const max = new Date('1995-12-22');
|
|
38
|
-
expect(isWithinRange(date, null, max)).toBe(false);
|
|
39
29
|
expect(isWithinRange(date, min, max)).toBe(false);
|
|
40
30
|
});
|
|
41
31
|
});
|
package/src/common/dateUtils/moveToWithinRange/{moveToWithinRange.js → moveToWithinRange.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isWithinRange } from '
|
|
1
|
+
import { isWithinRange } from '..';
|
|
2
2
|
|
|
3
3
|
// Makes sure that date is between min and max dates, returns a cloned min or max
|
|
4
|
-
export function moveToWithinRange(date, min, max) {
|
|
4
|
+
export function moveToWithinRange(date: Date, min: Date, max: Date) {
|
|
5
5
|
return isWithinRange(date, min, max) ? date : new Date(min && date < min ? +min : +max);
|
|
6
6
|
}
|
|
@@ -4,44 +4,12 @@ import { useIntl } from 'react-intl';
|
|
|
4
4
|
import { DateInput, Input } from '..';
|
|
5
5
|
import { mockMatchMedia, mockResizeObserver } from '../test-utils';
|
|
6
6
|
|
|
7
|
-
const MONTHS_FR = [
|
|
8
|
-
'janvier',
|
|
9
|
-
'février',
|
|
10
|
-
'mars',
|
|
11
|
-
'avril',
|
|
12
|
-
'mai',
|
|
13
|
-
'juin',
|
|
14
|
-
'juillet',
|
|
15
|
-
'août',
|
|
16
|
-
'septembre',
|
|
17
|
-
'octobre',
|
|
18
|
-
'novembre',
|
|
19
|
-
'décembre',
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const MONTHS_EN = [
|
|
23
|
-
'January',
|
|
24
|
-
'February',
|
|
25
|
-
'March',
|
|
26
|
-
'April',
|
|
27
|
-
'May',
|
|
28
|
-
'June',
|
|
29
|
-
'July',
|
|
30
|
-
'August',
|
|
31
|
-
'September',
|
|
32
|
-
'October',
|
|
33
|
-
'November',
|
|
34
|
-
'December',
|
|
35
|
-
];
|
|
36
|
-
|
|
37
7
|
const LOCALES = {
|
|
38
|
-
fr: 'fr-FR',
|
|
39
8
|
jp: 'ja-JP',
|
|
40
9
|
};
|
|
41
|
-
|
|
42
10
|
const DEFAULT_LOCALE = 'en-GB';
|
|
43
|
-
|
|
44
|
-
const
|
|
11
|
+
const FEBRUARY_INDEX = 1;
|
|
12
|
+
const AUGUST_INDEX = 7;
|
|
45
13
|
|
|
46
14
|
const DAY_SELECTOR = 'ForwardRef(Input)[name="day"]';
|
|
47
15
|
const MONTH_SELECTOR = 'SelectInput';
|
|
@@ -73,12 +41,6 @@ jest.mock('./DateInput.messages', () => ({
|
|
|
73
41
|
}));
|
|
74
42
|
|
|
75
43
|
jest.mock('react-intl');
|
|
76
|
-
jest.mock('@transferwise/formatting', () => {
|
|
77
|
-
return {
|
|
78
|
-
formatDate: (month, locale) =>
|
|
79
|
-
locale === LOCALES.fr ? MONTHS_FR[month.getMonth()] : MONTHS_EN[month.getMonth()],
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
44
|
|
|
83
45
|
describe('Date Input Component', () => {
|
|
84
46
|
let selectMonth;
|
|
@@ -111,7 +73,7 @@ describe('Date Input Component', () => {
|
|
|
111
73
|
});
|
|
112
74
|
|
|
113
75
|
it('sets month field to 0', () => {
|
|
114
|
-
expect(selectMonth.props().value).
|
|
76
|
+
expect(selectMonth.props().value).toBeNull();
|
|
115
77
|
});
|
|
116
78
|
|
|
117
79
|
it('sets year field to empty', () => {
|
|
@@ -143,7 +105,7 @@ describe('Date Input Component', () => {
|
|
|
143
105
|
inputYear = component.find(YEAR_SELECTOR);
|
|
144
106
|
|
|
145
107
|
expect(inputDay.prop('value')).toBe(1);
|
|
146
|
-
expect(selectMonth.prop('value')
|
|
108
|
+
expect(selectMonth.prop('value')).toBe(FEBRUARY_INDEX);
|
|
147
109
|
expect(inputYear.prop('value')).toBe(1971);
|
|
148
110
|
});
|
|
149
111
|
});
|
|
@@ -157,7 +119,7 @@ describe('Date Input Component', () => {
|
|
|
157
119
|
inputYear = component.find(YEAR_SELECTOR);
|
|
158
120
|
|
|
159
121
|
expect(inputDay.prop('value')).toBe(22);
|
|
160
|
-
expect(selectMonth.prop('value')
|
|
122
|
+
expect(selectMonth.prop('value')).toBe(AUGUST_INDEX);
|
|
161
123
|
expect(inputYear.prop('value')).toBe(1990);
|
|
162
124
|
});
|
|
163
125
|
});
|
|
@@ -171,7 +133,7 @@ describe('Date Input Component', () => {
|
|
|
171
133
|
inputYear = component.find(YEAR_SELECTOR);
|
|
172
134
|
|
|
173
135
|
expect(inputDay.prop('value')).toBe('');
|
|
174
|
-
expect(selectMonth.prop('value')
|
|
136
|
+
expect(selectMonth.prop('value')).toBe(AUGUST_INDEX);
|
|
175
137
|
expect(inputYear.prop('value')).toBe(1990);
|
|
176
138
|
});
|
|
177
139
|
});
|
|
@@ -185,7 +147,7 @@ describe('Date Input Component', () => {
|
|
|
185
147
|
inputYear = component.find(YEAR_SELECTOR);
|
|
186
148
|
|
|
187
149
|
expect(inputDay.prop('value')).toBe(28);
|
|
188
|
-
expect(selectMonth.prop('value')
|
|
150
|
+
expect(selectMonth.prop('value')).toBe(FEBRUARY_INDEX);
|
|
189
151
|
expect(inputYear.prop('value')).toBe(1990);
|
|
190
152
|
});
|
|
191
153
|
});
|
|
@@ -220,17 +182,6 @@ describe('Date Input Component', () => {
|
|
|
220
182
|
});
|
|
221
183
|
|
|
222
184
|
describe('when locale is provided', () => {
|
|
223
|
-
it('updates selectMonth based on locale', () => {
|
|
224
|
-
useIntl.mockReturnValue({
|
|
225
|
-
locale: LOCALES.fr,
|
|
226
|
-
formatMessage: (message) => message.defaultMessage,
|
|
227
|
-
});
|
|
228
|
-
component = shallow(<DateInput {...props} />);
|
|
229
|
-
selectMonth = component.find(MONTH_SELECTOR);
|
|
230
|
-
|
|
231
|
-
expect(selectMonth.props().items[0].value.label).toStrictEqual(MONTHS_FR[0]);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
185
|
it('shows day before month if locale not US', () => {
|
|
235
186
|
component = shallow(<DateInput {...props} />);
|
|
236
187
|
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Meta, StoryObj } from '@storybook/react';
|
|
2
2
|
import { userEvent, within } from '@storybook/test';
|
|
3
|
+
import * as React from 'react';
|
|
3
4
|
|
|
4
|
-
import { DateInput, Info, InlineAlert, Title, Typography } from '..';
|
|
5
|
+
import { DateInput, DateMode, Info, InlineAlert, Title, Typography } from '..';
|
|
5
6
|
import { lorem10, storyConfig } from '../test-utils';
|
|
6
7
|
|
|
8
|
+
import { DateInputProps } from './DateInput';
|
|
9
|
+
|
|
7
10
|
export default {
|
|
8
11
|
component: DateInput,
|
|
9
12
|
title: 'Forms/DateInput',
|
|
@@ -14,17 +17,15 @@ export default {
|
|
|
14
17
|
yearLabel: 'Year input',
|
|
15
18
|
yearAutoComplete: 'bday-year',
|
|
16
19
|
selectProps: {
|
|
17
|
-
|
|
18
|
-
'aria-label': 'Select month',
|
|
19
|
-
},
|
|
20
|
+
placeholder: 'Month',
|
|
20
21
|
},
|
|
21
22
|
},
|
|
22
23
|
tags: ['autodocs'],
|
|
23
24
|
} satisfies Meta<typeof DateInput>;
|
|
24
25
|
|
|
25
|
-
type Story = StoryObj<
|
|
26
|
+
type Story = StoryObj<DateInputProps>;
|
|
26
27
|
|
|
27
|
-
export const Basic:
|
|
28
|
+
export const Basic: StoryObj = {};
|
|
28
29
|
|
|
29
30
|
Basic.play = async ({ canvasElement }) => {
|
|
30
31
|
const canvas = within(canvasElement);
|
|
@@ -65,8 +66,10 @@ export const WithLabel: Story = {
|
|
|
65
66
|
label (rare use case)
|
|
66
67
|
</Title>
|
|
67
68
|
<fieldset>
|
|
68
|
-
<legend className="control-label">
|
|
69
|
-
|
|
69
|
+
<legend className="control-label">
|
|
70
|
+
Expiry Date for Credit Card (example of MONTH_YEAR mode)
|
|
71
|
+
</legend>
|
|
72
|
+
<DateInput {...args} mode={DateMode.MONTH_YEAR} />
|
|
70
73
|
</fieldset>
|
|
71
74
|
</>
|
|
72
75
|
);
|