@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.esm.js +59 -48
- package/build/index.esm.js.map +1 -1
- package/build/index.js +59 -48
- package/build/index.js.map +1 -1
- package/build/types/button/Button.d.ts +0 -1
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/dateLookup/tableLink/TableLink.d.ts +16 -2
- package/build/types/dateLookup/tableLink/TableLink.d.ts.map +1 -1
- package/build/types/dateLookup/tableLink/index.d.ts +1 -1
- package/build/types/dateLookup/tableLink/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/button/Button.spec.js +0 -12
- package/src/button/Button.tsx +1 -3
- package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +26 -0
- package/src/dateLookup/tableLink/TableLink.tsx +74 -0
- package/src/dateLookup/tableLink/TableLink.js +0 -70
- /package/src/dateLookup/tableLink/{index.js → index.ts} +0 -0
|
@@ -12,7 +12,6 @@ export type CommonProps = {
|
|
|
12
12
|
type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes;
|
|
13
13
|
priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary;
|
|
14
14
|
size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;
|
|
15
|
-
'aria-label'?: string;
|
|
16
15
|
};
|
|
17
16
|
export type ButtonProps = CommonProps & Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'type'> & {
|
|
18
17
|
as?: 'button';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.d.ts","sourceRoot":"","sources":["../../../src/button/Button.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,WAAW,EAAc,MAAM,OAAO,CAAC;AAG5F,OAAO,EAIL,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,iB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C;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,iBAAiB,GAAG,mBAAmB,GAAG,mBAAmB,GAAG,eAAe,CAAC;IACvF,QAAQ,CAAC,EAAE,eAAe,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;IAClE,IAAI,CAAC,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,eAAe,CAAC;CAC7D,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,WAAW,GACnC,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,GAAG;IACtD,EAAE,CAAC,EAAE,QAAQ,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;CAC1C,CAAC;AAEJ,MAAM,MAAM,WAAW,GAAG,WAAW,GACnC,oBAAoB,CAAC,iBAAiB,CAAC,GACvC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,GAAG;IACxB,EAAE,CAAC,EAAE,GAAG,CAAC;IACT,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEJ,MAAM,MAAM,KAAK,GAAG,WAAW,GAAG,WAAW,CAAC;AAE9C,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,GAAG,iBAAiB,CAAC;AAExE,QAAA,MAAM,MAAM,uGA4EX,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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>;
|
|
3
17
|
};
|
|
4
18
|
export default _default;
|
|
5
19
|
//# sourceMappingURL=TableLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableLink.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/TableLink.
|
|
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,2 +1,2 @@
|
|
|
1
|
-
export { default } from
|
|
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.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -85,12 +85,6 @@ 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
|
-
});
|
|
94
88
|
});
|
|
95
89
|
|
|
96
90
|
describe('onClick', () => {
|
|
@@ -176,12 +170,6 @@ describe('Button', () => {
|
|
|
176
170
|
expect(screen.getByRole('button', { name: 'loading' })).toBeInTheDocument();
|
|
177
171
|
});
|
|
178
172
|
|
|
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
|
-
|
|
185
173
|
it('renders as block if block is true', () => {
|
|
186
174
|
expect(render(<Button {...props} block />).container).toMatchSnapshot();
|
|
187
175
|
});
|
package/src/button/Button.tsx
CHANGED
|
@@ -38,7 +38,6 @@ export type CommonProps = {
|
|
|
38
38
|
type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes;
|
|
39
39
|
priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary;
|
|
40
40
|
size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;
|
|
41
|
-
'aria-label'?: string;
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
export type ButtonProps = CommonProps &
|
|
@@ -70,7 +69,6 @@ const Button = forwardRef<ButtonReferenceType, Props>(
|
|
|
70
69
|
priority = Priority.PRIMARY,
|
|
71
70
|
size = Size.MEDIUM,
|
|
72
71
|
type = ControlType.ACCENT,
|
|
73
|
-
'aria-label': ariaLabel,
|
|
74
72
|
...rest
|
|
75
73
|
}: Props,
|
|
76
74
|
reference,
|
|
@@ -128,7 +126,7 @@ const Button = forwardRef<ButtonReferenceType, Props>(
|
|
|
128
126
|
className={classes}
|
|
129
127
|
{...props}
|
|
130
128
|
aria-live={loading ? 'polite' : 'off'}
|
|
131
|
-
aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) :
|
|
129
|
+
aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : undefined}
|
|
132
130
|
>
|
|
133
131
|
{children}
|
|
134
132
|
{loading && <ProcessIndicator size={processIndicatorSize()} className="btn-loader" />}
|
|
@@ -65,6 +65,30 @@ 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
|
+
|
|
68
92
|
render() {
|
|
69
93
|
const {
|
|
70
94
|
viewMonth,
|
|
@@ -72,6 +96,7 @@ class DayCalendarTable extends PureComponent {
|
|
|
72
96
|
intl: { locale },
|
|
73
97
|
} = this.props;
|
|
74
98
|
const weeks = this.getTableStructure();
|
|
99
|
+
let autoFocusDay = this.getAutofocusDay(weeks);
|
|
75
100
|
return (
|
|
76
101
|
<table className="table table-condensed table-bordered tw-date-lookup-calendar m-b-0">
|
|
77
102
|
<thead>
|
|
@@ -103,6 +128,7 @@ class DayCalendarTable extends PureComponent {
|
|
|
103
128
|
locale,
|
|
104
129
|
SHORT_DAY_FORMAT,
|
|
105
130
|
)}
|
|
131
|
+
autofocus={day === autoFocusDay}
|
|
106
132
|
longTitle={formatDate(new Date(viewYear, viewMonth, day), locale)}
|
|
107
133
|
active={this.isActive(day)}
|
|
108
134
|
disabled={this.isDisabled(day)}
|
|
@@ -0,0 +1,74 @@
|
|
|
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);
|
|
@@ -1,70 +0,0 @@
|
|
|
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);
|
|
File without changes
|