@transferwise/components 0.0.0-experimental-751dc12 → 0.0.0-experimental-4341b9c
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 +0 -1
- package/build/button/Button.js.map +1 -1
- package/build/button/Button.mjs +0 -1
- package/build/button/Button.mjs.map +1 -1
- package/build/common/RadioButton/RadioButton.js +2 -5
- package/build/common/RadioButton/RadioButton.js.map +1 -1
- package/build/common/RadioButton/RadioButton.mjs +2 -5
- package/build/common/RadioButton/RadioButton.mjs.map +1 -1
- package/build/common/initials.js +4 -1
- package/build/common/initials.js.map +1 -1
- package/build/common/initials.mjs +4 -1
- package/build/common/initials.mjs.map +1 -1
- package/build/i18n/de.json +2 -0
- package/build/i18n/de.json.js +2 -0
- package/build/i18n/de.json.js.map +1 -1
- package/build/i18n/de.json.mjs +2 -0
- package/build/i18n/de.json.mjs.map +1 -1
- package/build/i18n/fr.json +2 -0
- package/build/i18n/fr.json.js +2 -0
- package/build/i18n/fr.json.js.map +1 -1
- package/build/i18n/fr.json.mjs +2 -0
- package/build/i18n/fr.json.mjs.map +1 -1
- package/build/i18n/hu.json +2 -0
- package/build/i18n/hu.json.js +2 -0
- package/build/i18n/hu.json.js.map +1 -1
- package/build/i18n/hu.json.mjs +2 -0
- package/build/i18n/hu.json.mjs.map +1 -1
- package/build/i18n/it.json +2 -0
- package/build/i18n/it.json.js +2 -0
- package/build/i18n/it.json.js.map +1 -1
- package/build/i18n/it.json.mjs +2 -0
- package/build/i18n/it.json.mjs.map +1 -1
- package/build/i18n/ja.json +2 -0
- package/build/i18n/ja.json.js +2 -0
- package/build/i18n/ja.json.js.map +1 -1
- package/build/i18n/ja.json.mjs +2 -0
- package/build/i18n/ja.json.mjs.map +1 -1
- package/build/i18n/pl.json +2 -0
- package/build/i18n/pl.json.js +2 -0
- package/build/i18n/pl.json.js.map +1 -1
- package/build/i18n/pl.json.mjs +2 -0
- package/build/i18n/pl.json.mjs.map +1 -1
- package/build/i18n/pt.json +2 -0
- package/build/i18n/pt.json.js +2 -0
- package/build/i18n/pt.json.js.map +1 -1
- package/build/i18n/pt.json.mjs +2 -0
- package/build/i18n/pt.json.mjs.map +1 -1
- package/build/i18n/ro.json +2 -0
- package/build/i18n/ro.json.js +2 -0
- package/build/i18n/ro.json.js.map +1 -1
- package/build/i18n/ro.json.mjs +2 -0
- package/build/i18n/ro.json.mjs.map +1 -1
- package/build/i18n/ru.json +2 -0
- package/build/i18n/ru.json.js +2 -0
- package/build/i18n/ru.json.js.map +1 -1
- package/build/i18n/ru.json.mjs +2 -0
- package/build/i18n/ru.json.mjs.map +1 -1
- package/build/i18n/tr.json +2 -0
- package/build/i18n/tr.json.js +2 -0
- package/build/i18n/tr.json.js.map +1 -1
- package/build/i18n/tr.json.mjs +2 -0
- package/build/i18n/tr.json.mjs.map +1 -1
- package/build/i18n/zh-CN.json +2 -0
- package/build/i18n/zh-CN.json.js +2 -0
- package/build/i18n/zh-CN.json.js.map +1 -1
- package/build/i18n/zh-CN.json.mjs +2 -0
- package/build/i18n/zh-CN.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +2 -0
- package/build/i18n/zh-HK.json.js +2 -0
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +2 -0
- package/build/i18n/zh-HK.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 +0 -2
- package/build/index.js.map +1 -1
- package/build/index.mjs +0 -1
- package/build/index.mjs.map +1 -1
- package/build/main.css +0 -709
- package/build/styles/main.css +0 -709
- package/build/switch/Switch.js +0 -2
- package/build/switch/Switch.js.map +1 -1
- package/build/switch/Switch.mjs +0 -2
- 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 +1 -3
- package/build/types/common/RadioButton/RadioButton.d.ts.map +1 -1
- package/build/types/common/initials.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 +0 -3
- package/build/types/image/Image.d.ts.map +1 -1
- package/build/types/image/index.d.ts +0 -1
- package/build/types/image/index.d.ts.map +1 -1
- package/build/types/index.d.ts +0 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/switch/Switch.d.ts +0 -2
- package/build/types/switch/Switch.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/button/Button.spec.tsx +0 -18
- package/src/button/Button.tsx +1 -5
- 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 +1 -6
- package/src/common/initials.spec.tsx +13 -0
- package/src/common/initials.ts +5 -0
- package/src/i18n/de.json +2 -0
- package/src/i18n/fr.json +2 -0
- package/src/i18n/hu.json +2 -0
- package/src/i18n/it.json +2 -0
- package/src/i18n/ja.json +2 -0
- package/src/i18n/pl.json +2 -0
- package/src/i18n/pt.json +2 -0
- package/src/i18n/ro.json +2 -0
- package/src/i18n/ru.json +2 -0
- package/src/i18n/tr.json +2 -0
- package/src/i18n/zh-CN.json +2 -0
- package/src/i18n/zh-HK.json +2 -0
- package/src/iconButton/IconButton.story.tsx +1 -1
- package/src/iconButton/IconButton.tsx +1 -1
- package/src/image/Image.tsx +0 -3
- package/src/image/index.ts +0 -1
- package/src/index.ts +0 -2
- package/src/main.css +0 -709
- package/src/main.less +0 -1
- package/src/switch/Switch.tsx +0 -4
- package/src/test-utils/Parameters.d.ts +77 -0
- package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.js +0 -56
- package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.js.map +0 -1
- package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.mjs +0 -54
- package/build/listItem/AdditionalInfo/ListItemAdditionalInfo.mjs.map +0 -1
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.js +0 -23
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.js.map +0 -1
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs +0 -21
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs.map +0 -1
- package/build/listItem/AvatarView/ListItemAvatarView.js +0 -23
- package/build/listItem/AvatarView/ListItemAvatarView.js.map +0 -1
- package/build/listItem/AvatarView/ListItemAvatarView.mjs +0 -21
- package/build/listItem/AvatarView/ListItemAvatarView.mjs.map +0 -1
- package/build/listItem/Button/ListItemButton.js +0 -43
- package/build/listItem/Button/ListItemButton.js.map +0 -1
- package/build/listItem/Button/ListItemButton.mjs +0 -41
- package/build/listItem/Button/ListItemButton.mjs.map +0 -1
- package/build/listItem/Checkbox/ListItemCheckbox.js +0 -30
- package/build/listItem/Checkbox/ListItemCheckbox.js.map +0 -1
- package/build/listItem/Checkbox/ListItemCheckbox.mjs +0 -28
- package/build/listItem/Checkbox/ListItemCheckbox.mjs.map +0 -1
- package/build/listItem/IconButton/ListItemIconButton.js +0 -42
- package/build/listItem/IconButton/ListItemIconButton.js.map +0 -1
- package/build/listItem/IconButton/ListItemIconButton.mjs +0 -40
- package/build/listItem/IconButton/ListItemIconButton.mjs.map +0 -1
- package/build/listItem/Image/ListItemImage.js +0 -31
- package/build/listItem/Image/ListItemImage.js.map +0 -1
- package/build/listItem/Image/ListItemImage.mjs +0 -29
- package/build/listItem/Image/ListItemImage.mjs.map +0 -1
- package/build/listItem/ListItem.js +0 -308
- package/build/listItem/ListItem.js.map +0 -1
- package/build/listItem/ListItem.mjs +0 -303
- package/build/listItem/ListItem.mjs.map +0 -1
- package/build/listItem/ListItemContext.js +0 -8
- package/build/listItem/ListItemContext.js.map +0 -1
- package/build/listItem/ListItemContext.mjs +0 -6
- package/build/listItem/ListItemContext.mjs.map +0 -1
- package/build/listItem/Navigation/ListItemNavigation.js +0 -45
- package/build/listItem/Navigation/ListItemNavigation.js.map +0 -1
- package/build/listItem/Navigation/ListItemNavigation.mjs +0 -43
- package/build/listItem/Navigation/ListItemNavigation.mjs.map +0 -1
- package/build/listItem/Prompt/ListItemPrompt.js +0 -59
- package/build/listItem/Prompt/ListItemPrompt.js.map +0 -1
- package/build/listItem/Prompt/ListItemPrompt.mjs +0 -54
- package/build/listItem/Prompt/ListItemPrompt.mjs.map +0 -1
- package/build/listItem/Radio/ListItemRadio.js +0 -30
- package/build/listItem/Radio/ListItemRadio.js.map +0 -1
- package/build/listItem/Radio/ListItemRadio.mjs +0 -28
- package/build/listItem/Radio/ListItemRadio.mjs.map +0 -1
- package/build/listItem/Switch/ListItemSwitch.js +0 -30
- package/build/listItem/Switch/ListItemSwitch.js.map +0 -1
- package/build/listItem/Switch/ListItemSwitch.mjs +0 -28
- package/build/listItem/Switch/ListItemSwitch.mjs.map +0 -1
- package/build/listItem/_stories/images/landscape.svg +0 -1
- package/build/listItem/_stories/images/portrait.svg +0 -1
- package/build/listItem/useListItemControl.js +0 -22
- package/build/listItem/useListItemControl.js.map +0 -1
- package/build/listItem/useListItemControl.mjs +0 -20
- package/build/listItem/useListItemControl.mjs.map +0 -1
- package/build/listItem/useListItemMedia.js +0 -21
- package/build/listItem/useListItemMedia.js.map +0 -1
- package/build/listItem/useListItemMedia.mjs +0 -19
- package/build/listItem/useListItemMedia.mjs.map +0 -1
- package/build/styles/listItem/ListItem.css +0 -709
- package/build/styles/listItem/ListItem.grid.css +0 -368
- package/build/types/listItem/AdditionalInfo/ListItemAdditionalInfo.d.ts +0 -15
- package/build/types/listItem/AdditionalInfo/ListItemAdditionalInfo.d.ts.map +0 -1
- package/build/types/listItem/AdditionalInfo/index.d.ts +0 -3
- package/build/types/listItem/AdditionalInfo/index.d.ts.map +0 -1
- package/build/types/listItem/AvatarLayout/ListItemAvatarLayout.d.ts +0 -18
- package/build/types/listItem/AvatarLayout/ListItemAvatarLayout.d.ts.map +0 -1
- package/build/types/listItem/AvatarLayout/index.d.ts +0 -3
- package/build/types/listItem/AvatarLayout/index.d.ts.map +0 -1
- package/build/types/listItem/AvatarView/ListItemAvatarView.d.ts +0 -16
- package/build/types/listItem/AvatarView/ListItemAvatarView.d.ts.map +0 -1
- package/build/types/listItem/AvatarView/index.d.ts +0 -3
- package/build/types/listItem/AvatarView/index.d.ts.map +0 -1
- package/build/types/listItem/Button/ListItemButton.d.ts +0 -20
- package/build/types/listItem/Button/ListItemButton.d.ts.map +0 -1
- package/build/types/listItem/Button/index.d.ts +0 -3
- package/build/types/listItem/Button/index.d.ts.map +0 -1
- package/build/types/listItem/Checkbox/ListItemCheckbox.d.ts +0 -14
- package/build/types/listItem/Checkbox/ListItemCheckbox.d.ts.map +0 -1
- package/build/types/listItem/Checkbox/index.d.ts +0 -3
- package/build/types/listItem/Checkbox/index.d.ts.map +0 -1
- package/build/types/listItem/IconButton/ListItemIconButton.d.ts +0 -18
- package/build/types/listItem/IconButton/ListItemIconButton.d.ts.map +0 -1
- package/build/types/listItem/IconButton/index.d.ts +0 -3
- package/build/types/listItem/IconButton/index.d.ts.map +0 -1
- package/build/types/listItem/Image/ListItemImage.d.ts +0 -25
- package/build/types/listItem/Image/ListItemImage.d.ts.map +0 -1
- package/build/types/listItem/Image/index.d.ts +0 -3
- package/build/types/listItem/Image/index.d.ts.map +0 -1
- package/build/types/listItem/ListItem.d.ts +0 -113
- package/build/types/listItem/ListItem.d.ts.map +0 -1
- package/build/types/listItem/ListItemContext.d.ts +0 -22
- package/build/types/listItem/ListItemContext.d.ts.map +0 -1
- package/build/types/listItem/Navigation/ListItemNavigation.d.ts +0 -15
- package/build/types/listItem/Navigation/ListItemNavigation.d.ts.map +0 -1
- package/build/types/listItem/Navigation/index.d.ts +0 -3
- package/build/types/listItem/Navigation/index.d.ts.map +0 -1
- package/build/types/listItem/Prompt/ListItemPrompt.d.ts +0 -16
- package/build/types/listItem/Prompt/ListItemPrompt.d.ts.map +0 -1
- package/build/types/listItem/Prompt/index.d.ts +0 -3
- package/build/types/listItem/Prompt/index.d.ts.map +0 -1
- package/build/types/listItem/Radio/ListItemRadio.d.ts +0 -14
- package/build/types/listItem/Radio/ListItemRadio.d.ts.map +0 -1
- package/build/types/listItem/Radio/index.d.ts +0 -3
- package/build/types/listItem/Radio/index.d.ts.map +0 -1
- package/build/types/listItem/Switch/ListItemSwitch.d.ts +0 -14
- package/build/types/listItem/Switch/ListItemSwitch.d.ts.map +0 -1
- package/build/types/listItem/Switch/index.d.ts +0 -3
- package/build/types/listItem/Switch/index.d.ts.map +0 -1
- package/build/types/listItem/_stories/subcomponents.d.ts +0 -18
- package/build/types/listItem/_stories/subcomponents.d.ts.map +0 -1
- package/build/types/listItem/index.d.ts +0 -14
- package/build/types/listItem/index.d.ts.map +0 -1
- package/build/types/listItem/test-utils.d.ts +0 -7
- package/build/types/listItem/test-utils.d.ts.map +0 -1
- package/build/types/listItem/useListItemControl.d.ts +0 -5
- package/build/types/listItem/useListItemControl.d.ts.map +0 -1
- package/build/types/listItem/useListItemMedia.d.ts +0 -6
- package/build/types/listItem/useListItemMedia.d.ts.map +0 -1
- package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.spec.tsx +0 -56
- package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.story.tsx +0 -145
- package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.tsx +0 -36
- package/src/listItem/AdditionalInfo/index.ts +0 -2
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.spec.tsx +0 -59
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.story.tsx +0 -118
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.tsx +0 -27
- package/src/listItem/AvatarLayout/index.ts +0 -2
- package/src/listItem/AvatarView/ListItemAvatarView.spec.tsx +0 -75
- package/src/listItem/AvatarView/ListItemAvatarView.story.tsx +0 -318
- package/src/listItem/AvatarView/ListItemAvatarView.tsx +0 -27
- package/src/listItem/AvatarView/index.ts +0 -2
- package/src/listItem/Button/ListItemButton.spec.tsx +0 -68
- package/src/listItem/Button/ListItemButton.story.tsx +0 -408
- package/src/listItem/Button/ListItemButton.tsx +0 -56
- package/src/listItem/Button/index.ts +0 -2
- package/src/listItem/Checkbox/ListItemCheckbox.spec.tsx +0 -82
- package/src/listItem/Checkbox/ListItemCheckbox.story.tsx +0 -107
- package/src/listItem/Checkbox/ListItemCheckbox.tsx +0 -33
- package/src/listItem/Checkbox/index.ts +0 -2
- package/src/listItem/IconButton/ListItemIconButton.spec.tsx +0 -119
- package/src/listItem/IconButton/ListItemIconButton.story.tsx +0 -236
- package/src/listItem/IconButton/ListItemIconButton.tsx +0 -56
- package/src/listItem/IconButton/index.ts +0 -2
- package/src/listItem/Image/ListItemImage.spec.tsx +0 -30
- package/src/listItem/Image/ListItemImage.story.tsx +0 -56
- package/src/listItem/Image/ListItemImage.tsx +0 -48
- package/src/listItem/Image/index.ts +0 -2
- package/src/listItem/ListItem.css +0 -709
- package/src/listItem/ListItem.grid.css +0 -368
- package/src/listItem/ListItem.grid.less +0 -620
- package/src/listItem/ListItem.less +0 -346
- package/src/listItem/ListItem.spec.tsx +0 -1496
- package/src/listItem/ListItem.tsx +0 -441
- package/src/listItem/ListItemContext.tsx +0 -27
- package/src/listItem/Navigation/ListItemNavigation.spec.tsx +0 -59
- package/src/listItem/Navigation/ListItemNavigation.story.tsx +0 -106
- package/src/listItem/Navigation/ListItemNavigation.tsx +0 -40
- package/src/listItem/Navigation/index.ts +0 -2
- package/src/listItem/Prompt/ListItemPrompt.spec.tsx +0 -36
- package/src/listItem/Prompt/ListItemPrompt.story.tsx +0 -201
- package/src/listItem/Prompt/ListItemPrompt.tsx +0 -32
- package/src/listItem/Prompt/index.ts +0 -2
- package/src/listItem/Radio/ListItemRadio.spec.tsx +0 -66
- package/src/listItem/Radio/ListItemRadio.story.tsx +0 -98
- package/src/listItem/Radio/ListItemRadio.tsx +0 -33
- package/src/listItem/Radio/index.ts +0 -2
- package/src/listItem/Switch/ListItemSwitch.spec.tsx +0 -47
- package/src/listItem/Switch/ListItemSwitch.story.tsx +0 -69
- package/src/listItem/Switch/ListItemSwitch.tsx +0 -33
- package/src/listItem/Switch/index.ts +0 -2
- package/src/listItem/_stories/ListItem.focus.test.story.tsx +0 -250
- package/src/listItem/_stories/ListItem.layout.test.story.tsx +0 -338
- package/src/listItem/_stories/ListItem.story.tsx +0 -670
- package/src/listItem/_stories/ListItem.variants.test.story.tsx +0 -271
- package/src/listItem/_stories/images/landscape.svg +0 -1
- package/src/listItem/_stories/images/portrait.svg +0 -1
- package/src/listItem/_stories/subcomponents.tsx +0 -139
- package/src/listItem/index.ts +0 -14
- package/src/listItem/test-utils.tsx +0 -33
- package/src/listItem/useListItemControl.tsx +0 -18
- package/src/listItem/useListItemMedia.tsx +0 -13
|
@@ -1,441 +0,0 @@
|
|
|
1
|
-
/* eslint-disable functional/immutable-data */
|
|
2
|
-
import {
|
|
3
|
-
useContext,
|
|
4
|
-
useId,
|
|
5
|
-
useMemo,
|
|
6
|
-
useState,
|
|
7
|
-
useEffect,
|
|
8
|
-
type PropsWithChildren,
|
|
9
|
-
type ReactNode,
|
|
10
|
-
} from 'react';
|
|
11
|
-
import { Typography } from '../common';
|
|
12
|
-
import Body from '../body';
|
|
13
|
-
import { AdditionalInfo } from './AdditionalInfo';
|
|
14
|
-
import { IconButton, type ListItemIconButtonProps } from './IconButton';
|
|
15
|
-
import { Checkbox, type ListItemCheckboxProps } from './Checkbox';
|
|
16
|
-
import { Navigation, type ListItemNavigationProps } from './Navigation';
|
|
17
|
-
import { clsx } from 'clsx';
|
|
18
|
-
import { Button, type ListItemButtonProps } from './Button';
|
|
19
|
-
import { Radio, type ListItemRadioProps } from './Radio';
|
|
20
|
-
import { Switch, type ListItemSwitchProps } from './Switch';
|
|
21
|
-
import { AvatarLayout } from './AvatarLayout';
|
|
22
|
-
import { AvatarView } from './AvatarView';
|
|
23
|
-
import { Image } from './Image';
|
|
24
|
-
import { Prompt } from './Prompt';
|
|
25
|
-
import { PrimitiveAnchor } from '../primitives';
|
|
26
|
-
import {
|
|
27
|
-
ListItemContext,
|
|
28
|
-
type ListItemContextData,
|
|
29
|
-
type ListItemMediaSize,
|
|
30
|
-
} from './ListItemContext';
|
|
31
|
-
|
|
32
|
-
export type ListItemTypes =
|
|
33
|
-
| 'non-interactive'
|
|
34
|
-
| 'navigation'
|
|
35
|
-
| 'radio'
|
|
36
|
-
| 'checkbox'
|
|
37
|
-
| 'switch'
|
|
38
|
-
| 'button'
|
|
39
|
-
| 'icon-button';
|
|
40
|
-
|
|
41
|
-
export type ListItemControlProps =
|
|
42
|
-
| ListItemNavigationProps
|
|
43
|
-
| ListItemCheckboxProps
|
|
44
|
-
| ListItemButtonProps
|
|
45
|
-
| ListItemIconButtonProps
|
|
46
|
-
| ListItemRadioProps
|
|
47
|
-
| ListItemSwitchProps;
|
|
48
|
-
|
|
49
|
-
export type Props = {
|
|
50
|
-
as?: 'li' | 'div';
|
|
51
|
-
/**
|
|
52
|
-
* Swaps vertical hierarchy of title and subtitle and their corresponding right values.
|
|
53
|
-
*/
|
|
54
|
-
inverted?: boolean;
|
|
55
|
-
disabled?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Highlights the list item as an action to be taken or already taken. <br />
|
|
58
|
-
*/
|
|
59
|
-
spotlight?: 'active' | 'inactive';
|
|
60
|
-
title: ReactNode;
|
|
61
|
-
subtitle?: ReactNode;
|
|
62
|
-
/**
|
|
63
|
-
* Requires `<ListItem.AdditionalInfo />` component as a sole child. <br />
|
|
64
|
-
* Can be only rendered if `subtitle` is also provided.
|
|
65
|
-
*/
|
|
66
|
-
additionalInfo?: ReactNode;
|
|
67
|
-
valueTitle?: ReactNode;
|
|
68
|
-
valueSubtitle?: ReactNode;
|
|
69
|
-
/**
|
|
70
|
-
* Requires one of the following as a sole child: <br />
|
|
71
|
-
* `<ListItem.AvatarView />`,
|
|
72
|
-
* `<ListItem.AvatarLayout />` or
|
|
73
|
-
* `<ListItem.Image />`
|
|
74
|
-
*/
|
|
75
|
-
media?: ReactNode;
|
|
76
|
-
/**
|
|
77
|
-
* Requires one of the following as a sole child: <br/>
|
|
78
|
-
* `<ListItem.Button />`, <br/>
|
|
79
|
-
* `<ListItem.Checkbox />`, <br/>
|
|
80
|
-
* `<ListItem.IconButton />`, <br/>
|
|
81
|
-
* `<ListItem.Navigation />`, <br/>
|
|
82
|
-
* `<ListItem.Radio />`, or
|
|
83
|
-
* `<ListItem.Switch />`
|
|
84
|
-
*/
|
|
85
|
-
control?: ReactNode;
|
|
86
|
-
/**
|
|
87
|
-
* Requires `<ListItem.Prompt />` component as a sole child.
|
|
88
|
-
*/
|
|
89
|
-
prompt?: ReactNode;
|
|
90
|
-
className?: string;
|
|
91
|
-
/**
|
|
92
|
-
* 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 />
|
|
93
|
-
* Controls the width ratio of left side content (title and subtitle) to the right side content.
|
|
94
|
-
*/
|
|
95
|
-
valueColumnWidth?: number;
|
|
96
|
-
id?: string;
|
|
97
|
-
role?: string;
|
|
98
|
-
'aria-labelledby'?: string;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @see [Design documentation](https://wise.design/components/list-item)
|
|
103
|
-
* @see [Storybook documentation](https://storybook.wise.design/?path=/docs/content-listitem--docs)
|
|
104
|
-
*/
|
|
105
|
-
export const ListItem = ({
|
|
106
|
-
as: ListItemElement = 'li',
|
|
107
|
-
title,
|
|
108
|
-
subtitle,
|
|
109
|
-
additionalInfo,
|
|
110
|
-
prompt,
|
|
111
|
-
inverted,
|
|
112
|
-
media,
|
|
113
|
-
spotlight,
|
|
114
|
-
valueTitle,
|
|
115
|
-
valueSubtitle,
|
|
116
|
-
control = null,
|
|
117
|
-
disabled,
|
|
118
|
-
className,
|
|
119
|
-
valueColumnWidth,
|
|
120
|
-
role,
|
|
121
|
-
id,
|
|
122
|
-
'aria-labelledby': ariaLabelledby,
|
|
123
|
-
}: Props) => {
|
|
124
|
-
const idPrefix = useId();
|
|
125
|
-
const [controlProps, setControlProps] = useState<ListItemControlProps>({});
|
|
126
|
-
const [controlType, setControlType] = useState<ListItemTypes>('non-interactive');
|
|
127
|
-
const [mediaSize, setMediaSize] = useState<ListItemMediaSize | undefined>();
|
|
128
|
-
|
|
129
|
-
const ids: ListItemContextData['ids'] = {
|
|
130
|
-
title: `${idPrefix}_title`,
|
|
131
|
-
...(subtitle ? { subtitle: `${idPrefix}_subtitle` } : {}),
|
|
132
|
-
...(valueTitle ? { valueTitle: `${idPrefix}_value-title` } : {}),
|
|
133
|
-
...(valueSubtitle ? { valueSubtitle: `${idPrefix}_value-subtitle` } : {}),
|
|
134
|
-
control: `${idPrefix}_control`,
|
|
135
|
-
...(prompt ? { prompt: `${idPrefix}_prompt` } : {}),
|
|
136
|
-
...(additionalInfo ? { additionalInfo: `${idPrefix}_additional-info` } : {}),
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const isPartiallyInteractive = Boolean(
|
|
140
|
-
(controlType === 'button' || controlType === 'icon-button') &&
|
|
141
|
-
(controlProps as ListItemButtonProps | ListItemIconButtonProps)?.partiallyInteractive,
|
|
142
|
-
);
|
|
143
|
-
const isFullyInteractive = controlType !== 'non-interactive' && !isPartiallyInteractive;
|
|
144
|
-
const isButtonAsLink =
|
|
145
|
-
(controlType === 'button' || controlType === 'icon-button') &&
|
|
146
|
-
Boolean((controlProps as ListItemButtonProps | ListItemIconButtonProps)?.href);
|
|
147
|
-
|
|
148
|
-
const titlesAndValues = [
|
|
149
|
-
inverted ? ids.subtitle : ids.title,
|
|
150
|
-
inverted ? ids.title : ids.subtitle,
|
|
151
|
-
inverted ? ids.valueSubtitle : ids.valueTitle,
|
|
152
|
-
inverted ? ids.valueTitle : ids.valueSubtitle,
|
|
153
|
-
].join(' ');
|
|
154
|
-
const additionalInfoPrompt = [ids.additionalInfo, ids.prompt].filter(Boolean).join(' ');
|
|
155
|
-
|
|
156
|
-
const describedByIds = useMemo(() => {
|
|
157
|
-
return isFullyInteractive && !isButtonAsLink
|
|
158
|
-
? additionalInfoPrompt
|
|
159
|
-
: `${titlesAndValues} ${additionalInfoPrompt}`;
|
|
160
|
-
}, [isFullyInteractive]);
|
|
161
|
-
|
|
162
|
-
const listItemContext = useMemo(
|
|
163
|
-
() => ({
|
|
164
|
-
setControlType,
|
|
165
|
-
setControlProps,
|
|
166
|
-
setMediaSize,
|
|
167
|
-
ids,
|
|
168
|
-
props: { disabled, inverted },
|
|
169
|
-
mediaSize,
|
|
170
|
-
describedByIds,
|
|
171
|
-
}),
|
|
172
|
-
[describedByIds, mediaSize],
|
|
173
|
-
);
|
|
174
|
-
const gridColumnsStyle = {
|
|
175
|
-
'--wds-list-item-body-left': valueColumnWidth ? `${100 - valueColumnWidth}fr` : '50fr',
|
|
176
|
-
'--wds-list-item-body-right': valueColumnWidth ? `${valueColumnWidth}fr` : '50fr',
|
|
177
|
-
} as React.CSSProperties;
|
|
178
|
-
|
|
179
|
-
const getFeatureClassName = () => {
|
|
180
|
-
const partials = [];
|
|
181
|
-
const hasMedia = Boolean(media);
|
|
182
|
-
const hasControl = Boolean(control);
|
|
183
|
-
const hasInfo = Boolean(additionalInfo);
|
|
184
|
-
const hasPrompt = Boolean(prompt);
|
|
185
|
-
|
|
186
|
-
if (hasMedia && hasControl) {
|
|
187
|
-
partials.push('wds-list-item-hasMedia-hasControl');
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (hasMedia && !hasControl) {
|
|
191
|
-
partials.push('wds-list-item-hasMedia-noControl');
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (!hasMedia && hasControl) {
|
|
195
|
-
partials.push('wds-list-item-noMedia-hasControl');
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (!hasMedia && !hasControl) {
|
|
199
|
-
partials.push('wds-list-item-noMedia-noControl');
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (hasInfo && hasPrompt) {
|
|
203
|
-
partials.push('wds-list-item-hasInfo-hasPrompt');
|
|
204
|
-
}
|
|
205
|
-
if (hasInfo && !hasPrompt) {
|
|
206
|
-
partials.push('wds-list-item-hasInfo-noPrompt');
|
|
207
|
-
}
|
|
208
|
-
if (!hasInfo && hasPrompt) {
|
|
209
|
-
partials.push('wds-list-item-noInfo-hasPrompt');
|
|
210
|
-
}
|
|
211
|
-
if (!hasInfo && !hasPrompt) {
|
|
212
|
-
partials.push('wds-list-item-noInfo-noPrompt');
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return partials.join(' ');
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
return (
|
|
219
|
-
<ListItemContext.Provider value={listItemContext}>
|
|
220
|
-
<ListItemElement
|
|
221
|
-
className={clsx(
|
|
222
|
-
'wds-list-item',
|
|
223
|
-
`wds-list-item-${controlType}`,
|
|
224
|
-
getFeatureClassName(),
|
|
225
|
-
{
|
|
226
|
-
'wds-list-item-interactive': isFullyInteractive,
|
|
227
|
-
'wds-list-item-partially-interactive': isPartiallyInteractive,
|
|
228
|
-
[`wds-list-item-spotlight wds-list-item-spotlight-${spotlight}`]:
|
|
229
|
-
isFullyInteractive && !!spotlight,
|
|
230
|
-
disabled,
|
|
231
|
-
},
|
|
232
|
-
className,
|
|
233
|
-
)}
|
|
234
|
-
id={id}
|
|
235
|
-
role={role}
|
|
236
|
-
aria-disabled={disabled}
|
|
237
|
-
aria-labelledby={ariaLabelledby}
|
|
238
|
-
>
|
|
239
|
-
<View
|
|
240
|
-
{...{
|
|
241
|
-
isPartiallyInteractive,
|
|
242
|
-
subtitle,
|
|
243
|
-
additionalInfo,
|
|
244
|
-
disabled,
|
|
245
|
-
prompt,
|
|
246
|
-
controlType,
|
|
247
|
-
controlProps,
|
|
248
|
-
}}
|
|
249
|
-
className={getFeatureClassName()}
|
|
250
|
-
>
|
|
251
|
-
{media && <div className="wds-list-item-media">{media}</div>}
|
|
252
|
-
|
|
253
|
-
{/* Title + Subtitle + Values - Group */}
|
|
254
|
-
<div
|
|
255
|
-
className="wds-list-item-body"
|
|
256
|
-
style={valueColumnWidth ? gridColumnsStyle : undefined}
|
|
257
|
-
>
|
|
258
|
-
{/* Title + Subtitle + Values - Group */}
|
|
259
|
-
<span
|
|
260
|
-
className={clsx({
|
|
261
|
-
'wds-list-item-body-center': title && !subtitle,
|
|
262
|
-
})}
|
|
263
|
-
>
|
|
264
|
-
{(() => {
|
|
265
|
-
const titles = [
|
|
266
|
-
<Body
|
|
267
|
-
key={ids.title}
|
|
268
|
-
id={ids.title}
|
|
269
|
-
type={Typography.BODY_LARGE_BOLD}
|
|
270
|
-
className="wds-list-item-title"
|
|
271
|
-
>
|
|
272
|
-
{title}
|
|
273
|
-
</Body>,
|
|
274
|
-
];
|
|
275
|
-
if (subtitle) {
|
|
276
|
-
titles.push(
|
|
277
|
-
<Body key={ids.subtitle} id={ids.subtitle} className="wds-list-item-subtitle">
|
|
278
|
-
{subtitle}
|
|
279
|
-
</Body>,
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
return inverted ? [...titles].reverse() : titles;
|
|
283
|
-
})()}
|
|
284
|
-
</span>
|
|
285
|
-
|
|
286
|
-
{(valueTitle || valueSubtitle) && (
|
|
287
|
-
<span
|
|
288
|
-
className={clsx('wds-list-item-value', {
|
|
289
|
-
'flex-column': valueTitle !== undefined || valueSubtitle !== undefined,
|
|
290
|
-
'wds-list-item-body-center':
|
|
291
|
-
(valueTitle && !valueSubtitle) || (!valueTitle && valueSubtitle),
|
|
292
|
-
})}
|
|
293
|
-
>
|
|
294
|
-
{(() => {
|
|
295
|
-
const values = [];
|
|
296
|
-
if (valueTitle) {
|
|
297
|
-
values.push(
|
|
298
|
-
<Body
|
|
299
|
-
key={ids.valueTitle}
|
|
300
|
-
id={ids.valueTitle}
|
|
301
|
-
type={Typography.BODY_LARGE_BOLD}
|
|
302
|
-
className="wds-list-item-title-value"
|
|
303
|
-
>
|
|
304
|
-
{valueTitle}
|
|
305
|
-
</Body>,
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
if (valueSubtitle) {
|
|
309
|
-
values.push(
|
|
310
|
-
<Body
|
|
311
|
-
key={ids.valueSubtitle}
|
|
312
|
-
id={ids.valueSubtitle}
|
|
313
|
-
className="wds-list-item-subtitle-value"
|
|
314
|
-
>
|
|
315
|
-
{valueSubtitle}
|
|
316
|
-
</Body>,
|
|
317
|
-
);
|
|
318
|
-
}
|
|
319
|
-
return inverted ? [...values].reverse() : values;
|
|
320
|
-
})()}
|
|
321
|
-
</span>
|
|
322
|
-
)}
|
|
323
|
-
</div>
|
|
324
|
-
|
|
325
|
-
{control === null ? null : (
|
|
326
|
-
<Body
|
|
327
|
-
className={clsx('wds-list-item-control-wrapper', {
|
|
328
|
-
'wds-list-item-button-control': controlType === 'button',
|
|
329
|
-
})}
|
|
330
|
-
style={
|
|
331
|
-
{
|
|
332
|
-
'--wds-list-item-control-wrapper-height': mediaSize ? `${mediaSize}px` : 'auto',
|
|
333
|
-
} as React.CSSProperties
|
|
334
|
-
}
|
|
335
|
-
>
|
|
336
|
-
{control}
|
|
337
|
-
</Body>
|
|
338
|
-
)}
|
|
339
|
-
</View>
|
|
340
|
-
</ListItemElement>
|
|
341
|
-
</ListItemContext.Provider>
|
|
342
|
-
);
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
type ViewProps = PropsWithChildren<{
|
|
346
|
-
isPartiallyInteractive: boolean;
|
|
347
|
-
controlType?: ListItemTypes;
|
|
348
|
-
controlProps?: ListItemControlProps;
|
|
349
|
-
}> &
|
|
350
|
-
Pick<Props, 'subtitle' | 'additionalInfo' | 'disabled' | 'prompt' | 'className'>;
|
|
351
|
-
|
|
352
|
-
function View({
|
|
353
|
-
children,
|
|
354
|
-
subtitle,
|
|
355
|
-
additionalInfo,
|
|
356
|
-
prompt,
|
|
357
|
-
disabled,
|
|
358
|
-
isPartiallyInteractive,
|
|
359
|
-
controlType = 'non-interactive',
|
|
360
|
-
controlProps,
|
|
361
|
-
className = '',
|
|
362
|
-
}: ViewProps) {
|
|
363
|
-
const { ids, describedByIds } = useContext<ListItemContextData>(ListItemContext);
|
|
364
|
-
const isLinkControl = ['navigation'].includes(controlType);
|
|
365
|
-
|
|
366
|
-
const isHrefProvided =
|
|
367
|
-
isLinkControl &&
|
|
368
|
-
!!(controlProps as ListItemNavigationProps)?.href &&
|
|
369
|
-
(controlProps as ListItemNavigationProps)?.href !== '#';
|
|
370
|
-
|
|
371
|
-
const renderExtras = () => (
|
|
372
|
-
<>
|
|
373
|
-
{Boolean(subtitle) && additionalInfo}
|
|
374
|
-
{prompt}
|
|
375
|
-
</>
|
|
376
|
-
);
|
|
377
|
-
|
|
378
|
-
if (isLinkControl && isHrefProvided) {
|
|
379
|
-
return (
|
|
380
|
-
// for link instances of .Navigation, .IconButton, .Button
|
|
381
|
-
<div className={clsx('wds-list-item-gridWrapper', className)}>
|
|
382
|
-
<PrimitiveAnchor
|
|
383
|
-
aria-describedby={describedByIds}
|
|
384
|
-
href={(controlProps as ListItemNavigationProps)?.href}
|
|
385
|
-
target={(controlProps as ListItemNavigationProps)?.target}
|
|
386
|
-
className={clsx('wds-list-item-view d-flex flex-row', {
|
|
387
|
-
'wds-list-item-control': controlType === 'navigation',
|
|
388
|
-
})}
|
|
389
|
-
disabled={disabled}
|
|
390
|
-
>
|
|
391
|
-
{children}
|
|
392
|
-
</PrimitiveAnchor>
|
|
393
|
-
|
|
394
|
-
{renderExtras()}
|
|
395
|
-
</div>
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (isPartiallyInteractive || controlType === 'non-interactive') {
|
|
400
|
-
return (
|
|
401
|
-
<div className={clsx('wds-list-item-gridWrapper', className)}>
|
|
402
|
-
<div className={clsx('wds-list-item-view d-flex flex-row')}>{children}</div>
|
|
403
|
-
|
|
404
|
-
{renderExtras()}
|
|
405
|
-
</div>
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// for form control instances of .Radio, .Checkbox, .Switch, .Button, .Navigation etc
|
|
410
|
-
// Radio cannot be wrapped in a <fieldset> element to announce it as a group.
|
|
411
|
-
const InputWrapper = controlType === 'radio' ? 'div' : 'fieldset';
|
|
412
|
-
return (
|
|
413
|
-
<InputWrapper className={clsx('wds-list-item-gridWrapper', className)}>
|
|
414
|
-
<label
|
|
415
|
-
htmlFor={ids.control}
|
|
416
|
-
className={clsx('wds-list-item-view', {
|
|
417
|
-
clickable: !disabled,
|
|
418
|
-
fullyInteractive: !isPartiallyInteractive,
|
|
419
|
-
})}
|
|
420
|
-
>
|
|
421
|
-
{children}
|
|
422
|
-
</label>
|
|
423
|
-
|
|
424
|
-
{renderExtras()}
|
|
425
|
-
</InputWrapper>
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
ListItem.Image = Image;
|
|
430
|
-
ListItem.AvatarView = AvatarView;
|
|
431
|
-
ListItem.AvatarLayout = AvatarLayout;
|
|
432
|
-
ListItem.AdditionalInfo = AdditionalInfo;
|
|
433
|
-
ListItem.Checkbox = Checkbox;
|
|
434
|
-
ListItem.Radio = Radio;
|
|
435
|
-
ListItem.IconButton = IconButton;
|
|
436
|
-
ListItem.Navigation = Navigation;
|
|
437
|
-
ListItem.Button = Button;
|
|
438
|
-
ListItem.Switch = Switch;
|
|
439
|
-
ListItem.Prompt = Prompt;
|
|
440
|
-
|
|
441
|
-
export default ListItem;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
import type { ListItemTypes, ListItemControlProps, Props as ListItemProps } from './ListItem';
|
|
3
|
-
import type { ListItemAvatarViewProps } from './AvatarView';
|
|
4
|
-
|
|
5
|
-
export type ListItemMediaSize = 32 | 40 | 48 | 56 | 72;
|
|
6
|
-
|
|
7
|
-
export type ListItemContextData = {
|
|
8
|
-
setControlType: (type: ListItemTypes) => void;
|
|
9
|
-
setControlProps: (props: ListItemControlProps) => void;
|
|
10
|
-
setMediaSize: (size: ListItemMediaSize | undefined) => void;
|
|
11
|
-
ids: {
|
|
12
|
-
title: string;
|
|
13
|
-
subtitle?: string;
|
|
14
|
-
valueTitle?: string;
|
|
15
|
-
valueSubtitle?: string;
|
|
16
|
-
additionalInfo?: string;
|
|
17
|
-
control: string;
|
|
18
|
-
prompt?: string;
|
|
19
|
-
};
|
|
20
|
-
props: Pick<ListItemProps, 'disabled' | 'inverted'>;
|
|
21
|
-
mediaSize?: ListItemAvatarViewProps['size'];
|
|
22
|
-
describedByIds: string;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const ListItemContext = createContext<ListItemContextData>(
|
|
26
|
-
null as unknown as ListItemContextData,
|
|
27
|
-
);
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { render, screen } from '../../test-utils';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { ListItem, type Props as ListItemProps } from '../ListItem';
|
|
4
|
-
|
|
5
|
-
describe('ListItem.Navigation', () => {
|
|
6
|
-
const renderWith = (overrides: Partial<ListItemProps> = {}) =>
|
|
7
|
-
render(<ListItem title="Test Title" {...overrides} />);
|
|
8
|
-
|
|
9
|
-
describe('as button', () => {
|
|
10
|
-
it('renders as button if onClick is set but no href', () => {
|
|
11
|
-
renderWith({ control: <ListItem.Navigation onClick={() => {}} /> });
|
|
12
|
-
expect(screen.getByRole('button')).toBeInTheDocument();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('handles onClick events', async () => {
|
|
16
|
-
const handleClick = jest.fn();
|
|
17
|
-
renderWith({ control: <ListItem.Navigation onClick={handleClick} /> });
|
|
18
|
-
|
|
19
|
-
await userEvent.click(screen.getByRole('button'));
|
|
20
|
-
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('respects disabled state', async () => {
|
|
24
|
-
renderWith({
|
|
25
|
-
disabled: true,
|
|
26
|
-
control: <ListItem.Navigation onClick={jest.fn()} />,
|
|
27
|
-
});
|
|
28
|
-
expect(screen.getByTestId('backslash-circle-icon')).toBeInTheDocument();
|
|
29
|
-
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
|
30
|
-
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('as link', () => {
|
|
35
|
-
it('renders a link if href is set', () => {
|
|
36
|
-
renderWith({ control: <ListItem.Navigation href="/test-path" /> });
|
|
37
|
-
|
|
38
|
-
expect(screen.queryByRole('button')).not.toBeInTheDocument();
|
|
39
|
-
expect(screen.getByRole('link')).toBeInTheDocument();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('respects target prop', () => {
|
|
43
|
-
renderWith({
|
|
44
|
-
control: <ListItem.Navigation href="/test-path" target="_blank" />,
|
|
45
|
-
});
|
|
46
|
-
const link = screen.getByRole('link');
|
|
47
|
-
expect(link).toHaveAttribute('target', '_blank');
|
|
48
|
-
expect(link).toHaveAttribute('rel', 'noopener noreferrer');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('renders disabled icon when ListItem is disabled', () => {
|
|
52
|
-
renderWith({
|
|
53
|
-
disabled: true,
|
|
54
|
-
control: <ListItem.Navigation href="wise.com" />,
|
|
55
|
-
});
|
|
56
|
-
expect(screen.getByTestId('backslash-circle-icon')).toBeInTheDocument();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
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={16} />;
|
|
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';
|