@transferwise/components 0.0.0-experimental-ff4fa52 → 0.0.0-experimental-1413ac0

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 (129) hide show
  1. package/README.md +14 -1
  2. package/build/i18n/zh-HK.json +2 -2
  3. package/build/index.esm.js +182 -273
  4. package/build/index.esm.js.map +1 -1
  5. package/build/index.js +155 -246
  6. package/build/index.js.map +1 -1
  7. package/build/mocks.esm.js +40 -0
  8. package/build/mocks.esm.js.map +1 -0
  9. package/build/mocks.js +43 -0
  10. package/build/mocks.js.map +1 -0
  11. package/build/types/body/Body.d.ts +1 -1
  12. package/build/types/common/commonProps.d.ts +1 -1
  13. package/build/types/common/commonProps.d.ts.map +1 -1
  14. package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts +1 -1
  15. package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts.map +1 -1
  16. package/build/types/common/dateUtils/getDayNames/index.d.ts +2 -0
  17. package/build/types/common/dateUtils/getDayNames/index.d.ts.map +1 -0
  18. package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts +1 -1
  19. package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts.map +1 -1
  20. package/build/types/common/dateUtils/getMonthNames/index.d.ts +2 -0
  21. package/build/types/common/dateUtils/getMonthNames/index.d.ts.map +1 -0
  22. package/build/types/common/dateUtils/index.d.ts +6 -6
  23. package/build/types/common/dateUtils/index.d.ts.map +1 -1
  24. package/build/types/common/dateUtils/isDateValid/index.d.ts +2 -0
  25. package/build/types/common/dateUtils/isDateValid/index.d.ts.map +1 -0
  26. package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts +2 -2
  27. package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts.map +1 -1
  28. package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts +2 -0
  29. package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts.map +1 -0
  30. package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts +1 -1
  31. package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts.map +1 -1
  32. package/build/types/common/dateUtils/isWithinRange/index.d.ts +2 -0
  33. package/build/types/common/dateUtils/isWithinRange/index.d.ts.map +1 -0
  34. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts +1 -1
  35. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts.map +1 -1
  36. package/build/types/common/dateUtils/moveToWithinRange/index.d.ts +2 -0
  37. package/build/types/common/dateUtils/moveToWithinRange/index.d.ts.map +1 -0
  38. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts +1 -1
  39. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts.map +1 -1
  40. package/build/types/common/panel/Panel.d.ts +1 -1
  41. package/build/types/common/responsivePanel/ResponsivePanel.d.ts +1 -1
  42. package/build/types/dateInput/DateInput.d.ts +41 -35
  43. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  44. package/build/types/dateInput/DateInput.messages.d.ts +33 -24
  45. package/build/types/dateInput/DateInput.messages.d.ts.map +1 -1
  46. package/build/types/dateInput/index.d.ts +1 -1
  47. package/build/types/dateInput/index.d.ts.map +1 -1
  48. package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts +1 -1
  49. package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts.map +1 -1
  50. package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts +1 -1
  51. package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts.map +1 -1
  52. package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts +5 -2
  53. package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts.map +1 -1
  54. package/build/types/dateInput/utils/explodeDate/index.d.ts +1 -1
  55. package/build/types/dateInput/utils/explodeDate/index.d.ts.map +1 -1
  56. package/build/types/dateInput/utils/index.d.ts +2 -2
  57. package/build/types/dateInput/utils/index.d.ts.map +1 -1
  58. package/build/types/decision/Decision.d.ts +39 -52
  59. package/build/types/decision/Decision.d.ts.map +1 -1
  60. package/build/types/decision/index.d.ts +1 -2
  61. package/build/types/decision/index.d.ts.map +1 -1
  62. package/build/types/dimmer/Dimmer.d.ts +1 -1
  63. package/build/types/index.d.ts +1 -0
  64. package/build/types/index.d.ts.map +1 -1
  65. package/build/types/mocks.d.ts +9 -0
  66. package/build/types/mocks.d.ts.map +1 -0
  67. package/build/types/promoCard/PromoCard.d.ts +1 -2
  68. package/build/types/promoCard/PromoCard.d.ts.map +1 -1
  69. package/build/types/select/searchBox/SearchBox.d.ts +1 -1
  70. package/build/types/test-utils/window-mock.d.ts.map +1 -1
  71. package/package.json +17 -1
  72. package/src/common/commonProps.ts +1 -1
  73. package/src/common/dateUtils/getDayNames/{getDayNames.ts → getDayNames.js} +2 -5
  74. package/src/common/dateUtils/getDayNames/getDayNames.spec.js +1 -1
  75. package/src/common/dateUtils/getDayNames/index.js +1 -0
  76. package/src/common/dateUtils/getMonthNames/{getMonthNames.ts → getMonthNames.js} +3 -5
  77. package/src/common/dateUtils/getMonthNames/getMonthNames.spec.js +8 -9
  78. package/src/common/dateUtils/getMonthNames/index.js +1 -0
  79. package/src/common/dateUtils/index.js +6 -0
  80. package/src/common/dateUtils/isDateValid/index.js +1 -0
  81. package/src/common/dateUtils/isDateValid/isDateValid.js +6 -0
  82. package/src/common/dateUtils/isDateValid/{isDateValid.spec.ts → isDateValid.spec.js} +1 -1
  83. package/src/common/dateUtils/isMonthAndYearFormat/index.js +1 -0
  84. package/src/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.js +4 -0
  85. package/src/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.spec.js +7 -3
  86. package/src/common/dateUtils/isWithinRange/index.js +1 -0
  87. package/src/common/dateUtils/isWithinRange/{isWithinRange.ts → isWithinRange.js} +1 -1
  88. package/src/common/dateUtils/isWithinRange/{isWithinRange.spec.ts → isWithinRange.spec.js} +1 -1
  89. package/src/common/dateUtils/moveToWithinRange/index.js +1 -0
  90. package/src/common/dateUtils/moveToWithinRange/{moveToWithinRange.ts → moveToWithinRange.js} +2 -2
  91. package/src/dateInput/{DateInput.tsx → DateInput.js} +97 -120
  92. package/src/dateInput/DateInput.spec.js +55 -6
  93. package/src/dateInput/DateInput.story.tsx +7 -9
  94. package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.ts → convertToLocalMidnight.js} +1 -1
  95. package/src/dateInput/utils/explodeDate/{explodeDate.ts → explodeDate.js} +1 -3
  96. package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +0 -1
  97. package/src/decision/Decision.spec.js +53 -59
  98. package/src/decision/{Decision.story.js → Decision.story.tsx} +5 -5
  99. package/src/decision/Decision.tsx +136 -0
  100. package/src/decision/index.ts +1 -0
  101. package/src/i18n/zh-HK.json +2 -2
  102. package/src/index.ts +1 -0
  103. package/src/mocks.ts +48 -0
  104. package/src/promoCard/PromoCard.tsx +1 -2
  105. package/src/test-utils/window-mock.ts +7 -23
  106. package/src/tile/Tile.js +1 -1
  107. package/build/types/decision/decisionEnums.d.ts +0 -9
  108. package/build/types/decision/decisionEnums.d.ts.map +0 -1
  109. package/build/types/sizeSwapper/SizeSwapper.d.ts +0 -3
  110. package/build/types/sizeSwapper/SizeSwapper.d.ts.map +0 -1
  111. package/build/types/sizeSwapper/index.d.ts +0 -2
  112. package/build/types/sizeSwapper/index.d.ts.map +0 -1
  113. package/src/common/dateUtils/index.ts +0 -6
  114. package/src/common/dateUtils/isDateValid/isDateValid.ts +0 -13
  115. package/src/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.ts +0 -4
  116. package/src/decision/Decision.js +0 -148
  117. package/src/decision/decisionEnums.ts +0 -11
  118. package/src/decision/index.js +0 -2
  119. package/src/sizeSwapper/SizeSwapper.js +0 -69
  120. package/src/sizeSwapper/SizeSwapper.spec.js +0 -100
  121. package/src/sizeSwapper/SizeSwapper.story.js +0 -34
  122. package/src/sizeSwapper/index.js +0 -1
  123. /package/src/dateInput/{DateInput.messages.ts → DateInput.messages.js} +0 -0
  124. /package/src/dateInput/{index.ts → index.js} +0 -0
  125. /package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.spec.ts → convertToLocalMidnight.spec.js} +0 -0
  126. /package/src/dateInput/utils/convertToLocalMidnight/{index.ts → index.js} +0 -0
  127. /package/src/dateInput/utils/explodeDate/{explodeDate.spec.ts → explodeDate.spec.js} +0 -0
  128. /package/src/dateInput/utils/explodeDate/{index.ts → index.js} +0 -0
  129. /package/src/dateInput/utils/{index.ts → index.js} +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,106 @@ 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
