@transferwise/components 46.103.1 → 46.105.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 (250) hide show
  1. package/build/header/Header.js +60 -43
  2. package/build/header/Header.js.map +1 -1
  3. package/build/header/Header.mjs +57 -43
  4. package/build/header/Header.mjs.map +1 -1
  5. package/build/i18n/cs.json +2 -0
  6. package/build/i18n/cs.json.js +2 -0
  7. package/build/i18n/cs.json.js.map +1 -1
  8. package/build/i18n/cs.json.mjs +2 -0
  9. package/build/i18n/cs.json.mjs.map +1 -1
  10. package/build/i18n/es.json +2 -0
  11. package/build/i18n/es.json.js +2 -0
  12. package/build/i18n/es.json.js.map +1 -1
  13. package/build/i18n/es.json.mjs +2 -0
  14. package/build/i18n/es.json.mjs.map +1 -1
  15. package/build/i18n/th.json +2 -0
  16. package/build/i18n/th.json.js +2 -0
  17. package/build/i18n/th.json.js.map +1 -1
  18. package/build/i18n/th.json.mjs +2 -0
  19. package/build/i18n/th.json.mjs.map +1 -1
  20. package/build/index.js +3 -1
  21. package/build/index.js.map +1 -1
  22. package/build/index.mjs +2 -1
  23. package/build/index.mjs.map +1 -1
  24. package/build/inputs/SelectInput.js +1 -1
  25. package/build/inputs/SelectInput.js.map +1 -1
  26. package/build/inputs/SelectInput.mjs +1 -1
  27. package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.js +56 -0
  28. package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.js.map +1 -0
  29. package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.mjs +54 -0
  30. package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.mjs.map +1 -0
  31. package/build/listItem/AvatarLayout/ListItemAvatarLayout.js +23 -0
  32. package/build/listItem/AvatarLayout/ListItemAvatarLayout.js.map +1 -0
  33. package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs +21 -0
  34. package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs.map +1 -0
  35. package/build/listItem/AvatarView/ListItemAvatarView.js +23 -0
  36. package/build/listItem/AvatarView/ListItemAvatarView.js.map +1 -0
  37. package/build/listItem/AvatarView/ListItemAvatarView.mjs +21 -0
  38. package/build/listItem/AvatarView/ListItemAvatarView.mjs.map +1 -0
  39. package/build/listItem/Button/ListItemButton.js +43 -0
  40. package/build/listItem/Button/ListItemButton.js.map +1 -0
  41. package/build/listItem/Button/ListItemButton.mjs +41 -0
  42. package/build/listItem/Button/ListItemButton.mjs.map +1 -0
  43. package/build/listItem/Checkbox/ListItemCheckbox.js +30 -0
  44. package/build/listItem/Checkbox/ListItemCheckbox.js.map +1 -0
  45. package/build/listItem/Checkbox/ListItemCheckbox.mjs +28 -0
  46. package/build/listItem/Checkbox/ListItemCheckbox.mjs.map +1 -0
  47. package/build/listItem/IconButton/ListItemIconButton.js +56 -0
  48. package/build/listItem/IconButton/ListItemIconButton.js.map +1 -0
  49. package/build/listItem/IconButton/ListItemIconButton.mjs +54 -0
  50. package/build/listItem/IconButton/ListItemIconButton.mjs.map +1 -0
  51. package/build/listItem/Image/ListItemImage.js +31 -0
  52. package/build/listItem/Image/ListItemImage.js.map +1 -0
  53. package/build/listItem/Image/ListItemImage.mjs +29 -0
  54. package/build/listItem/Image/ListItemImage.mjs.map +1 -0
  55. package/build/listItem/ListItem.js +311 -0
  56. package/build/listItem/ListItem.js.map +1 -0
  57. package/build/listItem/ListItem.mjs +306 -0
  58. package/build/listItem/ListItem.mjs.map +1 -0
  59. package/build/listItem/ListItemContext.js +8 -0
  60. package/build/listItem/ListItemContext.js.map +1 -0
  61. package/build/listItem/ListItemContext.mjs +6 -0
  62. package/build/listItem/ListItemContext.mjs.map +1 -0
  63. package/build/listItem/Navigation/ListItemNavigation.js +44 -0
  64. package/build/listItem/Navigation/ListItemNavigation.js.map +1 -0
  65. package/build/listItem/Navigation/ListItemNavigation.mjs +42 -0
  66. package/build/listItem/Navigation/ListItemNavigation.mjs.map +1 -0
  67. package/build/listItem/Prompt/ListItemPrompt.js +59 -0
  68. package/build/listItem/Prompt/ListItemPrompt.js.map +1 -0
  69. package/build/listItem/Prompt/ListItemPrompt.mjs +54 -0
  70. package/build/listItem/Prompt/ListItemPrompt.mjs.map +1 -0
  71. package/build/listItem/Radio/ListItemRadio.js +30 -0
  72. package/build/listItem/Radio/ListItemRadio.js.map +1 -0
  73. package/build/listItem/Radio/ListItemRadio.mjs +28 -0
  74. package/build/listItem/Radio/ListItemRadio.mjs.map +1 -0
  75. package/build/listItem/Switch/ListItemSwitch.js +30 -0
  76. package/build/listItem/Switch/ListItemSwitch.js.map +1 -0
  77. package/build/listItem/Switch/ListItemSwitch.mjs +28 -0
  78. package/build/listItem/Switch/ListItemSwitch.mjs.map +1 -0
  79. package/build/listItem/useListItemControl.js +22 -0
  80. package/build/listItem/useListItemControl.js.map +1 -0
  81. package/build/listItem/useListItemControl.mjs +20 -0
  82. package/build/listItem/useListItemControl.mjs.map +1 -0
  83. package/build/listItem/useListItemMedia.js +21 -0
  84. package/build/listItem/useListItemMedia.js.map +1 -0
  85. package/build/listItem/useListItemMedia.mjs +19 -0
  86. package/build/listItem/useListItemMedia.mjs.map +1 -0
  87. package/build/main.css +794 -14
  88. package/build/styles/header/Header.css +21 -14
  89. package/build/styles/listItem/ListItem.css +773 -0
  90. package/build/styles/listItem/ListItem.grid.css +370 -0
  91. package/build/styles/listItem/Prompt/ListItemPrompt.css +157 -0
  92. package/build/styles/main.css +794 -14
  93. package/build/title/Title.js +10 -4
  94. package/build/title/Title.js.map +1 -1
  95. package/build/title/Title.mjs +6 -4
  96. package/build/title/Title.mjs.map +1 -1
  97. package/build/types/header/Header.d.ts +27 -11
  98. package/build/types/header/Header.d.ts.map +1 -1
  99. package/build/types/header/index.d.ts +1 -0
  100. package/build/types/header/index.d.ts.map +1 -1
  101. package/build/types/index.d.ts +3 -0
  102. package/build/types/index.d.ts.map +1 -1
  103. package/build/types/listItem/AdditionalInfo/ListItemAdditionalInfo.d.ts +15 -0
  104. package/build/types/listItem/AdditionalInfo/ListItemAdditionalInfo.d.ts.map +1 -0
  105. package/build/types/listItem/AdditionalInfo/index.d.ts +3 -0
  106. package/build/types/listItem/AdditionalInfo/index.d.ts.map +1 -0
  107. package/build/types/listItem/AvatarLayout/ListItemAvatarLayout.d.ts +18 -0
  108. package/build/types/listItem/AvatarLayout/ListItemAvatarLayout.d.ts.map +1 -0
  109. package/build/types/listItem/AvatarLayout/index.d.ts +3 -0
  110. package/build/types/listItem/AvatarLayout/index.d.ts.map +1 -0
  111. package/build/types/listItem/AvatarView/ListItemAvatarView.d.ts +16 -0
  112. package/build/types/listItem/AvatarView/ListItemAvatarView.d.ts.map +1 -0
  113. package/build/types/listItem/AvatarView/index.d.ts +3 -0
  114. package/build/types/listItem/AvatarView/index.d.ts.map +1 -0
  115. package/build/types/listItem/Button/ListItemButton.d.ts +20 -0
  116. package/build/types/listItem/Button/ListItemButton.d.ts.map +1 -0
  117. package/build/types/listItem/Button/index.d.ts +3 -0
  118. package/build/types/listItem/Button/index.d.ts.map +1 -0
  119. package/build/types/listItem/Checkbox/ListItemCheckbox.d.ts +14 -0
  120. package/build/types/listItem/Checkbox/ListItemCheckbox.d.ts.map +1 -0
  121. package/build/types/listItem/Checkbox/index.d.ts +3 -0
  122. package/build/types/listItem/Checkbox/index.d.ts.map +1 -0
  123. package/build/types/listItem/IconButton/ListItemIconButton.d.ts +18 -0
  124. package/build/types/listItem/IconButton/ListItemIconButton.d.ts.map +1 -0
  125. package/build/types/listItem/IconButton/index.d.ts +3 -0
  126. package/build/types/listItem/IconButton/index.d.ts.map +1 -0
  127. package/build/types/listItem/Image/ListItemImage.d.ts +25 -0
  128. package/build/types/listItem/Image/ListItemImage.d.ts.map +1 -0
  129. package/build/types/listItem/Image/index.d.ts +3 -0
  130. package/build/types/listItem/Image/index.d.ts.map +1 -0
  131. package/build/types/listItem/ListItem.d.ts +111 -0
  132. package/build/types/listItem/ListItem.d.ts.map +1 -0
  133. package/build/types/listItem/ListItemContext.d.ts +21 -0
  134. package/build/types/listItem/ListItemContext.d.ts.map +1 -0
  135. package/build/types/listItem/Navigation/ListItemNavigation.d.ts +15 -0
  136. package/build/types/listItem/Navigation/ListItemNavigation.d.ts.map +1 -0
  137. package/build/types/listItem/Navigation/index.d.ts +3 -0
  138. package/build/types/listItem/Navigation/index.d.ts.map +1 -0
  139. package/build/types/listItem/Prompt/ListItemPrompt.d.ts +16 -0
  140. package/build/types/listItem/Prompt/ListItemPrompt.d.ts.map +1 -0
  141. package/build/types/listItem/Prompt/index.d.ts +3 -0
  142. package/build/types/listItem/Prompt/index.d.ts.map +1 -0
  143. package/build/types/listItem/Radio/ListItemRadio.d.ts +14 -0
  144. package/build/types/listItem/Radio/ListItemRadio.d.ts.map +1 -0
  145. package/build/types/listItem/Radio/index.d.ts +3 -0
  146. package/build/types/listItem/Radio/index.d.ts.map +1 -0
  147. package/build/types/listItem/Switch/ListItemSwitch.d.ts +14 -0
  148. package/build/types/listItem/Switch/ListItemSwitch.d.ts.map +1 -0
  149. package/build/types/listItem/Switch/index.d.ts +3 -0
  150. package/build/types/listItem/Switch/index.d.ts.map +1 -0
  151. package/build/types/listItem/_stories/helpers.d.ts +27 -0
  152. package/build/types/listItem/_stories/helpers.d.ts.map +1 -0
  153. package/build/types/listItem/_stories/subcomponents.d.ts +18 -0
  154. package/build/types/listItem/_stories/subcomponents.d.ts.map +1 -0
  155. package/build/types/listItem/index.d.ts +14 -0
  156. package/build/types/listItem/index.d.ts.map +1 -0
  157. package/build/types/listItem/test-utils.d.ts +7 -0
  158. package/build/types/listItem/test-utils.d.ts.map +1 -0
  159. package/build/types/listItem/useListItemControl.d.ts +5 -0
  160. package/build/types/listItem/useListItemControl.d.ts.map +1 -0
  161. package/build/types/listItem/useListItemMedia.d.ts +6 -0
  162. package/build/types/listItem/useListItemMedia.d.ts.map +1 -0
  163. package/build/types/title/Title.d.ts +4 -5
  164. package/build/types/title/Title.d.ts.map +1 -1
  165. package/package.json +3 -3
  166. package/src/button/Button.spec.tsx +25 -1
  167. package/src/button/Button.story.tsx +1 -0
  168. package/src/header/Header.accessibility.docs.mdx +85 -0
  169. package/src/header/Header.css +21 -14
  170. package/src/header/Header.less +17 -10
  171. package/src/header/Header.spec.tsx +68 -50
  172. package/src/header/Header.story.tsx +190 -36
  173. package/src/header/Header.tsx +96 -65
  174. package/src/header/index.ts +1 -0
  175. package/src/i18n/cs.json +2 -0
  176. package/src/i18n/es.json +2 -0
  177. package/src/i18n/th.json +2 -0
  178. package/src/iconButton/iconButton.spec.tsx +31 -0
  179. package/src/index.ts +16 -0
  180. package/src/legacylistItem/LegacyListItem.story.tsx +1 -1
  181. package/src/legacylistItem/LegacyListItem.tests.story.tsx +2 -1
  182. package/src/list/List.story.tsx +13 -3
  183. package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.spec.tsx +56 -0
  184. package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.story.tsx +198 -0
  185. package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.tsx +36 -0
  186. package/src/listItem/AdditionalInfo/index.ts +2 -0
  187. package/src/listItem/AvatarLayout/ListItemAvatarLayout.spec.tsx +59 -0
  188. package/src/listItem/AvatarLayout/ListItemAvatarLayout.story.tsx +124 -0
  189. package/src/listItem/AvatarLayout/ListItemAvatarLayout.tsx +27 -0
  190. package/src/listItem/AvatarLayout/index.ts +2 -0
  191. package/src/listItem/AvatarView/ListItemAvatarView.spec.tsx +75 -0
  192. package/src/listItem/AvatarView/ListItemAvatarView.story.tsx +339 -0
  193. package/src/listItem/AvatarView/ListItemAvatarView.tsx +27 -0
  194. package/src/listItem/AvatarView/index.ts +2 -0
  195. package/src/listItem/Button/ListItemButton.spec.tsx +90 -0
  196. package/src/listItem/Button/ListItemButton.story.tsx +473 -0
  197. package/src/listItem/Button/ListItemButton.tsx +56 -0
  198. package/src/listItem/Button/index.ts +2 -0
  199. package/src/listItem/Checkbox/ListItemCheckbox.spec.tsx +82 -0
  200. package/src/listItem/Checkbox/ListItemCheckbox.story.tsx +128 -0
  201. package/src/listItem/Checkbox/ListItemCheckbox.tsx +33 -0
  202. package/src/listItem/Checkbox/index.ts +2 -0
  203. package/src/listItem/IconButton/ListItemIconButton.spec.tsx +131 -0
  204. package/src/listItem/IconButton/ListItemIconButton.story.tsx +284 -0
  205. package/src/listItem/IconButton/ListItemIconButton.tsx +73 -0
  206. package/src/listItem/IconButton/index.ts +2 -0
  207. package/src/listItem/Image/ListItemImage.spec.tsx +30 -0
  208. package/src/listItem/Image/ListItemImage.story.tsx +80 -0
  209. package/src/listItem/Image/ListItemImage.tsx +46 -0
  210. package/src/listItem/Image/index.ts +2 -0
  211. package/src/listItem/ListItem.css +773 -0
  212. package/src/listItem/ListItem.grid.css +370 -0
  213. package/src/listItem/ListItem.grid.less +622 -0
  214. package/src/listItem/ListItem.less +291 -0
  215. package/src/listItem/ListItem.spec.tsx +1511 -0
  216. package/src/listItem/ListItem.tsx +440 -0
  217. package/src/listItem/ListItemContext.tsx +26 -0
  218. package/src/listItem/Navigation/ListItemNavigation.spec.tsx +67 -0
  219. package/src/listItem/Navigation/ListItemNavigation.story.tsx +114 -0
  220. package/src/listItem/Navigation/ListItemNavigation.tsx +39 -0
  221. package/src/listItem/Navigation/index.ts +2 -0
  222. package/src/listItem/Prompt/ListItemPrompt.css +157 -0
  223. package/src/listItem/Prompt/ListItemPrompt.less +134 -0
  224. package/src/listItem/Prompt/ListItemPrompt.spec.tsx +36 -0
  225. package/src/listItem/Prompt/ListItemPrompt.story.tsx +204 -0
  226. package/src/listItem/Prompt/ListItemPrompt.tsx +32 -0
  227. package/src/listItem/Prompt/index.ts +2 -0
  228. package/src/listItem/Radio/ListItemRadio.spec.tsx +66 -0
  229. package/src/listItem/Radio/ListItemRadio.story.tsx +111 -0
  230. package/src/listItem/Radio/ListItemRadio.tsx +33 -0
  231. package/src/listItem/Radio/index.ts +2 -0
  232. package/src/listItem/Switch/ListItemSwitch.spec.tsx +47 -0
  233. package/src/listItem/Switch/ListItemSwitch.story.tsx +79 -0
  234. package/src/listItem/Switch/ListItemSwitch.tsx +33 -0
  235. package/src/listItem/Switch/index.ts +2 -0
  236. package/src/listItem/_stories/ListItem.focus.test.story.tsx +265 -0
  237. package/src/listItem/_stories/ListItem.layout.test.story.tsx +374 -0
  238. package/src/listItem/_stories/ListItem.scenarios.story.tsx +228 -0
  239. package/src/listItem/_stories/ListItem.story.tsx +774 -0
  240. package/src/listItem/_stories/ListItem.variants.test.story.tsx +274 -0
  241. package/src/listItem/_stories/helpers.tsx +53 -0
  242. package/src/listItem/_stories/subcomponents.tsx +141 -0
  243. package/src/listItem/index.ts +14 -0
  244. package/src/listItem/test-utils.tsx +33 -0
  245. package/src/listItem/useListItemControl.tsx +18 -0
  246. package/src/listItem/useListItemMedia.tsx +16 -0
  247. package/src/main.css +794 -14
  248. package/src/main.less +1 -0
  249. package/src/primitives/PrimitiveAnchor/test/PrimitiveAnchor.spec.tsx +15 -4
  250. package/src/title/Title.tsx +25 -12
