Skip to content

Commit

Permalink
feat(header): add user menu component
Browse files Browse the repository at this point in the history
Co-authored-by: Kai Henseler <[email protected]>
Signed-off-by: Kai Henseler <[email protected]>
Signed-off-by: Franziska Bath <[email protected]>
  • Loading branch information
fracado and bromiesTM committed Aug 14, 2024
1 parent d746b70 commit 6819f3b
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
153 changes: 153 additions & 0 deletions IONOS/src/components/userMenu/UserMenu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<svelte:options customElement="ionos-user-menu" />

<script lang="ts">
import { onDestroy } from 'svelte';
let showMenu = false;
function toggleMenu() {
showMenu = !showMenu;
}
function handleClickOutside(event) {
const menu = document.querySelector('ionos-user-menu');
if (showMenu && menu && !menu.contains(event.target)) {
console.log('click outside triggered');
showMenu = false;
}
}
document.addEventListener('click', handleClickOutside);
onDestroy(() => {
document.removeEventListener('click', handleClickOutside);
});
</script>

<ionos-icons
user
on:click={toggleMenu}
on:keydown={toggleMenu}
tabindex="0"
role="button"
aria-label="User Menu" />

{#if showMenu}
<div class="menu-container">
<div class="menu-title-cell">
<div class="cell-content">
<div class="user-name">
<slot name="user-name" />
</div>
</div>
</div>
<div class="divider-line" />
<div class="dropdown-menu">
<slot name="options" />
<div class="divider-line" />
<slot name="logout" />
</div>
</div>
{/if}

<style lang="scss">
.menu-container {
width: 280px;
position: absolute;
top: 100%;
right: 0;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);
border-radius: 8px;
background-color: var(--color-main-background);
border: 2px solid var(--color-blue-ionos-b4);
box-sizing: border-box;
overflow: hidden;
font-size: 16px;
color: var(--text-color);
}
.logout-icon {

Check failure on line 69 in IONOS/src/components/userMenu/UserMenu.svelte

View workflow job for this annotation

GitHub Actions / code-quality

Unused CSS selector ".logout-icon"(css-unused-selector)
height: 24px;
}
.label {

Check failure on line 73 in IONOS/src/components/userMenu/UserMenu.svelte

View workflow job for this annotation

GitHub Actions / code-quality

Unused CSS selector ".label"(css-unused-selector)
flex: 1;
position: relative;
line-height: 24px;
font-weight: 500;
}
.icon-and-label {

Check failure on line 80 in IONOS/src/components/userMenu/UserMenu.svelte

View workflow job for this annotation

GitHub Actions / code-quality

Unused CSS selector ".icon-and-label"(css-unused-selector)
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
gap: 8px;
}
.cell-content {
align-self: stretch;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
gap: 8px;
}
.divider-line {
width: 100%;
position: relative;
border-top: 1px solid #bcc8d4;
box-sizing: border-box;
height: 1px;
flex-shrink: 0;
}
.user-name {
align-self: stretch;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: flex-start;
justify-content: flex-start;
}
.option-content {

Check failure on line 116 in IONOS/src/components/userMenu/UserMenu.svelte

View workflow job for this annotation

GitHub Actions / code-quality

Unused CSS selector ".option-content"(css-unused-selector)
padding: 16px;
gap: 16px;
}
.menu-title-cell {
align-self: stretch;
background-color: var(--color-blue-ionos-b1);
display: flex;
padding: 16px;
cursor: default;
}
.dropdown-menu {
flex: 1 1 0;
align-self: stretch;
justify-content: flex-start;
display: flex;
flex-direction: column;
}
a {

Check failure on line 137 in IONOS/src/components/userMenu/UserMenu.svelte

View workflow job for this annotation

GitHub Actions / code-quality

Unused CSS selector "a"(css-unused-selector)
text-decoration: none;
color: var(--text-color);
}
a:hover {

Check failure on line 142 in IONOS/src/components/userMenu/UserMenu.svelte

View workflow job for this annotation

GitHub Actions / code-quality

Unused CSS selector "a:hover"(css-unused-selector)
background-color: var(--color-blue-ionos-b1);
}
a:active {

Check failure on line 146 in IONOS/src/components/userMenu/UserMenu.svelte

View workflow job for this annotation

GitHub Actions / code-quality

Unused CSS selector "a:active"(css-unused-selector)
background-color: var(--color-blue-ionos-b2);
}
ionos-icons {
display: inline-flex;
}
</style>
16 changes: 16 additions & 0 deletions IONOS/src/components/userMenu/UserMenuItem.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<svelte:options customElement="ionos-user-menu-item" />

<script lang="ts">
import Icon from '../Icon.svelte';
export let icon: string = '';
export let label: string = '';
export let link: string = '';
</script>

<a href={link}>
<div class="icon-and-label">
<Icon {...{ [icon]: true }} />
<div class="label">{label}</div>
</div>
</a>
2 changes: 2 additions & 0 deletions IONOS/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@

import './App.svelte';
import './components/Icon.svelte';
import './components/userMenu/UserMenu.svelte';
import './components/userMenu/UserMenuItem.svelte';

0 comments on commit 6819f3b

Please sign in to comment.