@transferwise/components 0.0.0-experimental-dad811d → 0.0.0-experimental-5ea6623

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 (102) hide show
  1. package/build/index.esm.js +268 -506
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +242 -480
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +6 -82
  6. package/build/styles/decision/Decision.css +6 -82
  7. package/build/styles/main.css +6 -82
  8. package/build/types/actionButton/ActionButton.d.ts +1 -1
  9. package/build/types/body/Body.d.ts +1 -1
  10. package/build/types/card/Card.d.ts +0 -1
  11. package/build/types/card/Card.d.ts.map +1 -1
  12. package/build/types/common/Option/Option.d.ts +0 -1
  13. package/build/types/common/Option/Option.d.ts.map +1 -1
  14. package/build/types/common/RadioButton/RadioButton.d.ts +10 -34
  15. package/build/types/common/RadioButton/RadioButton.d.ts.map +1 -1
  16. package/build/types/common/RadioButton/index.d.ts +1 -1
  17. package/build/types/common/RadioButton/index.d.ts.map +1 -1
  18. package/build/types/common/commonProps.d.ts +1 -1
  19. package/build/types/common/commonProps.d.ts.map +1 -1
  20. package/build/types/common/panel/Panel.d.ts +1 -1
  21. package/build/types/common/responsivePanel/ResponsivePanel.d.ts +1 -1
  22. package/build/types/dateInput/index.d.ts +2 -2
  23. package/build/types/dateInput/index.d.ts.map +1 -1
  24. package/build/types/dateLookup/DateLookup.d.ts +1 -0
  25. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  26. package/build/types/decision/Decision.d.ts +39 -52
  27. package/build/types/decision/Decision.d.ts.map +1 -1
  28. package/build/types/decision/index.d.ts +1 -2
  29. package/build/types/decision/index.d.ts.map +1 -1
  30. package/build/types/dimmer/Dimmer.d.ts +1 -1
  31. package/build/types/index.d.ts +5 -0
  32. package/build/types/index.d.ts.map +1 -1
  33. package/build/types/promoCard/PromoCard.d.ts +1 -2
  34. package/build/types/promoCard/PromoCard.d.ts.map +1 -1
  35. package/build/types/radio/Radio.d.ts +10 -21
  36. package/build/types/radio/Radio.d.ts.map +1 -1
  37. package/build/types/radio/index.d.ts +2 -2
  38. package/build/types/radio/index.d.ts.map +1 -1
  39. package/build/types/radioGroup/RadioGroup.d.ts +10 -26
  40. package/build/types/radioGroup/RadioGroup.d.ts.map +1 -1
  41. package/build/types/radioGroup/index.d.ts +2 -1
  42. package/build/types/radioGroup/index.d.ts.map +1 -1
  43. package/build/types/radioOption/RadioOption.d.ts +15 -23
  44. package/build/types/radioOption/RadioOption.d.ts.map +1 -1
  45. package/build/types/radioOption/index.d.ts +2 -1
  46. package/build/types/radioOption/index.d.ts.map +1 -1
  47. package/build/types/select/searchBox/SearchBox.d.ts +1 -1
  48. package/package.json +1 -1
  49. package/src/card/Card.js +0 -3
  50. package/src/card/Card.story.js +2 -17
  51. package/src/common/Option/Option.spec.js +0 -7
  52. package/src/common/Option/Option.tsx +1 -9
  53. package/src/common/RadioButton/RadioButton.tsx +43 -0
  54. package/src/common/commonProps.ts +1 -1
  55. package/src/dateInput/index.ts +2 -3
  56. package/src/dateLookup/DateLookup.js +12 -1
  57. package/src/dateLookup/DateLookup.testingLibrary.spec.js +12 -1
  58. package/src/decision/Decision.css +6 -82
  59. package/src/decision/Decision.less +3 -41
  60. package/src/decision/Decision.spec.js +56 -61
  61. package/src/decision/{Decision.story.js → Decision.story.tsx} +5 -5
  62. package/src/decision/Decision.tsx +133 -0
  63. package/src/decision/index.ts +1 -0
  64. package/src/index.ts +5 -0
  65. package/src/main.css +6 -82
  66. package/src/promoCard/PromoCard.tsx +1 -2
  67. package/src/radio/{Radio.story.js → Radio.story.tsx} +0 -3
  68. package/src/radio/{Radio.js → Radio.tsx} +18 -28
  69. package/src/radio/index.ts +2 -0
  70. package/src/radioGroup/RadioGroup.spec.js +24 -26
  71. package/src/radioGroup/{RadioGroup.story.js → RadioGroup.story.tsx} +0 -3
  72. package/src/radioGroup/RadioGroup.tsx +43 -0
  73. package/src/radioGroup/index.ts +2 -0
  74. package/src/radioOption/RadioOption.spec.js +4 -4
  75. package/src/radioOption/{RadioOption.story.js → RadioOption.story.tsx} +4 -4
  76. package/src/radioOption/RadioOption.tsx +60 -0
  77. package/src/radioOption/index.ts +2 -0
  78. package/src/tile/Tile.js +1 -1
  79. package/build/types/decision/decisionEnums.d.ts +0 -9
  80. package/build/types/decision/decisionEnums.d.ts.map +0 -1
  81. package/build/types/sizeSwapper/SizeSwapper.d.ts +0 -3
  82. package/build/types/sizeSwapper/SizeSwapper.d.ts.map +0 -1
  83. package/build/types/sizeSwapper/index.d.ts +0 -2
  84. package/build/types/sizeSwapper/index.d.ts.map +0 -1
  85. package/src/common/RadioButton/RadioButton.js +0 -41
  86. package/src/decision/Decision.js +0 -148
  87. package/src/decision/decisionEnums.ts +0 -11
  88. package/src/decision/index.js +0 -2
  89. package/src/radio/index.js +0 -3
  90. package/src/radioGroup/RadioGroup.js +0 -66
  91. package/src/radioGroup/index.js +0 -1
  92. package/src/radioOption/RadioOption.js +0 -81
  93. package/src/radioOption/index.js +0 -1
  94. package/src/sizeSwapper/SizeSwapper.js +0 -69
  95. package/src/sizeSwapper/SizeSwapper.spec.js +0 -100
  96. package/src/sizeSwapper/SizeSwapper.story.js +0 -34
  97. package/src/sizeSwapper/index.js +0 -1
  98. /package/src/common/RadioButton/{RadioButton.spec.js → RadioButton.spec.tsx} +0 -0
  99. /package/src/common/RadioButton/__snapshots__/{RadioButton.spec.js.snap → RadioButton.spec.tsx.snap} +0 -0
  100. /package/src/common/RadioButton/{index.js → index.ts} +0 -0
  101. /package/src/radio/{Radio.rtl.spec.js → Radio.rtl.spec.tsx} +0 -0
  102. /package/src/radio/__snapshots__/{Radio.rtl.spec.js.snap → Radio.rtl.spec.tsx.snap} +0 -0
@@ -1,69 +0,0 @@
1
- import classNames from 'classnames';
2
- import PropTypes from 'prop-types';
3
- import { forwardRef, useRef } from 'react';
4
-
5
- import { Breakpoint } from '../common';
6
- import { useClientWidth } from '../common/hooks';
7
-
8
- const Layout = { COLUMN: 'COLUMN' };
9
-
10
- const SizeSwapper = forwardRef(({ items, inline }, reference) => {
11
- const parentReference = useRef(null);
12
- const [clientWidth] = useClientWidth({ ref: reference || parentReference });
13
-
14
- if (!items || items.length === 0) {
15
- return null;
16
- }
17
- // If all breakpoints are specified and clientWidth never > breakpoint itemsToRender can be undefined.
18
- // Do not use deconstruct here to get items and layout.
19
- let itemsToRender = [];
20
-
21
- if (clientWidth) {
22
- itemsToRender = items.filter(({ breakpoint = 0 }) => clientWidth >= breakpoint).pop();
23
- } else {
24
- // On SSR environments useClientWidth returns null because ref is undefined so we render
25
- // all elements by default.
26
- // If there's no SSR and on first Hydration only the right elements are going to be rendered.
27
- // If clientWidth is null or zero all elements render like a responsive technique would do.
28
- itemsToRender.items = items.map(({ items }) => Object.values(items));
29
- }
30
-
31
- // Always return parent container even if there are no items to display to
32
- // keep the ref on DOM and let clientWidth be calculated properly.
33
- return (
34
- <div
35
- ref={parentReference}
36
- className={classNames('np-size-swapper', {
37
- 'd-flex': !inline,
38
- 'd-inline-flex': inline,
39
- 'flex-column': itemsToRender && itemsToRender.layout === Layout.COLUMN,
40
- 'flex-wrap': itemsToRender && itemsToRender.wrap,
41
- })}
42
- style={{ visibility: clientWidth ? 'visible' : 'hidden' }}
43
- >
44
- {itemsToRender && itemsToRender.items}
45
- </div>
46
- );
47
- });
48
-
49
- SizeSwapper.Breakpoint = Breakpoint;
50
- SizeSwapper.Layout = Layout;
51
-
52
- SizeSwapper.propTypes = {
53
- inline: PropTypes.bool,
54
- /** List of items that will appear at the specified breakpoint and presented in row or columns depending on layout */
55
- items: PropTypes.arrayOf(
56
- PropTypes.shape({
57
- items: PropTypes.arrayOf(PropTypes.element),
58
- breakpoint: PropTypes.number,
59
- layout: PropTypes.oneOf([SizeSwapper.Layout.COLUMN]),
60
- wrap: PropTypes.bool,
61
- }),
62
- ).isRequired,
63
- };
64
-
65
- SizeSwapper.defaultProps = {
66
- inline: false,
67
- };
68
-
69
- export default SizeSwapper;
@@ -1,100 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- import { Breakpoint } from '../common';
3
- import { render, fireEvent, screen } from '../test-utils';
4
-
5
- import SizeSwapper from '.';
6
-
7
- jest.mock('lodash.throttle', () => jest.fn((fn) => fn));
8
-
9
- describe('SizeSwapper', () => {
10
- const resetClientWidth = (width) => {
11
- Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
12
- configurable: true,
13
- value: width,
14
- });
15
- };
16
- const breakpoints = [0, Breakpoint.EXTRA_SMALL];
17
-
18
- const items = breakpoints.map((bp) => ({
19
- items: [...new Array(2)].map((_, index) => (
20
- // eslint-disable-next-line react/no-array-index-key
21
- <div key={`${index}-${bp}`}>
22
- element-{index + 1}-{bp}
23
- </div>
24
- )),
25
- layout: SizeSwapper.Layout.COLUMN,
26
- breakpoint: bp,
27
- }));
28
-
29
- afterAll(() => {
30
- const originalClientWidth = Object.getOwnPropertyDescriptor(
31
- HTMLElement.prototype,
32
- 'clientWidth',
33
- );
34
-
35
- Object.defineProperty(HTMLElement.prototype, 'clientWidth', originalClientWidth);
36
- });
37
-
38
- it('renders all elements and hides sizeswapper if clientWidth is not defined', () => {
39
- const { container } = render(<SizeSwapper items={items} />);
40
-
41
- expect(screen.getByText('element-1-0')).toBeInTheDocument();
42
- expect(screen.getByText('element-2-0')).toBeInTheDocument();
43
- expect(screen.getByText(`element-1-${breakpoints[1]}`)).toBeInTheDocument();
44
- expect(screen.getByText(`element-2-${breakpoints[1]}`)).toBeInTheDocument();
45
-
46
- expect(container.querySelector('.np-size-swapper')).toHaveStyle(`visibility: hidden`);
47
- });
48
-
49
- it('changes visibility when clientWidth is set', () => {
50
- const { container } = render(<SizeSwapper items={items} />);
51
-
52
- expect(container.querySelector('.np-size-swapper')).toHaveStyle(`visibility: hidden`);
53
-
54
- resetClientWidth(breakpoints[1]);
55
- fireEvent(window, new Event('resize'));
56
-
57
- expect(container.querySelector('.np-size-swapper')).toHaveStyle(`visibility: visible`);
58
- });
59
-
60
- it('switches elements according to breakpoints', () => {
61
- render(<SizeSwapper items={items} />);
62
- resetClientWidth(breakpoints[1] - 1);
63
- fireEvent(window, new Event('resize'));
64
-
65
- expect(screen.getByText(`element-1-0`)).toBeInTheDocument();
66
- expect(screen.getByText(`element-2-0`)).toBeInTheDocument();
67
- expect(screen.queryByText(`element-1-${breakpoints[1]}`)).not.toBeInTheDocument();
68
- expect(screen.queryByText(`element-2-${breakpoints[1]}`)).not.toBeInTheDocument();
69
-
70
- // resetClientWidth(breakpoints[1]);
71
- // fireEvent(window, new Event('resize'));
72
-
73
- // expect(screen.queryByText(`element-1-${breakpoints[0]}`)).not.toBeInTheDocument();
74
- // expect(screen.queryByText(`element-2-${breakpoints[0]}`)).not.toBeInTheDocument();
75
- // expect(screen.getByText(`element-1-${breakpoints[1]}`)).toBeInTheDocument();
76
- // expect(screen.getByText(`element-2-${breakpoints[1]}`)).toBeInTheDocument();
77
- });
78
-
79
- describe('when ref is window', () => {
80
- it('switches elements according to breakpoints', () => {
81
- render(<SizeSwapper ref={window} items={items} />);
82
- global.innerWidth = breakpoints[1] - 1;
83
- fireEvent(window, new Event('resize'));
84
-
85
- expect(screen.getByText(`element-1-0`)).toBeInTheDocument();
86
- expect(screen.getByText(`element-2-0`)).toBeInTheDocument();
87
- expect(screen.queryByText(`element-1-${breakpoints[1]}`)).not.toBeInTheDocument();
88
- expect(screen.queryByText(`element-2-${breakpoints[1]}`)).not.toBeInTheDocument();
89
-
90
- [, global.innerWidth] = breakpoints;
91
-
92
- fireEvent(window, new Event('resize'));
93
-
94
- expect(screen.queryByText(`element-1-${breakpoints[0]}`)).not.toBeInTheDocument();
95
- expect(screen.queryByText(`element-2-${breakpoints[0]}`)).not.toBeInTheDocument();
96
- expect(screen.getByText(`element-1-${breakpoints[1]}`)).toBeInTheDocument();
97
- expect(screen.getByText(`element-2-${breakpoints[1]}`)).toBeInTheDocument();
98
- });
99
- });
100
- });
@@ -1,34 +0,0 @@
1
- import SizeSwapper from './SizeSwapper';
2
-
3
- export default {
4
- component: SizeSwapper,
5
- title: 'Internal/SizeSwapper',
6
- };
7
-
8
- export const Basic = () => {
9
- const breakpoints = [
10
- 0,
11
- SizeSwapper.Breakpoint.EXTRA_SMALL,
12
- SizeSwapper.Breakpoint.SMALL,
13
- SizeSwapper.Breakpoint.MEDIUM,
14
- SizeSwapper.Breakpoint.LARGE,
15
- SizeSwapper.Breakpoint.EXTRA_LARGE,
16
- ];
17
-
18
- const items = breakpoints.map((bp, key) => {
19
- const isColumn = (key + 1) % 2 === 0;
20
-
21
- return {
22
- items: [...new Array(4)].map((value, key2) => (
23
- // eslint-disable-next-line react/no-array-index-key
24
- <div key={`el-${key2}-${key}`} className="p-a-3 well m-x-2">
25
- Element shown from {bp}px {isColumn && `in ${SizeSwapper.Layout.COLUMN} mode`}
26
- </div>
27
- )),
28
- layout: isColumn ? SizeSwapper.Layout.COLUMN : null,
29
- breakpoint: bp,
30
- };
31
- });
32
-
33
- return <SizeSwapper items={items} />;
34
- };
@@ -1 +0,0 @@
1
- export { default } from './SizeSwapper';
File without changes