@transferwise/components 0.0.0-experimental-e05dfa3 → 0.0.0-experimental-d0b76b1

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 (42) hide show
  1. package/build/index.esm.js +76 -150
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +76 -150
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/dateLookup/DateLookup.css +1 -1
  7. package/build/styles/header/Header.css +1 -1
  8. package/build/styles/main.css +1 -1
  9. package/build/types/dateInput/DateInput.d.ts +2 -0
  10. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  11. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  12. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts +1 -1
  13. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -1
  14. package/build/types/dateLookup/tableLink/TableLink.d.ts +2 -16
  15. package/build/types/dateLookup/tableLink/TableLink.d.ts.map +1 -1
  16. package/build/types/dateLookup/tableLink/index.d.ts +1 -1
  17. package/build/types/dateLookup/tableLink/index.d.ts.map +1 -1
  18. package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts.map +1 -1
  19. package/package.json +1 -1
  20. package/src/dateInput/DateInput.js +6 -0
  21. package/src/dateInput/DateInput.story.tsx +43 -1
  22. package/src/dateLookup/DateLookup.css +1 -1
  23. package/src/dateLookup/DateLookup.js +3 -16
  24. package/src/dateLookup/DateLookup.keyboardEvents.spec.js +0 -12
  25. package/src/dateLookup/DateLookup.less +49 -46
  26. package/src/dateLookup/DateLookup.story.js +7 -8
  27. package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -14
  28. package/src/dateLookup/dayCalendar/table/DayCalendarTable.spec.js +0 -25
  29. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.js +20 -33
  30. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.spec.js +0 -33
  31. package/src/dateLookup/tableLink/TableLink.js +70 -0
  32. package/src/dateLookup/yearCalendar/table/YearCalendarTable.js +11 -33
  33. package/src/dateLookup/yearCalendar/table/YearCalendarTable.spec.js +0 -26
  34. package/src/header/Header.css +1 -1
  35. package/src/header/Header.less +0 -5
  36. package/src/main.css +1 -1
  37. package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts +0 -2
  38. package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts.map +0 -1
  39. package/src/dateLookup/getFocusableTime/getFocusable.spec.js +0 -38
  40. package/src/dateLookup/getFocusableTime/getFocusableTime.tsx +0 -28
  41. package/src/dateLookup/tableLink/TableLink.tsx +0 -80
  42. /package/src/dateLookup/tableLink/{index.ts → index.js} +0 -0
package/build/index.js CHANGED
@@ -2934,6 +2934,8 @@ const INITIAL_DEFAULT_STATE = {
2934
2934
  day: null
2935
2935
  };
