-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve dashboard with sidebar layout (#23)
- Loading branch information
Showing
8 changed files
with
223 additions
and
70 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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<script lang="ts"> | ||
import type { Approver } from "$lib/types" | ||
import { approver } from "$lib/store" | ||
import BasicModal from "$lib/components/modals/basic.svelte" | ||
import InputField from "$lib/components/inputs/field.svelte" | ||
import BasicButton from "$lib/components/buttons/basic.svelte" | ||
import { SidePanelOpenFilled, UserAvatarFilled } from "carbon-icons-svelte" | ||
export let openSidebar: () => void | ||
let showApproverModal = !$approver | ||
let approverName = $approver ? $approver.name : "" | ||
let approverEmail = $approver ? $approver.email : "" | ||
function saveProfile(name: string, email: string) { | ||
if (!name || !email) { | ||
return | ||
} | ||
let profile: Approver = { | ||
name: name, | ||
email: email | ||
} | ||
approver.set(profile) | ||
window.localStorage.setItem("approver", JSON.stringify($approver)) | ||
showApproverModal = false | ||
} | ||
</script> | ||
|
||
<header class="header space-x-4"> | ||
<button class="control-button" on:click={openSidebar}> | ||
<SidePanelOpenFilled size={24} /> | ||
</button> | ||
<button | ||
class="control-button" | ||
on:click={() => { | ||
showApproverModal = true | ||
}} | ||
> | ||
<UserAvatarFilled size={24} /> | ||
</button> | ||
</header> | ||
|
||
<BasicModal bind:show={showApproverModal}> | ||
<div class="flex flex-col space-y-6"> | ||
<div class="flex flex-col space-y-3"> | ||
<h3>Approver Profile</h3> | ||
<small> | ||
This information adds more context to the approval response. | ||
</small> | ||
</div> | ||
<div class="flex flex-col space-y-3"> | ||
<InputField | ||
id="name" | ||
label="Full Name" | ||
placeholder="Justin Case" | ||
bind:value={approverName} | ||
/> | ||
<InputField | ||
id="email" | ||
label="Email Address" | ||
placeholder="[email protected]" | ||
bind:value={approverEmail} | ||
/> | ||
</div> | ||
<BasicButton | ||
text="Save Profile" | ||
action={() => saveProfile(approverName, approverEmail)} | ||
/> | ||
</div> | ||
</BasicModal> | ||
|
||
<style lang="postcss"> | ||
.header { | ||
@apply flex items-center justify-between p-4 bg-gray-50; | ||
@apply absolute top-0 left-0 w-full z-[4]; | ||
height: 80px; | ||
} | ||
</style> |
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,93 @@ | ||
<script lang="ts"> | ||
import type { ComponentType } from "svelte" | ||
import { fade, slide } from "svelte/transition" | ||
import Wordmark from "$lib/components/utils/wordmark.svelte" | ||
import { SidePanelCloseFilled, Home, LogoGithub } from "carbon-icons-svelte" | ||
export let open: boolean = true | ||
export let close: () => void | ||
type Navigation = { | ||
icon: ComponentType | ||
label: string | ||
route: string | ||
} | ||
const navigation: Navigation[] = [ | ||
{ | ||
icon: Home, | ||
label: "Home", | ||
route: "/" | ||
}, | ||
{ | ||
icon: LogoGithub, | ||
label: "Repository", | ||
route: "https://github.com/phantasmlabs/phantasm" | ||
} | ||
] | ||
</script> | ||
|
||
{#if open} | ||
<div | ||
class="overlay" | ||
on:click={close} | ||
role="none" | ||
transition:fade={{ duration: 100 }} | ||
/> | ||
<nav class="sidebar" transition:slide={{ axis: "x", duration: 250 }}> | ||
<div class="control-section space-x-4"> | ||
<Wordmark size="sm" /> | ||
<button class="control-button" on:click={close}> | ||
<SidePanelCloseFilled size={24} /> | ||
</button> | ||
</div> | ||
<div class="flex flex-col p-4 space-y-1"> | ||
{#each navigation as nav} | ||
<a | ||
href={nav.route} | ||
class="navigation-link space-x-3" | ||
target={nav.route.startsWith("http") ? "_blank" : null} | ||
> | ||
<svelte:component this={nav.icon} size={20} class="flex-none" /> | ||
<span>{nav.label}</span> | ||
</a> | ||
{/each} | ||
</div> | ||
</nav> | ||
{/if} | ||
|
||
<style lang="postcss"> | ||
.sidebar { | ||
@apply flex flex-col flex-none fixed top-0 left-0; | ||
@apply bg-white h-dvh z-[6]; | ||
width: 320px; | ||
} | ||
.overlay { | ||
@apply fixed top-0 left-0 w-dvw h-dvh; | ||
@apply bg-black bg-opacity-50 z-[5]; | ||
} | ||
.control-section { | ||
@apply flex items-center justify-between p-4; | ||
height: 80px; | ||
} | ||
.navigation-link { | ||
@apply flex items-center p-2 rounded; | ||
} | ||
.navigation-link:hover { | ||
@apply bg-gray-100; | ||
} | ||
@screen lg { | ||
.sidebar { | ||
@apply static; | ||
} | ||
.overlay { | ||
@apply hidden; | ||
} | ||
} | ||
</style> |
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 |
---|---|---|
|
@@ -8,17 +8,15 @@ | |
import { flip } from "svelte/animate" | ||
import { onMount } from "svelte" | ||
import { connections, alerts, approver } from "$lib/store" | ||
import type { Approver } from "$lib/types" | ||
import { fly } from "svelte/transition" | ||
import Alert from "$lib/components/cards/alert.svelte" | ||
import BasicModal from "$lib/components/modals/basic.svelte" | ||
import InputField from "$lib/components/inputs/field.svelte" | ||
import BasicButton from "$lib/components/buttons/basic.svelte" | ||
import Sidebar from "$lib/components/navs/sidebar.svelte" | ||
import Header from "$lib/components/navs/header.svelte" | ||
const animationDuration = 200 | ||
let hydrated = false | ||
let showApproverModal = false | ||
let approverName = "" | ||
let approverEmail = "" | ||
let showSidebar = true | ||
onMount(() => { | ||
let storedConnections = window.localStorage.getItem("connections") | ||
|
@@ -31,33 +29,44 @@ | |
approver.set(JSON.parse(storedApprover)) | ||
} | ||
showApproverModal = !$approver | ||
hydrated = true | ||
}) | ||
function removeAlert(id: string) { | ||
alerts.update((alerts) => alerts.filter((alert) => alert.id !== id)) | ||
} | ||
function saveProfile(name: string, email: string) { | ||
if (!name || !email) { | ||
return | ||
} | ||
let profile: Approver = { | ||
name: name, | ||
email: email | ||
} | ||
approver.set(profile) | ||
window.localStorage.setItem("approver", JSON.stringify($approver)) | ||
showApproverModal = false | ||
} | ||
</script> | ||
|
||
{#if hydrated} | ||
<div class="flex bg-gray-100"> | ||
<Sidebar | ||
open={showSidebar} | ||
close={() => { | ||
showSidebar = false | ||
}} | ||
/> | ||
<div class="relative w-full"> | ||
<Header | ||
openSidebar={() => { | ||
showSidebar = true | ||
}} | ||
/> | ||
<main class="h-dvh overflow-y-auto"> | ||
<!-- This pads the layout in place of the header. --> | ||
<div class="h-[80px]" /> | ||
<slot /> | ||
</main> | ||
</div> | ||
</div> | ||
{/if} | ||
|
||
<div class="fixed bottom-0 right-0 space-y-3 p-6 w-full md:w-[480px]"> | ||
{#each $alerts as alert (alert.id)} | ||
<div animate:flip={{ duration: 200 }}> | ||
<div | ||
animate:flip={{ duration: animationDuration }} | ||
in:fly={{ x: -100, duration: animationDuration }} | ||
out:fly={{ x: 300, duration: animationDuration }} | ||
> | ||
<Alert | ||
{alert} | ||
remove={() => { | ||
|
@@ -67,36 +76,3 @@ | |
</div> | ||
{/each} | ||
</div> | ||
|
||
{#if hydrated} | ||
<slot /> | ||
|
||
<BasicModal bind:show={showApproverModal}> | ||
<div class="flex flex-col space-y-6"> | ||
<div class="flex flex-col space-y-3"> | ||
<h3>Approver Profile</h3> | ||
<small> | ||
This information adds more context to the approval response. | ||
</small> | ||
</div> | ||
<div class="flex flex-col space-y-3"> | ||
<InputField | ||
id="name" | ||
label="Full Name" | ||
placeholder="Justin Case" | ||
bind:value={approverName} | ||
/> | ||
<InputField | ||
id="email" | ||
label="Email Address" | ||
placeholder="[email protected]" | ||
bind:value={approverEmail} | ||
/> | ||
</div> | ||
<BasicButton | ||
text="Save Profile" | ||
action={() => saveProfile(approverName, approverEmail)} | ||
/> | ||
</div> | ||
</BasicModal> | ||
{/if} |
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