@transferwise/components 0.0.0-experimental-45502d0 → 0.0.0-experimental-bb03a6a

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.js CHANGED
@@ -2320,7 +2320,6 @@ const Button = /*#__PURE__*/React.forwardRef(({
2320
2320
  priority = exports.Priority.PRIMARY,
2321
2321
  size = exports.Size.MEDIUM,
2322
2322
  type = exports.ControlType.ACCENT,
2323
- 'aria-label': ariaLabel,
2324
2323
  ...rest
2325
2324
  }, reference) => {
2326
2325
  const intl = reactIntl.useIntl();
@@ -2370,7 +2369,7 @@ const Button = /*#__PURE__*/React.forwardRef(({
2370
2369
  className: classes,
2371
2370
  ...props,
2372
2371
  "aria-live": loading ? 'polite' : 'off',
2373
- "aria-label": loading ? intl.formatMessage(messages$9.loadingAriaLabel) : ariaLabel,
2372
+ "aria-label": loading ? intl.formatMessage(messages$9.loadingAriaLabel) : undefined,
2374
2373
  children: [children, loading && /*#__PURE__*/jsxRuntime.jsx(ProcessIndicator$1, {
2375
2374
  size: processIndicatorSize(),
2376
2375
  className: "btn-loader"
@@ -3507,59 +3506,50 @@ function getStartOfDay(date) {
3507
3506
  return new Date(date.getFullYear(), date.getMonth(), date.getDate());
3508
3507
  }
3509
3508
 
3510
- class TableLink extends React.PureComponent {
3511
- onClick = event => {
3509
+ const TableLink = ({
3510
+ item,
3511
+ type,
3512
+ title,
3513
+ longTitle,
3514
+ active,
3515
+ disabled,
3516
+ today,
3517
+ autofocus,
3518
+ onClick,
3519
+ intl: {
3520
+ formatMessage
3521
+ }
3522
+ }) => {
3523
+ const buttonRef = React.useRef(null);
3524
+ React.useEffect(() => {
3525
+ if (autofocus) {
3526
+ buttonRef.current?.focus();
3527
+ }
3528
+ }, []);
3529
+ const onCalendarClick = event => {
3512
3530
  event.preventDefault();
3513
- if (!this.props.disabled) {
3514
- this.props.onClick(this.props.item);
3531
+ if (!disabled) {
3532
+ onClick(item);
3515
3533
  }
3516
3534
  };
3517
- calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
3535
+ const calculateAriaLabel = () => {
3518
3536
  if (active) {
3519
- return `${longTitle || title}, ${formatMessage(messages$5.selected)} ${formatMessage(messages$5[type])}`;
3537
+ return `${longTitle || title || ''}, ${formatMessage(messages$5.selected)} ${formatMessage(messages$5[type])}`;
3520
3538
  }
3521
3539
  return longTitle || title;
3522
3540
  };
3523
- render() {
3524
- const {
3525
- item,
3526
- type,
3527
- title,
3528
- longTitle,
3529
- active,
3530
- disabled,
3531
- today,
3532
- intl: {
3533
- formatMessage
3534
- }
3535
- } = this.props;
3536
- return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
3537
- children: /*#__PURE__*/jsxRuntime.jsx("button", {
3538
- type: "button",
3539
- className: `tw-date-lookup-${type}-option ${active ? 'active' : ''} ${today ? 'today' : ''} np-text-body-default-bold`,
3540
- disabled: disabled,
3541
- "aria-label": this.calculateAriaLabel(longTitle, title, active, type, formatMessage),
3542
- "aria-pressed": active,
3543
- onClick: this.onClick,
3544
- children: title || item
3545
- })
3546
- });
3547
- }
3548
- }
3549
- TableLink.propTypes = {
3550
- item: PropTypes__default.default.number.isRequired,
3551
- // day (1-31), month (0-11) or year (2018 etc)
3552
- type: PropTypes__default.default.oneOf(['day', 'month', 'year']).isRequired,
3553
- title: PropTypes__default.default.string,
3554
- longTitle: PropTypes__default.default.string,
3555
- active: PropTypes__default.default.bool.isRequired,
3556
- disabled: PropTypes__default.default.bool.isRequired,
3557
- today: PropTypes__default.default.bool.isRequired,
3558
- onClick: PropTypes__default.default.func.isRequired
3559
- };
3560
- TableLink.defaultProps = {
3561
- title: null,
3562
- longTitle: null
3541
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
3542
+ children: /*#__PURE__*/jsxRuntime.jsx("button", {
3543
+ ref: buttonRef,
3544
+ type: "button",
3545
+ className: `tw-date-lookup-${type}-option ${active ? 'active' : ''} ${today ? 'today' : ''} np-text-body-default-bold`,
3546
+ disabled: disabled,
3547
+ "aria-label": calculateAriaLabel(),
3548
+ "aria-pressed": active,
3549
+ onClick: onCalendarClick,
3550
+ children: title || item
3551
+ })
3552
+ });
3563
3553
  };
3564
3554
  var TableLink$1 = reactIntl.injectIntl(TableLink);
3565
3555
 
@@ -3632,6 +3622,25 @@ class DayCalendarTable extends React.PureComponent {
3632
3622
  } = this.props;
3633
3623
  return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
3634
3624
  };
3625
+ getAutofocusDay = weeks => {
3626
+ let activeDay = null;
3627
+ let lowestNonDisabledDay = null;
3628
+ for (const week of weeks) {
3629
+ for (const day of week) {
3630
+ if (this.isActive(day)) {
3631
+ activeDay = day;
3632
+ break;
3633
+ }
3634
+ if (!this.isDisabled(day) && lowestNonDisabledDay === null) {
3635
+ lowestNonDisabledDay = day;
3636
+ }
3637
+ }
3638
+ if (activeDay !== null) {
3639
+ break;
3640
+ }
3641
+ }
3642
+ return activeDay || lowestNonDisabledDay;
3643
+ };
3635
3644
  render() {
3636
3645
  const {
3637
3646
  viewMonth,
@@ -3641,6 +3650,7 @@ class DayCalendarTable extends React.PureComponent {
3641
3650
  }
3642
3651
  } = this.props;
3643
3652
  const weeks = this.getTableStructure();
3653
+ let autoFocusDay = this.getAutofocusDay(weeks);
3644
3654
  return /*#__PURE__*/jsxRuntime.jsxs("table", {
3645
3655
  className: "table table-condensed table-bordered tw-date-lookup-calendar m-b-0",
3646
3656
  children: [/*#__PURE__*/jsxRuntime.jsx("thead", {
@@ -3670,6 +3680,7 @@ class DayCalendarTable extends React.PureComponent {
3670
3680
  item: day,
3671
3681
  type: "day",
3672
3682
  title: formatting.formatDate(new Date(viewYear, viewMonth, day), locale, SHORT_DAY_FORMAT),
3683
+ autofocus: day === autoFocusDay,
3673
3684
  longTitle: formatting.formatDate(new Date(viewYear, viewMonth, day), locale),
3674
3685
  active: this.isActive(day),
3675
3686
  disabled: this.isDisabled(day),