@transferwise/components 0.0.0-experimental-4c79cff → 0.0.0-experimental-28a3dd5

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 (183) hide show
  1. package/build/avatarLayout/AvatarLayout.js +10 -4
  2. package/build/avatarLayout/AvatarLayout.js.map +1 -1
  3. package/build/avatarLayout/AvatarLayout.mjs +10 -4
  4. package/build/avatarLayout/AvatarLayout.mjs.map +1 -1
  5. package/build/button/Button.js +86 -79
  6. package/build/button/Button.js.map +1 -1
  7. package/build/button/Button.mjs +87 -80
  8. package/build/button/Button.mjs.map +1 -1
  9. package/build/button/Button.resolver.js +74 -0
  10. package/build/button/Button.resolver.js.map +1 -0
  11. package/build/button/Button.resolver.mjs +72 -0
  12. package/build/button/Button.resolver.mjs.map +1 -0
  13. package/build/button/LegacyButton.js +114 -0
  14. package/build/button/LegacyButton.js.map +1 -0
  15. package/build/button/LegacyButton.mjs +112 -0
  16. package/build/button/LegacyButton.mjs.map +1 -0
  17. package/build/criticalBanner/CriticalCommsBanner.js +2 -2
  18. package/build/criticalBanner/CriticalCommsBanner.js.map +1 -1
  19. package/build/criticalBanner/CriticalCommsBanner.mjs +1 -1
  20. package/build/header/Header.js +2 -2
  21. package/build/header/Header.js.map +1 -1
  22. package/build/header/Header.mjs +1 -1
  23. package/build/i18n/ja.json +0 -1
  24. package/build/i18n/ja.json.js +0 -1
  25. package/build/i18n/ja.json.js.map +1 -1
  26. package/build/i18n/ja.json.mjs +0 -1
  27. package/build/i18n/ja.json.mjs.map +1 -1
  28. package/build/i18n/pt.json +0 -1
  29. package/build/i18n/pt.json.js +0 -1
  30. package/build/i18n/pt.json.js.map +1 -1
  31. package/build/i18n/pt.json.mjs +0 -1
  32. package/build/i18n/pt.json.mjs.map +1 -1
  33. package/build/i18n/ru.json +0 -1
  34. package/build/i18n/ru.json.js +0 -1
  35. package/build/i18n/ru.json.js.map +1 -1
  36. package/build/i18n/ru.json.mjs +0 -1
  37. package/build/i18n/ru.json.mjs.map +1 -1
  38. package/build/i18n/zh-HK.json +0 -1
  39. package/build/i18n/zh-HK.json.js +0 -1
  40. package/build/i18n/zh-HK.json.js.map +1 -1
  41. package/build/i18n/zh-HK.json.mjs +0 -1
  42. package/build/i18n/zh-HK.json.mjs.map +1 -1
  43. package/build/index.js +2 -4
  44. package/build/index.js.map +1 -1
  45. package/build/index.mjs +1 -2
  46. package/build/index.mjs.map +1 -1
  47. package/build/link/Link.js +8 -3
  48. package/build/link/Link.js.map +1 -1
  49. package/build/link/Link.mjs +8 -3
  50. package/build/link/Link.mjs.map +1 -1
  51. package/build/main.css +227 -13
  52. package/build/nudge/Nudge.js.map +1 -1
  53. package/build/nudge/Nudge.mjs.map +1 -1
  54. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js +2 -4
  55. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.js.map +1 -1
  56. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs +2 -4
  57. package/build/primitives/PrimitiveAnchor/src/PrimitiveAnchor.mjs.map +1 -1
  58. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js +3 -5
  59. package/build/primitives/PrimitiveButton/src/PrimitiveButton.js.map +1 -1
  60. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs +3 -5
  61. package/build/primitives/PrimitiveButton/src/PrimitiveButton.mjs.map +1 -1
  62. package/build/select/Select.js +2 -2
  63. package/build/select/Select.js.map +1 -1
  64. package/build/select/Select.mjs +1 -1
  65. package/build/styles/avatarLayout/AvatarLayout.css +12 -2
  66. package/build/styles/button/Button.css +207 -15
  67. package/build/styles/button/Button.vars.css +46 -0
  68. package/build/styles/button/LegacyButton.css +23 -0
  69. package/build/styles/main.css +227 -13
  70. package/build/styles/nudge/Nudge.css +0 -11
  71. package/build/types/avatarLayout/AvatarLayout.d.ts.map +1 -1
  72. package/build/types/button/Button.d.ts +2 -23
  73. package/build/types/button/Button.d.ts.map +1 -1
  74. package/build/types/button/Button.resolver.d.ts +33 -0
  75. package/build/types/button/Button.resolver.d.ts.map +1 -0
  76. package/build/types/button/Button.types.d.ts +67 -0
  77. package/build/types/button/Button.types.d.ts.map +1 -0
  78. package/build/types/button/LegacyButton.d.ts +30 -0
  79. package/build/types/button/LegacyButton.d.ts.map +1 -0
  80. package/build/types/button/index.d.ts +2 -2
  81. package/build/types/button/index.d.ts.map +1 -1
  82. package/build/types/index.d.ts +0 -2
  83. package/build/types/index.d.ts.map +1 -1
  84. package/build/types/link/Link.d.ts +2 -2
  85. package/build/types/link/Link.d.ts.map +1 -1
  86. package/build/types/nudge/Nudge.d.ts +1 -1
  87. package/build/types/nudge/Nudge.d.ts.map +1 -1
  88. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.d.ts.map +1 -1
  89. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts +6 -2
  90. package/build/types/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.d.ts.map +1 -1
  91. package/build/types/primitives/PrimitiveButton/src/PrimitiveButton.d.ts.map +1 -1
  92. package/build/types/test-utils/story-config.d.ts +1 -1
  93. package/build/types/test-utils/story-config.d.ts.map +1 -1
  94. package/build/types/uploadInput/uploadButton/getAllowedFileTypes.d.ts.map +1 -1
  95. package/build/upload/steps/completeStep/completeStep.js +2 -2
  96. package/build/upload/steps/completeStep/completeStep.js.map +1 -1
  97. package/build/upload/steps/completeStep/completeStep.mjs +1 -1
  98. package/build/upload/steps/processingStep/processingStep.js +2 -2
  99. package/build/upload/steps/processingStep/processingStep.js.map +1 -1
  100. package/build/upload/steps/processingStep/processingStep.mjs +1 -1
  101. package/build/uploadInput/UploadInput.js +3 -3
  102. package/build/uploadInput/UploadInput.js.map +1 -1
  103. package/build/uploadInput/UploadInput.mjs +1 -1
  104. package/build/uploadInput/uploadButton/getAllowedFileTypes.js +3 -23
  105. package/build/uploadInput/uploadButton/getAllowedFileTypes.js.map +1 -1
  106. package/build/uploadInput/uploadButton/getAllowedFileTypes.mjs +3 -23
  107. package/build/uploadInput/uploadButton/getAllowedFileTypes.mjs.map +1 -1
  108. package/package.json +3 -3
  109. package/src/alert/Alert.tests.story.tsx +1 -1
  110. package/src/avatarLayout/AvatarLayout.css +12 -2
  111. package/src/avatarLayout/AvatarLayout.less +19 -2
  112. package/src/avatarLayout/AvatarLayout.tsx +10 -3
  113. package/src/button/Button.css +207 -15
  114. package/src/button/Button.less +214 -14
  115. package/src/button/Button.resolver.tsx +73 -0
  116. package/src/button/Button.spec.tsx +188 -224
  117. package/src/button/Button.story.tsx +701 -135
  118. package/src/button/Button.tests.story.tsx +27 -0
  119. package/src/button/Button.tsx +99 -131
  120. package/src/button/Button.types.ts +94 -0
  121. package/src/button/Button.vars.css +46 -0
  122. package/src/button/Button.vars.less +60 -0
  123. package/src/button/LegacyButton.css +23 -0
  124. package/src/button/LegacyButton.less +24 -0
  125. package/src/button/LegacyButton.spec.tsx +147 -0
  126. package/src/button/LegacyButton.story.tsx +220 -0
  127. package/src/button/LegacyButton.tsx +160 -0
  128. package/src/button/index.ts +2 -3
  129. package/src/drawer/Drawer.rtl.spec.tsx +59 -0
  130. package/src/drawer/Drawer.spec.js +101 -0
  131. package/src/drawer/__snapshots__/Drawer.rtl.spec.tsx.snap +55 -0
  132. package/src/field/Field.story.tsx +1 -1
  133. package/src/flowNavigation/__snapshots__/FlowNavigation.spec.js.snap +1 -2
  134. package/src/i18n/ja.json +0 -1
  135. package/src/i18n/pt.json +0 -1
  136. package/src/i18n/ru.json +0 -1
  137. package/src/i18n/zh-HK.json +0 -1
  138. package/src/index.ts +0 -12
  139. package/src/inputs/SelectInput.story.tsx +1 -1
  140. package/src/label/Label.story.tsx +1 -1
  141. package/src/link/Link.tsx +15 -6
  142. package/src/main.css +227 -13
  143. package/src/main.less +1 -0
  144. package/src/nudge/Nudge.css +0 -11
  145. package/src/nudge/Nudge.less +0 -3
  146. package/src/nudge/Nudge.story.tsx +0 -10
  147. package/src/nudge/Nudge.tsx +1 -2
  148. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.tsx +2 -8
  149. package/src/primitives/PrimitiveAnchor/src/PrimitiveAnchor.types.ts +7 -2
  150. package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +1 -3
  151. package/src/primitives/PrimitiveButton/src/PrimitiveButton.tsx +4 -12
  152. package/src/primitives/PrimitiveButton/test/PrimitiveButton.spec.tsx +16 -13
  153. package/src/test-utils/Parameters.d.ts +9 -1
  154. package/src/test-utils/story-config.ts +10 -1
  155. package/src/uploadInput/UploadInput.tests.story.tsx +5 -5
  156. package/src/uploadInput/uploadButton/getAllowedFileTypes.spec.ts +0 -12
  157. package/src/uploadInput/uploadButton/getAllowedFileTypes.ts +7 -33
  158. package/build/table/Table.js +0 -166
  159. package/build/table/Table.js.map +0 -1
  160. package/build/table/Table.messages.js +0 -24
  161. package/build/table/Table.messages.js.map +0 -1
  162. package/build/table/Table.messages.mjs +0 -22
  163. package/build/table/Table.messages.mjs.map +0 -1
  164. package/build/table/Table.mjs +0 -164
  165. package/build/table/Table.mjs.map +0 -1
  166. package/build/table/TableCell.js +0 -86
  167. package/build/table/TableCell.js.map +0 -1
  168. package/build/table/TableCell.mjs +0 -84
  169. package/build/table/TableCell.mjs.map +0 -1
  170. package/build/table/TableHeader.js +0 -57
  171. package/build/table/TableHeader.js.map +0 -1
  172. package/build/table/TableHeader.mjs +0 -55
  173. package/build/table/TableHeader.mjs.map +0 -1
  174. package/build/table/TableRow.js +0 -85
  175. package/build/table/TableRow.js.map +0 -1
  176. package/build/table/TableRow.mjs +0 -83
  177. package/build/table/TableRow.mjs.map +0 -1
  178. package/build/table/TableStatusText.js +0 -54
  179. package/build/table/TableStatusText.js.map +0 -1
  180. package/build/table/TableStatusText.mjs +0 -52
  181. package/build/table/TableStatusText.mjs.map +0 -1
  182. package/src/button/__snapshots__/Button.spec.tsx.snap +0 -309
  183. package/src/drawer/Drawer.spec.tsx +0 -93