88
  expect(container.querySelector('.np-decision')).toHaveClass('np-decision--grid');
97
89
  expect(container.querySelector('.np-size-swapper')).toHaveClass('flex-wrap');
98
90
  });
99
91
  });
100
92
 
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
- });
93
+ describe(`when presentation is ${DecisionPresentation.LIST_BLOCK} and size is Small`, () => {
94
+ const props = {
95
+ ...commonProps,
96
+ presentation: DecisionPresentation.LIST_BLOCK,
97
+ size: Size.SMALL,
98
+ };
107
99
 
108
100
  it('renders only Navigation Option before breakpoint', () => {
109
- expect(getNavigationOption()).toBeInTheDocument();
110
- expect(getTile()).not.toBeInTheDocument();
101
+ const { container } = render(<Decision {...props} />);
102
+
103
+ expect(getNavigationOption(container)).toBeInTheDocument();
104
+ expect(getTile(container)).not.toBeInTheDocument();
111
105
  });
112
106
 
113
107
  it('renders Small Tile after breakpoint', () => {
114
108
  resetClientWidth(Breakpoint.EXTRA_SMALL);
115
- fireEvent(window, new Event('resize'));
109
+ const { container } = render(<Decision {...props} />);
116
110
 
117
- expect(getNavigationOption()).not.toBeInTheDocument();
118
- expect(getTile()).toBeInTheDocument();
119
- expect(getTile()).toHaveClass('np-tile--small');
111
+ expect(getNavigationOption(container)).not.toBeInTheDocument();
112
+ expect(getTile(container)).toBeInTheDocument();
113
+ expect(getTile(container)).toHaveClass('np-tile--small');
120
114
  });
121
115
  });
