Skip to content

Commit

Permalink
feat: implement options / mobile menu, dark mode fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xynydev committed Sep 19, 2024
1 parent 8f97879 commit 1fd02d1
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 127 deletions.
10 changes: 5 additions & 5 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
--muted-foreground: 0 0% 0%;

--popover: 0 0% 100%;
--popover-foreground: 0 0% 3.9%;
--popover-foreground: 0 0% 0%;

--card: 0 0% 100%;
--card-foreground: 0 0% 3.9%;
Expand Down Expand Up @@ -43,11 +43,11 @@
--muted: 0 0% 14.9%;
--muted-foreground: 0 0% 63.9%;

--popover: 0 0% 3.9%;
--popover-foreground: 0 0% 98%;
--popover: 0 0% 9%;
--popover-foreground: 0 0% 100%;

--card: 0 0% 3.9%;
--card-foreground: 0 0% 98%;
--card: 0 0% 0%;
--card-foreground: 0 0% 100%;

--border: 0 0% 14.9%;
--input: 0 0% 14.9%;
Expand Down
51 changes: 51 additions & 0 deletions src/lib/components/custom/MobileMenu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script lang="ts">
import { Button } from '@/components/ui/button';
import * as Sheet from '@/components/ui/sheet';
import RiMenu3Fill from '~icons/ri/menu-3-fill';
import RiUserLine from '~icons/ri/user-line';
import RiMoneyDollarCircleFill from '~icons/ri/money-dollar-circle-fill';
import Options from '@/components/custom/Options.svelte';
</script>

<Sheet.Root>
<Sheet.Trigger asChild let:builder>
<Button
builders={[builder]}
class="lg:hidden"
size="icon"
variant="secondary"
title="Menu"
aria-label="Menu"
>
<RiMenu3Fill class="h-6 w-6 text-black dark:text-white" />
</Button>
</Sheet.Trigger>
<Sheet.Content side="right">
<Sheet.Header class="mb-12">
<Sheet.Title>Options</Sheet.Title>
</Sheet.Header>
<hr class="absolute left-0 top-[4.5rem] w-full" />
<div class="flex flex-col gap-4">
<div class="grid grid-cols-2 gap-4">
Sign in to start curating
<Button href="/account" class="max-w-min justify-self-end px-6">
<RiUserLine class="mr-2 min-h-5 min-w-5 text-white dark:text-black" /> Sign In
</Button>
</div>
<div class="grid grid-cols-2 gap-4">
Donate to keep Mwmbl running
<Button
href="https://opencollective.com/mwmbl"
class="max-w-min justify-self-end px-6"
variant="secondary"
>
<RiMoneyDollarCircleFill class="mr-2 min-h-5 min-w-5 text-black dark:text-white" /> Donate
</Button>
</div>
<hr class="my-2" />
<Options />
</div>
</Sheet.Content>
</Sheet.Root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,51 @@
import { Switch } from '$lib/components/ui/switch';
import { Label } from '$lib/components/ui/label';
import { Skeleton } from '@/components/ui/skeleton';
import { localStoragePreferences } from '@/localStoragePreferences.svelte';
import { localStorageOptions } from '@/localStorageOptions.svelte';
import { Button } from '@/components/ui/button';
import { toggleMode } from 'mode-watcher';
import PhSunFill from '~icons/ph/sun-fill';
import PhMoonFill from '~icons/ph/moon-fill';
let preferences = localStoragePreferences();
let options = localStorageOptions();
let loaded = $state(false);
$effect(() => {
loaded = true;
});
</script>

