@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
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
import { shallow, mount } from 'enzyme';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
3
|
|
|
4
|
+
import { mockMatchMedia, mockResizeObserver } from '../test-utils';
|
|
5
|
+
|
|
4
6
|
import PhoneNumberInput from '.';
|
|
5
7
|
|
|
6
8
|
jest.mock('react-intl');
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
value: jest.fn().mockImplementation((query) => ({
|
|
11
|
-
matches: false,
|
|
12
|
-
media: query,
|
|
13
|
-
onchange: null,
|
|
14
|
-
addListener: jest.fn(), // Deprecated
|
|
15
|
-
removeListener: jest.fn(), // Deprecated
|
|
16
|
-
addEventListener: jest.fn(),
|
|
17
|
-
removeEventListener: jest.fn(),
|
|
18
|
-
dispatchEvent: jest.fn(),
|
|
19
|
-
})),
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
class ResizeObserver {
|
|
23
|
-
observe() {}
|
|
24
|
-
unobserve() {}
|
|
25
|
-
}
|
|
10
|
+
mockMatchMedia();
|
|
11
|
+
mockResizeObserver();
|
|
26
12
|
|
|
27
13
|
const simulatePaste = (element, value) =>
|
|
28
14
|
element.simulate('paste', { nativeEvent: { clipboardData: { getData: () => value } } });
|
|
@@ -112,8 +98,6 @@ describe('Given a telephone number component', () => {
|
|
|
112
98
|
});
|
|
113
99
|
|
|
114
100
|
describe('when pasting', () => {
|
|
115
|
-
window.ResizeObserver = ResizeObserver;
|
|
116
|
-
|
|
117
101
|
beforeEach(() => {
|
|
118
102
|
component = mount(<PhoneNumberInput {...props} initialValue="+39123456789" />);
|
|
119
103
|
select = () => component.find(PREFIX_SELECT_SELECTOR);
|
package/src/select/Select.js
CHANGED
|
@@ -76,6 +76,9 @@ const getUniqueIdForOption = (parentId = '', option) => {
|
|
|
76
76
|
return `option-${parentId}-${uniqueOptionId}`;
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use `SelectInput` instead (https://neptune.wise.design/blog/2023-11-28-adopting-our-new-selectinput)
|
|
81
|
+
*/
|
|
79
82
|
export default function Select({
|
|
80
83
|
placeholder,
|
|
81
84
|
id,
|
|
@@ -17,3 +17,14 @@ export function mockMatchMedia() {
|
|
|
17
17
|
}),
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
export function mockResizeObserver() {
|
|
22
|
+
// mock ResizeObserver because it's not implemented in jsdoc lib
|
|
23
|
+
// https://github.com/jsdom/jsdom/issues/3368
|
|
24
|
+
// eslint-disable-next-line compat/compat
|
|
25
|
+
window.ResizeObserver = class ResizeObserver {
|
|
26
|
+
observe = jest.fn();
|
|
27
|
+
unobserve = jest.fn();
|
|
28
|
+
disconnect = jest.fn();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFocusableTime.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/getFocusableTime/getFocusableTime.tsx"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EACrC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EAChC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,EACrC,QAAQ,EAAE,MAAM,EAAE,GACjB,MAAM,GAAG,IAAI,CAsBf"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { getFocusableTime } from './getFocusableTime';
|
|
2
|
-
|
|
3
|
-
describe('getFocusableTime', () => {
|
|
4
|
-
const isSelected = (value) => value === 2;
|
|
5
|
-
const isNow = (value) => value === 3;
|
|
6
|
-
const isDisabled = (value) => value === 4;
|
|
7
|
-
const values = [1, 2, 3, 4, 5];
|
|
8
|
-
|
|
9
|
-
it('returns first selected value', () => {
|
|
10
|
-
expect(getFocusableTime(isSelected, isNow, isDisabled, values)).toBe(2);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('returns first now value if nothing is selected', () => {
|
|
14
|
-
expect(getFocusableTime(() => false, isNow, isDisabled, values)).toBe(3);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('returns first non disabled value when nothing is selected or now', () => {
|
|
18
|
-
expect(
|
|
19
|
-
getFocusableTime(
|
|
20
|
-
() => false,
|
|
21
|
-
() => false,
|
|
22
|
-
isDisabled,
|
|
23
|
-
values,
|
|
24
|
-
),
|
|
25
|
-
).toBe(1);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('returns null if no selected, now, or non-disabled', () => {
|
|
29
|
-
expect(
|
|
30
|
-
getFocusableTime(
|
|
31
|
-
() => false,
|
|
32
|
-
() => false,
|
|
33
|
-
() => true,
|
|
34
|
-
values,
|
|
35
|
-
),
|
|
36
|
-
).toBeNull();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export function getFocusableTime(
|
|
2
|
-
isSelected: (time: number) => boolean,
|
|
3
|
-
isNow: (time: number) => boolean,
|
|
4
|
-
isDisabled: (time: number) => boolean,
|
|
5
|
-
timeSpan: number[],
|
|
6
|
-
): number | null {
|
|
7
|
-
let selected: number | null = null;
|
|
8
|
-
let now: number | null = null;
|
|
9
|
-
let disabled: number | null = null;
|
|
10
|
-
|
|
11
|
-
for (const time of timeSpan) {
|
|
12
|
-
if (isSelected(time)) {
|
|
13
|
-
selected = time;
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
16
|
-
if (isNow(time)) {
|
|
17
|
-
now = time;
|
|
18
|
-
}
|
|
19
|
-
if (!isDisabled(time) && disabled === null) {
|
|
20
|
-
disabled = time;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (selected) {
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return selected || now || disabled;
|
|
28
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import classNames from 'classnames';
|
|
2
|
-
import { useEffect, useRef } from 'react';
|
|
3
|
-
import { injectIntl, IntlShape } from 'react-intl';
|
|
4
|
-
|
|
5
|
-
import messages from '../DateLookup.messages';
|
|
6
|
-
|
|
7
|
-
interface TableLinkProps {
|
|
8
|
-
item: number;
|
|
9
|
-
type: 'day' | 'month' | 'year';
|
|
10
|
-
title?: string;
|
|
11
|
-
longTitle?: string;
|
|
12
|
-
active: boolean;
|
|
13
|
-
disabled: boolean;
|
|
14
|
-
today: boolean;
|
|
15
|
-
autofocus?: boolean;
|
|
16
|
-
onClick: (item: number) => void;
|
|
17
|
-
intl: IntlShape;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const TableLink = ({
|
|
21
|
-
item,
|
|
22
|
-
type,
|
|
23
|
-
title,
|
|
24
|
-
longTitle,
|
|
25
|
-
active,
|
|
26
|
-
disabled,
|
|
27
|
-
today,
|
|
28
|
-
autofocus,
|
|
29
|
-
onClick,
|
|
30
|
-
intl: { formatMessage },
|
|
31
|
-
}: TableLinkProps) => {
|
|
32
|
-
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (autofocus) {
|
|
36
|
-
setTimeout(() => {
|
|
37
|
-
buttonRef.current?.focus();
|
|
38
|
-
}, 0);
|
|
39
|
-
}
|
|
40
|
-
}, [autofocus]);
|
|
41
|
-
|
|
42
|
-
const onCalendarClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
43
|
-
event.preventDefault();
|
|
44
|
-
if (!disabled) {
|
|
45
|
-
onClick(item);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const calculateAriaLabel = () => {
|
|
50
|
-
if (active) {
|
|
51
|
-
return `${longTitle || title || ''}, ${formatMessage(messages.selected)} ${formatMessage(
|
|
52
|
-
messages[type],
|
|
53
|
-
)}`;
|
|
54
|
-
}
|
|
55
|
-
return longTitle || title;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<>
|
|
60
|
-
<button
|
|
61
|
-
ref={buttonRef}
|
|
62
|
-
type="button"
|
|
63
|
-
className={classNames(
|
|
64
|
-
`tw-date-lookup-${type}-option np-text-body-default-bold`,
|
|
65
|
-
{ active: !!active },
|
|
66
|
-
{ today: !!today },
|
|
67
|
-
)}
|
|
68
|
-
disabled={disabled}
|
|
69
|
-
tabIndex={autofocus ? 0 : -1}
|
|
70
|
-
aria-label={calculateAriaLabel()}
|
|
71
|
-
aria-pressed={active}
|
|
72
|
-
onClick={onCalendarClick}
|
|
73
|
-
>
|
|
74
|
-
{title || item}
|
|
75
|
-
</button>
|
|
76
|
-
</>
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export default injectIntl(TableLink);
|
|
File without changes
|