Skip to content

Commit

Permalink
feat(clerk-js, types): asStandalone accepts a callback (#4423)
Browse files Browse the repository at this point in the history
  • Loading branch information
panteliselef authored Oct 29, 2024
1 parent f875463 commit 5be7ca9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/few-swans-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@clerk/clerk-js": patch
"@clerk/types": patch
---

Experimental: `asStandalone` now accepts a callback that notifies if the standalone popover needs to unmount.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ const _OrganizationSwitcher = () => {
>
<AcceptedInvitationsProvider>
{__experimental_asStandalone ? (
<OrganizationSwitcherPopover />
<OrganizationSwitcherPopover
close={typeof __experimental_asStandalone === 'function' ? __experimental_asStandalone : undefined}
/>
) : (
<OrganizationSwitcherWithFloatingTree>
<OrganizationSwitcherPopover />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import { useRouter } from '../../router';
import type { PropsOfComponent, ThemableCssProp } from '../../styledSystem';
import { OrganizationActionList } from './OtherOrganizationActions';

type OrganizationSwitcherPopoverProps = {
close?: (open: boolean | ((prevState: boolean) => boolean)) => void;
} & PropsOfComponent<typeof PopoverCard.Root>;
type OrganizationSwitcherPopoverProps = { close?: (open: boolean) => void } & PropsOfComponent<typeof PopoverCard.Root>;

export const OrganizationSwitcherPopover = React.forwardRef<HTMLDivElement, OrganizationSwitcherPopoverProps>(
(props, ref) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ const _UserButton = () => {
sx={{ display: 'inline-flex' }}
>
{__experimental_asStandalone ? (
<UserButtonPopover />
<UserButtonPopover
close={typeof __experimental_asStandalone === 'function' ? __experimental_asStandalone : undefined}
/>
) : (
<UserButtonWithFloatingTree>
<UserButtonPopover />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import type { PropsOfComponent } from '../../styledSystem';
import { MultiSessionActions, SignOutAllActions, SingleSessionActions } from './SessionActions';
import { useMultisessionActions } from './useMultisessionActions';

type UserButtonPopoverProps = { close?: () => void } & PropsOfComponent<typeof PopoverCard.Root>;
type UserButtonPopoverProps = { close?: (open: boolean) => void } & PropsOfComponent<typeof PopoverCard.Root>;

export const UserButtonPopover = React.forwardRef<HTMLDivElement, UserButtonPopoverProps>((props, ref) => {
const { close: unsafeClose, ...rest } = props;
const close = () => unsafeClose?.();
const close = () => unsafeClose?.(false);
const { session } = useSession() as { session: ActiveSessionResource };
const { __experimental_asStandalone } = useUserButtonContext();
const { authConfig } = useEnvironment();
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ export type UserButtonProps = UserButtonProfileMode & {
* @experimental This API is experimental and may change at any moment.
* @default undefined
*/
__experimental_asStandalone?: boolean;
__experimental_asStandalone?: boolean | ((opened: boolean) => void);

/**
* Full URL or path to navigate after sign out is complete
Expand Down Expand Up @@ -1140,7 +1140,7 @@ export type OrganizationSwitcherProps = CreateOrganizationMode &
* @experimental This API is experimental and may change at any moment.
* @default undefined
*/
__experimental_asStandalone?: boolean;
__experimental_asStandalone?: boolean | ((opened: boolean) => void);

/**
* By default, users can switch between organization and their personal account.
Expand Down

0 comments on commit 5be7ca9

Please sign in to comment.