budibase/packages/standard-components/src/Navigation.svelte

90 lines
1.8 KiB
Svelte
Raw Normal View History

2020-04-23 14:32:36 +02:00
<script>
export let onLoad
export let logoUrl
export let _bb
2020-10-14 18:06:02 +02:00
export let title
2020-04-23 14:32:36 +02:00
let itemContainer
let hasLoaded
$: {
if (itemContainer) {
_bb.attachChildren(itemContainer)
if (!hasLoaded) {
2020-09-10 22:11:05 +02:00
_bb.call("onLoad")
2020-04-23 14:32:36 +02:00
hasLoaded = true
}
}
}
2020-10-14 21:12:41 +02:00
const logOut = () => {
// TODO: not the best way to clear cookie, try to find better way
const appId = location.pathname.split("/")[1]
if (appId) {
for (let environment of ["local", "cloud"]) {
document.cookie = `budibase:${appId}:${environment}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`
}
}
location.href = `/${appId}`
2020-10-14 21:12:41 +02:00
}
2020-04-23 14:32:36 +02:00
</script>
2020-10-14 18:06:02 +02:00
<div class="nav">
<div class="nav__top">
<a href="/">
{#if logoUrl}
<img class="logo" alt="logo" src={logoUrl} height="48" />
{/if}
2020-10-14 21:12:41 +02:00
{#if title}<span>{title}</span>{/if}
2020-10-14 18:06:02 +02:00
</a>
<div class="nav__controls">
2020-10-14 21:12:41 +02:00
<div on:click={logOut}>Log out</div>
2020-10-14 18:06:02 +02:00
</div>
</div>
<div class="nav__menu" bind:this={itemContainer} />
</div>
2020-04-23 14:32:36 +02:00
<style>
2020-10-14 18:06:02 +02:00
.nav {
2020-04-23 14:32:36 +02:00
display: flex;
2020-10-14 18:06:02 +02:00
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
2020-04-23 14:32:36 +02:00
}
2020-10-14 18:06:02 +02:00
.nav__top {
2020-04-23 14:32:36 +02:00
display: flex;
2020-10-14 18:06:02 +02:00
flex-direction: row;
justify-content: space-between;
2020-04-23 14:32:36 +02:00
align-items: center;
}
2020-10-14 18:06:02 +02:00
.nav__top img {
margin-right: 16px;
2020-04-23 14:32:36 +02:00
}
2020-10-14 18:06:02 +02:00
.nav__controls {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
gap: 16px;
}
.nav__controls > div:hover {
cursor: pointer;
color: #4285f4;
}
.nav__menu {
2020-04-23 14:32:36 +02:00
display: flex;
2020-10-14 18:06:02 +02:00
margin-top: 40px;
gap: 16px;
flex-direction: row;
justify-content: flex-start;
align-items: center;
2020-04-23 14:32:36 +02:00
}
2020-10-14 18:06:02 +02:00
.nav__menu > a {
font-size: 1.5em;
text-decoration: none;
2020-04-23 14:32:36 +02:00
}
</style>