@@ -0,0 +1,75 @@
1
+ import { mockMatchMedia, render, screen } from '../../test-utils';
2
+ import { ListItem, type ListItemProps } from '../ListItem';
3
+
4
+ mockMatchMedia();
5
+
6
+ const baseProps = {
7
+ title: 'Test Title',
8
+ };
9
+
10
+ const avatarProps = {
11
+ imgSrc: 'avatar.jpg',
12
+ profileName: 'User Avatar',
13
+ };
14
+
15
+ const renderWithMedia = (media: ListItemProps['media']) =>
16
+ render(<ListItem title={baseProps.title} media={media} />);
17
+
18
+ describe('ListItem.AvatarView', () => {
19
+ it('applies custom className alongside default class', () => {
20
+ const { container } = renderWithMedia(
21
+ <ListItem.AvatarView
22
+ className="custom-class"
23
+ imgSrc={avatarProps.imgSrc}
24
+ profileName={avatarProps.profileName}
25
+ />,
26
+ );
27
+
28
+ expect(container.querySelector('.custom-class')).toBeInTheDocument();
29
+ });
30
+
31
+ it('renders avatar with correct image src', () => {
32
+ renderWithMedia(
33
+ <ListItem.AvatarView imgSrc={avatarProps.imgSrc} profileName={avatarProps.profileName} />,
34
+ );
35
+
36
+ expect(screen.getByRole('presentation')).toHaveAttribute('src', avatarProps.imgSrc);
37
+ });
38
+
39
+ it('renders without image when no imgSrc provided', () => {
40
+ renderWithMedia(<ListItem.AvatarView profileName={avatarProps.profileName} />);
41
+ expect(screen.queryByRole('img')).not.toBeInTheDocument();
42
+ });
43
+
44
+ it('supports accessibility props', () => {
45
+ renderWithMedia(
46
+ <ListItem.AvatarView
47
+ imgSrc={avatarProps.imgSrc}
48
+ profileName={avatarProps.profileName}
49
+ aria-label="Profile picture"
50
+ />,
51
+ );
52
+
53
+ expect(screen.getByLabelText('Profile picture')).toBeInTheDocument();
54
+ });
55
+
56
+ it('passes through role attribute', () => {
57
+ renderWithMedia(
58
+ <ListItem.AvatarView
59
+ imgSrc={avatarProps.imgSrc}
60
+ profileName={avatarProps.profileName}
61
+ role="button"
62
+ aria-label="Profile button"
63
+ />,
64
+ );
65
+
66
+ expect(screen.getByRole('button', { name: 'Profile button' })).toBeInTheDocument();
67
+ });
68
+
69
+ it('renders initials when no image provided', () => {
70
+ const johnDoeProfile = 'John Doe';
71
+ renderWithMedia(<ListItem.AvatarView profileName={johnDoeProfile} />);
72
+
73
+ expect(screen.getByText('JD')).toBeInTheDocument();
74
+ });
75
+ });
@@ -0,0 +1,339 @@
1
+ import { Meta, StoryObj } from '@storybook/react-webpack5';
2
+ import { Leaf, Taxi } from '@transferwise/icons';
3
+ import { lorem10 } from '../../test-utils';
4
+ import { ProfileType } from '../../common';
5
+ import List from '../../list';
6
+ import { ListItem } from '../ListItem';
7
+ import {
8
+ SB_LIST_ITEM_ADDITIONAL_INFO as INFO,
9
+ SB_LIST_ITEM_CONTROLS as CONTROLS,
10
+ } from '../_stories/subcomponents';
11
+ import { disableControls } from '../_stories/helpers';
12
+ import type { ListItemAvatarViewProps } from './ListItemAvatarView';
13
+
14
+ const hideControls = disableControls(['badge', 'children']);
15
+
16
+ const SIZES = [32, 40, 48, 56, 72] as const;
17
+ const BADGES = {
18
+ 'Country flag badge': { flagCode: 'GBP' },
19
+ 'StatusIcon badge': { status: 'warning' },
20
+ 'Icon badge': { icon: <Taxi /> },
21
+ 'Default action badge': {
22
+ type: 'action',
23
+ },
24
+ 'Default reference badge': {
25
+ type: 'reference',
26
+ },
27
+ 'Action badge with custom icon': {
28
+ type: 'action',
29
+ icon: <Taxi />,
30
+ },
31
+ 'Reference badge with custom icon': {
32
+ type: 'reference',
33
+ icon: <Taxi />,
34
+ },
35
+ 'Custom badge': {
36
+ asset: (
37
+ <div
38
+ className="d-flex align-items-center justify-content-center"
39
+ style={{
40
+ backgroundColor: 'var(--color-bright-pink)',
41
+ color: 'var(--color-interactive-primary)',
42
+ width: '100%',
43
+ height: '100%',
44
+ }}
45
+ >
46
+ <Leaf />
47
+ </div>
48
+ ),
49
+ },
50
+ } as const;
51
+
52
+ export default {
53
+ component: ListItem.AvatarView,
54
+ title: 'Content/ListItem/ListItem.AvatarView',
55
+ parameters: {
56
+ docs: {
57
+ toc: true,
58
+ },
59
+ },
60
+ args: {
61
+ size: 48,
62
+ selected: false,
63
+ badge: { type: 'action' },
64
+ notification: false,
65
+ profileName: undefined,
66
+ profileType: undefined,
67
+ imgSrc: undefined,
68
+ },
69
+ argTypes: {
70
+ size: {
71
+ control: 'select',
72
+ options: SIZES,
73
+ description: 'Size of the avatar',
74
+ },
75
+ profileName: {
76
+ control: 'text',
77
+ description: 'Name used to generate initials when no image or icon is provided',
78
+ },
79
+ imgSrc: {
80
+ control: 'text',
81
+ description: 'URL of the profile image',
82
+ },
83
+ profileType: {
84
+ control: 'select',
85
+ options: [ProfileType.PERSONAL, ProfileType.BUSINESS],
86
+ description: 'Type of profile for default icons',
87
+ table: {
88
+ type: { summary: 'ProfileType' },
89
+ },
90
+ },
91
+ notification: {
92
+ control: 'boolean',
93
+ description: 'Shows notification dot',
94
+ },
95
+ selected: {
96
+ control: 'boolean',
97
+ description: 'Toggles selected state',
98
+ },
99
+ badge: {
100
+ description: 'Badge configuration object',
101
+ table: {
102
+ type: { summary: 'AvatarViewBadgeProps' },
103
+ },
104
+ },
105
+ children: {
106
+ table: {
107
+ type: { summary: 'ReactNode' },
108
+ },
109
+ },
110
+ style: {
111
+ table: {
112
+ disable: true,
113
+ },
114
+ },
115
+ },
116
+ } satisfies Meta<ListItemAvatarViewProps>;
117
+
118
+ type Story = StoryObj<ListItemAvatarViewProps>;
119
+
120
+ export const Playground: Story = {
121
+ tags: ['!autodocs'],
122
+ render: (args: ListItemAvatarViewProps) => {
123
+ return (
124
+ <List>
125
+ <ListItem
126
+ title="John Smith"
127
+ subtitle="Personal account"
128
+ media={<ListItem.AvatarView {...args} />}
129
+ control={CONTROLS.iconButton}
130
+ additionalInfo={INFO.nonInteractive}
131
+ />
132
+ </List>
133
+ );
134
+ },
135
+ };
136
+
137
+ /**
138
+ * AvatarView can display different types of content including icons, profile images, and initials. <br />
139
+ * Refer to the [design documentation](https://wise.design/components/avatar#:~:text=56%2C%20%E2%80%A8and%2072.-,Media,-There%20are%204) for details.
140
+ */
141
+ export const ContentTypes: Story = {
142
+ args: {
143
+ badge: undefined,
144
+ },
145
+ argTypes: hideControls(['profileName', 'imgSrc', 'profileType']),
146
+ parameters: {
147
+ docs: {
148
+ canvas: {
149
+ sourceState: 'hidden',
150
+ },
151
+ },
152
+ },
153
+ render: (args) => {
154
+ return (
155
+ <List>
156
+ <ListItem
157
+ title="With icon"
158
+ subtitle="Default icon content"
159
+ media={
160
+ <ListItem.AvatarView {...args}>
161
+ <Taxi />
162
+ </ListItem.AvatarView>
163
+ }
164
+ control={CONTROLS.iconButton}
165
+ />
166
+
167
+ <ListItem
168
+ title="With profile image"
169
+ subtitle="User profile picture."
170
+ media={
171
+ <ListItem.AvatarView
172
+ {...args}
173
+ imgSrc="../avatar-square-dude.webp"
174
+ profileName="John Smith"
175
+ />
176
+ }
177
+ control={CONTROLS.iconButton}
178
+ />
179
+
180
+ <ListItem
181
+ title="With initials"
182
+ subtitle="Fallback for when no profile image is available."
183
+ media={<ListItem.AvatarView {...args} profileName="Sarah Johnson" />}
184
+ control={CONTROLS.iconButton}
185
+ />
186
+
187
+ <ListItem
188
+ title="Business profile"
189
+ subtitle="Fallback for when no logo is available"
190
+ media={<ListItem.AvatarView {...args} profileType={ProfileType.BUSINESS} />}
191
+ control={CONTROLS.iconButton}
192
+ />
193
+
194
+ <ListItem
195
+ title="Personal profile"
196
+ subtitle="Fallback for when no personal data is available or when image fails to load."
197
+ media={
198
+ <ListItem.AvatarView
199
+ {...args}
200
+ profileType={ProfileType.PERSONAL}
201
+ profileName="Alex Chen"
202
+ />
203
+ }
204
+ control={CONTROLS.iconButton}
205
+ />
206
+ </List>
207
+ );
208
+ },
209
+ };
210
+
211
+ /**
212
+ * AvatarView supports 5 sizes to fit different list item contexts: `32`, `40`, `48`, `56`, `72`. If decorated with a Badge, those will be sized accordingly as well. <br />
213
+ * Please refer to the [design documentation](https://wise.design/components/list-item#avatar:~:text=of%20the%20avatar.-,Avatar%20sizes,-List%20item%20supports) for details on when to use which one.
214
+ */
215
+ export const Sizes: Story = {
216
+ parameters: {
217
+ docs: {
218
+ canvas: {
219
+ sourceState: 'hidden',
220
+ },
221
+ },
222
+ },
223
+ argTypes: hideControls(['profileName', 'imgSrc', 'profileType', 'size']),
224
+ render: (args) => {
225
+ return (
226
+ <List>
227
+ {SIZES.map((size) => (
228
+ <ListItem
229
+ key={size}
230
+ title={`Size ${size}`}
231
+ subtitle={lorem10}
232
+ media={
233
+ <ListItem.AvatarView {...args} size={size}>
234
+ <Taxi />
235
+ </ListItem.AvatarView>
236
+ }
237
+ control={CONTROLS.iconButton}
238
+ />
239
+ ))}
240
+ </List>
241
+ );
242
+ },
243
+ };
244
+
245
+ /**
246
+ * Similarly, AvatarView also support a notification dot, which also adjusts to the Avatar's size. <br />
247
+ * **NB:** You cannot use notification and badge at the same time – badge will always take precedence over notification.
248
+ */
249
+ export const Notification: Story = {
250
+ parameters: {
251
+ docs: {
252
+ canvas: {
253
+ sourceState: 'hidden',
254
+ },
255
+ },
256
+ },
257
+ args: {
258
+ badge: undefined,
259
+ },
260
+ argTypes: hideControls([
261
+ 'profileName',
262
+ 'imgSrc',
263
+ 'profileType',
264
+ 'size',
265
+ 'notification',
266
+ 'selected',
267
+ ]),
268
+ render: (args) => {
269
+ return (
270
+ <List>
271
+ {SIZES.map((size) => (
272
+ <ListItem
273
+ key={size}
274
+ title={`Size ${size}`}
275
+ subtitle={lorem10}
276
+ media={
277
+ <ListItem.AvatarView {...args} size={size} notification>
278
+ <Taxi />
279
+ </ListItem.AvatarView>
280
+ }
281
+ control={CONTROLS.iconButton}
282
+ />
283
+ ))}
284
+ </List>
285
+ );
286
+ },
287
+ };
288
+
289
+ /**
290
+ * AvatarView supports different type of badges for additional context and information. <br />
291
+ * Refer to the [design documentation](https://wise.design/components/avatar#:~:text=support%20the%20information.-,With%20badge,-Badges%20contain%20additional) for details.
292
+ */
293
+ export const Badges: Story = {
294
+ args: {
295
+ imgSrc: '../avatar-square-dude.webp',
296
+ },
297
+ argTypes: hideControls(['profileName', 'imgSrc', 'profileType', 'notification', 'selected']),
298
+ parameters: {
299
+ docs: {
300
+ canvas: {
301
+ sourceState: 'hidden',
302
+ },
303
+ },
304
+ },
305
+ render: (args) => {
306
+ return (
307
+ <List>
308
+ {Object.entries(BADGES).map(([title, badge]) => (
309
+ <ListItem
310
+ key={title}
311
+ title={title}
312
+ subtitle={lorem10}
313
+ media={<ListItem.AvatarView {...args} badge={badge} />}
314
+ control={CONTROLS.iconButton}
315
+ />
316
+ ))}
317
+ </List>
318
+ );
319
+ },
320
+ };
321
+
322
+ /**
323
+ * AvatarView supports selected state for interactive contexts.
324
+ */
325
+ export const Selected: Story = {
326
+ argTypes: hideControls(['profileName', 'imgSrc', 'profileType', 'notification', 'selected']),
327
+ render: (args) => {
328
+ return (
329
+ <List>
330
+ <ListItem
331
+ title="Selected state"
332
+ subtitle="Currently selected item"
333
+ media={<ListItem.AvatarView profileName="Alex Chen" selected />}
334
+ control={CONTROLS.iconButton}
335
+ />
336
+ </List>
337
+ );
338
+ },
339
+ };
@@ -0,0 +1,27 @@
1
+ import { clsx } from 'clsx';
2
+ import AvatarViewComp, { type AvatarViewProps } from '../../avatarView';
3
+ import { useListItemMedia } from '../useListItemMedia';
4
+
5
+ export type ListItemAvatarViewProps = Omit<AvatarViewProps, 'size' | 'interactive'> & {
6
+ size?: 32 | 40 | 48 | 56 | 72;
7
+ };
8
+
9
+ /**
10
+ * This component renders a single avatar. It's a thin wrapper around the
11
+ * [AvatarView component](https://storybook.wise.design/?path=/docs/content-avatarview--docs), but offers only
12
+ * a subset of its sizes, in line with the ListItem's constraints. <br />
13
+ * <br />
14
+ * Please refer to the [Design documentation](https://wise.design/components/list-item#avatar) for details.
15
+ */
16
+ export const AvatarView = ({ className, size = 48, ...props }: ListItemAvatarViewProps) => {
17
+ useListItemMedia(size);
18
+
19
+ return (
20
+ <AvatarViewComp
21
+ {...props}
22
+ size={size}
23
+ className={clsx('wds-list-item-media-avatar-view', className)}
24
+ />
25
+ );
26
+ };
27
+ AvatarView.displayName = 'ListItem.AvatarView';
@@ -0,0 +1,2 @@
1
+ export type { ListItemAvatarViewProps } from './ListItemAvatarView';
2
+ export { AvatarView } from './ListItemAvatarView';
@@ -0,0 +1,90 @@
1
+ import { screen, mockMatchMedia, userEvent } from '../../test-utils';
2
+ import { Button as ItemButton } from './ListItemButton';
3
+ import { ButtonPriority } from '../../button/Button.types';
4
+ import { renderWithListItemContext, clearListItemMocks, mockSetControlType } from '../test-utils';
5
+
6
+ mockMatchMedia();
7
+
8
+ describe('ItemButton', () => {
9
+ beforeEach(() => {
10
+ clearListItemMocks();
11
+ });
12
+
13
+ it('always sets v2 to true', () => {
14
+ renderWithListItemContext(<ItemButton priority="primary">Test Button</ItemButton>);
15
+ const button = screen.getByRole('button');
16
+ expect(button).toBeInTheDocument();
17
+ expect(mockSetControlType).toHaveBeenCalledWith('button');
18
+ });
19
+
20
+ it('always sets size to "sm"', () => {
21
+ renderWithListItemContext(<ItemButton priority="primary">Test Button</ItemButton>);
22
+ const button = screen.getByRole('button');
23
+ expect(button).toHaveClass('wds-Button--small');
24
+ });
25
+
26
+ it('supports all priorities', () => {
27
+ const priorities: ButtonPriority[] = ['primary', 'secondary', 'tertiary'];
28
+ priorities.forEach((priority) => {
29
+ renderWithListItemContext(<ItemButton priority={priority}>Test {priority}</ItemButton>);
30
+ const button = screen.getByRole('button', { name: `Test ${priority}` });
31
+ expect(button).toBeInTheDocument();
32
+ });
33
+ });
34
+
35
+ it('renders as a button by default', () => {
36
+ renderWithListItemContext(<ItemButton>Click me</ItemButton>);
37
+ const button = screen.getByRole('button');
38
+ expect(button).toBeInTheDocument();
39
+ expect(button.tagName).toBe('BUTTON');
40
+ });
41
+
42
+ it('renders as an anchor when href is provided', () => {
43
+ renderWithListItemContext(<ItemButton href="https://example.com">Go to Example</ItemButton>);
44
+ const link = screen.getByRole('link', { name: 'Go to Example' });
45
+ expect(link).toBeInTheDocument();
46
+ expect(link.tagName).toBe('A');
47
+ expect(link).toHaveAttribute('href', 'https://example.com');
48
+ });
49
+
50
+ it('spreads additional props to the button', () => {
51
+ renderWithListItemContext(<ItemButton aria-label="Custom Button">Custom</ItemButton>);
52
+ const button = screen.getByRole('button', { name: 'Custom Button' });
53
+ expect(button).toBeInTheDocument();
54
+ expect(button).toHaveAttribute('aria-label', 'Custom Button');
55
+ });
56
+
57
+ it('spreads additional props to the anchor', () => {
58
+ renderWithListItemContext(
59
+ <ItemButton href="https://example.com" target="_blank" aria-label="Custom Link">
60
+ Custom Link
61
+ </ItemButton>,
62
+ );
63
+ const link = screen.getByRole('link', { name: 'Custom Link' });
64
+ expect(link).toBeInTheDocument();
65
+ expect(link).toHaveAttribute('href', 'https://example.com');
66
+ expect(link).toHaveAttribute('target', '_blank');
67
+ });
68
+
69
+ describe('onClick', () => {
70
+ it('handles onClick events when rendered as HTML button', async () => {
71
+ const handleClick = jest.fn();
72
+ renderWithListItemContext(<ItemButton onClick={handleClick}>Go to Example</ItemButton>);
73
+
74
+ await userEvent.click(screen.getByRole('button'));
75
+ expect(handleClick).toHaveBeenCalledTimes(1);
76
+ });
77
+
78
+ it('handles onClick events when rendered as HTML anchor', async () => {
79
+ const handleClick = jest.fn();
80
+ renderWithListItemContext(
81
+ <ItemButton href="#target" onClick={handleClick}>
82
+ Go to Example
83
+ </ItemButton>,
84
+ );
85
+
86
+ await userEvent.click(screen.getByRole('link'));
87
+ expect(handleClick).toHaveBeenCalledTimes(1);
88
+ });
89
+ });
90
+ });