@ledgerhq/lumen-ui-rnative 0.1.50 → 0.1.52
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/dist/module/lib/Components/Avatar/Avatar.figma.js +3 -6
- package/dist/module/lib/Components/Avatar/Avatar.figma.js.map +1 -1
- package/dist/module/lib/Components/Avatar/Avatar.js +92 -39
- package/dist/module/lib/Components/Avatar/Avatar.js.map +1 -1
- package/dist/module/lib/Components/Avatar/Avatar.mdx +36 -191
- package/dist/module/lib/Components/Avatar/Avatar.stories.js +80 -125
- package/dist/module/lib/Components/Avatar/Avatar.stories.js.map +1 -1
- package/dist/module/lib/Components/Avatar/Avatar.test.js +56 -45
- package/dist/module/lib/Components/Avatar/Avatar.test.js.map +1 -1
- package/dist/module/lib/Components/Avatar/index.js +1 -0
- package/dist/module/lib/Components/Avatar/index.js.map +1 -1
- package/dist/module/lib/Components/Avatar/resolveAvatarColor.js +18 -0
- package/dist/module/lib/Components/Avatar/resolveAvatarColor.js.map +1 -0
- package/dist/module/lib/Components/AvatarButton/AvatarButton.js +77 -0
- package/dist/module/lib/Components/AvatarButton/AvatarButton.js.map +1 -0
- package/dist/module/lib/Components/AvatarButton/AvatarButton.mdx +62 -0
- package/dist/module/lib/Components/AvatarButton/AvatarButton.stories.js +59 -0
- package/dist/module/lib/Components/AvatarButton/AvatarButton.stories.js.map +1 -0
- package/dist/module/lib/Components/AvatarButton/AvatarButton.test.js +100 -0
- package/dist/module/lib/Components/AvatarButton/AvatarButton.test.js.map +1 -0
- package/dist/module/lib/Components/AvatarButton/index.js +5 -0
- package/dist/module/lib/Components/AvatarButton/index.js.map +1 -0
- package/dist/module/lib/Components/AvatarButton/types.js +4 -0
- package/dist/module/lib/Components/AvatarButton/types.js.map +1 -0
- package/dist/module/lib/Components/DotIndicator/getDotIndicatorProps.js +16 -1
- package/dist/module/lib/Components/DotIndicator/getDotIndicatorProps.js.map +1 -1
- package/dist/module/lib/Components/DotIndicator/getDotIndicatorProps.test.js +16 -0
- package/dist/module/lib/Components/DotIndicator/getDotIndicatorProps.test.js.map +1 -1
- package/dist/module/lib/Components/MediaBanner/MediaBanner.js +55 -37
- package/dist/module/lib/Components/MediaBanner/MediaBanner.js.map +1 -1
- package/dist/module/lib/Components/MediaBanner/MediaBanner.mdx +25 -3
- package/dist/module/lib/Components/MediaBanner/MediaBanner.stories.js +23 -0
- package/dist/module/lib/Components/MediaBanner/MediaBanner.stories.js.map +1 -1
- package/dist/module/lib/Components/MediaBanner/MediaBanner.test.js +17 -0
- package/dist/module/lib/Components/MediaBanner/MediaBanner.test.js.map +1 -1
- package/dist/module/lib/Components/index.js +1 -0
- package/dist/module/lib/Components/index.js.map +1 -1
- package/dist/module/lib/Symbols/Icons/Atm.js +50 -0
- package/dist/module/lib/Symbols/Icons/Atm.js.map +1 -0
- package/dist/module/lib/Symbols/Icons/Cutlery.js +50 -0
- package/dist/module/lib/Symbols/Icons/Cutlery.js.map +1 -0
- package/dist/module/lib/Symbols/Icons/GameControler.js +50 -0
- package/dist/module/lib/Symbols/Icons/GameControler.js.map +1 -0
- package/dist/module/lib/Symbols/index.js +3 -0
- package/dist/module/lib/Symbols/index.js.map +1 -1
- package/dist/typescript/src/lib/Components/Avatar/Avatar.d.ts +3 -3
- package/dist/typescript/src/lib/Components/Avatar/Avatar.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/Avatar/index.d.ts +1 -0
- package/dist/typescript/src/lib/Components/Avatar/index.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/Avatar/resolveAvatarColor.d.ts +8 -0
- package/dist/typescript/src/lib/Components/Avatar/resolveAvatarColor.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/Avatar/types.d.ts +22 -7
- package/dist/typescript/src/lib/Components/Avatar/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/AvatarButton/AvatarButton.d.ts +13 -0
- package/dist/typescript/src/lib/Components/AvatarButton/AvatarButton.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/AvatarButton/index.d.ts +3 -0
- package/dist/typescript/src/lib/Components/AvatarButton/index.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/AvatarButton/types.d.ts +11 -0
- package/dist/typescript/src/lib/Components/AvatarButton/types.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/DotIndicator/getDotIndicatorProps.d.ts +32 -0
- package/dist/typescript/src/lib/Components/DotIndicator/getDotIndicatorProps.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/MediaBanner/MediaBanner.d.ts +1 -1
- package/dist/typescript/src/lib/Components/MediaBanner/MediaBanner.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/MediaBanner/types.d.ts +1 -1
- package/dist/typescript/src/lib/Components/MediaBanner/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/index.d.ts +1 -0
- package/dist/typescript/src/lib/Components/index.d.ts.map +1 -1
- package/dist/typescript/src/lib/Symbols/Icons/Atm.d.ts +35 -0
- package/dist/typescript/src/lib/Symbols/Icons/Atm.d.ts.map +1 -0
- package/dist/typescript/src/lib/Symbols/Icons/Cutlery.d.ts +35 -0
- package/dist/typescript/src/lib/Symbols/Icons/Cutlery.d.ts.map +1 -0
- package/dist/typescript/src/lib/Symbols/Icons/GameControler.d.ts +35 -0
- package/dist/typescript/src/lib/Symbols/Icons/GameControler.d.ts.map +1 -0
- package/dist/typescript/src/lib/Symbols/index.d.ts +3 -0
- package/dist/typescript/src/lib/Symbols/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/Components/Avatar/Avatar.figma.tsx +2 -5
- package/src/lib/Components/Avatar/Avatar.mdx +36 -191
- package/src/lib/Components/Avatar/Avatar.stories.tsx +58 -83
- package/src/lib/Components/Avatar/Avatar.test.tsx +58 -58
- package/src/lib/Components/Avatar/Avatar.tsx +100 -32
- package/src/lib/Components/Avatar/index.ts +1 -0
- package/src/lib/Components/Avatar/resolveAvatarColor.ts +19 -0
- package/src/lib/Components/Avatar/types.ts +23 -7
- package/src/lib/Components/AvatarButton/AvatarButton.mdx +62 -0
- package/src/lib/Components/AvatarButton/AvatarButton.stories.tsx +58 -0
- package/src/lib/Components/AvatarButton/AvatarButton.test.tsx +92 -0
- package/src/lib/Components/AvatarButton/AvatarButton.tsx +77 -0
- package/src/lib/Components/AvatarButton/index.ts +2 -0
- package/src/lib/Components/AvatarButton/types.ts +15 -0
- package/src/lib/Components/DotIndicator/getDotIndicatorProps.test.ts +16 -0
- package/src/lib/Components/DotIndicator/getDotIndicatorProps.ts +6 -2
- package/src/lib/Components/MediaBanner/MediaBanner.mdx +25 -3
- package/src/lib/Components/MediaBanner/MediaBanner.stories.tsx +25 -0
- package/src/lib/Components/MediaBanner/MediaBanner.test.tsx +18 -0
- package/src/lib/Components/MediaBanner/MediaBanner.tsx +54 -32
- package/src/lib/Components/MediaBanner/types.ts +1 -1
- package/src/lib/Components/index.ts +1 -0
- package/src/lib/Symbols/Icons/Atm.tsx +45 -0
- package/src/lib/Symbols/Icons/Cutlery.tsx +45 -0
- package/src/lib/Symbols/Icons/GameControler.tsx +45 -0
- package/src/lib/Symbols/index.ts +3 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks';
|
|
2
|
+
import * as AvatarButtonStories from './AvatarButton.stories';
|
|
3
|
+
import { CustomTabs, Tab } from '../../../../.storybook/components';
|
|
4
|
+
|
|
5
|
+
<Meta title='Core/AvatarButton' of={AvatarButtonStories} />
|
|
6
|
+
|
|
7
|
+
# AvatarButton
|
|
8
|
+
|
|
9
|
+
<CustomTabs>
|
|
10
|
+
<Tab label="Overview">
|
|
11
|
+
|
|
12
|
+
## Introduction
|
|
13
|
+
|
|
14
|
+
`AvatarButton` wraps an [`Avatar`](/docs/rnative-avatar--docs) in a `Pressable`, for use as an interactive trigger such as opening a user menu or navigating to a profile. It accepts every `Avatar` prop plus `onPress` and `onLongPress`.
|
|
15
|
+
|
|
16
|
+
## Anatomy
|
|
17
|
+
|
|
18
|
+
<Canvas of={AvatarButtonStories.Base} />
|
|
19
|
+
<Controls of={AvatarButtonStories.Base} />
|
|
20
|
+
|
|
21
|
+
## Fallback
|
|
22
|
+
|
|
23
|
+
Like `Avatar`, it falls back to a User icon when no image is available.
|
|
24
|
+
|
|
25
|
+
<Canvas of={AvatarButtonStories.Fallback} />
|
|
26
|
+
|
|
27
|
+
## Disabled
|
|
28
|
+
|
|
29
|
+
Pass `disabled` to prevent interaction. The pressable is not activatable, and the avatar renders at reduced opacity.
|
|
30
|
+
|
|
31
|
+
<Canvas of={AvatarButtonStories.Disabled} />
|
|
32
|
+
|
|
33
|
+
## Accessibility
|
|
34
|
+
|
|
35
|
+
- Renders with `accessibilityRole="button"` so it is announced as a button by screen readers.
|
|
36
|
+
- Provide a meaningful `alt` describing the action (e.g. `"Open user menu"`); it is exposed as the avatar's accessible label.
|
|
37
|
+
|
|
38
|
+
</Tab>
|
|
39
|
+
<Tab label="Implementation">
|
|
40
|
+
|
|
41
|
+
## Setup
|
|
42
|
+
|
|
43
|
+
Install and set up the library with our [Setup Guide →](?path=/docs/getting-started-setup--docs).
|
|
44
|
+
|
|
45
|
+
## Basic Usage
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { AvatarButton } from '@ledgerhq/lumen-ui-rnative';
|
|
49
|
+
|
|
50
|
+
function MyComponent() {
|
|
51
|
+
return (
|
|
52
|
+
<AvatarButton
|
|
53
|
+
src="https://example.com/photo.jpg"
|
|
54
|
+
alt="Open user menu"
|
|
55
|
+
onPress={openMenu}
|
|
56
|
+
/>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
</Tab>
|
|
62
|
+
</CustomTabs>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
|
|
2
|
+
import { AvatarButton } from './AvatarButton';
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
component: AvatarButton,
|
|
6
|
+
id: 'rnative-avatar-button',
|
|
7
|
+
title: 'Core/AvatarButton',
|
|
8
|
+
parameters: {
|
|
9
|
+
docs: {
|
|
10
|
+
source: {
|
|
11
|
+
language: 'tsx',
|
|
12
|
+
format: true,
|
|
13
|
+
type: 'code',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
} satisfies Meta<typeof AvatarButton>;
|
|
18
|
+
|
|
19
|
+
export default meta;
|
|
20
|
+
type Story = StoryObj<typeof meta>;
|
|
21
|
+
|
|
22
|
+
const exampleSrc =
|
|
23
|
+
'https://plus.unsplash.com/premium_photo-1689551670902-19b441a6afde?q=80&w=774&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D';
|
|
24
|
+
|
|
25
|
+
export const Base: Story = {
|
|
26
|
+
args: {
|
|
27
|
+
src: exampleSrc,
|
|
28
|
+
size: 'md',
|
|
29
|
+
alt: 'Open user menu',
|
|
30
|
+
onPress: () => ({}),
|
|
31
|
+
},
|
|
32
|
+
render: (args) => <AvatarButton {...args} />,
|
|
33
|
+
parameters: {
|
|
34
|
+
docs: {
|
|
35
|
+
source: {
|
|
36
|
+
code: `<AvatarButton src="https://example.com" alt="Open user menu" onPress={openMenu} />`,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const Fallback: Story = {
|
|
43
|
+
args: {
|
|
44
|
+
alt: 'Open user menu',
|
|
45
|
+
},
|
|
46
|
+
render: (args) => <AvatarButton {...args} />,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const Disabled: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
src: exampleSrc,
|
|
52
|
+
size: 'md',
|
|
53
|
+
alt: 'Open user menu',
|
|
54
|
+
disabled: true,
|
|
55
|
+
onPress: () => ({}),
|
|
56
|
+
},
|
|
57
|
+
render: (args) => <AvatarButton {...args} />,
|
|
58
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, it, expect, jest } from '@jest/globals';
|
|
2
|
+
import { ledgerLiveThemes } from '@ledgerhq/lumen-design-core';
|
|
3
|
+
import { render, fireEvent } from '@testing-library/react-native';
|
|
4
|
+
import { type ReactNode, createRef } from 'react';
|
|
5
|
+
import type { View } from 'react-native';
|
|
6
|
+
import { ThemeProvider } from '../ThemeProvider/ThemeProvider';
|
|
7
|
+
import { AvatarButton } from './AvatarButton';
|
|
8
|
+
|
|
9
|
+
const TestWrapper = ({ children }: { children: ReactNode }) => (
|
|
10
|
+
<ThemeProvider themes={ledgerLiveThemes} colorScheme='dark' locale='en'>
|
|
11
|
+
{children}
|
|
12
|
+
</ThemeProvider>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
describe('AvatarButton Component', () => {
|
|
16
|
+
const validSrc = 'https://example.com/photo.jpg';
|
|
17
|
+
|
|
18
|
+
it('should render a pressable wrapping the avatar', () => {
|
|
19
|
+
const { getByRole, getByLabelText } = render(
|
|
20
|
+
<TestWrapper>
|
|
21
|
+
<AvatarButton src={validSrc} alt='Open menu' />
|
|
22
|
+
</TestWrapper>,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
expect(getByRole('button')).toBeTruthy();
|
|
26
|
+
expect(getByLabelText('Open menu')).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should call onPress when pressed', () => {
|
|
30
|
+
const onPress = jest.fn();
|
|
31
|
+
const { getByRole } = render(
|
|
32
|
+
<TestWrapper>
|
|
33
|
+
<AvatarButton src={validSrc} onPress={onPress} />
|
|
34
|
+
</TestWrapper>,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
fireEvent.press(getByRole('button'));
|
|
38
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should forward alt to the underlying Avatar', () => {
|
|
42
|
+
const { getByLabelText } = render(
|
|
43
|
+
<TestWrapper>
|
|
44
|
+
<AvatarButton src={validSrc} alt='User profile' />
|
|
45
|
+
</TestWrapper>,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
expect(getByLabelText('User profile')).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should render fallback icon when no src is provided', () => {
|
|
52
|
+
const { getByTestId } = render(
|
|
53
|
+
<TestWrapper>
|
|
54
|
+
<AvatarButton />
|
|
55
|
+
</TestWrapper>,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(getByTestId('avatar-fallback-icon')).toBeTruthy();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should render image when src is provided', () => {
|
|
62
|
+
const { getByTestId } = render(
|
|
63
|
+
<TestWrapper>
|
|
64
|
+
<AvatarButton src={validSrc} />
|
|
65
|
+
</TestWrapper>,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const image = getByTestId('avatar-image');
|
|
69
|
+
expect(image.props.source).toEqual({ uri: validSrc });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should forward testID to the pressable', () => {
|
|
73
|
+
const { getByTestId } = render(
|
|
74
|
+
<TestWrapper>
|
|
75
|
+
<AvatarButton src={validSrc} testID='avatar-btn' />
|
|
76
|
+
</TestWrapper>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(getByTestId('avatar-btn')).toBeTruthy();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should forward ref to the pressable element', () => {
|
|
83
|
+
const ref = createRef<View>();
|
|
84
|
+
render(
|
|
85
|
+
<TestWrapper>
|
|
86
|
+
<AvatarButton src={validSrc} ref={ref} />
|
|
87
|
+
</TestWrapper>,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expect(ref.current).toBeTruthy();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useDisabledContext } from '@ledgerhq/lumen-utils-shared';
|
|
2
|
+
import { StyleSheet, View } from 'react-native';
|
|
3
|
+
import { useStyleSheet } from '../../../styles';
|
|
4
|
+
import { Avatar } from '../Avatar/Avatar';
|
|
5
|
+
import { Pressable } from '../Utility';
|
|
6
|
+
import type { AvatarButtonProps } from './types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An {@link Avatar} wrapped in a Pressable, for use as an interactive trigger.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://ldls-react-native.vercel.app/?path=/docs/rnative-avatar-button--docs Storybook}
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { AvatarButton } from '@ledgerhq/lumen-ui-rnative';
|
|
15
|
+
*
|
|
16
|
+
* <AvatarButton src="https://example.com/photo.jpg" alt="Open user menu" onPress={openMenu} />
|
|
17
|
+
*/
|
|
18
|
+
export const AvatarButton = ({
|
|
19
|
+
src,
|
|
20
|
+
alt,
|
|
21
|
+
size,
|
|
22
|
+
fallbackText,
|
|
23
|
+
fallbackColor,
|
|
24
|
+
appearance,
|
|
25
|
+
disabled: disabledProp = false,
|
|
26
|
+
style,
|
|
27
|
+
...props
|
|
28
|
+
}: AvatarButtonProps) => {
|
|
29
|
+
const disabled = useDisabledContext({
|
|
30
|
+
consumerName: 'AvatarButton',
|
|
31
|
+
mergeWith: { disabled: disabledProp },
|
|
32
|
+
});
|
|
33
|
+
const styles = useStyles({ disabled });
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Pressable
|
|
37
|
+
accessibilityRole='button'
|
|
38
|
+
disabled={disabled}
|
|
39
|
+
style={[styles.container, style]}
|
|
40
|
+
{...props}
|
|
41
|
+
>
|
|
42
|
+
{({ pressed }) => (
|
|
43
|
+
<>
|
|
44
|
+
<Avatar
|
|
45
|
+
src={src}
|
|
46
|
+
alt={alt}
|
|
47
|
+
size={size}
|
|
48
|
+
fallbackText={fallbackText}
|
|
49
|
+
fallbackColor={fallbackColor}
|
|
50
|
+
appearance={appearance}
|
|
51
|
+
/>
|
|
52
|
+
<View
|
|
53
|
+
style={[styles.overlay, pressed && styles.overlayPressed]}
|
|
54
|
+
pointerEvents='none'
|
|
55
|
+
/>
|
|
56
|
+
</>
|
|
57
|
+
)}
|
|
58
|
+
</Pressable>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const useStyles = ({ disabled }: { disabled: boolean }) =>
|
|
63
|
+
useStyleSheet(
|
|
64
|
+
(t) => ({
|
|
65
|
+
container: {
|
|
66
|
+
...(disabled && { opacity: 0.3 }),
|
|
67
|
+
},
|
|
68
|
+
overlay: {
|
|
69
|
+
...StyleSheet.absoluteFillObject,
|
|
70
|
+
borderRadius: 9999,
|
|
71
|
+
},
|
|
72
|
+
overlayPressed: {
|
|
73
|
+
backgroundColor: t.colors.bg.baseTransparentPressed,
|
|
74
|
+
},
|
|
75
|
+
}),
|
|
76
|
+
[disabled],
|
|
77
|
+
);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StyledPressableProps } from '../../../styles';
|
|
2
|
+
import type { AvatarProps } from '../Avatar/types';
|
|
3
|
+
|
|
4
|
+
export type AvatarButtonProps = Pick<
|
|
5
|
+
AvatarProps,
|
|
6
|
+
'src' | 'alt' | 'size' | 'fallbackText' | 'fallbackColor' | 'appearance'
|
|
7
|
+
> &
|
|
8
|
+
StyledPressableProps & {
|
|
9
|
+
/**
|
|
10
|
+
* When `true`, prevents the user from interacting with the avatar.
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
};
|
|
@@ -3,6 +3,10 @@ import { getDotIndicatorProps } from './getDotIndicatorProps';
|
|
|
3
3
|
|
|
4
4
|
describe('getDotIndicatorProps', () => {
|
|
5
5
|
it('resolves avatar dot indicator props', () => {
|
|
6
|
+
expect(getDotIndicatorProps('avatar', 'xs')).toEqual({
|
|
7
|
+
size: 'sm',
|
|
8
|
+
appearance: 'red',
|
|
9
|
+
});
|
|
6
10
|
expect(getDotIndicatorProps('avatar', 'sm')).toEqual({
|
|
7
11
|
size: 'lg',
|
|
8
12
|
appearance: 'red',
|
|
@@ -11,5 +15,17 @@ describe('getDotIndicatorProps', () => {
|
|
|
11
15
|
size: 'xl',
|
|
12
16
|
appearance: 'red',
|
|
13
17
|
});
|
|
18
|
+
expect(getDotIndicatorProps('avatar', 'lg')).toEqual({
|
|
19
|
+
size: 'xl',
|
|
20
|
+
appearance: 'red',
|
|
21
|
+
});
|
|
22
|
+
expect(getDotIndicatorProps('avatar', 'xl')).toEqual({
|
|
23
|
+
size: 'xl',
|
|
24
|
+
appearance: 'red',
|
|
25
|
+
});
|
|
26
|
+
expect(getDotIndicatorProps('avatar', '2xl')).toEqual({
|
|
27
|
+
size: 'xl',
|
|
28
|
+
appearance: 'red',
|
|
29
|
+
});
|
|
14
30
|
});
|
|
15
31
|
});
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { createPropsResolver } from '@ledgerhq/lumen-utils-shared';
|
|
2
|
+
import type { AvatarSize } from '../Avatar/types';
|
|
2
3
|
import type { DotIndicatorProps } from './types';
|
|
3
4
|
|
|
4
5
|
export const getDotIndicatorProps = createPropsResolver({
|
|
5
|
-
// larger avatars (`lg`, `xl`) don't render a dot indicator
|
|
6
6
|
avatar: {
|
|
7
|
+
xs: { size: 'sm', appearance: 'red' },
|
|
7
8
|
sm: { size: 'lg', appearance: 'red' },
|
|
8
9
|
md: { size: 'xl', appearance: 'red' },
|
|
9
|
-
|
|
10
|
+
lg: { size: 'xl', appearance: 'red' },
|
|
11
|
+
xl: { size: 'xl', appearance: 'red' },
|
|
12
|
+
'2xl': { size: 'xl', appearance: 'red' },
|
|
13
|
+
} satisfies Record<AvatarSize, DotIndicatorProps>,
|
|
10
14
|
});
|
|
@@ -17,7 +17,7 @@ import { CustomTabs, Tab } from '../../../../.storybook/components';
|
|
|
17
17
|
|
|
18
18
|
## Introduction
|
|
19
19
|
|
|
20
|
-
MediaBanner is a promotional banner component that displays a background image alongside a title and description. It is designed for marketing or informational content and supports an optional
|
|
20
|
+
MediaBanner is a promotional banner component that displays a background image alongside a title and description. It is designed for marketing or informational content and supports an optional press action and an optional close button for dismissibility.
|
|
21
21
|
|
|
22
22
|
> View in [Figma](https://www.figma.com/design/JxaLVMTWirCpU0rsbZ30k7/2.-Components-Library?node-id=11235-5982&m=dev).
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ MediaBanner is a promotional banner component that displays a background image a
|
|
|
25
25
|
|
|
26
26
|
<Canvas of={MediaBannerStories.Base} />
|
|
27
27
|
|
|
28
|
-
- **MediaBanner**: Root
|
|
28
|
+
- **MediaBanner**: Root `Pressable` with surface background, rounded corners, and a fixed height.
|
|
29
29
|
- **MediaBannerTitle**: The main label of the banner (clamps at 1 line)
|
|
30
30
|
- **MediaBannerDescription**: Additional context below the title (clamps at 2 lines)
|
|
31
31
|
- **Image**: Background image displayed on the right side with a gradient overlay
|
|
@@ -50,6 +50,12 @@ When the `imageUrl` fails to load, the broken image is hidden while the gradient
|
|
|
50
50
|
|
|
51
51
|
<Canvas of={MediaBannerStories.WithBrokenImage} />
|
|
52
52
|
|
|
53
|
+
### Clickable
|
|
54
|
+
|
|
55
|
+
Pass `onPress` to make the banner interactive. The pressed background feedback is applied on touch.
|
|
56
|
+
|
|
57
|
+
<Canvas of={MediaBannerStories.Clickable} />
|
|
58
|
+
|
|
53
59
|
### Dismissible
|
|
54
60
|
|
|
55
61
|
When `onClose` is provided, the close button allows the user to dismiss the banner.
|
|
@@ -58,8 +64,8 @@ When `onClose` is provided, the close button allows the user to dismiss the bann
|
|
|
58
64
|
|
|
59
65
|
## Accessibility
|
|
60
66
|
|
|
67
|
+
- The root renders as a `Pressable`, which is natively tappable and accessible
|
|
61
68
|
- The close button uses `InteractiveIcon` with proper press states
|
|
62
|
-
- The root element is a `Pressable` for interactive use cases
|
|
63
69
|
- Title and description use semantic `Text` elements
|
|
64
70
|
|
|
65
71
|
</Tab>
|
|
@@ -92,6 +98,22 @@ function MyComponent() {
|
|
|
92
98
|
}
|
|
93
99
|
```
|
|
94
100
|
|
|
101
|
+
### Clickable Banner
|
|
102
|
+
|
|
103
|
+
Pass `onPress` to make the banner navigate or trigger an action:
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
<MediaBanner
|
|
107
|
+
imageUrl='https://example.com/promo.jpg'
|
|
108
|
+
onPress={() => navigation.navigate('Staking')}
|
|
109
|
+
>
|
|
110
|
+
<MediaBannerTitle>Start Staking</MediaBannerTitle>
|
|
111
|
+
<MediaBannerDescription>
|
|
112
|
+
Earn rewards on your crypto assets.
|
|
113
|
+
</MediaBannerDescription>
|
|
114
|
+
</MediaBanner>
|
|
115
|
+
```
|
|
116
|
+
|
|
95
117
|
### With Close Button
|
|
96
118
|
|
|
97
119
|
Add an `onClose` callback to make the banner dismissible:
|
|
@@ -33,6 +33,9 @@ const meta: Meta<typeof MediaBanner> = {
|
|
|
33
33
|
control: 'text',
|
|
34
34
|
description: 'URL of the background image',
|
|
35
35
|
},
|
|
36
|
+
onPress: {
|
|
37
|
+
action: 'pressed',
|
|
38
|
+
},
|
|
36
39
|
onClose: {
|
|
37
40
|
control: 'select',
|
|
38
41
|
description: 'Close action callback',
|
|
@@ -111,6 +114,28 @@ export const WithBrokenImage: Story = {
|
|
|
111
114
|
),
|
|
112
115
|
};
|
|
113
116
|
|
|
117
|
+
export const Clickable: Story = {
|
|
118
|
+
render: () => {
|
|
119
|
+
const [count, setCount] = useState(0);
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<Box lx={{ width: 's400', gap: 's8' }}>
|
|
123
|
+
<MediaBanner
|
|
124
|
+
imageUrl={IMAGE_URL}
|
|
125
|
+
onPress={() => setCount((c) => c + 1)}
|
|
126
|
+
>
|
|
127
|
+
<MediaBannerTitle>Firmware Update</MediaBannerTitle>
|
|
128
|
+
<MediaBannerDescription>
|
|
129
|
+
{count === 0
|
|
130
|
+
? 'Press the banner to get started!'
|
|
131
|
+
: `Pressed ${count} time${count === 1 ? '' : 's'}`}
|
|
132
|
+
</MediaBannerDescription>
|
|
133
|
+
</MediaBanner>
|
|
134
|
+
</Box>
|
|
135
|
+
);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
114
139
|
export const WithClose: Story = {
|
|
115
140
|
render: () => {
|
|
116
141
|
const [visible, setVisible] = useState(true);
|
|
@@ -48,6 +48,24 @@ describe('MediaBanner', () => {
|
|
|
48
48
|
expect(handleClose).toHaveBeenCalledTimes(1);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
+
it('should call onPress when pressed', () => {
|
|
52
|
+
const handlePress = jest.fn();
|
|
53
|
+
const { getByTestId } = render(
|
|
54
|
+
<TestWrapper>
|
|
55
|
+
<MediaBanner
|
|
56
|
+
testID='media-banner'
|
|
57
|
+
imageUrl={IMAGE_URL}
|
|
58
|
+
onPress={handlePress}
|
|
59
|
+
>
|
|
60
|
+
<MediaBannerTitle>Title</MediaBannerTitle>
|
|
61
|
+
</MediaBanner>
|
|
62
|
+
</TestWrapper>,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
fireEvent.press(getByTestId('media-banner'));
|
|
66
|
+
expect(handlePress).toHaveBeenCalledTimes(1);
|
|
67
|
+
});
|
|
68
|
+
|
|
51
69
|
it('should apply surface background color', () => {
|
|
52
70
|
const { getByTestId } = render(
|
|
53
71
|
<TestWrapper>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { Image, StyleSheet } from 'react-native';
|
|
2
|
+
import { Image, StyleSheet, View } from 'react-native';
|
|
3
3
|
import { useCommonTranslation } from '../../../i18n';
|
|
4
4
|
import { useStyleSheet, useTheme } from '../../../styles';
|
|
5
5
|
import { Close } from '../../Symbols';
|
|
@@ -20,6 +20,7 @@ export function MediaBanner({
|
|
|
20
20
|
lx,
|
|
21
21
|
style,
|
|
22
22
|
imageUrl,
|
|
23
|
+
onPress,
|
|
23
24
|
onClose,
|
|
24
25
|
closeAccessibilityLabel,
|
|
25
26
|
children,
|
|
@@ -43,6 +44,7 @@ export function MediaBanner({
|
|
|
43
44
|
overflow: 'hidden',
|
|
44
45
|
flexDirection: 'row',
|
|
45
46
|
minHeight: t.sizes.s72,
|
|
47
|
+
userSelect: 'none',
|
|
46
48
|
},
|
|
47
49
|
contentWrapper: {
|
|
48
50
|
flex: 1,
|
|
@@ -65,31 +67,55 @@ export function MediaBanner({
|
|
|
65
67
|
);
|
|
66
68
|
|
|
67
69
|
return (
|
|
68
|
-
<
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
<Box lx={lx} style={{ position: 'relative' }}>
|
|
71
|
+
<Pressable
|
|
72
|
+
style={[styles.container, style]}
|
|
73
|
+
onPress={onPress}
|
|
74
|
+
accessibilityRole={onPress ? 'button' : 'none'}
|
|
75
|
+
{...props}
|
|
76
|
+
>
|
|
77
|
+
{({ pressed }) => (
|
|
78
|
+
<>
|
|
79
|
+
<Box style={styles.contentWrapper}>
|
|
80
|
+
<Box style={styles.contentContainer}>{children}</Box>
|
|
81
|
+
</Box>
|
|
82
|
+
<Box style={{ width: 120 }}>
|
|
83
|
+
{showImage && (
|
|
84
|
+
<Image
|
|
85
|
+
source={{ uri: imageUrl }}
|
|
86
|
+
style={StyleSheet.absoluteFill}
|
|
87
|
+
resizeMode='cover'
|
|
88
|
+
onError={() => setImageLoadError(true)}
|
|
89
|
+
accessible={false}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
<LinearGradient
|
|
93
|
+
direction='to-topright'
|
|
94
|
+
stops={[
|
|
95
|
+
{ color: t.colors.bg.black, opacity: 0, offset: 0.67 },
|
|
96
|
+
{ color: t.colors.bg.black, opacity: 0.8 },
|
|
97
|
+
]}
|
|
98
|
+
style={StyleSheet.absoluteFill}
|
|
99
|
+
accessible={false}
|
|
100
|
+
pointerEvents='none'
|
|
101
|
+
/>
|
|
102
|
+
</Box>
|
|
103
|
+
{onPress && (
|
|
104
|
+
<View
|
|
105
|
+
pointerEvents='none'
|
|
106
|
+
style={[
|
|
107
|
+
StyleSheet.absoluteFill,
|
|
108
|
+
{
|
|
109
|
+
backgroundColor: pressed
|
|
110
|
+
? t.colors.bg.baseTransparentPressed
|
|
111
|
+
: t.colors.bg.baseTransparent,
|
|
112
|
+
},
|
|
113
|
+
]}
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
</>
|
|
81
117
|
)}
|
|
82
|
-
|
|
83
|
-
direction='to-topright'
|
|
84
|
-
stops={[
|
|
85
|
-
{ color: t.colors.bg.black, opacity: 0, offset: 0.67 },
|
|
86
|
-
{ color: t.colors.bg.black, opacity: 0.8 },
|
|
87
|
-
]}
|
|
88
|
-
style={StyleSheet.absoluteFill}
|
|
89
|
-
accessible={false}
|
|
90
|
-
pointerEvents='none'
|
|
91
|
-
/>
|
|
92
|
-
</Box>
|
|
118
|
+
</Pressable>
|
|
93
119
|
{onClose && (
|
|
94
120
|
<Box style={styles.closeButton}>
|
|
95
121
|
<InteractiveIcon
|
|
@@ -106,7 +132,7 @@ export function MediaBanner({
|
|
|
106
132
|
/>
|
|
107
133
|
</Box>
|
|
108
134
|
)}
|
|
109
|
-
</
|
|
135
|
+
</Box>
|
|
110
136
|
);
|
|
111
137
|
}
|
|
112
138
|
|
|
@@ -123,9 +149,7 @@ export function MediaBannerTitle({
|
|
|
123
149
|
(t) => ({
|
|
124
150
|
title: StyleSheet.flatten([
|
|
125
151
|
t.typographies.body2SemiBold,
|
|
126
|
-
{
|
|
127
|
-
color: t.colors.text.base,
|
|
128
|
-
},
|
|
152
|
+
{ color: t.colors.text.base },
|
|
129
153
|
]),
|
|
130
154
|
}),
|
|
131
155
|
[],
|
|
@@ -151,9 +175,7 @@ export function MediaBannerDescription({
|
|
|
151
175
|
(t) => ({
|
|
152
176
|
description: StyleSheet.flatten([
|
|
153
177
|
t.typographies.body3,
|
|
154
|
-
{
|
|
155
|
-
color: t.colors.text.muted,
|
|
156
|
-
},
|
|
178
|
+
{ color: t.colors.text.muted },
|
|
157
179
|
]),
|
|
158
180
|
}),
|
|
159
181
|
[],
|
|
@@ -21,7 +21,7 @@ export type MediaBannerProps = {
|
|
|
21
21
|
* The banner content (MediaBannerTitle, MediaBannerDescription).
|
|
22
22
|
*/
|
|
23
23
|
children: ReactNode;
|
|
24
|
-
} & Omit<StyledPressableProps, 'children'>;
|
|
24
|
+
} & Omit<StyledPressableProps, 'children' | 'disabled'>;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Props for the MediaBannerTitle component.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Svg, { Path } from 'react-native-svg';
|
|
2
|
+
import createIcon from '../../Components/Icon/createIcon';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Atm icon component for React Native.
|
|
6
|
+
*
|
|
7
|
+
* This icon component is automatically generated from SVG files and uses the createIcon utility
|
|
8
|
+
* to create a consistent icon interface. It supports all standard SVG props (from react-native-svg)
|
|
9
|
+
* and additional size variants defined in the Icon component.
|
|
10
|
+
*
|
|
11
|
+
* @component
|
|
12
|
+
* @param {16 | 20 | 24 | 40 | 48 | 56} [size=24] - The size of the icon in pixels.
|
|
13
|
+
* @param {string} [color] - The color of the icon.
|
|
14
|
+
* @param {SVGProps} [...props] - All standard SVG element props (from react-native-svg).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Basic usage with default size (24px)
|
|
18
|
+
* import { Atm } from '@ledgerhq/lumen-ui-rnative/symbols';
|
|
19
|
+
*
|
|
20
|
+
* <Atm />
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // With custom size and style
|
|
24
|
+
* <Atm size={40} color="warning" lx={{ marginTop: 's4' }} />
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Used within a Button component
|
|
28
|
+
* import { Button } from '@ledgerhq/lumen-ui-rnative';
|
|
29
|
+
*
|
|
30
|
+
* <Button icon={Atm} size="md">
|
|
31
|
+
* Click me
|
|
32
|
+
* </Button>
|
|
33
|
+
*/
|
|
34
|
+
export const Atm = createIcon(
|
|
35
|
+
'Atm',
|
|
36
|
+
<Svg width={24} height={24} fill='currentColor' viewBox='0 0 16 16'>
|
|
37
|
+
<Path
|
|
38
|
+
stroke='currentColor'
|
|
39
|
+
strokeLinecap='round'
|
|
40
|
+
strokeLinejoin='round'
|
|
41
|
+
strokeWidth={1.3}
|
|
42
|
+
d='M4.665 9.176H3.331a1.334 1.334 0 0 1-1.333-1.334V3.841c0-.737.597-1.334 1.333-1.334h9.338c.736 0 1.334.597 1.334 1.334v4.001c0 .737-.598 1.334-1.334 1.334h-1.334M7 11.878h2m2.335-6.036h-6.67v7.02a.98.98 0 0 0 .983.983h4.704a.98.98 0 0 0 .983-.982zM7 8.875a1 1 0 1 1 2 0 1 1 0 0 1-2 0'
|
|
43
|
+
/>
|
|
44
|
+
</Svg>,
|
|
45
|
+
);
|