<main class="flex w-full max-w-2xl flex-col gap-2 self-center px-6">
<h2 class="-mx-2 text-3xl">Preferences</h2>
<hr class="my-2" />
<div class="flex flex-col gap-3">
<div class="flex w-full max-w-2xl flex-row items-center justify-start gap-3">
{#if !loaded}
<Skeleton class="h-[24px] w-[44px] rounded-full bg-input" />
{:else}
<Switch id="newtab-switch" class="switch-fade" bind:checked={preferences.openInNewTab} />
<Switch id="newtab-switch" class="switch-fade" bind:checked={options.openInNewTab} />
{/if}
<Label for="newtab-switch">Open results in new tab</Label>
</div>
<div class="flex w-full max-w-2xl flex-row items-center justify-start gap-3">
<Button
on:click={toggleMode}
variant="outline"
size="icon"
variant="secondary"
class="relative"
id="dark-toggle"
title="Toggle theme"
aria-label="Toggle theme"
>
<PhSunFill
class="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"
class="absolute left-3.5 top-[0.66rem] h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"
/>
<PhMoonFill
class="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"
class="absolute left-3.5 top-[0.66rem] h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"
/>
<span class="ml-6 hidden dark:inline">Dark</span>
<span class="ml-6 inline dark:hidden">Light</span>
</Button>
<Label for="dark-toggle">Switch between dark / light mode</Label>
<Label for="dark-toggle">Switch theme</Label>
</div>
</main>
</div>

<style>
@keyframes switch-fade {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/custom/Search.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
type="search"
name="q"
placeholder="Search with Mwmbl..."
class={'text-l2 h-12 rounded-2xl border-none bg-card p-6 text-lg text-black ' +
class={'text-l2 h-12 rounded-2xl border-none bg-card p-6 text-lg ' +
(completionsExist ? ' rounded-b-none ' : '')}
bind:inputEl={input}
bind:value={query}
Expand Down
10 changes: 3 additions & 7 deletions src/lib/components/custom/SearchResult.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
};
} = $props();
import { localStoragePreferences } from '@/localStoragePreferences.svelte';
let preferences = localStoragePreferences();
import { localStorageOptions } from '@/localStorageOptions.svelte';
let options = localStorageOptions();
</script>

<a
href={result.url}
class="group max-w-full"
target={preferences.openInNewTab ? '_blank' : '_self'}
>
<a href={result.url} class="group max-w-full" target={options.openInNewTab ? '_blank' : '_self'}>
<Card.Root class="flex w-full flex-col gap-2 p-4">
<div class="leading-snug group-hover:underline">
{#each result.url
Expand Down
17 changes: 17 additions & 0 deletions src/lib/components/ui/popover/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Popover as PopoverPrimitive } from "bits-ui";
import Content from "./popover-content.svelte";
const Root = PopoverPrimitive.Root;
const Trigger = PopoverPrimitive.Trigger;
const Close = PopoverPrimitive.Close;

export {
Root,
Content,
Trigger,
Close,
//
Root as Popover,
Content as PopoverContent,
Trigger as PopoverTrigger,
Close as PopoverClose,
};
22 changes: 22 additions & 0 deletions src/lib/components/ui/popover/popover-content.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script lang="ts">
import { Popover as PopoverPrimitive } from 'bits-ui';
import { cn, flyAndScale } from '$lib/utils.js';
type $$Props = PopoverPrimitive.ContentProps;
let className: $$Props['class'] = undefined;
export let transition: $$Props['transition'] = flyAndScale;
export let transitionConfig: $$Props['transitionConfig'] = undefined;
export { className as class };
</script>

<PopoverPrimitive.Content
{transition}
{transitionConfig}
class={cn(
'z-50 w-96 rounded-2xl bg-popover p-4 text-popover-foreground shadow-2xl outline-none',
className
)}
{...$$restProps}
>
<slot />
</PopoverPrimitive.Content>
4 changes: 2 additions & 2 deletions src/lib/components/ui/sheet/sheet-content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
>
<slot />
<SheetPrimitive.Close
class="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary"
class="absolute right-6 top-4 h-10 w-10 rounded-2xl bg-secondary ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none"
>
<X class="h-4 w-4" />
<X class="absolute left-2 top-2 h-6 w-6" />
<span class="sr-only">Close</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
Expand Down
24 changes: 24 additions & 0 deletions src/lib/localStorageOptions.svelte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { browser } from '$app/environment';

type optionObject = {
openInNewTab: boolean | undefined;
};

const defaults: optionObject = {
openInNewTab: false
};

export function localStorageOptions(): optionObject {
let options: optionObject = $state(defaults);

if (browser) {
const value = window.localStorage.getItem('options');
if (value) options = JSON.parse(value);
}

$effect(() => {
window.localStorage.setItem('options', JSON.stringify(options));
});

return options;
}
24 changes: 0 additions & 24 deletions src/lib/localStoragePreferences.svelte.ts

This file was deleted.

40 changes: 5 additions & 35 deletions src/routes/(nosearch)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,25 @@
import RiMenu3Fill from '~icons/ri/menu-3-fill';
import RiSettings4Fill from '~icons/ri/settings-4-fill';
import RiUserLine from '~icons/ri/user-line';
import MobileMenu from '@/components/custom/MobileMenu.svelte';
</script>

<header
class="flex h-16 w-full max-w-[80rem] flex-row items-center gap-2 self-center px-5 pb-8 pt-10 sm:gap-6 lg:px-8"
>
<a href="/" class="col-start-1 mr-auto flex flex-row items-center gap-4">
<img src="/logo.svg" alt="mwmbl" class="h-12" />
<img src="/mwmbl-text.svg" alt="" class="h-6" />
<img src="/mwmbl-text.svg" alt="" class="h-6 dark:invert" />
</a>
<div class="hidden md:contents">
<Button variant="link" href="https://opencollective.com/mwmbl" class="px-2">Donate</Button>
<Button href="/account" class="max-lg:hidden">
<Button href="/account">
<RiUserLine class="mr-2 min-h-5 min-w-5 text-white dark:text-black" /> Sign In
</Button>
</div>
<div class="contents md:hidden">
<Sheet.Root>
<Sheet.Trigger asChild let:builder>
<Button
builders={[builder]}
class="lg:hidden"
size="icon"
variant="secondary"
title="Menu"
aria-label="Menu"
>
<RiMenu3Fill class="min-h-6 min-w-6 text-black dark:text-white" />
</Button>
</Sheet.Trigger>
<Sheet.Content side="right">
<Sheet.Header>
<Sheet.Title>Mwmbl Menu</Sheet.Title>
</Sheet.Header>
<ol class="flex flex-col items-start">
<Button variant="link" href="/" class="px-2">Home</Button>
<Button variant="link" href="https://opencollective.com/mwmbl" class="px-2">
Donate
</Button>
<Button variant="outline" href="/preferences" class="mb-3 px-2">
<RiSettings4Fill class="mr-2 min-h-6 min-w-6 text-black dark:text-white" />
Preferences
</Button>
<Button variant="outline" href="/account" class="px-2">
<RiUserLine class="mr-2 min-h-6 min-w-6 text-black dark:text-white" />
Account
</Button>
</ol>
</Sheet.Content>
</Sheet.Root>
<MobileMenu />
</div>
</header>

Expand Down
Loading

0 comments on commit 1fd02d1

Please sign in to comment.