2936
2936
  const DateInput = ({
2937
+ 'aria-labelledby': ariaLabelledBy,
2938
+ 'aria-label': ariaLabel,
2937
2939
  disabled,
2938
2940
  size,
2939
2941
  value,
@@ -3121,6 +3123,8 @@ const DateInput = ({
3121
3123
  return /*#__PURE__*/jsxRuntime.jsx("div", {
3122
3124
  className: "tw-date",
3123
3125
  id: id,
3126
+ "aria-labelledby": ariaLabelledBy,
3127
+ "aria-label": ariaLabel,
3124
3128
  onFocus: event => shouldPropagateOnFocus(event) ? onFocus && onFocus() : event.stopPropagation(),
3125
3129
  onBlur: event => shouldPropagateOnBlur(event) ? onBlur && onBlur() : event.stopPropagation(),
3126
3130
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
@@ -3203,6 +3207,8 @@ function shouldPropagateOnBlur({
3203
3207
  return blurElementParent !== focusElementParent;
3204
3208
  }
3205
3209
  DateInput.propTypes = {
3210
+ 'aria-label': PropTypes__default.default.string,
3211
+ 'aria-labelledby': PropTypes__default.default.string,
3206
3212
  disabled: PropTypes__default.default.bool,
3207
3213
  size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
3208
3214
  value: PropTypes__default.default.oneOfType([PropTypes__default.default.string, PropTypes__default.default.instanceOf(Date)]),
@@ -3598,28 +3604,6 @@ DateHeader.defaultProps = {
3598
3604
  };
3599
3605
  var DateHeader$1 = DateHeader;
3600
3606
 
3601
- function getFocusableTime(isSelected, isNow, isDisabled, timeSpan) {
3602
- let selected = null;
3603
- let now = null;
3604
- let disabled = null;
3605
- for (const time of timeSpan) {
3606
- if (isSelected(time)) {
3607
- selected = time;
3608
- break;
3609
- }
3610
- if (isNow(time)) {
3611
- now = time;
3612
- }
3613
- if (!isDisabled(time) && disabled === null) {
3614
- disabled = time;
3615
- }
3616
- if (selected) {
3617
- break;
3618
- }
3619
- }
3620
- return selected || now || disabled;
3621
- }
3622
-
3623
3607
  // NB! Using with UTC timestamp (YYYY-MM-DD) might lead to unexpected results, for example
3624
3608
  // getStartOfDay(new Date('1995-01-01')) in Los Angeles returns 31 Dec 1994, but in
3625
3609
  // in Singapore it is 1 Jan 1995.
@@ -3631,57 +3615,59 @@ function getStartOfDay(date) {
3631
3615
  return new Date(date.getFullYear(), date.getMonth(), date.getDate());
3632
3616
  }
3633
3617
 
3634
- const TableLink = ({
3635
- item,
3636
- type,
3637
- title,
3638
- longTitle,
3639
- active,
3640
- disabled,
3641
- today,
3642
- autofocus,
3643
- onClick,
3644
- intl: {
3645
- formatMessage
3646
- }
3647
- }) => {
3648
- const buttonRef = React.useRef(null);
3649
- React.useEffect(() => {
3650
- if (autofocus) {
3651
- setTimeout(() => {
3652
- buttonRef.current?.focus();
3653
- }, 0);
3654
- }
3655
- }, [autofocus]);
3656
- const onCalendarClick = event => {
3618
+ class TableLink extends React.PureComponent {
3619
+ onClick = event => {
3657
3620
  event.preventDefault();
3658
- if (!disabled) {
3659
- onClick(item);
3621
+ if (!this.props.disabled) {
3622
+ this.props.onClick(this.props.item);
3660
3623
  }
3661
3624
  };
3662
- const calculateAriaLabel = () => {
3625
+ calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
3663
3626
  if (active) {
3664
- return `${longTitle || title || ''}, ${formatMessage(messages$6.selected)} ${formatMessage(messages$6[type])}`;
3627
+ return `${longTitle || title}, ${formatMessage(messages$6.selected)} ${formatMessage(messages$6[type])}`;
3665
3628
  }
3666
3629
  return longTitle || title;
3667
3630
  };
3668
- return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
3669
- children: /*#__PURE__*/jsxRuntime.jsx("button", {
3670
- ref: buttonRef,
3671
- type: "button",
3672
- className: classNames__default.default(`tw-date-lookup-${type}-option np-text-body-default-bold`, {
3673
- active: !!active
3674
- }, {
3675
- today: !!today
3676
- }),
3677
- disabled: disabled,
3678
- tabIndex: autofocus ? 0 : -1,
3679
- "aria-label": calculateAriaLabel(),
3680
- "aria-pressed": active,
3681
- onClick: onCalendarClick,
3682
- children: title || item
3683
- })
3684
- });
3631
+ render() {
3632
+ const {
3633
+ item,
3634
+ type,
3635
+ title,
3636
+ longTitle,
3637
+ active,
3638
+ disabled,
3639
+ today,
3640
+ intl: {
3641
+ formatMessage
3642
+ }
3643
+ } = this.props;
3644
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
3645
+ children: /*#__PURE__*/jsxRuntime.jsx("button", {
3646
+ type: "button",
3647
+ className: `tw-date-lookup-${type}-option ${active ? 'active' : ''} ${today ? 'today' : ''} np-text-body-default-bold`,
3648
+ disabled: disabled,
3649
+ "aria-label": this.calculateAriaLabel(longTitle, title, active, type, formatMessage),
3650
+ "aria-pressed": active,
3651
+ onClick: this.onClick,
3652
+ children: title || item
3653
+ })
3654
+ });
3655
+ }
3656
+ }
3657
+ TableLink.propTypes = {
3658
+ item: PropTypes__default.default.number.isRequired,
3659
+ // day (1-31), month (0-11) or year (2018 etc)
3660
+ type: PropTypes__default.default.oneOf(['day', 'month', 'year']).isRequired,
3661
+ title: PropTypes__default.default.string,
3662
+ longTitle: PropTypes__default.default.string,
3663
+ active: PropTypes__default.default.bool.isRequired,
3664
+ disabled: PropTypes__default.default.bool.isRequired,
3665
+ today: PropTypes__default.default.bool.isRequired,
3666
+ onClick: PropTypes__default.default.func.isRequired
3667
+ };
3668
+ TableLink.defaultProps = {
3669
+ title: null,
3670
+ longTitle: null
3685
3671
  };
3686
3672
  var TableLink$1 = reactIntl.injectIntl(TableLink);
3687
3673
 
@@ -3754,17 +3740,6 @@ class DayCalendarTable extends React.PureComponent {
3754
3740
  } = this.props;
3755
3741
  return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
3756
3742
  };
3757
- isToday = day => {
3758
- const {
3759
- viewMonth,
3760
- viewYear
3761
- } = this.props;
3762
- return +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day);
3763
- };
3764
- getAutofocusDay = weeks => {
3765
- const days = weeks.flatMap(week => week);
3766
- return getFocusableTime(this.isActive, this.isToday, this.isDisabled, days);
3767
- };
3768
3743
  render() {
3769
3744
  const {
3770
3745
  viewMonth,
@@ -3774,7 +3749,6 @@ class DayCalendarTable extends React.PureComponent {
3774
3749
  }
3775
3750
  } = this.props;
3776
3751
  const weeks = this.getTableStructure();
3777
- let autoFocusDay = this.getAutofocusDay(weeks, viewMonth, viewYear);
3778
3752
  return /*#__PURE__*/jsxRuntime.jsxs("table", {
3779
3753
  className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
3780
3754
  children: [/*#__PURE__*/jsxRuntime.jsx("thead", {
@@ -3804,11 +3778,10 @@ class DayCalendarTable extends React.PureComponent {
3804
3778
  item: day,
3805
3779
  type: "day",
3806
3780
  title: formatting.formatDate(new Date(viewYear, viewMonth, day), locale, SHORT_DAY_FORMAT),
3807
- autofocus: day === autoFocusDay,
3808
3781
  longTitle: formatting.formatDate(new Date(viewYear, viewMonth, day), locale),
3809
3782
  active: this.isActive(day),
3810
3783
  disabled: this.isDisabled(day),
3811
- today: this.isToday(day),
3784
+ today: +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day),
3812
3785
  onClick: this.selectDay
3813
3786
  })
3814
3787
  }, dayIndex))
@@ -3909,11 +3882,11 @@ var DayCalendar$1 = reactIntl.injectIntl(DayCalendar);
3909
3882
 
3910
3883
  const ROWS$1 = 3;
3911
3884
  const COLS$1 = 4;
3912
- const MONTH_ONLY_FORMAT = {
3885
+ const MONTH_ONLY_FORMAY = {
3913
3886
  month: 'short'
3914
3887
  };
3915
3888
  const MonthCalendarTable = ({
3916
- selectedDate,
3889
+ selectedDate: selected,
3917
3890
  min,
3918
3891
  max,
3919
3892
  viewYear,
@@ -3923,32 +3896,19 @@ const MonthCalendarTable = ({
3923
3896
  const {
3924
3897
  locale
3925
3898
  } = reactIntl.useIntl();
3926
- const getLink = month => {
3927
- return /*#__PURE__*/jsxRuntime.jsx(TableLink$1, {
3928
- item: month,
3929
- type: "month",
3930
- title: formatting.formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAT),
3931
- active: isSelected(month),
3932
- disabled: isDisabled(month),
3933
- today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
3934
- autofocus: autofocusMonth === month,
3935
- onClick: onSelect
3936
- });
3937
- };
3938
- const isSelected = month => {
3939
- return selectedDate && month === selectedDate.getMonth() && viewYear === selectedDate.getFullYear();
3940
- };
3941
- const isThisMonth = month => {
3942
- return viewYear === new Date().getFullYear() && month === new Date().getMonth();
3943
- };
3899
+ const getLink = month => /*#__PURE__*/jsxRuntime.jsx(TableLink$1, {
3900
+ item: month,
3901
+ type: "month",
3902
+ title: formatting.formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAY),
3903
+ active: !!(selected && month === selected.getMonth() && viewYear === selected.getFullYear()),
3904
+ disabled: isDisabled(month),
3905
+ today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
3906
+ onClick: onSelect
3907
+ });
3944
3908
  const isDisabled = month => {
3945
3909
  const date = new Date(viewYear, month);
3946
3910
  return !!(min && date < new Date(min.getFullYear(), min.getMonth()) || max && date > new Date(max.getFullYear(), max.getMonth()));
3947
3911
  };
3948
- const autofocusMonth = (() => {
3949
- const months = [...new Array(ROWS$1 * COLS$1)].map((_, index) => index);
3950
- return getFocusableTime(isSelected, isThisMonth, isDisabled, months);
3951
- })();
3952
3912
  return /*#__PURE__*/jsxRuntime.jsxs("table", {
3953
3913
  className: "table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0",
3954
3914
  children: [/*#__PURE__*/jsxRuntime.jsx("thead", {
@@ -4067,31 +4027,15 @@ const YearCalendarTable = ({
4067
4027
  locale
4068
4028
  } = reactIntl.useIntl();
4069
4029
  const startYear = viewYear - viewYear % 20;
4070
- const getLink = year => {
4071
- return /*#__PURE__*/jsxRuntime.jsx(TableLink$1, {
4072
- item: year,
4073
- type: "year",
4074
- title: formatting.formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
4075
- active: !!(selectedDate && year === selectedDate.getFullYear()),
4076
- disabled: isDisabled(year),
4077
- today: year === new Date().getFullYear(),
4078
- autofocus: autofocusYear === year,
4079
- onClick: onSelect
4080
- });
4081
- };
4082
- const isSelected = 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(isSelected, isThisYear, isDisabled, years);
4094
- })();
4030
+ const getLink = year => /*#__PURE__*/jsxRuntime.jsx(TableLink$1, {
4031
+ item: year,
4032
+ type: "year",
4033
+ title: formatting.formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
4034
+ active: !!(selectedDate && year === selectedDate.getFullYear()),
4035
+ disabled: !!(min && year < min.getFullYear() || max && year > max.getFullYear()),
4036
+ today: year === new Date().getFullYear(),
4037
+ onClick: onSelect
4038
+ });
4095
4039
  return /*#__PURE__*/jsxRuntime.jsxs("table", {
4096
4040
  className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
4097
4041
  children: [/*#__PURE__*/jsxRuntime.jsx("thead", {
@@ -4198,7 +4142,6 @@ class DateLookup extends React.PureComponent {
4198
4142
  super(props);
4199
4143
  this.state = {
4200
4144
  selectedDate: getStartOfDay(props.value),
4201
- originalDate: null,
4202
4145
  min: getStartOfDay(props.min),
4203
4146
  max: getStartOfDay(props.max),
4204
4147
  viewMonth: (props.value || new Date()).getMonth(),
@@ -4261,15 +4204,6 @@ class DateLookup extends React.PureComponent {
4261
4204
  onFocus();
4262
4205
  }
4263
4206
  };
4264
- discard = () => {
4265
- const {
4266
- originalDate
4267
- } = this.state;
4268
- if (originalDate !== null) {
4269
- this.props.onChange(originalDate);
4270
- }
4271
- this.close();
4272
- };
4273
4207
  close = () => {
4274
4208
  const {
4275
4209
  onBlur
@@ -4283,8 +4217,7 @@ class DateLookup extends React.PureComponent {
4283
4217
  };
4284
4218
  handleKeyDown = event => {
4285
4219
  const {
4286
- open,
4287
- originalDate
4220
+ open
4288
4221
  } = this.state;
4289
4222
  switch (event.keyCode) {
4290
4223
  case KeyCodes.LEFT:
@@ -4320,7 +4253,6 @@ class DateLookup extends React.PureComponent {
4320
4253
  event.preventDefault();
4321
4254
  break;
4322
4255
  case KeyCodes.ESCAPE:
4323
- originalDate && this.props.onChange(originalDate);
4324
4256
  this.close();
4325
4257
  event.preventDefault();
4326
4258
  break;
@@ -4331,14 +4263,8 @@ class DateLookup extends React.PureComponent {
4331
4263
  selectedDate,
4332
4264
  min,
4333
4265
  max,
4334
- mode,
4335
- originalDate
4266
+ mode
4336
4267
  } = this.state;
4337
- if (originalDate === null) {
4338
- this.setState({
4339
- originalDate: selectedDate
4340
- });
4341
- }
4342
4268
  let date;
4343
4269
  if (selectedDate) {
4344
4270
  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());
@@ -4471,7 +4397,7 @@ class DateLookup extends React.PureComponent {
4471
4397
  open: open,
4472
4398
  className: "tw-date-lookup-menu",
4473
4399
  position: exports.Position.BOTTOM,
4474
- onClose: this.discard,
4400
+ onClose: this.close,
4475
4401
  children: this.getCalendar()
4476
4402
  })]
4477
4403
  });