Skip to content
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

feat(clerk-js): Retheme <UserButton /> #2212

Merged
merged 5 commits into from
Nov 29, 2023
Merged
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
2 changes: 2 additions & 0 deletions .changeset/dirty-panthers-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import type { ActiveSessionResource } from '@clerk/types';

import { descriptors, Flex, localizationKeys } from '../../customizables';
import { Action, Actions, SmallAction } from '../../elements';
import { CogFilled, SignOut } from '../../icons';

type SessionActionsProps = {
handleManageAccountClicked: () => Promise<unknown> | void;
handleSignOutSessionClicked: (session: ActiveSessionResource) => () => Promise<unknown> | void;
session: ActiveSessionResource;
};

export const SingleSessionActions = (props: SessionActionsProps) => {
const { handleManageAccountClicked, handleSignOutSessionClicked, session } = props;

return (
<Actions
role='menu'
elementDescriptor={descriptors.userButtonPopoverActions}
elementId={descriptors.userButtonPopoverActions.setId('singleSession')}
sx={t => ({ backgroundColor: t.colors.$blackAlpha100 })}
>
<Action
elementDescriptor={descriptors.userButtonPopoverActionButton}
elementId={descriptors.userButtonPopoverActionButton.setId('manageAccount')}
iconBoxElementDescriptor={descriptors.userButtonPopoverActionButtonIconBox}
iconBoxElementId={descriptors.userButtonPopoverActionButtonIconBox.setId('manageAccount')}
iconElementDescriptor={descriptors.userButtonPopoverActionButtonIcon}
iconElementId={descriptors.userButtonPopoverActionButtonIcon.setId('manageAccount')}
textElementDescriptor={descriptors.userButtonPopoverActionButtonText}
textElementId={descriptors.userButtonPopoverActionButtonText.setId('manageAccount')}
icon={CogFilled}
label={localizationKeys('userButton.action__manageAccount')}
onClick={handleManageAccountClicked}
sx={t => ({
borderTop: `${t.borders.$normal} ${t.colors.$blackAlpha100}`,
})}
/>
<Action
elementDescriptor={descriptors.userButtonPopoverActionButton}
elementId={descriptors.userButtonPopoverActionButton.setId('signOut')}
iconBoxElementDescriptor={descriptors.userButtonPopoverActionButtonIconBox}
iconBoxElementId={descriptors.userButtonPopoverActionButtonIconBox.setId('signOut')}
iconElementDescriptor={descriptors.userButtonPopoverActionButtonIcon}
iconElementId={descriptors.userButtonPopoverActionButtonIcon.setId('signOut')}
textElementDescriptor={descriptors.userButtonPopoverActionButtonText}
textElementId={descriptors.userButtonPopoverActionButtonText.setId('signOut')}
icon={SignOut}
label={localizationKeys('userButton.action__signOut')}
onClick={handleSignOutSessionClicked(session)}
sx={[
t => ({
borderBottomLeftRadius: t.radii.$lg,
borderBottomRightRadius: t.radii.$lg,
':hover': {
backgroundColor: t.colors.$danger50,
color: t.colors.$danger400,
},
}),
]}
/>
</Actions>
);
};

export const MultiSessionActions = (props: SessionActionsProps) => {
const { handleManageAccountClicked, handleSignOutSessionClicked, session } = props;

return (
<Actions
role='menu'
elementDescriptor={descriptors.userButtonPopoverActions}
elementId={descriptors.userButtonPopoverActions.setId('multiSession')}
sx={t => ({
borderBottom: `${t.borders.$normal} ${t.colors.$blackAlpha100}`,
})}
>
<Flex
justify='between'
sx={t => ({ marginLeft: t.space.$12, padding: `0 ${t.space.$5} ${t.space.$4}`, gap: t.space.$2 })}
>
<SmallAction
elementDescriptor={descriptors.userButtonPopoverActionButton}
elementId={descriptors.userButtonPopoverActionButton.setId('manageAccount')}
iconBoxElementDescriptor={descriptors.userButtonPopoverActionButtonIconBox}
iconBoxElementId={descriptors.userButtonPopoverActionButtonIconBox.setId('manageAccount')}
iconElementDescriptor={descriptors.userButtonPopoverActionButtonIcon}
iconElementId={descriptors.userButtonPopoverActionButtonIcon.setId('manageAccount')}
textElementDescriptor={descriptors.userButtonPopoverActionButtonText}
textElementId={descriptors.userButtonPopoverActionButtonText.setId('manageAccount')}
icon={CogFilled}
label={localizationKeys('userButton.action__manageAccount')}
onClick={handleManageAccountClicked}
/>
<SmallAction
elementDescriptor={descriptors.userButtonPopoverActionButton}
elementId={descriptors.userButtonPopoverActionButton.setId('signOut')}
iconBoxElementDescriptor={descriptors.userButtonPopoverActionButtonIconBox}
iconBoxElementId={descriptors.userButtonPopoverActionButtonIconBox.setId('signOut')}
iconElementDescriptor={descriptors.userButtonPopoverActionButtonIcon}
iconElementId={descriptors.userButtonPopoverActionButtonIcon.setId('signOut')}
textElementDescriptor={descriptors.userButtonPopoverActionButtonText}
textElementId={descriptors.userButtonPopoverActionButtonText.setId('signOut')}
icon={SignOut}
label={localizationKeys('userButton.action__signOut')}
onClick={handleSignOutSessionClicked(session)}
sx={[
t => ({
':hover': {
backgroundColor: t.colors.$danger50,
color: t.colors.$danger400,
},
}),
]}
/>
</Flex>
</Actions>
);
};
Loading
Loading