@@ -0,0 +1,220 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+ import { userEvent, within, fn, expect } from '@storybook/test';
3
+ import { useState } from 'react';
4
+
5
+ import Button from '.';
6
+
7
+ const withContainer = (Story: any) => (
8
+ <div
9
+ style={{
10
+ display: 'flex',
11
+ flexDirection: 'initial',
12
+ justifyContent: 'center',
13
+ flexFlow: 'column',
14
+ alignItems: 'center',
15
+ }}
16
+ >
17
+ <Story />
18
+ </div>
19
+ );
20
+
21
+ const meta: Meta<typeof Button> = {
22
+ component: Button,
23
+ title: 'Actions/Button/Legacy',
24
+ args: {
25
+ children: 'Button text',
26
+ loading: false,
27
+ type: undefined,
28
+ onClick: fn(),
29
+ onBlur: fn(),
30
+ onFocus: fn(),
31
+ href: 'https://example.com',
32
+ as: undefined,
33
+ },
34
+ argTypes: {
35
+ as: {
36
+ control: {
37
+ name: 'enum',
38
+ options: ['button', 'a'],
39
+ },
40
+ },
41
+ type: {
42
+ type: {
43
+ name: 'enum',
44
+ value: ['accent', 'positive', 'negative'],
45
+ },
46
+ },
47
+ size: {
48
+ type: {
49
+ name: 'enum',
50
+ value: ['xs', 'sm', 'md', 'lg'],
51
+ },
52
+ },
53
+ priority: {
54
+ type: {
55
+ name: 'enum',
56
+ value: ['primary', 'secondary', 'tertiary'],
57
+ },
58
+ },
59
+ sentiment: {
60
+ table: {
61
+ disable: true,
62
+ },
63
+ },
64
+ iconStart: {
65
+ table: {
66
+ disable: true,
67
+ },
68
+ },
69
+ iconEnd: {
70
+ table: {
71
+ disable: true,
72
+ },
73
+ },
74
+ avatars: {
75
+ table: {
76
+ disable: true,
77
+ },
78
+ },
79
+ },
80
+ tags: ['autodocs'],
81
+ decorators: [withContainer],
82
+ };
83
+
84
+ export default meta;
85
+
86
+ type Story = StoryObj<typeof Button>;
87
+
88
+ export const Basic: Story = {};
89
+
90
+ export const Secondary: Story = {
91
+ args: {
92
+ type: 'accent',
93
+ priority: 'secondary',
94
+ },
95
+ };
96
+
97
+ export const Tertiary: Story = {
98
+ args: {
99
+ type: 'accent',
100
+ priority: 'tertiary',
101
+ },
102
+ };
103
+
104
+ export const Negative: Story = {
105
+ args: {
106
+ type: 'negative',
107
+ priority: 'primary',
108
+ },
109
+ };
110
+
111
+ export const Loading: Story = {
112
+ args: {
113
+ loading: true,
114
+ },
115
+ };
116
+
117
+ export const Variants: Story = {
118
+ render: () => {
119
+ return (
120
+ <div className="d-flex flex-column p-b-2 align-items-start">
121
+ <div className="d-flex flex-row p-b-2" style={{ gap: 'var(--size-16)' }}>
122
+ <Button type="accent" priority="primary">
123
+ Primary Accent
124
+ </Button>
125
+ <Button type="accent" priority="secondary">
126
+ Secondary Accent
127
+ </Button>
128
+ <Button type="accent" priority="tertiary">
129
+ Tertiary Accent
130
+ </Button>
131
+ </div>
132
+ <div className="d-flex flex-row p-b-2" style={{ gap: 'var(--size-16)' }}>
133
+ <Button type="positive" priority="primary">
134
+ Primary Positive
135
+ </Button>
136
+ <Button type="positive" priority="secondary">
137
+ Secondary Accent
138
+ </Button>
139
+ </div>
140
+ <div className="d-flex flex-row flex- p-b-2" style={{ gap: 'var(--size-16)' }}>
141
+ <Button type="negative" priority="primary">
142
+ Primary Negative
143
+ </Button>
144
+ <Button type="negative" priority="secondary">
145
+ Secondary Negative
146
+ </Button>
147
+ </div>
148
+ <div className="d-flex flex-row p-b-1" style={{ gap: 'var(--size-16)' }}>
149
+ <Button type="accent" priority="primary" disabled>
150
+ Button Disabled
151
+ </Button>
152
+ <Button type="accent" priority="secondary" disabled>
153
+ Button Disabled
154
+ </Button>
155
+ <Button type="accent" priority="tertiary" disabled>
156
+ Button Disabled
157
+ </Button>
158
+ </div>
159
+ </div>
160
+ );
161
+ },
162
+ };
163
+
164
+ const wait = async (duration = 500) =>
165
+ new Promise<void>((resolve) => {
166
+ setTimeout(resolve, duration);
167
+ });
168
+
169
+ export const Focused: Story = {
170
+ play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
171
+ const canvas = within(canvasElement);
172
+ const button = canvas.getByRole('button');
173
+ await userEvent.tab();
174
+ await expect(button).toHaveFocus();
175
+ await expect(button).toHaveTextContent('Focused!');
176
+ },
177
+ render: function Render(args: React.ComponentProps<typeof Button>) {
178
+ const [focused, setFocused] = useState(false);
179
+
180
+ return (
181
+ <Button {...args} onFocus={() => setFocused(true)}>
182
+ {focused ? 'Focused!' : 'Button text'}
183
+ </Button>
184
+ );
185
+ },
186
+ };
187
+
188
+ export const SocialMedia: Story = {
189
+ render: () => {
190
+ return (
191
+ <>
192
+ <div className="m-b-2">
193
+ <button type="button" className="btn btn-google">
194
+ Login with Google
195
+ </button>
196
+ </div>
197
+ <div className="m-b-2">
198
+ <button type="button" className="btn btn-facebook">
199
+ Login with Facebook
200
+ </button>
201
+ </div>
202
+ <div className="m-b-2">
203
+ <button type="button" className="btn btn-lg btn-facebook">
204
+ Large Button
205
+ </button>
206
+ </div>
207
+ <div className="m-b-2">
208
+ <button type="button" className="btn btn-block btn-facebook">
209
+ Block Button
210
+ </button>
211
+ </div>
212
+ <div className="m-b-2">
213
+ <button type="button" className="btn btn-lg btn-block btn-facebook">
214
+ Large Block Button
215
+ </button>
216
+ </div>
217
+ </>
218
+ );
219
+ },
220
+ };
@@ -0,0 +1,160 @@
1
+ import { clsx } from 'clsx';
2
+ import { ElementType, forwardRef, MouseEvent } from 'react';
3
+ import { useIntl } from 'react-intl';
4
+
5
+ import {
6
+ Size,
7
+ ControlType,
8
+ Priority,
9
+ ControlTypeAccent,
10
+ ControlTypeNegative,
11
+ ControlTypePositive,
12
+ PriorityPrimary,
13
+ PrioritySecondary,
14
+ PriorityTertiary,
15
+ SizeExtraSmall,
16
+ SizeSmall,
17
+ SizeMedium,
18
+ SizeLarge,
19
+ } from '../common';
20
+ import ProcessIndicator from '../processIndicator';
21
+
22
+ import messages from '../i18n/commonMessages/Button.messages';
23
+ import { typeClassMap, priorityClassMap } from './classMap';
24
+ import { establishNewPriority, establishNewType, logDeprecationNotices } from './legacyUtils';
25
+ import { ButtonReferenceType } from './Button.types';
26
+
27
+ /** @deprecated */
28
+ type DeprecatedTypes = 'primary' | 'pay' | 'secondary' | 'danger' | 'link';
29
+
30
+ /** @deprecated */
31
+ type DeprecatedSizes = SizeExtraSmall;
32
+
33
+ type CommonProps = {
34
+ v2?: false;
35
+ block?: boolean;
36
+ disabled?: boolean;
37
+ loading?: boolean;
38
+ type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes | null;
39
+ priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary | null;
40
+ size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;
41
+ htmlType?: 'submit' | 'reset' | 'button';
42
+ };
43
+
44
+ type ButtonProps = CommonProps &
45
+ Omit<React.ComponentPropsWithRef<'button'>, 'type'> & {
46
+ as?: 'button';
47
+ };
48
+
49
+ type AnchorProps = CommonProps &
50
+ Omit<React.ComponentPropsWithRef<'a'>, 'type'> & {
51
+ as?: 'a';
52
+ href?: string;
53
+ };
54
+
55
+ export type LegacyButtonProps = ButtonProps | AnchorProps;
56
+
57
+ /**
58
+ * @deprecated make sure you use new Button component via `<Button v2 .. />` and new props
59
+ */
60
+ const LegacyButton = forwardRef<ButtonReferenceType, LegacyButtonProps>(
61
+ (
62
+ {
63
+ as: component = 'button',
64
+ block = false,
65
+ children,
66
+ className,
67
+ disabled,
68
+ loading = false,
69
+ priority = Priority.PRIMARY,
70
+ size = Size.MEDIUM,
71
+ type = ControlType.ACCENT,
72
+ onClick,
73
+ ...rest
74
+ }: LegacyButtonProps,
75
+ ref,
76
+ ) => {
77
+ const intl = useIntl();
78
+
79
+ logDeprecationNotices({ size, type });
80
+
81
+ const newType = establishNewType(type);
82
+ const newPriority = establishNewPriority(priority, type);
83
+
84
+ const classes = clsx(
85
+ `btn btn-${size}`,
86
+ `np-btn np-btn-${size}`,
87
+ {
88
+ 'btn-loading': loading,
89
+ 'btn-block np-btn-block': block,
90
+ disabled,
91
+ },
92
+ // @ts-expect-error fix when refactor `typeClassMap` to TypeScript
93
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
94
+ typeClassMap[newType],
95
+ // @ts-expect-error fix when refactor `typeClassMap` to TypeScript
96
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
97
+ priorityClassMap[newPriority],
98
+ className,
99
+ );
100
+
101
+ function processIndicatorSize() {
102
+ return ['sm', 'xs'].includes(size) ? 'xxs' : 'xs';
103
+ }
104
+
105
+ const Element = (component as ElementType) ?? 'button';
106
+ let props;
107
+
108
+ if (Element === 'button') {
109
+ const { htmlType = 'button', ...restProps } = rest as ButtonProps;
110
+ props = {
111
+ ...restProps,
112
+ disabled,
113
+ 'aria-disabled': loading,
114
+ type: htmlType,
115
+ };
116
+ } else {
117
+ props = {
118
+ ...rest,
119
+ 'aria-disabled': loading,
120
+ } as AnchorProps;
121
+ }
122
+
123
+ /**
124
+ * Ensures that the button cannot be activated in loading or disabled mode,
125
+ * when `aria-disabled` might be used over the `disabled` HTML attribute
126
+ */
127
+ const handleClick =
128
+ (handler: LegacyButtonProps['onClick']) =>
129
+ (event: MouseEvent<HTMLButtonElement> & MouseEvent<HTMLAnchorElement>) => {
130
+ if (disabled || loading) {
131
+ event.preventDefault();
132
+ } else if (typeof handler === 'function') {
133
+ handler(event);
134
+ }
135
+ };
136
+
137
+ return (
138
+ <Element
139
+ ref={ref as React.Ref<ButtonReferenceType>}
140
+ className={classes}
141
+ onClick={handleClick(onClick)}
142
+ {...props}
143
+ aria-live={loading ? 'polite' : 'off'}
144
+ aria-busy={loading}
145
+ aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}
146
+ >
147
+ {children}
148
+ {loading && (
149
+ <ProcessIndicator
150
+ size={processIndicatorSize()}
151
+ className="btn-loader"
152
+ data-testid="ButtonProgressIndicator"
153
+ />
154
+ )}
155
+ </Element>
156
+ );
157
+ },
158
+ );
159
+
160
+ export default LegacyButton;
@@ -1,3 +1,2 @@
1
- export { default } from './Button';
2
-
3
- export type { Props as ButtonProps } from './Button';
1
+ export { default } from './Button.resolver';
2
+ export type { ButtonProps } from './Button.resolver';
@@ -0,0 +1,59 @@
1
+ import { DimmerProps } from '../dimmer';
2
+ import { SlidingPanelProps } from '../slidingPanel';
3
+ import { mockMatchMedia, render, screen, userEvent } from '../test-utils';
4
+
5
+ import Drawer from './Drawer';
6
+
7
+ mockMatchMedia();
8
+
9
+ jest.mock(
10
+ '../dimmer',
11
+ () =>
12
+ function Dimmer({ open, children }: DimmerProps) {
13
+ return open ? <div className="dimmer">{children}</div> : null;
14
+ },
15
+ );
16
+
17
+ jest.mock(
18
+ '../slidingPanel',
19
+ () =>
20
+ function SlidingPanel({ open, children }: SlidingPanelProps) {
21
+ return open ? <div className="sliding-panel">{children}</div> : null;
22
+ },
23
+ );
24
+
25
+ describe('Drawer', () => {
26
+ const props = {
27
+ onClose: jest.fn(),
28
+ open: true,
29
+ };
30
+
31
+ afterEach(() => {
32
+ jest.clearAllMocks();
33
+ });
34
+
35
+ it('renders content when open', () => {
36
+ const { container } = render(<Drawer {...props}>content</Drawer>);
37
+
38
+ expect(container).toMatchSnapshot();
39
+ });
40
+
41
+ it("doesn't render content when closed", () => {
42
+ const { container } = render(
43
+ <Drawer {...props} open={false}>
44
+ content
45
+ </Drawer>,
46
+ );
47
+
48
+ expect(container).toMatchSnapshot();
49
+ });
50
+
51
+ it('calls onClose when user clicks close button', async () => {
52
+ render(<Drawer {...props}>content</Drawer>);
53
+ expect(props.onClose).not.toHaveBeenCalled();
54
+ await userEvent.click(getCloseButton());
55
+ expect(props.onClose).toHaveBeenCalledTimes(1);
56
+ });
57
+
58
+ const getCloseButton = () => screen.getByLabelText('Close');
59
+ });
@@ -0,0 +1,101 @@
1
+ import { mount } from 'enzyme';
2
+
3
+ import { mockMatchMedia } from '../test-utils';
4
+ import Title from '../title/Title';
5
+
6
+ import Drawer from '.';
7
+
8
+ mockMatchMedia();
9
+ jest.mock('../common');
10
+ jest.useFakeTimers();
11
+
12
+ jest.mock(
13
+ '../dimmer',
14
+ () =>
15
+ function Dimmer({ open, children }) {
16
+ return open ? <div className="dimmer">{children}</div> : null;
17
+ },
18
+ );
19
+
20
+ jest.mock(
21
+ '../slidingPanel',
22
+ () =>
23
+ function SlidingPanel({ open, children }) {
24
+ return open ? <div className="sliding-panel">{children}</div> : null;
25
+ },
26
+ );
27
+
28
+ const defaultLocale = 'en-GB';
29
+
30
+ jest.mock('react-intl', () => ({
31
+ injectIntl: (Component) =>
32
+ function InjectedComponent(props) {
33
+ return <Component {...props} intl={{ locale: defaultLocale }} />;
34
+ },
35
+ useIntl: () => ({ locale: defaultLocale, formatMessage: (id) => String(id) }),
36
+ defineMessages: (translations) => translations,
37
+ }));
38
+
39
+ describe('Drawer', () => {
40
+ let component;
41
+ const props = {
42
+ open: true,
43
+ position: 'left',
44
+ onClose: jest.fn(),
45
+ children: null,
46
+ headerTitle: null,
47
+ footerContent: null,
48
+ };
49
+
50
+ beforeEach(() => {
51
+ component = mount(<Drawer {...props} />);
52
+ });
53
+
54
+ afterEach(() => {
55
+ jest.clearAllMocks();
56
+ component.unmount();
57
+ });
58
+
59
+ it('renders drawer header if title is provided', () => {
60
+ expect(component.find('.np-drawer-header--title')).toHaveLength(0);
61
+ component.setProps({ headerTitle: 'A title' });
62
+ expect(component.find(Title)).toHaveLength(1);
63
+ expect(component.find(Title).props().children).toBe('A title');
64
+ });
65
+
66
+ it('renders header with or without borders', () => {
67
+ expect(component.find('.np-drawer-header--withborder')).toHaveLength(0);
68
+ component.setProps({ headerTitle: 'A title' });
69
+ expect(component.find('.np-drawer-header--withborder')).toHaveLength(1);
70
+ });
71
+
72
+ it('renders content if children are provided', () => {
73
+ expect(component.find('.np-drawer-content')).toHaveLength(0);
74
+ component.setProps({ children: 'SomeChildren' });
75
+ expect(component.find('.np-drawer-content')).toHaveLength(1);
76
+ });
77
+
78
+ it('renders drawer footer if footerContent is provided', () => {
79
+ expect(component.find('.np-drawer-footer')).toHaveLength(0);
80
+ component.setProps({ footerContent: 'SomeContent' });
81
+ expect(component.find('.np-drawer-footer')).toHaveLength(1);
82
+ });
83
+
84
+ it('passes onUnmount to Dimmer onExited prop', () => {
85
+ const onUnmount = jest.fn();
86
+ component.setProps({ onUnmount });
87
+ component.setProps({ open: true });
88
+ expect(component.find('Dimmer').prop('onExited')).toBe(onUnmount);
89
+ });
90
+
91
+ it('calls onUnmount when the component unmounts', () => {
92
+ const onUnmount = jest.fn();
93
+ component.setProps({ onUnmount });
94
+ component.setProps({ open: true });
95
+ expect(onUnmount).not.toHaveBeenCalled();
96
+ jest.runAllTimers();
97
+ component.setProps({ open: false });
98
+ component.find('Dimmer').prop('onExited')();
99
+ expect(onUnmount).toHaveBeenCalledTimes(1);
100
+ });
101
+ });
@@ -0,0 +1,55 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`Drawer doesn't render content when closed 1`] = `<div />`;
4
+
5
+ exports[`Drawer renders content when open 1`] = `
6
+ <div>
7
+ <div
8
+ class="dimmer"
9
+ >
10
+ <div
11
+ class="sliding-panel"
12
+ >
13
+ <div
14
+ aria-modal="true"
15
+ class="np-drawer"
16
+ role="dialog"
17
+ >
18
+ <div
19
+ class="np-drawer-header"
20
+ >
21
+ <button
22
+ aria-label="Close"
23
+ class="np-close-button close btn-link text-no-decoration np-close-button--large"
24
+ type="button"
25
+ >
26
+ <span
27
+ class="tw-icon tw-icon-cross "
28
+ data-testid="cross-icon"
29
+ >
30
+ <svg
31
+ aria-hidden="true"
32
+ fill="currentColor"
33
+ focusable="false"
34
+ height="24"
35
+ role="none"
36
+ viewBox="0 0 24 24"
37
+ width="24"
38
+ >
39
+ <path
40
+ d="m19.629 5.915-1.2-1.2-6.257 6.257-6.258-6.257-1.2 1.2 6.258 6.257-6.258 6.257 1.2 1.2 6.258-6.257 6.257 6.257 1.2-1.2-6.258-6.257 6.258-6.257Z"
41
+ />
42
+ </svg>
43
+ </span>
44
+ </button>
45
+ </div>
46
+ <div
47
+ class="np-drawer-content"
48
+ >
49
+ content
50
+ </div>
51
+ </div>
52
+ </div>
53
+ </div>
54
+ </div>
55
+ `;
@@ -12,7 +12,7 @@ import Info from '../info';
12
12
 
