Skip to content

Commit 3a3807a

Browse files
Merge pull request #48 from input-output-hk/chore/lw-10712-use-custom-component-in-profile-dropdown
feat: allow custom components as profile dropdown profile image
2 parents 5f36f6b + e2e3e1e commit 3a3807a

File tree

4 files changed

+57
-26
lines changed

4 files changed

+57
-26
lines changed

src/design-system/profile-dropdown/profile-dropdown-trigger.component.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ import { Flex } from '../flex';
1111
import * as cx from './profile-dropdown-trigger.css';
1212
import { WalletCard } from './profile-dropdown-wallet-card.component';
1313

14+
import type { ProfileType } from './profile-dropdown-wallet-card.component';
1415
import type { WalletType } from './profile-dropdown.data';
1516

1617
export type Props = Omit<ComponentPropsWithoutRef<'button'>, 'type'> & {
1718
disabled?: boolean;
1819
active?: boolean;
1920
title: string;
2021
subtitle?: string;
21-
profile?: {
22-
imageSrc: string;
23-
fallbackText: string;
24-
alt?: string;
25-
delayMs?: number;
26-
};
22+
profile?: ProfileType;
2723
type: WalletType;
2824
};
2925

src/design-system/profile-dropdown/profile-dropdown-trigger.stories.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { Flex } from '../flex';
88
import { Grid, Cell } from '../grid';
99

1010
import { Trigger } from './profile-dropdown-trigger.component';
11+
12+
import type { ProfileType } from './profile-dropdown-wallet-card.component';
1113
const subtitle = `Reusable button component for use in a variety of controls containing only an icon for its content.`;
1214

1315
export default {
@@ -24,11 +26,13 @@ const TriggerSample = ({
2426
id,
2527
active,
2628
hasSubtitle = true,
29+
profile,
2730
}: Readonly<{
2831
disabled?: boolean;
2932
id?: string;
3033
active?: boolean;
3134
hasSubtitle?: boolean;
35+
profile?: ProfileType;
3236
}>): JSX.Element => (
3337
<Trigger
3438
title="Alice's wallet"
@@ -37,6 +41,7 @@ const TriggerSample = ({
3741
id={id}
3842
active={active}
3943
type="hot"
44+
profile={profile}
4045
/>
4146
);
4247

@@ -67,6 +72,21 @@ export const Overview = (): JSX.Element => (
6772
<Flex gap="$16" alignItems="center" w="$fill" justifyContent="center">
6873
<TriggerSample />
6974
<TriggerSample hasSubtitle={false} />
75+
<TriggerSample
76+
hasSubtitle={false}
77+
profile={{
78+
customProfileComponent: (
79+
<Flex
80+
alignItems="center"
81+
w={'$32'}
82+
h={'$32'}
83+
justifyContent="center"
84+
>
85+
TT
86+
</Flex>
87+
),
88+
}}
89+
/>
7090
</Flex>
7191
</Section>
7292

src/design-system/profile-dropdown/profile-dropdown-wallet-card.component.tsx

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,26 @@ import { WalletIcon } from './profile-dropdown-wallet-icon.component';
1212

1313
import type { WalletType } from './profile-dropdown.data';
1414

15+
type UserProfileComponentType = {
16+
imageSrc: string;
17+
fallbackText: string;
18+
alt?: string;
19+
delayMs?: number;
20+
};
21+
22+
type CustomProfileComponentType = {
23+
customProfileComponent: React.ReactNode;
24+
};
25+
26+
export type ProfileType = UserProfileComponentType | CustomProfileComponentType;
27+
1528
export interface Props {
1629
title: {
1730
text: string;
1831
type: 'button' | 'content';
1932
};
2033
subtitle?: string;
21-
profile?: {
22-
imageSrc: string;
23-
fallbackText: string;
24-
alt?: string;
25-
delayMs?: number;
26-
};
34+
profile?: ProfileType;
2735
type: WalletType;
2836
testId?: string;
2937
}
@@ -32,6 +40,22 @@ const makeTestId = (namespace = '', path = ''): string => {
3240
return namespace === '' ? namespace : `${namespace}${path}`;
3341
};
3442

43+
const getProfileImage = (
44+
profile: ProfileType,
45+
testId: string,
46+
): React.ReactNode => {
47+
if ('customProfileComponent' in profile) {
48+
return profile.customProfileComponent;
49+
}
50+
return (
51+
<UserProfile
52+
{...profile}
53+
radius="rounded"
54+
testId={makeTestId(testId, '-icon')}
55+
/>
56+
);
57+
};
58+
3559
export const WalletCard = ({
3660
title,
3761
subtitle,
@@ -43,16 +67,11 @@ export const WalletCard = ({
4367

4468
return (
4569
<Flex>
46-
{profile === undefined ? (
47-
<WalletIcon type={type} testId={makeTestId(testId, '-icon')} />
70+
{profile ? (
71+
getProfileImage(profile, testId)
4872
) : (
49-
<UserProfile
50-
{...profile}
51-
radius="rounded"
52-
testId={makeTestId(testId, '-icon')}
53-
/>
73+
<WalletIcon type={type} testId={makeTestId(testId, '-icon')} />
5474
)}
55-
5675
{subtitle ? (
5776
<Flex flexDirection="column" ml="$10" h="$32" alignItems="flex-start">
5877
<Title color="secondary" data-testid={makeTestId(testId, '-title')}>

src/design-system/profile-dropdown/profile-dropdown-wallet-option.component.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ import { Flex } from '../flex';
1111
import { WalletCard } from './profile-dropdown-wallet-card.component';
1212
import * as cx from './profile-dropdown-wallet-option.css';
1313

14+
import type { ProfileType } from './profile-dropdown-wallet-card.component';
1415
import type { WalletType } from './profile-dropdown.data';
1516

1617
export type Props = Omit<ComponentPropsWithoutRef<'button'>, 'type'> & {
1718
disabled?: boolean;
1819
title: string;
1920
subtitle?: string;
20-
profile?: {
21-
imageSrc: string;
22-
fallbackText: string;
23-
alt?: string;
24-
delayMs?: number;
25-
};
21+
profile?: ProfileType;
2622
type: WalletType;
2723
onOpenAccountsMenu?: () => void;
2824
};

0 commit comments

Comments
 (0)