@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.
Files changed (39) hide show
  1. package/build/index.esm.js +75 -152
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +75 -152
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/chips/Chip.css +1 -1
  7. package/build/styles/dateLookup/DateLookup.css +1 -1
  8. package/build/styles/main.css +1 -1
  9. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  10. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts +1 -1
  11. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -1
  12. package/build/types/dateLookup/tableLink/TableLink.d.ts +4 -14
  13. package/build/types/dateLookup/tableLink/TableLink.d.ts.map +1 -1
  14. package/build/types/dateLookup/tableLink/index.d.ts +1 -1
  15. package/build/types/dateLookup/tableLink/index.d.ts.map +1 -1
  16. package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts.map +1 -1
  17. package/package.json +2 -2
  18. package/src/chips/Chip.css +1 -1
  19. package/src/chips/Chip.less +9 -21
  20. package/src/dateLookup/DateLookup.css +1 -1
  21. package/src/dateLookup/DateLookup.js +4 -19
  22. package/src/dateLookup/DateLookup.keyboardEvents.spec.js +0 -12
  23. package/src/dateLookup/DateLookup.less +49 -39
  24. package/src/dateLookup/DateLookup.story.js +7 -8
  25. package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +3 -28
  26. package/src/dateLookup/dayCalendar/table/DayCalendarTable.spec.js +0 -25
  27. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.js +20 -33
  28. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.spec.js +0 -33
  29. package/src/dateLookup/tableLink/TableLink.js +70 -0
  30. package/src/dateLookup/tableLink/TableLink.spec.js +15 -6
  31. package/src/dateLookup/yearCalendar/table/YearCalendarTable.js +11 -33
  32. package/src/dateLookup/yearCalendar/table/YearCalendarTable.spec.js +0 -26
  33. package/src/main.css +1 -1
  34. package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts +0 -9
  35. package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts.map +0 -1
  36. package/src/dateLookup/getFocusableTime/getFocusable.spec.ts +0 -40
  37. package/src/dateLookup/getFocusableTime/getFocusableTime.tsx +0 -14
  38. package/src/dateLookup/tableLink/TableLink.tsx +0 -79
  39. /package/src/dateLookup/tableLink/{index.ts → index.js} +0 -0
package/build/index.js CHANGED
@@ -3609,10 +3609,6 @@ DateHeader.defaultProps = {
3609
3609
  };
3610
3610
  var DateHeader$1 = DateHeader;
3611
3611
 
3612
- function getFocusableTime(props) {
3613
- 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));
3614
- }
3615
-
3616
3612
  // NB! Using with UTC timestamp (YYYY-MM-DD) might lead to unexpected results, for example
3617
3613
  // getStartOfDay(new Date('1995-01-01')) in Los Angeles returns 31 Dec 1994, but in
3618
3614
  // in Singapore it is 1 Jan 1995.
@@ -3624,56 +3620,61 @@ function getStartOfDay(date) {
3624
3620
  return new Date(date.getFullYear(), date.getMonth(), date.getDate());
3625
3621
  }
3626
3622
 
