-
Notifications
You must be signed in to change notification settings - Fork 392
feat(clerk-js,nextjs,clerk-react,testing,types,vue): UserAvatar component #6808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
'@clerk/tanstack-react-start': minor | ||
'@clerk/chrome-extension': minor | ||
'@clerk/react-router': minor | ||
'@clerk/clerk-js': minor | ||
'@clerk/nextjs': minor | ||
'@clerk/clerk-react': minor | ||
'@clerk/remix': minor | ||
'@clerk/types': minor | ||
'@clerk/vue': minor | ||
--- | ||
|
||
Add new <UserAvatar /> component |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/testing': minor | ||
--- | ||
|
||
Add Playwright testing helpers under unstable page-objects: `userAvatar.goTo()`, `userAvatar.waitForMounted()`, and `userAvatar.toBeVisible()` for <UserAvatar />. |
9 changes: 9 additions & 0 deletions
9
integration/templates/next-app-router/src/app/user-avatar/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { UserAvatar } from '@clerk/nextjs'; | ||
|
||
export default function Page() { | ||
return ( | ||
<div> | ||
<UserAvatar fallback={<>Loading user avatar</>} /> | ||
</div> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
integration/templates/react-vite/src/user-avatar/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { UserAvatar } from '@clerk/clerk-react'; | ||
import React from 'react'; | ||
|
||
export default function UserAvatarPage() { | ||
return ( | ||
<div> | ||
<h1>UserAvatar</h1> | ||
<UserAvatar fallback={<>Loading user avatar</>} /> | ||
</div> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script setup lang="ts"> | ||
import { UserAvatar } from '@clerk/vue'; | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h1>UserAvatar</h1> | ||
<UserAvatar /> | ||
</div> | ||
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { test } from '@playwright/test'; | ||
|
||
import { appConfigs } from '../presets'; | ||
import type { FakeUser } from '../testUtils'; | ||
import { createTestUtils, testAgainstRunningApps } from '../testUtils'; | ||
|
||
testAgainstRunningApps({ | ||
withEnv: [appConfigs.envs.withEmailCodes], | ||
withPattern: ['react.vite.withEmailCodes', 'vue.vite'], | ||
})('UserAvatar component integration tests @generic', ({ app }) => { | ||
test.describe.configure({ mode: 'serial' }); | ||
|
||
let fakeUser: FakeUser; | ||
|
||
test.beforeAll(async () => { | ||
const u = createTestUtils({ app }); | ||
fakeUser = u.services.users.createFakeUser({ | ||
withPhoneNumber: true, | ||
withUsername: true, | ||
}); | ||
await u.services.users.createBapiUser(fakeUser); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await app.teardown(); | ||
await fakeUser.deleteIfExists(); | ||
}); | ||
|
||
test.afterEach(async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
await u.page.signOut(); | ||
await u.page.context().clearCookies(); | ||
}); | ||
|
||
test('UserAvatar loads and renders correctly when user is signed in', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
|
||
await u.po.signIn.goTo(); | ||
await u.po.signIn.signInWithEmailAndInstantPassword({ | ||
email: fakeUser.email, | ||
password: fakeUser.password, | ||
}); | ||
await u.po.expect.toBeSignedIn(); | ||
|
||
await u.po.userAvatar.goTo(); | ||
await u.po.userAvatar.toBeVisible(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ export { | |
SignUpButton, | ||
SignedIn, | ||
SignedOut, | ||
UserAvatar, | ||
UserButton, | ||
UserProfile, | ||
Waitlist, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useUser } from '@clerk/shared/react/index'; | ||
import type { UserAvatarProps } from '@clerk/types'; | ||
|
||
import { useUserAvatarContext, withCoreUserGuard } from '@/ui/contexts'; | ||
import { descriptors } from '@/ui/customizables'; | ||
import { UserAvatar as InternalUserAvatar } from '@/ui/elements/UserAvatar'; | ||
import { InternalThemeProvider } from '@/ui/styledSystem'; | ||
|
||
export const _UserAvatar = (props: UserAvatarProps) => { | ||
const ctx = useUserAvatarContext(); | ||
const { user } = useUser(); | ||
|
||
return ( | ||
<InternalThemeProvider> | ||
<InternalUserAvatar | ||
boxElementDescriptor={descriptors.userAvatarBox} | ||
imageElementDescriptor={descriptors.userAvatarImage} | ||
{...user} | ||
rounded={props.rounded ?? ctx.rounded ?? true} | ||
size={theme => theme.sizes.$7} | ||
/> | ||
</InternalThemeProvider> | ||
); | ||
}; | ||
|
||
export const UserAvatar = withCoreUserGuard(_UserAvatar); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/clerk-js/src/ui/contexts/components/UserAvatar.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createContext, useContext } from 'react'; | ||
|
||
import type { UserAvatarCtx } from '../../types'; | ||
|
||
export const UserAvatarContext = createContext<UserAvatarCtx | null>(null); | ||
|
||
export const useUserAvatarContext = () => { | ||
const context = useContext(UserAvatarContext); | ||
|
||
if (!context || context.componentName !== 'UserAvatar') { | ||
throw new Error('Clerk: useUserAvatarContext called outside UserAvatar.'); | ||
} | ||
|
||
const { componentName, ...ctx } = context; | ||
|
||
return { | ||
...ctx, | ||
componentName, | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
export * from './ApiKeys'; | ||
export * from './Checkout'; | ||
export * from './CreateOrganization'; | ||
export * from './GoogleOneTap'; | ||
export * from './OAuthConsent'; | ||
export * from './OrganizationList'; | ||
export * from './OrganizationProfile'; | ||
export * from './OrganizationSwitcher'; | ||
export * from './Plans'; | ||
export * from './PricingTable'; | ||
export * from './SignIn'; | ||
export * from './SignUp'; | ||
export * from './SignOut'; | ||
export * from './SignUp'; | ||
export * from './SubscriberType'; | ||
export * from './SubscriptionDetails'; | ||
export * from './UserAvatar'; | ||
export * from './UserButton'; | ||
export * from './UserProfile'; | ||
export * from './UserVerification'; | ||
export * from './UserButton'; | ||
export * from './OrganizationSwitcher'; | ||
export * from './OrganizationList'; | ||
export * from './OrganizationProfile'; | ||
export * from './CreateOrganization'; | ||
export * from './GoogleOneTap'; | ||
export * from './Waitlist'; | ||
export * from './PricingTable'; | ||
export * from './Checkout'; | ||
export * from './Plans'; | ||
export * from './ApiKeys'; | ||
export * from './OAuthConsent'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.