-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
177 additions
and
2 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,60 @@ | ||
<script lang="ts" context="module"> | ||
type ItemPool = { | ||
name: NavigationTarget; | ||
id: number; | ||
}; | ||
</script> | ||
|
||
<script lang="ts"> | ||
import { navbarEntries } from '$lib/constants/navbar'; | ||
import { dndzone } from 'svelte-dnd-action'; | ||
import NavbarSettingButton from './NavbarSettingButton.svelte'; | ||
import { flip } from 'svelte/animate'; | ||
import type { NavigationTarget } from '$lib/components/layout/navigation/types'; | ||
import { createEventDispatcher } from 'svelte'; | ||
export let items: ItemPool[]; | ||
export let flipDurationMs: number; | ||
export let block = 0; | ||
const dispatch = createEventDispatcher<{ | ||
final: ItemPool[]; | ||
}>(); | ||
</script> | ||
|
||
<section | ||
class=" | ||
flex flex-col gap-3 | ||
rounded px-4 py-3 outline outline-1 outline-zinc-300 | ||
dark:outline-zinc-600 | ||
" | ||
use:dndzone={{ | ||
items, | ||
flipDurationMs, | ||
dropTargetStyle: {}, | ||
dragDisabled: items.length <= block | ||
}} | ||
on:consider={({ detail }) => { | ||
items = detail.items; | ||
}} | ||
on:finalize={({ detail }) => { | ||
items = detail.items; | ||
dispatch('final', items); | ||
}} | ||
> | ||
<div> | ||
<slot name="pre-content" /> | ||
</div> | ||
|
||
<div class="flex min-h-20 flex-wrap items-center justify-center gap-2"> | ||
{#each items as item (item.id)} | ||
{@const obj = navbarEntries[item.name]} | ||
|
||
<span animate:flip={{ duration: flipDurationMs }} class="flex-1"> | ||
<NavbarSettingButton label={obj.text} icon={obj.icon} /> | ||
</span> | ||
{:else} | ||
<slot name="empty" /> | ||
{/each} | ||
</div> | ||
</section> |
52 changes: 52 additions & 0 deletions
52
src/lib/components/settings/navigation/NavbarCustomizor.svelte
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,52 @@ | ||
<script lang="ts" context="module"> | ||
const FLIP_DURATION = 300; | ||
type ItemPool = { | ||
name: NavigationTarget; | ||
id: number; | ||
}; | ||
const ITEM_POOL: ItemPool[] = ( | ||
['homework', 'calendar', 'notes', 'login', 'register', 'launcher'] as const | ||
).map((name, id) => ({ name, id })); | ||
function createItemsFromNames(names: NavigationTarget[]) { | ||
return ITEM_POOL.filter(({ name }) => names.includes(name)); | ||
} | ||
const isSelectedId = (id: number, selected: ItemPool[]) => !!selected.find((x) => x.id === id); | ||
</script> | ||
|
||
<script lang="ts"> | ||
import type { NavigationTarget } from '$lib/components/layout/navigation/types'; | ||
import { svocal } from '$lib/utils/store/svocal'; | ||
import { get } from 'svelte/store'; | ||
import DropArea from './DropArea.svelte'; | ||
import Store from '$lib/components/utils/Store.svelte'; | ||
import { i } from '$lib/i18n/store'; | ||
const selectedSvocal = svocal('settings.nav.entries'); | ||
let selectedPreview = createItemsFromNames(get(selectedSvocal)); | ||
let notSelectedPreview = ITEM_POOL.filter(({ id }) => !isSelectedId(id, selectedPreview)); | ||
</script> | ||
|
||
<div class="flex flex-col gap-2 rounded px-4 py-2"> | ||
<DropArea | ||
block={1} | ||
flipDurationMs={FLIP_DURATION} | ||
bind:items={selectedPreview} | ||
on:final={({ detail }) => { | ||
selectedSvocal.set(detail.map(({ name }) => name)); | ||
}} | ||
> | ||
<h4 slot="pre-content"><Store store={i('settings.general.nav.composer.your')} /></h4> | ||
</DropArea> | ||
|
||
<DropArea flipDurationMs={FLIP_DURATION} bind:items={notSelectedPreview}> | ||
<h4 slot="pre-content"><Store store={i('settings.general.nav.composer.available')} /></h4> | ||
<span class="text-gray-500" slot="empty"> | ||
<Store store={i('settings.general.nav.composer.empty')} /> | ||
</span> | ||
</DropArea> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
src/lib/components/settings/navigation/NavbarSettingButton.svelte
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,22 @@ | ||
<svelte:options accessors /> | ||
|
||
<script lang="ts"> | ||
import Store from '$lib/components/utils/Store.svelte'; | ||
import { Icon } from 'svelte-hero-icons'; | ||
import type { Readable } from 'svelte/store'; | ||
import type { IconSource } from 'svelte-hero-icons'; | ||
export let label: Readable<string>; | ||
export let icon: IconSource; | ||
</script> | ||
|
||
<div | ||
class=" | ||
flex flex-col items-center gap-2 rounded-sm bg-zinc-200 bg-opacity-50 px-2 py-2 shadow outline outline-1 outline-zinc-300 backdrop-blur-md | ||
dark:bg-zinc-700 dark:bg-opacity-50 dark:outline-zinc-600 | ||
" | ||
> | ||
<Icon src={icon} class="h-10 w-10" solid /> | ||
|
||
<Store store={label} /> | ||
</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
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,11 @@ | ||
import { browser } from '$app/environment'; | ||
|
||
/** | ||
* This function enables or disables scrolling on the entire document. | ||
* @param isEnabled - A boolean value indicating whether scrolling should be enabled (true) or disabled (false). | ||
*/ | ||
export function enableScrolling(isEnabled: boolean) { | ||
if (!browser) return false; | ||
document.body.style.overflow = isEnabled ? 'initial' : 'hidden'; | ||
return true; | ||
} |
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,6 @@ | ||
import type { NavigationTarget } from "$lib/components/layout/navigation/types"; | ||
import type { IconSource } from "svelte-hero-icons" | ||
|
||
export const iconMap: Record<NavigationTarget, IconSource> = { | ||
login: | ||
} |
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