@transferwise/components 0.0.0-experimental-6a6c19f → 0.0.0-experimental-e72bc9f
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/i18n/cs.json +1 -0
- package/build/i18n/cs.json.js +1 -0
- package/build/i18n/cs.json.js.map +1 -1
- package/build/i18n/cs.json.mjs +1 -0
- package/build/i18n/cs.json.mjs.map +1 -1
- package/build/i18n/de.json +1 -0
- package/build/i18n/de.json.js +1 -0
- package/build/i18n/de.json.js.map +1 -1
- package/build/i18n/de.json.mjs +1 -0
- package/build/i18n/de.json.mjs.map +1 -1
- package/build/i18n/es.json +1 -0
- package/build/i18n/es.json.js +1 -0
- package/build/i18n/es.json.js.map +1 -1
- package/build/i18n/es.json.mjs +1 -0
- package/build/i18n/es.json.mjs.map +1 -1
- package/build/i18n/fr.json +1 -0
- package/build/i18n/fr.json.js +1 -0
- package/build/i18n/fr.json.js.map +1 -1
- package/build/i18n/fr.json.mjs +1 -0
- package/build/i18n/fr.json.mjs.map +1 -1
- package/build/i18n/hu.json +1 -0
- package/build/i18n/hu.json.js +1 -0
- package/build/i18n/hu.json.js.map +1 -1
- package/build/i18n/hu.json.mjs +1 -0
- package/build/i18n/hu.json.mjs.map +1 -1
- package/build/i18n/id.json +1 -0
- package/build/i18n/id.json.js +1 -0
- package/build/i18n/id.json.js.map +1 -1
- package/build/i18n/id.json.mjs +1 -0
- package/build/i18n/id.json.mjs.map +1 -1
- package/build/i18n/it.json +1 -0
- package/build/i18n/it.json.js +1 -0
- package/build/i18n/it.json.js.map +1 -1
- package/build/i18n/it.json.mjs +1 -0
- package/build/i18n/it.json.mjs.map +1 -1
- package/build/i18n/ja.json +1 -0
- package/build/i18n/ja.json.js +1 -0
- package/build/i18n/ja.json.js.map +1 -1
- package/build/i18n/ja.json.mjs +1 -0
- package/build/i18n/ja.json.mjs.map +1 -1
- package/build/i18n/nl.json +4 -3
- package/build/i18n/pl.json +1 -0
- package/build/i18n/pl.json.js +1 -0
- package/build/i18n/pl.json.js.map +1 -1
- package/build/i18n/pl.json.mjs +1 -0
- package/build/i18n/pl.json.mjs.map +1 -1
- package/build/i18n/pt.json +1 -0
- package/build/i18n/pt.json.js +1 -0
- package/build/i18n/pt.json.js.map +1 -1
- package/build/i18n/pt.json.mjs +1 -0
- package/build/i18n/pt.json.mjs.map +1 -1
- package/build/i18n/ro.json +1 -0
- package/build/i18n/ro.json.js +1 -0
- package/build/i18n/ro.json.js.map +1 -1
- package/build/i18n/ro.json.mjs +1 -0
- package/build/i18n/ro.json.mjs.map +1 -1
- package/build/i18n/ru.json +1 -0
- package/build/i18n/ru.json.js +1 -0
- package/build/i18n/ru.json.js.map +1 -1
- package/build/i18n/ru.json.mjs +1 -0
- package/build/i18n/ru.json.mjs.map +1 -1
- package/build/i18n/th.json +1 -0
- package/build/i18n/th.json.js +1 -0
- package/build/i18n/th.json.js.map +1 -1
- package/build/i18n/th.json.mjs +1 -0
- package/build/i18n/th.json.mjs.map +1 -1
- package/build/i18n/tr.json +1 -0
- package/build/i18n/tr.json.js +1 -0
- package/build/i18n/tr.json.js.map +1 -1
- package/build/i18n/tr.json.mjs +1 -0
- package/build/i18n/tr.json.mjs.map +1 -1
- package/build/i18n/zh-CN.json +1 -0
- package/build/i18n/zh-CN.json.js +1 -0
- package/build/i18n/zh-CN.json.js.map +1 -1
- package/build/i18n/zh-CN.json.mjs +1 -0
- package/build/i18n/zh-CN.json.mjs.map +1 -1
- package/build/i18n/zh-HK.json +1 -0
- package/build/i18n/zh-HK.json.js +1 -0
- package/build/i18n/zh-HK.json.js.map +1 -1
- package/build/i18n/zh-HK.json.mjs +1 -0
- package/build/i18n/zh-HK.json.mjs.map +1 -1
- package/build/image/Image.js +10 -9
- package/build/image/Image.js.map +1 -1
- package/build/image/Image.mjs +11 -11
- package/build/image/Image.mjs.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/index.mjs +1 -1
- package/build/main.css +188 -0
- package/build/styles/listItem/ListItem.css +188 -0
- package/build/styles/main.css +188 -0
- package/build/test-utils/assets/apple-pay-logo.svg +84 -0
- package/build/types/image/Image.d.ts +1 -0
- package/build/types/image/Image.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/ListItem.d.ts +43 -0
- package/build/types/listItem/ListItem.d.ts.map +1 -0
- package/build/types/listItem/ListItemAdditionalInfo.d.ts +9 -0
- package/build/types/listItem/ListItemAdditionalInfo.d.ts.map +1 -0
- package/build/types/listItem/ListItemButton.d.ts +4 -0
- package/build/types/listItem/ListItemButton.d.ts.map +1 -0
- package/build/types/listItem/ListItemCheckbox.d.ts +4 -0
- package/build/types/listItem/ListItemCheckbox.d.ts.map +1 -0
- package/build/types/listItem/ListItemIconButton.d.ts +7 -0
- package/build/types/listItem/ListItemIconButton.d.ts.map +1 -0
- package/build/types/listItem/ListItemMedia.d.ts +19 -0
- package/build/types/listItem/ListItemMedia.d.ts.map +1 -0
- package/build/types/listItem/ListItemNavigation.d.ts +4 -0
- package/build/types/listItem/ListItemNavigation.d.ts.map +1 -0
- package/build/types/listItem/ListItemSwitch.d.ts +3 -0
- package/build/types/listItem/ListItemSwitch.d.ts.map +1 -0
- package/build/types/listItem/index.d.ts +6 -0
- package/build/types/listItem/index.d.ts.map +1 -0
- package/build/types/listItem/prompt/Prompt.d.ts +12 -0
- package/build/types/listItem/prompt/Prompt.d.ts.map +1 -0
- package/build/types/listItem/useItemControl.d.ts +5 -0
- package/build/types/listItem/useItemControl.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/i18n/cs.json +1 -0
- package/src/i18n/de.json +1 -0
- package/src/i18n/es.json +1 -0
- package/src/i18n/fr.json +1 -0
- package/src/i18n/hu.json +1 -0
- package/src/i18n/id.json +1 -0
- package/src/i18n/it.json +1 -0
- package/src/i18n/ja.json +1 -0
- package/src/i18n/nl.json +4 -3
- package/src/i18n/pl.json +1 -0
- package/src/i18n/pt.json +1 -0
- package/src/i18n/ro.json +1 -0
- package/src/i18n/ru.json +1 -0
- package/src/i18n/th.json +1 -0
- package/src/i18n/tr.json +1 -0
- package/src/i18n/zh-CN.json +1 -0
- package/src/i18n/zh-HK.json +1 -0
- package/src/image/Image.spec.tsx +3 -3
- package/src/image/Image.tsx +12 -10
- package/src/index.ts +2 -0
- package/src/legacylistItem/LegacyListItem.story.tsx +5 -5
- package/src/legacylistItem/LegacyListItem.tests.story.tsx +6 -6
- package/src/listItem/ListItem.css +188 -0
- package/src/listItem/ListItem.less +182 -0
- package/src/listItem/ListItem.story.tsx +273 -0
- package/src/listItem/ListItem.tsx +183 -0
- package/src/listItem/ListItemAdditionalInfo.tsx +31 -0
- package/src/listItem/ListItemButton.spec.tsx +90 -0
- package/src/listItem/ListItemButton.tsx +18 -0
- package/src/listItem/ListItemCheckbox.tsx +14 -0
- package/src/listItem/ListItemIconButton.tsx +13 -0
- package/src/listItem/ListItemMedia.tsx +52 -0
- package/src/listItem/ListItemNavigation.tsx +11 -0
- package/src/listItem/ListItemSwitch.tsx +8 -0
- package/src/listItem/index.ts +10 -0
- package/src/listItem/prompt/Prompt.spec.tsx +77 -0
- package/src/listItem/prompt/Prompt.story.tsx +170 -0
- package/src/listItem/prompt/Prompt.tsx +44 -0
- package/src/listItem/useItemControl.tsx +12 -0
- package/src/main.css +188 -0
- package/src/main.less +1 -0
- package/src/promoCard/__snapshots__/PromoCard.spec.tsx.snap +0 -1
- package/src/promoCard/__snapshots__/PromoCardGroup.spec.tsx.snap +0 -2
- package/src/test-utils/assets/apple-pay-logo.svg +84 -0
- package/src/test-utils/fake-data.ts +5 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { render, screen, mockMatchMedia } from '../test-utils';
|
|
2
|
+
import { Button as ItemButton } from './ListItemButton';
|
|
3
|
+
import { ButtonPriority } from '../button/Button.types';
|
|
4
|
+
import { ListItemContext } from './ListItem';
|
|
5
|
+
|
|
6
|
+
mockMatchMedia();
|
|
7
|
+
|
|
8
|
+
describe('ItemButton', () => {
|
|
9
|
+
const mockSetControlType = jest.fn();
|
|
10
|
+
|
|
11
|
+
const renderWithItemContext = (ui: React.ReactNode) => {
|
|
12
|
+
return render(
|
|
13
|
+
<ListItemContext.Provider
|
|
14
|
+
value={{
|
|
15
|
+
setControlType: mockSetControlType,
|
|
16
|
+
ids: {
|
|
17
|
+
label: 'label',
|
|
18
|
+
additionalInfo: 'additional Info',
|
|
19
|
+
value: 'value',
|
|
20
|
+
control: 'control',
|
|
21
|
+
prompt: 'prompt',
|
|
22
|
+
},
|
|
23
|
+
props: {},
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
{ui}
|
|
27
|
+
</ListItemContext.Provider>,
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
jest.clearAllMocks();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('always sets v2 to true', () => {
|
|
36
|
+
renderWithItemContext(<ItemButton priority="primary">Test Button</ItemButton>);
|
|
37
|
+
const button = screen.getByRole('button');
|
|
38
|
+
expect(button).toBeInTheDocument();
|
|
39
|
+
expect(mockSetControlType).toHaveBeenCalledWith('button');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('always sets size to "md"', () => {
|
|
43
|
+
renderWithItemContext(<ItemButton priority="primary">Test Button</ItemButton>);
|
|
44
|
+
const button = screen.getByRole('button');
|
|
45
|
+
expect(button).toHaveClass('wds-Button--medium');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('supports all priorities', () => {
|
|
49
|
+
const priorities: ButtonPriority[] = ['primary', 'secondary', 'tertiary'];
|
|
50
|
+
priorities.forEach((priority) => {
|
|
51
|
+
renderWithItemContext(<ItemButton priority={priority}>Test {priority}</ItemButton>);
|
|
52
|
+
const button = screen.getByRole('button', { name: `Test ${priority}` });
|
|
53
|
+
expect(button).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('renders as a button by default', () => {
|
|
58
|
+
renderWithItemContext(<ItemButton>Click me</ItemButton>);
|
|
59
|
+
const button = screen.getByRole('button');
|
|
60
|
+
expect(button).toBeInTheDocument();
|
|
61
|
+
expect(button.tagName).toBe('BUTTON');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('renders as an anchor when href is provided', () => {
|
|
65
|
+
renderWithItemContext(<ItemButton href="https://example.com">Go to Example</ItemButton>);
|
|
66
|
+
const link = screen.getByRole('link', { name: 'Go to Example' });
|
|
67
|
+
expect(link).toBeInTheDocument();
|
|
68
|
+
expect(link.tagName).toBe('A');
|
|
69
|
+
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('spreads additional props to the button', () => {
|
|
73
|
+
renderWithItemContext(<ItemButton aria-label="Custom Button">Custom</ItemButton>);
|
|
74
|
+
const button = screen.getByRole('button', { name: 'Custom Button' });
|
|
75
|
+
expect(button).toBeInTheDocument();
|
|
76
|
+
expect(button).toHaveAttribute('aria-label', 'Custom Button');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('spreads additional props to the anchor', () => {
|
|
80
|
+
renderWithItemContext(
|
|
81
|
+
<ItemButton href="https://example.com" target="_blank" aria-label="Custom Link">
|
|
82
|
+
Custom Link
|
|
83
|
+
</ItemButton>,
|
|
84
|
+
);
|
|
85
|
+
const link = screen.getByRole('link', { name: 'Custom Link' });
|
|
86
|
+
expect(link).toBeInTheDocument();
|
|
87
|
+
expect(link).toHaveAttribute('href', 'https://example.com');
|
|
88
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { default as ButtonComp, NewButtonProps } from '../button';
|
|
2
|
+
import { useItemControl } from './useItemControl';
|
|
3
|
+
|
|
4
|
+
export type ListItemButtonProps = Omit<NewButtonProps, 'v2' | 'size' | 'disabled'>;
|
|
5
|
+
|
|
6
|
+
export const Button = ({ priority = 'secondary', ...props }: ListItemButtonProps) => {
|
|
7
|
+
const { baseItemProps } = useItemControl('button');
|
|
8
|
+
|
|
9
|
+
const commonProps = {
|
|
10
|
+
...props,
|
|
11
|
+
priority,
|
|
12
|
+
v2: true,
|
|
13
|
+
size: 'md',
|
|
14
|
+
disabled: baseItemProps.disabled,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return <ButtonComp {...(commonProps as NewButtonProps)} />;
|
|
18
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import CheckboxButton from '../checkboxButton';
|
|
2
|
+
import { CheckboxButtonProps } from '../checkboxButton/CheckboxButton';
|
|
3
|
+
import { useItemControl } from './useItemControl';
|
|
4
|
+
|
|
5
|
+
export type ListItemCheckboxProps = Pick<
|
|
6
|
+
CheckboxButtonProps,
|
|
7
|
+
'checked' | 'indeterminate' | 'onChange'
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
export const Checkbox = function (props: ListItemCheckboxProps) {
|
|
11
|
+
const { baseItemProps } = useItemControl('checkbox');
|
|
12
|
+
|
|
13
|
+
return <CheckboxButton disabled={baseItemProps.disabled} {...props} />;
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { default as IconButtonComp, IconButtonProps } from '../iconButton';
|
|
2
|
+
import { useItemControl } from './useItemControl';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
export type ListItemIconButtonProps = Pick<IconButtonProps, 'onClick' | 'href' | 'target'> & {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const IconButton = function (props: ListItemIconButtonProps) {
|
|
10
|
+
const { baseItemProps } = useItemControl('icon-button');
|
|
11
|
+
|
|
12
|
+
return <IconButtonComp {...props} size={32} disabled={baseItemProps.disabled} />;
|
|
13
|
+
};
|
|
@@ -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 ListItemAvatarViewProps = Omit<AvatarViewProps, 'size' | 'interactive'> & SizeProp;
|
|
9
|
+
|
|
10
|
+
export const AvatarView = ({ className, size = 48, ...props }: ListItemAvatarViewProps) => {
|
|
11
|
+
return (
|
|
12
|
+
<AvatarViewComp
|
|
13
|
+
{...props}
|
|
14
|
+
size={size}
|
|
15
|
+
className={clsx('wds-list-item-media-avatar-view', className)}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ListItemAvatarLayoutProps = Omit<AvatarLayoutProps, 'size' | 'interactive'> & SizeProp;
|
|
21
|
+
|
|
22
|
+
export const AvatarLayout = ({ className, size = 48, ...props }: ListItemAvatarLayoutProps) => {
|
|
23
|
+
return (
|
|
24
|
+
<AvatarLayoutComp
|
|
25
|
+
{...props}
|
|
26
|
+
size={size}
|
|
27
|
+
className={clsx('wds-list-item-media-avatar-layout', className)}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type ListItemImageProps = 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 }: ListItemImageProps) => {
|
|
41
|
+
return (
|
|
42
|
+
<div
|
|
43
|
+
className={clsx('wds-list-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,11 @@
|
|
|
1
|
+
import { ChevronRight, BillSplit as Disabled } from '@transferwise/icons';
|
|
2
|
+
import { ButtonProps } from '../button/Button.types';
|
|
3
|
+
import { useItemControl } from './useItemControl';
|
|
4
|
+
|
|
5
|
+
export type ListItemNavigationProps = Pick<ButtonProps, 'onClick' | 'href'>;
|
|
6
|
+
|
|
7
|
+
export const Navigation = function Navigation({ onClick }: ListItemNavigationProps) {
|
|
8
|
+
const { baseItemProps } = useItemControl('navigation');
|
|
9
|
+
|
|
10
|
+
return baseItemProps.disabled ? <Disabled size={24} /> : <ChevronRight size={24} />;
|
|
11
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as SwitchComp, SwitchProps } from '../switch';
|
|
2
|
+
import { useItemControl } from './useItemControl';
|
|
3
|
+
|
|
4
|
+
export const Switch = function (props: SwitchProps) {
|
|
5
|
+
const { baseItemProps } = useItemControl('switch');
|
|
6
|
+
|
|
7
|
+
return <SwitchComp disabled={baseItemProps.disabled} {...props} />;
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { Props as ListItemProps } from './ListItem';
|
|
2
|
+
export type { ListItemAdditionalInfoProps } from './ListItemAdditionalInfo';
|
|
3
|
+
export type { ListItemCheckboxProps } from './ListItemCheckbox';
|
|
4
|
+
export type {
|
|
5
|
+
ListItemImageProps,
|
|
6
|
+
ListItemAvatarViewProps,
|
|
7
|
+
ListItemAvatarLayoutProps,
|
|
8
|
+
} from './ListItemMedia';
|
|
9
|
+
|
|
10
|
+
export { default } from './ListItem';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { render, screen, mockMatchMedia } from '../../test-utils';
|
|
2
|
+
import { Prompt } from './Prompt';
|
|
3
|
+
import { Sentiment } from '../../common';
|
|
4
|
+
|
|
5
|
+
mockMatchMedia();
|
|
6
|
+
|
|
7
|
+
describe('ListItem.Prompt', () => {
|
|
8
|
+
it('renders the aria-label when provided', () => {
|
|
9
|
+
const ariaLabel = 'Test aria-label';
|
|
10
|
+
render(
|
|
11
|
+
<Prompt
|
|
12
|
+
type={Sentiment.POSITIVE}
|
|
13
|
+
action={{ 'aria-label': ariaLabel, href: 'https://example.com' }}
|
|
14
|
+
>
|
|
15
|
+
Positive prompt
|
|
16
|
+
</Prompt>,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(screen.getByLabelText(ariaLabel)).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('applies the interactive class when href is provided', () => {
|
|
23
|
+
render(
|
|
24
|
+
<Prompt
|
|
25
|
+
type={Sentiment.POSITIVE}
|
|
26
|
+
action={{ href: 'https://example.com', 'aria-label': 'Interactive link' }}
|
|
27
|
+
>
|
|
28
|
+
Interactive link
|
|
29
|
+
</Prompt>,
|
|
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
|
+
<Prompt
|
|
38
|
+
type={Sentiment.POSITIVE}
|
|
39
|
+
action={{ onClick: jest.fn(), 'aria-label': 'Interactive button' }}
|
|
40
|
+
>
|
|
41
|
+
Interactive button
|
|
42
|
+
</Prompt>,
|
|
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(<Prompt type={Sentiment.POSITIVE}>Non-interactive prompt</Prompt>);
|
|
50
|
+
|
|
51
|
+
expect(screen.getByText('Non-interactive prompt')).not.toHaveClass('np-prompt-interactive');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('renders the children content', () => {
|
|
55
|
+
render(<Prompt type={Sentiment.POSITIVE}>This is a child prompt</Prompt>);
|
|
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
|
+
<Prompt
|
|
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
|
+
</Prompt>,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const link = screen.getByRole('link');
|
|
75
|
+
expect(link).toHaveAttribute('target', '_blank');
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import Link from '../../link';
|
|
2
|
+
import { Sentiment } from '../../common';
|
|
3
|
+
import { Prompt, ListItemPromptProps } from './Prompt';
|
|
4
|
+
import { lorem40 } from '../../test-utils';
|
|
5
|
+
import { StoryObj } from '@storybook/react';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
component: Prompt,
|
|
9
|
+
title: 'Content/ListItem/Prompt',
|
|
10
|
+
args: {
|
|
11
|
+
type: Sentiment.NEGATIVE,
|
|
12
|
+
children: 'You have done a terrible thing',
|
|
13
|
+
},
|
|
14
|
+
argTypes: {
|
|
15
|
+
type: {
|
|
16
|
+
options: [
|
|
17
|
+
Sentiment.POSITIVE,
|
|
18
|
+
Sentiment.NEGATIVE,
|
|
19
|
+
Sentiment.NEUTRAL,
|
|
20
|
+
Sentiment.WARNING,
|
|
21
|
+
'discount',
|
|
22
|
+
'savings',
|
|
23
|
+
],
|
|
24
|
+
control: { type: 'radio' },
|
|
25
|
+
description: 'The type of prompt to display',
|
|
26
|
+
},
|
|
27
|
+
action: {
|
|
28
|
+
table: {
|
|
29
|
+
disable: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
children: {
|
|
33
|
+
type: {
|
|
34
|
+
name: 'string',
|
|
35
|
+
required: true,
|
|
36
|
+
description: 'The content of the prompt',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type CustomStory = StoryObj<
|
|
43
|
+
ListItemPromptProps & {
|
|
44
|
+
interactivity?: 'none' | 'full-anchor' | 'full-button' | 'link';
|
|
45
|
+
}
|
|
46
|
+
>;
|
|
47
|
+
|
|
48
|
+
export const Basic: CustomStory = {
|
|
49
|
+
args: {
|
|
50
|
+
interactivity: 'none',
|
|
51
|
+
},
|
|
52
|
+
argTypes: {
|
|
53
|
+
interactivity: {
|
|
54
|
+
options: ['none', 'full-button', 'full-anchor', 'link'],
|
|
55
|
+
control: { type: 'radio' },
|
|
56
|
+
description: 'The type of interactivity to display',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
render: ({ interactivity, ...args }) => {
|
|
60
|
+
return (
|
|
61
|
+
<div>
|
|
62
|
+
<Prompt
|
|
63
|
+
type={args.type}
|
|
64
|
+
action={
|
|
65
|
+
interactivity === 'full-anchor'
|
|
66
|
+
? { href: 'wise.com' }
|
|
67
|
+
: interactivity === 'full-button'
|
|
68
|
+
? {
|
|
69
|
+
onClick: () => {
|
|
70
|
+
console.log('clicked');
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
: undefined
|
|
74
|
+
}
|
|
75
|
+
>
|
|
76
|
+
{args.children} {interactivity === 'link' && <Link href="www.wise.com">with a link</Link>}
|
|
77
|
+
</Prompt>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const Variants = () => {
|
|
84
|
+
return (
|
|
85
|
+
<>
|
|
86
|
+
<div className="m-b-2">
|
|
87
|
+
<Prompt type={Sentiment.POSITIVE}>
|
|
88
|
+
Positive prompt <Link href="www.wise.com">with a link to amazing content</Link>
|
|
89
|
+
</Prompt>
|
|
90
|
+
</div>
|
|
91
|
+
<div className="m-b-2">
|
|
92
|
+
<Prompt type={Sentiment.NEGATIVE}>
|
|
93
|
+
Negative prompt <Link href="www.wise.com">with a link to amazing content</Link>
|
|
94
|
+
</Prompt>
|
|
95
|
+
</div>
|
|
96
|
+
<div className="m-b-2">
|
|
97
|
+
<Prompt type={Sentiment.NEUTRAL}>
|
|
98
|
+
Neutral prompt <Link href="www.wise.com">with a link to amazing content</Link>
|
|
99
|
+
</Prompt>
|
|
100
|
+
</div>
|
|
101
|
+
<div className="m-b-2">
|
|
102
|
+
<Prompt type={Sentiment.WARNING}>
|
|
103
|
+
Warning prompt <Link href="www.wise.com">with a link to amazing content</Link>
|
|
104
|
+
</Prompt>
|
|
105
|
+
</div>
|
|
106
|
+
<div className="m-b-2">
|
|
107
|
+
<Prompt type="discount">
|
|
108
|
+
Discount prompt <Link href="www.wise.com">with a link to amazing content</Link>
|
|
109
|
+
</Prompt>
|
|
110
|
+
</div>
|
|
111
|
+
<div className="m-b-2">
|
|
112
|
+
<Prompt type="savings">
|
|
113
|
+
Savings prompt <Link href="www.wise.com">with a link to amazing content</Link>
|
|
114
|
+
</Prompt>
|
|
115
|
+
</div>
|
|
116
|
+
<div className="m-b-2">
|
|
117
|
+
<Prompt
|
|
118
|
+
type="discount"
|
|
119
|
+
action={{
|
|
120
|
+
href: 'www.wise.com',
|
|
121
|
+
target: '_self',
|
|
122
|
+
'aria-label': 'hidden anchor tags are accessible, right?',
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
The whole prompt is secretly clickable
|
|
126
|
+
</Prompt>
|
|
127
|
+
</div>
|
|
128
|
+
<div className="m-b-2">
|
|
129
|
+
<Prompt
|
|
130
|
+
type="negative"
|
|
131
|
+
action={{
|
|
132
|
+
href: 'www.wise.com',
|
|
133
|
+
target: '_self',
|
|
134
|
+
'aria-label': 'clickable <a>',
|
|
135
|
+
}}
|
|
136
|
+
>
|
|
137
|
+
The whole prompt is secretly clickable as an anchor tag
|
|
138
|
+
</Prompt>
|
|
139
|
+
</div>
|
|
140
|
+
<div className="m-b-2">
|
|
141
|
+
<Prompt
|
|
142
|
+
type="warning"
|
|
143
|
+
action={{
|
|
144
|
+
onClick: () => {
|
|
145
|
+
console.log('clicked');
|
|
146
|
+
},
|
|
147
|
+
'aria-label': 'clickable button',
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
The whole prompt is secretly clickable as a button
|
|
151
|
+
</Prompt>
|
|
152
|
+
</div>
|
|
153
|
+
<div className="m-b-2">
|
|
154
|
+
<Prompt
|
|
155
|
+
type="neutral"
|
|
156
|
+
action={{
|
|
157
|
+
href: 'www.wise.com',
|
|
158
|
+
target: '_self',
|
|
159
|
+
'aria-label': 'clickable prompt',
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
The whole prompt is secretly clickable
|
|
163
|
+
</Prompt>
|
|
164
|
+
</div>
|
|
165
|
+
<div className="m-b-2" style={{ maxWidth: '300px' }}>
|
|
166
|
+
<Prompt type="warning">The prompt has very long text that wraps {lorem40}</Prompt>
|
|
167
|
+
</div>
|
|
168
|
+
</>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Confetti, Tags } from '@transferwise/icons';
|
|
2
|
+
import { Sentiment } from '../../common';
|
|
3
|
+
import StatusIcon from '../../statusIcon';
|
|
4
|
+
import { clsx } from 'clsx';
|
|
5
|
+
import { LinkProps } from '../../link';
|
|
6
|
+
import Body from '../../body';
|
|
7
|
+
|
|
8
|
+
export type ListItemPromptProps = {
|
|
9
|
+
type:
|
|
10
|
+
| `${Sentiment.POSITIVE | Sentiment.NEGATIVE | Sentiment.NEUTRAL | Sentiment.WARNING}`
|
|
11
|
+
| 'discount'
|
|
12
|
+
| 'savings';
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
action?: Pick<LinkProps, 'href' | 'target' | 'onClick'> & { 'aria-label'?: string };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const Prompt = ({ type, children, action }: ListItemPromptProps) => {
|
|
18
|
+
const Wrapper = action?.href ? 'a' : action?.onClick ? 'button' : 'span';
|
|
19
|
+
|
|
20
|
+
const icon =
|
|
21
|
+
type === 'discount' ? (
|
|
22
|
+
<Tags size={16} />
|
|
23
|
+
) : type === 'savings' ? (
|
|
24
|
+
<Confetti size={16} />
|
|
25
|
+
) : (
|
|
26
|
+
<StatusIcon size={16} sentiment={type} />
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Wrapper
|
|
31
|
+
className={clsx(
|
|
32
|
+
'wds-list-item-prompt',
|
|
33
|
+
type,
|
|
34
|
+
(action?.href || action?.onClick) && 'np-prompt-interactive',
|
|
35
|
+
)}
|
|
36
|
+
{...(action ?? {})}
|
|
37
|
+
>
|
|
38
|
+
<div className="np-prompt-icon">{icon}</div>
|
|
39
|
+
<Body>{children}</Body>
|
|
40
|
+
</Wrapper>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export default Prompt;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext, useEffect } from 'react';
|
|
2
|
+
import { ListItemContext, ListItemContextData, ListItemTypes } from './ListItem';
|
|
3
|
+
|
|
4
|
+
export function useItemControl(controlType: ListItemTypes) {
|
|
5
|
+
const { setControlType, props: baseItemProps } = useContext<ListItemContextData>(ListItemContext);
|
|
6
|
+
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
setControlType(controlType);
|
|
9
|
+
}, [controlType, setControlType]);
|
|
10
|
+
|
|
11
|
+
return { baseItemProps };
|
|
12
|
+
}
|