Skip to content

Commit c6daf4f

Browse files
author
Kenton Duprey
committed
feat(clerk-js,types): Add WalletInitialIcon component and update element descriptors for Web3 wallet buttons
Signed-off-by: Kenton Duprey <kenton@clerk.dev>
1 parent 5ce98f1 commit c6daf4f

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Box, descriptors, Text } from '../customizables';
2+
import type { PropsOfComponent } from '../styledSystem';
3+
import { common } from '../styledSystem';
4+
5+
type WalletInitialIconProps = PropsOfComponent<typeof Box> & {
6+
value: string;
7+
/**
8+
* The wallet provider name
9+
*/
10+
id: string;
11+
};
12+
13+
export const WalletInitialIcon = (props: WalletInitialIconProps) => {
14+
const { value, id, ...rest } = props;
15+
16+
return (
17+
<Box
18+
as='span'
19+
elementDescriptor={[descriptors.walletIcon, descriptors.web3WalletButtonsWalletInitialIcon]}
20+
elementId={descriptors.web3WalletButtonsWalletInitialIcon.setId(id)}
21+
sx={t => ({
22+
...common.centeredFlex('inline-flex'),
23+
width: t.space.$4,
24+
height: t.space.$4,
25+
borderRadius: t.radii.$sm,
26+
color: t.colors.$colorPrimaryForeground,
27+
backgroundColor: t.colors.$primary500,
28+
})}
29+
{...rest}
30+
>
31+
<Text
32+
as='span'
33+
variant='buttonSmall'
34+
sx={{
35+
...common.centeredFlex('inline-flex'),
36+
width: '100%',
37+
}}
38+
>
39+
{value[0].toUpperCase()}
40+
</Text>
41+
</Box>
42+
);
43+
};

packages/clerk-js/src/ui/customizables/elementDescriptors.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,17 @@ export const APPEARANCE_KEYS = containsAllElementsConfigKeys([
515515
'enterpriseConnectionsRoot',
516516
'enterpriseConnectionButton',
517517
'enterpriseConnectionButtonText',
518+
519+
'web3WalletButtonsRoot',
520+
'web3WalletButtons',
521+
'web3WalletButtonsIconButton',
522+
'web3WalletButtonsBlockButton',
523+
'web3WalletButtonsBlockButtonText',
524+
'web3WalletButtonsWalletIcon',
525+
'web3WalletButtonsWalletInitialIcon',
526+
527+
'walletIcon',
528+
'walletInitialIcon',
518529
] as const).map(camelize) as (keyof ElementsConfig)[];
519530

520531
type TargettableClassname<K extends keyof ElementsConfig> = `${typeof CLASS_PREFIX}${K}`;

packages/clerk-js/src/ui/elements/Web3SolanaWalletButtons.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MAINNET_ENDPOINT } from '@solana/wallet-standard';
44
import type { Ref } from 'react';
55
import React, { forwardRef, isValidElement, useMemo } from 'react';
66

7-
import { ProviderInitialIcon } from '@/ui/common';
7+
import { WalletInitialIcon } from '@/ui/common/WalletInitialIcon';
88
import {
99
Button,
1010
descriptors,
@@ -94,6 +94,7 @@ const Web3SolanaWalletButtonsInner = ({ web3AuthCallback }: Web3WalletButtonsPro
9494
<Flex
9595
direction='col'
9696
gap={2}
97+
elementDescriptor={descriptors.web3WalletButtonsRoot}
9798
>
9899
{strategyRows.map((row, rowIndex) => (
99100
<Grid
@@ -102,6 +103,7 @@ const Web3SolanaWalletButtonsInner = ({ web3AuthCallback }: Web3WalletButtonsPro
102103
return r.name;
103104
})
104105
.join('-')}
106+
elementDescriptor={descriptors.web3WalletButtons}
105107
gap={2}
106108
sx={t => ({
107109
justifyContent: 'center',
@@ -130,17 +132,18 @@ const Web3SolanaWalletButtonsInner = ({ web3AuthCallback }: Web3WalletButtonsPro
130132

131133
const imageOrInitial = w.icon ? (
132134
<Image
135+
elementDescriptor={[descriptors.walletIcon, descriptors.web3WalletButtonsWalletInitialIcon]}
133136
isDisabled={card.isLoading}
134137
isLoading={card.loadingMetadata === w.name}
135138
src={w.icon}
136139
alt={t(localizationKeys('web3WalletButtons.connect', { walletName: w.name }))}
137140
sx={theme => ({ width: theme.sizes.$4, height: 'auto', maxWidth: '100%' })}
138141
/>
139142
) : (
140-
<ProviderInitialIcon
143+
<WalletInitialIcon
141144
value={w.name}
142145
isDisabled={card.isLoading}
143-
id={'linear'}
146+
id={w.name}
144147
/>
145148
);
146149

packages/shared/src/types/appearance.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,17 @@ export type ElementsConfig = {
650650
enterpriseConnectionsRoot: WithOptions;
651651
enterpriseConnectionButton: WithOptions;
652652
enterpriseConnectionButtonText: WithOptions;
653+
654+
web3WalletButtonsRoot: WithOptions;
655+
web3WalletButtons: WithOptions;
656+
web3WalletButtonsIconButton: WithOptions<string, LoadingState>;
657+
web3WalletButtonsBlockButton: WithOptions<string, LoadingState>;
658+
web3WalletButtonsBlockButtonText: WithOptions<string>;
659+
web3WalletButtonsWalletIcon: WithOptions<string, LoadingState>;
660+
web3WalletButtonsWalletInitialIcon: WithOptions<string, LoadingState>;
661+
662+
walletIcon: WithOptions<string, LoadingState>;
663+
walletInitialIcon: WithOptions<string, LoadingState>;
653664
};
654665

655666
export type Elements = {

0 commit comments

Comments
 (0)