Skip to content

Commit b59b6b7

Browse files
authored
feat(clerk-js): Allow customization of OrganizationProfile through OrganizationSwitcher (#1801)
Expose organizationProfileProps from switcher and deprecate UserButton appearance
1 parent 9514618 commit b59b6b7

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

.changeset/chilled-parrots-pump.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
'@clerk/types': patch
4+
---
5+
6+
- Introduce organizationProfileProps as prop in `<OrganizationSwitcher/>`.
7+
- Introduce appearance in userProfileProps in `<UserButton/>`.
8+
- Deprecate the usage of `appearance.userProfile` in <UserButton/>`.

packages/clerk-js/src/ui/components/OrganizationSwitcher/OrganizationSwitcherPopover.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const OrganizationSwitcherPopover = React.forwardRef<HTMLDivElement, Orga
5252
navigateOrganizationProfile,
5353
navigateAfterSelectPersonal,
5454
navigateAfterSelectOrganization,
55+
organizationProfileProps,
5556
} = useOrganizationSwitcherContext();
5657

5758
const user = useCoreUser();
@@ -93,6 +94,7 @@ export const OrganizationSwitcherPopover = React.forwardRef<HTMLDivElement, Orga
9394
return navigateOrganizationProfile();
9495
}
9596
return openOrganizationProfile({
97+
...organizationProfileProps,
9698
afterLeaveOrganizationUrl,
9799
//@ts-expect-error
98100
__unstable_manageBillingUrl,

packages/clerk-js/src/ui/components/UserButton/useMultisessionActions.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { deprecatedObjectProperty } from '@clerk/shared';
12
import type { ActiveSessionResource, UserButtonProps, UserResource } from '@clerk/types';
23

34
import { windowNavigate } from '../../../utils/windowNavigate';
@@ -44,7 +45,18 @@ export const useMultisessionActions = (opts: UseMultisessionActionsParams) => {
4445
}
4546

4647
// The UserButton can also accept an appearance object for the nested UserProfile modal
47-
openUserProfile({ ...opts.userProfileProps, appearance: opts.appearance?.userProfile });
48+
if (opts.appearance?.userProfile) {
49+
deprecatedObjectProperty(
50+
opts.appearance,
51+
'userProfile',
52+
'Use `<UserButton userProfileProps={{appearance: {...}}} />` instead.',
53+
);
54+
}
55+
openUserProfile({
56+
appearance: opts.appearance?.userProfile,
57+
// Prioritize the appearance of `userProfileProps`
58+
...opts.userProfileProps,
59+
});
4860
return opts.actionCompleteCallback?.();
4961
};
5062

packages/types/src/clerk.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,18 @@ export type UserButtonProps = {
795795
* These options serve as overrides and will be merged with the global `appearance`
796796
* prop of ClerkProvided (if one is provided)
797797
*/
798-
appearance?: UserButtonTheme & { userProfile?: UserProfileTheme };
798+
appearance?: UserButtonTheme & {
799+
/**
800+
* @deprecated Use `userProfileProps.appearance` instead.
801+
*/
802+
userProfile?: UserProfileTheme;
803+
};
799804

800805
/*
801806
* Specify options for the underlying <UserProfile /> component.
802807
* e.g. <UserButton userProfileProps={{additionalOAuthScopes: {google: ['foo', 'bar'], github: ['qux']}}} />
803808
*/
804-
userProfileProps?: Pick<UserProfileProps, 'additionalOAuthScopes'>;
809+
userProfileProps?: Pick<UserProfileProps, 'additionalOAuthScopes' | 'appearance'>;
805810
};
806811

807812
type PrimitiveKeys<T> = {
@@ -886,6 +891,12 @@ export type OrganizationSwitcherProps = {
886891
* prop of ClerkProvided (if one is provided)
887892
*/
888893
appearance?: OrganizationSwitcherTheme;
894+
895+
/*
896+
* Specify options for the underlying <OrganizationProfile /> component.
897+
* e.g. <UserButton userProfileProps={{appearance: {...}}} />
898+
*/
899+
organizationProfileProps?: Pick<OrganizationProfileProps, 'appearance'>;
889900
};
890901

891902
export type OrganizationListProps = {

0 commit comments

Comments
 (0)