@transferwise/components 0.0.0-experimental-c59c986 → 0.0.0-experimental-7025851
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 +57 -54
- package/build/index.esm.js.map +1 -1
- package/build/index.js +59 -56
- package/build/index.js.map +1 -1
- package/build/main.css +1 -1
- package/build/styles/dateLookup/DateLookup.css +1 -1
- package/build/styles/main.css +1 -1
- package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts +8 -1
- package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts.map +1 -1
- package/build/types/dateLookup/tableLink/TableLink.d.ts +2 -6
- package/build/types/dateLookup/tableLink/TableLink.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 +3 -3
- package/src/dateInput/DateInput.js +8 -8
- package/src/dateInput/DateInput.spec.js +12 -136
- package/src/dateInput/DateInput.story.tsx +6 -1
- package/src/dateLookup/DateLookup.css +1 -1
- package/src/dateLookup/DateLookup.less +2 -6
- package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +6 -1
- package/src/dateLookup/getFocusableTime/getFocusable.spec.ts +40 -0
- package/src/dateLookup/getFocusableTime/getFocusableTime.tsx +12 -26
- package/src/dateLookup/monthCalendar/table/MonthCalendarTable.js +3 -3
- package/src/dateLookup/tableLink/TableLink.spec.js +6 -15
- package/src/dateLookup/tableLink/TableLink.tsx +6 -7
- package/src/dateLookup/yearCalendar/table/YearCalendarTable.js +2 -2
- 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/src/dateLookup/getFocusableTime/getFocusable.spec.js +0 -38
package/build/index.esm.js
CHANGED
|
@@ -7,19 +7,19 @@ import { ChevronUp, CrossCircleFill, Cross, NavigateAway, Check, Info as Info$1,
|
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import { defineMessages, useIntl, injectIntl, IntlProvider } from 'react-intl';
|
|
9
9
|
import { useTheme, ThemeProvider } from '@wise/components-theming';
|
|
10
|
-
import { formatDate, formatNumber, formatMoney, formatAmount } from '@transferwise/formatting';
|
|
11
|
-
import throttle from 'lodash.throttle';
|
|
12
|
-
import { CSSTransition } from 'react-transition-group';
|
|
13
|
-
import { createPortal } from 'react-dom';
|
|
14
|
-
import { FocusScope } from '@react-aria/focus';
|
|
15
|
-
import mergeRefs from 'react-merge-refs';
|
|
16
|
-
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
17
|
-
import { isUndefined, isKey, isNumber, isEmpty, isNull, isArray } from '@transferwise/neptune-validation';
|
|
18
|
-
import { usePopper } from 'react-popper';
|
|
19
10
|
import { Transition, Listbox } from '@headlessui/react';
|
|
20
11
|
import mergeProps from 'merge-props';
|
|
12
|
+
import mergeRefs from 'react-merge-refs';
|
|
13
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
21
14
|
import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager, offset, flip, shift, size, autoUpdate } from '@floating-ui/react';
|
|
15
|
+
import { FocusScope } from '@react-aria/focus';
|
|
22
16
|
import { usePreventScroll } from '@react-aria/overlays';
|
|
17
|
+
import { formatDate, formatNumber, formatMoney, formatAmount } from '@transferwise/formatting';
|
|
18
|
+
import { CSSTransition } from 'react-transition-group';
|
|
19
|
+
import { usePopper } from 'react-popper';
|
|
20
|
+
import throttle from 'lodash.throttle';
|
|
21
|
+
import { createPortal } from 'react-dom';
|
|
22
|
+
import { isUndefined, isKey, isNumber, isEmpty, isNull, isArray } from '@transferwise/neptune-validation';
|
|
23
23
|
import { Illustration } from '@wise/art';
|
|
24
24
|
import clamp$2 from 'lodash.clamp';
|
|
25
25
|
import debounce from 'lodash.debounce';
|
|
@@ -2965,22 +2965,24 @@ const DateInput = ({
|
|
|
2965
2965
|
}
|
|
2966
2966
|
};
|
|
2967
2967
|
const getSelectElement = () => {
|
|
2968
|
-
const
|
|
2968
|
+
const monthOptions = getMonthsOptions();
|
|
2969
2969
|
return /*#__PURE__*/jsxs("label", {
|
|
2970
|
+
className: "d-flex flex-column",
|
|
2970
2971
|
children: [/*#__PURE__*/jsx("span", {
|
|
2971
2972
|
className: "sr-only",
|
|
2972
2973
|
children: monthLabel
|
|
2973
|
-
}), /*#__PURE__*/jsx(
|
|
2974
|
-
id: id ? `${id}-select` : undefined,
|
|
2974
|
+
}), /*#__PURE__*/jsx(SelectInput, {
|
|
2975
2975
|
name: "month",
|
|
2976
2976
|
disabled: disabled,
|
|
2977
2977
|
placeholder: placeholders.month,
|
|
2978
|
-
|
|
2978
|
+
items: monthOptions,
|
|
2979
2979
|
size: size,
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
label
|
|
2983
|
-
},
|
|
2980
|
+
value: monthOptions.find(item => item.value.value === month)?.value,
|
|
2981
|
+
renderValue: ({
|
|
2982
|
+
label
|
|
2983
|
+
}) => /*#__PURE__*/jsx(SelectInputOptionContent, {
|
|
2984
|
+
title: label
|
|
2985
|
+
}),
|
|
2984
2986
|
onChange: selectedValue => handleMonthChange(selectedValue),
|
|
2985
2987
|
...selectProps
|
|
2986
2988
|
})]
|
|
@@ -2991,8 +2993,11 @@ const DateInput = ({
|
|
|
2991
2993
|
const months = getMonthNames(locale, monthFormat);
|
|
2992
2994
|
months.forEach((label, index) => {
|
|
2993
2995
|
options.push({
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
+
type: 'option',
|
|
2997
|
+
value: {
|
|
2998
|
+
label,
|
|
2999
|
+
value: index
|
|
3000
|
+
}
|
|
2996
3001
|
});
|
|
2997
3002
|
});
|
|
2998
3003
|
return options;
|
|
@@ -3570,26 +3575,8 @@ DateHeader.defaultProps = {
|
|
|
3570
3575
|
};
|
|
3571
3576
|
var DateHeader$1 = DateHeader;
|
|
3572
3577
|
|
|
3573
|
-
function getFocusableTime(
|
|
3574
|
-
|
|
3575
|
-
let now = null;
|
|
3576
|
-
let disabled = null;
|
|
3577
|
-
for (const time of timeSpan) {
|
|
3578
|
-
if (isSelected(time)) {
|
|
3579
|
-
selected = time;
|
|
3580
|
-
break;
|
|
3581
|
-
}
|
|
3582
|
-
if (isNow(time)) {
|
|
3583
|
-
now = time;
|
|
3584
|
-
}
|
|
3585
|
-
if (!isDisabled(time) && disabled === null) {
|
|
3586
|
-
disabled = time;
|
|
3587
|
-
}
|
|
3588
|
-
if (selected) {
|
|
3589
|
-
break;
|
|
3590
|
-
}
|
|
3591
|
-
}
|
|
3592
|
-
return selected || now || disabled;
|
|
3578
|
+
function getFocusableTime(props) {
|
|
3579
|
+
return props.timeSpan.find(time => props.isActive(time)) || props.timeSpan.find(time => props.isNow(time) && !props.isDisabled(time)) || props.timeSpan.find(time => !props.isDisabled(time));
|
|
3593
3580
|
}
|
|
3594
3581
|
|
|
3595
3582
|
// NB! Using with UTC timestamp (YYYY-MM-DD) might lead to unexpected results, for example
|
|
@@ -3612,12 +3599,10 @@ const TableLink = ({
|
|
|
3612
3599
|
disabled,
|
|
3613
3600
|
today,
|
|
3614
3601
|
autofocus,
|
|
3615
|
-
onClick
|
|
3616
|
-
intl: {
|
|
3617
|
-
formatMessage
|
|
3618
|
-
}
|
|
3602
|
+
onClick
|
|
3619
3603
|
}) => {
|
|
3620
3604
|
const buttonRef = useRef(null);
|
|
3605
|
+
const intl = useIntl();
|
|
3621
3606
|
useEffect(() => {
|
|
3622
3607
|
if (autofocus) {
|
|
3623
3608
|
setTimeout(() => {
|
|
@@ -3633,7 +3618,7 @@ const TableLink = ({
|
|
|
3633
3618
|
};
|
|
3634
3619
|
const calculateAriaLabel = () => {
|
|
3635
3620
|
if (active) {
|
|
3636
|
-
return `${longTitle || title || ''}, ${formatMessage(messages$6.selected)} ${formatMessage(messages$6[type])}`;
|
|
3621
|
+
return `${longTitle || title || ''}, ${intl.formatMessage(messages$6.selected)} ${intl.formatMessage(messages$6[type])}`;
|
|
3637
3622
|
}
|
|
3638
3623
|
return longTitle || title;
|
|
3639
3624
|
};
|
|
@@ -3655,7 +3640,6 @@ const TableLink = ({
|
|
|
3655
3640
|
})
|
|
3656
3641
|
});
|
|
3657
3642
|
};
|
|
3658
|
-
var TableLink$1 = injectIntl(TableLink);
|
|
3659
3643
|
|
|
3660
3644
|
const SHORT_DAY_FORMAT = {
|
|
3661
3645
|
day: 'numeric'
|
|
@@ -3735,7 +3719,12 @@ class DayCalendarTable extends PureComponent {
|
|
|
3735
3719
|
};
|
|
3736
3720
|
getAutofocusDay = weeks => {
|
|
3737
3721
|
const days = weeks.flatMap(week => week);
|
|
3738
|
-
return getFocusableTime(
|
|
3722
|
+
return getFocusableTime({
|
|
3723
|
+
isActive: this.isActive,
|
|
3724
|
+
isNow: this.isToday,
|
|
3725
|
+
isDisabled: this.isDisabled,
|
|
3726
|
+
timeSpan: days
|
|
3727
|
+
});
|
|
3739
3728
|
};
|
|
3740
3729
|
render() {
|
|
3741
3730
|
const {
|
|
@@ -3772,7 +3761,7 @@ class DayCalendarTable extends PureComponent {
|
|
|
3772
3761
|
children: weeks.map((week, weekIndex) => /*#__PURE__*/jsx("tr", {
|
|
3773
3762
|
children: week.map((day, dayIndex) => /*#__PURE__*/jsx("td", {
|
|
3774
3763
|
className: dayIndex > 4 ? 'default' : '',
|
|
3775
|
-
children: day && /*#__PURE__*/jsx(TableLink
|
|
3764
|
+
children: day && /*#__PURE__*/jsx(TableLink, {
|
|
3776
3765
|
item: day,
|
|
3777
3766
|
type: "day",
|
|
3778
3767
|
title: formatDate(new Date(viewYear, viewMonth, day), locale, SHORT_DAY_FORMAT),
|
|
@@ -3896,18 +3885,18 @@ const MonthCalendarTable = ({
|
|
|
3896
3885
|
locale
|
|
3897
3886
|
} = useIntl();
|
|
3898
3887
|
const getLink = month => {
|
|
3899
|
-
return /*#__PURE__*/jsx(TableLink
|
|
3888
|
+
return /*#__PURE__*/jsx(TableLink, {
|
|
3900
3889
|
item: month,
|
|
3901
3890
|
type: "month",
|
|
3902
3891
|
title: formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAT),
|
|
3903
|
-
active:
|
|
3892
|
+
active: isActive(month),
|
|
3904
3893
|
disabled: isDisabled(month),
|
|
3905
3894
|
today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
|
|
3906
3895
|
autofocus: autofocusMonth === month,
|
|
3907
3896
|
onClick: onSelect
|
|
3908
3897
|
});
|
|
3909
3898
|
};
|
|
3910
|
-
const
|
|
3899
|
+
const isActive = month => {
|
|
3911
3900
|
return selectedDate && month === selectedDate.getMonth() && viewYear === selectedDate.getFullYear();
|
|
3912
3901
|
};
|
|
3913
3902
|
const isThisMonth = month => {
|
|
@@ -3919,7 +3908,12 @@ const MonthCalendarTable = ({
|
|
|
3919
3908
|
};
|
|
3920
3909
|
const autofocusMonth = (() => {
|
|
3921
3910
|
const months = [...new Array(ROWS$1 * COLS$1)].map((_, index) => index);
|
|
3922
|
-
return getFocusableTime(
|
|
3911
|
+
return getFocusableTime({
|
|
3912
|
+
isActive,
|
|
3913
|
+
isNow: isThisMonth,
|
|
3914
|
+
isDisabled,
|
|
3915
|
+
timeSpan: months
|
|
3916
|
+
});
|
|
3923
3917
|
})();
|
|
3924
3918
|
return /*#__PURE__*/jsxs("table", {
|
|
3925
3919
|
className: "table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0",
|
|
@@ -4040,7 +4034,7 @@ const YearCalendarTable = ({
|
|
|
4040
4034
|
} = useIntl();
|
|
4041
4035
|
const startYear = viewYear - viewYear % 20;
|
|
4042
4036
|
const getLink = year => {
|
|
4043
|
-
return /*#__PURE__*/jsx(TableLink
|
|
4037
|
+
return /*#__PURE__*/jsx(TableLink, {
|
|
4044
4038
|
item: year,
|
|
4045
4039
|
type: "year",
|
|
4046
4040
|
title: formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
|
|
@@ -4051,7 +4045,7 @@ const YearCalendarTable = ({
|
|
|
4051
4045
|
onClick: onSelect
|
|
4052
4046
|
});
|
|
4053
4047
|
};
|
|
4054
|
-
const
|
|
4048
|
+
const isActive = year => {
|
|
4055
4049
|
return selectedDate && year === selectedDate.getFullYear();
|
|
4056
4050
|
};
|
|
4057
4051
|
const isThisYear = year => {
|
|
@@ -4062,7 +4056,12 @@ const YearCalendarTable = ({
|
|
|
4062
4056
|
};
|
|
4063
4057
|
const autofocusYear = (() => {
|
|
4064
4058
|
const years = [...new Array(ROWS * COLS)].map((_, index) => startYear + index);
|
|
4065
|
-
return getFocusableTime(
|
|
4059
|
+
return getFocusableTime({
|
|
4060
|
+
isActive,
|
|
4061
|
+
isNow: isThisYear,
|
|
4062
|
+
isDisabled,
|
|
4063
|
+
timeSpan: years
|
|
4064
|
+
});
|
|
4066
4065
|
})();
|
|
4067
4066
|
return /*#__PURE__*/jsxs("table", {
|
|
4068
4067
|
className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
|
|
@@ -7921,6 +7920,10 @@ const getUniqueIdForOption = (parentId = '', option) => {
|
|
|
7921
7920
|
const uniqueOptionId = option.value || (option.label?.replace(/\s/g, '') ?? '');
|
|
7922
7921
|
return `option-${parentId}-${uniqueOptionId}`;
|
|
7923
7922
|
};
|
|
7923
|
+
|
|
7924
|
+
/**
|
|
7925
|
+
* @deprecated Use `SelectInput` instead (https://neptune.wise.design/blog/2023-11-28-adopting-our-new-selectinput)
|
|
7926
|
+
*/
|
|
7924
7927
|
function Select({
|
|
7925
7928
|
placeholder,
|
|
7926
7929
|
id,
|