122
116
 
123
- describe(`when presentation is ${Presentation.LIST}`, () => {
124
- beforeEach(() => {
125
- ({ container } = render(<Decision {...props} presentation={Presentation.LIST} />));
126
- });
117
+ describe(`when presentation is ${DecisionPresentation.LIST}`, () => {
118
+ const props = { ...commonProps, presentation: DecisionPresentation.LIST };
127
119
 
128
120
  it('renders Navigation Option before breakpoint', () => {
129
- expect(getNavigationOption()).toBeInTheDocument();
130
- expect(getTile()).not.toBeInTheDocument();
121
+ const { container } = render(<Decision {...props} />);
122
+
123
+ expect(getNavigationOption(container)).toBeInTheDocument();
124
+ expect(getTile(container)).not.toBeInTheDocument();
131
125
  });
132
126
  });
133
127
 
134
- const getNavigationOption = () => container.querySelector('.np-navigation-option');
135
- const getTile = () => container.querySelector('.np-tile');
128
+ const getNavigationOption = (container) => container.querySelector('.np-navigation-option');
129
+ const getTile = (container) => container.querySelector('.np-tile');
136
130
  });
@@ -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,136 @@
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('np-decision', {
92
+ 'np-decision--small': isSmall,
93
+ 'np-decision--grid': isGrid,
94
+ })}
95
+ >
96
+ <div
97
+ className={classNames(
98
+ 'np-size-swapper d-flex',
99
+ breakpoint ? isGrid && 'flex-wrap' : 'flex-column',
100
+ )}
101
+ >
102
+ {breakpoint
103
+ ? options.map(
104
+ (
105
+ { description, disabled, href, target, media: { block }, onClick, title },
106
+ key,
107
+ ) => (
108
+ <Tile
109
+ // eslint-disable-next-line react/no-array-index-key
110
+ key={`tile-${key}`}
111
+ className={classNames(`np-decision__tile${isSmall ? '--small' : ''}`, {
112
+ 'np-decision__tile--fixed-width': isGrid,
113
+ })}
114
+ description={description}
115
+ disabled={disabled}
116
+ href={href}
117
+ target={target}
118
+ media={block}
119
+ size={isSmall ? Size.SMALL : Size.MEDIUM}
120
+ title={title}
121
+ onClick={onClick}
122
+ />
123
+ ),
124
+ )
125
+ : renderedOptions}
126
+ </div>
127
+ </div>
128
+ );
129
+ }
130
+ // LIST
131
+ return <>{renderedOptions}</>;
132
+ }
133
+ return null;
134
+ };
135
+
136
+ export default Decision;
@@ -0,0 +1 @@
1
+ export { default, DecisionPresentation, DecisionType } from './Decision';
@@ -4,10 +4,10 @@
4
4
  "neptune.ClearButton.ariaLabel": "清除",
