@transferwise/components 0.0.0-experimental-76b7ab6 → 0.0.0-experimental-fd6654d
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/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/index.mjs +1 -1
- package/build/main.css +185 -3
- package/build/styles/item/Item.css +185 -0
- package/build/styles/main.css +185 -3
- package/build/styles/switch/Switch.css +0 -3
- package/build/test-utils/assets/apple-pay-logo.svg +84 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/item/Item.d.ts +41 -0
- package/build/types/item/Item.d.ts.map +1 -0
- package/build/types/item/ItemAdditionalInfo.d.ts +9 -0
- package/build/types/item/ItemAdditionalInfo.d.ts.map +1 -0
- package/build/types/item/ItemCheckbox.d.ts +4 -0
- package/build/types/item/ItemCheckbox.d.ts.map +1 -0
- package/build/types/item/ItemIconButton.d.ts +6 -0
- package/build/types/item/ItemIconButton.d.ts.map +1 -0
- package/build/types/item/ItemMedia.d.ts +19 -0
- package/build/types/item/ItemMedia.d.ts.map +1 -0
- package/build/types/item/ItemNavigation.d.ts +4 -0
- package/build/types/item/ItemNavigation.d.ts.map +1 -0
- package/build/types/item/index.d.ts +6 -0
- package/build/types/item/index.d.ts.map +1 -0
- package/build/types/item/prompt/Prompt.d.ts +12 -0
- package/build/types/item/prompt/Prompt.d.ts.map +1 -0
- package/build/types/test-utils/fake-data.d.ts +2 -0
- package/build/types/test-utils/fake-data.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/item/Item.css +185 -0
- package/src/item/Item.less +178 -0
- package/src/item/Item.story.tsx +124 -0
- package/src/item/Item.tsx +170 -0
- package/src/item/ItemAdditionalInfo.tsx +31 -0
- package/src/item/ItemCheckbox.tsx +16 -0
- package/src/item/ItemIconButton.tsx +17 -0
- package/src/item/ItemMedia.tsx +52 -0
- package/src/item/ItemNavigation.tsx +16 -0
- package/src/item/index.ts +6 -0
- package/src/item/prompt/Prompt.spec.tsx +77 -0
- package/src/item/prompt/Prompt.story.tsx +170 -0
- package/src/item/prompt/Prompt.tsx +44 -0
- package/src/main.css +185 -3
- package/src/main.less +1 -0
- package/src/switch/Switch.css +0 -3
- package/src/switch/Switch.less +0 -1
- package/src/test-utils/assets/apple-pay-logo.svg +84 -0
- package/src/test-utils/fake-data.ts +5 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
.np-item {
|
|
2
|
+
padding: var(--size-16);
|
|
3
|
+
border-radius: var(--radius-large);
|
|
4
|
+
background-color: var(--color-background-screen);
|
|
5
|
+
gap: var(--size-16);
|
|
6
|
+
|
|
7
|
+
&-interactive {
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
&:hover {
|
|
10
|
+
background-color: var(--color-background-screen-hover);
|
|
11
|
+
}
|
|
12
|
+
&:active {
|
|
13
|
+
background-color: var(--color-background-screen-active);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&-media {
|
|
18
|
+
|
|
19
|
+
&-image {
|
|
20
|
+
width: var(--item-media-image-size);
|
|
21
|
+
height: var(--item-media-image-size);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&-title {
|
|
26
|
+
color: var(--color-content-primary);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&-additional-info {
|
|
30
|
+
color: var(--color-content-tertiary);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&-value {
|
|
34
|
+
flex: 0 0 auto;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&-control {
|
|
38
|
+
flex: 0 0 auto;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&-spotlight {
|
|
42
|
+
&-active {
|
|
43
|
+
background-color: var(--color-background-neutral);
|
|
44
|
+
|
|
45
|
+
&:hover {
|
|
46
|
+
background-color: var(--color-background-neutral-hover);
|
|
47
|
+
}
|
|
48
|
+
&:active {
|
|
49
|
+
background-color: var(--color-background-neutral-active);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
&-inactive {
|
|
54
|
+
background-color: color-mix(in srgb, var(--color-background-neutral) 25%, transparent);
|
|
55
|
+
border: 1px dashed var(--color-border-neutral);
|
|
56
|
+
|
|
57
|
+
&:hover {
|
|
58
|
+
background-color: color-mix(in srgb, var(--color-background-neutral-hover) 25%, transparent);
|
|
59
|
+
}
|
|
60
|
+
&:active {
|
|
61
|
+
background-color: color-mix(in srgb, var(--color-background-neutral-active) 25%, transparent);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&-prompt {
|
|
67
|
+
display: inline-flex;
|
|
68
|
+
padding-top: calc(var(--padding-x-small) / 2);
|
|
69
|
+
padding-bottom: calc(var(--padding-x-small) / 2);
|
|
70
|
+
padding-left: calc(var(--padding-x-small) - 1px);
|
|
71
|
+
padding-right: var(--padding-x-small);
|
|
72
|
+
border-radius: var(--radius-small);
|
|
73
|
+
word-break: break-word;
|
|
74
|
+
overflow-wrap: break-word;
|
|
75
|
+
|
|
76
|
+
.np-prompt-icon {
|
|
77
|
+
padding-right: calc(var(--size-12) / 2);
|
|
78
|
+
padding-top: calc(var(--size-4) - 1px);
|
|
79
|
+
padding-bottom: calc(var(--size-4) - 1px);
|
|
80
|
+
|
|
81
|
+
.tw-icon-tags,
|
|
82
|
+
.tw-icon-confetti {
|
|
83
|
+
color: var(--color-sentiment-positive-primary);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
a {
|
|
88
|
+
text-underline-offset: calc(var(--size-4) / 2);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
&.np-prompt-interactive {
|
|
92
|
+
text-decoration: none;
|
|
93
|
+
cursor: pointer;
|
|
94
|
+
border: none;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&.negative {
|
|
98
|
+
background-color: var(--color-sentiment-negative-secondary);
|
|
99
|
+
color: var(--color-sentiment-negative-primary);
|
|
100
|
+
a {
|
|
101
|
+
color: var(--color-sentiment-negative-primary);
|
|
102
|
+
&:hover {
|
|
103
|
+
color: var(--color-sentiment-negative-primary-hover);
|
|
104
|
+
}
|
|
105
|
+
&:active {
|
|
106
|
+
color: var(--color-sentiment-negative-primary-active);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
.np-prompt-interactive& {
|
|
110
|
+
&:hover {
|
|
111
|
+
background-color: color-mix(in srgb, var(--color-sentiment-negative-secondary) 95%, var(--color-sentiment-negative-primary));
|
|
112
|
+
}
|
|
113
|
+
&:active {
|
|
114
|
+
background-color: color-mix(in srgb, var(--color-sentiment-negative-secondary) 90%, var(--color-sentiment-negative-primary));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
&.positive,
|
|
119
|
+
&.discount,
|
|
120
|
+
&.savings {
|
|
121
|
+
background-color: var(--color-sentiment-positive-secondary);
|
|
122
|
+
color: var(--color-sentiment-positive-primary);
|
|
123
|
+
a {
|
|
124
|
+
color: var(--color-sentiment-positive-primary);
|
|
125
|
+
&:hover {
|
|
126
|
+
color: var(--color-sentiment-positive-primary-hover);
|
|
127
|
+
}
|
|
128
|
+
&:active {
|
|
129
|
+
color: var(--color-sentiment-positive-primary-active);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
.np-prompt-interactive& {
|
|
133
|
+
&:hover {
|
|
134
|
+
background-color: color-mix(in srgb, var(--color-sentiment-positive-secondary) 95%, var(--color-sentiment-positive-primary));
|
|
135
|
+
}
|
|
136
|
+
&:active {
|
|
137
|
+
background-color: color-mix(in srgb, var(--color-sentiment-positive-secondary) 90%, var(--color-sentiment-positive-primary));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
&.neutral {
|
|
142
|
+
background-color: var(--color-background-neutral);
|
|
143
|
+
color: var(--color-content-primary);
|
|
144
|
+
a {
|
|
145
|
+
color: var(--color-content-primary);
|
|
146
|
+
}
|
|
147
|
+
.np-prompt-interactive& {
|
|
148
|
+
&:hover {
|
|
149
|
+
background-color: var(--color-background-neutral-hover);
|
|
150
|
+
}
|
|
151
|
+
&:active {
|
|
152
|
+
background-color: var(--color-background-neutral-active);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
&.warning {
|
|
157
|
+
background-color: var(--color-sentiment-warning-secondary);
|
|
158
|
+
color: var(--color-sentiment-warning-content);
|
|
159
|
+
a {
|
|
160
|
+
color: var(--color-sentiment-warning-content);
|
|
161
|
+
&:hover {
|
|
162
|
+
color: var(--color-sentiment-warning-content-hover);
|
|
163
|
+
}
|
|
164
|
+
&:active {
|
|
165
|
+
color: var(--color-sentiment-warning-content-active);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
.np-prompt-interactive& {
|
|
169
|
+
&:hover {
|
|
170
|
+
background-color: color-mix(in srgb, var(--color-sentiment-warning-secondary) 90%, var(--color-sentiment-warning-primary));
|
|
171
|
+
}
|
|
172
|
+
&:active {
|
|
173
|
+
background-color: color-mix(in srgb, var(--color-sentiment-warning-secondary) 80%, var(--color-sentiment-warning-primary));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import Item, { Props as ItemProps } from './Item';
|
|
2
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { lorem10, lorem20, lorem40, lorem5 } from '../test-utils';
|
|
4
|
+
import { Flag } from '@wise/art';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
component: Item,
|
|
8
|
+
title: 'Content/Item',
|
|
9
|
+
} satisfies Meta<ItemProps>;
|
|
10
|
+
|
|
11
|
+
type Story = StoryObj<ItemProps>;
|
|
12
|
+
|
|
13
|
+
// TODO: delete this story later when we have more peace of the List Item puzzle
|
|
14
|
+
export const TempPlayground: Story = {
|
|
15
|
+
render: () => (
|
|
16
|
+
<div>
|
|
17
|
+
<Item
|
|
18
|
+
media={
|
|
19
|
+
<Item.AvatarView badge={{ type: 'action' }}>
|
|
20
|
+
<Flag code="BBD" />
|
|
21
|
+
</Item.AvatarView>
|
|
22
|
+
}
|
|
23
|
+
title="Test title"
|
|
24
|
+
subtitle="Test subtitle"
|
|
25
|
+
additionalInfo={<Item.AdditionalInfo>{lorem10}</Item.AdditionalInfo>}
|
|
26
|
+
/>
|
|
27
|
+
<Item
|
|
28
|
+
media={
|
|
29
|
+
<Item.AvatarLayout
|
|
30
|
+
avatars={[{ asset: <Flag code="BBD" /> }, { asset: <Flag code="MXN" /> }]}
|
|
31
|
+
/>
|
|
32
|
+
}
|
|
33
|
+
title="Test title"
|
|
34
|
+
subtitle={lorem10}
|
|
35
|
+
additionalInfo={<Item.AdditionalInfo>{lorem20}</Item.AdditionalInfo>}
|
|
36
|
+
/>
|
|
37
|
+
<Item
|
|
38
|
+
media={
|
|
39
|
+
<Item.AvatarLayout
|
|
40
|
+
size={72}
|
|
41
|
+
orientation="diagonal"
|
|
42
|
+
avatars={[{ asset: <Flag code="BBD" /> }, { asset: <Flag code="MXN" /> }]}
|
|
43
|
+
/>
|
|
44
|
+
}
|
|
45
|
+
title="Test title"
|
|
46
|
+
subtitle={lorem10}
|
|
47
|
+
valueTitle="100 GBP"
|
|
48
|
+
valueSubtitle="100 USD"
|
|
49
|
+
additionalInfo={<Item.AdditionalInfo>{lorem20}</Item.AdditionalInfo>}
|
|
50
|
+
/>
|
|
51
|
+
<Item
|
|
52
|
+
media={<Item.AvatarView profileType="BUSINESS" notification />}
|
|
53
|
+
title="Test title"
|
|
54
|
+
subtitle="Test subtitle"
|
|
55
|
+
additionalInfo={
|
|
56
|
+
<Item.AdditionalInfo
|
|
57
|
+
action={{ label: 'Learn more', href: 'https://wise.com', target: '_blank' }}
|
|
58
|
+
>
|
|
59
|
+
{lorem10}
|
|
60
|
+
</Item.AdditionalInfo>
|
|
61
|
+
}
|
|
62
|
+
prompt={<Item.Prompt type="negative">You have done something wrong</Item.Prompt>}
|
|
63
|
+
/>
|
|
64
|
+
<Item
|
|
65
|
+
media={<Item.AvatarView imgSrc="../avatar-square-dude.webp" selected />}
|
|
66
|
+
title="Test title"
|
|
67
|
+
additionalInfo={<Item.AdditionalInfo>{lorem10}</Item.AdditionalInfo>}
|
|
68
|
+
prompt={
|
|
69
|
+
<Item.Prompt
|
|
70
|
+
type="discount"
|
|
71
|
+
action={{
|
|
72
|
+
href: 'https://wise.com',
|
|
73
|
+
target: '_blank',
|
|
74
|
+
'aria-label': 'clickable prompt',
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
The whole prompt is secretly clickable
|
|
78
|
+
</Item.Prompt>
|
|
79
|
+
}
|
|
80
|
+
/>
|
|
81
|
+
|
|
82
|
+
<Item
|
|
83
|
+
media={<Item.Image src="../apple-pay-logo.svg" />}
|
|
84
|
+
title="Accepting Apple Pay"
|
|
85
|
+
subtitle={lorem10}
|
|
86
|
+
/>
|
|
87
|
+
|
|
88
|
+
<Item
|
|
89
|
+
media={<Item.Image src="../wise-card.svg" />}
|
|
90
|
+
title="Wise Business Card"
|
|
91
|
+
subtitle={lorem5}
|
|
92
|
+
/>
|
|
93
|
+
</div>
|
|
94
|
+
),
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const ItemRadio: Story = {
|
|
98
|
+
render: () => (
|
|
99
|
+
<div>
|
|
100
|
+
{/* Basic */}
|
|
101
|
+
{/* with additional info */}
|
|
102
|
+
{/* with prompt */}
|
|
103
|
+
{/* Disabled */}
|
|
104
|
+
{/* Spotlight */}
|
|
105
|
+
{/* Active */}
|
|
106
|
+
</div>
|
|
107
|
+
),
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export const ItemButton: Story = {
|
|
111
|
+
render: () => (
|
|
112
|
+
<div>
|
|
113
|
+
{/* Basic */}
|
|
114
|
+
{/* with additional info */}
|
|
115
|
+
{/* with prompt */}
|
|
116
|
+
{/* partially interactive */}
|
|
117
|
+
{/* Disabled */}
|
|
118
|
+
{/* Spotlight */}
|
|
119
|
+
{/* Active */}
|
|
120
|
+
</div>
|
|
121
|
+
),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// add intaces with dark mode
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { createContext, ReactNode, useId, useMemo, useState } from 'react';
|
|
2
|
+
import { Typography } from '../common';
|
|
3
|
+
import Body from '../body';
|
|
4
|
+
import { AdditionalInfo } from './ItemAdditionalInfo';
|
|
5
|
+
import { IconButton } from './ItemIconButton';
|
|
6
|
+
import { Checkbox } from './ItemCheckbox';
|
|
7
|
+
import { Navigation } from './ItemNavigation';
|
|
8
|
+
import { clsx } from 'clsx';
|
|
9
|
+
import { AvatarLayout, AvatarView, Image } from './ItemMedia';
|
|
10
|
+
import Prompt from './prompt/Prompt';
|
|
11
|
+
|
|
12
|
+
export type ItemTypes =
|
|
13
|
+
| 'non-interactive'
|
|
14
|
+
| 'navigation'
|
|
15
|
+
| 'radio'
|
|
16
|
+
| 'checkbox'
|
|
17
|
+
| 'switch'
|
|
18
|
+
| 'button'
|
|
19
|
+
| 'icon-button';
|
|
20
|
+
|
|
21
|
+
export type Props = {
|
|
22
|
+
as?: 'li' | 'div' | 'span';
|
|
23
|
+
inverted?: boolean;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
spotlight?: 'active' | 'inactive';
|
|
26
|
+
title: ReactNode;
|
|
27
|
+
subtitle?: ReactNode;
|
|
28
|
+
additionalInfo?: ReactNode;
|
|
29
|
+
valueTitle?: ReactNode;
|
|
30
|
+
valueSubtitle?: ReactNode;
|
|
31
|
+
media?: ReactNode;
|
|
32
|
+
control?: ReactNode;
|
|
33
|
+
prompt?: ReactNode;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ItemContextData = {
|
|
37
|
+
setControlType: (type: ItemTypes) => void;
|
|
38
|
+
ids: {
|
|
39
|
+
label: string;
|
|
40
|
+
additionalInfo: string;
|
|
41
|
+
value: string;
|
|
42
|
+
control: string;
|
|
43
|
+
prompt: string;
|
|
44
|
+
};
|
|
45
|
+
props: Pick<Props, 'as' | 'disabled' | 'inverted'>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// @ts-expect-error for now let's mock it with `null` value
|
|
49
|
+
// but actually by default we should specify `setControlType('none')`
|
|
50
|
+
export const ItemContext = createContext<ItemContextData>(null);
|
|
51
|
+
|
|
52
|
+
export const Item = ({
|
|
53
|
+
as: View = 'li',
|
|
54
|
+
title,
|
|
55
|
+
subtitle,
|
|
56
|
+
additionalInfo,
|
|
57
|
+
prompt,
|
|
58
|
+
inverted,
|
|
59
|
+
media,
|
|
60
|
+
spotlight = undefined,
|
|
61
|
+
valueTitle,
|
|
62
|
+
valueSubtitle,
|
|
63
|
+
control = null,
|
|
64
|
+
disabled,
|
|
65
|
+
}: Props) => {
|
|
66
|
+
/*
|
|
67
|
+
const returnType = (): ReactNode => {
|
|
68
|
+
switch (type) {
|
|
69
|
+
case 'Navigation':
|
|
70
|
+
return <Chevron orientation={Position.RIGHT} disabled />;
|
|
71
|
+
case 'Radio':
|
|
72
|
+
return <RadioButton name="Hello" checked />;
|
|
73
|
+
case 'Checkbox':
|
|
74
|
+
return <CheckboxButton name="Hello" checked />;
|
|
75
|
+
case 'Switch':
|
|
76
|
+
return <Switch onClick={() => console.log('clicked')} />;
|
|
77
|
+
case 'Button':
|
|
78
|
+
return <Button v2>Hello</Button>;
|
|
79
|
+
case 'IconButton':
|
|
80
|
+
return (
|
|
81
|
+
<IconButton size={40} priority="minimal">
|
|
82
|
+
<InfoCircle />
|
|
83
|
+
</IconButton>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
*/
|
|
88
|
+
const idPrefix = useId();
|
|
89
|
+
|
|
90
|
+
const [controlType, setControlType] = useState<ItemTypes>('non-interactive');
|
|
91
|
+
const ids = {
|
|
92
|
+
label: `${idPrefix}_label`,
|
|
93
|
+
value: `${idPrefix}_value`,
|
|
94
|
+
control: `${idPrefix}_control`,
|
|
95
|
+
prompt: `${idPrefix}_prompt`,
|
|
96
|
+
additionalInfo: `${idPrefix}_additional-info`,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const itemCtx = useMemo(
|
|
100
|
+
() => ({ setControlType, ids, props: { as: View, disabled, inverted } }),
|
|
101
|
+
[],
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<ItemContext.Provider value={itemCtx}>
|
|
106
|
+
<View
|
|
107
|
+
className={clsx(
|
|
108
|
+
'np-item',
|
|
109
|
+
{ 'np-item-interactive': controlType !== 'non-interactive' },
|
|
110
|
+
`np-item-${controlType}`,
|
|
111
|
+
'd-flex flex-row',
|
|
112
|
+
{ 'align-items-center': !subtitle },
|
|
113
|
+
{
|
|
114
|
+
[`np-item-spotlight-${spotlight}`]: !!spotlight,
|
|
115
|
+
},
|
|
116
|
+
)}
|
|
117
|
+
aria-describedby={[ids.additionalInfo].join(' ')}
|
|
118
|
+
>
|
|
119
|
+
{media && <div className="np-item-media">{media}</div>}
|
|
120
|
+
|
|
121
|
+
{/* Title + Subtitle + Values + Additional Info - Group */}
|
|
122
|
+
<div>
|
|
123
|
+
{/* Title + Subtitle + Values - Group */}
|
|
124
|
+
<div className="d-flex justify-content-between">
|
|
125
|
+
<span>
|
|
126
|
+
{/* @ts-expect-error div can have role and aria-lavel props */}
|
|
127
|
+
<Body
|
|
128
|
+
type={Typography.BODY_LARGE_BOLD}
|
|
129
|
+
className="np-item-title"
|
|
130
|
+
// for a11y this needs to be a header but for SEO it shouldn't be `h*` tag
|
|
131
|
+
// so we enable header semantics via `role` and `aria-level` attrs
|
|
132
|
+
role="heading"
|
|
133
|
+
aria-level="4"
|
|
134
|
+
>
|
|
135
|
+
{title}
|
|
136
|
+
</Body>
|
|
137
|
+
<Body className="np-item-subtitle">{subtitle}</Body>
|
|
138
|
+
</span>
|
|
139
|
+
{(valueTitle || valueSubtitle) && (
|
|
140
|
+
<span id={ids.value} className="np-item-value">
|
|
141
|
+
<Body type={Typography.BODY_LARGE_BOLD} className="np-item-title-value">
|
|
142
|
+
{valueTitle}
|
|
143
|
+
</Body>
|
|
144
|
+
<Body className="np-item-subtitle-value">{valueSubtitle}</Body>
|
|
145
|
+
</span>
|
|
146
|
+
)}
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
{/* Additional Info and Prompt here */}
|
|
150
|
+
{Boolean(subtitle) && additionalInfo}
|
|
151
|
+
</div>
|
|
152
|
+
{control === null ? null : <Body className="np-item-control">{control}</Body>}
|
|
153
|
+
{prompt}
|
|
154
|
+
</View>
|
|
155
|
+
</ItemContext.Provider>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/* eslint-disable functional/immutable-data */
|
|
160
|
+
Item.Image = Image;
|
|
161
|
+
Item.AvatarView = AvatarView;
|
|
162
|
+
Item.AvatarLayout = AvatarLayout;
|
|
163
|
+
Item.AdditionalInfo = AdditionalInfo;
|
|
164
|
+
Item.Checkbox = Checkbox;
|
|
165
|
+
Item.IconButton = IconButton;
|
|
166
|
+
Item.Navigation = Navigation;
|
|
167
|
+
Item.Prompt = Prompt;
|
|
168
|
+
/* eslint-enable functional/immutable-data */
|
|
169
|
+
|
|
170
|
+
export default Item;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PropsWithChildren, useContext } from 'react';
|
|
2
|
+
import { ItemContext, ItemContextData } from './Item';
|
|
3
|
+
import Body from '../body';
|
|
4
|
+
import Link, { LinkProps } from '../link';
|
|
5
|
+
import { Typography } from '../common';
|
|
6
|
+
|
|
7
|
+
export type ItemAdditionalInfoProps = PropsWithChildren<{
|
|
8
|
+
action?: Pick<LinkProps, 'href' | 'onClick' | 'target'> & { label?: string };
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
export const AdditionalInfo = function ({ children, action }: ItemAdditionalInfoProps) {
|
|
12
|
+
const { ids } = useContext<ItemContextData>(ItemContext);
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Body
|
|
16
|
+
type={Typography.BODY_DEFAULT}
|
|
17
|
+
id={ids.additionalInfo}
|
|
18
|
+
className="np-item-additional-info"
|
|
19
|
+
>
|
|
20
|
+
{children}
|
|
21
|
+
{action ? (
|
|
22
|
+
<>
|
|
23
|
+
{' '}
|
|
24
|
+
<Link href={action.href} target={action.target} onClick={action.onClick}>
|
|
25
|
+
{action.label}
|
|
26
|
+
</Link>
|
|
27
|
+
</>
|
|
28
|
+
) : null}
|
|
29
|
+
</Body>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useContext, useEffect } from 'react';
|
|
2
|
+
import CheckboxButton from '../checkboxButton';
|
|
3
|
+
import { CheckboxButtonProps } from '../checkboxButton/CheckboxButton';
|
|
4
|
+
import { ItemContext, ItemContextData } from './Item';
|
|
5
|
+
|
|
6
|
+
export type ItemCheckboxProps = Pick<CheckboxButtonProps, 'checked' | 'indeterminate' | 'onChange'>;
|
|
7
|
+
|
|
8
|
+
export const Checkbox = function (props: ItemCheckboxProps) {
|
|
9
|
+
const { setControlType, props: baseItemProps } = useContext<ItemContextData>(ItemContext);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setControlType('checkbox');
|
|
13
|
+
}, []);
|
|
14
|
+
|
|
15
|
+
return <CheckboxButton disabled={baseItemProps.disabled} {...props} />;
|
|
16
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useContext, useEffect } from 'react';
|
|
2
|
+
import { default as IconButtonComp, IconButtonProps } from '../iconButton';
|
|
3
|
+
import { ItemContext, ItemContextData } from './Item';
|
|
4
|
+
|
|
5
|
+
export type ItemIconButtonProps = Pick<IconButtonProps, 'onClick' | 'href' | 'target'> & {
|
|
6
|
+
partialInteractivity?: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const IconButton = function (props: ItemIconButtonProps) {
|
|
10
|
+
const { setControlType } = useContext<ItemContextData>(ItemContext);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setControlType('icon-button');
|
|
14
|
+
}, []);
|
|
15
|
+
|
|
16
|
+
return <IconButtonComp {...props} size={32} />;
|
|
17
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { default as AvatarViewComp, AvatarViewProps } from '../avatarView';
|
|
2
|
+
import { default as AvatarLayoutComp, AvatarLayoutProps } from '../avatarLayout';
|
|
3
|
+
import { default as ImageComp, ImageProps } from '../image/Image';
|
|
4
|
+
import { clsx } from 'clsx';
|
|
5
|
+
|
|
6
|
+
type SizeProp = { size?: 32 | 40 | 48 | 56 | 72 };
|
|
7
|
+
|
|
8
|
+
export type ItemAvatarViewProps = Omit<AvatarViewProps, 'size' | 'interactive'> & SizeProp;
|
|
9
|
+
|
|
10
|
+
export const AvatarView = ({ className, size = 48, ...props }: ItemAvatarViewProps) => {
|
|
11
|
+
return (
|
|
12
|
+
<AvatarViewComp
|
|
13
|
+
{...props}
|
|
14
|
+
size={size}
|
|
15
|
+
className={clsx('np-item-media-avatar-view', className)}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ItemAvatarLayoutProps = Omit<AvatarLayoutProps, 'size' | 'interactive'> & SizeProp;
|
|
21
|
+
|
|
22
|
+
export const AvatarLayout = ({ className, size = 48, ...props }: ItemAvatarLayoutProps) => {
|
|
23
|
+
return (
|
|
24
|
+
<AvatarLayoutComp
|
|
25
|
+
{...props}
|
|
26
|
+
size={size}
|
|
27
|
+
className={clsx('np-item-media-avatar-layout', className)}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type ItemImageProps = Omit<ImageProps, 'stretch' | 'shrink' | 'id' | 'alt'> &
|
|
33
|
+
SizeProp & {
|
|
34
|
+
alt?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* TODO: mention that image is for rare cases not for DS illustrations, they discouraged
|
|
39
|
+
*/
|
|
40
|
+
export const Image = ({ alt = '', size = 48, ...props }: ItemImageProps) => {
|
|
41
|
+
return (
|
|
42
|
+
<div
|
|
43
|
+
className={clsx('np-item-media-image')}
|
|
44
|
+
style={{
|
|
45
|
+
// @ts-expect-error CSS custom props allowed
|
|
46
|
+
'--item-media-image-size': `${size}px`,
|
|
47
|
+
}}
|
|
48
|
+
>
|
|
49
|
+
<ImageComp {...props} alt={alt} />
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ChevronRight, BillSplit as Disabled } from '@transferwise/icons';
|
|
2
|
+
import { ButtonProps } from '../button/Button.types';
|
|
3
|
+
import Item, { ItemContext, ItemContextData } from './Item';
|
|
4
|
+
import { useContext, useEffect } from 'react';
|
|
5
|
+
|
|
6
|
+
export type ItemNavigationProps = Pick<ButtonProps, 'onClick' | 'href'>;
|
|
7
|
+
|
|
8
|
+
export const Navigation = function Navigation({ onClick }: ItemNavigationProps) {
|
|
9
|
+
const { setControlType, props: baseItemProps } = useContext<ItemContextData>(ItemContext);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setControlType('navigation');
|
|
13
|
+
}, []);
|
|
14
|
+
|
|
15
|
+
return baseItemProps?.disabled ? <Disabled size={24} /> : <ChevronRight size={24} />;
|
|
16
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { Props as ItemProps } from './Item';
|
|
2
|
+
export type { ItemAdditionalInfoProps } from './ItemAdditionalInfo';
|
|
3
|
+
export type { ItemCheckboxProps } from './ItemCheckbox';
|
|
4
|
+
export type { ItemImageProps, ItemAvatarViewProps, ItemAvatarLayoutProps } from './ItemMedia';
|
|
5
|
+
|
|
6
|
+
export { default } from './Item';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { render, screen, mockMatchMedia } from '../../test-utils';
|
|
2
|
+
import { ItemPrompt } from './Prompt';
|
|
3
|
+
import { Sentiment } from '../../common';
|
|
4
|
+
|
|
5
|
+
mockMatchMedia();
|
|
6
|
+
|
|
7
|
+
describe('ItemPrompt', () => {
|
|
8
|
+
it('renders the aria-label when provided', () => {
|
|
9
|
+
const ariaLabel = 'Test aria-label';
|
|
10
|
+
render(
|
|
11
|
+
<ItemPrompt
|
|
12
|
+
type={Sentiment.POSITIVE}
|
|
13
|
+
action={{ 'aria-label': ariaLabel, href: 'https://example.com' }}
|
|
14
|
+
>
|
|
15
|
+
Positive prompt
|
|
16
|
+
</ItemPrompt>,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(screen.getByLabelText(ariaLabel)).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('applies the interactive class when href is provided', () => {
|
|
23
|
+
render(
|
|
24
|
+
<ItemPrompt
|
|
25
|
+
type={Sentiment.POSITIVE}
|
|
26
|
+
action={{ href: 'https://example.com', 'aria-label': 'Interactive link' }}
|
|
27
|
+
>
|
|
28
|
+
Interactive link
|
|
29
|
+
</ItemPrompt>,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(screen.getByRole('link')).toHaveClass('np-prompt-interactive');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('applies the interactive class when onClick is provided', () => {
|
|
36
|
+
render(
|
|
37
|
+
<ItemPrompt
|
|
38
|
+
type={Sentiment.POSITIVE}
|
|
39
|
+
action={{ onClick: jest.fn(), 'aria-label': 'Interactive button' }}
|
|
40
|
+
>
|
|
41
|
+
Interactive button
|
|
42
|
+
</ItemPrompt>,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
expect(screen.getByRole('button')).toHaveClass('np-prompt-interactive');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('does not apply the interactive class when no action is provided', () => {
|
|
49
|
+
render(<ItemPrompt type={Sentiment.POSITIVE}>Non-interactive prompt</ItemPrompt>);
|
|
50
|
+
|
|
51
|
+
expect(screen.getByText('Non-interactive prompt')).not.toHaveClass('np-prompt-interactive');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('renders the children content', () => {
|
|
55
|
+
render(<ItemPrompt type={Sentiment.POSITIVE}>This is a child prompt</ItemPrompt>);
|
|
56
|
+
|
|
57
|
+
expect(screen.getByText('This is a child prompt')).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('spreads additional props to the wrapper element', () => {
|
|
61
|
+
render(
|
|
62
|
+
<ItemPrompt
|
|
63
|
+
type={Sentiment.POSITIVE}
|
|
64
|
+
action={{
|
|
65
|
+
href: 'https://example.com',
|
|
66
|
+
target: '_blank',
|
|
67
|
+
'aria-label': 'Custom props prompt',
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
Custom props prompt
|
|
71
|
+
</ItemPrompt>,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const link = screen.getByRole('link');
|
|
75
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
76
|
+
});
|
|
77
|
+
});
|