@transferwise/components 46.12.0 → 46.14.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.
Files changed (136) hide show
  1. package/build/index.esm.js +193 -352
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +166 -325
  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/body/Body.d.ts +1 -1
  9. package/build/types/common/commonProps.d.ts +1 -1
  10. package/build/types/common/commonProps.d.ts.map +1 -1
  11. package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts +1 -1
  12. package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts.map +1 -1
  13. package/build/types/common/dateUtils/getDayNames/index.d.ts +1 -1
  14. package/build/types/common/dateUtils/getDayNames/index.d.ts.map +1 -1
  15. package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts +1 -1
  16. package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts.map +1 -1
  17. package/build/types/common/dateUtils/getMonthNames/index.d.ts +1 -1
  18. package/build/types/common/dateUtils/getMonthNames/index.d.ts.map +1 -1
  19. package/build/types/common/dateUtils/index.d.ts +6 -6
  20. package/build/types/common/dateUtils/index.d.ts.map +1 -1
  21. package/build/types/common/dateUtils/isDateValid/index.d.ts +1 -1
  22. package/build/types/common/dateUtils/isDateValid/index.d.ts.map +1 -1
  23. package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts +2 -2
  24. package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts.map +1 -1
  25. package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts +1 -1
  26. package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts.map +1 -1
  27. package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts +1 -1
  28. package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts.map +1 -1
  29. package/build/types/common/dateUtils/isWithinRange/index.d.ts +1 -1
  30. package/build/types/common/dateUtils/isWithinRange/index.d.ts.map +1 -1
  31. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts +1 -1
  32. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts.map +1 -1
  33. package/build/types/common/dateUtils/moveToWithinRange/index.d.ts +1 -1
  34. package/build/types/common/dateUtils/moveToWithinRange/index.d.ts.map +1 -1
  35. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts +1 -1
  36. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts.map +1 -1
  37. package/build/types/common/panel/Panel.d.ts +1 -1
  38. package/build/types/common/responsivePanel/ResponsivePanel.d.ts +1 -1
  39. package/build/types/dateInput/DateInput.d.ts +30 -41
  40. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  41. package/build/types/dateInput/DateInput.messages.d.ts +24 -33
  42. package/build/types/dateInput/DateInput.messages.d.ts.map +1 -1
  43. package/build/types/dateInput/index.d.ts +2 -2
  44. package/build/types/dateInput/index.d.ts.map +1 -1
  45. package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts +1 -1
  46. package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts.map +1 -1
  47. package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts +1 -1
  48. package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts.map +1 -1
  49. package/build/types/dateInput/utils/index.d.ts +1 -2
  50. package/build/types/dateInput/utils/index.d.ts.map +1 -1
  51. package/build/types/dateLookup/DateLookup.d.ts +1 -0
  52. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  53. package/build/types/decision/Decision.d.ts +39 -52
  54. package/build/types/decision/Decision.d.ts.map +1 -1
  55. package/build/types/decision/index.d.ts +1 -2
  56. package/build/types/decision/index.d.ts.map +1 -1
  57. package/build/types/dimmer/Dimmer.d.ts +1 -1
  58. package/build/types/drawer/Drawer.d.ts.map +1 -1
  59. package/build/types/index.d.ts +2 -0
  60. package/build/types/index.d.ts.map +1 -1
  61. package/build/types/modal/Modal.d.ts.map +1 -1
  62. package/build/types/popover/Popover.d.ts +1 -0
  63. package/build/types/popover/Popover.d.ts.map +1 -1
  64. package/build/types/promoCard/PromoCard.d.ts +1 -2
  65. package/build/types/promoCard/PromoCard.d.ts.map +1 -1
  66. package/build/types/select/searchBox/SearchBox.d.ts +1 -1
  67. package/package.json +1 -1
  68. package/src/common/commonProps.ts +1 -1
  69. package/src/common/dateUtils/getDayNames/getDayNames.spec.js +2 -2
  70. package/src/common/dateUtils/getDayNames/{getDayNames.js → getDayNames.ts} +5 -2
  71. package/src/common/dateUtils/getMonthNames/getMonthNames.spec.js +9 -8
  72. package/src/common/dateUtils/getMonthNames/{getMonthNames.js → getMonthNames.ts} +5 -3
  73. package/src/common/dateUtils/isDateValid/{isDateValid.spec.js → isDateValid.spec.ts} +1 -1
  74. package/src/common/dateUtils/isDateValid/isDateValid.ts +13 -0
  75. package/src/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.spec.js +3 -7
  76. package/src/common/dateUtils/isMonthAndYearFormat/{isMonthAndYearFormat.js → isMonthAndYearFormat.ts} +1 -1
  77. package/src/common/dateUtils/isWithinRange/{isWithinRange.spec.js → isWithinRange.spec.ts} +0 -10
  78. package/src/common/dateUtils/isWithinRange/{isWithinRange.js → isWithinRange.ts} +1 -1
  79. package/src/common/dateUtils/moveToWithinRange/{moveToWithinRange.js → moveToWithinRange.ts} +2 -2
  80. package/src/dateInput/DateInput.spec.js +7 -56
  81. package/src/dateInput/DateInput.story.tsx +11 -8
  82. package/src/dateInput/{DateInput.js → DateInput.tsx} +116 -123
  83. package/src/dateInput/index.ts +2 -0
  84. package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.js → convertToLocalMidnight.ts} +1 -1
  85. package/src/dateInput/utils/{index.js → index.ts} +0 -1
  86. package/src/dateLookup/DateLookup.js +12 -1
  87. package/src/dateLookup/DateLookup.testingLibrary.spec.js +12 -1
  88. package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -0
  89. package/src/decision/Decision.css +6 -82
  90. package/src/decision/Decision.less +3 -41
  91. package/src/decision/Decision.spec.js +56 -61
  92. package/src/decision/{Decision.story.js → Decision.story.tsx} +5 -5
  93. package/src/decision/Decision.tsx +133 -0
  94. package/src/decision/index.ts +1 -0
  95. package/src/drawer/Drawer.js +13 -2
  96. package/src/drawer/__snapshots__/Drawer.rtl.spec.js.snap +1 -0
  97. package/src/index.ts +2 -0
  98. package/src/main.css +6 -82
  99. package/src/modal/Modal.tsx +6 -3
  100. package/src/popover/Popover.js +7 -3
  101. package/src/popover/Popover.spec.js +16 -8
  102. package/src/popover/__snapshots__/Popover.spec.js.snap +0 -56
  103. package/src/promoCard/PromoCard.tsx +1 -2
  104. package/src/tile/Tile.js +1 -1
  105. package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts +0 -6
  106. package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts.map +0 -1
  107. package/build/types/dateInput/utils/explodeDate/index.d.ts +0 -2
  108. package/build/types/dateInput/utils/explodeDate/index.d.ts.map +0 -1
  109. package/build/types/decision/decisionEnums.d.ts +0 -9
  110. package/build/types/decision/decisionEnums.d.ts.map +0 -1
  111. package/build/types/sizeSwapper/SizeSwapper.d.ts +0 -3
  112. package/build/types/sizeSwapper/SizeSwapper.d.ts.map +0 -1
  113. package/build/types/sizeSwapper/index.d.ts +0 -2
  114. package/build/types/sizeSwapper/index.d.ts.map +0 -1
  115. package/src/common/dateUtils/isDateValid/isDateValid.js +0 -6
  116. package/src/dateInput/index.js +0 -3
  117. package/src/dateInput/utils/explodeDate/explodeDate.js +0 -7
  118. package/src/dateInput/utils/explodeDate/explodeDate.spec.js +0 -11
  119. package/src/dateInput/utils/explodeDate/index.js +0 -1
  120. package/src/decision/Decision.js +0 -148
  121. package/src/decision/decisionEnums.ts +0 -11
  122. package/src/decision/index.js +0 -2
  123. package/src/sizeSwapper/SizeSwapper.js +0 -69
  124. package/src/sizeSwapper/SizeSwapper.spec.js +0 -100
  125. package/src/sizeSwapper/SizeSwapper.story.js +0 -34
  126. package/src/sizeSwapper/index.js +0 -1
  127. /package/src/common/dateUtils/getDayNames/{index.js → index.ts} +0 -0
  128. /package/src/common/dateUtils/getMonthNames/{index.js → index.ts} +0 -0
  129. /package/src/common/dateUtils/{index.js → index.ts} +0 -0
  130. /package/src/common/dateUtils/isDateValid/{index.js → index.ts} +0 -0
  131. /package/src/common/dateUtils/isMonthAndYearFormat/{index.js → index.ts} +0 -0
  132. /package/src/common/dateUtils/isWithinRange/{index.js → index.ts} +0 -0
  133. /package/src/common/dateUtils/moveToWithinRange/{index.js → index.ts} +0 -0
  134. /package/src/dateInput/{DateInput.messages.js → DateInput.messages.ts} +0 -0
  135. /package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.spec.js → convertToLocalMidnight.spec.ts} +0 -0
  136. /package/src/dateInput/utils/convertToLocalMidnight/{index.js → index.ts} +0 -0
