Skip to content

Commit 29a25f3

Browse files
refactor(clerk-js): Expand ApplicationLogo usage for oAuth logo (#6518)
1 parent d93b0ed commit 29a25f3

File tree

4 files changed

+71
-41
lines changed

4 files changed

+71
-41
lines changed

.changeset/chilly-ravens-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Refactor ApplicationLogo rendering logic to account for oAuth logos within OAuthConsent component.

packages/clerk-js/src/ui/components/OAuthConsent/OAuthConsent.tsx

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useUser } from '@clerk/shared/react';
2+
import type { ComponentProps } from 'react';
23
import { useState } from 'react';
34

45
import { useEnvironment, useOAuthConsentContext } from '@/ui/contexts';
56
import { Box, Button, Flex, Flow, Grid, Icon, Text } from '@/ui/customizables';
67
import { ApplicationLogo } from '@/ui/elements/ApplicationLogo';
7-
import { Avatar } from '@/ui/elements/Avatar';
88
import { Card } from '@/ui/elements/Card';
99
import { withCardStateProvider } from '@/ui/elements/contexts';
1010
import { Header } from '@/ui/elements/Header';
@@ -42,13 +42,16 @@ export function OAuthConsentInternal() {
4242
{/* both have avatars */}
4343
{oAuthApplicationLogoUrl && logoImageUrl && (
4444
<ConnectionHeader>
45-
<Avatar
46-
imageUrl={oAuthApplicationLogoUrl}
47-
size={t => t.space.$12}
48-
rounded={false}
49-
/>
45+
<ConnectionItem justify='end'>
46+
<ApplicationLogo
47+
src={oAuthApplicationLogoUrl}
48+
alt={oAuthApplicationName}
49+
/>
50+
</ConnectionItem>
5051
<ConnectionSeparator />
51-
<ApplicationLogo />
52+
<ConnectionItem justify='start'>
53+
<ApplicationLogo />
54+
</ConnectionItem>
5255
</ConnectionHeader>
5356
)}
5457
{/* only OAuth app has an avatar */}
@@ -59,10 +62,9 @@ export function OAuthConsentInternal() {
5962
position: 'relative',
6063
}}
6164
>
62-
<Avatar
63-
imageUrl={oAuthApplicationLogoUrl}
64-
size={t => t.space.$12}
65-
rounded={false}
65+
<ApplicationLogo
66+
src={oAuthApplicationLogoUrl}
67+
alt={oAuthApplicationName}
6668
/>
6769
<ConnectionIcon
6870
size='sm'
@@ -77,31 +79,21 @@ export function OAuthConsentInternal() {
7779
)}
7880
{/* only Clerk application has an avatar */}
7981
{!oAuthApplicationLogoUrl && logoImageUrl && (
80-
<Flex
81-
justify='center'
82-
align='center'
83-
gap={4}
84-
sx={t => ({
85-
marginBlockEnd: t.space.$6,
86-
})}
87-
>
88-
<ConnectionIcon />
82+
<ConnectionHeader>
83+
<ConnectionItem justify='end'>
84+
<ConnectionIcon />
85+
</ConnectionItem>
8986
<ConnectionSeparator />
90-
<ApplicationLogo />
91-
</Flex>
87+
<ConnectionItem justify='start'>
88+
<ApplicationLogo />
89+
</ConnectionItem>
90+
</ConnectionHeader>
9291
)}
9392
{/* no avatars */}
9493
{!oAuthApplicationLogoUrl && !logoImageUrl && (
95-
<Flex
96-
justify='center'
97-
align='center'
98-
gap={4}
99-
sx={t => ({
100-
marginBlockEnd: t.space.$6,
101-
})}
102-
>
94+
<ConnectionHeader>
10395
<ConnectionIcon />
104-
</Flex>
96+
</ConnectionHeader>
10597
)}
10698
<Header.Title localizationKey={oAuthApplicationName} />
10799
<Header.Subtitle
@@ -320,6 +312,17 @@ function ConnectionHeader({ children }: { children: React.ReactNode }) {
320312
);
321313
}
322314