5
5
  "neptune.CloseButton.ariaLabel": "關閉",
6
6
  "neptune.DateInput.day.label": "日",
7
- "neptune.DateInput.day.placeholder": "日",
7
+ "neptune.DateInput.day.placeholder": "DD",
8
8
  "neptune.DateInput.month.label": "月",
9
9
  "neptune.DateInput.year.label": "年",
10
- "neptune.DateInput.year.placeholder": "年",
10
+ "neptune.DateInput.year.placeholder": "YYYY",
11
11
  "neptune.DateLookup.day": "日",
12
12
  "neptune.DateLookup.goTo20YearView": "切換至20年視圖",
13
13
  "neptune.DateLookup.month": "月",
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Types
3
3
  */
4
+ export type { DecisionProps } from './decision/Decision';
4
5
  export type { InputProps } from './inputs/Input';
5
6
  export type { InputWithDisplayFormatProps } from './inputWithDisplayFormat';
6
7
  export type { InputGroupProps } from './inputs/InputGroup';
package/src/mocks.ts ADDED
@@ -0,0 +1,48 @@
1
+ type StubGlobal = (name: PropertyKey, value: unknown) => void;
2
+
3
+ interface GlobalMockParams {
4
+ fn: <T extends (...args: never[]) => unknown>(implementation?: T) => T;
5
+ stubGlobal?: StubGlobal;
6
+ }
7
+
8
+ const defaultStubGlobal: StubGlobal = (name, value) => {
9
+ Object.defineProperty(globalThis, name, {
10
+ value,
11
+ writable: true,
12
+ enumerable: true,
13
+ configurable: true,
14
+ });
15
+ };
16
+
17
+ export function mockMatchMedia({ fn, stubGlobal = defaultStubGlobal }: GlobalMockParams) {
18
+ stubGlobal(
19
+ 'matchMedia',
20
+ fn<Window['matchMedia']>((query) => {
21
+ const matches = /^\(min-width: (\d+)px\)$/u.exec(query);
22
+ const minWidth = matches != null ? Number(matches[1]) : undefined;
23
+ return {
24
+ matches: minWidth != null ? window.innerWidth >= minWidth : false,
25
+ media: query,
26
+ onchange: null,
27
+ addListener: fn(),
28
+ removeListener: fn(),
29
+ addEventListener: fn(),
30
+ removeEventListener: fn(),
31
+ dispatchEvent: fn(),
32
+ };
33
+ }),
34
+ );
35
+ }
36
+
37
+ export function mockResizeObserver({ fn, stubGlobal = defaultStubGlobal }: GlobalMockParams) {
38
+ stubGlobal(
39
+ 'ResizeObserver',
40
+ fn(
41
+ (): ResizeObserver => ({
42
+ observe: fn(),
43
+ unobserve: fn(),
44
+ disconnect: fn(),
45
+ }),
46
+ ),
47
+ );
48
+ }
@@ -13,7 +13,6 @@ import { usePromoCardContext } from './PromoCardContext';
13
13
  import PromoCardIndicator, { PromoCardIndicatorProps } from './PromoCardIndicator';
14
14
 
15
15
  export type ReferenceType = React.Ref<HTMLInputElement>;
16
- export type LinkTarget = '_blank' | '_parent' | '_self' | '_top';
17
16
  export type RelatedTypes =
18
17
  | ''
19
18
  | 'alternate'
@@ -98,7 +97,7 @@ export interface PromoCardLinkProps extends PromoCardCommonProps, Omit<CardProps
98
97
  rel?: RelatedTypes;
99
98
 
100
99
  /** Optional prop to to display where the linked URL will show */
101
- target?: LinkTarget;
100
+ target?: React.HTMLAttributeAnchorTarget;
102
101
 
103
102
  /** Only applies to role="radio" or "checkbox" */
104
103
  defaultChecked?: never;
