@transferwise/components 0.0.0-experimental-2242f8a → 0.0.0-experimental-5759f4d

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 (255) hide show
  1. package/build/button/Button.js +1 -0
  2. package/build/button/Button.js.map +1 -1
  3. package/build/button/Button.mjs +1 -0
  4. package/build/button/Button.mjs.map +1 -1
  5. package/build/common/RadioButton/RadioButton.js +5 -2
  6. package/build/common/RadioButton/RadioButton.js.map +1 -1
  7. package/build/common/RadioButton/RadioButton.mjs +5 -2
  8. package/build/common/RadioButton/RadioButton.mjs.map +1 -1
  9. package/build/i18n/en.json +2 -0
  10. package/build/i18n/en.json.js +2 -0
  11. package/build/i18n/en.json.js.map +1 -1
  12. package/build/i18n/en.json.mjs +2 -0
  13. package/build/i18n/en.json.mjs.map +1 -1
  14. package/build/iconButton/IconButton.js.map +1 -1
  15. package/build/iconButton/IconButton.mjs.map +1 -1
  16. package/build/image/Image.js.map +1 -1
  17. package/build/image/Image.mjs.map +1 -1
  18. package/build/index.js +2 -0
  19. package/build/index.js.map +1 -1
  20. package/build/index.mjs +1 -0
  21. package/build/index.mjs.map +1 -1
  22. package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.js +56 -0
  23. package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.js.map +1 -0
  24. package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.mjs +54 -0
  25. package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.mjs.map +1 -0
  26. package/build/listItem/AvatarLayout/ListItemAvatarLayout.js +21 -0
  27. package/build/listItem/AvatarLayout/ListItemAvatarLayout.js.map +1 -0
  28. package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs +19 -0
  29. package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs.map +1 -0
  30. package/build/listItem/AvatarView/ListItemAvatarView.js +21 -0
  31. package/build/listItem/AvatarView/ListItemAvatarView.js.map +1 -0
  32. package/build/listItem/AvatarView/ListItemAvatarView.mjs +19 -0
  33. package/build/listItem/AvatarView/ListItemAvatarView.mjs.map +1 -0
  34. package/build/listItem/Button/ListItemButton.js +43 -0
  35. package/build/listItem/Button/ListItemButton.js.map +1 -0
  36. package/build/listItem/Button/ListItemButton.mjs +41 -0
  37. package/build/listItem/Button/ListItemButton.mjs.map +1 -0
  38. package/build/listItem/Checkbox/ListItemCheckbox.js +30 -0
  39. package/build/listItem/Checkbox/ListItemCheckbox.js.map +1 -0
  40. package/build/listItem/Checkbox/ListItemCheckbox.mjs +28 -0
  41. package/build/listItem/Checkbox/ListItemCheckbox.mjs.map +1 -0
  42. package/build/listItem/IconButton/ListItemIconButton.js +42 -0
  43. package/build/listItem/IconButton/ListItemIconButton.js.map +1 -0
  44. package/build/listItem/IconButton/ListItemIconButton.mjs +40 -0
  45. package/build/listItem/IconButton/ListItemIconButton.mjs.map +1 -0
  46. package/build/listItem/Image/ListItemImage.js +27 -0
  47. package/build/listItem/Image/ListItemImage.js.map +1 -0
  48. package/build/listItem/Image/ListItemImage.mjs +25 -0
  49. package/build/listItem/Image/ListItemImage.mjs.map +1 -0
  50. package/build/listItem/ListItem.js +302 -0
  51. package/build/listItem/ListItem.js.map +1 -0
  52. package/build/listItem/ListItem.mjs +297 -0
  53. package/build/listItem/ListItem.mjs.map +1 -0
  54. package/build/listItem/ListItemContext.js +8 -0
  55. package/build/listItem/ListItemContext.js.map +1 -0
  56. package/build/listItem/ListItemContext.mjs +6 -0
  57. package/build/listItem/ListItemContext.mjs.map +1 -0
  58. package/build/listItem/Navigation/ListItemNavigation.js +45 -0
  59. package/build/listItem/Navigation/ListItemNavigation.js.map +1 -0
  60. package/build/listItem/Navigation/ListItemNavigation.mjs +43 -0
  61. package/build/listItem/Navigation/ListItemNavigation.mjs.map +1 -0
  62. package/build/listItem/Prompt/ListItemPrompt.js +59 -0
  63. package/build/listItem/Prompt/ListItemPrompt.js.map +1 -0
  64. package/build/listItem/Prompt/ListItemPrompt.mjs +54 -0
  65. package/build/listItem/Prompt/ListItemPrompt.mjs.map +1 -0
  66. package/build/listItem/Radio/ListItemRadio.js +30 -0
  67. package/build/listItem/Radio/ListItemRadio.js.map +1 -0
  68. package/build/listItem/Radio/ListItemRadio.mjs +28 -0
  69. package/build/listItem/Radio/ListItemRadio.mjs.map +1 -0
  70. package/build/listItem/Switch/ListItemSwitch.js +30 -0
  71. package/build/listItem/Switch/ListItemSwitch.js.map +1 -0
  72. package/build/listItem/Switch/ListItemSwitch.mjs +28 -0
  73. package/build/listItem/Switch/ListItemSwitch.mjs.map +1 -0
  74. package/build/listItem/useListItemControl.js +22 -0
  75. package/build/listItem/useListItemControl.js.map +1 -0
  76. package/build/listItem/useListItemControl.mjs +20 -0
  77. package/build/listItem/useListItemControl.mjs.map +1 -0
  78. package/build/main.css +657 -0
  79. package/build/styles/listItem/ListItem.css +657 -0
  80. package/build/styles/listItem/ListItem.grid.css +362 -0
  81. package/build/styles/main.css +657 -0
  82. package/build/switch/Switch.js +2 -0
  83. package/build/switch/Switch.js.map +1 -1
  84. package/build/switch/Switch.mjs +2 -0
  85. package/build/switch/Switch.mjs.map +1 -1
  86. package/build/types/button/Button.d.ts.map +1 -1
  87. package/build/types/button/Button.types.d.ts +1 -1
  88. package/build/types/button/Button.types.d.ts.map +1 -1
  89. package/build/types/button/index.d.ts +1 -1
  90. package/build/types/button/index.d.ts.map +1 -1
  91. package/build/types/common/RadioButton/RadioButton.d.ts +3 -1
  92. package/build/types/common/RadioButton/RadioButton.d.ts.map +1 -1
  93. package/build/types/iconButton/IconButton.d.ts +2 -2
  94. package/build/types/iconButton/IconButton.d.ts.map +1 -1
  95. package/build/types/image/Image.d.ts +3 -0
  96. package/build/types/image/Image.d.ts.map +1 -1
  97. package/build/types/image/index.d.ts +1 -0
  98. package/build/types/image/index.d.ts.map +1 -1
  99. package/build/types/index.d.ts +2 -0
  100. package/build/types/index.d.ts.map +1 -1
  101. package/build/types/listItem/AdditionalInfo/ListItemAdditionalInfo.d.ts +15 -0
  102. package/build/types/listItem/AdditionalInfo/ListItemAdditionalInfo.d.ts.map +1 -0
  103. package/build/types/listItem/AdditionalInfo/index.d.ts +3 -0
  104. package/build/types/listItem/AdditionalInfo/index.d.ts.map +1 -0
  105. package/build/types/listItem/AvatarLayout/ListItemAvatarLayout.d.ts +18 -0
  106. package/build/types/listItem/AvatarLayout/ListItemAvatarLayout.d.ts.map +1 -0
  107. package/build/types/listItem/AvatarLayout/index.d.ts +3 -0
  108. package/build/types/listItem/AvatarLayout/index.d.ts.map +1 -0
  109. package/build/types/listItem/AvatarView/ListItemAvatarView.d.ts +16 -0
  110. package/build/types/listItem/AvatarView/ListItemAvatarView.d.ts.map +1 -0
  111. package/build/types/listItem/AvatarView/index.d.ts +3 -0
  112. package/build/types/listItem/AvatarView/index.d.ts.map +1 -0
  113. package/build/types/listItem/Button/ListItemButton.d.ts +20 -0
  114. package/build/types/listItem/Button/ListItemButton.d.ts.map +1 -0
  115. package/build/types/listItem/Button/index.d.ts +3 -0
  116. package/build/types/listItem/Button/index.d.ts.map +1 -0
  117. package/build/types/listItem/Checkbox/ListItemCheckbox.d.ts +14 -0
  118. package/build/types/listItem/Checkbox/ListItemCheckbox.d.ts.map +1 -0
  119. package/build/types/listItem/Checkbox/index.d.ts +3 -0
  120. package/build/types/listItem/Checkbox/index.d.ts.map +1 -0
  121. package/build/types/listItem/IconButton/ListItemIconButton.d.ts +18 -0
  122. package/build/types/listItem/IconButton/ListItemIconButton.d.ts.map +1 -0
  123. package/build/types/listItem/IconButton/index.d.ts +3 -0
  124. package/build/types/listItem/IconButton/index.d.ts.map +1 -0
  125. package/build/types/listItem/Image/ListItemImage.d.ts +25 -0
  126. package/build/types/listItem/Image/ListItemImage.d.ts.map +1 -0
  127. package/build/types/listItem/Image/index.d.ts +3 -0
  128. package/build/types/listItem/Image/index.d.ts.map +1 -0
  129. package/build/types/listItem/ListItem.d.ts +113 -0
  130. package/build/types/listItem/ListItem.d.ts.map +1 -0
  131. package/build/types/listItem/ListItemContext.d.ts +18 -0
  132. package/build/types/listItem/ListItemContext.d.ts.map +1 -0
  133. package/build/types/listItem/Navigation/ListItemNavigation.d.ts +15 -0
  134. package/build/types/listItem/Navigation/ListItemNavigation.d.ts.map +1 -0
  135. package/build/types/listItem/Navigation/index.d.ts +3 -0
  136. package/build/types/listItem/Navigation/index.d.ts.map +1 -0
  137. package/build/types/listItem/Prompt/ListItemPrompt.d.ts +16 -0
  138. package/build/types/listItem/Prompt/ListItemPrompt.d.ts.map +1 -0
  139. package/build/types/listItem/Prompt/index.d.ts +3 -0
  140. package/build/types/listItem/Prompt/index.d.ts.map +1 -0
  141. package/build/types/listItem/Radio/ListItemRadio.d.ts +14 -0
  142. package/build/types/listItem/Radio/ListItemRadio.d.ts.map +1 -0
  143. package/build/types/listItem/Radio/index.d.ts +3 -0
  144. package/build/types/listItem/Radio/index.d.ts.map +1 -0
  145. package/build/types/listItem/Switch/ListItemSwitch.d.ts +14 -0
  146. package/build/types/listItem/Switch/ListItemSwitch.d.ts.map +1 -0
  147. package/build/types/listItem/Switch/index.d.ts +3 -0
  148. package/build/types/listItem/Switch/index.d.ts.map +1 -0
  149. package/build/types/listItem/_stories/subcomponents.d.ts +18 -0
  150. package/build/types/listItem/_stories/subcomponents.d.ts.map +1 -0
  151. package/build/types/listItem/index.d.ts +14 -0
  152. package/build/types/listItem/index.d.ts.map +1 -0
  153. package/build/types/listItem/useListItemControl.d.ts +5 -0
  154. package/build/types/listItem/useListItemControl.d.ts.map +1 -0
  155. package/build/types/switch/Switch.d.ts +2 -0
  156. package/build/types/switch/Switch.d.ts.map +1 -1
  157. package/build/types/test-utils/index.d.ts +4 -0
  158. package/build/types/test-utils/index.d.ts.map +1 -1
  159. package/build/types/upload/Upload.d.ts +6 -2
  160. package/build/types/upload/Upload.d.ts.map +1 -1
  161. package/build/types/upload/Upload.messages.d.ts +8 -0
  162. package/build/types/upload/Upload.messages.d.ts.map +1 -1
  163. package/build/types/uploadInput/UploadInput.d.ts +1 -1
  164. package/build/types/uploadInput/uploadButton/UploadButton.d.ts +4 -2
  165. package/build/types/uploadInput/uploadButton/UploadButton.d.ts.map +1 -1
  166. package/build/upload/Upload.js +16 -9
  167. package/build/upload/Upload.js.map +1 -1
  168. package/build/upload/Upload.messages.js +6 -0
  169. package/build/upload/Upload.messages.js.map +1 -1
  170. package/build/upload/Upload.messages.mjs +6 -0
  171. package/build/upload/Upload.messages.mjs.map +1 -1
  172. package/build/upload/Upload.mjs +16 -9
  173. package/build/upload/Upload.mjs.map +1 -1
  174. package/build/uploadInput/UploadInput.js +1 -1
  175. package/build/uploadInput/UploadInput.js.map +1 -1
  176. package/build/uploadInput/UploadInput.mjs +1 -1
  177. package/build/uploadInput/UploadInput.mjs.map +1 -1
  178. package/build/uploadInput/uploadButton/UploadButton.js +7 -4
  179. package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
  180. package/build/uploadInput/uploadButton/UploadButton.mjs +7 -4
  181. package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
  182. package/package.json +1 -1
  183. package/src/button/Button.spec.tsx +18 -0
  184. package/src/button/Button.tsx +5 -1
  185. package/src/button/Button.types.ts +1 -1
  186. package/src/button/index.ts +1 -1
  187. package/src/checkboxButton/CheckboxButton.story.tsx +4 -4
  188. package/src/common/RadioButton/RadioButton.tsx +6 -1
  189. package/src/i18n/en.json +2 -0
  190. package/src/iconButton/IconButton.story.tsx +1 -1
  191. package/src/iconButton/IconButton.tsx +1 -1
  192. package/src/image/Image.tsx +3 -0
  193. package/src/image/index.ts +1 -0
  194. package/src/index.ts +2 -0
  195. package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.story.tsx +145 -0
  196. package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.tsx +36 -0
  197. package/src/listItem/AdditionalInfo/index.ts +2 -0
  198. package/src/listItem/AvatarLayout/ListItemAvatarLayout.story.tsx +118 -0
  199. package/src/listItem/AvatarLayout/ListItemAvatarLayout.tsx +24 -0
  200. package/src/listItem/AvatarLayout/index.ts +2 -0
  201. package/src/listItem/AvatarView/ListItemAvatarView.story.tsx +318 -0
  202. package/src/listItem/AvatarView/ListItemAvatarView.tsx +24 -0
  203. package/src/listItem/AvatarView/index.ts +2 -0
  204. package/src/listItem/Button/ListItemButton.spec.tsx +93 -0
  205. package/src/listItem/Button/ListItemButton.story.tsx +408 -0
  206. package/src/listItem/Button/ListItemButton.tsx +56 -0
  207. package/src/listItem/Button/index.ts +2 -0
  208. package/src/listItem/Checkbox/ListItemCheckbox.story.tsx +107 -0
  209. package/src/listItem/Checkbox/ListItemCheckbox.tsx +33 -0
  210. package/src/listItem/Checkbox/index.ts +2 -0
  211. package/src/listItem/IconButton/ListItemIconButton.story.tsx +236 -0
  212. package/src/listItem/IconButton/ListItemIconButton.tsx +56 -0
  213. package/src/listItem/IconButton/index.ts +2 -0
  214. package/src/listItem/Image/ListItemImage.story.tsx +39 -0
  215. package/src/listItem/Image/ListItemImage.tsx +40 -0
  216. package/src/listItem/Image/index.ts +2 -0
  217. package/src/listItem/ListItem.css +657 -0
  218. package/src/listItem/ListItem.grid.css +362 -0
  219. package/src/listItem/ListItem.grid.less +612 -0
  220. package/src/listItem/ListItem.less +312 -0
  221. package/src/listItem/ListItem.spec.tsx +97 -0
  222. package/src/listItem/ListItem.tsx +428 -0
  223. package/src/listItem/ListItemContext.tsx +22 -0
  224. package/src/listItem/Navigation/ListItemNavigation.story.tsx +106 -0
  225. package/src/listItem/Navigation/ListItemNavigation.tsx +40 -0
  226. package/src/listItem/Navigation/index.ts +2 -0
  227. package/src/listItem/Prompt/ListItemPrompt.spec.tsx +49 -0
  228. package/src/listItem/Prompt/ListItemPrompt.story.tsx +199 -0
  229. package/src/listItem/Prompt/ListItemPrompt.tsx +32 -0
  230. package/src/listItem/Prompt/index.ts +2 -0
  231. package/src/listItem/Radio/ListItemRadio.story.tsx +98 -0
  232. package/src/listItem/Radio/ListItemRadio.tsx +33 -0
  233. package/src/listItem/Radio/index.ts +2 -0
  234. package/src/listItem/Switch/ListItemSwitch.story.tsx +69 -0
  235. package/src/listItem/Switch/ListItemSwitch.tsx +33 -0
  236. package/src/listItem/Switch/index.ts +2 -0
  237. package/src/listItem/_stories/ListItem.focus.test.story.tsx +250 -0
  238. package/src/listItem/_stories/ListItem.layout.test.story.tsx +169 -0
  239. package/src/listItem/_stories/ListItem.story.tsx +670 -0
  240. package/src/listItem/_stories/ListItem.variants.test.story.tsx +266 -0
  241. package/src/listItem/_stories/subcomponents.tsx +139 -0
  242. package/src/listItem/index.ts +14 -0
  243. package/src/listItem/useListItemControl.tsx +18 -0
  244. package/src/main.css +657 -0
  245. package/src/main.less +1 -0
  246. package/src/switch/Switch.tsx +4 -0
  247. package/src/upload/Upload.messages.ts +8 -0
  248. package/src/upload/Upload.spec.tsx +6 -0
  249. package/src/upload/Upload.story.tsx +118 -3
  250. package/src/upload/Upload.tests.story.tsx +5 -3
  251. package/src/upload/Upload.tsx +24 -15
  252. package/src/uploadInput/UploadInput.tests.story.tsx +7 -0
  253. package/src/uploadInput/UploadInput.tsx +2 -2
  254. package/src/uploadInput/uploadButton/UploadButton.spec.tsx +6 -0
  255. package/src/uploadInput/uploadButton/UploadButton.tsx +12 -6