315+
function ConnectionItem({ children, sx, ...props }: ComponentProps<typeof Flex>) {
316+
return (
317+
<Flex
318+
{...props}
319+
sx={[{ flex: 1 }, sx]}
320+
>
321+
{children}
322+
</Flex>
323+
);
324+
}
325+
323326
function ConnectionIcon({ size = 'md', sx }: { size?: 'sm' | 'md'; sx?: ThemableCssProp }) {
324327
const scale: ThemableCssProp = t => {
325328
const value = size === 'sm' ? t.space.$6 : t.space.$12;

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,30 @@ const getContainerHeightForImageRatio = (imageRef: React.RefObject<HTMLImageElem
2121
return width;
2222
};
2323

24-
type ApplicationLogoProps = PropsOfComponent<typeof Flex>;
24+
export type ApplicationLogoProps = PropsOfComponent<typeof Flex> & {
25+
/**
26+
* The URL of the image to display.
27+
*/
28+
src?: string;
29+
/**
30+
* The alt text for the image.
31+
*/
32+
alt?: string;
33+
/**
34+
* The URL to navigate to when the logo is clicked.
35+
*/
36+
href?: string;
37+
};
2538

26-
export const ApplicationLogo = (props: ApplicationLogoProps) => {
39+
export const ApplicationLogo: React.FC<ApplicationLogoProps> = (props: ApplicationLogoProps): JSX.Element | null => {
40+
const { src, alt, href, sx, ...rest } = props;
2741
const imageRef = React.useRef<HTMLImageElement>(null);
2842
const [loaded, setLoaded] = React.useState(false);
2943
const { logoImageUrl, applicationName, homeUrl } = useEnvironment().displayConfig;
3044
const { parsedLayout } = useAppearance();
31-
const imageSrc = parsedLayout.logoImageUrl || logoImageUrl;
32-
const logoUrl = parsedLayout.logoLinkUrl || homeUrl;
45+
const imageSrc = src || parsedLayout.logoImageUrl || logoImageUrl;
46+
const imageAlt = alt || applicationName;
47+
const logoUrl = href || parsedLayout.logoLinkUrl || homeUrl;
3348

3449
if (!imageSrc) {
3550
return null;
@@ -39,7 +54,7 @@ export const ApplicationLogo = (props: ApplicationLogoProps) => {
3954
<Image
4055
ref={imageRef}
4156
elementDescriptor={descriptors.logoImage}
42-
alt={applicationName}
57+
alt={imageAlt}
4358
src={imageSrc}
4459
size={200}
4560
onLoad={() => setLoaded(true)}
@@ -55,20 +70,18 @@ export const ApplicationLogo = (props: ApplicationLogoProps) => {
5570
return (
5671
<Flex
5772
elementDescriptor={descriptors.logoBox}
58-
{...props}
73+
{...rest}
5974
sx={[
6075
theme => ({
6176
height: getContainerHeightForImageRatio(imageRef, theme.sizes.$6),
6277
justifyContent: 'center',
6378
}),
64-
props.sx,
79+
sx,
6580
]}
6681
>
6782
{logoUrl ? (
6883
<RouterLink
69-
sx={{
70-
justifyContent: 'center',
71-
}}
84+
focusRing
7285
to={logoUrl}
7386
>
7487
{image}

packages/clerk-js/src/ui/primitives/Link.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ const { applyVariants, filterProps } = createVariants(theme => ({
3333
},
3434
inherit: { color: 'inherit' },
3535
},
36+
focusRing: {
37+
true: {
38+
'&:focus': {
39+
outline: 'none',
40+
...common.focusRing(theme),
41+
},
42+
},
43+
},
3644
},
3745
defaultVariants: {
3846
colorScheme: 'primary',
3947
variant: 'body',
48+
focusRing: false,
4049
},
4150
}));
4251

0 commit comments

Comments
 (0)