@@ -1,30 +1,14 @@
1
+ import {
2
+ mockMatchMedia as baseMockMatchMedia,
3
+ mockResizeObserver as baseMockResizeObserver,
4
+ } from '../mocks';
5
+
1
6
  export function mockMatchMedia() {
2
- Object.defineProperty(window, 'matchMedia', {
3
- writable: true,
4
- value: jest.fn().mockImplementation((query: string) => {
5
- const matches = /^\(min-width: ([0-9]+)px\)$/.exec(query);
6
- const minWidth = matches != null ? Number(matches[1]) : undefined;
7
- return {
8
- matches: minWidth != null ? window.innerWidth >= minWidth : false,
9
- media: query,
10
- onchange: null,
11
- addListener: jest.fn(), // deprecated
12
- removeListener: jest.fn(), // deprecated
13
- addEventListener: jest.fn(),
14
- removeEventListener: jest.fn(),
15
- dispatchEvent: jest.fn(),
16
- };
17
- }),
18
- });
7
+ baseMockMatchMedia(jest);
19
8
  }
20
9
 
21
10
  export function mockResizeObserver() {
22
11
  // mock ResizeObserver because it's not implemented in jsdoc lib
23
12
  // https://github.com/jsdom/jsdom/issues/3368
24
- // eslint-disable-next-line compat/compat
25
- window.ResizeObserver = class ResizeObserver {
26
- observe = jest.fn();
27
- unobserve = jest.fn();
28
- disconnect = jest.fn();
29
- };
13
+ baseMockResizeObserver(jest);
30
14
  }
package/src/tile/Tile.js CHANGED
@@ -65,7 +65,7 @@ Tile.propTypes = {
65
65
  className: PropTypes.string,
66
66
  description: PropTypes.node,
67
67
  disabled: PropTypes.bool,
68
- href: PropTypes.string.isRequired,
68
+ href: PropTypes.string,
69
69
  target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top']),
70
70
  /** Accepts only Avatar and images */
71
71
  media: PropTypes.node.isRequired,
@@ -1,9 +0,0 @@
1
- export declare enum Presentation {
2
- LIST = "LIST",
3
- LIST_BLOCK = "LIST_BLOCK",
4
- LIST_BLOCK_GRID = "LIST_BLOCK_GRID"
5
- }
6
- export declare enum Type {
7
- NAVIGATION = "NAVIGATION"
8
- }
9
- //# sourceMappingURL=decisionEnums.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decisionEnums.d.ts","sourceRoot":"","sources":["../../../src/decision/decisionEnums.ts"],"names":[],"mappings":"AACA,oBAAY,YAAY;IACtB,IAAI,SAAS;IACb,UAAU,eAAe;IACzB,eAAe,oBAAoB;CACpC;AAGD,oBAAY,IAAI;IACd,UAAU,eAAe;CAC1B"}
@@ -1,3 +0,0 @@
1
- export default SizeSwapper;
2
- declare const SizeSwapper: import("react").ForwardRefExoticComponent<import("react").RefAttributes<any>>;
3
- //# sourceMappingURL=SizeSwapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SizeSwapper.d.ts","sourceRoot":"","sources":["../../../src/sizeSwapper/SizeSwapper.js"],"names":[],"mappings":";AASA,yGAqCG"}
@@ -1,2 +0,0 @@
1
- export { default } from "./SizeSwapper";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/sizeSwapper/index.js"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- export { getDayNames } from './getDayNames/getDayNames';
2
- export { moveToWithinRange } from './moveToWithinRange/moveToWithinRange';
3
- export { isWithinRange } from './isWithinRange/isWithinRange';
4
- export { getMonthNames } from './getMonthNames/getMonthNames';
5
- export { isDateValid } from './isDateValid/isDateValid';
6
- export { isMonthAndYearFormat } from './isMonthAndYearFormat/isMonthAndYearFormat';
@@ -1,13 +0,0 @@
1
- export const isDateValid = (date: Date | string | null) => {
2
- if (date === null) {
3
- return false;
4
- } else if (date instanceof Date) {
5
- return validDateObject(date);
6
- } else {
7
- return validDateString(date);
8
- }
9
- };
10
-
11
- export const validDateString = (dateString: string) => validDateObject(new Date(dateString));
12
-
13
- const validDateObject = (dateObject: Date) => !isNaN(dateObject.getTime());
@@ -1,4 +0,0 @@
1
- import { validDateString } from '../isDateValid/isDateValid';
2
-
3
- export const isMonthAndYearFormat = (dateString: string) =>
4
- validDateString(dateString) && dateString.split('-').length < 3;