-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #150 Fixes #153 --------- Co-authored-by: Anton Lilleby <[email protected]>
- Loading branch information
Showing
13 changed files
with
248 additions
and
64 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,71 @@ | ||
<!-- | ||
@component | ||
[Go to docs](https://flowbite-svelte.com/) | ||
--> | ||
|
||
<script lang="ts"> | ||
import { twMerge } from "tailwind-merge"; | ||
import type { HTMLButtonAttributes } from "svelte/elements"; | ||
import { Button } from "flowbite-svelte"; | ||
import { MoonIcon, SunIcon } from "svelte-feather-icons"; | ||
interface $$Props extends HTMLButtonAttributes { | ||
btnClass?: string; | ||
size?: "sm" | "md" | "lg"; | ||
ariaLabel?: string; | ||
value?: string; | ||
} | ||
export let btnClass: $$Props["btnClass"] = ""; | ||
export let size: NonNullable<$$Props["size"]> = "md"; | ||
export let ariaLabel: $$Props["ariaLabel"] = "Dark mode"; | ||
export let value: $$Props["value"] = ""; | ||
const sizes = { | ||
sm: "w-4 h-4", | ||
md: "w-5 h-5", | ||
lg: "w-6 h-6", | ||
}; | ||
const toggleTheme = (ev: MouseEvent) => { | ||
const target = ev.target as HTMLElement; | ||
const isDark = target.ownerDocument.documentElement.classList.toggle("dark"); | ||
if (target.ownerDocument === document) | ||
// we are NOT in the iFrame | ||
localStorage.setItem("color-theme", isDark ? "dark" : "light"); | ||
}; | ||
</script> | ||
|
||
<svelte:head> | ||
<script> | ||
if ("color-theme" in localStorage) { | ||
// explicit preference - overrides author's choice | ||
localStorage.getItem("color-theme") === "dark" | ||
? window.document.documentElement.classList.add("dark") | ||
: window.document.documentElement.classList.remove("dark"); | ||
} else { | ||
// browser preference - does not overrides | ||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) | ||
window.document.documentElement.classList.add("dark"); | ||
} | ||
</script> | ||
</svelte:head> | ||
|
||
<Button | ||
on:click={toggleTheme} | ||
aria-label={ariaLabel} | ||
role="button" | ||
{...$$restProps} | ||
class={twMerge(btnClass, $$props.class)} | ||
color="alternative" | ||
> | ||
{#if value} | ||
<span class="mr-1.5">{value}</span> | ||
{/if} | ||
<span class="hidden dark:block"> | ||
<SunIcon class={sizes[size]} strokeWidth={1.5} /> | ||
</span> | ||
<span class="block dark:hidden"> | ||
<MoonIcon class={sizes[size]} strokeWidth={1.5} /> | ||
</span> | ||
</Button> |
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,32 @@ | ||
<script> | ||
import { PUBLIC_SANITY_STUDIO_URL } from "$env/static/public"; | ||
import { signIn, signOut } from "@auth/sveltekit/client"; | ||
import SignedOutMenu from "./SignedOutMenu.svelte"; | ||
import SignedInDesktopMenu from "./SignedInDesktopMenu.svelte"; | ||
import SignedInMobileMenu from "./SignedInMobileMenu.svelte"; | ||
export let auth; | ||
let isSigningOut = false; | ||
let isSigningIn = false; | ||
const openSanityStudio = () => { | ||
window.open(PUBLIC_SANITY_STUDIO_URL, "_blank"); | ||
}; | ||
const signOutHandler = async () => { | ||
isSigningOut = true; | ||
await signOut({ callbackUrl: "/" }); | ||
}; | ||
const signInHandler = async () => { | ||
isSigningIn = true; | ||
await signIn("google"); | ||
}; | ||
</script> | ||
|
||
{#if auth} | ||
<SignedInDesktopMenu {auth} {isSigningOut} {openSanityStudio} {signOutHandler} /> | ||
<SignedInMobileMenu {auth} {isSigningOut} {openSanityStudio} {signOutHandler} /> | ||
{:else} | ||
<SignedOutMenu {isSigningIn} {signInHandler} /> | ||
{/if} |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
<script> | ||
import { Button } from "flowbite-svelte"; | ||
import { LogOutIcon, PlusIcon } from "svelte-feather-icons"; | ||
import DarkMode from "./DarkMode.svelte"; | ||
export let auth; | ||
export let isSigningOut; | ||
export let openSanityStudio; | ||
export let signOutHandler; | ||
</script> | ||
|
||
<div class="hidden flex-row items-center gap-3 md:flex"> | ||
<span class="text-sm font-semibold">{auth.user.name}</span> | ||
<img class="h-8 rounded-2xl" alt="Profilbilde" src={auth.user.image} /> | ||
|
||
<Button color="dark" class="h-9" pill on:click={openSanityStudio}> | ||
<span class="mr-1.5">Opprett</span> | ||
<PlusIcon strokeWidth={1.5} class="w-[16px]" /> | ||
</Button> | ||
|
||
<Button | ||
color="alternative" | ||
class="h-9 border-[#999]" | ||
pill | ||
on:click={signOutHandler} | ||
disabled={isSigningOut} | ||
> | ||
<span class="mr-1.5">Logg ut</span> | ||
<LogOutIcon strokeWidth={1.5} class="w-[16px]" /> | ||
</Button> | ||
<DarkMode size="sm" btnClass="h-9 border-[#999] rounded-2xl p-2.5" /> | ||
</div> |
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,48 @@ | ||
<script> | ||
import { Button } from "flowbite-svelte"; | ||
import { LogOutIcon, PlusIcon } from "svelte-feather-icons"; | ||
import DarkMode from "./DarkMode.svelte"; | ||
export let auth; | ||
export let openSanityStudio; | ||
export let isSigningOut; | ||
export let signOutHandler; | ||
let isMenuOpen = false; | ||
const toggleMenu = () => { | ||
isMenuOpen = !isMenuOpen; | ||
}; | ||
</script> | ||
|
||
<div class="flex items-center gap-3 md:hidden"> | ||
<Button color="alternative" class="border-[#CCC] px-2 py-1 text-black" pill on:click={toggleMenu}> | ||
<span class="mr-1.5 max-w-[150px] truncate text-sm font-semibold" title={auth.user.name} | ||
>{auth.user.name}</span | ||
> | ||
<img class="h-8 rounded-2xl" alt="Profilbilde" src={auth.user.image} /> | ||
</Button> | ||
|
||
{#if isMenuOpen} | ||
<div | ||
class="absolute right-4 top-20 flex w-40 flex-col items-center gap-3 rounded-md border bg-white p-4 shadow-lg dark:border-[#4B5563] dark:bg-black" | ||
> | ||
<Button color="dark" class="w-32 px-4 py-2 text-left" pill on:click={openSanityStudio}> | ||
<span class="mr-1.5">Opprett</span> | ||
<PlusIcon strokeWidth={1.5} class="w-[16px]" /> | ||
</Button> | ||
|
||
<Button | ||
color="alternative" | ||
class="h-9 w-32 border-[#999]" | ||
pill | ||
on:click={signOutHandler} | ||
disabled={isSigningOut} | ||
> | ||
<span class="mr-1.5">Logg ut</span> | ||
<LogOutIcon strokeWidth={1.5} class="w-[16px]" /> | ||
</Button> | ||
<DarkMode size="sm" value="Modus" btnClass="h-9 border-[#999] w-32 rounded-2xl" /> | ||
</div> | ||
{/if} | ||
</div> |
Oops, something went wrong.
dec31ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
skjer – ./
capra-web.vercel.app
skjer-capra.vercel.app
skjer-git-main-capra.vercel.app
skjer.liflig.no
skjer.fryde.no
skjer.capraconsulting.no