@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.
- package/build/button/Button.js +1 -0
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.mjs +1 -0
- package/build/button/Button.mjs.map +1 -1
- package/build/common/RadioButton/RadioButton.js +5 -2
- package/build/common/RadioButton/RadioButton.js.map +1 -1
- package/build/common/RadioButton/RadioButton.mjs +5 -2
- package/build/common/RadioButton/RadioButton.mjs.map +1 -1
- package/build/i18n/en.json +2 -0
- package/build/i18n/en.json.js +2 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +2 -0
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/iconButton/IconButton.js.map +1 -1
- package/build/iconButton/IconButton.mjs.map +1 -1
- package/build/image/Image.js.map +1 -1
- package/build/image/Image.mjs.map +1 -1
- package/build/index.js +2 -0
- package/build/index.js.map +1 -1
- package/build/index.mjs +1 -0
- package/build/index.mjs.map +1 -1
- package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.js +56 -0
- package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.js.map +1 -0
- package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.mjs +54 -0
- package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.mjs.map +1 -0
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.js +21 -0
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.js.map +1 -0
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs +19 -0
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs.map +1 -0
- package/build/listItem/AvatarView/ListItemAvatarView.js +21 -0
- package/build/listItem/AvatarView/ListItemAvatarView.js.map +1 -0
- package/build/listItem/AvatarView/ListItemAvatarView.mjs +19 -0
- package/build/listItem/AvatarView/ListItemAvatarView.mjs.map +1 -0
- package/build/listItem/Button/ListItemButton.js +43 -0
- package/build/listItem/Button/ListItemButton.js.map +1 -0
- package/build/listItem/Button/ListItemButton.mjs +41 -0
- package/build/listItem/Button/ListItemButton.mjs.map +1 -0
- package/build/listItem/Checkbox/ListItemCheckbox.js +30 -0
- package/build/listItem/Checkbox/ListItemCheckbox.js.map +1 -0
- package/build/listItem/Checkbox/ListItemCheckbox.mjs +28 -0
- package/build/listItem/Checkbox/ListItemCheckbox.mjs.map +1 -0
- package/build/listItem/IconButton/ListItemIconButton.js +42 -0
- package/build/listItem/IconButton/ListItemIconButton.js.map +1 -0
- package/build/listItem/IconButton/ListItemIconButton.mjs +40 -0
- package/build/listItem/IconButton/ListItemIconButton.mjs.map +1 -0
- package/build/listItem/Image/ListItemImage.js +27 -0
- package/build/listItem/Image/ListItemImage.js.map +1 -0
- package/build/listItem/Image/ListItemImage.mjs +25 -0
- package/build/listItem/Image/ListItemImage.mjs.map +1 -0
- package/build/listItem/ListItem.js +302 -0
- package/build/listItem/ListItem.js.map +1 -0
- package/build/listItem/ListItem.mjs +297 -0
- package/build/listItem/ListItem.mjs.map +1 -0
- package/build/listItem/ListItemContext.js +8 -0
- package/build/listItem/ListItemContext.js.map +1 -0
- package/build/listItem/ListItemContext.mjs +6 -0
- package/build/listItem/ListItemContext.mjs.map +1 -0
- package/build/listItem/Navigation/ListItemNavigation.js +45 -0
- package/build/listItem/Navigation/ListItemNavigation.js.map +1 -0
- package/build/listItem/Navigation/ListItemNavigation.mjs +43 -0
- package/build/listItem/Navigation/ListItemNavigation.mjs.map +1 -0
- package/build/listItem/Prompt/ListItemPrompt.js +59 -0
- package/build/listItem/Prompt/ListItemPrompt.js.map +1 -0
- package/build/listItem/Prompt/ListItemPrompt.mjs +54 -0
- package/build/listItem/Prompt/ListItemPrompt.mjs.map +1 -0
- package/build/listItem/Radio/ListItemRadio.js +30 -0
- package/build/listItem/Radio/ListItemRadio.js.map +1 -0
- package/build/listItem/Radio/ListItemRadio.mjs +28 -0
- package/build/listItem/Radio/ListItemRadio.mjs.map +1 -0
- package/build/listItem/Switch/ListItemSwitch.js +30 -0
- package/build/listItem/Switch/ListItemSwitch.js.map +1 -0
- package/build/listItem/Switch/ListItemSwitch.mjs +28 -0
- package/build/listItem/Switch/ListItemSwitch.mjs.map +1 -0
- package/build/listItem/useListItemControl.js +22 -0
- package/build/listItem/useListItemControl.js.map +1 -0
- package/build/listItem/useListItemControl.mjs +20 -0
- package/build/listItem/useListItemControl.mjs.map +1 -0
- package/build/main.css +657 -0
- package/build/styles/listItem/ListItem.css +657 -0
- package/build/styles/listItem/ListItem.grid.css +362 -0
- package/build/styles/main.css +657 -0
- package/build/switch/Switch.js +2 -0
- package/build/switch/Switch.js.map +1 -1
- package/build/switch/Switch.mjs +2 -0
- package/build/switch/Switch.mjs.map +1 -1
- package/build/types/button/Button.d.ts.map +1 -1
- package/build/types/button/Button.types.d.ts +1 -1
- package/build/types/button/Button.types.d.ts.map +1 -1
- package/build/types/button/index.d.ts +1 -1
- package/build/types/button/index.d.ts.map +1 -1
- package/build/types/common/RadioButton/RadioButton.d.ts +3 -1
- package/build/types/common/RadioButton/RadioButton.d.ts.map +1 -1
- package/build/types/iconButton/IconButton.d.ts +2 -2
- package/build/types/iconButton/IconButton.d.ts.map +1 -1
- package/build/types/image/Image.d.ts +3 -0
- package/build/types/image/Image.d.ts.map +1 -1
- package/build/types/image/index.d.ts +1 -0
- package/build/types/image/index.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/listItem/AdditionalInfo/ListItemAdditionalInfo.d.ts +15 -0
- package/build/types/listItem/AdditionalInfo/ListItemAdditionalInfo.d.ts.map +1 -0
- package/build/types/listItem/AdditionalInfo/index.d.ts +3 -0
- package/build/types/listItem/AdditionalInfo/index.d.ts.map +1 -0
- package/build/types/listItem/AvatarLayout/ListItemAvatarLayout.d.ts +18 -0
- package/build/types/listItem/AvatarLayout/ListItemAvatarLayout.d.ts.map +1 -0
- package/build/types/listItem/AvatarLayout/index.d.ts +3 -0
- package/build/types/listItem/AvatarLayout/index.d.ts.map +1 -0
- package/build/types/listItem/AvatarView/ListItemAvatarView.d.ts +16 -0
- package/build/types/listItem/AvatarView/ListItemAvatarView.d.ts.map +1 -0
- package/build/types/listItem/AvatarView/index.d.ts +3 -0
- package/build/types/listItem/AvatarView/index.d.ts.map +1 -0
- package/build/types/listItem/Button/ListItemButton.d.ts +20 -0
- package/build/types/listItem/Button/ListItemButton.d.ts.map +1 -0
- package/build/types/listItem/Button/index.d.ts +3 -0
- package/build/types/listItem/Button/index.d.ts.map +1 -0
- package/build/types/listItem/Checkbox/ListItemCheckbox.d.ts +14 -0
- package/build/types/listItem/Checkbox/ListItemCheckbox.d.ts.map +1 -0
- package/build/types/listItem/Checkbox/index.d.ts +3 -0
- package/build/types/listItem/Checkbox/index.d.ts.map +1 -0
- package/build/types/listItem/IconButton/ListItemIconButton.d.ts +18 -0
- package/build/types/listItem/IconButton/ListItemIconButton.d.ts.map +1 -0
- package/build/types/listItem/IconButton/index.d.ts +3 -0
- package/build/types/listItem/IconButton/index.d.ts.map +1 -0
- package/build/types/listItem/Image/ListItemImage.d.ts +25 -0
- package/build/types/listItem/Image/ListItemImage.d.ts.map +1 -0
- package/build/types/listItem/Image/index.d.ts +3 -0
- package/build/types/listItem/Image/index.d.ts.map +1 -0
- package/build/types/listItem/ListItem.d.ts +113 -0
- package/build/types/listItem/ListItem.d.ts.map +1 -0
- package/build/types/listItem/ListItemContext.d.ts +18 -0
- package/build/types/listItem/ListItemContext.d.ts.map +1 -0
- package/build/types/listItem/Navigation/ListItemNavigation.d.ts +15 -0
- package/build/types/listItem/Navigation/ListItemNavigation.d.ts.map +1 -0
- package/build/types/listItem/Navigation/index.d.ts +3 -0
- package/build/types/listItem/Navigation/index.d.ts.map +1 -0
- package/build/types/listItem/Prompt/ListItemPrompt.d.ts +16 -0
- package/build/types/listItem/Prompt/ListItemPrompt.d.ts.map +1 -0
- package/build/types/listItem/Prompt/index.d.ts +3 -0
- package/build/types/listItem/Prompt/index.d.ts.map +1 -0
- package/build/types/listItem/Radio/ListItemRadio.d.ts +14 -0
- package/build/types/listItem/Radio/ListItemRadio.d.ts.map +1 -0
- package/build/types/listItem/Radio/index.d.ts +3 -0
- package/build/types/listItem/Radio/index.d.ts.map +1 -0
- package/build/types/listItem/Switch/ListItemSwitch.d.ts +14 -0
- package/build/types/listItem/Switch/ListItemSwitch.d.ts.map +1 -0
- package/build/types/listItem/Switch/index.d.ts +3 -0
- package/build/types/listItem/Switch/index.d.ts.map +1 -0
- package/build/types/listItem/_stories/subcomponents.d.ts +18 -0
- package/build/types/listItem/_stories/subcomponents.d.ts.map +1 -0
- package/build/types/listItem/index.d.ts +14 -0
- package/build/types/listItem/index.d.ts.map +1 -0
- package/build/types/listItem/useListItemControl.d.ts +5 -0
- package/build/types/listItem/useListItemControl.d.ts.map +1 -0
- package/build/types/switch/Switch.d.ts +2 -0
- package/build/types/switch/Switch.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +4 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/build/types/upload/Upload.d.ts +6 -2
- package/build/types/upload/Upload.d.ts.map +1 -1
- package/build/types/upload/Upload.messages.d.ts +8 -0
- package/build/types/upload/Upload.messages.d.ts.map +1 -1
- package/build/types/uploadInput/UploadInput.d.ts +1 -1
- package/build/types/uploadInput/uploadButton/UploadButton.d.ts +4 -2
- package/build/types/uploadInput/uploadButton/UploadButton.d.ts.map +1 -1
- package/build/upload/Upload.js +16 -9
- package/build/upload/Upload.js.map +1 -1
- package/build/upload/Upload.messages.js +6 -0
- package/build/upload/Upload.messages.js.map +1 -1
- package/build/upload/Upload.messages.mjs +6 -0
- package/build/upload/Upload.messages.mjs.map +1 -1
- package/build/upload/Upload.mjs +16 -9
- package/build/upload/Upload.mjs.map +1 -1
- package/build/uploadInput/UploadInput.js +1 -1
- package/build/uploadInput/UploadInput.js.map +1 -1
- package/build/uploadInput/UploadInput.mjs +1 -1
- package/build/uploadInput/UploadInput.mjs.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.js +7 -4
- package/build/uploadInput/uploadButton/UploadButton.js.map +1 -1
- package/build/uploadInput/uploadButton/UploadButton.mjs +7 -4
- package/build/uploadInput/uploadButton/UploadButton.mjs.map +1 -1
- package/package.json +1 -1
- package/src/button/Button.spec.tsx +18 -0
- package/src/button/Button.tsx +5 -1
- package/src/button/Button.types.ts +1 -1
- package/src/button/index.ts +1 -1
- package/src/checkboxButton/CheckboxButton.story.tsx +4 -4
- package/src/common/RadioButton/RadioButton.tsx +6 -1
- package/src/i18n/en.json +2 -0
- package/src/iconButton/IconButton.story.tsx +1 -1
- package/src/iconButton/IconButton.tsx +1 -1
- package/src/image/Image.tsx +3 -0
- package/src/image/index.ts +1 -0
- package/src/index.ts +2 -0
- package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.story.tsx +145 -0
- package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.tsx +36 -0
- package/src/listItem/AdditionalInfo/index.ts +2 -0
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.story.tsx +118 -0
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.tsx +24 -0
- package/src/listItem/AvatarLayout/index.ts +2 -0
- package/src/listItem/AvatarView/ListItemAvatarView.story.tsx +318 -0
- package/src/listItem/AvatarView/ListItemAvatarView.tsx +24 -0
- package/src/listItem/AvatarView/index.ts +2 -0
- package/src/listItem/Button/ListItemButton.spec.tsx +93 -0
- package/src/listItem/Button/ListItemButton.story.tsx +408 -0
- package/src/listItem/Button/ListItemButton.tsx +56 -0
- package/src/listItem/Button/index.ts +2 -0
- package/src/listItem/Checkbox/ListItemCheckbox.story.tsx +107 -0
- package/src/listItem/Checkbox/ListItemCheckbox.tsx +33 -0
- package/src/listItem/Checkbox/index.ts +2 -0
- package/src/listItem/IconButton/ListItemIconButton.story.tsx +236 -0
- package/src/listItem/IconButton/ListItemIconButton.tsx +56 -0
- package/src/listItem/IconButton/index.ts +2 -0
- package/src/listItem/Image/ListItemImage.story.tsx +39 -0
- package/src/listItem/Image/ListItemImage.tsx +40 -0
- package/src/listItem/Image/index.ts +2 -0
- package/src/listItem/ListItem.css +657 -0
- package/src/listItem/ListItem.grid.css +362 -0
- package/src/listItem/ListItem.grid.less +612 -0
- package/src/listItem/ListItem.less +312 -0
- package/src/listItem/ListItem.spec.tsx +97 -0
- package/src/listItem/ListItem.tsx +428 -0
- package/src/listItem/ListItemContext.tsx +22 -0
- package/src/listItem/Navigation/ListItemNavigation.story.tsx +106 -0
- package/src/listItem/Navigation/ListItemNavigation.tsx +40 -0
- package/src/listItem/Navigation/index.ts +2 -0
- package/src/listItem/Prompt/ListItemPrompt.spec.tsx +49 -0
- package/src/listItem/Prompt/ListItemPrompt.story.tsx +199 -0
- package/src/listItem/Prompt/ListItemPrompt.tsx +32 -0
- package/src/listItem/Prompt/index.ts +2 -0
- package/src/listItem/Radio/ListItemRadio.story.tsx +98 -0
- package/src/listItem/Radio/ListItemRadio.tsx +33 -0
- package/src/listItem/Radio/index.ts +2 -0
- package/src/listItem/Switch/ListItemSwitch.story.tsx +69 -0
- package/src/listItem/Switch/ListItemSwitch.tsx +33 -0
- package/src/listItem/Switch/index.ts +2 -0
- package/src/listItem/_stories/ListItem.focus.test.story.tsx +250 -0
- package/src/listItem/_stories/ListItem.layout.test.story.tsx +169 -0
- package/src/listItem/_stories/ListItem.story.tsx +670 -0
- package/src/listItem/_stories/ListItem.variants.test.story.tsx +266 -0
- package/src/listItem/_stories/subcomponents.tsx +139 -0
- package/src/listItem/index.ts +14 -0
- package/src/listItem/useListItemControl.tsx +18 -0
- package/src/main.css +657 -0
- package/src/main.less +1 -0
- package/src/switch/Switch.tsx +4 -0
- package/src/upload/Upload.messages.ts +8 -0
- package/src/upload/Upload.spec.tsx +6 -0
- package/src/upload/Upload.story.tsx +118 -3
- package/src/upload/Upload.tests.story.tsx +5 -3
- package/src/upload/Upload.tsx +24 -15
- package/src/uploadInput/UploadInput.tests.story.tsx +7 -0
- package/src/uploadInput/UploadInput.tsx +2 -2
- package/src/uploadInput/uploadButton/UploadButton.spec.tsx +6 -0
- 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,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
|
+
});
|