-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(vue): Add custom menu items to
<UserButton />
(#4693)
- Loading branch information
1 parent
5276c9f
commit 1c51045
Showing
14 changed files
with
519 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@clerk/vue": patch | ||
--- | ||
|
||
Add support for custom menu items to `<UserButton />` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
integration/templates/vue-vite/src/components/CustomUserButton.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<script setup lang="ts"> | ||
import { UserButton } from '@clerk/vue'; | ||
import { ref } from 'vue'; | ||
const isActionClicked = ref(false); | ||
</script> | ||
|
||
<template> | ||
<UserButton> | ||
<UserButton.MenuItems> | ||
<UserButton.Action label="signOut" /> | ||
<UserButton.Action label="manageAccount" /> | ||
<UserButton.Link | ||
label="Custom link" | ||
href="/profile" | ||
> | ||
<template #labelIcon> | ||
<div>Icon</div> | ||
</template> | ||
</UserButton.Link> | ||
<UserButton.Action | ||
label="Custom action" | ||
@click="isActionClicked = true" | ||
> | ||
<template #labelIcon> | ||
<div>Icon</div> | ||
</template> | ||
</UserButton.Action> | ||
</UserButton.MenuItems> | ||
</UserButton> | ||
<div>Is action clicked: {{ isActionClicked }}</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
import type { InjectionKey } from 'vue'; | ||
|
||
import type { VueClerkInjectionKeyType } from './types'; | ||
import type { AddCustomMenuItemParams, VueClerkInjectionKeyType } from './types'; | ||
|
||
export const ClerkInjectionKey = Symbol('clerk') as InjectionKey<VueClerkInjectionKeyType>; | ||
|
||
export const UserButtonInjectionKey = Symbol('UserButton') as InjectionKey<{ | ||
addCustomMenuItem(params: AddCustomMenuItemParams): void; | ||
}>; | ||
|
||
export const UserButtonMenuItemsInjectionKey = Symbol('UserButton.MenuItems') as InjectionKey<{ | ||
addCustomMenuItem(params: AddCustomMenuItemParams): void; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
packages/vue/src/utils/__tests__/useCustomElementPortal.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { h, Teleport } from 'vue'; | ||
|
||
import { useCustomElementPortal } from '../useCustomElementPortal'; | ||
|
||
describe('useCustomElementPortal', () => { | ||
it('should return empty array when no element is mounted', () => { | ||
const { portals } = useCustomElementPortal(); | ||
expect(portals.value).toEqual([]); | ||
}); | ||
|
||
it('should add/remove element to portal list', () => { | ||
const { mount, unmount, portals } = useCustomElementPortal(); | ||
|
||
const el = document.createElement('div'); | ||
el.id = 'test-portal'; | ||
const slot = () => [h('div', 'Test Content')]; | ||
|
||
mount(el, slot); | ||
|
||
expect(portals.value).toHaveLength(1); | ||
|
||
expect(portals.value[0].type).toBe(Teleport); | ||
expect(portals.value[0].props!.to).toBe(el); | ||
|
||
unmount(el); | ||
|
||
expect(portals.value).toHaveLength(0); | ||
}); | ||
}); |
Oops, something went wrong.