summaryrefslogtreecommitdiffstats
path: root/apps/web-shared/src/components/user-menu.svelte
blob: c0195f4666961da7d90bee134d2c94725c6c6125 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script>
	import {onMount} from "svelte";
	import {Menu, MenuItem, MenuItemSeparator} from "./menu";

	let userMenuTrigger;
	let showUserMenu = false;
	
	export let avatar = "";
	export let name;
	export let secondary = "";
	let userMenuId;
	
	onMount(() => {
		userMenuTrigger = document.getElementById("open-user-menu");
	});
</script>

<button class="reset user-menu-control"
        id="open-user-menu"
        aria-controls="{userMenuId}"
        on:click={() => showUserMenu = true}>
    {#if avatar}
        <figure class="user-menu-control__img-wrapper radius-50%">
            <img class="user-menu-control__img"
                 src="{avatar}"
                 alt="User picture">
        </figure>
    {/if}

    <div class="margin-x-xs user-menu__meta">
        <p class="user-menu__meta-title text-sm line-height-1 padding-y-xxxxs font-semibold color-contrast-higher text-truncate">{name}</p>
        {#if secondary}
            <p class="text-xs color-contrast-medium line-height-1 padding-bottom-xxxxs">{secondary}</p>
        {/if}
    </div>

    <svg class="icon icon--xxs"
         aria-hidden="true"
         viewBox="0 0 12 12">
        <polyline points="1 4 6 9 11 4"
                  fill="none"
                  stroke="currentColor"
                  stroke-linecap="round"
                  stroke-linejoin="round"
                  stroke-width="2"/>
    </svg>
</button>

<Menu trigger={userMenuTrigger}
      bind:id={userMenuId}
      bind:show="{showUserMenu}">
    <div slot="options">
        <MenuItem>
            <svg class="icon menu__icon"
                 aria-hidden="true"
                 viewBox="0 0 16 16">
                <circle cx="8"
                        cy="3.5"
                        r="3.5"/>
                <path d="M14.747,14.15a6.995,6.995,0,0,0-13.494,0A1.428,1.428,0,0,0,1.5,15.4a1.531,1.531,0,0,0,1.209.6H13.288a1.531,1.531,0,0,0,1.209-.6A1.428,1.428,0,0,0,14.747,14.15Z"/>
            </svg>
            <span>Profile</span>

        </MenuItem>

        <MenuItem>
            <svg class="icon menu__icon"
                 aria-hidden="true"
                 viewBox="0 0 16 16">
                <g fill="currentColor">
                    <path d="M15.135,6.784c-1.303-0.326-1.921-1.818-1.23-2.969c0.322-0.536,0.225-0.998-0.094-1.316l-0.31-0.31 c-0.318-0.318-0.78-0.415-1.316-0.094c-1.152,0.691-2.644,0.073-2.969-1.23C9.065,0.258,8.669,0,8.219,0H7.781 c-0.45,0-0.845,0.258-0.997,0.865c-0.326,1.303-1.818,1.921-2.969,1.23C3.279,1.773,2.816,1.87,2.498,2.188l-0.31,0.31 C1.87,2.816,1.773,3.279,2.095,3.815c0.691,1.152,0.073,2.644-1.23,2.969C0.26,6.935,0,7.33,0,7.781v0.438 c0,0.45,0.258,0.845,0.865,0.997c1.303,0.326,1.921,1.818,1.23,2.969c-0.322,0.536-0.225,0.998,0.094,1.316l0.31,0.31 c0.319,0.319,0.782,0.415,1.316,0.094c1.152-0.691,2.644-0.073,2.969,1.23C6.935,15.742,7.331,16,7.781,16h0.438 c0.45,0,0.845-0.258,0.997-0.865c0.326-1.303,1.818-1.921,2.969-1.23c0.535,0.321,0.997,0.225,1.316-0.094l0.31-0.31 c0.318-0.318,0.415-0.78,0.094-1.316c-0.691-1.152-0.073-2.644,1.23-2.969C15.742,9.065,16,8.669,16,8.219V7.781 C16,7.33,15.74,6.935,15.135,6.784z M8,11c-1.657,0-3-1.343-3-3s1.343-3,3-3s3,1.343,3,3S9.657,11,8,11z"></path>
                </g>
            </svg>
            <span>Settings</span>
        </MenuItem>

        <MenuItem>
            <svg class="icon menu__icon"
                 aria-hidden="true"
                 viewBox="0 0 16 16">
                <circle cx="10.5"
                        cy="2.5"
                        r="2.5"/>
                <circle cx="5.5"
                        cy="6.5"
                        r="2.5"/>
                <path d="M15.826,10.124A5.455,5.455,0,0,0,9.46,6.107,3.932,3.932,0,0,1,9.5,6.5,3.97,3.97,0,0,1,8.452,9.176,6.963,6.963,0,0,1,11.539,12h2.829a1.5,1.5,0,0,0,1.458-1.876Z"/>
                <path d="M10.826,14.124a5.5,5.5,0,0,0-10.652,0A1.5,1.5,0,0,0,1.632,16H9.368a1.5,1.5,0,0,0,1.458-1.876Z"/>
            </svg>
            <span>Team</span>
        </MenuItem>

        <MenuItemSeparator/>

        <MenuItem danger="true" on:click={() => logout_user()}>
            Logout
        </MenuItem>
    </div>
</Menu>