|
| 1 | +import type { OrganizationProfileProps, UserProfileProps } from '@clerk/shared/types'; |
| 2 | +import { createContext, useContext } from 'react'; |
| 3 | + |
| 4 | +import type { OrganizationProfilePageId } from '../switcher/switcher.pages'; |
| 5 | +import type { CustomProfileItem, UserProfilePageId } from '../user-profile/user-profile.types'; |
| 6 | + |
| 7 | +export interface MosaicProfile { |
| 8 | + /** |
| 9 | + * Whether one profile carries the account's pages and the active organization's. `false` keeps them |
| 10 | + * in separate profiles. It decides the profile's shape, not what `UserButton`'s menu lists. |
| 11 | + * |
| 12 | + * @default true |
| 13 | + */ |
| 14 | + combined?: boolean; |
| 15 | + /** |
| 16 | + * Options for the user profile, whichever component opens or mounts it. |
| 17 | + */ |
| 18 | + userProfileProps?: ProfileUserProps; |
| 19 | + /** |
| 20 | + * Options for the organization profile, or the organization's pages in a combined profile, |
| 21 | + * whichever component opens or mounts it. |
| 22 | + */ |
| 23 | + organizationProfileProps?: ProfileOrganizationProps; |
| 24 | +} |
| 25 | + |
| 26 | +/** What a profile takes beyond the profile component's own props. */ |
| 27 | +export interface ProfilePages<PageId extends string> { |
| 28 | + /** |
| 29 | + * Provide custom pages and links to be rendered inside the profile. |
| 30 | + */ |
| 31 | + customPages?: CustomProfileItem[]; |
| 32 | + /** |
| 33 | + * Controls the order of the profile's navigation. Accepts the ids of built-in pages and the |
| 34 | + * `path` of custom pages. Pages not listed are placed after the listed ones. The first entry is |
| 35 | + * the page the profile opens on, so it cannot be a link. |
| 36 | + * |
| 37 | + * @default undefined |
| 38 | + */ |
| 39 | + pageOrder?: (PageId | (string & {}))[]; |
| 40 | +} |
| 41 | + |
| 42 | +/** Options for the underlying `<UserProfile />` component. */ |
| 43 | +export interface ProfileUserProps |
| 44 | + extends |
| 45 | + ProfilePages<UserProfilePageId>, |
| 46 | + Pick<UserProfileProps, 'additionalOAuthScopes' | 'apiKeysProps' | 'appearance'> {} |
| 47 | + |
| 48 | +/** Options for the underlying `<OrganizationProfile />` component. */ |
| 49 | +export interface ProfileOrganizationProps |
| 50 | + extends ProfilePages<OrganizationProfilePageId>, Pick<OrganizationProfileProps, 'appearance'> {} |
| 51 | + |
| 52 | +const MosaicProfileContext = createContext<MosaicProfile>({}); |
| 53 | + |
| 54 | +export const MosaicProfileProvider = MosaicProfileContext.Provider; |
| 55 | + |
| 56 | +export function useMosaicProfile(): MosaicProfile { |
| 57 | + return useContext(MosaicProfileContext); |
| 58 | +} |
0 commit comments