45 lines
1.2 KiB
Text
45 lines
1.2 KiB
Text
package components
|
|
|
|
import (
|
|
"github.com/logto-io/go/core"
|
|
"unicode"
|
|
)
|
|
|
|
templ User(claims core.IdTokenClaims) {
|
|
<div
|
|
x-data="{
|
|
open: false,
|
|
toggle() {
|
|
if (this.open) return this.close();
|
|
this.open = true;
|
|
},
|
|
close(focusAfter) {
|
|
if (! this.open) return;
|
|
this.open = false;
|
|
}
|
|
}"
|
|
class="relative"
|
|
>
|
|
<button x-on:click="toggle()" class="avatar" type="button">
|
|
<div class="w-10 h-10 rounded-xl bg-primary relative opacity-80 hover:opacity-100 transition-opacity">
|
|
if claims.Picture == "" {
|
|
<span class="font-xl text-primary-content absolute top-1/2 left-1/2 -translate-y-1/2 -translate-x-1/2">{ string(unicode.ToUpper(rune(claims.Name[0]))) }</span>
|
|
} else {
|
|
<img src={ claims.Picture }/>
|
|
}
|
|
</div>
|
|
</button>
|
|
<ul
|
|
x-show="open"
|
|
x-transition.origin.top.right
|
|
x-on:click.outside="close($refs.button)"
|
|
style="display: none;"
|
|
class="z-50 absolute right-0 mt-2 menu bg-base-200 rounded-box"
|
|
>
|
|
<li class="menu-title whitespace-nowrap">{ claims.Name }</li>
|
|
<li>
|
|
<a href="/sign-out"><span class="icon-[bi--box-arrow-left]"></span> Logout</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
}
|