@@ -3,16 +3,16 @@ import '@testing-library/jest-dom';
3
3
 
4
4
  import Avatar from '../avatar';
5
5
  import { Breakpoint, Size } from '../common';
6
- import { render, fireEvent } from '../test-utils';
6
+ import { mockMatchMedia } from '../mocks';
7
+ import { render, fireEvent, screen } from '../test-utils';
7
8
 
8
- import { Presentation, Type } from './decisionEnums';
9
-
10
- import Decision from '.';
9
+ import Decision, { DecisionPresentation, DecisionType } from '.';
11
10
 
12
11
  jest.mock('lodash.throttle', () => jest.fn((fn) => fn));
12
+ mockMatchMedia(jest);
13
13
 
14
14
  describe('Decision', () => {
15
- const props = {
15
+ const commonProps = {
16
16
  options: [
17
17
  {
18
18
  media: {
@@ -25,112 +25,107 @@ describe('Decision', () => {
25
25
  onClick: jest.fn(),
26
26
  },
27
27
  ],
28
- presentation: Presentation.LIST_BLOCK,
29
- type: Type.NAVIGATION,
28
+ presentation: DecisionPresentation.LIST_BLOCK,
29
+ type: DecisionType.NAVIGATION,
30
30
  };
31
31
 
32
+ const initialInnerWidth = window.innerWidth;
32
33
  const resetClientWidth = (width) => {
33
- Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
34
- configurable: true,
35
- value: width,
36
- });
34
+ window.innerWidth = width;
37
35
  };
38
36
 
39
37
  afterAll(() => {
40
- const originalClientWidth = Object.getOwnPropertyDescriptor(
41
- HTMLElement.prototype,
42
- 'clientWidth',
43
- );
44
-
45
- Object.defineProperty(HTMLElement.prototype, 'clientWidth', originalClientWidth);
38
+ window.innerWidth = initialInnerWidth;
46
39
  });
47
40
 
48
- let container;
49
41
  beforeEach(() => {
50
42
  resetClientWidth(Breakpoint.EXTRA_SMALL - 1);
51
43
  });
52
44
 
53
- describe(`when presentation is ${Presentation.LIST_BLOCK}`, () => {
54
- beforeEach(() => {
55
- ({ container } = render(<Decision {...props} />));
56
- });
45
+ describe(`when presentation is ${DecisionPresentation.LIST_BLOCK}`, () => {
46
+ const props = { ...commonProps };
57
47
 
58
48
  it('renders only Navigation Option before first breakpoint', () => {
59
- expect(getNavigationOption()).toBeInTheDocument();
60
- expect(getTile()).not.toBeInTheDocument();
49
+ const { container } = render(<Decision {...props} />);
50
+
51
+ expect(getNavigationOption(container)).toBeInTheDocument();
52
+ expect(getTile(container)).not.toBeInTheDocument();
61
53
  });
62
54
 
63
55
  it('renders only Tile after first breakpoint', () => {
64
56
  resetClientWidth(Breakpoint.SMALL);
65
- fireEvent(window, new Event('resize'));
57
+ const { container } = render(<Decision {...props} />);
66
58
 
67
- expect(getNavigationOption()).not.toBeInTheDocument();
68
- expect(getTile()).toBeInTheDocument();
69
- expect(getTile()).not.toHaveClass('np-tile--small');
59
+ expect(getNavigationOption(container)).not.toBeInTheDocument();
60
+ expect(getTile(container)).toBeInTheDocument();
61
+ expect(getTile(container)).not.toHaveClass('np-tile--small');
70
62
  });
71
63
  });
72
64
 
73
- describe(`when presentation is ${Presentation.LIST_BLOCK_GRID}`, () => {
74
- beforeEach(() => {
75
- ({ container } = render(<Decision {...props} presentation={Presentation.LIST_BLOCK_GRID} />));
76
- });
65
+ describe(`when presentation is ${DecisionPresentation.LIST_BLOCK_GRID}`, () => {
66
+ const props = { ...commonProps, presentation: DecisionPresentation.LIST_BLOCK_GRID };
77
67
 
78
68
  it('renders only Navigation Option before first breakpoint', () => {
79
- expect(getNavigationOption()).toBeInTheDocument();
80
- expect(getTile()).not.toBeInTheDocument();
69
+ const { container } = render(<Decision {...props} />);
70
+
71
+ expect(getNavigationOption(container)).toBeInTheDocument();
72
+ expect(getTile(container)).not.toBeInTheDocument();
81
73
  });
82
74
 
83
75
  it('renders only Tile after first breakpoint', () => {
84
76
  resetClientWidth(Breakpoint.SMALL);
85
- fireEvent(window, new Event('resize'));
77
+ const { container } = render(<Decision {...props} />);
86
78
 
87
- expect(getNavigationOption()).not.toBeInTheDocument();
88
- expect(getTile()).toBeInTheDocument();
89
- expect(getTile()).not.toHaveClass('np-tile--small');
79
+ expect(getNavigationOption(container)).not.toBeInTheDocument();
80
+ expect(getTile(container)).toBeInTheDocument();
81
+ expect(getTile(container)).not.toHaveClass('np-tile--small');
90
82
  });
91
83
 
92
84
  it('renders container as a grid', () => {
93
85
  resetClientWidth(Breakpoint.SMALL);
94
- fireEvent(window, new Event('resize'));
86
+ const { container } = render(<Decision {...props} />);
95
87
 
96
- expect(container.querySelector('.np-decision')).toHaveClass('np-decision--grid');
97
- expect(container.querySelector('.np-size-swapper')).toHaveClass('flex-wrap');
88
+ const decisionElement = container.querySelector('.np-decision');
89
+ expect(decisionElement).toHaveClass('np-decision--grid');
90
+ expect(decisionElement).toHaveClass('flex-wrap');
98
91
  });
99
92
  });
100
93
 
101
- describe(`when presentation is ${Presentation.LIST_BLOCK} and size is Small`, () => {
102
- beforeEach(() => {
103
- ({ container } = render(
104
- <Decision {...props} presentation={Presentation.LIST_BLOCK} size={Size.SMALL} />,
105
- ));
106
- });
94
+ describe(`when presentation is ${DecisionPresentation.LIST_BLOCK} and size is Small`, () => {
95
+ const props = {
96
+ ...commonProps,
97
+ presentation: DecisionPresentation.LIST_BLOCK,
98
+ size: Size.SMALL,
99
+ };
107
100
 
108
101
  it('renders only Navigation Option before breakpoint', () => {
109
- expect(getNavigationOption()).toBeInTheDocument();
110
- expect(getTile()).not.toBeInTheDocument();
102
+ const { container } = render(<Decision {...props} />);
103
+
104
+ expect(getNavigationOption(container)).toBeInTheDocument();
105
+ expect(getTile(container)).not.toBeInTheDocument();
111
106
  });
112
107
 
113
108
  it('renders Small Tile after breakpoint', () => {
114
109
  resetClientWidth(Breakpoint.EXTRA_SMALL);
115
- fireEvent(window, new Event('resize'));
110
+ const { container } = render(<Decision {...props} />);
116
111
 
117
- expect(getNavigationOption()).not.toBeInTheDocument();
118
- expect(getTile()).toBeInTheDocument();
119
- expect(getTile()).toHaveClass('np-tile--small');
112
+ expect(getNavigationOption(container)).not.toBeInTheDocument();
113
+ expect(getTile(container)).toBeInTheDocument();
114
+ expect(getTile(container)).toHaveClass('np-tile--small');
120
115
  });
121
116
  });
122
117
 
123
- describe(`when presentation is ${Presentation.LIST}`, () => {
124
- beforeEach(() => {
125
- ({ container } = render(<Decision {...props} presentation={Presentation.LIST} />));
126
- });
118
+ describe(`when presentation is ${DecisionPresentation.LIST}`, () => {
119
+ const props = { ...commonProps, presentation: DecisionPresentation.LIST };
127
120
 
128
121
  it('renders Navigation Option before breakpoint', () => {
129
- expect(getNavigationOption()).toBeInTheDocument();
130
- expect(getTile()).not.toBeInTheDocument();
122
+ const { container } = render(<Decision {...props} />);
123
+
124
+ expect(getNavigationOption(container)).toBeInTheDocument();
125
+ expect(getTile(container)).not.toBeInTheDocument();
131
126
  });
132
127
  });
133
128
 
134
- const getNavigationOption = () => container.querySelector('.np-navigation-option');
135
- const getTile = () => container.querySelector('.np-tile');
129
+ const getNavigationOption = (container) => container.querySelector('.np-navigation-option');
130
+ const getTile = (container) => container.querySelector('.np-tile');
136
131
  });
@@ -21,7 +21,7 @@ export const Basic = () => {
21
21
  const disabled = boolean('disabled', false);
22
22
  const showMediaCircleInList = boolean('showMediaCircleInList', true);
23
23
  const isContainerAligned = boolean('isContainerAligned', false);
24
- const size = select('size', [Size.MEDIUM, Size.SMALL]);
24
+ const size = select('size', [Size.MEDIUM, Size.SMALL], Size.MEDIUM);
25
25
 
26
26
  return (
27
27
  <>
@@ -33,7 +33,7 @@ export const Basic = () => {
33
33
  href: '#href1',
34
34
  disabled,
35
35
  media: {
36
- block: <Illustration name="globe" alt="" disableMargin />,
36
+ block: <Illustration name="globe" alt="" disablePadding />,
37
37
  list: (
38
38
  <Avatar size="md" type="initials">
39
39
  HM
@@ -49,7 +49,7 @@ export const Basic = () => {
49
49
  disabled,
50
50
  href: '#href2',
51
51
  media: {
52
- block: <Illustration name="confetti" alt="" disableMargin />,
52
+ block: <Illustration name="confetti" alt="" disablePadding />,
53
53
  list: (
54
54
  <Avatar size="md" type="initials">
55
55
  HM
@@ -61,7 +61,7 @@ export const Basic = () => {
61
61
  {
62
62
  description: "I'm disabled and don't require an onClick or href.",
63
63
  media: {
64
- block: <Illustration name="briefcase" alt="" disableMargin />,
64
+ block: <Illustration name="briefcase" alt="" disablePadding />,
65
65
  list: (
66
66
  <img
67
67
  src="https://wise.com/public-resources/assets/illustrations/business_account_web_small.svg"
@@ -91,7 +91,7 @@ export const grid = () => {
91
91
  DecisionPresentation.LIST_BLOCK_GRID,
92
92
  );
93
93
  const disabled = boolean('disabled', false);
94
- const size = select('size', [Size.MEDIUM, Size.SMALL]);
94
+ const size = select('size', [Size.MEDIUM, Size.SMALL], Size.MEDIUM);
95
95
 
96
96
  return (
97
97
  <>
@@ -0,0 +1,133 @@
1
+ import classNames from 'classnames';
2
+
3
+ import { Size, Breakpoint, SizeSmall, SizeMedium } from '../common';
4
+ import { useScreenSize } from '../common/hooks/useScreenSize';
5
+ import NavigationOption from '../navigationOption';
6
+ import Tile from '../tile';
7
+
8
+ interface DecisionOption {
9
+ description?: React.ReactNode;
10
+ disabled?: boolean;
11
+ href?: string;
12
+ target?: React.HTMLAttributeAnchorTarget;
13
+ media: {
14
+ block: React.ReactNode;
15
+ list: React.ReactNode;
16
+ };
17
+ onClick?: React.MouseEventHandler<HTMLElement>;
18
+ title: React.ReactNode;
19
+ }
20
+
21
+ export enum DecisionPresentation {
22
+ LIST = 'LIST',
23
+ LIST_BLOCK = 'LIST_BLOCK',
24
+ LIST_BLOCK_GRID = 'LIST_BLOCK_GRID',
25
+ }
26
+
27
+ export enum DecisionType {
28
+ NAVIGATION = 'NAVIGATION',
29
+ }
30
+
31
+ export interface DecisionProps {
32
+ /** A list of elements to be rendered */
33
+ options: DecisionOption[];
34
+ /** Handles the display mode of the component */
35
+ presentation?: `${DecisionPresentation}`;
36
+ /** Size currently affects only Tile dimension */
37
+ size?: SizeSmall | SizeMedium;
38
+ /** Decide which kind of element type needs to be rendered ex: Navigation Options or in the future Radio or Checkbox Options */
39
+ type?: `${DecisionType}`;
40
+
41
+ /** Display media in a circle in list presentation */
42
+ showMediaCircleInList?: boolean;
43
+
44
+ /** Sets navigation options to be aligned with the parent container */
45
+ isContainerAligned?: boolean;
46
+ }
47
+
48
+ const Decision = ({
49
+ options,
50
+ presentation = DecisionPresentation.LIST,
51
+ size = Size.MEDIUM,
52
+ type = DecisionType.NAVIGATION,
53
+ showMediaCircleInList = true,
54
+ isContainerAligned = false,
55
+ }: DecisionProps) => {
56
+ const screenXs = useScreenSize(Breakpoint.EXTRA_SMALL);
57
+ const screenSm = useScreenSize(Breakpoint.SMALL);
58
+
59
+ if (type === DecisionType.NAVIGATION) {
60
+ const renderedOptions = options.map(
61
+ ({ title, description, disabled, href, target, media: { list }, onClick }, key) => (
62
+ <NavigationOption
63
+ // eslint-disable-next-line react/no-array-index-key
64
+ key={`nav-${key}`}
65
+ complex={false}
66
+ content={description}
67
+ disabled={disabled}
68
+ href={href}
69
+ target={target}
70
+ media={list}
71
+ showMediaAtAllSizes
72
+ showMediaCircle={showMediaCircleInList}
73
+ isContainerAligned={isContainerAligned}
74
+ title={title}
75
+ onClick={onClick}
76
+ />
77
+ ),
78
+ );
79
+
80
+ if (
81
+ presentation === DecisionPresentation.LIST_BLOCK ||
82
+ presentation === DecisionPresentation.LIST_BLOCK_GRID
83
+ ) {
84
+ const isSmall = size === Size.SMALL;
85
+ const breakpoint = isSmall ? screenXs : screenSm;
86
+
87
+ const isGrid = presentation === DecisionPresentation.LIST_BLOCK_GRID;
88
+
89
+ return (
90
+ <div
91
+ className={classNames(
92
+ 'np-decision d-flex',
93
+ {
94
+ 'np-decision--small': isSmall,
95
+ 'np-decision--grid': isGrid,
96
+ },
97
+ breakpoint ? isGrid && 'flex-wrap' : 'flex-column',
98
+ )}
99
+ >
100
+ {breakpoint
101
+ ? options.map(
102
+ (
103
+ { description, disabled, href, target, media: { block }, onClick, title },
104
+ key,
105
+ ) => (
106
+ <Tile
107
+ // eslint-disable-next-line react/no-array-index-key
108
+ key={`tile-${key}`}
109
+ className={classNames(`np-decision__tile${isSmall ? '--small' : ''}`, {
110
+ 'np-decision__tile--fixed-width': isGrid,
111
+ })}
112
+ description={description}
113
+ disabled={disabled}
114
+ href={href}
115
+ target={target}
116
+ media={block}
117
+ size={isSmall ? Size.SMALL : Size.MEDIUM}
118
+ title={title}
119
+ onClick={onClick}
120
+ />
121
+ ),
122
+ )
123
+ : renderedOptions}
124
+ </div>
125
+ );
126
+ }
127
+ // LIST
128
+ return <>{renderedOptions}</>;
129
+ }
130
+ return null;
131
+ };
132
+
133
+ export default Decision;
@@ -0,0 +1 @@
1
+ export { default, DecisionPresentation, DecisionType } from './Decision';
@@ -1,3 +1,4 @@
1
+ import { useId } from '@radix-ui/react-id';
1
2
  import classNames from 'classnames';
2
3
  import PropTypes from 'prop-types';
3
4
 
@@ -16,17 +17,27 @@ const Drawer = ({ children, className, footerContent, headerTitle, onClose, open
16
17
  );
17
18
 
18
19
  const { isMobile } = useLayout();
20
+ const titleId = useId();
19
21
 
20
22
  return (
21
23
  <Dimmer open={open} onClose={onClose}>
22
24
  <SlidingPanel open={open} position={isMobile ? Position.BOTTOM : position}>
23
- <div className={classNames('np-drawer', className)} role="dialog">
25
+ <div
26
+ role="dialog"
27
+ aria-modal
28
+ aria-labelledby={headerTitle ? titleId : undefined}
29
+ className={classNames('np-drawer', className)}
30
+ >
24
31
  <div
25
32
  className={classNames('np-drawer-header', {
26
33
  'np-drawer-header--withborder': headerTitle,
27
34
  })}
28
35
  >
29
- {headerTitle && <Title type={Typography.TITLE_BODY}>{headerTitle}</Title>}
36
+ {headerTitle && (
37
+ <Title id={titleId} type={Typography.TITLE_BODY}>
38
+ {headerTitle}
39
+ </Title>
40
+ )}
30
41
  <CloseButton onClick={onClose} />
31
42
  </div>
32
43
  {children && <div className={classNames('np-drawer-content')}>{children}</div>}
@@ -11,6 +11,7 @@ exports[`Drawer renders content when open 1`] = `
11
11
  class="sliding-panel"
12
12
  >
13
13
  <div
14
+ aria-modal="true"
14
15
  class="np-drawer"
15
16
  role="dialog"
16
17
  >
package/src/index.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Types
3
3
  */
4
+ export type { DecisionProps } from './decision/Decision';
4
5
  export type { InputProps } from './inputs/Input';
6
+ export type { DateInputProps } from './dateInput';
5
7
  export type { InputWithDisplayFormatProps } from './inputWithDisplayFormat';
6
8
  export type { InputGroupProps } from './inputs/InputGroup';
7
9
  export type { SearchInputProps } from './inputs/SearchInput';
package/src/main.css CHANGED
@@ -1598,95 +1598,19 @@ button.np-option {
1598
1598
  .np-decision .decision {
1599
1599
  display: flex;
1600
1600
  }
1601
- .np-decision__tile--small + .np-decision__tile--small {
1602
- margin-left: 16px;
1603
- margin-left: var(--size-16);
1604
- }
1605
- [dir="rtl"] .np-decision__tile--small + .np-decision__tile--small {
1606
- margin-right: 16px;
1607
- margin-right: var(--size-16);
1608
- margin-left: 0;
1609
- margin-left: initial;
1610
- }
1611
- .np-decision.np-decision--grid .np-decision__tile--small {
1612
- margin-left: 0;
1613
- margin-bottom: 16px !important;
1614
- margin-bottom: var(--size-16) !important;
1615
- }
1616
- [dir="rtl"] .np-decision.np-decision--grid .np-decision__tile--small {
1617
- margin-right: 0;
1618
- margin-left: 0;
1619
- margin-left: initial;
1620
- }
1621
- .np-decision.np-decision--grid .np-decision__tile--small:not(:last-of-type) {
1622
- margin-right: 16px;
1623
- margin-right: var(--size-16);
1624
- }
1625
- [dir="rtl"] .np-decision.np-decision--grid .np-decision__tile--small:not(:last-of-type) {
1626
- margin-left: 16px;
1627
- margin-left: var(--size-16);
1628
- margin-right: 0;
1629
- margin-right: initial;
1630
- }
1631
- .np-decision__tile + .np-decision__tile {
1632
- margin-left: 24px;
1633
- margin-left: var(--size-24);
1634
- }
1635
- [dir="rtl"] .np-decision__tile + .np-decision__tile {
1636
- margin-right: 24px;
1637
- margin-right: var(--size-24);
1638
- margin-left: 0;
1639
- margin-left: initial;
1640
- }
1641
- .np-decision .np-text-title-subsection {
1642
- margin-bottom: 0;
1643
- }
1644
1601
  .np-decision__tile--small .np-text-title-subsection {
1645
1602
  font-size: 1rem;
1646
1603
  font-size: var(--font-size-16);
1647
1604
  line-height: 1.2;
1648
1605
  line-height: var(--line-height-title);
1649
- margin-bottom: 0;
1650
- }
1651
- .np-decision.np-decision--grid .np-decision__tile {
1652
- margin-left: 0;
1653
- margin-bottom: 24px !important;
1654
- margin-bottom: var(--size-24) !important;
1655
- }
1656
- [dir="rtl"] .np-decision.np-decision--grid .np-decision__tile {
1657
- margin-right: 0;
1658
- margin-left: 0;
1659
- margin-left: initial;
1660
- }
1661
- .np-decision.np-decision--grid .np-decision__tile:not(:last-of-type) {
1662
- margin-right: 24px;
1663
- margin-right: var(--size-24);
1664
1606
  }
1665
- [dir="rtl"] .np-decision.np-decision--grid .np-decision__tile:not(:last-of-type) {
1666
- margin-left: 24px;
1667
- margin-left: var(--size-24);
1668
- margin-right: 0;
1669
- margin-right: initial;
1670
- }
1671
- .np-decision.np-decision--grid .np-size-swapper {
1672
- margin-right: calc(0 - 24px);
1673
- margin-right: calc(0 - var(--size-24));
1674
- }
1675
- [dir="rtl"] .np-decision.np-decision--grid .np-size-swapper {
1676
- margin-left: calc(0 - 24px);
1677
- margin-left: calc(0 - var(--size-24));
1678
- margin-right: 0;
1679
- margin-right: initial;
1680
- }
1681
- .np-decision.np-decision--grid.np-decision--small .np-size-swapper {
1682
- margin-right: calc(0 - 16px);
1683
- margin-right: calc(0 - var(--size-16));
1607
+ .np-decision:not(.flex-column) {
1608
+ gap: 24px;
1609
+ gap: var(--size-24);
1684
1610
  }
1685
- [dir="rtl"] .np-decision.np-decision--grid.np-decision--small .np-size-swapper {
1686
- margin-left: calc(0 - 16px);
1687
- margin-left: calc(0 - var(--size-16));
1688
- margin-right: 0;
1689
- margin-right: initial;
1611
+ .np-decision:not(.flex-column).np-decision--small {
1612
+ gap: 16px;
1613
+ gap: var(--size-16);
1690
1614
  }
1691
1615
  .tw-definition-list__item dd {
1692
1616
  word-break: break-all;
@@ -1,3 +1,4 @@
1
+ import { useId } from '@radix-ui/react-id';
1
2
  import classNames from 'classnames';
2
3
  import { ReactNode, useRef } from 'react';
3
4
  import { CSSTransition } from 'react-transition-group';
@@ -59,6 +60,7 @@ const Modal = ({
59
60
  const noDivider = checkSpecialClasses('no-divider');
60
61
 
61
62
  const contentReference = useRef<HTMLDivElement>(null);
63
+ const titleId = useId();
62
64
 
63
65
  return !isMedium ? (
64
66
  <Drawer
@@ -99,11 +101,12 @@ const Modal = ({
99
101
  {...otherProps}
100
102
  >
101
103
  <div
104
+ role="dialog"
105
+ aria-modal
106
+ aria-labelledby={titleId}
102
107
  className={classNames('tw-modal-dialog', 'd-flex', {
103
108
  [`tw-modal-${size}`]: size,
104
109
  })}
105
- aria-modal
106
- role="dialog"
107
110
  >
108
111
  <div
109
112
  className={classNames(
@@ -129,7 +132,7 @@ const Modal = ({
129
132
  },
130
133
  )}
131
134
  >
132
- <Title type={Typography.TITLE_BODY} className="tw-modal-title">
135
+ <Title id={titleId} type={Typography.TITLE_BODY} className="tw-modal-title">
133
136
  {title}
134
137
  </Title>
135
138
  <CloseButton onClick={onClose} />
@@ -8,13 +8,16 @@ import ResponsivePanel from '../common/responsivePanel';
8
8
  import Title from '../title';
9
9
  import { logActionRequiredIf } from '../utilities';
10
10
 
11
- const Popover = ({ children, className, content, preferredPlacement, title }) => {
11
+ const Popover = ({ children, className, content, preferredPlacement, title, onClose }) => {
12
12
  logActionRequired({ preferredPlacement });
13
13
  const anchorReference = useRef(null);
14
14
  const [open, setOpen] = useState(false);
15
15
  const { isModern } = useTheme();
16
16
 
17
- const onClose = () => setOpen(false);
17
+ const handleOnClose = () => {
18
+ setOpen(false);
19
+ onClose?.();
20
+ };
18
21
 
19
22
  return (
20
23
  <span className={classnames('np-popover', className)}>
@@ -34,7 +37,7 @@ const Popover = ({ children, className, content, preferredPlacement, title }) =>
34
37
  position={deprecatedPlacements[preferredPlacement] || preferredPlacement}
35
38
  arrow
36
39
  className="np-popover__container"
37
- onClose={onClose}
40
+ onClose={handleOnClose}
38
41
  >
39
42
  <div
40
43
  className={isModern ? 'np-popover__content np-text-default-body' : 'np-popover__content'}
@@ -84,6 +87,7 @@ Popover.propTypes = {
84
87
  'bottom-right',
85
88
  'bottom-left',
86
89
  ]),
90
+ onClose: PropTypes.func,
87
91
  title: PropTypes.node,
88
92
  };
89
93
 
@@ -10,14 +10,6 @@ jest.mock('react-transition-group', () => ({
10
10
  CSSTransition: (props) => (props.in ? props.children : null),
11
11
  }));
12
12
 
13
- jest.mock(
14
- '../dimmer',
15
- () =>
16
- function ({ open, children }) {
17
- return open ? <div className="dimmer">{children}</div> : null;
18
- },
19
- );
20
-
21
13
  describe('Popover', () => {
22
14
  const props = {
23
15
  arrow: true,
@@ -114,7 +106,23 @@ describe('Popover', () => {
114
106
  });
115
107
  });
116
108
 
109
+ it('onClose fires when close Popover', async () => {
110
+ const handleOnClose = jest.fn();
111
+ render(
112
+ <Popover {...props} onClose={handleOnClose}>
113
+ <button type="button">Open</button>
114
+ </Popover>,
115
+ );
116
+
117
+ expect(handleOnClose).not.toHaveBeenCalled();
118
+ userEvent.click(screen.getByText('Open'));
119
+ await waitForPanel();
120
+ userEvent.click(getDimmer());
121
+ expect(handleOnClose).toHaveBeenCalledTimes(1);
122
+ });
123
+
117
124
  const waitForPanel = async () => screen.findByText('content');
125
+ const getDimmer = () => document.querySelector('.dimmer');
118
126
  const getPanel = () => document.querySelector('.np-panel');
119
127
  const getBottomSheet = () => document.querySelector('.np-bottom-sheet');
120
128
  const getTitle = () => screen.queryByText('title');