@transferwise/components 0.0.0-experimental-29d0f94 → 0.0.0-experimental-4b1de0a
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/common/initials.js +1 -4
- package/build/common/initials.js.map +1 -1
- package/build/common/initials.mjs +1 -4
- package/build/common/initials.mjs.map +1 -1
- package/build/i18n/de.json +0 -2
- package/build/i18n/de.json.js +0 -2
- package/build/i18n/de.json.js.map +1 -1
- package/build/i18n/de.json.mjs +0 -2
- package/build/i18n/de.json.mjs.map +1 -1
- package/build/i18n/fr.json +0 -2
- package/build/i18n/fr.json.js +0 -2
- package/build/i18n/fr.json.js.map +1 -1
- package/build/i18n/fr.json.mjs +0 -2
- package/build/i18n/fr.json.mjs.map +1 -1
- package/build/i18n/hu.json +0 -2
- package/build/i18n/hu.json.js +0 -2
- package/build/i18n/hu.json.js.map +1 -1
- package/build/i18n/hu.json.mjs +0 -2
- package/build/i18n/hu.json.mjs.map +1 -1
- package/build/i18n/it.json +0 -2
- package/build/i18n/it.json.js +0 -2
- package/build/i18n/it.json.js.map +1 -1
- package/build/i18n/it.json.mjs +0 -2
- package/build/i18n/it.json.mjs.map +1 -1
- package/build/i18n/ja.json +0 -2
- package/build/i18n/ja.json.js +0 -2
- package/build/i18n/ja.json.js.map +1 -1
- package/build/i18n/ja.json.mjs +0 -2
- package/build/i18n/ja.json.mjs.map +1 -1
- package/build/i18n/pl.json +0 -2
- package/build/i18n/pl.json.js +0 -2
- package/build/i18n/pl.json.js.map +1 -1
- package/build/i18n/pl.json.mjs +0 -2
- package/build/i18n/pl.json.mjs.map +1 -1
- package/build/i18n/ro.json +0 -2
- package/build/i18n/ro.json.js +0 -2
- package/build/i18n/ro.json.js.map +1 -1
- package/build/i18n/ro.json.mjs +0 -2
- package/build/i18n/ro.json.mjs.map +1 -1
- package/build/i18n/ru.json +0 -2
- package/build/i18n/ru.json.js +0 -2
- package/build/i18n/ru.json.js.map +1 -1
- package/build/i18n/ru.json.mjs +0 -2
- package/build/i18n/ru.json.mjs.map +1 -1
- package/build/i18n/tr.json +0 -2
- package/build/i18n/tr.json.js +0 -2
- package/build/i18n/tr.json.js.map +1 -1
- package/build/i18n/tr.json.mjs +0 -2
- package/build/i18n/tr.json.mjs.map +1 -1
- package/build/i18n/zh-CN.json +0 -2
- package/build/i18n/zh-CN.json.js +0 -2
- package/build/i18n/zh-CN.json.js.map +1 -1
- package/build/i18n/zh-CN.json.mjs +0 -2
- package/build/i18n/zh-CN.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +0 -2
- package/build/i18n/zh-HK.json.js +0 -2
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +0 -2
- 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 +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 +23 -0
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.js.map +1 -0
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs +21 -0
- package/build/listItem/AvatarLayout/ListItemAvatarLayout.mjs.map +1 -0
- package/build/listItem/AvatarView/ListItemAvatarView.js +23 -0
- package/build/listItem/AvatarView/ListItemAvatarView.js.map +1 -0
- package/build/listItem/AvatarView/ListItemAvatarView.mjs +21 -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 +31 -0
- package/build/listItem/Image/ListItemImage.js.map +1 -0
- package/build/listItem/Image/ListItemImage.mjs +29 -0
- package/build/listItem/Image/ListItemImage.mjs.map +1 -0
- package/build/listItem/ListItem.js +312 -0
- package/build/listItem/ListItem.js.map +1 -0
- package/build/listItem/ListItem.mjs +307 -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/listItem/useListItemMedia.js +21 -0
- package/build/listItem/useListItemMedia.js.map +1 -0
- package/build/listItem/useListItemMedia.mjs +19 -0
- package/build/listItem/useListItemMedia.mjs.map +1 -0
- package/build/main.css +773 -1
- package/build/styles/avatarView/AvatarView.css +3 -1
- package/build/styles/listItem/ListItem.css +770 -0
- package/build/styles/listItem/ListItem.grid.css +370 -0
- package/build/styles/main.css +773 -1
- 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/test-utils/assets/placeholder-landscape.svg +1 -0
- package/build/test-utils/assets/placeholder-portrait.svg +1 -0
- 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/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 +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 +22 -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/helpers.d.ts +27 -0
- package/build/types/listItem/_stories/helpers.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/test-utils.d.ts +7 -0
- package/build/types/listItem/test-utils.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/listItem/useListItemMedia.d.ts +6 -0
- package/build/types/listItem/useListItemMedia.d.ts.map +1 -0
- package/build/types/switch/Switch.d.ts +3 -1
- package/build/types/switch/Switch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/avatarView/AvatarView.css +3 -1
- package/src/avatarView/AvatarView.less +2 -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/common/initials.spec.tsx +0 -13
- package/src/common/initials.ts +0 -5
- package/src/i18n/de.json +0 -2
- package/src/i18n/fr.json +0 -2
- package/src/i18n/hu.json +0 -2
- package/src/i18n/it.json +0 -2
- package/src/i18n/ja.json +0 -2
- package/src/i18n/pl.json +0 -2
- package/src/i18n/ro.json +0 -2
- package/src/i18n/ru.json +0 -2
- package/src/i18n/tr.json +0 -2
- package/src/i18n/zh-CN.json +0 -2
- package/src/i18n/zh-HK.json +0 -2
- 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.spec.tsx +56 -0
- package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.story.tsx +195 -0
- package/src/listItem/AdditionalInfo/ListItemAdditionalInfo.tsx +36 -0
- package/src/listItem/AdditionalInfo/index.ts +2 -0
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.spec.tsx +59 -0
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.story.tsx +121 -0
- package/src/listItem/AvatarLayout/ListItemAvatarLayout.tsx +27 -0
- package/src/listItem/AvatarLayout/index.ts +2 -0
- package/src/listItem/AvatarView/ListItemAvatarView.spec.tsx +75 -0
- package/src/listItem/AvatarView/ListItemAvatarView.story.tsx +336 -0
- package/src/listItem/AvatarView/ListItemAvatarView.tsx +27 -0
- package/src/listItem/AvatarView/index.ts +2 -0
- package/src/listItem/Button/ListItemButton.spec.tsx +68 -0
- package/src/listItem/Button/ListItemButton.story.tsx +466 -0
- package/src/listItem/Button/ListItemButton.tsx +56 -0
- package/src/listItem/Button/index.ts +2 -0
- package/src/listItem/Checkbox/ListItemCheckbox.spec.tsx +82 -0
- package/src/listItem/Checkbox/ListItemCheckbox.story.tsx +125 -0
- package/src/listItem/Checkbox/ListItemCheckbox.tsx +33 -0
- package/src/listItem/Checkbox/index.ts +2 -0
- package/src/listItem/IconButton/ListItemIconButton.spec.tsx +119 -0
- package/src/listItem/IconButton/ListItemIconButton.story.tsx +249 -0
- package/src/listItem/IconButton/ListItemIconButton.tsx +56 -0
- package/src/listItem/IconButton/index.ts +2 -0
- package/src/listItem/Image/ListItemImage.spec.tsx +30 -0
- package/src/listItem/Image/ListItemImage.story.tsx +77 -0
- package/src/listItem/Image/ListItemImage.tsx +48 -0
- package/src/listItem/Image/index.ts +2 -0
- package/src/listItem/ListItem.css +770 -0
- package/src/listItem/ListItem.grid.css +370 -0
- package/src/listItem/ListItem.grid.less +622 -0
- package/src/listItem/ListItem.less +421 -0
- package/src/listItem/ListItem.spec.tsx +1496 -0
- package/src/listItem/ListItem.tsx +447 -0
- package/src/listItem/ListItemContext.tsx +27 -0
- package/src/listItem/Navigation/ListItemNavigation.spec.tsx +59 -0
- package/src/listItem/Navigation/ListItemNavigation.story.tsx +109 -0
- package/src/listItem/Navigation/ListItemNavigation.tsx +40 -0
- package/src/listItem/Navigation/index.ts +2 -0
- package/src/listItem/Prompt/ListItemPrompt.spec.tsx +36 -0
- package/src/listItem/Prompt/ListItemPrompt.story.tsx +201 -0
- package/src/listItem/Prompt/ListItemPrompt.tsx +32 -0
- package/src/listItem/Prompt/index.ts +2 -0
- package/src/listItem/Radio/ListItemRadio.spec.tsx +66 -0
- package/src/listItem/Radio/ListItemRadio.story.tsx +108 -0
- package/src/listItem/Radio/ListItemRadio.tsx +33 -0
- package/src/listItem/Radio/index.ts +2 -0
- package/src/listItem/Switch/ListItemSwitch.spec.tsx +47 -0
- package/src/listItem/Switch/ListItemSwitch.story.tsx +77 -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 +353 -0
- package/src/listItem/_stories/ListItem.scenarios.story.tsx +209 -0
- package/src/listItem/_stories/ListItem.story.tsx +772 -0
- package/src/listItem/_stories/ListItem.variants.test.story.tsx +271 -0
- package/src/listItem/_stories/helpers.tsx +53 -0
- package/src/listItem/_stories/subcomponents.tsx +139 -0
- package/src/listItem/index.ts +14 -0
- package/src/listItem/test-utils.tsx +33 -0
- package/src/listItem/useListItemControl.tsx +18 -0
- package/src/listItem/useListItemMedia.tsx +13 -0
- package/src/main.css +773 -1
- package/src/main.less +1 -0
- package/src/switch/Switch.tsx +5 -1
- package/src/test-utils/assets/placeholder-landscape.svg +1 -0
- package/src/test-utils/assets/placeholder-portrait.svg +1 -0
- package/src/test-utils/Parameters.d.ts +0 -77
|
@@ -0,0 +1,447 @@
|
|
|
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
|
+
{spotlight === 'inactive' && (
|
|
240
|
+
<svg aria-hidden="true" className="wds-list-item-spotlight__border">
|
|
241
|
+
<rect />
|
|
242
|
+
</svg>
|
|
243
|
+
)}
|
|
244
|
+
|
|
245
|
+
<View
|
|
246
|
+
{...{
|
|
247
|
+
isPartiallyInteractive,
|
|
248
|
+
subtitle,
|
|
249
|
+
additionalInfo,
|
|
250
|
+
disabled,
|
|
251
|
+
prompt,
|
|
252
|
+
controlType,
|
|
253
|
+
controlProps,
|
|
254
|
+
}}
|
|
255
|
+
className={getFeatureClassName()}
|
|
256
|
+
>
|
|
257
|
+
{media && <div className="wds-list-item-media">{media}</div>}
|
|
258
|
+
|
|
259
|
+
{/* Title + Subtitle + Values - Group */}
|
|
260
|
+
<div
|
|
261
|
+
className="wds-list-item-body"
|
|
262
|
+
style={valueColumnWidth ? gridColumnsStyle : undefined}
|
|
263
|
+
>
|
|
264
|
+
{/* Title + Subtitle + Values - Group */}
|
|
265
|
+
<span
|
|
266
|
+
className={clsx({
|
|
267
|
+
'wds-list-item-body-center': title && !subtitle,
|
|
268
|
+
})}
|
|
269
|
+
>
|
|
270
|
+
{(() => {
|
|
271
|
+
const titles = [
|
|
272
|
+
<Body
|
|
273
|
+
key={ids.title}
|
|
274
|
+
id={ids.title}
|
|
275
|
+
type={Typography.BODY_LARGE_BOLD}
|
|
276
|
+
className="wds-list-item-title"
|
|
277
|
+
>
|
|
278
|
+
{title}
|
|
279
|
+
</Body>,
|
|
280
|
+
];
|
|
281
|
+
if (subtitle) {
|
|
282
|
+
titles.push(
|
|
283
|
+
<Body key={ids.subtitle} id={ids.subtitle} className="wds-list-item-subtitle">
|
|
284
|
+
{subtitle}
|
|
285
|
+
</Body>,
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
return inverted ? [...titles].reverse() : titles;
|
|
289
|
+
})()}
|
|
290
|
+
</span>
|
|
291
|
+
|
|
292
|
+
{(valueTitle || valueSubtitle) && (
|
|
293
|
+
<span
|
|
294
|
+
className={clsx('wds-list-item-value', {
|
|
295
|
+
'flex-column': valueTitle !== undefined || valueSubtitle !== undefined,
|
|
296
|
+
'wds-list-item-body-center':
|
|
297
|
+
(valueTitle && !valueSubtitle) || (!valueTitle && valueSubtitle),
|
|
298
|
+
})}
|
|
299
|
+
>
|
|
300
|
+
{(() => {
|
|
301
|
+
const values = [];
|
|
302
|
+
if (valueTitle) {
|
|
303
|
+
values.push(
|
|
304
|
+
<Body
|
|
305
|
+
key={ids.valueTitle}
|
|
306
|
+
id={ids.valueTitle}
|
|
307
|
+
type={Typography.BODY_LARGE_BOLD}
|
|
308
|
+
className="wds-list-item-title-value"
|
|
309
|
+
>
|
|
310
|
+
{valueTitle}
|
|
311
|
+
</Body>,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
if (valueSubtitle) {
|
|
315
|
+
values.push(
|
|
316
|
+
<Body
|
|
317
|
+
key={ids.valueSubtitle}
|
|
318
|
+
id={ids.valueSubtitle}
|
|
319
|
+
className="wds-list-item-subtitle-value"
|
|
320
|
+
>
|
|
321
|
+
{valueSubtitle}
|
|
322
|
+
</Body>,
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
return inverted ? [...values].reverse() : values;
|
|
326
|
+
})()}
|
|
327
|
+
</span>
|
|
328
|
+
)}
|
|
329
|
+
</div>
|
|
330
|
+
|
|
331
|
+
{control === null ? null : (
|
|
332
|
+
<Body
|
|
333
|
+
className={clsx('wds-list-item-control-wrapper', {
|
|
334
|
+
'wds-list-item-button-control': controlType === 'button',
|
|
335
|
+
})}
|
|
336
|
+
style={
|
|
337
|
+
{
|
|
338
|
+
'--wds-list-item-control-wrapper-height': mediaSize ? `${mediaSize}px` : 'auto',
|
|
339
|
+
} as React.CSSProperties
|
|
340
|
+
}
|
|
341
|
+
>
|
|
342
|
+
{control}
|
|
343
|
+
</Body>
|
|
344
|
+
)}
|
|
345
|
+
</View>
|
|
346
|
+
</ListItemElement>
|
|
347
|
+
</ListItemContext.Provider>
|
|
348
|
+
);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
type ViewProps = PropsWithChildren<{
|
|
352
|
+
isPartiallyInteractive: boolean;
|
|
353
|
+
controlType?: ListItemTypes;
|
|
354
|
+
controlProps?: ListItemControlProps;
|
|
355
|
+
}> &
|
|
356
|
+
Pick<Props, 'subtitle' | 'additionalInfo' | 'disabled' | 'prompt' | 'className'>;
|
|
357
|
+
|
|
358
|
+
function View({
|
|
359
|
+
children,
|
|
360
|
+
subtitle,
|
|
361
|
+
additionalInfo,
|
|
362
|
+
prompt,
|
|
363
|
+
disabled,
|
|
364
|
+
isPartiallyInteractive,
|
|
365
|
+
controlType = 'non-interactive',
|
|
366
|
+
controlProps,
|
|
367
|
+
className = '',
|
|
368
|
+
}: ViewProps) {
|
|
369
|
+
const { ids, describedByIds } = useContext<ListItemContextData>(ListItemContext);
|
|
370
|
+
const isLinkControl = ['navigation'].includes(controlType);
|
|
371
|
+
|
|
372
|
+
const isHrefProvided =
|
|
373
|
+
isLinkControl &&
|
|
374
|
+
!!(controlProps as ListItemNavigationProps)?.href &&
|
|
375
|
+
(controlProps as ListItemNavigationProps)?.href !== '#';
|
|
376
|
+
|
|
377
|
+
const renderExtras = () => (
|
|
378
|
+
<>
|
|
379
|
+
{Boolean(subtitle) && additionalInfo}
|
|
380
|
+
{prompt}
|
|
381
|
+
</>
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
if (isLinkControl && isHrefProvided) {
|
|
385
|
+
return (
|
|
386
|
+
// for link instances of .Navigation, .IconButton, .Button
|
|
387
|
+
<div className={clsx('wds-list-item-gridWrapper', className)}>
|
|
388
|
+
<PrimitiveAnchor
|
|
389
|
+
aria-describedby={describedByIds}
|
|
390
|
+
href={(controlProps as ListItemNavigationProps)?.href}
|
|
391
|
+
target={(controlProps as ListItemNavigationProps)?.target}
|
|
392
|
+
className={clsx('wds-list-item-view d-flex flex-row', {
|
|
393
|
+
'wds-list-item-control': controlType === 'navigation',
|
|
394
|
+
})}
|
|
395
|
+
disabled={disabled}
|
|
396
|
+
>
|
|
397
|
+
{children}
|
|
398
|
+
</PrimitiveAnchor>
|
|
399
|
+
|
|
400
|
+
{renderExtras()}
|
|
401
|
+
</div>
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (isPartiallyInteractive || controlType === 'non-interactive') {
|
|
406
|
+
return (
|
|
407
|
+
<div className={clsx('wds-list-item-gridWrapper', className)}>
|
|
408
|
+
<div className={clsx('wds-list-item-view d-flex flex-row')}>{children}</div>
|
|
409
|
+
|
|
410
|
+
{renderExtras()}
|
|
411
|
+
</div>
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// for form control instances of .Radio, .Checkbox, .Switch, .Button, .Navigation etc
|
|
416
|
+
// Radio cannot be wrapped in a <fieldset> element to announce it as a group.
|
|
417
|
+
const InputWrapper = controlType === 'radio' ? 'div' : 'fieldset';
|
|
418
|
+
return (
|
|
419
|
+
<InputWrapper className={clsx('wds-list-item-gridWrapper', className)}>
|
|
420
|
+
<label
|
|
421
|
+
htmlFor={ids.control}
|
|
422
|
+
className={clsx('wds-list-item-view', {
|
|
423
|
+
clickable: !disabled,
|
|
424
|
+
fullyInteractive: !isPartiallyInteractive,
|
|
425
|
+
})}
|
|
426
|
+
>
|
|
427
|
+
{children}
|
|
428
|
+
</label>
|
|
429
|
+
|
|
430
|
+
{renderExtras()}
|
|
431
|
+
</InputWrapper>
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
ListItem.Image = Image;
|
|
436
|
+
ListItem.AvatarView = AvatarView;
|
|
437
|
+
ListItem.AvatarLayout = AvatarLayout;
|
|
438
|
+
ListItem.AdditionalInfo = AdditionalInfo;
|
|
439
|
+
ListItem.Checkbox = Checkbox;
|
|
440
|
+
ListItem.Radio = Radio;
|
|
441
|
+
ListItem.IconButton = IconButton;
|
|
442
|
+
ListItem.Navigation = Navigation;
|
|
443
|
+
ListItem.Button = Button;
|
|
444
|
+
ListItem.Switch = Switch;
|
|
445
|
+
ListItem.Prompt = Prompt;
|
|
446
|
+
|
|
447
|
+
export default ListItem;
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
);
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-webpack5';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
3
|
+
import { lorem10 } from '../../test-utils';
|
|
4
|
+
import { ListItem } from '../ListItem';
|
|
5
|
+
import {
|
|
6
|
+
SB_LIST_ITEM_ADDITIONAL_INFO as INFO,
|
|
7
|
+
SB_LIST_ITEM_PROMPTS as PROMPTS,
|
|
8
|
+
SB_LIST_ITEM_MEDIA as MEDIA,
|
|
9
|
+
} from '../_stories/subcomponents';
|
|
10
|
+
import type { ListItemNavigationProps } from './ListItemNavigation';
|
|
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
|
+
parameters: {
|
|
66
|
+
controls: { disable: true },
|
|
67
|
+
},
|
|
68
|
+
render: (args) => {
|
|
69
|
+
return (
|
|
70
|
+
<ol className="list-unstyled">
|
|
71
|
+
<ListItem
|
|
72
|
+
control={<ListItem.Navigation href="https://wise.com" target="_blank" />}
|
|
73
|
+
title="Navigation as link"
|
|
74
|
+
subtitle="This will navigate to an external URL"
|
|
75
|
+
media={MEDIA.avatarSingle}
|
|
76
|
+
/>
|
|
77
|
+
|
|
78
|
+
<ListItem
|
|
79
|
+
control={<ListItem.Navigation onClick={args.onClick} />}
|
|
80
|
+
title="Navigation as button"
|
|
81
|
+
subtitle="This will trigger a click handler"
|
|
82
|
+
media={MEDIA.avatarSingle}
|
|
83
|
+
/>
|
|
84
|
+
</ol>
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Unlike other controls, the Navigation control has a custom disabled state
|
|
91
|
+
* for improved discoverability, accessibility and overall UX.
|
|
92
|
+
*/
|
|
93
|
+
export const Disabled: Story = {
|
|
94
|
+
render: (args) => {
|
|
95
|
+
return (
|
|
96
|
+
<ol className="list-unstyled">
|
|
97
|
+
<ListItem
|
|
98
|
+
disabled
|
|
99
|
+
control={<ListItem.Navigation {...args} />}
|
|
100
|
+
title="This option is disabled"
|
|
101
|
+
subtitle={lorem10}
|
|
102
|
+
additionalInfo={INFO.nonInteractive}
|
|
103
|
+
prompt={PROMPTS.interactive}
|
|
104
|
+
media={MEDIA.avatarSingle}
|
|
105
|
+
/>
|
|
106
|
+
</ol>
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
};
|
|
@@ -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={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';
|