@transferwise/components 0.0.0-experimental-3e282e9 → 0.0.0-experimental-65e51cb
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 +70 -134
- package/build/index.esm.js.map +1 -1
- package/build/index.js +70 -134
- 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/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/info/Info.d.ts +6 -2
- package/build/types/info/Info.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dateLookup/DateLookup.css +1 -1
- package/src/dateLookup/DateLookup.js +0 -3
- package/src/dateLookup/DateLookup.less +47 -57
- package/src/dateLookup/DateLookup.story.js +5 -7
- package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -35
- package/src/dateLookup/monthCalendar/table/MonthCalendarTable.js +20 -43
- package/src/dateLookup/tableLink/TableLink.js +70 -0
- package/src/dateLookup/yearCalendar/table/YearCalendarTable.js +11 -39
- package/src/info/Info.tsx +6 -1
- package/src/main.css +1 -1
- package/src/dateLookup/tableLink/TableLink.tsx +0 -77
- /package/src/dateLookup/tableLink/{index.ts → index.js} +0 -0
package/build/index.esm.js
CHANGED
|
@@ -3575,53 +3575,59 @@ function getStartOfDay(date) {
|
|
|
3575
3575
|
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
3576
3576
|
}
|
|
3577
3577
|
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
type,
|
|
3581
|
-
title,
|
|
3582
|
-
longTitle,
|
|
3583
|
-
active,
|
|
3584
|
-
disabled,
|
|
3585
|
-
today,
|
|
3586
|
-
autofocus,
|
|
3587
|
-
onClick,
|
|
3588
|
-
intl: {
|
|
3589
|
-
formatMessage
|
|
3590
|
-
}
|
|
3591
|
-
}) => {
|
|
3592
|
-
const buttonRef = useRef(null);
|
|
3593
|
-
useEffect(() => {
|
|
3594
|
-
if (autofocus) {
|
|
3595
|
-
setTimeout(() => {
|
|
3596
|
-
buttonRef.current?.focus();
|
|
3597
|
-
}, 0);
|
|
3598
|
-
}
|
|
3599
|
-
}, [autofocus]);
|
|
3600
|
-
const onCalendarClick = event => {
|
|
3578
|
+
class TableLink extends PureComponent {
|
|
3579
|
+
onClick = event => {
|
|
3601
3580
|
event.preventDefault();
|
|
3602
|
-
if (!disabled) {
|
|
3603
|
-
onClick(item);
|
|
3581
|
+
if (!this.props.disabled) {
|
|
3582
|
+
this.props.onClick(this.props.item);
|
|
3604
3583
|
}
|
|
3605
3584
|
};
|
|
3606
|
-
|
|
3585
|
+
calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
|
|
3607
3586
|
if (active) {
|
|
3608
|
-
return `${longTitle || title
|
|
3587
|
+
return `${longTitle || title}, ${formatMessage(messages$6.selected)} ${formatMessage(messages$6[type])}`;
|
|
3609
3588
|
}
|
|
3610
3589
|
return longTitle || title;
|
|
3611
3590
|
};
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
type
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3591
|
+
render() {
|
|
3592
|
+
const {
|
|
3593
|
+
item,
|
|
3594
|
+
type,
|
|
3595
|
+
title,
|
|
3596
|
+
longTitle,
|
|
3597
|
+
active,
|
|
3598
|
+
disabled,
|
|
3599
|
+
today,
|
|
3600
|
+
intl: {
|
|
3601
|
+
formatMessage
|
|
3602
|
+
}
|
|
3603
|
+
} = this.props;
|
|
3604
|
+
return /*#__PURE__*/jsx(Fragment, {
|
|
3605
|
+
children: /*#__PURE__*/jsx("button", {
|
|
3606
|
+
type: "button",
|
|
3607
|
+
className: `tw-date-lookup-${type}-option ${active ? 'active' : ''} ${today ? 'today' : ''} np-text-body-default-bold`,
|
|
3608
|
+
disabled: disabled,
|
|
3609
|
+
"aria-label": this.calculateAriaLabel(longTitle, title, active, type, formatMessage),
|
|
3610
|
+
"aria-pressed": active,
|
|
3611
|
+
onClick: this.onClick,
|
|
3612
|
+
children: title || item
|
|
3613
|
+
})
|
|
3614
|
+
});
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
TableLink.propTypes = {
|
|
3618
|
+
item: PropTypes.number.isRequired,
|
|
3619
|
+
// day (1-31), month (0-11) or year (2018 etc)
|
|
3620
|
+
type: PropTypes.oneOf(['day', 'month', 'year']).isRequired,
|
|
3621
|
+
title: PropTypes.string,
|
|
3622
|
+
longTitle: PropTypes.string,
|
|
3623
|
+
active: PropTypes.bool.isRequired,
|
|
3624
|
+
disabled: PropTypes.bool.isRequired,
|
|
3625
|
+
today: PropTypes.bool.isRequired,
|
|
3626
|
+
onClick: PropTypes.func.isRequired
|
|
3627
|
+
};
|
|
3628
|
+
TableLink.defaultProps = {
|
|
3629
|
+
title: null,
|
|
3630
|
+
longTitle: null
|
|
3625
3631
|
};
|
|
3626
3632
|
var TableLink$1 = injectIntl(TableLink);
|
|
3627
3633
|
|
|
@@ -3694,32 +3700,6 @@ class DayCalendarTable extends PureComponent {
|
|
|
3694
3700
|
} = this.props;
|
|
3695
3701
|
return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
|
|
3696
3702
|
};
|
|
3697
|
-
isToday = (day, viewMonth, viewYear) => {
|
|
3698
|
-
return +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day);
|
|
3699
|
-
};
|
|
3700
|
-
getAutofocusDay = (weeks, viewMonth, viewYear) => {
|
|
3701
|
-
let activeDay = null;
|
|
3702
|
-
let today = null;
|
|
3703
|
-
let lowestNonDisabledDay = null;
|
|
3704
|
-
for (const week of weeks) {
|
|
3705
|
-
for (const day of week) {
|
|
3706
|
-
if (this.isActive(day)) {
|
|
3707
|
-
activeDay = day;
|
|
3708
|
-
break;
|
|
3709
|
-
}
|
|
3710
|
-
if (this.isToday(day, viewMonth, viewYear)) {
|
|
3711
|
-
today = day;
|
|
3712
|
-
}
|
|
3713
|
-
if (day && !this.isDisabled(day) && lowestNonDisabledDay === null) {
|
|
3714
|
-
lowestNonDisabledDay = day;
|
|
3715
|
-
}
|
|
3716
|
-
}
|
|
3717
|
-
if (activeDay !== null) {
|
|
3718
|
-
break;
|
|
3719
|
-
}
|
|
3720
|
-
}
|
|
3721
|
-
return activeDay || today || lowestNonDisabledDay;
|
|
3722
|
-
};
|
|
3723
3703
|
render() {
|
|
3724
3704
|
const {
|
|
3725
3705
|
viewMonth,
|
|
@@ -3729,7 +3709,6 @@ class DayCalendarTable extends PureComponent {
|
|
|
3729
3709
|
}
|
|
3730
3710
|
} = this.props;
|
|
3731
3711
|
const weeks = this.getTableStructure();
|
|
3732
|
-
let autoFocusDay = this.getAutofocusDay(weeks, viewMonth, viewYear);
|
|
3733
3712
|
return /*#__PURE__*/jsxs("table", {
|
|
3734
3713
|
className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
|
|
3735
3714
|
children: [/*#__PURE__*/jsx("thead", {
|
|
@@ -3759,11 +3738,10 @@ class DayCalendarTable extends PureComponent {
|
|
|
3759
3738
|
item: day,
|
|
3760
3739
|
type: "day",
|
|
3761
3740
|
title: formatDate(new Date(viewYear, viewMonth, day), locale, SHORT_DAY_FORMAT),
|
|
3762
|
-
autofocus: day === autoFocusDay,
|
|
3763
3741
|
longTitle: formatDate(new Date(viewYear, viewMonth, day), locale),
|
|
3764
3742
|
active: this.isActive(day),
|
|
3765
3743
|
disabled: this.isDisabled(day),
|
|
3766
|
-
today:
|
|
3744
|
+
today: +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day),
|
|
3767
3745
|
onClick: this.selectDay
|
|
3768
3746
|
})
|
|
3769
3747
|
}, dayIndex))
|
|
@@ -3864,11 +3842,11 @@ var DayCalendar$1 = injectIntl(DayCalendar);
|
|
|
3864
3842
|
|
|
3865
3843
|
const ROWS$1 = 3;
|
|
3866
3844
|
const COLS$1 = 4;
|
|
3867
|
-
const
|
|
3845
|
+
const MONTH_ONLY_FORMAY = {
|
|
3868
3846
|
month: 'short'
|
|
3869
3847
|
};
|
|
3870
3848
|
const MonthCalendarTable = ({
|
|
3871
|
-
selectedDate,
|
|
3849
|
+
selectedDate: selected,
|
|
3872
3850
|
min,
|
|
3873
3851
|
max,
|
|
3874
3852
|
viewYear,
|
|
@@ -3878,39 +3856,19 @@ const MonthCalendarTable = ({
|
|
|
3878
3856
|
const {
|
|
3879
3857
|
locale
|
|
3880
3858
|
} = useIntl();
|
|
3881
|
-
const getLink = month => {
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
onClick: onSelect
|
|
3891
|
-
});
|
|
3892
|
-
};
|
|
3859
|
+
const getLink = month => /*#__PURE__*/jsx(TableLink$1, {
|
|
3860
|
+
item: month,
|
|
3861
|
+
type: "month",
|
|
3862
|
+
title: formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAY),
|
|
3863
|
+
active: !!(selected && month === selected.getMonth() && viewYear === selected.getFullYear()),
|
|
3864
|
+
disabled: isDisabled(month),
|
|
3865
|
+
today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
|
|
3866
|
+
onClick: onSelect
|
|
3867
|
+
});
|
|
3893
3868
|
const isDisabled = month => {
|
|
3894
3869
|
const date = new Date(viewYear, month);
|
|
3895
3870
|
return !!(min && date < new Date(min.getFullYear(), min.getMonth()) || max && date > new Date(max.getFullYear(), max.getMonth()));
|
|
3896
3871
|
};
|
|
3897
|
-
const months = [...new Array(ROWS$1 * COLS$1)].map((_, index) => index);
|
|
3898
|
-
const autofocusMonth = (() => {
|
|
3899
|
-
let activeMonth = null;
|
|
3900
|
-
let lowestNonDisabledMonth = null;
|
|
3901
|
-
for (const month of months) {
|
|
3902
|
-
if (selectedDate && month === selectedDate.getMonth()) {
|
|
3903
|
-
activeMonth = month;
|
|
3904
|
-
}
|
|
3905
|
-
if (!isDisabled(month) && lowestNonDisabledMonth === null) {
|
|
3906
|
-
lowestNonDisabledMonth = month;
|
|
3907
|
-
}
|
|
3908
|
-
if (activeMonth !== null) {
|
|
3909
|
-
break;
|
|
3910
|
-
}
|
|
3911
|
-
}
|
|
3912
|
-
return activeMonth || lowestNonDisabledMonth;
|
|
3913
|
-
})();
|
|
3914
3872
|
return /*#__PURE__*/jsxs("table", {
|
|
3915
3873
|
className: "table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0",
|
|
3916
3874
|
children: [/*#__PURE__*/jsx("thead", {
|
|
@@ -4029,38 +3987,15 @@ const YearCalendarTable = ({
|
|
|
4029
3987
|
locale
|
|
4030
3988
|
} = useIntl();
|
|
4031
3989
|
const startYear = viewYear - viewYear % 20;
|
|
4032
|
-
const getLink = year => {
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
onClick: onSelect
|
|
4042
|
-
});
|
|
4043
|
-
};
|
|
4044
|
-
const isDisabled = year => {
|
|
4045
|
-
return !!(min && year < min.getFullYear() || max && year > max.getFullYear());
|
|
4046
|
-
};
|
|
4047
|
-
const years = [...new Array(ROWS * COLS)].map((_, index) => startYear + index);
|
|
4048
|
-
const autofocusYear = (() => {
|
|
4049
|
-
let activeYear = null;
|
|
4050
|
-
let lowestNonDisabledYear = null;
|
|
4051
|
-
for (const year of years) {
|
|
4052
|
-
if (selectedDate && year === selectedDate.getFullYear()) {
|
|
4053
|
-
activeYear = year;
|
|
4054
|
-
}
|
|
4055
|
-
if (!isDisabled(year) && lowestNonDisabledYear === null) {
|
|
4056
|
-
lowestNonDisabledYear = year;
|
|
4057
|
-
}
|
|
4058
|
-
if (activeYear !== null) {
|
|
4059
|
-
break;
|
|
4060
|
-
}
|
|
4061
|
-
}
|
|
4062
|
-
return activeYear || lowestNonDisabledYear;
|
|
4063
|
-
})();
|
|
3990
|
+
const getLink = year => /*#__PURE__*/jsx(TableLink$1, {
|
|
3991
|
+
item: year,
|
|
3992
|
+
type: "year",
|
|
3993
|
+
title: formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
|
|
3994
|
+
active: !!(selectedDate && year === selectedDate.getFullYear()),
|
|
3995
|
+
disabled: !!(min && year < min.getFullYear() || max && year > max.getFullYear()),
|
|
3996
|
+
today: year === new Date().getFullYear(),
|
|
3997
|
+
onClick: onSelect
|
|
3998
|
+
});
|
|
4064
3999
|
return /*#__PURE__*/jsxs("table", {
|
|
4065
4000
|
className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
|
|
4066
4001
|
children: [/*#__PURE__*/jsx("thead", {
|
|
@@ -6161,7 +6096,8 @@ const Info = ({
|
|
|
6161
6096
|
presentation = InfoPresentation.POPOVER,
|
|
6162
6097
|
size = Size.SMALL,
|
|
6163
6098
|
title = undefined,
|
|
6164
|
-
'aria-label': ariaLabel
|
|
6099
|
+
'aria-label': ariaLabel,
|
|
6100
|
+
preferredPlacement = Position.BOTTOM
|
|
6165
6101
|
}) => {
|
|
6166
6102
|
const [open, setOpen] = useState(false);
|
|
6167
6103
|
const isModal = presentation === InfoPresentation.MODAL;
|
|
@@ -6196,7 +6132,7 @@ const Info = ({
|
|
|
6196
6132
|
})]
|
|
6197
6133
|
}) : /*#__PURE__*/jsx(Popover$2, {
|
|
6198
6134
|
content: content,
|
|
6199
|
-
preferredPlacement:
|
|
6135
|
+
preferredPlacement: preferredPlacement,
|
|
6200
6136
|
title: title,
|
|
6201
6137
|
children: /*#__PURE__*/jsx("button", {
|
|
6202
6138
|
type: "button",
|