@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
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { AVATAR_COLOR_KEYS } from '@ledgerhq/lumen-utils-shared';
|
|
1
2
|
import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
|
|
2
|
-
import { View, Text, Pressable, Linking } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { DotIndicator, getDotIndicatorProps } from '../DotIndicator';
|
|
5
5
|
import { Box } from '../Utility';
|
|
6
6
|
import { Avatar } from './Avatar';
|
|
7
|
+
import { resolveAvatarColor } from '.';
|
|
7
8
|
|
|
8
9
|
const meta = {
|
|
9
10
|
component: Avatar,
|
|
@@ -26,6 +27,12 @@ type Story = StoryObj<typeof meta>;
|
|
|
26
27
|
const exampleSrc =
|
|
27
28
|
'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';
|
|
28
29
|
|
|
30
|
+
const getInitials = (index: number) => {
|
|
31
|
+
const left = String.fromCharCode(65 + index * 2);
|
|
32
|
+
const right = String.fromCharCode(66 + index * 2);
|
|
33
|
+
return left + right;
|
|
34
|
+
};
|
|
35
|
+
|
|
29
36
|
export const Base: Story = {
|
|
30
37
|
args: {
|
|
31
38
|
src: exampleSrc,
|
|
@@ -44,110 +51,78 @@ export const Base: Story = {
|
|
|
44
51
|
|
|
45
52
|
export const SizeShowcase: Story = {
|
|
46
53
|
render: () => (
|
|
47
|
-
<Box
|
|
48
|
-
lx={{
|
|
49
|
-
alignItems: 'stretch',
|
|
50
|
-
flexDirection: 'row',
|
|
51
|
-
gap: 's16',
|
|
52
|
-
}}
|
|
53
|
-
>
|
|
54
|
-
<View style={{ alignItems: 'center', justifyContent: 'flex-end' }}>
|
|
55
|
-
<Avatar src={exampleSrc} alt='avatar' size='sm' />
|
|
56
|
-
<Text style={{ marginTop: 4 }}>sm</Text>
|
|
57
|
-
</View>
|
|
58
|
-
<View style={{ alignItems: 'center', justifyContent: 'flex-end' }}>
|
|
59
|
-
<Avatar src={exampleSrc} alt='avatar' size='md' />
|
|
60
|
-
<Text style={{ marginTop: 4 }}>md</Text>
|
|
61
|
-
</View>
|
|
62
|
-
<View style={{ alignItems: 'center', justifyContent: 'flex-end' }}>
|
|
63
|
-
<Avatar src={exampleSrc} alt='avatar' size='lg' />
|
|
64
|
-
<Text style={{ marginTop: 4 }}>lg</Text>
|
|
65
|
-
</View>
|
|
66
|
-
<View style={{ alignItems: 'center', justifyContent: 'flex-end' }}>
|
|
67
|
-
<Avatar src={exampleSrc} alt='avatar' size='xl' />
|
|
68
|
-
<Text style={{ marginTop: 4 }}>xl</Text>
|
|
69
|
-
</View>
|
|
70
|
-
</Box>
|
|
71
|
-
),
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const AppearanceShowcaseRender = () => {
|
|
75
|
-
return (
|
|
76
54
|
<Box lx={{ gap: 's8' }}>
|
|
77
|
-
<Box lx={{
|
|
78
|
-
|
|
79
|
-
|
|
55
|
+
<Box lx={{ alignItems: 'flex-end', flexDirection: 'row', gap: 's16' }}>
|
|
56
|
+
{(['xs', 'sm', 'md', 'lg', 'xl', '2xl'] as const).map((size) => (
|
|
57
|
+
<Avatar key={size} src={exampleSrc} alt={size} size={size} />
|
|
58
|
+
))}
|
|
59
|
+
</Box>
|
|
60
|
+
<Box lx={{ alignItems: 'flex-end', flexDirection: 'row', gap: 's16' }}>
|
|
61
|
+
{(['xs', 'sm', 'md', 'lg', 'xl', '2xl'] as const).map((size) => (
|
|
62
|
+
<Avatar key={size} alt={size} size={size} fallbackText='AB' />
|
|
63
|
+
))}
|
|
80
64
|
</Box>
|
|
81
|
-
<Box lx={{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
size='md'
|
|
86
|
-
appearance='gray'
|
|
87
|
-
/>
|
|
88
|
-
<Avatar
|
|
89
|
-
src={exampleSrc}
|
|
90
|
-
alt='transparent with image'
|
|
91
|
-
size='md'
|
|
92
|
-
appearance='transparent'
|
|
93
|
-
/>
|
|
65
|
+
<Box lx={{ alignItems: 'flex-end', flexDirection: 'row', gap: 's16' }}>
|
|
66
|
+
{(['xs', 'sm', 'md', 'lg', 'xl', '2xl'] as const).map((size) => (
|
|
67
|
+
<Avatar key={size} alt={size} size={size} />
|
|
68
|
+
))}
|
|
94
69
|
</Box>
|
|
95
70
|
</Box>
|
|
96
|
-
)
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export const AppearanceShowcase: Story = {
|
|
100
|
-
render: () => <AppearanceShowcaseRender />,
|
|
71
|
+
),
|
|
101
72
|
};
|
|
102
73
|
|
|
103
74
|
export const FallbackShowcase: Story = {
|
|
104
|
-
args: {
|
|
105
|
-
src: 'https://brokenLink.random',
|
|
106
|
-
size: 'md',
|
|
107
|
-
alt: 'Fallback example',
|
|
108
|
-
},
|
|
109
|
-
render: (args) => <Avatar {...args} />,
|
|
110
75
|
parameters: {
|
|
111
76
|
docs: {
|
|
112
77
|
source: {
|
|
113
|
-
code: `<Avatar
|
|
78
|
+
code: `<Avatar fallbackColor={resolveAvatarColor(user.id)} alt={user.name} />`,
|
|
114
79
|
},
|
|
115
80
|
},
|
|
116
81
|
},
|
|
82
|
+
render: () => (
|
|
83
|
+
<Box lx={{ gap: 's16' }}>
|
|
84
|
+
<Box lx={{ flexDirection: 'row', flexWrap: 'wrap', gap: 's16' }}>
|
|
85
|
+
{AVATAR_COLOR_KEYS.map((_, i) => (
|
|
86
|
+
<Avatar
|
|
87
|
+
key={i}
|
|
88
|
+
fallbackColor={resolveAvatarColor(`user-${i}`)}
|
|
89
|
+
fallbackText={getInitials(i)}
|
|
90
|
+
alt={getInitials(i)}
|
|
91
|
+
/>
|
|
92
|
+
))}
|
|
93
|
+
<Avatar fallbackText={getInitials(AVATAR_COLOR_KEYS.length)} />
|
|
94
|
+
</Box>
|
|
95
|
+
<Box lx={{ flexDirection: 'row', flexWrap: 'wrap', gap: 's16' }}>
|
|
96
|
+
{AVATAR_COLOR_KEYS.map((_, i) => (
|
|
97
|
+
<Avatar
|
|
98
|
+
key={i}
|
|
99
|
+
fallbackColor={resolveAvatarColor(`user-${i}`)}
|
|
100
|
+
alt={`User ${i}`}
|
|
101
|
+
/>
|
|
102
|
+
))}
|
|
103
|
+
<Avatar />
|
|
104
|
+
</Box>
|
|
105
|
+
</Box>
|
|
106
|
+
),
|
|
117
107
|
};
|
|
118
108
|
|
|
119
|
-
export const
|
|
109
|
+
export const AppearanceShowcase: Story = {
|
|
120
110
|
render: () => (
|
|
121
|
-
<Box
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}}
|
|
126
|
-
>
|
|
127
|
-
<Avatar src={exampleSrc} alt='avatar' size='md' />
|
|
128
|
-
<DotIndicator {...getDotIndicatorProps('avatar', 'md')}>
|
|
129
|
-
<Avatar src={exampleSrc} alt='avatar' size='md' />
|
|
130
|
-
</DotIndicator>
|
|
111
|
+
<Box lx={{ flexDirection: 'row', alignItems: 'center', gap: 's16' }}>
|
|
112
|
+
<Avatar size='md' alt='No ring' />
|
|
113
|
+
<Avatar size='md' alt='Thin ring' appearance='thin' />
|
|
114
|
+
<Avatar size='md' alt='Thick ring' appearance='thick' />
|
|
131
115
|
</Box>
|
|
132
116
|
),
|
|
133
117
|
};
|
|
134
118
|
|
|
135
|
-
const
|
|
136
|
-
Linking.openURL('https://shop.ledger.com/pages/ledger-nano-gen5');
|
|
137
|
-
|
|
138
|
-
export const InteractiveShowcase: Story = {
|
|
119
|
+
export const NotificationShowcase: Story = {
|
|
139
120
|
render: () => (
|
|
140
|
-
<
|
|
141
|
-
|
|
142
|
-
style={({ pressed }) => ({
|
|
143
|
-
borderRadius: 9999,
|
|
144
|
-
opacity: pressed ? 0.7 : 1,
|
|
145
|
-
backgroundColor: pressed ? 'rgba(0, 0, 0, 0.05)' : 'transparent',
|
|
146
|
-
})}
|
|
147
|
-
>
|
|
121
|
+
<Box lx={{ flexDirection: 'row', gap: 's16' }}>
|
|
122
|
+
<Avatar src={exampleSrc} alt='avatar' size='md' />
|
|
148
123
|
<DotIndicator {...getDotIndicatorProps('avatar', 'md')}>
|
|
149
|
-
<Avatar src={exampleSrc} size='md' />
|
|
124
|
+
<Avatar src={exampleSrc} alt='avatar' size='md' />
|
|
150
125
|
</DotIndicator>
|
|
151
|
-
</
|
|
126
|
+
</Box>
|
|
152
127
|
),
|
|
153
128
|
};
|
|
@@ -16,13 +16,14 @@ const TestWrapper = ({ children }: { children: React.ReactNode }) => (
|
|
|
16
16
|
describe('Avatar Component', () => {
|
|
17
17
|
const testSrc =
|
|
18
18
|
'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';
|
|
19
|
+
|
|
19
20
|
it('should render correctly with minimal props', () => {
|
|
20
21
|
const { getByLabelText } = render(
|
|
21
22
|
<TestWrapper>
|
|
22
23
|
<Avatar src={testSrc} />
|
|
23
24
|
</TestWrapper>,
|
|
24
25
|
);
|
|
25
|
-
getByLabelText('avatar');
|
|
26
|
+
getByLabelText('User avatar');
|
|
26
27
|
});
|
|
27
28
|
|
|
28
29
|
it('should render with custom alt text', () => {
|
|
@@ -34,35 +35,35 @@ describe('Avatar Component', () => {
|
|
|
34
35
|
getByLabelText('user profile');
|
|
35
36
|
});
|
|
36
37
|
|
|
37
|
-
it('should render with
|
|
38
|
+
it('should render with md size by default', () => {
|
|
38
39
|
const { getByTestId } = render(
|
|
39
40
|
<TestWrapper>
|
|
40
41
|
<Avatar testID='avatar-id' />
|
|
41
42
|
</TestWrapper>,
|
|
42
43
|
);
|
|
44
|
+
expect(getByTestId('avatar-id').props.style.width).toBe(sizes.s48);
|
|
45
|
+
expect(getByTestId('avatar-id').props.style.height).toBe(sizes.s48);
|
|
46
|
+
});
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
it('should render with xs size when specified', () => {
|
|
49
|
+
const { getByTestId } = render(
|
|
50
|
+
<TestWrapper>
|
|
51
|
+
<Avatar testID='avatar-id' size='xs' />
|
|
52
|
+
</TestWrapper>,
|
|
46
53
|
);
|
|
54
|
+
expect(getByTestId('avatar-id').props.style.width).toBe(sizes.s24);
|
|
55
|
+
expect(getByTestId('avatar-id').props.style.height).toBe(sizes.s24);
|
|
47
56
|
});
|
|
48
57
|
|
|
49
|
-
it
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
</TestWrapper>,
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
expect(getByTestId('avatar-id').props.style.backgroundColor).toBe(
|
|
62
|
-
expectedColor,
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
|
-
);
|
|
58
|
+
it('should render with 2xl size when specified', () => {
|
|
59
|
+
const { getByTestId } = render(
|
|
60
|
+
<TestWrapper>
|
|
61
|
+
<Avatar testID='avatar-id' size='2xl' />
|
|
62
|
+
</TestWrapper>,
|
|
63
|
+
);
|
|
64
|
+
expect(getByTestId('avatar-id').props.style.width).toBe(sizes.s128);
|
|
65
|
+
expect(getByTestId('avatar-id').props.style.height).toBe(sizes.s128);
|
|
66
|
+
});
|
|
66
67
|
|
|
67
68
|
it('should render with different sizes', () => {
|
|
68
69
|
const { getByTestId, rerender } = render(
|
|
@@ -71,15 +72,6 @@ describe('Avatar Component', () => {
|
|
|
71
72
|
</TestWrapper>,
|
|
72
73
|
);
|
|
73
74
|
expect(getByTestId('avatar-id').props.style.width).toBe(sizes.s40);
|
|
74
|
-
expect(getByTestId('avatar-id').props.style.height).toBe(sizes.s40);
|
|
75
|
-
|
|
76
|
-
rerender(
|
|
77
|
-
<TestWrapper>
|
|
78
|
-
<Avatar testID='avatar-id' size='md' />
|
|
79
|
-
</TestWrapper>,
|
|
80
|
-
);
|
|
81
|
-
expect(getByTestId('avatar-id').props.style.width).toBe(sizes.s48);
|
|
82
|
-
expect(getByTestId('avatar-id').props.style.height).toBe(sizes.s48);
|
|
83
75
|
|
|
84
76
|
rerender(
|
|
85
77
|
<TestWrapper>
|
|
@@ -87,7 +79,6 @@ describe('Avatar Component', () => {
|
|
|
87
79
|
</TestWrapper>,
|
|
88
80
|
);
|
|
89
81
|
expect(getByTestId('avatar-id').props.style.width).toBe(sizes.s56);
|
|
90
|
-
expect(getByTestId('avatar-id').props.style.height).toBe(sizes.s56);
|
|
91
82
|
|
|
92
83
|
rerender(
|
|
93
84
|
<TestWrapper>
|
|
@@ -95,7 +86,6 @@ describe('Avatar Component', () => {
|
|
|
95
86
|
</TestWrapper>,
|
|
96
87
|
);
|
|
97
88
|
expect(getByTestId('avatar-id').props.style.width).toBe(sizes.s72);
|
|
98
|
-
expect(getByTestId('avatar-id').props.style.height).toBe(sizes.s72);
|
|
99
89
|
});
|
|
100
90
|
|
|
101
91
|
it('should render fallback icon when no src is provided', () => {
|
|
@@ -105,13 +95,47 @@ describe('Avatar Component', () => {
|
|
|
105
95
|
</TestWrapper>,
|
|
106
96
|
);
|
|
107
97
|
|
|
108
|
-
const avatarContainer = getByLabelText('avatar');
|
|
98
|
+
const avatarContainer = getByLabelText('User avatar');
|
|
109
99
|
expect(avatarContainer).toBeTruthy();
|
|
110
100
|
expect(avatarContainer.props.accessibilityRole).toBe('image');
|
|
111
|
-
|
|
112
101
|
expect(getByTestId('avatar-fallback-icon')).toBeTruthy();
|
|
113
102
|
});
|
|
114
103
|
|
|
104
|
+
it('should render fallback text instead of the icon when provided', () => {
|
|
105
|
+
const { getByText, queryByTestId } = render(
|
|
106
|
+
<TestWrapper>
|
|
107
|
+
<Avatar fallbackText='AB' />
|
|
108
|
+
</TestWrapper>,
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
expect(getByText('AB')).toBeTruthy();
|
|
112
|
+
expect(queryByTestId('avatar-fallback-icon')).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should apply the fallback color as the background when falling back', () => {
|
|
116
|
+
const { getByTestId } = render(
|
|
117
|
+
<TestWrapper>
|
|
118
|
+
<Avatar testID='avatar-id' fallbackColor='#aed09c' />
|
|
119
|
+
</TestWrapper>,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
expect(getByTestId('avatar-id').props.style.backgroundColor).toBe(
|
|
123
|
+
'#aed09c',
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should not apply the fallback color when an image is shown', () => {
|
|
128
|
+
const { getByTestId } = render(
|
|
129
|
+
<TestWrapper>
|
|
130
|
+
<Avatar testID='avatar-id' src={testSrc} fallbackColor='#aed09c' />
|
|
131
|
+
</TestWrapper>,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(getByTestId('avatar-id').props.style.backgroundColor).toBe(
|
|
135
|
+
colors.bg.baseTransparentHover,
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
115
139
|
it('should render image when src is provided', () => {
|
|
116
140
|
const { getByLabelText, getByTestId } = render(
|
|
117
141
|
<TestWrapper>
|
|
@@ -199,30 +223,6 @@ describe('Avatar Component', () => {
|
|
|
199
223
|
expect(getByTestId('avatar-id')).toBeTruthy();
|
|
200
224
|
});
|
|
201
225
|
|
|
202
|
-
it('should style the notification indicator based on the avatar size', () => {
|
|
203
|
-
const { toJSON, rerender } = render(
|
|
204
|
-
<TestWrapper>
|
|
205
|
-
<DotIndicator {...getDotIndicatorProps('avatar', 'sm')}>
|
|
206
|
-
<Avatar testID='avatar-id' size='sm' />
|
|
207
|
-
</DotIndicator>
|
|
208
|
-
</TestWrapper>,
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
let dot = toJSON().children[0];
|
|
212
|
-
expect(dot.props.style.height).toBe(sizes.s10);
|
|
213
|
-
|
|
214
|
-
rerender(
|
|
215
|
-
<TestWrapper>
|
|
216
|
-
<DotIndicator {...getDotIndicatorProps('avatar', 'md')}>
|
|
217
|
-
<Avatar testID='avatar-id' size='md' />
|
|
218
|
-
</DotIndicator>
|
|
219
|
-
</TestWrapper>,
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
dot = toJSON().children[0];
|
|
223
|
-
expect(dot.props.style.height).toBe(sizes.s12);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
226
|
it('should apply custom styles', () => {
|
|
227
227
|
const customStyle = { borderWidth: 2 };
|
|
228
228
|
const { getByTestId } = render(
|
|
@@ -1,40 +1,53 @@
|
|
|
1
|
+
import type { TypographyDefinition } from '@ledgerhq/lumen-design-core';
|
|
1
2
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import { Image, StyleSheet } from 'react-native';
|
|
3
|
+
import { Image, StyleSheet, Text, View } from 'react-native';
|
|
3
4
|
import { useCommonTranslation } from '../../../i18n';
|
|
4
5
|
import { useStyleSheet } from '../../../styles';
|
|
5
6
|
import { User } from '../../Symbols';
|
|
7
|
+
import type { IconSize } from '../Icon';
|
|
6
8
|
import { Box } from '../Utility';
|
|
7
9
|
import type { AvatarProps } from './types';
|
|
8
10
|
|
|
9
|
-
type Appearance = NonNullable<AvatarProps['appearance']>;
|
|
10
11
|
type Size = NonNullable<AvatarProps['size']>;
|
|
11
12
|
|
|
12
|
-
const
|
|
13
|
+
const fallbackIconSizes: Record<Size, IconSize> = {
|
|
14
|
+
xs: 12,
|
|
13
15
|
sm: 16,
|
|
14
16
|
md: 24,
|
|
15
17
|
lg: 32,
|
|
16
18
|
xl: 40,
|
|
17
|
-
|
|
19
|
+
'2xl': 56,
|
|
20
|
+
};
|
|
18
21
|
|
|
19
22
|
const useStyles = ({
|
|
20
|
-
appearance,
|
|
21
23
|
size,
|
|
24
|
+
fallbackColor,
|
|
25
|
+
shouldFallback,
|
|
26
|
+
appearance,
|
|
22
27
|
}: {
|
|
23
|
-
appearance: Appearance;
|
|
24
28
|
size: Size;
|
|
29
|
+
fallbackColor?: string;
|
|
30
|
+
shouldFallback: boolean;
|
|
31
|
+
appearance?: 'thin' | 'thick';
|
|
25
32
|
}) => {
|
|
26
33
|
return useStyleSheet(
|
|
27
34
|
(t) => {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
const sizeMap: Record<Size, { size: number }> = {
|
|
36
|
+
xs: { size: t.sizes.s24 },
|
|
37
|
+
sm: { size: t.sizes.s40 },
|
|
38
|
+
md: { size: t.sizes.s48 },
|
|
39
|
+
lg: { size: t.sizes.s56 },
|
|
40
|
+
xl: { size: t.sizes.s72 },
|
|
41
|
+
'2xl': { size: t.sizes.s128 },
|
|
31
42
|
};
|
|
32
43
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
const fallbackTextTypography: Record<Size, TypographyDefinition> = {
|
|
45
|
+
xs: t.typographies.body4SemiBold,
|
|
46
|
+
sm: t.typographies.body1SemiBold,
|
|
47
|
+
md: t.typographies.heading5SemiBold,
|
|
48
|
+
lg: t.typographies.heading4SemiBold,
|
|
49
|
+
xl: t.typographies.heading2SemiBold,
|
|
50
|
+
'2xl': t.typographies.heading1SemiBold,
|
|
38
51
|
};
|
|
39
52
|
|
|
40
53
|
return {
|
|
@@ -43,28 +56,76 @@ const useStyles = ({
|
|
|
43
56
|
width: sizeMap[size].size,
|
|
44
57
|
height: sizeMap[size].size,
|
|
45
58
|
borderRadius: 9999,
|
|
46
|
-
|
|
59
|
+
overflow: 'hidden',
|
|
60
|
+
backgroundColor:
|
|
61
|
+
shouldFallback && fallbackColor
|
|
62
|
+
? fallbackColor
|
|
63
|
+
: t.colors.bg.baseTransparentHover,
|
|
47
64
|
alignItems: 'center',
|
|
48
65
|
justifyContent: 'center',
|
|
49
|
-
|
|
66
|
+
},
|
|
67
|
+
fallbackText: {
|
|
68
|
+
...fallbackTextTypography[size],
|
|
69
|
+
color: fallbackColor ? t.colors.text.black : t.colors.text.base,
|
|
50
70
|
},
|
|
51
71
|
image: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
position: 'absolute',
|
|
73
|
+
top: 0,
|
|
74
|
+
left: 0,
|
|
75
|
+
right: 0,
|
|
76
|
+
bottom: 0,
|
|
77
|
+
},
|
|
78
|
+
insetBorder: {
|
|
79
|
+
position: 'absolute',
|
|
80
|
+
top: 0,
|
|
81
|
+
left: 0,
|
|
82
|
+
right: 0,
|
|
83
|
+
bottom: 0,
|
|
55
84
|
borderRadius: 9999,
|
|
85
|
+
...(appearance === 'thin' && {
|
|
86
|
+
borderWidth: 1,
|
|
87
|
+
borderColor: t.colors.border.icon,
|
|
88
|
+
}),
|
|
89
|
+
...(appearance === 'thick' && {
|
|
90
|
+
borderWidth: 2,
|
|
91
|
+
borderColor: t.colors.border.mutedSubtleTransparent,
|
|
92
|
+
}),
|
|
56
93
|
},
|
|
57
94
|
};
|
|
58
95
|
},
|
|
59
|
-
[
|
|
96
|
+
[size, fallbackColor, shouldFallback, appearance],
|
|
60
97
|
);
|
|
61
98
|
};
|
|
62
99
|
|
|
100
|
+
const FallbackContent = ({
|
|
101
|
+
size,
|
|
102
|
+
fallbackText,
|
|
103
|
+
fallbackColor,
|
|
104
|
+
styles,
|
|
105
|
+
}: {
|
|
106
|
+
size: Size;
|
|
107
|
+
fallbackText?: string;
|
|
108
|
+
fallbackColor?: string;
|
|
109
|
+
styles: ReturnType<typeof useStyles>;
|
|
110
|
+
}) =>
|
|
111
|
+
fallbackText ? (
|
|
112
|
+
<Text style={styles.fallbackText} selectable={false}>
|
|
113
|
+
{fallbackText}
|
|
114
|
+
</Text>
|
|
115
|
+
) : (
|
|
116
|
+
<User
|
|
117
|
+
size={fallbackIconSizes[size]}
|
|
118
|
+
color={fallbackColor ? 'black' : 'base'}
|
|
119
|
+
accessible={false}
|
|
120
|
+
testID='avatar-fallback-icon'
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
|
|
63
124
|
/**
|
|
64
125
|
* A circular avatar component that displays a user image or fallback icon.
|
|
65
126
|
*
|
|
66
|
-
* When the image fails to load or no src is provided, displays
|
|
67
|
-
*
|
|
127
|
+
* When the image fails to load or no src is provided, displays either the
|
|
128
|
+
* `fallbackText` (e.g. initials) or a User icon fallback.
|
|
68
129
|
*
|
|
69
130
|
* @see {@link https://ldls-react-native.vercel.app/?path=/docs/rnative-avatar--docs Storybook}
|
|
70
131
|
*
|
|
@@ -77,16 +138,23 @@ export const Avatar = ({
|
|
|
77
138
|
lx,
|
|
78
139
|
style,
|
|
79
140
|
src,
|
|
80
|
-
alt
|
|
81
|
-
appearance = 'transparent',
|
|
141
|
+
alt,
|
|
82
142
|
size = 'md',
|
|
143
|
+
fallbackText,
|
|
144
|
+
fallbackColor,
|
|
145
|
+
appearance,
|
|
83
146
|
ref,
|
|
84
147
|
...props
|
|
85
148
|
}: AvatarProps) => {
|
|
86
149
|
const { t } = useCommonTranslation();
|
|
87
150
|
const [error, setError] = useState<boolean>(false);
|
|
88
151
|
const shouldFallback = !src || error;
|
|
89
|
-
const styles = useStyles({
|
|
152
|
+
const styles = useStyles({
|
|
153
|
+
size,
|
|
154
|
+
fallbackColor,
|
|
155
|
+
shouldFallback,
|
|
156
|
+
appearance,
|
|
157
|
+
});
|
|
90
158
|
|
|
91
159
|
const resolvedAlt = alt || t('components.avatar.defaultAriaLabel');
|
|
92
160
|
|
|
@@ -94,7 +162,7 @@ export const Avatar = ({
|
|
|
94
162
|
setError(false);
|
|
95
163
|
}, [src]);
|
|
96
164
|
|
|
97
|
-
|
|
165
|
+
return (
|
|
98
166
|
<Box
|
|
99
167
|
ref={ref}
|
|
100
168
|
lx={lx}
|
|
@@ -104,10 +172,11 @@ export const Avatar = ({
|
|
|
104
172
|
{...props}
|
|
105
173
|
>
|
|
106
174
|
{shouldFallback ? (
|
|
107
|
-
<
|
|
108
|
-
size={
|
|
109
|
-
|
|
110
|
-
|
|
175
|
+
<FallbackContent
|
|
176
|
+
size={size}
|
|
177
|
+
fallbackText={fallbackText}
|
|
178
|
+
fallbackColor={fallbackColor}
|
|
179
|
+
styles={styles}
|
|
111
180
|
/>
|
|
112
181
|
) : (
|
|
113
182
|
<Image
|
|
@@ -118,8 +187,7 @@ export const Avatar = ({
|
|
|
118
187
|
testID='avatar-image'
|
|
119
188
|
/>
|
|
120
189
|
)}
|
|
190
|
+
{appearance && <View style={styles.insetBorder} pointerEvents='none' />}
|
|
121
191
|
</Box>
|
|
122
192
|
);
|
|
123
|
-
|
|
124
|
-
return avatarContent;
|
|
125
193
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { primitiveColorTokens } from '@ledgerhq/lumen-design-core';
|
|
2
|
+
import {
|
|
3
|
+
resolveAvatarColorKey,
|
|
4
|
+
type AvatarColorKey,
|
|
5
|
+
} from '@ledgerhq/lumen-utils-shared';
|
|
6
|
+
|
|
7
|
+
// either light or dark works, they're the same regardless of theme
|
|
8
|
+
const AVATAR_COLOR_TOKENS: Record<AvatarColorKey, string> =
|
|
9
|
+
primitiveColorTokens.light.avatar;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves a stable identifier (e.g. a user id) to one of the avatar pastel
|
|
13
|
+
* colors. The same identifier always resolves to the same color.
|
|
14
|
+
*
|
|
15
|
+
* Pass the result directly to `<Avatar fallbackColor={resolveAvatarColor(id)} />`.
|
|
16
|
+
*/
|
|
17
|
+
export function resolveAvatarColor(identifier: string): string {
|
|
18
|
+
return AVATAR_COLOR_TOKENS[resolveAvatarColorKey(identifier)];
|
|
19
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { StyledViewProps } from '../../../styles';
|
|
2
2
|
|
|
3
|
+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
|
|
4
|
+
|
|
3
5
|
export type AvatarProps = {
|
|
4
6
|
/**
|
|
5
|
-
* Image source URL. When undefined or on load error, displays a fallback
|
|
7
|
+
* Image source URL. When undefined or on load error, displays a fallback.
|
|
6
8
|
* @optional
|
|
7
9
|
*/
|
|
8
10
|
src?: string;
|
|
@@ -12,15 +14,29 @@ export type AvatarProps = {
|
|
|
12
14
|
*/
|
|
13
15
|
alt?: string;
|
|
14
16
|
/**
|
|
15
|
-
* The
|
|
17
|
+
* The size variant of the avatar.
|
|
16
18
|
* @optional
|
|
17
|
-
* @default
|
|
19
|
+
* @default md
|
|
18
20
|
*/
|
|
19
|
-
|
|
21
|
+
size?: AvatarSize;
|
|
20
22
|
/**
|
|
21
|
-
*
|
|
23
|
+
* Background color behind the fallback when no image is displayed.
|
|
24
|
+
* Use `resolveAvatarColor` from `@ledgerhq/lumen-ui-rnative` to derive
|
|
25
|
+
* a stable pastel color from an identifier such as a user id.
|
|
26
|
+
* @optional
|
|
27
|
+
*/
|
|
28
|
+
fallbackColor?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Short text shown in place of the fallback icon when no image is displayed,
|
|
31
|
+
* typically a user's initials.
|
|
32
|
+
* @optional
|
|
33
|
+
*/
|
|
34
|
+
fallbackText?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Appearance for the avatar.
|
|
37
|
+
* - `thin`: 1px ring using the icon border color
|
|
38
|
+
* - `thick`: 2px ring using the muted subtle transparent border color
|
|
22
39
|
* @optional
|
|
23
|
-
* @default md
|
|
24
40
|
*/
|
|
25
|
-
|
|
41
|
+
appearance?: 'thin' | 'thick';
|
|
26
42
|
} & Omit<StyledViewProps, 'children'>;
|