Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/application-logomark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/clerk-js': minor
'@clerk/shared': minor
'@clerk/mosaic': minor
---

Add `logomarkImageUrl` to `DisplayConfig`.
5 changes: 5 additions & 0 deletions .changeset/mosaic-avatar-fallback-variant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/mosaic': minor
---

Add `variant` to `Avatar.Fallback`. `'initials'` paints its children; `'skeleton'`, the default, keeps the blank fill.
5 changes: 5 additions & 0 deletions .changeset/mosaic-avatar-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/mosaic': patch
---

Darken the edge ring on bordered avatars so it stays visible against light and dark images.
5 changes: 5 additions & 0 deletions .changeset/mosaic-oauth-consent-known-clients.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/mosaic': minor
---

`OAuthConsent` shows the Claude or ChatGPT logo when the OAuth application has no logo and redirects to one of those clients, and the OAuth application's initials otherwise.
3 changes: 3 additions & 0 deletions packages/clerk-js/src/core/resources/DisplayConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class DisplayConfig extends BaseResource implements DisplayConfigResource
id: string = '';
instanceEnvironmentType: string = '';
logoImageUrl: string = '';
logomarkImageUrl: string = '';
organizationProfileUrl: string = '';
preferredSignInStrategy: PreferredSignInStrategy = 'password';
privacyPolicyUrl: string = '';
Expand Down Expand Up @@ -99,6 +100,7 @@ export class DisplayConfig extends BaseResource implements DisplayConfigResource
this.id = this.withDefault(data.id, this.id);
this.instanceEnvironmentType = this.withDefault(data.instance_environment_type, this.instanceEnvironmentType);
this.logoImageUrl = this.withDefault(data.logo_image_url, this.logoImageUrl);
this.logomarkImageUrl = this.withDefault(data.logomark_image_url, this.logomarkImageUrl);
this.organizationProfileUrl = this.withDefault(data.organization_profile_url, this.organizationProfileUrl);
this.preferredSignInStrategy = this.withDefault(data.preferred_sign_in_strategy, this.preferredSignInStrategy);
this.privacyPolicyUrl = this.withDefault(data.privacy_policy_url, this.privacyPolicyUrl);
Expand Down Expand Up @@ -142,6 +144,7 @@ export class DisplayConfig extends BaseResource implements DisplayConfigResource
id: this.id,
instance_environment_type: this.instanceEnvironmentType,
logo_image_url: this.logoImageUrl,
logomark_image_url: this.logomarkImageUrl,
organization_profile_url: this.organizationProfileUrl,
preferred_sign_in_strategy: this.preferredSignInStrategy,
privacy_policy_url: this.privacyPolicyUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('Environment', () => {
},
preferred_sign_in_strategy: 'password',
logo_image_url: '',
logomark_image_url: 'https://img.clerk.com/logomark.png',
favicon_image_url: '',
home_url: '',
sign_in_url: '',
Expand Down Expand Up @@ -303,6 +304,7 @@ describe('Environment', () => {
branded: true,
showDevModeWarning: true,
preferredSignInStrategy: 'password',
logomarkImageUrl: 'https://img.clerk.com/logomark.png',
theme: expect.objectContaining({
general: expect.objectContaining({
color: '#6c47ff',
Expand Down Expand Up @@ -373,6 +375,7 @@ describe('Environment', () => {
},
preferred_sign_in_strategy: 'password',
logo_image_url: '',
logomark_image_url: 'https://img.clerk.com/logomark.png',
favicon_image_url: '',
home_url: '',
sign_in_url: '',
Expand Down Expand Up @@ -593,6 +596,7 @@ describe('Environment', () => {
branded: true,
show_devmode_warning: true,
preferred_sign_in_strategy: 'password',
logomark_image_url: 'https://img.clerk.com/logomark.png',
}),
user_settings: expect.objectContaining({
attributes: expect.objectContaining({
Expand Down
1 change: 1 addition & 0 deletions packages/clerk-js/src/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const createBaseDisplayConfig = (): DisplayConfigJSON => {
},
preferred_sign_in_strategy: 'password',
logo_image_url: 'https://images.clerk.com/uploaded/img_logo.png',
logomark_image_url: 'https://images.clerk.com/uploaded/img_logomark.png',
favicon_image_url: 'https://images.clerk.com/uploaded/img_favicon.png',
home_url: 'https://dashboard.clerk.com',
sign_in_url: 'https://dashboard.clerk.com/sign-in',
Expand Down
1 change: 1 addition & 0 deletions packages/expo/src/cache/dummy-data/environment-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const DUMMY_CLERK_ENVIRONMENT_RESOURCE = {
},
preferred_sign_in_strategy: 'password',
logo_image_url: '',
logomark_image_url: '',
favicon_image_url: '',
home_url: '',
sign_in_url: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const DUMMY_TEST_LARGE_JSON = {
},
preferred_sign_in_strategy: 'password',
logo_image_url: '',
logomark_image_url: '',
favicon_image_url: '',
home_url: '',
sign_in_url: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/mosaic/bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": [
{ "path": "./dist/.bundlewatch/eager/index.js", "maxSize": "28KB" },
{ "path": "./dist/.bundlewatch/eager/index.js", "maxSize": "31KB" },
{ "path": "./dist/.bundlewatch/total/index.js", "maxSize": "315KB" },
{ "path": "./dist/styles.css", "maxSize": "19KB" }
]
Expand Down
1 change: 1 addition & 0 deletions packages/mosaic/src/__tests__/feature/fapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export function fapiEnvironment(overrides: FapiEnvironmentOverrides = {}): FapiE
home_url: '',
instance_environment_type: 'production',
logo_image_url: '',
logomark_image_url: '',
favicon_image_url: '',
preferred_sign_in_strategy: 'password',
sign_in_url: '/sign-in',
Expand Down
10 changes: 1 addition & 9 deletions packages/mosaic/src/blocks/avatar-upload/avatar-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { mergeStyleProps, themeProps } from '../../props';
import { focusOutline } from '../../styles/focus-outline.styles';
import { reset } from '../../styles/reset.styles';
import { AVATAR_UPLOAD, cropAvatar, croppedFile, skipsCrop } from '../../utils/avatar-upload';
import { initials } from '../../utils/initials';
import { avatarUploadDropzoneScope } from './avatar-upload.markers.stylex';
import { styles } from './avatar-upload.styles';

Expand Down Expand Up @@ -380,12 +381,3 @@ function useAvatarUploadContext() {
}
return context;
}

function initials(name: string) {
return name
.split(/\s+/)
.map(part => part[0])
.join('')
.slice(0, 2)
.toUpperCase();
}
11 changes: 9 additions & 2 deletions packages/mosaic/src/components/avatar/avatar.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
{ do: true, text: 'Pass `alt` on `Avatar.Image`.' },
{
do: false,
text: 'Expect initials passed to `Avatar.Fallback` to show. They stay hidden so a missing picture reads as an absent image.',
text: "Expect initials passed to `Avatar.Fallback` to show without `variant='initials'`. They stay hidden so a missing picture reads as an absent image.",
},
],
parts: {
Expand All @@ -35,7 +35,14 @@ export default {
'Avatar.Fallback': {
description: 'Holds the space while the image is pending or failed. Carries `data-pending` while resolving.',
slot: 'cl-avatar-fallback',
props: { delayMs: { type: 'number', doc: 'Waits this long before rendering, to avoid a flash on fast loads.' } },
props: {
delayMs: { type: 'number', doc: 'Waits this long before rendering, to avoid a flash on fast loads.' },
variant: {
type: "'skeleton' | 'initials'",
doc: '`skeleton` is a blank fill that pulses while an image loads. `initials` paints the children and holds still.',
default: "'skeleton'",
},
},
},
'Avatar.Icon': {
description: 'An optional icon over the corner of the avatar.',
Expand Down
2 changes: 1 addition & 1 deletion packages/mosaic/src/components/avatar/avatar.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const styles = stylex.create({
},

overlay: {
outlineColor: colorVars['--cl-color-neutral-alpha-100'],
outlineColor: colorVars['--cl-color-neutral-subtle'],
outlineOffset: '-1px',
outlineStyle: 'solid',
outlineWidth: '1px',
Expand Down
26 changes: 26 additions & 0 deletions packages/mosaic/src/components/avatar/avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,32 @@ describe('Mosaic Avatar', () => {
);
expect(screen.getByTestId('fallback')).toHaveTextContent('CN');
expect(screen.getByText('CN')).toHaveClass('cl-avatar-fallback-content');
expect(screen.getByText('CN')).toHaveClass(stylex.props(styles.fallbackContent).className ?? '');
});

it('paints the fallback content in the initials variant', () => {
render(
<Avatar.Root>
<Avatar.Fallback variant='initials'>CN</Avatar.Fallback>
</Avatar.Root>,
);
expect(screen.getByText('CN')).not.toHaveClass(stylex.props(styles.fallbackContent).className ?? '');
});

it('holds still in the initials variant while an image is still resolving', () => {
unresolved.add('https://example.com/slow.png');
render(
<Avatar.Root>
<Avatar.Image src='https://example.com/slow.png' />
<Avatar.Fallback
data-testid='fallback'
variant='initials'
>
CN
</Avatar.Fallback>
</Avatar.Root>,
);
expect(screen.getByTestId('fallback')).not.toHaveAttribute('data-pending');
});

it('pulses only while an image is still resolving', async () => {
Expand Down
64 changes: 40 additions & 24 deletions packages/mosaic/src/components/avatar/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,22 @@ const AvatarRoot = React.forwardRef<HTMLSpanElement, AvatarProps>(function Mosai
return <AvatarContext.Provider value={value}>{element}</AvatarContext.Provider>;
});

export type AvatarImageProps = MosaicElementProps<'img'>;
export type AvatarImageProps = MosaicComponentProps<'img'>;

const AvatarImage = React.forwardRef<HTMLImageElement, AvatarImageProps>(function MosaicAvatarImage(
{ src, alt = '', xstyle, ...rest },
{ src, alt = '', render, xstyle, ...rest },
ref,
) {
const { bordered, status, onStatusChange } = useAvatarContext('Avatar.Image');

// Preload `src` and report status to the root, so the fallback shows until the image resolves.
// A layout effect, because it also has to catch the case below before anything is painted.
useSafeLayoutEffect(() => {
if (render) {
onStatusChange('loaded');
return;
}

if (!src) {
onStatusChange('error');
return;
Expand All @@ -107,36 +112,44 @@ const AvatarImage = React.forwardRef<HTMLImageElement, AvatarImageProps>(functio
return () => {
active = false;
};
}, [src, onStatusChange]);
}, [src, render, onStatusChange]);

if (status !== 'loaded') {
return null;
}

return (
<img
ref={ref}
src={src}
alt={alt}
// An avatar is an identity mark, not content to pull out of the page — dragging one
// only ever produces a stray ghost image mid-interaction.
draggable={false}
{...mergeStyleProps(
themeProps('avatar-image'),
stylex.props(reset.base, styles.image, bordered && styles.overlay, xstyle),
rest,
)}
/>
const styleProps = mergeStyleProps(
themeProps('avatar-image'),
stylex.props(reset.base, styles.image, bordered && styles.overlay, xstyle),
rest,
);

return useRender({
defaultTagName: 'img',
render,
ref,
enabled: Boolean(render) || status === 'loaded',
props: render
? styleProps
: {
src,
alt,
// An avatar is an identity mark, not content to pull out of the page — dragging one
// only ever produces a stray ghost image mid-interaction.
draggable: false,
...styleProps,
},
});
});

export interface AvatarFallbackProps extends MosaicElementProps<'span'> {
/** Wait this many ms before showing the fallback, to avoid a flash on fast connections. */
delayMs?: number;
/**
* `skeleton` hides the children behind a blank fill that pulses while an image loads.
* `initials` paints the children, such as initials, and holds still.
*/
variant?: 'skeleton' | 'initials';
}

const AvatarFallback = React.forwardRef<HTMLSpanElement, AvatarFallbackProps>(function MosaicAvatarFallback(
{ delayMs, xstyle, children, ...rest },
{ delayMs, variant = 'skeleton', xstyle, children, ...rest },
ref,
) {
const { bordered, status } = useAvatarContext('Avatar.Fallback');
Expand All @@ -150,7 +163,8 @@ const AvatarFallback = React.forwardRef<HTMLSpanElement, AvatarFallbackProps>(fu
return () => clearTimeout(timer);
}, [delayMs]);

const pending = canRender && status === 'loading';
const skeleton = variant === 'skeleton';
const pending = skeleton && canRender && status === 'loading';

if (!canRender || status === 'loaded') {
return null;
Expand All @@ -171,7 +185,9 @@ const AvatarFallback = React.forwardRef<HTMLSpanElement, AvatarFallbackProps>(fu
rest,
)}
>
<span {...mergeStyleProps(themeProps('avatar-fallback-content'), stylex.props(styles.fallbackContent))}>
<span
{...mergeStyleProps(themeProps('avatar-fallback-content'), stylex.props(skeleton && styles.fallbackContent))}
>
{children}
</span>
</span>
Expand Down
6 changes: 1 addition & 5 deletions packages/mosaic/src/components/switcher/switcher-avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import type { ReactElement } from 'react';

import { mergeStyleProps, themeProps } from '../../props';
import { reset } from '../../styles/reset.styles';
import { initials } from '../../utils/initials';
import type { AvatarProps } from '../avatar';
import { Avatar } from '../avatar';
import { useSlot } from './switcher.context';
import { sizes, styles } from './switcher-avatar.styles';

function initials(name: string): string {
const [first = '', second = ''] = name.trim().split(/\s+/);
return `${first.charAt(0)}${second.charAt(0)}`.toUpperCase() || '?';
}

export interface SwitcherAvatarProps {
name: string;
imageUrl?: string;
Expand Down
Loading
Loading