@ledgerhq/lumen-ui-rnative 0.1.68 → 0.1.69
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/core/MediaImage/MediaImage.js +1 -1
- package/dist/module/lib/Components/core/MediaImage/MediaImage.js.map +1 -1
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.figma.js +215 -0
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.figma.js.map +1 -0
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.js +221 -0
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.js.map +1 -0
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.mdx +90 -0
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.stories.js +184 -0
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.stories.js.map +1 -0
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.test.js +246 -0
- package/dist/module/lib/Components/core/MediaImageGroup/MediaImageGroup.test.js.map +1 -0
- package/dist/module/lib/Components/core/MediaImageGroup/index.js +5 -0
- package/dist/module/lib/Components/core/MediaImageGroup/index.js.map +1 -0
- package/dist/module/lib/Components/core/MediaImageGroup/types.js +4 -0
- package/dist/module/lib/Components/core/MediaImageGroup/types.js.map +1 -0
- package/dist/module/lib/Components/core/index.js +1 -0
- package/dist/module/lib/Components/core/index.js.map +1 -1
- package/dist/module/lib/Components/symbols/icons/Ar.js +2 -2
- package/dist/module/lib/Components/symbols/icons/Ar.js.map +1 -1
- package/dist/module/lib/Components/symbols/icons/Range.js +1 -1
- package/dist/module/lib/Components/symbols/icons/Share.js +1 -1
- package/dist/module/lib/Components/symbols/icons/{Charon.js → ShoppingInvoiceList.js} +8 -8
- package/dist/module/lib/Components/symbols/icons/ShoppingInvoiceList.js.map +1 -0
- package/dist/module/lib/Components/symbols/icons/WalletInput.js +1 -1
- package/dist/module/lib/Components/symbols/icons/WalletInput.js.map +1 -1
- package/dist/module/lib/Components/symbols/index.js +1 -4
- package/dist/module/lib/Components/symbols/index.js.map +1 -1
- package/dist/typescript/src/lib/Components/core/MediaImage/MediaImage.d.ts +4 -0
- package/dist/typescript/src/lib/Components/core/MediaImage/MediaImage.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/core/MediaImageGroup/MediaImageGroup.d.ts +33 -0
- package/dist/typescript/src/lib/Components/core/MediaImageGroup/MediaImageGroup.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/MediaImageGroup/index.d.ts +3 -0
- package/dist/typescript/src/lib/Components/core/MediaImageGroup/index.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/MediaImageGroup/types.d.ts +66 -0
- package/dist/typescript/src/lib/Components/core/MediaImageGroup/types.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/core/index.d.ts +1 -0
- package/dist/typescript/src/lib/Components/core/index.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/symbols/icons/{Charon.d.ts → ShoppingInvoiceList.d.ts} +7 -7
- package/dist/typescript/src/lib/Components/symbols/icons/ShoppingInvoiceList.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/symbols/index.d.ts +1 -4
- package/dist/typescript/src/lib/Components/symbols/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/Components/core/MediaImage/MediaImage.tsx +1 -1
- package/src/lib/Components/core/MediaImageGroup/MediaImageGroup.figma.tsx +119 -0
- package/src/lib/Components/core/MediaImageGroup/MediaImageGroup.mdx +90 -0
- package/src/lib/Components/core/MediaImageGroup/MediaImageGroup.stories.tsx +122 -0
- package/src/lib/Components/core/MediaImageGroup/MediaImageGroup.test.tsx +213 -0
- package/src/lib/Components/core/MediaImageGroup/MediaImageGroup.tsx +264 -0
- package/src/lib/Components/core/MediaImageGroup/index.ts +2 -0
- package/src/lib/Components/core/MediaImageGroup/types.ts +77 -0
- package/src/lib/Components/core/index.ts +1 -0
- package/src/lib/Components/symbols/icons/Ar.tsx +2 -2
- package/src/lib/Components/symbols/icons/Range.tsx +1 -1
- package/src/lib/Components/symbols/icons/Share.tsx +1 -1
- package/src/lib/Components/symbols/icons/{Charon.tsx → ShoppingInvoiceList.tsx} +8 -8
- package/src/lib/Components/symbols/icons/WalletInput.tsx +1 -1
- package/src/lib/Components/symbols/index.ts +1 -4
- package/dist/module/lib/Components/symbols/icons/Apex.js +0 -49
- package/dist/module/lib/Components/symbols/icons/Apex.js.map +0 -1
- package/dist/module/lib/Components/symbols/icons/BellNotification.js +0 -91
- package/dist/module/lib/Components/symbols/icons/BellNotification.js.map +0 -1
- package/dist/module/lib/Components/symbols/icons/Charon.js.map +0 -1
- package/dist/module/lib/Components/symbols/icons/ShieldCheckNotification.js +0 -82
- package/dist/module/lib/Components/symbols/icons/ShieldCheckNotification.js.map +0 -1
- package/dist/typescript/src/lib/Components/symbols/icons/Apex.d.ts +0 -35
- package/dist/typescript/src/lib/Components/symbols/icons/Apex.d.ts.map +0 -1
- package/dist/typescript/src/lib/Components/symbols/icons/BellNotification.d.ts +0 -35
- package/dist/typescript/src/lib/Components/symbols/icons/BellNotification.d.ts.map +0 -1
- package/dist/typescript/src/lib/Components/symbols/icons/Charon.d.ts.map +0 -1
- package/dist/typescript/src/lib/Components/symbols/icons/ShieldCheckNotification.d.ts +0 -35
- package/dist/typescript/src/lib/Components/symbols/icons/ShieldCheckNotification.d.ts.map +0 -1
- package/src/lib/Components/symbols/icons/Apex.tsx +0 -44
- package/src/lib/Components/symbols/icons/BellNotification.tsx +0 -75
- package/src/lib/Components/symbols/icons/ShieldCheckNotification.tsx +0 -67
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
|
|
2
|
+
import { Box } from '../../primitives';
|
|
3
|
+
import { MediaImage } from '../MediaImage';
|
|
4
|
+
import { MediaImageGroup } from './MediaImageGroup';
|
|
5
|
+
import type { MediaImageGroupItem } from './types';
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
component: MediaImageGroup,
|
|
9
|
+
id: 'rnative-mediaimagegroup',
|
|
10
|
+
title: 'Core/MediaImageGroup',
|
|
11
|
+
parameters: {
|
|
12
|
+
docs: {
|
|
13
|
+
source: {
|
|
14
|
+
language: 'tsx',
|
|
15
|
+
format: true,
|
|
16
|
+
type: 'dynamic',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
} satisfies Meta<typeof MediaImageGroup>;
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<typeof MediaImageGroup>;
|
|
24
|
+
|
|
25
|
+
const assets = [
|
|
26
|
+
{ src: 'https://crypto-icons.ledger.com/BTC.png', id: 'btc', alt: 'Bitcoin' },
|
|
27
|
+
{
|
|
28
|
+
src: 'https://crypto-icons.ledger.com/ETH.png',
|
|
29
|
+
id: 'eth',
|
|
30
|
+
alt: 'Ethereum',
|
|
31
|
+
},
|
|
32
|
+
{ src: 'https://crypto-icons.ledger.com/ADA.png', id: 'ada', alt: 'Cardano' },
|
|
33
|
+
{ src: 'https://crypto-icons.ledger.com/SOL.png', id: 'sol', alt: 'Solana' },
|
|
34
|
+
{
|
|
35
|
+
src: 'https://crypto-icons.ledger.com/DOT.png',
|
|
36
|
+
id: 'dot',
|
|
37
|
+
alt: 'Polkadot',
|
|
38
|
+
},
|
|
39
|
+
{ src: 'https://crypto-icons.ledger.com/XRP.png', id: 'xrp', alt: 'XRP' },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const fallbackItems: MediaImageGroupItem[] = [
|
|
43
|
+
{ id: 'btc', fallback: 'Bitcoin' },
|
|
44
|
+
{ id: 'eth', fallback: 'Ethereum' },
|
|
45
|
+
{ id: 'loading', loading: true },
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export const Base: Story = {
|
|
49
|
+
args: {
|
|
50
|
+
data: assets.slice(0, 3),
|
|
51
|
+
size: 32,
|
|
52
|
+
shape: 'circle',
|
|
53
|
+
maxVisible: 4,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const SizeShowcase: Story = {
|
|
58
|
+
args: { data: assets },
|
|
59
|
+
render: () => (
|
|
60
|
+
<Box lx={{ gap: 's16' }}>
|
|
61
|
+
<MediaImageGroup data={assets} size={12} />
|
|
62
|
+
<MediaImageGroup data={assets} size={16} />
|
|
63
|
+
<MediaImageGroup data={assets} size={20} />
|
|
64
|
+
<MediaImageGroup data={assets} size={24} />
|
|
65
|
+
<MediaImageGroup data={assets} size={32} />
|
|
66
|
+
<MediaImageGroup data={assets} size={40} />
|
|
67
|
+
<MediaImageGroup data={assets} size={48} />
|
|
68
|
+
<MediaImageGroup data={assets} size={56} />
|
|
69
|
+
<MediaImageGroup data={assets} size={64} />
|
|
70
|
+
<MediaImageGroup data={assets} size={72} />
|
|
71
|
+
</Box>
|
|
72
|
+
),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const ShapeShowcase: Story = {
|
|
76
|
+
args: { data: assets },
|
|
77
|
+
render: () => (
|
|
78
|
+
<Box lx={{ gap: 's24' }}>
|
|
79
|
+
<MediaImageGroup data={assets} size={40} shape='circle' />
|
|
80
|
+
<MediaImageGroup data={assets} size={40} shape='square' />
|
|
81
|
+
</Box>
|
|
82
|
+
),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const WithOverflow: Story = {
|
|
86
|
+
args: { data: assets },
|
|
87
|
+
render: () => (
|
|
88
|
+
<Box lx={{ gap: 's24' }}>
|
|
89
|
+
<MediaImageGroup data={assets.slice(0, 4)} maxVisible={4} />
|
|
90
|
+
<MediaImageGroup data={assets} maxVisible={4} />
|
|
91
|
+
<MediaImageGroup data={assets} maxVisible={3} />
|
|
92
|
+
</Box>
|
|
93
|
+
),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const Disabled: Story = {
|
|
97
|
+
args: { data: assets, maxVisible: 4, disabled: true },
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const DisabledItem: Story = {
|
|
101
|
+
args: {
|
|
102
|
+
data: assets.map((asset) => ({ ...asset, disabled: asset.id === 'eth' })),
|
|
103
|
+
maxVisible: 4,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const WithFallback: Story = {
|
|
108
|
+
args: { data: fallbackItems },
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const WithRenderItem: Story = {
|
|
112
|
+
args: { data: assets },
|
|
113
|
+
render: () => (
|
|
114
|
+
<MediaImageGroup
|
|
115
|
+
data={assets}
|
|
116
|
+
size={40}
|
|
117
|
+
renderItem={(asset, { size, shape }) => (
|
|
118
|
+
<MediaImage src={asset.src} alt={asset.alt} size={size} shape={shape} />
|
|
119
|
+
)}
|
|
120
|
+
/>
|
|
121
|
+
),
|
|
122
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { describe, it, expect } from '@jest/globals';
|
|
2
|
+
import { ledgerLiveThemes } from '@ledgerhq/lumen-design-core';
|
|
3
|
+
import { useDisabledContext } from '@ledgerhq/lumen-utils-shared';
|
|
4
|
+
import { render } from '@testing-library/react-native';
|
|
5
|
+
import { Text } from 'react-native';
|
|
6
|
+
import { ThemeProvider } from '../ThemeProvider/ThemeProvider';
|
|
7
|
+
import { MediaImageGroup } from './MediaImageGroup';
|
|
8
|
+
|
|
9
|
+
const TestWrapper = ({ children }: { children: React.ReactNode }) => (
|
|
10
|
+
<ThemeProvider themes={ledgerLiveThemes} colorScheme='dark' locale='en'>
|
|
11
|
+
{children}
|
|
12
|
+
</ThemeProvider>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const DisabledProbe = () => {
|
|
16
|
+
const disabled = useDisabledContext({ consumerName: 'DisabledProbe' });
|
|
17
|
+
return <Text>{disabled ? 'disabled' : 'enabled'}</Text>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const items = (count: number) =>
|
|
21
|
+
Array.from({ length: count }, (_, i) => ({
|
|
22
|
+
id: `item-${i}`,
|
|
23
|
+
alt: `item-${i}`,
|
|
24
|
+
fallback: 'A',
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
describe('MediaImageGroup', () => {
|
|
28
|
+
describe('Rendering', () => {
|
|
29
|
+
it('should render every item and no badge within maxVisible', () => {
|
|
30
|
+
const { getAllByLabelText, queryByText } = render(
|
|
31
|
+
<TestWrapper>
|
|
32
|
+
<MediaImageGroup data={items(3)} maxVisible={4} />
|
|
33
|
+
</TestWrapper>,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
expect(getAllByLabelText(/^item-/)).toHaveLength(3);
|
|
37
|
+
expect(queryByText(/^\+/)).toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should render the overflow badge within the maxVisible budget', () => {
|
|
41
|
+
const { getAllByLabelText, getByText } = render(
|
|
42
|
+
<TestWrapper>
|
|
43
|
+
<MediaImageGroup data={items(10)} maxVisible={4} />
|
|
44
|
+
</TestWrapper>,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(getAllByLabelText(/^item-/)).toHaveLength(3);
|
|
48
|
+
expect(getByText('+7')).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should render nothing when data is empty', () => {
|
|
52
|
+
const { toJSON } = render(
|
|
53
|
+
<TestWrapper>
|
|
54
|
+
<MediaImageGroup data={[]} testID='group' />
|
|
55
|
+
</TestWrapper>,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(toJSON()).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should not forward the item id to the rendered media image', () => {
|
|
62
|
+
const { getByLabelText } = render(
|
|
63
|
+
<TestWrapper>
|
|
64
|
+
<MediaImageGroup
|
|
65
|
+
data={[{ id: 'btc', alt: 'Bitcoin', fallback: 'B' }]}
|
|
66
|
+
/>
|
|
67
|
+
</TestWrapper>,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(getByLabelText('Bitcoin').props.id).toBeUndefined();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('renderItem', () => {
|
|
75
|
+
it('should pass the group size and shape to renderItem', () => {
|
|
76
|
+
const contexts: unknown[] = [];
|
|
77
|
+
const { getByText } = render(
|
|
78
|
+
<TestWrapper>
|
|
79
|
+
<MediaImageGroup
|
|
80
|
+
data={[{ id: 'btc' }, { id: 'eth' }]}
|
|
81
|
+
size={24}
|
|
82
|
+
shape='square'
|
|
83
|
+
renderItem={(item, context) => {
|
|
84
|
+
contexts.push(context);
|
|
85
|
+
return <Text>{item.id}</Text>;
|
|
86
|
+
}}
|
|
87
|
+
/>
|
|
88
|
+
</TestWrapper>,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(getByText('btc')).toBeTruthy();
|
|
92
|
+
expect(getByText('eth')).toBeTruthy();
|
|
93
|
+
expect(contexts).toEqual([
|
|
94
|
+
{ size: 24, shape: 'square' },
|
|
95
|
+
{ size: 24, shape: 'square' },
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should only render the visible items', () => {
|
|
100
|
+
const { getByText, queryByText } = render(
|
|
101
|
+
<TestWrapper>
|
|
102
|
+
<MediaImageGroup
|
|
103
|
+
data={Array.from({ length: 6 }, (_, i) => ({ id: `asset-${i}` }))}
|
|
104
|
+
maxVisible={3}
|
|
105
|
+
renderItem={(item) => <Text>{item.id}</Text>}
|
|
106
|
+
/>
|
|
107
|
+
</TestWrapper>,
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
expect(getByText('asset-0')).toBeTruthy();
|
|
111
|
+
expect(getByText('asset-1')).toBeTruthy();
|
|
112
|
+
expect(queryByText('asset-2')).toBeNull();
|
|
113
|
+
expect(getByText('+4')).toBeTruthy();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('Props', () => {
|
|
118
|
+
it('should forward testID to the root', () => {
|
|
119
|
+
const { getByTestId } = render(
|
|
120
|
+
<TestWrapper>
|
|
121
|
+
<MediaImageGroup data={items(2)} testID='group' />
|
|
122
|
+
</TestWrapper>,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
expect(getByTestId('group')).toBeTruthy();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should forward overflowTestID to the overflow badge', () => {
|
|
129
|
+
const { getByTestId } = render(
|
|
130
|
+
<TestWrapper>
|
|
131
|
+
<MediaImageGroup
|
|
132
|
+
data={items(10)}
|
|
133
|
+
maxVisible={4}
|
|
134
|
+
overflowTestID='overflow'
|
|
135
|
+
/>
|
|
136
|
+
</TestWrapper>,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
expect(getByTestId('overflow')).toBeTruthy();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe('Disabled', () => {
|
|
144
|
+
it('should dim the overflow badge when disabled', () => {
|
|
145
|
+
const { getByTestId } = render(
|
|
146
|
+
<TestWrapper>
|
|
147
|
+
<MediaImageGroup
|
|
148
|
+
data={items(10)}
|
|
149
|
+
maxVisible={4}
|
|
150
|
+
disabled
|
|
151
|
+
overflowTestID='overflow'
|
|
152
|
+
/>
|
|
153
|
+
</TestWrapper>,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(getByTestId('overflow')).toHaveStyle({ opacity: 0.3 });
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should not dim the overflow badge by default', () => {
|
|
160
|
+
const { getByTestId } = render(
|
|
161
|
+
<TestWrapper>
|
|
162
|
+
<MediaImageGroup
|
|
163
|
+
data={items(10)}
|
|
164
|
+
maxVisible={4}
|
|
165
|
+
overflowTestID='overflow'
|
|
166
|
+
/>
|
|
167
|
+
</TestWrapper>,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
expect(getByTestId('overflow')).not.toHaveStyle({ opacity: 0.3 });
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should provide the disabled state to custom items', () => {
|
|
174
|
+
const { getByText } = render(
|
|
175
|
+
<TestWrapper>
|
|
176
|
+
<MediaImageGroup
|
|
177
|
+
data={[{ id: 'btc' }]}
|
|
178
|
+
disabled
|
|
179
|
+
renderItem={() => <DisabledProbe />}
|
|
180
|
+
/>
|
|
181
|
+
</TestWrapper>,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
expect(getByText('disabled')).toBeTruthy();
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('Types', () => {
|
|
189
|
+
it('should require renderItem when data is not MediaImageGroupItem[]', () => {
|
|
190
|
+
const assets = [{ ticker: 'BTC' }];
|
|
191
|
+
|
|
192
|
+
// Compile-time only: a `@ts-expect-error` fails typecheck if the union
|
|
193
|
+
// stops rejecting the line below it.
|
|
194
|
+
const typeChecks = () => (
|
|
195
|
+
<>
|
|
196
|
+
<MediaImageGroup data={[{ src: 'btc.png', alt: 'Bitcoin' }]} />
|
|
197
|
+
<MediaImageGroup
|
|
198
|
+
data={assets}
|
|
199
|
+
renderItem={(asset) => <Text>{asset.ticker}</Text>}
|
|
200
|
+
/>
|
|
201
|
+
{/* @ts-expect-error custom data requires renderItem */}
|
|
202
|
+
<MediaImageGroup data={assets} />
|
|
203
|
+
{/* @ts-expect-error excess property on an inline MediaImage item */}
|
|
204
|
+
<MediaImageGroup
|
|
205
|
+
data={[{ src: 'btc.png', alt: 'Bitcoin', ticker: 'BTC' }]}
|
|
206
|
+
/>
|
|
207
|
+
</>
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
expect(typeChecks).toBeDefined();
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_GROUP_MAX_VISIBLE,
|
|
3
|
+
DisabledProvider,
|
|
4
|
+
useDisabledContext,
|
|
5
|
+
sliceGroupItems,
|
|
6
|
+
formatGroupOverflowCount,
|
|
7
|
+
} from '@ledgerhq/lumen-utils-shared';
|
|
8
|
+
import { StyleSheet } from 'react-native';
|
|
9
|
+
import { useStyleSheet } from '../../../../styles';
|
|
10
|
+
import type { LumenStyleSheetTheme } from '../../../../styles';
|
|
11
|
+
import { Box, Text } from '../../primitives';
|
|
12
|
+
import { MediaImage } from '../MediaImage';
|
|
13
|
+
import type { MediaImageSize, MediaImageShape } from '../MediaImage';
|
|
14
|
+
import { borderRadiusMap } from '../MediaImage/MediaImage';
|
|
15
|
+
import type { MediaImageGroupItem, MediaImageGroupProps } from './types';
|
|
16
|
+
|
|
17
|
+
type SpacingKey = keyof LumenStyleSheetTheme['spacings'];
|
|
18
|
+
type TypographyKey =
|
|
19
|
+
| 'body4SemiBold'
|
|
20
|
+
| 'body3SemiBold'
|
|
21
|
+
| 'body2SemiBold'
|
|
22
|
+
| 'body1SemiBold'
|
|
23
|
+
| 'heading4SemiBold'
|
|
24
|
+
| 'heading3SemiBold'
|
|
25
|
+
| 'heading2SemiBold';
|
|
26
|
+
|
|
27
|
+
// About 25% of the size, snapped to the spacing scale.
|
|
28
|
+
const overlapMap: Record<MediaImageSize, SpacingKey> = {
|
|
29
|
+
12: 's4',
|
|
30
|
+
16: 's4',
|
|
31
|
+
20: 's6',
|
|
32
|
+
24: 's6',
|
|
33
|
+
32: 's8',
|
|
34
|
+
40: 's10',
|
|
35
|
+
48: 's12',
|
|
36
|
+
56: 's14',
|
|
37
|
+
64: 's16',
|
|
38
|
+
72: 's16',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// The ring grows with the size, up to 2px.
|
|
42
|
+
const ringMap: Record<MediaImageSize, SpacingKey> = {
|
|
43
|
+
12: 's1',
|
|
44
|
+
16: 's1',
|
|
45
|
+
20: 's1',
|
|
46
|
+
24: 's1',
|
|
47
|
+
32: 's1',
|
|
48
|
+
40: 's2',
|
|
49
|
+
48: 's2',
|
|
50
|
+
56: 's2',
|
|
51
|
+
64: 's2',
|
|
52
|
+
72: 's2',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const overflowTypographyMap: Record<MediaImageSize, TypographyKey> = {
|
|
56
|
+
12: 'body4SemiBold',
|
|
57
|
+
16: 'body4SemiBold',
|
|
58
|
+
20: 'body4SemiBold',
|
|
59
|
+
24: 'body4SemiBold',
|
|
60
|
+
32: 'body3SemiBold',
|
|
61
|
+
40: 'body2SemiBold',
|
|
62
|
+
48: 'body1SemiBold',
|
|
63
|
+
56: 'heading4SemiBold',
|
|
64
|
+
64: 'heading3SemiBold',
|
|
65
|
+
72: 'heading2SemiBold',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const useStyles = ({
|
|
69
|
+
size,
|
|
70
|
+
shape,
|
|
71
|
+
disabled = false,
|
|
72
|
+
}: {
|
|
73
|
+
size: MediaImageSize;
|
|
74
|
+
shape: MediaImageShape;
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
}) => {
|
|
77
|
+
return useStyleSheet(
|
|
78
|
+
(t) => {
|
|
79
|
+
const sizeValue = t.sizes[`s${size}` as keyof typeof t.sizes] as number;
|
|
80
|
+
const ring = t.spacings[ringMap[size]];
|
|
81
|
+
const radius =
|
|
82
|
+
shape === 'circle'
|
|
83
|
+
? t.borderRadius.full
|
|
84
|
+
: t.borderRadius[borderRadiusMap[size]];
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
root: {
|
|
88
|
+
flexDirection: 'row',
|
|
89
|
+
alignItems: 'center',
|
|
90
|
+
},
|
|
91
|
+
slot: {
|
|
92
|
+
borderWidth: ring,
|
|
93
|
+
borderColor: t.colors.border.baseInverted,
|
|
94
|
+
borderRadius: shape === 'circle' ? radius : radius + ring,
|
|
95
|
+
overflow: 'hidden',
|
|
96
|
+
backgroundColor: t.colors.bg.base,
|
|
97
|
+
},
|
|
98
|
+
slotOverlap: {
|
|
99
|
+
marginLeft: -t.spacings[overlapMap[size]],
|
|
100
|
+
},
|
|
101
|
+
overflow: {
|
|
102
|
+
minWidth: sizeValue,
|
|
103
|
+
height: sizeValue,
|
|
104
|
+
paddingHorizontal: t.spacings.s2,
|
|
105
|
+
borderRadius: radius,
|
|
106
|
+
alignItems: 'center',
|
|
107
|
+
justifyContent: 'center',
|
|
108
|
+
backgroundColor: t.colors.bg.interactive,
|
|
109
|
+
...(disabled && { opacity: 0.3 }),
|
|
110
|
+
},
|
|
111
|
+
overflowText: {
|
|
112
|
+
...t.typographies[overflowTypographyMap[size]],
|
|
113
|
+
color: t.colors.text.onInteractive,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
[size, shape, disabled],
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
type OverflowBadgeProps = {
|
|
122
|
+
count: number;
|
|
123
|
+
size: MediaImageSize;
|
|
124
|
+
shape: MediaImageShape;
|
|
125
|
+
overlap: boolean;
|
|
126
|
+
testID?: string;
|
|
127
|
+
label?: string;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const OverflowBadge = ({
|
|
131
|
+
count,
|
|
132
|
+
size,
|
|
133
|
+
shape,
|
|
134
|
+
overlap,
|
|
135
|
+
testID,
|
|
136
|
+
label,
|
|
137
|
+
}: OverflowBadgeProps) => {
|
|
138
|
+
const disabled = useDisabledContext({ consumerName: 'MediaImageGroup' });
|
|
139
|
+
const styles = useStyles({ size, shape, disabled });
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<Box
|
|
143
|
+
style={StyleSheet.flatten([styles.slot, overlap && styles.slotOverlap])}
|
|
144
|
+
>
|
|
145
|
+
<Box
|
|
146
|
+
style={styles.overflow}
|
|
147
|
+
testID={testID}
|
|
148
|
+
accessible={!!label}
|
|
149
|
+
accessibilityLabel={label}
|
|
150
|
+
>
|
|
151
|
+
<Text style={styles.overflowText} allowFontScaling={false}>
|
|
152
|
+
{formatGroupOverflowCount(count)}
|
|
153
|
+
</Text>
|
|
154
|
+
</Box>
|
|
155
|
+
</Box>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Displays a stack of overlapping media images, with a `+N` badge when the
|
|
161
|
+
* data exceeds `maxVisible`.
|
|
162
|
+
*
|
|
163
|
+
* The group owns `size` and `shape`. A custom `renderItem` receives them and
|
|
164
|
+
* must forward them to the rendered element (e.g. a crypto icon). Items are
|
|
165
|
+
* clipped to the group's ring, so decorations overhanging an item, such as a
|
|
166
|
+
* network badge, are not supported.
|
|
167
|
+
*
|
|
168
|
+
* Without `renderItem`, `data` must be `MediaImage` props. For any other item
|
|
169
|
+
* shape, pass `renderItem`. The types can't always catch a missing one.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* import { MediaImageGroup } from '@ledgerhq/lumen-ui-rnative';
|
|
173
|
+
*
|
|
174
|
+
* <MediaImageGroup
|
|
175
|
+
* size={32}
|
|
176
|
+
* data={[
|
|
177
|
+
* { src: btcUrl, alt: 'Bitcoin' },
|
|
178
|
+
* { src: ethUrl, alt: 'Ethereum' },
|
|
179
|
+
* ]}
|
|
180
|
+
* />
|
|
181
|
+
*
|
|
182
|
+
* <MediaImageGroup
|
|
183
|
+
* data={assets} // [{ ledgerId: 'bitcoin', ticker: 'BTC' }, ...]
|
|
184
|
+
* renderItem={(asset, { size, shape }) => (
|
|
185
|
+
* <CryptoIcon ledgerId={asset.ledgerId} ticker={asset.ticker} size={size} shape={shape} />
|
|
186
|
+
* )}
|
|
187
|
+
* />
|
|
188
|
+
*/
|
|
189
|
+
export function MediaImageGroup<T = MediaImageGroupItem>({
|
|
190
|
+
data,
|
|
191
|
+
renderItem,
|
|
192
|
+
size = 32,
|
|
193
|
+
shape = 'circle',
|
|
194
|
+
maxVisible = DEFAULT_GROUP_MAX_VISIBLE,
|
|
195
|
+
disabled: disabledProp = false,
|
|
196
|
+
overflowTestID,
|
|
197
|
+
overflowLabel,
|
|
198
|
+
lx = {},
|
|
199
|
+
style,
|
|
200
|
+
ref,
|
|
201
|
+
...props
|
|
202
|
+
}: MediaImageGroupProps<T>) {
|
|
203
|
+
const disabled = useDisabledContext({
|
|
204
|
+
consumerName: 'MediaImageGroup',
|
|
205
|
+
mergeWith: { disabled: disabledProp },
|
|
206
|
+
});
|
|
207
|
+
const styles = useStyles({ size, shape });
|
|
208
|
+
|
|
209
|
+
const { visibleItems, overflowCount } = sliceGroupItems<unknown>(
|
|
210
|
+
data,
|
|
211
|
+
maxVisible,
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
if (data.length === 0) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<Box
|
|
220
|
+
ref={ref}
|
|
221
|
+
lx={lx}
|
|
222
|
+
style={StyleSheet.flatten([styles.root, style])}
|
|
223
|
+
{...props}
|
|
224
|
+
>
|
|
225
|
+
<DisabledProvider value={{ disabled }}>
|
|
226
|
+
{renderItem
|
|
227
|
+
? data.slice(0, visibleItems.length).map((item, index) => (
|
|
228
|
+
<Box
|
|
229
|
+
key={index}
|
|
230
|
+
style={StyleSheet.flatten([
|
|
231
|
+
styles.slot,
|
|
232
|
+
index > 0 && styles.slotOverlap,
|
|
233
|
+
])}
|
|
234
|
+
>
|
|
235
|
+
{renderItem(item, { size, shape })}
|
|
236
|
+
</Box>
|
|
237
|
+
))
|
|
238
|
+
: data
|
|
239
|
+
.slice(0, visibleItems.length)
|
|
240
|
+
.map(({ id, ...imageProps }, index) => (
|
|
241
|
+
<Box
|
|
242
|
+
key={id ?? index}
|
|
243
|
+
style={StyleSheet.flatten([
|
|
244
|
+
styles.slot,
|
|
245
|
+
index > 0 && styles.slotOverlap,
|
|
246
|
+
])}
|
|
247
|
+
>
|
|
248
|
+
<MediaImage {...imageProps} size={size} shape={shape} />
|
|
249
|
+
</Box>
|
|
250
|
+
))}
|
|
251
|
+
{overflowCount > 0 && (
|
|
252
|
+
<OverflowBadge
|
|
253
|
+
count={overflowCount}
|
|
254
|
+
size={size}
|
|
255
|
+
shape={shape}
|
|
256
|
+
overlap={visibleItems.length > 0}
|
|
257
|
+
testID={overflowTestID}
|
|
258
|
+
label={overflowLabel}
|
|
259
|
+
/>
|
|
260
|
+
)}
|
|
261
|
+
</DisabledProvider>
|
|
262
|
+
</Box>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyledViewProps } from '../../../../styles';
|
|
3
|
+
import type { MediaImageProps } from '../MediaImage';
|
|
4
|
+
|
|
5
|
+
export type MediaImageGroupItem = {
|
|
6
|
+
/**
|
|
7
|
+
* Stable identifier of the item, used as its React key. Falls back to the
|
|
8
|
+
* item's index.
|
|
9
|
+
* @optional
|
|
10
|
+
*/
|
|
11
|
+
id?: string;
|
|
12
|
+
} & Omit<MediaImageProps, 'id' | 'size' | 'shape' | 'ref' | 'style' | 'lx'>;
|
|
13
|
+
|
|
14
|
+
export type MediaImageGroupItemContext = Required<
|
|
15
|
+
Pick<MediaImageProps, 'size' | 'shape'>
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export type MediaImageGroupRenderItem<T> = (
|
|
19
|
+
item: T,
|
|
20
|
+
context: MediaImageGroupItemContext,
|
|
21
|
+
) => ReactNode;
|
|
22
|
+
|
|
23
|
+
type MediaImageGroupDataProps<T> =
|
|
24
|
+
| {
|
|
25
|
+
/**
|
|
26
|
+
* Items to display, rendered as `MediaImage`.
|
|
27
|
+
*/
|
|
28
|
+
data: readonly MediaImageGroupItem[];
|
|
29
|
+
renderItem?: never;
|
|
30
|
+
}
|
|
31
|
+
| {
|
|
32
|
+
/**
|
|
33
|
+
* Items to display, rendered by `renderItem`.
|
|
34
|
+
*/
|
|
35
|
+
data: readonly T[];
|
|
36
|
+
/**
|
|
37
|
+
* Renders an item in place of the default `MediaImage`. Required when
|
|
38
|
+
* `data` is not `MediaImageGroupItem[]`. Receives the `size` and `shape`
|
|
39
|
+
* owned by the group, which must be forwarded to the rendered element so
|
|
40
|
+
* the overlap and overflow badge stay consistent.
|
|
41
|
+
*/
|
|
42
|
+
renderItem: MediaImageGroupRenderItem<T>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type MediaImageGroupProps<T = MediaImageGroupItem> =
|
|
46
|
+
MediaImageGroupDataProps<T> & {
|
|
47
|
+
/**
|
|
48
|
+
* Size applied to every item.
|
|
49
|
+
* @default 32
|
|
50
|
+
*/
|
|
51
|
+
size?: MediaImageProps['size'];
|
|
52
|
+
/**
|
|
53
|
+
* Shape applied to every item.
|
|
54
|
+
* @default 'circle'
|
|
55
|
+
*/
|
|
56
|
+
shape?: MediaImageProps['shape'];
|
|
57
|
+
/**
|
|
58
|
+
* Dims the items and the `+N` badge.
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum number of slots displayed, the `+N` overflow badge included.
|
|
64
|
+
* @default 4
|
|
65
|
+
*/
|
|
66
|
+
maxVisible?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Test id of the `+N` overflow badge.
|
|
69
|
+
* @optional
|
|
70
|
+
*/
|
|
71
|
+
overflowTestID?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Accessible label of the `+N` overflow badge, e.g. "7 more assets".
|
|
74
|
+
* @optional
|
|
75
|
+
*/
|
|
76
|
+
overflowLabel?: string;
|
|
77
|
+
} & Omit<StyledViewProps, 'children'>;
|