@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
@@ -2900,6 +2900,8 @@ const INITIAL_DEFAULT_STATE = {
2900
2900
  day: null
2901
2901
  };
2902
2902
  const DateInput = ({
2903
+ 'aria-labelledby': ariaLabelledBy,
2904
+ 'aria-label': ariaLabel,
2903
2905
  disabled,
2904
2906
  size,
2905
2907
  value,
@@ -3087,6 +3089,8 @@ const DateInput = ({
3087
3089
  return /*#__PURE__*/jsx("div", {
3088
3090
  className: "tw-date",
3089
3091
  id: id,
3092
+ "aria-labelledby": ariaLabelledBy,
3093
+ "aria-label": ariaLabel,
3090
3094
  onFocus: event => shouldPropagateOnFocus(event) ? onFocus && onFocus() : event.stopPropagation(),
3091
3095
  onBlur: event => shouldPropagateOnBlur(event) ? onBlur && onBlur() : event.stopPropagation(),
3092
3096
  children: /*#__PURE__*/jsxs("div", {
@@ -3169,6 +3173,8 @@ function shouldPropagateOnBlur({
3169
3173
  return blurElementParent !== focusElementParent;
3170
3174
  }
3171
3175
  DateInput.propTypes = {
3176
+ 'aria-label': PropTypes.string,
3177
+ 'aria-labelledby': PropTypes.string,
3172
3178
  disabled: PropTypes.bool,
3173
3179
  size: PropTypes.oneOf(['sm', 'md', 'lg']),
3174
3180
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
@@ -3564,28 +3570,6 @@ DateHeader.defaultProps = {
3564
3570
  };
3565
3571
  var DateHeader$1 = DateHeader;
3566
3572
 
3567
- function getFocusableTime(isSelected, isNow, isDisabled, timeSpan) {
3568
- let selected = null;
3569
- let now = null;
3570
- let disabled = null;
3571
- for (const time of timeSpan) {
3572
- if (isSelected(time)) {
3573
- selected = time;
3574
- break;
3575
- }
3576
- if (isNow(time)) {
3577
- now = time;
3578
- }
3579
- if (!isDisabled(time) && disabled === null) {
3580
- disabled = time;
3581
- }
3582
- if (selected) {
3583
- break;
3584
- }
3585
- }
3586
- return selected || now || disabled;
3587
- }
3588
-
3589
3573
  // NB! Using with UTC timestamp (YYYY-MM-DD) might lead to unexpected results, for example
3590
3574
  // getStartOfDay(new Date('1995-01-01')) in Los Angeles returns 31 Dec 1994, but in
3591
3575
  // in Singapore it is 1 Jan 1995.
@@ -3597,57 +3581,59 @@ function getStartOfDay(date) {
3597
3581
  return new Date(date.getFullYear(), date.getMonth(), date.getDate());
3598
3582
  }
3599
3583
 
3600
- const TableLink = ({
3601
- item,
3602
- type,
3603
- title,
3604
- longTitle,
3605
- active,
3606
- disabled,
3607
- today,
3608
- autofocus,
3609
- onClick,
3610
- intl: {
3611
- formatMessage
3612
- }
3613
- }) => {
3614
- const buttonRef = useRef(null);
3615
- useEffect(() => {
3616
- if (autofocus) {
3617
- setTimeout(() => {
3618
- buttonRef.current?.focus();
3619
- }, 0);
3620
- }
3621
- }, [autofocus]);
3622
- const onCalendarClick = event => {
3584
+ class TableLink extends PureComponent {
3585
+ onClick = event => {
3623
3586
  event.preventDefault();
3624
- if (!disabled) {
3625
- onClick(item);
3587
+ if (!this.props.disabled) {
3588
+ this.props.onClick(this.props.item);
3626
3589
  }
3627
3590
  };
3628
- const calculateAriaLabel = () => {
3591
+ calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
3629
3592
  if (active) {
3630
- return `${longTitle || title || ''}, ${formatMessage(messages$6.selected)} ${formatMessage(messages$6[type])}`;
3593
+ return `${longTitle || title}, ${formatMessage(messages$6.selected)} ${formatMessage(messages$6[type])}`;
3631
3594
  }
3632
3595
  return longTitle || title;
3633
3596
  };
3634
- return /*#__PURE__*/jsx(Fragment, {
3635
- children: /*#__PURE__*/jsx("button", {
3636
- ref: buttonRef,
3637
- type: "button",
3638
- className: classNames(`tw-date-lookup-${type}-option np-text-body-default-bold`, {
3639
- active: !!active
3640
- }, {
3641
- today: !!today
3642
- }),
3643
- disabled: disabled,
3644
- tabIndex: autofocus ? 0 : -1,
3645
- "aria-label": calculateAriaLabel(),
3646
- "aria-pressed": active,
3647
- onClick: onCalendarClick,
3648
- children: title || item
3649
- })
3650
- });
3597
+ render() {
3598
+ const {
3599
+ item,
3600
+ type,
3601
+ title,
3602
+ longTitle,
3603
+ active,
3604
+ disabled,
3605
+ today,
3606
+ intl: {
3607
+ formatMessage
3608
+ }
3609
+ } = this.props;
3610
+ return /*#__PURE__*/jsx(Fragment, {
3611
+ children: /*#__PURE__*/jsx("button", {
3612
+ type: "button",
3613
+ className: `tw-date-lookup-${type}-option ${active ? 'active' : ''} ${today ? 'today' : ''} np-text-body-default-bold`,
3614
+ disabled: disabled,
3615
+ "aria-label": this.calculateAriaLabel(longTitle, title, active, type, formatMessage),
3616
+ "aria-pressed": active,
3617
+ onClick: this.onClick,
3618
+ children: title || item
3619
+ })
3620
+ });
3621
+ }
3622
+ }
3623
+ TableLink.propTypes = {
3624
+ item: PropTypes.number.isRequired,
3625
+ // day (1-31), month (0-11) or year (2018 etc)
3626
+ type: PropTypes.oneOf(['day', 'month', 'year']).isRequired,
3627
+ title: PropTypes.string,
3628
+ longTitle: PropTypes.string,
3629
+ active: PropTypes.bool.isRequired,
3630
+ disabled: PropTypes.bool.isRequired,
3631
+ today: PropTypes.bool.isRequired,
3632
+ onClick: PropTypes.func.isRequired
3633
+ };
3634
+ TableLink.defaultProps = {
3635
+ title: null,
3636
+ longTitle: null
3651
3637
  };
3652
3638
  var TableLink$1 = injectIntl(TableLink);
3653
3639
 
@@ -3720,17 +3706,6 @@ class DayCalendarTable extends PureComponent {
3720
3706
  } = this.props;
3721
3707
  return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
3722
3708
  };
3723
- isToday = day => {
3724
- const {
3725
- viewMonth,
3726
- viewYear
3727
- } = this.props;
3728
- return +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day);
3729
- };
3730
- getAutofocusDay = weeks => {
3731
- const days = weeks.flatMap(week => week);
3732
- return getFocusableTime(this.isActive, this.isToday, this.isDisabled, days);
3733
- };
3734
3709
  render() {
3735
3710
  const {
3736
3711
  viewMonth,
@@ -3740,7 +3715,6 @@ class DayCalendarTable extends PureComponent {
3740
3715
  }
3741
3716
  } = this.props;
3742
3717
  const weeks = this.getTableStructure();
3743
- let autoFocusDay = this.getAutofocusDay(weeks, viewMonth, viewYear);
3744
3718
  return /*#__PURE__*/jsxs("table", {
3745
3719
  className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
3746
3720
  children: [/*#__PURE__*/jsx("thead", {
@@ -3770,11 +3744,10 @@ class DayCalendarTable extends PureComponent {
3770
3744
  item: day,
3771
3745
  type: "day",
3772
3746
  title: formatDate(new Date(viewYear, viewMonth, day), locale, SHORT_DAY_FORMAT),
3773
- autofocus: day === autoFocusDay,
3774
3747
  longTitle: formatDate(new Date(viewYear, viewMonth, day), locale),
3775
3748
  active: this.isActive(day),
3776
3749
  disabled: this.isDisabled(day),
3777
- today: this.isToday(day),
3750
+ today: +getStartOfDay(new Date()) === +new Date(viewYear, viewMonth, day),
3778
3751
  onClick: this.selectDay
3779
3752
  })
3780
3753
  }, dayIndex))
@@ -3875,11 +3848,11 @@ var DayCalendar$1 = injectIntl(DayCalendar);
3875
3848
 
3876
3849
  const ROWS$1 = 3;
3877
3850
  const COLS$1 = 4;
3878
- const MONTH_ONLY_FORMAT = {
3851
+ const MONTH_ONLY_FORMAY = {
3879
3852
  month: 'short'
3880
3853
  };
3881
3854
  const MonthCalendarTable = ({
3882
- selectedDate,
3855
+ selectedDate: selected,
3883
3856
  min,
3884
3857
  max,
3885
3858
  viewYear,
@@ -3889,32 +3862,19 @@ const MonthCalendarTable = ({
3889
3862
  const {
3890
3863
  locale
3891
3864
  } = useIntl();
3892
- const getLink = month => {
3893
- return /*#__PURE__*/jsx(TableLink$1, {
3894
- item: month,
3895
- type: "month",
3896
- title: formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAT),
3897
- active: isSelected(month),
3898
- disabled: isDisabled(month),
3899
- today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
3900
- autofocus: autofocusMonth === month,
3901
- onClick: onSelect
3902
- });
3903
- };
3904
- const isSelected = month => {
3905
- return selectedDate && month === selectedDate.getMonth() && viewYear === selectedDate.getFullYear();
3906
- };
3907
- const isThisMonth = month => {
3908
- return viewYear === new Date().getFullYear() && month === new Date().getMonth();
3909
- };
3865
+ const getLink = month => /*#__PURE__*/jsx(TableLink$1, {
3866
+ item: month,
3867
+ type: "month",
3868
+ title: formatDate(new Date(viewYear, month), locale, MONTH_ONLY_FORMAY),
3869
+ active: !!(selected && month === selected.getMonth() && viewYear === selected.getFullYear()),
3870
+ disabled: isDisabled(month),
3871
+ today: viewYear === new Date().getFullYear() && month === new Date().getMonth(),
3872
+ onClick: onSelect
3873
+ });
3910
3874
  const isDisabled = month => {
3911
3875
  const date = new Date(viewYear, month);
3912
3876
  return !!(min && date < new Date(min.getFullYear(), min.getMonth()) || max && date > new Date(max.getFullYear(), max.getMonth()));
3913
3877
  };
3914
- const autofocusMonth = (() => {
3915
- const months = [...new Array(ROWS$1 * COLS$1)].map((_, index) => index);
3916
- return getFocusableTime(isSelected, isThisMonth, isDisabled, months);
3917
- })();
3918
3878
  return /*#__PURE__*/jsxs("table", {
3919
3879
  className: "table table-condensed table-bordered tw-date-lookup-calendar np-text-body-default-bold m-b-0",
3920
3880
  children: [/*#__PURE__*/jsx("thead", {
@@ -4033,31 +3993,15 @@ const YearCalendarTable = ({
4033
3993
  locale
4034
3994
  } = useIntl();
4035
3995
  const startYear = viewYear - viewYear % 20;
4036
- const getLink = year => {
4037
- return /*#__PURE__*/jsx(TableLink$1, {
4038
- item: year,
4039
- type: "year",
4040
- title: formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
4041
- active: !!(selectedDate && year === selectedDate.getFullYear()),
4042
- disabled: isDisabled(year),
4043
- today: year === new Date().getFullYear(),
4044
- autofocus: autofocusYear === year,
4045
- onClick: onSelect
4046
- });
4047
- };
4048
- const isSelected = 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(isSelected, isThisYear, isDisabled, years);
4060
- })();
3996
+ const getLink = year => /*#__PURE__*/jsx(TableLink$1, {
3997
+ item: year,
3998
+ type: "year",
3999
+ title: formatDate(new Date(year, 0), locale, YEAR_ONLY_FORMAT),
4000
+ active: !!(selectedDate && year === selectedDate.getFullYear()),
4001
+ disabled: !!(min && year < min.getFullYear() || max && year > max.getFullYear()),
4002
+ today: year === new Date().getFullYear(),
4003
+ onClick: onSelect
4004
+ });
4061
4005
  return /*#__PURE__*/jsxs("table", {
4062
4006
  className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
4063
4007
  children: [/*#__PURE__*/jsx("thead", {
@@ -4164,7 +4108,6 @@ class DateLookup extends PureComponent {
4164
4108
  super(props);
4165
4109
  this.state = {
4166
4110
  selectedDate: getStartOfDay(props.value),
4167
- originalDate: null,
4168
4111
  min: getStartOfDay(props.min),
4169
4112
  max: getStartOfDay(props.max),
4170
4113
  viewMonth: (props.value || new Date()).getMonth(),
@@ -4227,15 +4170,6 @@ class DateLookup extends PureComponent {
4227
4170
  onFocus();
4228
4171
  }
4229
4172
  };
4230
- discard = () => {
4231
- const {
4232
- originalDate
4233
- } = this.state;
4234
- if (originalDate !== null) {
4235
- this.props.onChange(originalDate);
4236
- }
4237
- this.close();
4238
- };
4239
4173
  close = () => {
4240
4174
  const {
4241
4175
  onBlur
@@ -4249,8 +4183,7 @@ class DateLookup extends PureComponent {
4249
4183
  };
4250
4184
  handleKeyDown = event => {
4251
4185
  const {
4252
- open,
4253
- originalDate
4186
+ open
4254
4187
  } = this.state;
4255
4188
  switch (event.keyCode) {
4256
4189
  case KeyCodes.LEFT:
@@ -4286,7 +4219,6 @@ class DateLookup extends PureComponent {
4286
4219
  event.preventDefault();
4287
4220
  break;
4288
4221
  case KeyCodes.ESCAPE:
4289
- originalDate && this.props.onChange(originalDate);
4290
4222
  this.close();
4291
4223
  event.preventDefault();
4292
4224
  break;
@@ -4297,14 +4229,8 @@ class DateLookup extends PureComponent {
4297
4229
  selectedDate,
4298
4230
  min,
4299
4231
  max,
4300
- mode,
4301
- originalDate
4232
+ mode
4302
4233
  } = this.state;
4303
- if (originalDate === null) {
4304
- this.setState({
4305
- originalDate: selectedDate
4306
- });
4307
- }
4308
4234
  let date;
4309
4235
  if (selectedDate) {
4310
4236
  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());
@@ -4437,7 +4363,7 @@ class DateLookup extends PureComponent {
4437
4363
  open: open,
4438
4364
  className: "tw-date-lookup-menu",
4439
4365
  position: Position.BOTTOM,
4440
- onClose: this.discard,
4366
+ onClose: this.close,
4441
4367
  children: this.getCalendar()
4442
4368
  })]
4443
4369
  });