@@ -0,0 +1,428 @@
1
+ /* eslint-disable functional/immutable-data */
2
+ import {
3
+ useContext,
4
+ useId,
5
+ useMemo,
6
+ useState,
7
+ type PropsWithChildren,
8
+ type ReactNode,
9
+ } from 'react';
10
+ import { Typography } from '../common';
11
+ import Body from '../body';
12
+ import { AdditionalInfo } from './AdditionalInfo';
13
+ import { IconButton, type ListItemIconButtonProps } from './IconButton';
14
+ import { Checkbox, type ListItemCheckboxProps } from './Checkbox';
15
+ import { Navigation, type ListItemNavigationProps } from './Navigation';
16
+ import { clsx } from 'clsx';
17
+ import { Button, type ListItemButtonProps } from './Button';
18
+ import { Radio, type ListItemRadioProps } from './Radio';
19
+ import { Switch, type ListItemSwitchProps } from './Switch';
20
+ import { AvatarLayout } from './AvatarLayout';
21
+ import { AvatarView } from './AvatarView';
22
+ import { Image } from './Image';
23
+ import { Prompt } from './Prompt';
24
+ import { PrimitiveAnchor } from '../primitives';
25
+ import { ListItemContext, type ListItemContextData } from './ListItemContext';
26
+
27
+ export type ListItemTypes =
28
+ | 'non-interactive'
29
+ | 'navigation'
30
+ | 'radio'
31
+ | 'checkbox'
32
+ | 'switch'
33
+ | 'button'
34
+ | 'icon-button';
35
+
36
+ export type ListItemControlProps =
37
+ | ListItemNavigationProps
38
+ | ListItemCheckboxProps
39
+ | ListItemButtonProps
40
+ | ListItemIconButtonProps
41
+ | ListItemRadioProps
42
+ | ListItemSwitchProps;
43
+
44
+ export type Props = {
45
+ as?: 'li' | 'div';
46
+ /**
47
+ * Swaps vertical hierarchy of title and subtitle and their corresponding right values.
48
+ */
49
+ inverted?: boolean;
50
+ disabled?: boolean;
51
+ /**
52
+ * Highlights the list item as an action to be taken or already taken. <br />
53
+ */
54
+ spotlight?: 'active' | 'inactive';
55
+ title: ReactNode;
56
+ subtitle?: ReactNode;
57
+ /**
58
+ * Requires `<ListItem.AdditionalInfo />` component as a sole child. <br />
59
+ * Can be only rendered if `subtitle` is also provided.
60
+ */
61
+ additionalInfo?: ReactNode;
62
+ valueTitle?: ReactNode;
63
+ valueSubtitle?: ReactNode;
64
+ /**
65
+ * Requires one of the following as a sole child: <br />
66
+ * `<ListItem.AvatarView />`,
67
+ * `<ListItem.AvatarLayout />` or
68
+ * `<ListItem.Image />`
69
+ */
70
+ media?: ReactNode;
71
+ /**
72
+ * Requires one of the following as a sole child: <br/>
73
+ * `<ListItem.Button />`, <br/>
74
+ * `<ListItem.Checkbox />`, <br/>
75
+ * `<ListItem.IconButton />`, <br/>
76
+ * `<ListItem.Navigation />`, <br/>
77
+ * `<ListItem.Radio />`, or
78
+ * `<ListItem.Switch />`
79
+ */
80
+ control?: ReactNode;
81
+ /**
82
+ * Requires `<ListItem.Prompt />` component as a sole child.
83
+ */
84
+ prompt?: ReactNode;
85
+ className?: string;
86
+ /**
87
+ * A number between `0–100` which resolves to a `fr` value of a `grid-template-columns` declaration. E.g. `valueColumnWidth={25}` will result in a `75fr 25fr`. <br />
88
+ * Controls the width ratio of left side content (title and subtitle) to the right side content.
89
+ */
90
+ valueColumnWidth?: number;
91
+ id?: string;
92
+ role?: string;
93
+ 'aria-labelledby'?: string;
94
+ };
95
+
96
+ /**
97
+ * @see [Design documentation](https://wise.design/components/list-item)
98
+ * @see [Storybook documentation](https://storybook.wise.design/?path=/docs/content-listitem--docs)
99
+ */
100
+ export const ListItem = ({
101
+ as: ListItemElement = 'li',
102
+ title,
103
+ subtitle,
104
+ additionalInfo,
105
+ prompt,
106
+ inverted,
107
+ media,
108
+ spotlight,
109
+ valueTitle,
110
+ valueSubtitle,
111
+ control = null,
112
+ disabled,
113
+ className,
114
+ valueColumnWidth,
115
+ role,
116
+ id,
117
+ 'aria-labelledby': ariaLabelledby,
118
+ }: Props) => {
119
+ const idPrefix = useId();
120
+ const [controlProps, setControlProps] = useState<ListItemControlProps>({});
121
+ const [controlType, setControlType] = useState<ListItemTypes>('non-interactive');
122
+ const ids: ListItemContextData['ids'] = {
123
+ title: `${idPrefix}_title`,
124
+ ...(subtitle ? { subtitle: `${idPrefix}_subtitle` } : {}),
125
+ ...(valueTitle ? { valueTitle: `${idPrefix}_value-title` } : {}),
126
+ ...(valueSubtitle ? { valueSubtitle: `${idPrefix}_value-subtitle` } : {}),
127
+ control: `${idPrefix}_control`,
128
+ ...(prompt ? { prompt: `${idPrefix}_prompt` } : {}),
129
+ ...(additionalInfo ? { additionalInfo: `${idPrefix}_additional-info` } : {}),
130
+ };
131
+
132
+ const isPartiallyInteractive = Boolean(
133
+ (controlType === 'button' || controlType === 'icon-button') &&
134
+ (controlProps as ListItemButtonProps | ListItemIconButtonProps)?.partiallyInteractive,
135
+ );
136
+ const isFullyInteractive = controlType !== 'non-interactive' && !isPartiallyInteractive;
137
+ const isButtonAsLink =
138
+ (controlType === 'button' || controlType === 'icon-button') &&
139
+ Boolean((controlProps as ListItemButtonProps | ListItemIconButtonProps)?.href);
140
+
141
+ const titlesAndValues = [
142
+ inverted ? ids.subtitle : ids.title,
143
+ inverted ? ids.title : ids.subtitle,
144
+ inverted ? ids.valueSubtitle : ids.valueTitle,
145
+ inverted ? ids.valueTitle : ids.valueSubtitle,
146
+ ].join(' ');
147
+ const additionalInfoPrompt = [ids.additionalInfo, ids.prompt].filter(Boolean).join(' ');
148
+
149
+ const describedByIds = useMemo(() => {
150
+ return isFullyInteractive && !isButtonAsLink
151
+ ? additionalInfoPrompt
152
+ : `${titlesAndValues} ${additionalInfoPrompt}`;
153
+ }, [isFullyInteractive]);
154
+
155
+ const listItemContext = useMemo(
156
+ () => ({
157
+ setControlType,
158
+ setControlProps,
159
+ ids,
160
+ props: { disabled, inverted },
161
+ describedByIds,
162
+ }),
163
+ [describedByIds],
164
+ );
165
+ const gridColumnsStyle = {
166
+ '--wds-list-item-body-left': valueColumnWidth ? `${100 - valueColumnWidth}fr` : '50fr',
167
+ '--wds-list-item-body-right': valueColumnWidth ? `${valueColumnWidth}fr` : '50fr',
168
+ } as React.CSSProperties;
169
+
170
+ const getFeatureClassName = () => {
171
+ const partials = [];
172
+ const hasMedia = Boolean(media);
173
+ const hasControl = Boolean(control);
174
+ const hasInfo = Boolean(additionalInfo);
175
+ const hasPrompt = Boolean(prompt);
176
+
177
+ if (hasMedia && hasControl) {
178
+ partials.push('wds-list-item-hasMedia-hasControl');
179
+ }
180
+
181
+ if (hasMedia && !hasControl) {
182
+ partials.push('wds-list-item-hasMedia-noControl');
183
+ }
184
+
185
+ if (!hasMedia && hasControl) {
186
+ partials.push('wds-list-item-noMedia-hasControl');
187
+ }
188
+
189
+ if (!hasMedia && !hasControl) {
190
+ partials.push('wds-list-item-noMedia-noControl');
191
+ }
192
+
193
+ if (hasInfo && hasPrompt) {
194
+ partials.push('wds-list-item-hasInfo-hasPrompt');
195
+ }
196
+ if (hasInfo && !hasPrompt) {
197
+ partials.push('wds-list-item-hasInfo-noPrompt');
198
+ }
199
+ if (!hasInfo && hasPrompt) {
200
+ partials.push('wds-list-item-noInfo-hasPrompt');
201
+ }
202
+ if (!hasInfo && !hasPrompt) {
203
+ partials.push('wds-list-item-noInfo-noPrompt');
204
+ }
205
+
206
+ return partials.join(' ');
207
+ };
208
+
209
+ return (
210
+ <ListItemContext.Provider value={listItemContext}>
211
+ <ListItemElement
212
+ className={clsx(
213
+ 'wds-list-item',
214
+ `wds-list-item-${controlType}`,
215
+ getFeatureClassName(),
216
+ {
217
+ 'wds-list-item-interactive': isFullyInteractive,
218
+ 'wds-list-item-partially-interactive': isPartiallyInteractive,
219
+ [`wds-list-item-spotlight-${spotlight}`]: isFullyInteractive && !!spotlight,
220
+ disabled,
221
+ },
222
+ className,
223
+ )}
224
+ id={id}
225
+ role={role}
226
+ aria-disabled={disabled}
227
+ aria-labelledby={ariaLabelledby}
228
+ >
229
+ <View
230
+ {...{
231
+ isPartiallyInteractive,
232
+ subtitle,
233
+ additionalInfo,
234
+ disabled,
235
+ prompt,
236
+ controlType,
237
+ controlProps,
238
+ }}
239
+ className={getFeatureClassName()}
240
+ >
241
+ {media && <div className="wds-list-item-media">{media}</div>}
242
+
243
+ {/* Title + Subtitle + Values - Group */}
244
+ <div
245
+ className="wds-list-item-body"
246
+ style={valueColumnWidth ? gridColumnsStyle : undefined}
247
+ >
248
+ {/* Title + Subtitle + Values - Group */}
249
+ <span>
250
+ {(() => {
251
+ const titles = [
252
+ <Body
253
+ key={ids.title}
254
+ id={ids.title}
255
+ type={Typography.BODY_LARGE_BOLD}
256
+ className="wds-list-item-title"
257
+ >
258
+ {title}
259
+ </Body>,
260
+ ];
261
+ if (subtitle) {
262
+ titles.push(
263
+ <Body key={ids.subtitle} id={ids.subtitle} className="wds-list-item-subtitle">
264
+ {subtitle}
265
+ </Body>,
266
+ );
267
+ }
268
+ return inverted ? [...titles].reverse() : titles;
269
+ })()}
270
+ </span>
271
+
272
+ {(valueTitle || valueSubtitle) && (
273
+ <span
274
+ className={clsx('wds-list-item-value', {
275
+ 'flex-column': valueTitle !== undefined || valueSubtitle !== undefined,
276
+ })}
277
+ >
278
+ {(() => {
279
+ const values = [];
280
+ if (valueTitle) {
281
+ values.push(
282
+ <Body
283
+ key={ids.valueTitle}
284
+ id={ids.valueTitle}
285
+ type={Typography.BODY_LARGE_BOLD}
286
+ className="wds-list-item-title-value"
287
+ >
288
+ {valueTitle}
289
+ </Body>,
290
+ );
291
+ }
292
+ if (valueSubtitle) {
293
+ values.push(
294
+ <Body
295
+ key={ids.valueSubtitle}
296
+ id={ids.valueSubtitle}
297
+ className="wds-list-item-subtitle-value"
298
+ >
299
+ {valueSubtitle}
300
+ </Body>,
301
+ );
302
+ }
303
+ return inverted ? [...values].reverse() : values;
304
+ })()}
305
+ </span>
306
+ )}
307
+ </div>
308
+
309
+ {control === null ? null : (
310
+ <Body
311
+ className={clsx('wds-list-item-control-wrapper', {
312
+ 'wds-list-item-button-control': controlType === 'button',
313
+ })}
314
+ >
315
+ {control}
316
+ </Body>
317
+ )}
318
+ </View>
319
+ </ListItemElement>
320
+ </ListItemContext.Provider>
321
+ );
322
+ };
323
+
324
+ type ViewProps = PropsWithChildren<{
325
+ isPartiallyInteractive: boolean;
326
+ controlType?: ListItemTypes;
327
+ controlProps?: ListItemControlProps;
328
+ }> &
329
+ Pick<Props, 'subtitle' | 'additionalInfo' | 'disabled' | 'prompt' | 'className'>;
330
+
331
+ function View({
332
+ children,
333
+ subtitle,
334
+ additionalInfo,
335
+ prompt,
336
+ disabled,
337
+ isPartiallyInteractive,
338
+ controlType = 'non-interactive',
339
+ controlProps,
340
+ className = '',
341
+ }: ViewProps) {
342
+ const { ids, describedByIds } = useContext<ListItemContextData>(ListItemContext);
343
+ const isLinkControl = ['navigation'].includes(controlType);
344
+
345
+ const isHrefProvided =
346
+ isLinkControl &&
347
+ !!(controlProps as ListItemNavigationProps)?.href &&
348
+ (controlProps as ListItemNavigationProps)?.href !== '#';
349
+
350
+ const renderExtras = () => (
351
+ <>
352
+ {Boolean(subtitle) && additionalInfo}
353
+ {prompt}
354
+ </>
355
+ );
356
+
357
+ if (isLinkControl && isHrefProvided) {
358
+ return (
359
+ // for link instances of .Navigation, .IconButton, .Button
360
+ <div className={clsx('wds-list-item-gridWrapper', className)}>
361
+ <PrimitiveAnchor
362
+ aria-describedby={describedByIds}
363
+ href={(controlProps as ListItemNavigationProps)?.href}
364
+ target={(controlProps as ListItemNavigationProps)?.target}
365
+ className={clsx('wds-list-item-view d-flex flex-row', {
366
+ 'align-items-center': !subtitle,
367
+ 'wds-list-item-control': controlType === 'navigation',
368
+ })}
369
+ disabled={disabled}
370
+ >
371
+ {children}
372
+ </PrimitiveAnchor>
373
+
374
+ {renderExtras()}
375
+ </div>
376
+ );
377
+ }
378
+
379
+ if (isPartiallyInteractive || controlType === 'non-interactive') {
380
+ return (
381
+ <div className={clsx('wds-list-item-gridWrapper', className)}>
382
+ <div
383
+ className={clsx('wds-list-item-view d-flex flex-row', {
384
+ 'align-items-center': !subtitle,
385
+ })}
386
+ >
387
+ {children}
388
+ </div>
389
+
390
+ {renderExtras()}
391
+ </div>
392
+ );
393
+ }
394
+
395
+ // for form control instances of .Radio, .Checkbox, .Switch, .Button, .Navigation etc
396
+ // Radio cannot be wrapped in a <fieldset> element to announce it as a group.
397
+ const InputWrapper = controlType === 'radio' ? 'div' : 'fieldset';
398
+ return (
399
+ <InputWrapper className={clsx('wds-list-item-gridWrapper', className)}>
400
+ <label
401
+ htmlFor={ids.control}
402
+ className={clsx('wds-list-item-view', {
403
+ 'align-items-center': !subtitle,
404
+ clickable: !disabled,
405
+ fullyInteractive: !isPartiallyInteractive,
406
+ })}
407
+ >
408
+ {children}
409
+ </label>
410
+
411
+ {renderExtras()}
412
+ </InputWrapper>
413
+ );
414
+ }
415
+
416
+ ListItem.Image = Image;
417
+ ListItem.AvatarView = AvatarView;
418
+ ListItem.AvatarLayout = AvatarLayout;
419
+ ListItem.AdditionalInfo = AdditionalInfo;
420
+ ListItem.Checkbox = Checkbox;
421
+ ListItem.Radio = Radio;
422
+ ListItem.IconButton = IconButton;
423
+ ListItem.Navigation = Navigation;
424
+ ListItem.Button = Button;
425
+ ListItem.Switch = Switch;
426
+ ListItem.Prompt = Prompt;
427
+
428
+ export default ListItem;
@@ -0,0 +1,22 @@
1
+ import { createContext } from 'react';
2
+ import type { ListItemTypes, ListItemControlProps, Props as ListItemProps } from './ListItem';
3
+
4
+ export type ListItemContextData = {
5
+ setControlType: (type: ListItemTypes) => void;
6
+ setControlProps: (props: ListItemControlProps) => void;
7
+ ids: {
8
+ title: string;
9
+ subtitle?: string;
10
+ valueTitle?: string;
11
+ valueSubtitle?: string;
12
+ additionalInfo?: string;
13
+ control: string;
14
+ prompt?: string;
15
+ };
16
+ props: Pick<ListItemProps, 'disabled' | 'inverted'>;
17
+ describedByIds: string;
18
+ };
19
+
20
+ export const ListItemContext = createContext<ListItemContextData>(
21
+ null as unknown as ListItemContextData,
22
+ );
@@ -0,0 +1,106 @@
1
+ import { Meta, StoryObj } from '@storybook/react-webpack5';
2
+ import { ListItem } from '../ListItem';
3
+ import {
4
+ SB_LIST_ITEM_ADDITIONAL_INFO as INFO,
5
+ SB_LIST_ITEM_PROMPTS as PROMPTS,
6
+ SB_LIST_ITEM_MEDIA as MEDIA,
7
+ } from '../_stories/subcomponents';
8
+ import type { ListItemNavigationProps } from './ListItemNavigation';
9
+ import { lorem10 } from '../../test-utils';
10
+ import { fn } from 'storybook/test';
11
+
12
+ const meta: Meta<ListItemNavigationProps> = {
13
+ component: ListItem.Navigation,
14
+ title: 'Content/ListItem/ListItem.Navigation',
15
+ parameters: {
16
+ docs: {
17
+ toc: true,
18
+ },
19
+ },
20
+ args: {
21
+ href: 'https://wise.com',
22
+ onClick: undefined,
23
+ target: undefined,
24
+ },
25
+ argTypes: {
26
+ onClick: {
27
+ description:
28
+ 'If `href` is falsy and `onClick` is set, the component will render as an HTML button.',
29
+ },
30
+ target: {
31
+ control: 'select',
32
+ options: [undefined, '_blank', '_self', '_parent', '_top'],
33
+ description:
34
+ 'The `target` attribute for HTML anchor. If set to `_blank`, `rel="noopener noreferrer"` is automatically added to the rendered node.',
35
+ },
36
+ },
37
+ } satisfies Meta<ListItemNavigationProps>;
38
+
39
+ export default meta;
40
+
41
+ type Story = StoryObj<ListItemNavigationProps>;
42
+
43
+ export const Playground: Story = {
44
+ tags: ['!autodocs'],
45
+ render: (args: ListItemNavigationProps) => {
46
+ return (
47
+ <ListItem
48
+ title="List item title"
49
+ subtitle="Subtitle goes here"
50
+ media={MEDIA.avatarSingle}
51
+ control={<ListItem.Navigation {...args} />}
52
+ additionalInfo={INFO.nonInteractive}
53
+ />
54
+ );
55
+ },
56
+ };
57
+
58
+ /**
59
+ * Navigation control can be rendered as HTML anchor or a button
60
+ */
61
+ export const AsButton: Story = {
62
+ args: {
63
+ onClick: fn(),
64
+ },
65
+ render: (args) => {
66
+ return (
67
+ <ol className="list-unstyled">
68
+ <ListItem
69
+ control={<ListItem.Navigation href="https://wise.com" target="_blank" />}
70
+ title="Navigation as link"
71
+ subtitle="This will navigate to an external URL"
72
+ media={MEDIA.avatarSingle}
73
+ />
74
+
75
+ <ListItem
76
+ control={<ListItem.Navigation onClick={args.onClick} />}
77
+ title="Navigation as button"
78
+ subtitle="This will trigger a click handler"
79
+ media={MEDIA.avatarSingle}
80
+ />
81
+ </ol>
82
+ );
83
+ },
84
+ };
85
+
86
+ /**
87
+ * Unlike other controls, the Navigation control has a custom disabled state
88
+ * for improved discoverability, accessibility and overall UX.
89
+ */
90
+ export const Disabled: Story = {
91
+ render: (args) => {
92
+ return (
93
+ <ol className="list-unstyled">
94
+ <ListItem
95
+ disabled
96
+ control={<ListItem.Navigation {...args} />}
97
+ title="This option is disabled"
98
+ subtitle={lorem10}
99
+ additionalInfo={INFO.nonInteractive}
100
+ prompt={PROMPTS.interactive}
101
+ media={MEDIA.avatarSingle}
102
+ />
103
+ </ol>
104
+ );
105
+ },
106
+ };
@@ -0,0 +1,40 @@
1
+ import { ChevronRight, BackslashCircle } from '@transferwise/icons';
2
+ import type { ButtonProps } from '../../button/Button.types';
3
+ import { useListItemControl } from '../useListItemControl';
4
+ import { PrimitiveButton } from '../../primitives';
5
+ import { useContext } from 'react';
6
+ import { ListItemContext } from '../ListItemContext';
7
+
8
+ export type ListItemNavigationProps = Pick<ButtonProps, 'onClick' | 'href' | 'target'>;
9
+
10
+ /**
11
+ * This component allows for rendering a control functionally synonymous with HTML `anchor` or a
12
+ * `button`, giving users a rich way to choose between options and navigate to another screen or
13
+ * step in a flow. It offers only a subset of features of the HTML element in line with the
14
+ * ListItem's constraints.<br />
15
+ * <br />
16
+ * Please refer to the [Design documentation](https://wise.design/components/list-item---navigation) for details.
17
+ */
18
+ export const Navigation = function Navigation({ href = '#', ...props }: ListItemNavigationProps) {
19
+ const { baseItemProps } = useListItemControl('navigation', { href, ...props });
20
+ const { ids, describedByIds } = useContext(ListItemContext);
21
+ const isLink = href !== '#';
22
+ const icon = <ChevronRight size={24} />;
23
+
24
+ if (baseItemProps.disabled) return <BackslashCircle size={24} />;
25
+
26
+ return isLink ? (
27
+ <>{icon}</>
28
+ ) : (
29
+ <PrimitiveButton
30
+ aria-describedby={describedByIds}
31
+ id={ids.control}
32
+ className="btn-unstyled wds-list-item-control"
33
+ onClick={props.onClick as React.MouseEventHandler<HTMLButtonElement> | undefined}
34
+ >
35
+ {icon}
36
+ </PrimitiveButton>
37
+ );
38
+ };
39
+
40
+ Navigation.displayName = 'ListItem.Navigation';
@@ -0,0 +1,2 @@
1
+ export type { ListItemNavigationProps } from './ListItemNavigation';
2
+ export { Navigation } from './ListItemNavigation';
@@ -0,0 +1,49 @@
1
+ import { render, screen, mockMatchMedia } from '../../test-utils';
2
+ import { Sentiment } from '../../common';
3
+ import { type ListItemPromptProps, Prompt } from './ListItemPrompt';
4
+ import { ListItemContext } from '../ListItemContext';
5
+
6
+ mockMatchMedia();
7
+
8
+ const mockContext = {
9
+ setControlType: jest.fn(),
10
+ setControlProps: jest.fn(),
11
+ ids: {
12
+ title: 'title',
13
+ control: 'control',
14
+ prompt: 'prompt',
15
+ additionalInfo: 'additionalInfo',
16
+ valueTitle: 'valueTitle',
17
+ valueSubtitle: 'valueSubtitle',
18
+ subtitle: 'subtitle',
19
+ },
20
+ props: {},
21
+ describedByIds: 'described-by-ids',
22
+ };
23
+
24
+ describe('ListItem.Prompt', () => {
25
+ it('renders the children content', () => {
26
+ render(
27
+ <ListItemContext.Provider value={mockContext}>
28
+ <Prompt sentiment={Sentiment.POSITIVE}>This is a child prompt</Prompt>
29
+ </ListItemContext.Provider>,
30
+ );
31
+ expect(screen.getByText('This is a child prompt')).toBeInTheDocument();
32
+ });
33
+
34
+ describe('render icon', () => {
35
+ it.each([
36
+ [Sentiment.NEUTRAL, 'info-icon'],
37
+ [Sentiment.POSITIVE, 'check-icon'],
38
+ [Sentiment.NEGATIVE, 'cross-icon'],
39
+ [Sentiment.WARNING, 'alert-icon'],
40
+ ] as [ListItemPromptProps['sentiment'], string][])('renders %s icon', (sentiment, iconId) => {
41
+ render(
42
+ <ListItemContext.Provider value={mockContext}>
43
+ <Prompt sentiment={sentiment}>Neutral prompt</Prompt>
44
+ </ListItemContext.Provider>,
45
+ );
46
+ expect(screen.getByTestId(iconId)).toBeInTheDocument();
47
+ });
48
+ });
49
+ });