Skip to content

Conversation

@nikospapcom
Copy link
Contributor

@nikospapcom nikospapcom commented Jul 23, 2024

Description

Introduce support for custom menu items in <UserButton/>.

  • Use <UserButton.MenuItems> as a child component to wrap custom menu items.
  • Use <UserButton.Link/> for creating external or internal links.
  • Use <UserButton.Action/> for opening a specific custom page of "UserProfile" or to trigger your own custom logic via onClick.
  • If needed, reorder existing items like manageAccount and signOut
<UserButton>
  <UserButton.MenuItems>
    <UserButton.Link label='Terms' labelIcon={<Icon />} href='/terms' />
    <UserButton.Action label='Help' labelIcon={<Icon />} open='help' /> // Opens help page in UserProfileModal
    <UserButton.Action label='manageAccount' labelIcon={<Icon />} />
    <UserButton.Action label='Chat Modal' labelIcon={<Icon />} onClick={() => setModal(true)} />
  </UserButton.MenuItems>
</UserButton>

Custom Item

Screenshot 2024-07-26 at 1 01 49 PM

Custom Items and reordered default items

Screenshot 2024-07-26 at 1 02 47 PM

Multi-session with custom item

Screenshot 2024-07-26 at 1 06 15 PM

Multi-session custom items and reordered default items

Screenshot 2024-07-26 at 1 03 57 PM

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@changeset-bot
Copy link

changeset-bot bot commented Jul 23, 2024

🦋 Changeset detected

Latest commit: 80e991f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@clerk/clerk-js Minor
@clerk/clerk-react Minor
@clerk/types Minor
@clerk/astro Patch
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch
@clerk/elements Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/tanstack-start Patch
@clerk/backend Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/localizations Patch
@clerk/clerk-sdk-node Patch
@clerk/shared Patch
@clerk/testing Patch
@clerk/themes Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@nikospapcom
Copy link
Contributor Author

!snapshot

@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch 4 times, most recently from 34f2f73 to 04b187b Compare July 25, 2024 15:20
@nikospapcom
Copy link
Contributor Author

!snapshot

@nikospapcom nikospapcom self-assigned this Jul 25, 2024
@clerk clerk deleted a comment from clerk-cookie Jul 26, 2024
@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch from 04b187b to 4ef610e Compare July 26, 2024 07:25
@nikospapcom nikospapcom changed the title feat(clerk-js,react,types): Introduce UserButton & OrganizationSwitcher custom menu items feat(clerk-js,react,types): Introduce UserButton custom menu items Jul 26, 2024
@clerk clerk deleted a comment from clerk-cookie Jul 26, 2024
@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch 3 times, most recently from c8d5c5c to 48ca521 Compare July 26, 2024 08:41
@nikospapcom
Copy link
Contributor Author

!snapshot

@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch 3 times, most recently from 6ee1d06 to f41dbf6 Compare July 26, 2024 09:22
@nikospapcom nikospapcom changed the title feat(clerk-js,react,types): Introduce UserButton custom menu items feat(clerk-js,clerk-react,types): Introduce UserButton custom menu items Jul 26, 2024
@nikospapcom nikospapcom marked this pull request as ready for review July 26, 2024 10:07
Copy link
Contributor

@panteliselef panteliselef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a first pass on it.