3627
- const TableLink = ({
3628
- item,
3629
- type,
3630
- title,
3631
- longTitle,
3632
- active,
3633
- disabled,
3634
- today,
3635
- autofocus,
3636
- onClick
3637
- }) => {
3638
- const buttonRef = React.useRef(null);
3639
- const intl = reactIntl.useIntl();
3640
- React.useEffect(() => {
3641
- if (autofocus) {
3642
- setTimeout(() => {
3643
- buttonRef.current?.focus();
3644
- }, 0);
3645
- }
3646
- }, [autofocus]);
3647
- const onCalendarClick = event => {
3623
+ class TableLink extends React.PureComponent {
3624
+ onClick = event => {
3648
3625
  event.preventDefault();
3649
- if (!disabled) {
3650
- onClick(item);
3626
+ if (!this.props.disabled) {
3627
+ this.props.onClick(this.props.item);
3651
3628
  }
3652
3629
  };
3653
- const calculateAriaLabel = () => {
3630
+ calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
3654
3631
  if (active) {
3655
- return `${longTitle || title || ''}, ${intl.formatMessage(messages$6.selected)} ${intl.formatMessage(messages$6[type])}`;
3632
+ return `${longTitle || title}, ${formatMessage(messages$6.selected)} ${formatMessage(messages$6[type])}`;
3656
3633
  }
3657
3634
  return longTitle || title;
3658
3635
  };
3659
- return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
3660
- children: /*#__PURE__*/jsxRuntime.jsx("button", {
3661
- ref: buttonRef,
3662
- type: "button",
3663
- className: classNames__default.default(`tw-date-lookup-${type}-option np-text-body-default-bold`, {
3664
- active: !!active
3665
- }, {
3666
- today: !!today
3667
- }),
3668
- disabled: disabled,
3669
- tabIndex: autofocus ? 0 : -1,
3670
- "aria-label": calculateAriaLabel(),
3671
- "aria-pressed": active,
3672
- onClick: onCalendarClick,
3673
- children: title || item
3674
- })
3675
- });
3636
+ render() {
3637
+ const {
3638
+ item,
3639
+ type,
3640
+ title,
3641
+ longTitle,
3642
+ active,
3643
+ disabled,
3644
+ today,
3645
+ intl: {
3646
+ formatMessage
3647
+ }
3648
+ } = this.props;
3649
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
3650
+ children: /*#__PURE__*/jsxRuntime.jsx("button", {
3651
+ type: "button",
3652
+ className: `tw-date-lookup-${type}-option ${active ? 'active' : ''} ${today ? 'today' : ''} np-text-body-default-bold`,
3653
+ disabled: disabled,
3654
+ "aria-label": this.calculateAriaLabel(longTitle, title, active, type, formatMessage),
3655
+ "aria-pressed": active,
3656
+ onClick: this.onClick,
3657
+ children: title || item
3658
+ })
3659
+ });
3660
+ }
3661
+ }
3662
+ TableLink.propTypes = {
3663
+ item: PropTypes__default.default.number.isRequired,
3664
+ // day (1-31), month (0-11) or year (2018 etc)
3665
+ type: PropTypes__default.default.oneOf(['day', 'month', 'year']).isRequired,
3666
+ title: PropTypes__default.default.string,
3667
+ longTitle: PropTypes__default.default.string,
3668
+ active: PropTypes__default.default.bool.isRequired,
3669
+ disabled: PropTypes__default.default.bool.isRequired,
3670
+ today: PropTypes__default.default.bool.isRequired,
3671
+ onClick: PropTypes__default.default.func.isRequired
3676
3672
  };
3673
+ TableLink.defaultProps = {
3674
+ title: null,
3675
+ longTitle: null
3676
+ };
3677
+ var TableLink$1 = reactIntl.injectIntl(TableLink);
3677
3678
 
3678
3679
  const SHORT_DAY_FORMAT = {
3679
3680
  day: 'numeric'
@@ -3744,22 +3745,6 @@ class DayCalendarTable extends React.PureComponent {
3744
3745
  } = this.props;
3745
3746
  return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
3746
3747
  };
3747
- isToday = day => {
3748
- const {
3749
- viewMonth,
3750
- viewYear
3751
- } = this.props;
3752
- return Number(getStartOfDay(new Date())) === Number(new Date(viewYear, viewMonth, day));
3753
- };
3754
- getAutofocusDay = weeks => {
3755
- const days = weeks.flatMap(week => week);
3756
- return getFocusableTime({
3757
- isActive: this.isActive,
3758
- isNow: this.isToday,
3759
- isDisabled: this.isDisabled,
3760
- timeSpan: days
3761
- });
3762
- };
3763
3748
  render() {
3764
3749
  const {
3765
3750
  viewMonth,
@@ -3769,13 +3754,12 @@ class DayCalendarTable extends React.PureComponent {
3769
3754
  }
3770
3755
  } = this.props;
3771
3756
  const weeks = this.getTableStructure();
3772
- let autoFocusDay = this.getAutofocusDay(weeks, viewMonth, viewYear);
3773
3757
  return /*#__PURE__*/jsxRuntime.jsxs("table", {
3774
3758
  className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
3775
3759
  children: [/*#__PURE__*/jsxRuntime.jsx("thead", {
3776
3760
  children: /*#__PURE__*/jsxRuntime.jsx("tr", {
3777
3761
  children: this.days.map((day, index) => /*#__PURE__*/jsxRuntime.jsxs("th", {
3778
- className: index > 4 ? 'text-xs-center np-text-body-default' : 'text-xs-center np-text-body-default-bold',
3762
+ className: "text-xs-center np-text-body-default-bold",
3779
3763
  children: [/*#__PURE__*/jsxRuntime.jsx("span", {
3780
3764
  className: "hidden-xs",
3781
3765
  children: /*#__PURE__*/jsxRuntime.jsx("abbr", {
@@ -3794,16 +3778,15 @@ class DayCalendarTable extends React.PureComponent {
3794
3778
  }), /*#__PURE__*/jsxRuntime.jsx("tbody", {
3795
3779
  children: weeks.map((week, weekIndex) => /*#__PURE__*/jsxRuntime.jsx("tr", {
3796
3780
  children: week.map((day, dayIndex) => /*#__PURE__*/jsxRuntime.jsx("td", {
3797
- className: dayIndex > 4 ? 'weekend' : '',
3798
- children: day && /*#__PURE__*/jsxRuntime.jsx(TableLink, {
3781
+ className: dayIndex > 4 ? 'default' : '',
3782
+ children: day && /*#__PURE__*/jsxRuntime.jsx(TableLink$1, {
3799
3783
  item: day,
3800
3784
  type: "day",
3801
3785
  title: formatting.formatDate(new Date(viewYear, viewMonth, day), locale, SHORT_DAY_FORMAT),
3802
- autofocus: day === autoFocusDay,
3803
3786
  longTitle: formatting.formatDate(new Date(viewYear, viewMonth, day), locale),
3804
3787
  active: this.isActive(day),
3805
3788
  disabled: this.isDisabled(day),
3806
- today: this.isToday(day),
3789
+ today: +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day),
3807
3790
  onClick: this.selectDay
3808
3791
  })
3809
3792
  }, dayIndex))
@@ -3904,11 +3887,11 @@ var DayCalendar$1 = reactIntl.injectIntl(DayCalendar);
3904
3887
 
3905
3888
  const ROWS$1 = 3;
3906
3889
  const COLS$1 = 4;
3907
- const MONTH_ONLY_FORMAT = {
3890
+ const MONTH_ONLY_FORMAY = {
3908
3891
  month: 'short'
3909
3892
  };
3910
3893
  const MonthCalendarTable = ({
3911
- selectedDate,
3894
+ selectedDate: selected,
3912
3895
  min,
3913
3896
  max,
3914
3897
  viewYear,
@@ -3918,37 +3901,19 @@ const MonthCalendarTable = ({
3918
3901
  const {
3919
3902
  locale
3920
3903
  } = reactIntl.useIntl();
3921
- const getLink = month => {
3922
- return /*#__PURE__*/jsxRuntime.jsx(TableLink, {
3923
- item: month,
3924
- type: "month",
3925
- title: formatting.formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAT),
3926
- active: isActive(month),
3927
- disabled: isDisabled(month),
3928
- today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
3929
- autofocus: autofocusMonth === month,
3930
- onClick: onSelect
3931
- });
3932
- };
3933
- const isActive = month => {
3934
- return selectedDate && month === selectedDate.getMonth() && viewYear === selectedDate.getFullYear();
3935
- };
3936
- const isThisMonth = month => {
3937
- return viewYear === new Date().getFullYear() && month === new Date().getMonth();
3938
- };
3904
+ const getLink = month => /*#__PURE__*/jsxRuntime.jsx(TableLink$1, {
3905
+ item: month,
3906
+ type: "month",
3907
+ title: formatting.formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAY),
3908
+ active: !!(selected && month === selected.getMonth() && viewYear === selected.getFullYear()),
3909
+ disabled: isDisabled(month),
3910
+ today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
3911
+ onClick: onSelect
3912
+ });
3939
3913
  const isDisabled = month => {
3940
3914
  const date = new Date(viewYear, month);
3941
3915
  return !!(min && date < new Date(min.getFullYear(), min.getMonth()) || max && date > new Date(max.getFullYear(), max.getMonth()));
3942
3916
  };
3943
- const autofocusMonth = (() => {
3944
- const months = [...new Array(ROWS$1 * COLS$1)].map((_, index) => index);
3945
- return getFocusableTime({
3946
- isActive,
3947
- isNow: isThisMonth,
3948
- isDisabled,
3949
- timeSpan: months
3950
- });
3951
- })();
3952
3917
  return /*#__PURE__*/jsxRuntime.jsxs("table", {
3953
3918
  className: "table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0",
3954
3919
  children: [/*#__PURE__*/jsxRuntime.jsx("thead", {
@@ -4067,36 +4032,15 @@ const YearCalendarTable = ({
4067
4032
  locale
4068
4033
  } = reactIntl.useIntl();
4069
4034
  const startYear = viewYear - viewYear % 20;
4070
- const getLink = year => {
4071
- return /*#__PURE__*/jsxRuntime.jsx(TableLink, {
4072
- item: year,
4073
- type: "year",
4074
- title: formatting.formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
4075
- active: isActive(year),
4076
- disabled: isDisabled(year),
4077
- today: isThisYear(year),
4078
- autofocus: autofocusYear === year,
4079
- onClick: onSelect
4080
- });
4081
- };
4082
- const isActive = year => {
4083
- return !!(selectedDate && year === selectedDate.getFullYear());
4084
- };
4085
- const isThisYear = year => {
4086
- return year === new Date().getFullYear();
4087
- };
4088
- const isDisabled = year => {
4089
- return !!(min && year < min.getFullYear() || max && year > max.getFullYear());
4090
- };
4091
- const autofocusYear = (() => {
4092
- const years = [...new Array(ROWS * COLS)].map((_, index) => startYear + index);
4093
- return getFocusableTime({
4094
- isActive,
4095
- isNow: isThisYear,
4096
- isDisabled,
4097
- timeSpan: years
4098
- });
4099
- })();
4035
+ const getLink = year => /*#__PURE__*/jsxRuntime.jsx(TableLink$1, {
4036
+ item: year,
4037
+ type: "year",
4038
+ title: formatting.formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
4039
+ active: !!(selectedDate && year === selectedDate.getFullYear()),
4040
+ disabled: !!(min && year < min.getFullYear() || max && year > max.getFullYear()),
4041
+ today: year === new Date().getFullYear(),
4042
+ onClick: onSelect
4043
+ });
4100
4044
  return /*#__PURE__*/jsxRuntime.jsxs("table", {
4101
4045
  className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
4102
4046
  children: [/*#__PURE__*/jsxRuntime.jsx("thead", {
@@ -4203,7 +4147,6 @@ class DateLookup extends React.PureComponent {
4203
4147
  super(props);
4204
4148
  this.state = {
4205
4149
  selectedDate: getStartOfDay(props.value),
4206
- originalDate: null,
4207
4150
  min: getStartOfDay(props.min),
4208
4151
  max: getStartOfDay(props.max),
4209
4152
  viewMonth: (props.value || new Date()).getMonth(),
@@ -4266,22 +4209,12 @@ class DateLookup extends React.PureComponent {
4266
4209
  onFocus();
4267
4210
  }
4268
4211
  };
4269
- discard = () => {
4270
- const {
4271
- originalDate
4272
- } = this.state;
4273
- if (originalDate !== null) {
4274
- this.props.onChange(originalDate);
4275
- }
4276
- this.close();
4277
- };
4278
4212
  close = () => {
4279
4213
  const {
4280
4214
  onBlur
4281
4215
  } = this.props;
4282
4216
  this.setState({
4283
- open: false,
4284
- originalDate: null
4217
+ open: false
4285
4218
  });
4286
4219
  if (onBlur) {
4287
4220
  onBlur();
@@ -4289,8 +4222,7 @@ class DateLookup extends React.PureComponent {
4289
4222
  };
4290
4223
  handleKeyDown = event => {
4291
4224
  const {
4292
- open,
4293
- originalDate
4225
+ open
4294
4226
  } = this.state;
4295
4227
  switch (event.keyCode) {
4296
4228
  case KeyCodes.LEFT:
@@ -4326,9 +4258,6 @@ class DateLookup extends React.PureComponent {
4326
4258
  event.preventDefault();
4327
4259
  break;
4328
4260
  case KeyCodes.ESCAPE:
4329
- if (originalDate !== null) {
4330
- this.props.onChange(originalDate);
4331
- }
4332
4261
  this.close();
4333
4262
  event.preventDefault();
4334
4263
  break;
@@ -4339,14 +4268,8 @@ class DateLookup extends React.PureComponent {
4339
4268
  selectedDate,
4340
4269
  min,
4341
4270
  max,
4342
- mode,
4343
- originalDate
4271
+ mode
4344
4272
  } = this.state;
4345
- if (originalDate === null) {
4346
- this.setState({
4347
- originalDate: selectedDate
4348
- });
4349
- }
4350
4273
  let date;
4351
4274
  if (selectedDate) {
4352
4275
  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());
@@ -4479,7 +4402,7 @@ class DateLookup extends React.PureComponent {
4479
4402
  open: open,
4480
4403
  className: "tw-date-lookup-menu",
4481
4404
  position: exports.Position.BOTTOM,
4482
- onClose: this.discard,
4405
+ onClose: this.close,
4483
4406
  children: this.getCalendar()
4484
4407
  })]
4485
4408
  });