@transferwise/components 45.17.0 → 45.18.0
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/i18n/en.json +1 -0
- package/build/index.esm.js +391 -350
- package/build/index.esm.js.map +1 -1
- package/build/index.js +391 -349
- package/build/index.js.map +1 -1
- package/build/main.css +1 -1
- package/build/styles/common/Option/Option.css +1 -1
- package/build/styles/inputs/SelectInput.css +1 -1
- package/build/styles/instructionsList/InstructionsList.css +1 -1
- package/build/styles/main.css +1 -1
- package/build/styles/stepper/Stepper.css +1 -1
- package/build/styles/tooltip/Tooltip.css +1 -1
- package/build/types/accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/button/Button.messages.d.ts +9 -0
- package/build/types/button/Button.messages.d.ts.map +1 -0
- package/build/types/common/index.d.ts +1 -0
- package/build/types/common/polymorphicWithOverrides/PolymorphicWithOverrides.d.ts +13 -0
- package/build/types/common/polymorphicWithOverrides/PolymorphicWithOverrides.d.ts.map +1 -0
- package/build/types/common/randomId.d.ts +13 -0
- package/build/types/common/randomId.d.ts.map +1 -0
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/inputs/SelectInput.d.ts +16 -6
- package/build/types/inputs/SelectInput.d.ts.map +1 -1
- package/build/types/instructionsList/InstructionsList.d.ts +10 -3
- package/build/types/instructionsList/InstructionsList.d.ts.map +1 -1
- package/build/types/processIndicator/ProcessIndicator.d.ts +1 -1
- package/build/types/promoCard/PromoCard.d.ts.map +1 -1
- package/build/types/select/Select.d.ts.map +1 -1
- package/build/types/select/searchBox/SearchBox.d.ts.map +1 -1
- package/build/types/tooltip/Tooltip.d.ts +2 -1
- package/build/types/tooltip/Tooltip.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/accordion/AccordionItem/AccordionItem.spec.js +1 -0
- package/src/accordion/AccordionItem/AccordionItem.tsx +19 -11
- package/src/accordion/AccordionItem/__snapshots__/AccordionItem.spec.js.snap +18 -4
- package/src/button/Button.messages.js +9 -0
- package/src/button/Button.spec.js +1 -2
- package/src/button/Button.story.tsx +6 -0
- package/src/button/Button.tsx +17 -2
- package/src/button/__snapshots__/Button.spec.js.snap +22 -15
- package/src/common/Option/Option.css +1 -1
- package/src/common/Option/Option.less +0 -5
- package/src/common/index.js +1 -0
- package/src/common/polymorphicWithOverrides/PolymorphicWithOverrides.tsx +19 -0
- package/src/common/randomId.ts +14 -0
- package/src/dateInput/DateInput.story.tsx +0 -3
- package/src/i18n/en.json +1 -0
- package/src/index.ts +3 -0
- package/src/inputs/SelectInput.css +1 -1
- package/src/inputs/SelectInput.less +8 -2
- package/src/inputs/SelectInput.story.tsx +52 -5
- package/src/inputs/SelectInput.tsx +165 -104
- package/src/inputs/_Popover.less +1 -1
- package/src/instructionsList/InstructionList.story.tsx +39 -0
- package/src/instructionsList/InstructionsList.css +1 -1
- package/src/instructionsList/InstructionsList.less +3 -15
- package/src/instructionsList/InstructionsList.spec.tsx +35 -0
- package/src/instructionsList/InstructionsList.tsx +40 -25
- package/src/main.css +1 -1
- package/src/moneyInput/MoneyInput.story.tsx +0 -3
- package/src/phoneNumberInput/PhoneNumberInput.story.js +0 -3
- package/src/processIndicator/ProcessIndicator.js +2 -2
- package/src/promoCard/PromoCard.tsx +1 -16
- package/src/select/Select.js +2 -0
- package/src/select/Select.story.js +0 -6
- package/src/select/searchBox/SearchBox.spec.js +3 -7
- package/src/select/searchBox/SearchBox.tsx +2 -0
- package/src/stepper/Stepper.css +1 -1
- package/src/stepper/Stepper.less +1 -1
- package/src/tooltip/Tooltip.css +1 -1
- package/src/tooltip/Tooltip.less +13 -0
- package/src/tooltip/Tooltip.spec.tsx +97 -29
- package/src/tooltip/Tooltip.tsx +24 -31
- package/src/tooltip/__snapshots__/Tooltip.spec.tsx.snap +31 -0
- package/src/upload/Upload.spec.js +2 -0
- package/src/instructionsList/InstructionList.story.js +0 -27
- package/src/instructionsList/InstructionsList.spec.js +0 -29
- package/src/select/searchBox/__snapshots__/SearchBox.spec.js.snap +0 -46
|
@@ -4,7 +4,7 @@ import { Component } from 'react';
|
|
|
4
4
|
|
|
5
5
|
import { Status, Size } from '../common';
|
|
6
6
|
|
|
7
|
-
const radius = { xs: 11, sm: 22, xl: 61 };
|
|
7
|
+
const radius = { xxs: 6, xs: 11, sm: 22, xl: 61 };
|
|
8
8
|
export const ANIMATION_DURATION_IN_MS = 1500;
|
|
9
9
|
|
|
10
10
|
class ProcessIndicator extends Component {
|
|
@@ -100,7 +100,7 @@ class ProcessIndicator extends Component {
|
|
|
100
100
|
}
|
|
101
101
|
ProcessIndicator.propTypes = {
|
|
102
102
|
status: PropTypes.oneOf(['processing', 'failed', 'succeeded', 'hidden']),
|
|
103
|
-
size: PropTypes.oneOf(['xs', 'sm', 'xl']),
|
|
103
|
+
size: PropTypes.oneOf(['xxs', 'xs', 'sm', 'xl']),
|
|
104
104
|
onAnimationCompleted: PropTypes.func,
|
|
105
105
|
className: PropTypes.string,
|
|
106
106
|
'data-testid': PropTypes.string,
|
|
@@ -3,7 +3,7 @@ import classNames from 'classnames';
|
|
|
3
3
|
import React, { forwardRef, FunctionComponent, ReactElement, useEffect, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import Body from '../body';
|
|
6
|
-
import { Typography } from '../common';
|
|
6
|
+
import { Typography, generateRandomId } from '../common';
|
|
7
7
|
import Card, { CardProps } from '../common/card';
|
|
8
8
|
import Display from '../display';
|
|
9
9
|
import Image from '../image/Image';
|
|
@@ -142,21 +142,6 @@ export type PolymorphicPromoCard = (
|
|
|
142
142
|
props: PromoCardLinkProps | PromoCardCheckedProps,
|
|
143
143
|
) => JSX.Element;
|
|
144
144
|
|
|
145
|
-
/**
|
|
146
|
-
* generateRandomId() function
|
|
147
|
-
*
|
|
148
|
-
* This function generates a random string of characters that can be used as
|
|
149
|
-
* an ID.
|
|
150
|
-
*
|
|
151
|
-
* @returns {string} A random string of characters.
|
|
152
|
-
* @example
|
|
153
|
-
* const id = generateRandomId();
|
|
154
|
-
* // id will be a random string of characters, such as "id-4711".
|
|
155
|
-
*/
|
|
156
|
-
const generateRandomId = (): string => {
|
|
157
|
-
return `id-${Math.random().toString(36).slice(7)}`;
|
|
158
|
-
};
|
|
159
|
-
|
|
160
145
|
/**
|
|
161
146
|
* PromoCard component.
|
|
162
147
|
*
|
package/src/select/Select.js
CHANGED
|
@@ -333,6 +333,8 @@ export default function Select({
|
|
|
333
333
|
ref={optionsListReference}
|
|
334
334
|
id={listboxId}
|
|
335
335
|
role="listbox"
|
|
336
|
+
aria-orientation="vertical"
|
|
337
|
+
aria-activedescendant={getUniqueIdForOption(id, selected)}
|
|
336
338
|
tabIndex="-1"
|
|
337
339
|
className={dropdownClass}
|
|
338
340
|
{...dropdownProps}
|
|
@@ -41,12 +41,6 @@ export const Basic = () => {
|
|
|
41
41
|
return (
|
|
42
42
|
<Select
|
|
43
43
|
id={id}
|
|
44
|
-
buttonProps={{
|
|
45
|
-
'aria-label': 'Basic button',
|
|
46
|
-
}}
|
|
47
|
-
dropdownProps={{
|
|
48
|
-
'aria-label': 'Options for basic button',
|
|
49
|
-
}}
|
|
50
44
|
size={size}
|
|
51
45
|
classNames={`${hasError ? 'has-error' : ''}`}
|
|
52
46
|
placeholder={placeholder}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import '
|
|
2
|
-
|
|
3
|
-
import { render } from '../../test-utils';
|
|
1
|
+
import { render, screen } from '../../test-utils';
|
|
4
2
|
|
|
5
3
|
import SearchBox from '.';
|
|
6
4
|
|
|
7
|
-
jest.mock('react-transition-group/Transition', () => jest.fn('placeholder'));
|
|
8
|
-
|
|
9
5
|
describe('SearchBox', () => {
|
|
10
6
|
const props = {
|
|
11
7
|
classNames: {},
|
|
@@ -17,8 +13,8 @@ describe('SearchBox', () => {
|
|
|
17
13
|
};
|
|
18
14
|
|
|
19
15
|
it('renders', () => {
|
|
20
|
-
|
|
16
|
+
render(<SearchBox {...props} />);
|
|
21
17
|
|
|
22
|
-
expect(
|
|
18
|
+
expect(screen.getByRole('searchbox')).toBeInTheDocument();
|
|
23
19
|
});
|
|
24
20
|
});
|
package/src/stepper/Stepper.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.tw-stepper{padding-bottom:24px;width:100%}@media only screen and (max-width:575px){.tw-stepper{padding-bottom:0}}.tw-stepper__step{list-style-type:none;position:absolute;top:0}.tw-stepper__step--active .tw-stepper__step-label{color:#37517e;color:var(--color-content-primary);cursor:default}.tw-stepper__step--clickable .tw-stepper__step-label{border-radius:2px;color:#0097c7;color:var(--color-content-accent);line-height:0;transition:color .15s ease-in-out}.np-theme-personal .tw-stepper__step--clickable .tw-stepper__step-label{color:#5d7079;color:var(--color-content-secondary);top:0}.tw-stepper__step--has-tooltip{cursor:pointer}@media screen and (min-width:576px) and (max-width:991px){.tw-stepper__step:first-child .tooltip-inner{transform:translateX(calc(50% - 32px))}.tw-stepper__step:last-child .tooltip-inner{transform:translateX(calc(-50% + 32px))}}.tw-stepper__step-label{color:#5d7079;color:var(--color-content-secondary);position:absolute;top:0;transform:translateX(-50%);transition:color .6s ease-in-out;white-space:nowrap}[dir=rtl] .tw-stepper__step-label{transform:translateX(50%)}.tw-stepper .tooltip{top:24px!important;white-space:nowrap}.tw-stepper .tooltip .tooltip-inner{max-width:100%}.tw-stepper .tw-tooltip-container{display:block}.tw-stepper-steps{padding:0;position:relative}[dir=rtl] .tw-stepper-steps{padding:0}.progress-bar{-webkit-backface-visibility:hidden;background-color:var(--color-interactive-primary);border-bottom-left-radius:1px;border-top-left-radius:1px;float:left;height:100%;transition:width .6s ease-in-out;will-change:width}[dir=rtl] .progress-bar{float:right}.progress-bar:after{border-radius:4px;content:"";float:right;height:8px;margin-right:-4px;margin-top:-3px;width:8px}[dir=rtl] .progress-bar:after{float:left;margin-left:-4px;margin-right:0}.btn-unstyled{background:none;border:none;display:block;margin:0;padding:0}
|
|
1
|
+
.tw-stepper{padding-bottom:24px;width:100%}@media only screen and (max-width:575px){.tw-stepper{padding-bottom:0}}.tw-stepper__step{list-style-type:none;position:absolute;top:0}.tw-stepper__step--active .tw-stepper__step-label{color:#37517e;color:var(--color-content-primary);cursor:default}.tw-stepper__step--clickable .tw-stepper__step-label{border-radius:2px;color:#0097c7;color:var(--color-content-accent);line-height:0;transition:color .15s ease-in-out}.np-theme-personal .tw-stepper__step--clickable .tw-stepper__step-label{color:#5d7079;color:var(--color-content-secondary);top:0}.tw-stepper__step--has-tooltip{cursor:pointer}@media screen and (min-width:576px) and (max-width:991px){.tw-stepper__step:first-child .tooltip-inner{transform:translateX(calc(50% - 32px))}.tw-stepper__step:last-child .tooltip-inner{transform:translateX(calc(-50% + 32px))}}.tw-stepper__step-label{color:#5d7079;color:var(--color-content-secondary);position:absolute;top:0;transform:translateX(-50%);transition:color .6s ease-in-out;white-space:nowrap}[dir=rtl] .tw-stepper__step-label{transform:translateX(50%)}.tw-stepper .tooltip{top:24px!important;white-space:nowrap}.tw-stepper .tooltip .tooltip-inner{max-width:100%}.tw-stepper .tw-tooltip-container{display:inline-block}.tw-stepper-steps{padding:0;position:relative}[dir=rtl] .tw-stepper-steps{padding:0}.progress-bar{-webkit-backface-visibility:hidden;background-color:var(--color-interactive-primary);border-bottom-left-radius:1px;border-top-left-radius:1px;float:left;height:100%;transition:width .6s ease-in-out;will-change:width}[dir=rtl] .progress-bar{float:right}.progress-bar:after{border-radius:4px;content:"";float:right;height:8px;margin-right:-4px;margin-top:-3px;width:8px}[dir=rtl] .progress-bar:after{float:left;margin-left:-4px;margin-right:0}.btn-unstyled{background:none;border:none;display:block;margin:0;padding:0}
|
package/src/stepper/Stepper.less
CHANGED
package/src/tooltip/Tooltip.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.tw-tooltip-container{display:inline-block}.tw-tooltip-container .tooltip{-webkit-user-select:none;-moz-user-select:none;user-select:none;visibility:visible}.tw-tooltip-container .tooltip:not(.in){animation:tw-tooltip-disappear;animation-delay:.15s;animation-duration:0s;animation-fill-mode:both;pointer-events:none}@keyframes tw-tooltip-disappear{0%{visibility:visible}to{visibility:hidden}}.np-tooltip{z-index:1070}.np-panel[data-popper-placement^=right]>.np-panel__content.tooltip-inner .np-panel__arrow{left:-7px}.np-panel[data-popper-placement^=left]>.np-panel__content.tooltip-inner .np-panel__arrow{right:-7px}
|
|
1
|
+
.tw-tooltip-container{display:inline-block}.tw-tooltip-container .tooltip{-webkit-user-select:none;-moz-user-select:none;user-select:none;visibility:visible}.tw-tooltip-container .tooltip:not(.in){animation:tw-tooltip-disappear;animation-delay:.15s;animation-duration:0s;animation-fill-mode:both;pointer-events:none}@keyframes tw-tooltip-disappear{0%{visibility:visible}to{visibility:hidden}}.np-tooltip{z-index:1070}.np-tooltip,.np-tooltip .tooltip-inner{visibility:hidden}.np-tooltip--open,.np-tooltip--open .tooltip-inner{visibility:initial}.np-panel[data-popper-placement^=right]>.np-panel__content.tooltip-inner .np-panel__arrow{left:-7px}.np-panel[data-popper-placement^=left]>.np-panel__content.tooltip-inner .np-panel__arrow{right:-7px}
|
package/src/tooltip/Tooltip.less
CHANGED
|
@@ -34,6 +34,19 @@
|
|
|
34
34
|
|
|
35
35
|
.np-tooltip {
|
|
36
36
|
z-index: @zindex-tooltip;
|
|
37
|
+
visibility: hidden;
|
|
38
|
+
|
|
39
|
+
.tooltip-inner {
|
|
40
|
+
visibility: hidden;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&--open {
|
|
44
|
+
visibility: initial;
|
|
45
|
+
|
|
46
|
+
.tooltip-inner {
|
|
47
|
+
visibility: initial;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
.np-panel[data-popper-placement^="right"] > .np-panel__content.tooltip-inner {
|
|
@@ -1,48 +1,116 @@
|
|
|
1
|
-
import { render, screen
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import React from 'react';
|
|
2
4
|
|
|
3
5
|
import Tooltip from '.';
|
|
4
6
|
|
|
5
|
-
describe('Tooltip', () => {
|
|
6
|
-
|
|
7
|
+
describe('Tooltip Component', () => {
|
|
8
|
+
it('renders an empty list when no items are passed', () => {
|
|
9
|
+
expect(
|
|
10
|
+
render(
|
|
11
|
+
<Tooltip label="Test Tooltip">
|
|
12
|
+
<span>Hover me</span>
|
|
13
|
+
</Tooltip>,
|
|
14
|
+
).container,
|
|
15
|
+
).toMatchSnapshot();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('initially is hidden (test with toBeInTheDocument)', () => {
|
|
19
|
+
render(
|
|
20
|
+
<Tooltip label="Test Tooltip">
|
|
21
|
+
<span>Hover me</span>
|
|
22
|
+
</Tooltip>,
|
|
23
|
+
);
|
|
24
|
+
const tooltip = screen.getByRole('tooltip', { hidden: true });
|
|
25
|
+
expect(tooltip).toBeInTheDocument();
|
|
26
|
+
expect(tooltip).toHaveAttribute('aria-hidden', 'true');
|
|
27
|
+
});
|
|
7
28
|
|
|
8
|
-
it('
|
|
9
|
-
render(
|
|
29
|
+
it('should render the tooltip label when closed', () => {
|
|
30
|
+
render(
|
|
31
|
+
<Tooltip label="Test Tooltip">
|
|
32
|
+
<span>Hover me</span>
|
|
33
|
+
</Tooltip>,
|
|
34
|
+
);
|
|
35
|
+
const triggerElement = screen.getByText('Hover me');
|
|
36
|
+
const tooltip = screen.getByRole('tooltip', { hidden: true });
|
|
37
|
+
expect(tooltip).toHaveAttribute('aria-hidden', 'true');
|
|
10
38
|
|
|
11
|
-
|
|
39
|
+
userEvent.hover(triggerElement);
|
|
40
|
+
expect(tooltip).toHaveAttribute('aria-hidden', 'false');
|
|
12
41
|
});
|
|
13
42
|
|
|
14
|
-
it('
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
43
|
+
it('should display the tooltip on mouse hover', () => {
|
|
44
|
+
render(
|
|
45
|
+
<Tooltip label="Test Tooltip">
|
|
46
|
+
<span>Hover over me!</span>
|
|
47
|
+
</Tooltip>,
|
|
48
|
+
);
|
|
49
|
+
const triggerElement = screen.getByText('Hover over me!');
|
|
18
50
|
|
|
19
|
-
userEvent.hover(
|
|
20
|
-
|
|
51
|
+
userEvent.hover(triggerElement);
|
|
52
|
+
|
|
53
|
+
const tooltipElement = screen.queryByText('Test Tooltip');
|
|
54
|
+
expect(tooltipElement).toBeVisible();
|
|
21
55
|
});
|
|
22
56
|
|
|
23
|
-
it('
|
|
24
|
-
|
|
25
|
-
|
|
57
|
+
it('should hide the tooltip on mouse out', () => {
|
|
58
|
+
render(
|
|
59
|
+
<Tooltip label="Test Tooltip">
|
|
60
|
+
<span>Hover me</span>
|
|
61
|
+
</Tooltip>,
|
|
62
|
+
);
|
|
63
|
+
const triggerElement = screen.getByText('Hover me');
|
|
64
|
+
|
|
65
|
+
userEvent.hover(triggerElement);
|
|
66
|
+
let tooltipElement = screen.getByText('Test Tooltip');
|
|
67
|
+
expect(tooltipElement).toBeVisible();
|
|
26
68
|
|
|
27
|
-
userEvent.
|
|
28
|
-
|
|
29
|
-
|
|
69
|
+
userEvent.unhover(triggerElement);
|
|
70
|
+
tooltipElement = screen.getByRole('tooltip', { hidden: true });
|
|
71
|
+
expect(tooltipElement).toHaveAttribute('aria-hidden', 'true');
|
|
30
72
|
});
|
|
31
73
|
|
|
32
|
-
it('
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
74
|
+
it('should display the tooltip on focus', () => {
|
|
75
|
+
render(
|
|
76
|
+
<Tooltip label="Test Tooltip">
|
|
77
|
+
<span>Focus me</span>
|
|
78
|
+
</Tooltip>,
|
|
79
|
+
);
|
|
80
|
+
const triggerElement = screen.getByText('Focus me');
|
|
81
|
+
|
|
82
|
+
userEvent.tab();
|
|
83
|
+
const tooltipElement = screen.getByText('Test Tooltip');
|
|
84
|
+
expect(tooltipElement).toBeVisible();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should hide the tooltip on blur', () => {
|
|
88
|
+
render(
|
|
89
|
+
<Tooltip label="Test Tooltip">
|
|
90
|
+
<span>Focus me</span>
|
|
91
|
+
</Tooltip>,
|
|
92
|
+
);
|
|
93
|
+
const triggerElement = screen.getByText('Focus me');
|
|
94
|
+
|
|
95
|
+
userEvent.tab();
|
|
96
|
+
let tooltipElement = screen.getByRole('tooltip', { hidden: true });
|
|
97
|
+
expect(tooltipElement).toBeVisible();
|
|
36
98
|
|
|
37
|
-
|
|
38
|
-
|
|
99
|
+
userEvent.tab({ shift: true }); // Blur the element
|
|
100
|
+
tooltipElement = screen.getByRole('tooltip', { hidden: true });
|
|
101
|
+
expect(tooltipElement).toHaveAttribute('aria-hidden', 'true');
|
|
39
102
|
});
|
|
40
103
|
|
|
41
|
-
it('
|
|
42
|
-
|
|
43
|
-
|
|
104
|
+
it('should display the tooltip when the "children" prop is a React element', () => {
|
|
105
|
+
render(
|
|
106
|
+
<Tooltip label="Test Tooltip">
|
|
107
|
+
<button type="button">Click me</button>
|
|
108
|
+
</Tooltip>,
|
|
109
|
+
);
|
|
110
|
+
const triggerElement = screen.getByText('Click me');
|
|
44
111
|
|
|
45
|
-
|
|
46
|
-
|
|
112
|
+
userEvent.hover(triggerElement);
|
|
113
|
+
const tooltipElement = screen.getByRole('tooltip', { hidden: true });
|
|
114
|
+
expect(tooltipElement).toBeVisible();
|
|
47
115
|
});
|
|
48
116
|
});
|
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
import { useId } from '@radix-ui/react-id';
|
|
2
3
|
import classNames from 'classnames';
|
|
3
4
|
import {
|
|
4
5
|
cloneElement,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
type Props = PropsWithChildren<{
|
|
23
24
|
position?: PositionTop | PositionRight | PositionBottom | PositionLeft;
|
|
24
25
|
label: ReactNode;
|
|
26
|
+
id?: string;
|
|
25
27
|
}> &
|
|
26
28
|
CommonProps;
|
|
27
29
|
|
|
@@ -29,6 +31,7 @@ const Tooltip = ({
|
|
|
29
31
|
position = Position.TOP,
|
|
30
32
|
children = undefined,
|
|
31
33
|
label,
|
|
34
|
+
id,
|
|
32
35
|
className,
|
|
33
36
|
}: Props): ReactElement => {
|
|
34
37
|
const [open, setOpen] = useState(false);
|
|
@@ -36,6 +39,8 @@ const Tooltip = ({
|
|
|
36
39
|
const [arrowElement, setArrowElement] = useState(null);
|
|
37
40
|
const [popperElement, setPopperElement] = useState(null);
|
|
38
41
|
|
|
42
|
+
const fallbackId = useId();
|
|
43
|
+
const tooltipId = id ?? fallbackId;
|
|
39
44
|
const modifiers = [];
|
|
40
45
|
|
|
41
46
|
modifiers.push({
|
|
@@ -71,46 +76,34 @@ const Tooltip = ({
|
|
|
71
76
|
|
|
72
77
|
return (
|
|
73
78
|
<>
|
|
74
|
-
<span
|
|
79
|
+
<span
|
|
80
|
+
ref={anchorReference}
|
|
81
|
+
className="tw-tooltip-container"
|
|
82
|
+
onMouseOver={() => setOpen(true)}
|
|
83
|
+
onFocus={() => setOpen(true)}
|
|
84
|
+
onMouseOut={() => setOpen(false)}
|
|
85
|
+
onBlur={() => setOpen(false)}
|
|
86
|
+
>
|
|
75
87
|
{children
|
|
76
88
|
? cloneElement(children as ReactElement, {
|
|
77
|
-
|
|
78
|
-
onMouseOver: () => {
|
|
79
|
-
if ((children as ReactElement)?.props?.onMouseOver) {
|
|
80
|
-
(children as ReactElement)?.props?.onMouseOver();
|
|
81
|
-
}
|
|
82
|
-
setOpen(true);
|
|
83
|
-
},
|
|
84
|
-
onFocus: () => {
|
|
85
|
-
if ((children as ReactElement)?.props?.onFocus) {
|
|
86
|
-
(children as ReactElement).props.onFocus();
|
|
87
|
-
}
|
|
88
|
-
setOpen(true);
|
|
89
|
-
},
|
|
90
|
-
onMouseOut: () => {
|
|
91
|
-
if ((children as ReactElement)?.props?.onMouseOver) {
|
|
92
|
-
(children as ReactElement).props.onMouseOver();
|
|
93
|
-
}
|
|
94
|
-
setOpen(false);
|
|
95
|
-
},
|
|
96
|
-
onBlur: () => {
|
|
97
|
-
if ((children as ReactElement)?.props?.onBlur) {
|
|
98
|
-
(children as ReactElement).props.onBlur();
|
|
99
|
-
}
|
|
100
|
-
setOpen(false);
|
|
101
|
-
},
|
|
102
|
-
/* eslint-enable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call */
|
|
89
|
+
'aria-describedby': `${tooltipId}-tooltip`,
|
|
103
90
|
})
|
|
104
91
|
: null}
|
|
105
|
-
</span>
|
|
106
|
-
{open ? (
|
|
107
92
|
<div
|
|
108
93
|
// @ts-expect-error
|
|
109
94
|
ref={setPopperElement}
|
|
110
|
-
className={classNames(
|
|
95
|
+
className={classNames(
|
|
96
|
+
'np-tooltip',
|
|
97
|
+
'np-panel',
|
|
98
|
+
open ? `np-panel--open np-tooltip--open` : null,
|
|
99
|
+
className,
|
|
100
|
+
)}
|
|
111
101
|
// eslint-disable-next-line react/forbid-dom-props
|
|
112
102
|
style={{ ...styles.popper }}
|
|
113
103
|
{...attributes.popper}
|
|
104
|
+
aria-hidden={!open}
|
|
105
|
+
role="tooltip"
|
|
106
|
+
id={`${tooltipId}-tooltip`}
|
|
114
107
|
>
|
|
115
108
|
<div className="np-panel__content tooltip-inner">
|
|
116
109
|
{label}
|
|
@@ -123,7 +116,7 @@ const Tooltip = ({
|
|
|
123
116
|
/>
|
|
124
117
|
</div>
|
|
125
118
|
</div>
|
|
126
|
-
|
|
119
|
+
</span>
|
|
127
120
|
</>
|
|
128
121
|
);
|
|
129
122
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Tooltip Component renders an empty list when no items are passed 1`] = `
|
|
4
|
+
<div>
|
|
5
|
+
<span
|
|
6
|
+
class="tw-tooltip-container"
|
|
7
|
+
>
|
|
8
|
+
<span
|
|
9
|
+
aria-describedby="radix-0-tooltip"
|
|
10
|
+
>
|
|
11
|
+
Hover me
|
|
12
|
+
</span>
|
|
13
|
+
<div
|
|
14
|
+
aria-hidden="true"
|
|
15
|
+
class="np-tooltip np-panel"
|
|
16
|
+
id="radix-0-tooltip"
|
|
17
|
+
role="tooltip"
|
|
18
|
+
style="position: absolute; left: 0px; top: 0px;"
|
|
19
|
+
>
|
|
20
|
+
<div
|
|
21
|
+
class="np-panel__content tooltip-inner"
|
|
22
|
+
>
|
|
23
|
+
Test Tooltip
|
|
24
|
+
<div
|
|
25
|
+
class="np-panel__arrow"
|
|
26
|
+
/>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
</span>
|
|
30
|
+
</div>
|
|
31
|
+
`;
|
|
@@ -15,6 +15,7 @@ jest.mock('./utils/asyncFileRead');
|
|
|
15
15
|
const { asyncFileRead } = require('./utils/asyncFileRead');
|
|
16
16
|
|
|
17
17
|
const defaultLocale = 'en-GB';
|
|
18
|
+
const formatMessage = (id) => `${id}`;
|
|
18
19
|
jest.mock('react-intl', () => ({
|
|
19
20
|
injectIntl: (Component) =>
|
|
20
21
|
function (props) {
|
|
@@ -22,6 +23,7 @@ jest.mock('react-intl', () => ({
|
|
|
22
23
|
<Component {...props} intl={{ locale: defaultLocale, formatMessage: (id) => `${id}` }} />
|
|
23
24
|
);
|
|
24
25
|
},
|
|
26
|
+
useIntl: () => ({ formatMessage }),
|
|
25
27
|
defineMessages: (translations) => translations,
|
|
26
28
|
}));
|
|
27
29
|
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import Link from '../link';
|
|
2
|
-
|
|
3
|
-
import InstructionsList from './InstructionsList';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
component: InstructionsList,
|
|
7
|
-
title: 'Typography/InstructionsList',
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const Basic = () => {
|
|
11
|
-
return (
|
|
12
|
-
<InstructionsList
|
|
13
|
-
dos={[
|
|
14
|
-
'Do an initial money transfer',
|
|
15
|
-
'Invite at least 3 friends',
|
|
16
|
-
<span key="12">
|
|
17
|
-
Paying extra{' '}
|
|
18
|
-
<Link href="" type="link-large">
|
|
19
|
-
hidden fees
|
|
20
|
-
</Link>{' '}
|
|
21
|
-
for transfers
|
|
22
|
-
</span>,
|
|
23
|
-
]}
|
|
24
|
-
donts={['Paying extra hidden fees for transfers', 'Use bad exchange rate']}
|
|
25
|
-
/>
|
|
26
|
-
);
|
|
27
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { shallow } from 'enzyme';
|
|
2
|
-
|
|
3
|
-
import InstructionsList from '.';
|
|
4
|
-
|
|
5
|
-
describe('InstructionsList', () => {
|
|
6
|
-
it('should render dos list only', () => {
|
|
7
|
-
const dos = ['Test this component', 'With multiple dos'];
|
|
8
|
-
const component = shallow(<InstructionsList dos={dos} />);
|
|
9
|
-
|
|
10
|
-
expect(component.find('.do')).toHaveLength(2);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should render donts list only', () => {
|
|
14
|
-
const donts = ['Putting things into production without testing'];
|
|
15
|
-
|
|
16
|
-
const component = shallow(<InstructionsList donts={donts} />);
|
|
17
|
-
expect(component.find('.dont')).toHaveLength(1);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should render do/dont lists', () => {
|
|
21
|
-
const dos = ['Do this'];
|
|
22
|
-
const donts = [`Don't do that`];
|
|
23
|
-
|
|
24
|
-
const component = shallow(<InstructionsList dos={dos} donts={donts} />);
|
|
25
|
-
expect(component.find('.do')).toHaveLength(1);
|
|
26
|
-
expect(component.find('.dont')).toHaveLength(1);
|
|
27
|
-
expect(component.find('.instruction')).toHaveLength(2);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`SearchBox renders 1`] = `
|
|
4
|
-
<div>
|
|
5
|
-
<li
|
|
6
|
-
class="border-bottom"
|
|
7
|
-
>
|
|
8
|
-
<a
|
|
9
|
-
class="np-select-filter-link p-a-0"
|
|
10
|
-
>
|
|
11
|
-
<div
|
|
12
|
-
class="input-group"
|
|
13
|
-
>
|
|
14
|
-
<span
|
|
15
|
-
class="input-group-addon input-group-addon--search"
|
|
16
|
-
>
|
|
17
|
-
<span
|
|
18
|
-
aria-hidden="true"
|
|
19
|
-
class="tw-icon tw-icon-search tw-icon tw-icon-search"
|
|
20
|
-
data-testid="search-icon"
|
|
21
|
-
role="presentation"
|
|
22
|
-
>
|
|
23
|
-
<svg
|
|
24
|
-
fill="currentColor"
|
|
25
|
-
focusable="false"
|
|
26
|
-
height="24"
|
|
27
|
-
viewBox="0 0 24 24"
|
|
28
|
-
width="24"
|
|
29
|
-
>
|
|
30
|
-
<path
|
|
31
|
-
d="m20.786 19.543-4.029-4.029c1.072-1.328 1.672-3 1.672-4.8C18.429 6.471 14.957 3 10.714 3S3 6.471 3 10.714s3.471 7.715 7.714 7.715c1.8 0 3.472-.643 4.8-1.672l4.029 4.029 1.243-1.243Zm-10.029-2.829c-3.3 0-6-2.7-6-6s2.7-6 6-6 6 2.7 6 6-2.7 6-6 6Z"
|
|
32
|
-
/>
|
|
33
|
-
</svg>
|
|
34
|
-
</span>
|
|
35
|
-
</span>
|
|
36
|
-
<input
|
|
37
|
-
class="np-select-filter form-control np-form-control np-form-control--size-auto np-text-body-large np-input np-input--shape-rectangle"
|
|
38
|
-
placeholder="placeholder"
|
|
39
|
-
spellcheck="false"
|
|
40
|
-
value="value"
|
|
41
|
-
/>
|
|
42
|
-
</div>
|
|
43
|
-
</a>
|
|
44
|
-
</li>
|
|
45
|
-
</div>
|
|
46
|
-
`;
|