@transferwise/components 0.0.0-experimental-bb03a6a → 0.0.0-experimental-c420d29

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.
@@ -1,19 +1,5 @@
1
- /// <reference types="react" />
2
- import { IntlShape } from 'react-intl';
3
- interface TableLinkProps {
4
- item: number;
5
- type: 'day' | 'month' | 'year';
6
- title?: string;
7
- longTitle?: string;
8
- active: boolean;
9
- disabled: boolean;
10
- today: boolean;
11
- autofocus?: boolean;
12
- onClick: (item: number) => void;
13
- intl: IntlShape;
14
- }
15
- declare const _default: import("react").FC<import("react-intl").WithIntlProps<TableLinkProps>> & {
16
- WrappedComponent: import("react").ComponentType<TableLinkProps>;
1
+ declare const _default: import("react").FC<import("react-intl").WithIntlProps<any>> & {
2
+ WrappedComponent: import("react").ComponentType<any>;
17
3
  };
18
4
  export default _default;
19
5
  //# sourceMappingURL=TableLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TableLink.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/TableLink.tsx"],"names":[],"mappings":";AACA,OAAO,EAAc,SAAS,EAAE,MAAM,YAAY,CAAC;AAInD,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,SAAS,CAAC;CACjB;;;;AAyDD,wBAAqC"}
1
+ {"version":3,"file":"TableLink.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/TableLink.js"],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- export { default } from './TableLink';
1
+ export { default } from "./TableLink";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/index.js"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-bb03a6a",
3
+ "version": "0.0.0-experimental-c420d29",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -85,6 +85,12 @@ describe('Button', () => {
85
85
  render(<Button {...props} className="catsarethebest" />);
86
86
  expect(screen.getByRole('button')).toHaveClass('catsarethebest');
87
87
  });
88
+
89
+ it('passes through aria-label if set', () => {
90
+ render(<Button {...props} aria-label="unique label" />);
91
+ const loadingButton = screen.getByLabelText('unique label');
92
+ expect(loadingButton).toBeInTheDocument();
93
+ });
88
94
  });
89
95
 