13
13
  export default {
14
14
  component: Field,
15
- title: 'Field',
15
+ title: 'Forms/Field',
16
16
  tags: ['autodocs'],
17
17
  argTypes: {
18
18
  messageIconLabel: {
@@ -9,10 +9,9 @@ exports[`FlowNavigation on mobile renders as expected 1`] = `
9
9
  class="np-flow-header d-flex flex-wrap align-items-center justify-content-between flex__item--12 np-flow-navigation__content p-x-3 np-flow-navigation--xs-max"
10
10
  >
11
11
  <button
12
- aria-disabled="false"
13
12
  aria-label="back to previous step"
14
13
  aria-live="off"
15
- class="wds-Button np-circle d-flex align-items-center justify-content-center np-icon-button np-icon-button-tertiary-default"
14
+ class="np-circle d-flex align-items-center justify-content-center np-icon-button np-icon-button-tertiary-default"
16
15
  style="--circle-size: 40px; --circle-icon-size: 20px; --circle-font-size: 18px;"
17
16
  type="button"
18
17
  >
package/src/i18n/ja.json CHANGED
@@ -54,7 +54,6 @@
54
54
  "neptune.UploadButton.allFileTypes": "すべてのファイル種類",
55
55
  "neptune.UploadButton.dropFiles": "ファイルをドロップしてアップロードする",
56
56
  "neptune.UploadButton.instructions": "{fileTypes}、{size}MB以下",
57
- "neptune.UploadButton.maximumFiles": "最大ファイル数:{maxFiles}個",
58
57
  "neptune.UploadButton.uploadFile": "ファイルをアップロードする",
59
58
  "neptune.UploadButton.uploadFiles": "ファイルをアップロードする",
60
59
  "neptune.UploadInput.deleteModalBody": "このファイルを削除すると、当社のシステムからも削除されます。",
package/src/i18n/pt.json CHANGED
@@ -54,7 +54,6 @@
54
54
  "neptune.UploadButton.allFileTypes": "Todos os tipos de arquivos",
55
55
  "neptune.UploadButton.dropFiles": "Arraste o arquivo para iniciar o envio",
56
56
  "neptune.UploadButton.instructions": "{fileTypes}, com menos de {size}MB",
57
- "neptune.UploadButton.maximumFiles": "Máximo de {maxFiles} arquivos.",
58
57
  "neptune.UploadButton.uploadFile": "Enviar arquivo",
59
58
  "neptune.UploadButton.uploadFiles": "Enviar arquivos",
60
59
  "neptune.UploadInput.deleteModalBody": "Se você remover este arquivo, ele será permanentemente excluído do nosso sistema.",
package/src/i18n/ru.json CHANGED
@@ -54,7 +54,6 @@
54
54
  "neptune.UploadButton.allFileTypes": "Все типы файлов",
55
55
  "neptune.UploadButton.dropFiles": "Перетащите файл, чтобы начать загрузку",
56
56
  "neptune.UploadButton.instructions": "{fileTypes}, не превышающий {size} MB",
57
- "neptune.UploadButton.maximumFiles": "Макс. количество файлов: {maxFiles}.",
58
57
  "neptune.UploadButton.uploadFile": "Загрузить файл",
59
58
  "neptune.UploadButton.uploadFiles": "Загрузить файлы",
60
59
  "neptune.UploadInput.deleteModalBody": "Удаление этого файла приведет к его удалению из нашей системы.",
@@ -54,7 +54,6 @@
54
54
  "neptune.UploadButton.allFileTypes": "所有檔案類型",
55
55
  "neptune.UploadButton.dropFiles": "拖放檔案以開始上載",
56
56
  "neptune.UploadButton.instructions": "{fileTypes},小於{size}MB",
57
- "neptune.UploadButton.maximumFiles": "最多{maxFiles}個檔案。",
58
57
  "neptune.UploadButton.uploadFile": "上載檔案",
59
58
  "neptune.UploadButton.uploadFiles": "上載檔案",
60
59
  "neptune.UploadInput.deleteModalBody": "移除此檔案會把它從我們的系統中刪除。",
package/src/index.ts CHANGED
@@ -96,17 +96,6 @@ export type { UploadProps } from './upload';
96
96
  export type { UploadError, UploadResponse, UploadedFile } from './uploadInput/types';
97
97
  export type { WithIdProps } from './withId';
98
98
  export type { IconButtonProps } from './iconButton';
99
- export type {
100
- TableProps,
101
- TableRowType,
102
- TableRowClickableType,
103
- TableHeaderType,
104
- TableCellLeading,
105
- TableCellText,
106
- TableCellCurrency,
107
- TableCellStatus,
108
- TableCellType,
109
- } from './table';
110
99
 
111
100
  /**
112
101
  * Components
@@ -207,7 +196,6 @@ export { default as Tooltip } from './tooltip';
207
196
  export { default as Typeahead } from './typeahead';
208
197
  export { default as Upload } from './upload';
209
198
  export { default as UploadInput } from './uploadInput';
210
- export { default as Table } from './table';
211
199
 
212
200
  /**
213
201
  * Hooks