@transferwise/components 0.0.0-experimental-8f9699a → 0.0.0-experimental-a25e4d8
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 +75 -152
- package/build/index.esm.js.map +1 -1
- package/build/index.js +75 -152
- package/build/index.js.map +1 -1
- package/build/main.css +1 -1
- package/build/styles/chips/Chip.css +1 -1
- package/build/styles/dateLookup/DateLookup.css +1 -1
- package/build/styles/main.css +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 +4 -14
- 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/package.json +2 -2
- package/src/chips/Chip.css +1 -1
- package/src/chips/Chip.less +9 -21
- package/src/dateLookup/DateLookup.css +1 -1
- package/src/dateLookup/DateLookup.js +4 -19
- package/src/dateLookup/DateLookup.keyboardEvents.spec.js +0 -12
- package/src/dateLookup/DateLookup.less +49 -39
- package/src/dateLookup/DateLookup.story.js +7 -8
- package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +3 -28
- 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/tableLink/TableLink.spec.js +15 -6
- package/src/dateLookup/yearCalendar/table/YearCalendarTable.js +11 -33
- package/src/dateLookup/yearCalendar/table/YearCalendarTable.spec.js +0 -26
- package/src/main.css +1 -1
- package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts +0 -9
- package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts.map +0 -1
- package/src/dateLookup/getFocusableTime/getFocusable.spec.ts +0 -40
- package/src/dateLookup/getFocusableTime/getFocusableTime.tsx +0 -14
- package/src/dateLookup/tableLink/TableLink.tsx +0 -79
- /package/src/dateLookup/tableLink/{index.ts → index.js} +0 -0
package/build/index.esm.js
CHANGED
|
@@ -3575,10 +3575,6 @@ DateHeader.defaultProps = {
|
|
|
3575
3575
|
};
|
|
3576
3576
|
var DateHeader$1 = DateHeader;
|
|
3577
3577
|
|
|
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));
|
|
3580
|
-
}
|
|
3581
|
-
|
|
3582
3578
|
// NB! Using with UTC timestamp (YYYY-MM-DD) might lead to unexpected results, for example
|
|
3583
3579
|
// getStartOfDay(new Date('1995-01-01')) in Los Angeles returns 31 Dec 1994, but in
|
|
3584
3580
|
// in Singapore it is 1 Jan 1995.
|
|
@@ -3590,56 +3586,61 @@ function getStartOfDay(date) {
|
|
|
3590
3586
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
3591
3587
|
}
|
|
3592
3588
|
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
type,
|
|
3596
|
-
title,
|
|
3597
|
-
longTitle,
|
|
3598
|
-
active,
|
|
3599
|
-
disabled,
|
|
3600
|
-
today,
|
|
3601
|
-
autofocus,
|
|
3602
|
-
onClick
|
|
3603
|
-
}) => {
|
|
3604
|
-
const buttonRef = useRef(null);
|
|
3605
|
-
const intl = useIntl();
|
|
3606
|
-
useEffect(() => {
|
|
3607
|
-
if (autofocus) {
|
|
3608
|
-
setTimeout(() => {
|
|
3609
|
-
buttonRef.current?.focus();
|
|
3610
|
-
}, 0);
|
|
3611
|
-
}
|
|
3612
|
-
}, [autofocus]);
|
|
3613
|
-
const onCalendarClick = event => {
|
|
3589
|
+
class TableLink extends PureComponent {
|
|
3590
|
+
onClick = event => {
|
|
3614
3591
|
event.preventDefault();
|
|
3615
|
-
if (!disabled) {
|
|
3616
|
-
onClick(item);
|
|
3592
|
+
if (!this.props.disabled) {
|
|
3593
|
+
this.props.onClick(this.props.item);
|
|
3617
3594
|
}
|
|
3618
3595
|
};
|
|
3619
|
-
|
|
3596
|
+
calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
|
|
3620
3597
|
if (active) {
|
|
3621
|
-
return `${longTitle || title
|
|
3598
|
+
return `${longTitle || title}, ${formatMessage(messages$6.selected)} ${formatMessage(messages$6[type])}`;
|
|
3622
3599
|
}
|
|
3623
3600
|
return longTitle || title;
|
|
3624
3601
|
};
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
type
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
children:
|
|
3640
|
-
|
|
3641
|
-
|
|
3602
|
+
render() {
|
|
3603
|
+
const {
|
|
3604
|
+
item,
|
|
3605
|
+
type,
|
|
3606
|
+
title,
|
|
3607
|
+
longTitle,
|
|
3608
|
+
active,
|
|
3609
|
+
disabled,
|
|
3610
|
+
today,
|
|
3611
|
+
intl: {
|
|
3612
|
+
formatMessage
|
|
3613
|
+
}
|
|
3614
|
+
} = this.props;
|
|
3615
|
+
return /*#__PURE__*/jsx(Fragment, {
|
|
3616
|
+
children: /*#__PURE__*/jsx("button", {
|
|
3617
|
+
type: "button",
|
|
3618
|
+
className: `tw-date-lookup-${type}-option ${active ? 'active' : ''} ${today ? 'today' : ''} np-text-body-default-bold`,
|
|
3619
|
+
disabled: disabled,
|
|
3620
|
+
"aria-label": this.calculateAriaLabel(longTitle, title, active, type, formatMessage),
|
|
3621
|
+
"aria-pressed": active,
|
|
3622
|
+
onClick: this.onClick,
|
|
3623
|
+
children: title || item
|
|
3624
|
+
})
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
TableLink.propTypes = {
|
|
3629
|
+
item: PropTypes.number.isRequired,
|
|
3630
|
+
// day (1-31), month (0-11) or year (2018 etc)
|
|
3631
|
+
type: PropTypes.oneOf(['day', 'month', 'year']).isRequired,
|
|
3632
|
+
title: PropTypes.string,
|
|
3633
|
+
longTitle: PropTypes.string,
|
|
3634
|
+
active: PropTypes.bool.isRequired,
|
|
3635
|
+
disabled: PropTypes.bool.isRequired,
|
|
3636
|
+
today: PropTypes.bool.isRequired,
|
|
3637
|
+
onClick: PropTypes.func.isRequired
|
|
3642
3638
|
};
|
|
3639
|
+
TableLink.defaultProps = {
|
|
3640
|
+
title: null,
|
|
3641
|
+
longTitle: null
|
|
3642
|
+
};
|
|
3643
|
+
var TableLink$1 = injectIntl(TableLink);
|
|
3643
3644
|
|
|
3644
3645
|
const SHORT_DAY_FORMAT = {
|
|
3645
3646
|
day: 'numeric'
|
|
@@ -3710,22 +3711,6 @@ class DayCalendarTable extends PureComponent {
|
|
|
3710
3711
|
} = this.props;
|
|
3711
3712
|
return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
|
|
3712
3713
|
};
|
|
3713
|
-
isToday = day => {
|
|
3714
|
-
const {
|
|
3715
|
-
viewMonth,
|
|
3716
|
-
viewYear
|
|
3717
|
-
} = this.props;
|
|
3718
|
-
return Number(getStartOfDay(new Date())) === Number(new Date(viewYear, viewMonth, day));
|
|
3719
|
-
};
|
|
3720
|
-
getAutofocusDay = weeks => {
|
|
3721
|
-
const days = weeks.flatMap(week => week);
|
|
3722
|
-
return getFocusableTime({
|
|
3723
|
-
isActive: this.isActive,
|
|
3724
|
-
isNow: this.isToday,
|
|
3725
|
-
isDisabled: this.isDisabled,
|
|
3726
|
-
timeSpan: days
|
|
3727
|
-
});
|
|
3728
|
-
};
|
|
3729
3714
|
render() {
|
|
3730
3715
|
const {
|
|
3731
3716
|
viewMonth,
|
|
@@ -3735,13 +3720,12 @@ class DayCalendarTable extends PureComponent {
|
|
|
3735
3720
|
}
|
|
3736
3721
|
} = this.props;
|
|
3737
3722
|
const weeks = this.getTableStructure();
|
|
3738
|
-
let autoFocusDay = this.getAutofocusDay(weeks, viewMonth, viewYear);
|
|
3739
3723
|
return /*#__PURE__*/jsxs("table", {
|
|
3740
3724
|
className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
|
|
3741
3725
|
children: [/*#__PURE__*/jsx("thead", {
|
|
3742
3726
|
children: /*#__PURE__*/jsx("tr", {
|
|
3743
3727
|
children: this.days.map((day, index) => /*#__PURE__*/jsxs("th", {
|
|
3744
|
-
className:
|
|
3728
|
+
className: "text-xs-center np-text-body-default-bold",
|
|
3745
3729
|
children: [/*#__PURE__*/jsx("span", {
|
|
3746
3730
|
className: "hidden-xs",
|
|
3747
3731
|
children: /*#__PURE__*/jsx("abbr", {
|
|
@@ -3760,16 +3744,15 @@ class DayCalendarTable extends PureComponent {
|
|
|
3760
3744
|
}), /*#__PURE__*/jsx("tbody", {
|
|
3761
3745
|
children: weeks.map((week, weekIndex) => /*#__PURE__*/jsx("tr", {
|
|
3762
3746
|
children: week.map((day, dayIndex) => /*#__PURE__*/jsx("td", {
|
|
3763
|
-
className: dayIndex > 4 ? '
|
|
3764
|
-
children: day && /*#__PURE__*/jsx(TableLink, {
|
|
3747
|
+
className: dayIndex > 4 ? 'default' : '',
|
|
3748
|
+
children: day && /*#__PURE__*/jsx(TableLink$1, {
|
|
3765
3749
|
item: day,
|
|
3766
3750
|
type: "day",
|
|
3767
3751
|
title: formatDate(new Date(viewYear, viewMonth, day), locale, SHORT_DAY_FORMAT),
|
|
3768
|
-
autofocus: day === autoFocusDay,
|
|
3769
3752
|
longTitle: formatDate(new Date(viewYear, viewMonth, day), locale),
|
|
3770
3753
|
active: this.isActive(day),
|
|
3771
3754
|
disabled: this.isDisabled(day),
|
|
3772
|
-
today:
|
|
3755
|
+
today: +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day),
|
|
3773
3756
|
onClick: this.selectDay
|
|
3774
3757
|
})
|
|
3775
3758
|
}, dayIndex))
|
|
@@ -3870,11 +3853,11 @@ var DayCalendar$1 = injectIntl(DayCalendar);
|
|
|
3870
3853
|
|
|
3871
3854
|
const ROWS$1 = 3;
|
|
3872
3855
|
const COLS$1 = 4;
|
|
3873
|
-
const
|
|
3856
|
+
const MONTH_ONLY_FORMAY = {
|
|
3874
3857
|
month: 'short'
|
|
3875
3858
|
};
|
|
3876
3859
|
const MonthCalendarTable = ({
|
|
3877
|
-
selectedDate,
|
|
3860
|
+
selectedDate: selected,
|
|
3878
3861
|
min,
|
|
3879
3862
|
max,
|
|
3880
3863
|
viewYear,
|
|
@@ -3884,37 +3867,19 @@ const MonthCalendarTable = ({
|
|
|
3884
3867
|
const {
|
|
3885
3868
|
locale
|
|
3886
3869
|
} = useIntl();
|
|
3887
|
-
const getLink = month => {
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
onClick: onSelect
|
|
3897
|
-
});
|
|
3898
|
-
};
|
|
3899
|
-
const isActive = month => {
|
|
3900
|
-
return selectedDate && month === selectedDate.getMonth() && viewYear === selectedDate.getFullYear();
|
|
3901
|
-
};
|
|
3902
|
-
const isThisMonth = month => {
|
|
3903
|
-
return viewYear === new Date().getFullYear() && month === new Date().getMonth();
|
|
3904
|
-
};
|
|
3870
|
+
const getLink = month => /*#__PURE__*/jsx(TableLink$1, {
|
|
3871
|
+
item: month,
|
|
3872
|
+
type: "month",
|
|
3873
|
+
title: formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAY),
|
|
3874
|
+
active: !!(selected && month === selected.getMonth() && viewYear === selected.getFullYear()),
|
|
3875
|
+
disabled: isDisabled(month),
|
|
3876
|
+
today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
|
|
3877
|
+
onClick: onSelect
|
|
3878
|
+
});
|
|
3905
3879
|
const isDisabled = month => {
|
|
3906
3880
|
const date = new Date(viewYear, month);
|
|
3907
3881
|
return !!(min && date < new Date(min.getFullYear(), min.getMonth()) || max && date > new Date(max.getFullYear(), max.getMonth()));
|
|
3908
3882
|
};
|
|
3909
|
-
const autofocusMonth = (() => {
|
|
3910
|
-
const months = [...new Array(ROWS$1 * COLS$1)].map((_, index) => index);
|
|
3911
|
-
return getFocusableTime({
|
|
3912
|
-
isActive,
|
|
3913
|
-
isNow: isThisMonth,
|
|
3914
|
-
isDisabled,
|
|
3915
|
-
timeSpan: months
|
|
3916
|
-
});
|
|
3917
|
-
})();
|
|
3918
3883
|
return /*#__PURE__*/jsxs("table", {
|
|
3919
3884
|
className: "table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0",
|
|
3920
3885
|
children: [/*#__PURE__*/jsx("thead", {
|
|
@@ -4033,36 +3998,15 @@ const YearCalendarTable = ({
|
|
|
4033
3998
|
locale
|
|
4034
3999
|
} = useIntl();
|
|
4035
4000
|
const startYear = viewYear - viewYear % 20;
|
|
4036
|
-
const getLink = year => {
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
onClick: onSelect
|
|
4046
|
-
});
|
|
4047
|
-
};
|
|
4048
|
-
const isActive = year => {
|
|
4049
|
-
return !!(selectedDate && year === selectedDate.getFullYear());
|
|
4050
|
-
};
|
|
4051
|
-
const isThisYear = year => {
|
|
4052
|
-
return year === new Date().getFullYear();
|
|
4053
|
-
};
|
|
4054
|
-
const isDisabled = year => {
|
|
4055
|
-
return !!(min && year < min.getFullYear() || max && year > max.getFullYear());
|
|
4056
|
-
};
|
|
4057
|
-
const autofocusYear = (() => {
|
|
4058
|
-
const years = [...new Array(ROWS * COLS)].map((_, index) => startYear + index);
|
|
4059
|
-
return getFocusableTime({
|
|
4060
|
-
isActive,
|
|
4061
|
-
isNow: isThisYear,
|
|
4062
|
-
isDisabled,
|
|
4063
|
-
timeSpan: years
|
|
4064
|
-
});
|
|
4065
|
-
})();
|
|
4001
|
+
const getLink = year => /*#__PURE__*/jsx(TableLink$1, {
|
|
4002
|
+
item: year,
|
|
4003
|
+
type: "year",
|
|
4004
|
+
title: formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
|
|
4005
|
+
active: !!(selectedDate && year === selectedDate.getFullYear()),
|
|
4006
|
+
disabled: !!(min && year < min.getFullYear() || max && year > max.getFullYear()),
|
|
4007
|
+
today: year === new Date().getFullYear(),
|
|
4008
|
+
onClick: onSelect
|
|
4009
|
+
});
|
|
4066
4010
|
return /*#__PURE__*/jsxs("table", {
|
|
4067
4011
|
className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
|
|
4068
4012
|
children: [/*#__PURE__*/jsx("thead", {
|
|
@@ -4169,7 +4113,6 @@ class DateLookup extends PureComponent {
|
|
|
4169
4113
|
super(props);
|
|
4170
4114
|
this.state = {
|
|
4171
4115
|
selectedDate: getStartOfDay(props.value),
|
|
4172
|
-
originalDate: null,
|
|
4173
4116
|
min: getStartOfDay(props.min),
|
|
4174
4117
|
max: getStartOfDay(props.max),
|
|
4175
4118
|
viewMonth: (props.value || new Date()).getMonth(),
|
|
@@ -4232,22 +4175,12 @@ class DateLookup extends PureComponent {
|
|
|
4232
4175
|
onFocus();
|
|
4233
4176
|
}
|
|
4234
4177
|
};
|
|
4235
|
-
discard = () => {
|
|
4236
|
-
const {
|
|
4237
|
-
originalDate
|
|
4238
|
-
} = this.state;
|
|
4239
|
-
if (originalDate !== null) {
|
|
4240
|
-
this.props.onChange(originalDate);
|
|
4241
|
-
}
|
|
4242
|
-
this.close();
|
|
4243
|
-
};
|
|
4244
4178
|
close = () => {
|
|
4245
4179
|
const {
|
|
4246
4180
|
onBlur
|
|
4247
4181
|
} = this.props;
|
|
4248
4182
|
this.setState({
|
|
4249
|
-
open: false
|
|
4250
|
-
originalDate: null
|
|
4183
|
+
open: false
|
|
4251
4184
|
});
|
|
4252
4185
|
if (onBlur) {
|
|
4253
4186
|
onBlur();
|
|
@@ -4255,8 +4188,7 @@ class DateLookup extends PureComponent {
|
|
|
4255
4188
|
};
|
|
4256
4189
|
handleKeyDown = event => {
|
|
4257
4190
|
const {
|
|
4258
|
-
open
|
|
4259
|
-
originalDate
|
|
4191
|
+
open
|
|
4260
4192
|
} = this.state;
|
|
4261
4193
|
switch (event.keyCode) {
|
|
4262
4194
|
case KeyCodes.LEFT:
|
|
@@ -4292,9 +4224,6 @@ class DateLookup extends PureComponent {
|
|
|
4292
4224
|
event.preventDefault();
|
|
4293
4225
|
break;
|
|
4294
4226
|
case KeyCodes.ESCAPE:
|
|
4295
|
-
if (originalDate !== null) {
|
|
4296
|
-
this.props.onChange(originalDate);
|
|
4297
|
-
}
|
|
4298
4227
|
this.close();
|
|
4299
4228
|
event.preventDefault();
|
|
4300
4229
|
break;
|
|
@@ -4305,14 +4234,8 @@ class DateLookup extends PureComponent {
|
|
|
4305
4234
|
selectedDate,
|
|
4306
4235
|
min,
|
|
4307
4236
|
max,
|
|
4308
|
-
mode
|
|
4309
|
-
originalDate
|
|
4237
|
+
mode
|
|
4310
4238
|
} = this.state;
|
|
4311
|
-
if (originalDate === null) {
|
|
4312
|
-
this.setState({
|
|
4313
|
-
originalDate: selectedDate
|
|
4314
|
-
});
|
|
4315
|
-
}
|
|
4316
4239
|
let date;
|
|
4317
4240
|
if (selectedDate) {
|
|
4318
4241
|
date = new Date(mode === MODE.YEAR ? selectedDate.getFullYear() + yearsToAdd : selectedDate.getFullYear(), mode === MODE.MONTH ? selectedDate.getMonth() + monthsToAdd : selectedDate.getMonth(), mode === MODE.DAY ? selectedDate.getDate() + daysToAdd : selectedDate.getDate());
|
|
@@ -4445,7 +4368,7 @@ class DateLookup extends PureComponent {
|
|
|
4445
4368
|
open: open,
|
|
4446
4369
|
className: "tw-date-lookup-menu",
|
|
4447
4370
|
position: Position.BOTTOM,
|
|
4448
|
-
onClose: this.
|
|
4371
|
+
onClose: this.close,
|
|
4449
4372
|
children: this.getCalendar()
|
|
4450
4373
|
})]
|
|
4451
4374
|
});
|