90
96
  describe('onClick', () => {
@@ -170,6 +176,12 @@ describe('Button', () => {
170
176
  expect(screen.getByRole('button', { name: 'loading' })).toBeInTheDocument();
171
177
  });
172
178
 
179
+ it('loading button has aria-label of loading', () => {
180
+ render(<Button {...props} loading />);
181
+ const loadingButton = screen.getByLabelText('loading');
182
+ expect(loadingButton).toBeInTheDocument();
183
+ });
184
+
173
185
  it('renders as block if block is true', () => {
174
186
  expect(render(<Button {...props} block />).container).toMatchSnapshot();
175
187
  });
@@ -126,7 +126,7 @@ const Button = forwardRef<ButtonReferenceType, Props>(
126
126
  className={classes}
127
127
  {...props}
128
128
  aria-live={loading ? 'polite' : 'off'}
129
- aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : undefined}
129
+ aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}
130
130
  >
131
131
  {children}
132
132
  {loading && <ProcessIndicator size={processIndicatorSize()} className="btn-loader" />}
@@ -65,30 +65,6 @@ class DayCalendarTable extends PureComponent {
65
65
  return !!(selectedDate && +new Date(viewYear, viewMonth, day) === +selectedDate);
66
66
  };
67
67
 
68
- getAutofocusDay = (weeks) => {
69
- let activeDay = null;
70
- let lowestNonDisabledDay = null;
71
-
72
- for (const week of weeks) {
73
- for (const day of week) {
74
- if (this.isActive(day)) {
75
- activeDay = day;
76
- break;
77
- }
78
-
79
- if (!this.isDisabled(day) && lowestNonDisabledDay === null) {
80
- lowestNonDisabledDay = day;
81
- }
82
- }
83
-
84
- if (activeDay !== null) {
85
- break;
86
- }
87
- }
88
-
89
- return activeDay || lowestNonDisabledDay;
90
- };
91
-
92
68
  render() {
93
69
  const {
94
70
  viewMonth,
@@ -96,7 +72,6 @@ class DayCalendarTable extends PureComponent {
96
72
  intl: { locale },
97
73
  } = this.props;
98
74
  const weeks = this.getTableStructure();
99
- let autoFocusDay = this.getAutofocusDay(weeks);
100
75
  return (
101
76
  <table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
102
77
  <thead>
@@ -128,7 +103,6 @@ class DayCalendarTable extends PureComponent {
128
103
  locale,
129
104
  SHORT_DAY_FORMAT,
130
105
  )}
131
- autofocus={day === autoFocusDay}
132
106
  longTitle={formatDate(new Date(viewYear, viewMonth, day), locale)}
133
107
  active={this.isActive(day)}
134
108
  disabled={this.isDisabled(day)}
@@ -0,0 +1,70 @@
1
+ import PropTypes from 'prop-types';
2
+ import { PureComponent } from 'react';
3
+ import { injectIntl } from 'react-intl';
4
+
5
+ import messages from '../DateLookup.messages';
6
+
7
+ class TableLink extends PureComponent {
8
+ onClick = (event) => {
9
+ event.preventDefault();
10
+ if (!this.props.disabled) {
11
+ this.props.onClick(this.props.item);
12
+ }
13
+ };
14
+
15
+ calculateAriaLabel = (longTitle, title, active, type, formatMessage) => {
16
+ if (active) {
17
+ return `${longTitle || title}, ${formatMessage(messages.selected)} ${formatMessage(
18
+ messages[type],
19
+ )}`;
20
+ }
21
+ return longTitle || title;
22
+ };
23
+
24
+ render() {
25
+ const {
26
+ item,
27
+ type,
28
+ title,
29
+ longTitle,
30
+ active,
31
+ disabled,
32
+ today,
33
+ intl: { formatMessage },
34
+ } = this.props;
35
+ return (
36
+ <>
37
+ <button
38
+ type="button"
39
+ className={`tw-date-lookup-${type}-option ${active ? 'active' : ''} ${
40
+ today ? 'today' : ''
41
+ } np-text-body-default-bold`}
42
+ disabled={disabled}
43
+ aria-label={this.calculateAriaLabel(longTitle, title, active, type, formatMessage)}
44
+ aria-pressed={active}
45
+ onClick={this.onClick}
46
+ >
47
+ {title || item}
48
+ </button>
49
+ </>
50
+ );
51
+ }
52
+ }
53
+
54
+ TableLink.propTypes = {
55
+ item: PropTypes.number.isRequired, // day (1-31), month (0-11) or year (2018 etc)
56
+ type: PropTypes.oneOf(['day', 'month', 'year']).isRequired,
57
+ title: PropTypes.string,
58
+ longTitle: PropTypes.string,
59
+ active: PropTypes.bool.isRequired,
60
+ disabled: PropTypes.bool.isRequired,
61
+ today: PropTypes.bool.isRequired,
62
+ onClick: PropTypes.func.isRequired,
63
+ };
64
+
65
+ TableLink.defaultProps = {
66
+ title: null,
67
+ longTitle: null,
68
+ };
69
+
70
+ export default injectIntl(TableLink);
@@ -1,74 +0,0 @@
1
- import { useEffect, useRef } from 'react';
2
- import { injectIntl, IntlShape } from 'react-intl';
3
-
4
- import messages from '../DateLookup.messages';
5
-
6
- interface TableLinkProps {
7
- item: number;
8
- type: 'day' | 'month' | 'year';
9
- title?: string;
10
- longTitle?: string;
11
- active: boolean;
12
- disabled: boolean;
13
- today: boolean;
14
- autofocus?: boolean;
15
- onClick: (item: number) => void;
16
- intl: IntlShape;
17
- }
18
-
19
- const TableLink = ({
20
- item,
21
- type,
22
- title,
23
- longTitle,
24
- active,
25
- disabled,
26
- today,
27
- autofocus,
28
- onClick,
29
- intl: { formatMessage },
30
- }: TableLinkProps) => {
31
- const buttonRef = useRef<HTMLButtonElement>(null);
32
-
33
- useEffect(() => {
34
- if (autofocus) {
35
- buttonRef.current?.focus();
36
- }
37
- }, []);
38
-
39
- const onCalendarClick = (event: React.MouseEvent<HTMLButtonElement>) => {
40
- event.preventDefault();
41
- if (!disabled) {
42
- onClick(item);
43
- }
44
- };
45
-
46
- const calculateAriaLabel = () => {
47
- if (active) {
48
- return `${longTitle || title || ''}, ${formatMessage(messages.selected)} ${formatMessage(
49
- messages[type],
50
- )}`;
51
- }
52
- return longTitle || title;
53
- };
54
-
55
- return (
56
- <>
57
- <button
58
- ref={buttonRef}
59
- type="button"
60
- className={`tw-date-lookup-${type}-option ${active ? 'active' : ''} ${
61
- today ? 'today' : ''
62
- } np-text-body-default-bold`}
63
- disabled={disabled}
64
- aria-label={calculateAriaLabel()}
65
- aria-pressed={active}
66
- onClick={onCalendarClick}
67
- >
68
- {title || item}
69
- </button>
70
- </>
71
- );
72
- };
73
-
74
- export default injectIntl(TableLink);
File without changes