if (
!isThatComponent(child, PageComponent) &&
!isThatComponent(child, LinkComponent) &&
!isThatComponent(child, MenuItemsComponent)
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Do we allow for <UserProfile.MenuItems/> ? What's the reason we need this ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@panteliselef We can define custom pages through UserButton component and we need to allow MenuItems as children component.
For custom pages we use the useUserProfileCustomPages for both UserProfile and UserButton, maybe we should create 2 separate utils here in order to be able to determine the correct component and validate the component only if is it UserButton, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After our discussion, I confirm that this change is necessary. Regarding your question, this is definitely a good suggestion but nothing that needs to delay this PR any longer.

@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch 2 times, most recently from ee66c8b to dcda643 Compare July 29, 2024 15:48
@octoper
Copy link
Member

octoper commented Jul 29, 2024

!preview

@clerk-cookie
Copy link
Collaborator

clerk-cookie commented Jul 29, 2024

Hey @octoper, your preview is available.

Status Preview Updated (UTC)
🍪 Deployed Visit preview Jul 29, 2024 04:14 PM

@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch 3 times, most recently from 4daf854 to 60da18f Compare July 30, 2024 07:07
Copy link
Member

@anagstef anagstef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work! 💯 🚀

@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch from 60da18f to 12ddd71 Compare July 30, 2024 09:45
@clerk clerk deleted a comment from clerk-cookie Jul 30, 2024
@nikospapcom
Copy link
Contributor Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @nikospapcom - the snapshot version command generated the following package versions:

Package Version
@clerk/astro 1.0.5-snapshot.v12ddd71
@clerk/backend 1.5.0-snapshot.v12ddd71
@clerk/chrome-extension 1.1.8-snapshot.v12ddd71
@clerk/clerk-js 5.11.0-snapshot.v12ddd71
@clerk/elements 0.10.8-snapshot.v12ddd71
@clerk/clerk-expo 2.0.1-snapshot.v12ddd71
@clerk/express 0.0.22-snapshot.v12ddd71
@clerk/fastify 1.0.24-snapshot.v12ddd71
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/localizations 2.5.3-snapshot.v12ddd71
@clerk/nextjs 5.2.9-snapshot.v12ddd71
@clerk/clerk-react 5.3.0-snapshot.v12ddd71
@clerk/remix 4.2.8-snapshot.v12ddd71
@clerk/clerk-sdk-node 5.0.21-snapshot.v12ddd71
@clerk/shared 2.4.2-snapshot.v12ddd71
@clerk/tanstack-start 0.1.12-snapshot.v12ddd71
@clerk/testing 1.2.4-snapshot.v12ddd71
@clerk/themes 2.1.15-snapshot.v12ddd71
@clerk/types 4.10.0-snapshot.v12ddd71

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/astro

npm i @clerk/astro@1.0.5-snapshot.v12ddd71 --save-exact

@clerk/backend

npm i @clerk/backend@1.5.0-snapshot.v12ddd71 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.1.8-snapshot.v12ddd71 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.11.0-snapshot.v12ddd71 --save-exact

@clerk/elements

npm i @clerk/elements@0.10.8-snapshot.v12ddd71 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@2.0.1-snapshot.v12ddd71 --save-exact

@clerk/express

npm i @clerk/express@0.0.22-snapshot.v12ddd71 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.24-snapshot.v12ddd71 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.5.3-snapshot.v12ddd71 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.2.9-snapshot.v12ddd71 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.3.0-snapshot.v12ddd71 --save-exact

@clerk/remix

npm i @clerk/remix@4.2.8-snapshot.v12ddd71 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.21-snapshot.v12ddd71 --save-exact

@clerk/shared

npm i @clerk/shared@2.4.2-snapshot.v12ddd71 --save-exact

@clerk/tanstack-start

npm i @clerk/tanstack-start@0.1.12-snapshot.v12ddd71 --save-exact

@clerk/testing

npm i @clerk/testing@1.2.4-snapshot.v12ddd71 --save-exact

@clerk/themes

npm i @clerk/themes@2.1.15-snapshot.v12ddd71 --save-exact

@clerk/types

npm i @clerk/types@4.10.0-snapshot.v12ddd71 --save-exact

@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch from 12ddd71 to 49e0275 Compare July 30, 2024 13:31
if (
!isThatComponent(child, PageComponent) &&
!isThatComponent(child, LinkComponent) &&
!isThatComponent(child, MenuItemsComponent)
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After our discussion, I confirm that this change is necessary. Regarding your question, this is definitely a good suggestion but nothing that needs to delay this PR any longer.

@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch from 49e0275 to 821e3ec Compare July 30, 2024 13:45
@nikospapcom nikospapcom force-pushed the nikospap/user-179-introduce-userbuttonmenuitems branch from 821e3ec to 80e991f Compare July 31, 2024 06:21
@nikospapcom nikospapcom merged commit aa06f3b into main Jul 31, 2024
@nikospapcom nikospapcom deleted the nikospap/user-179-introduce-userbuttonmenuitems branch July 31, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants