design: use better credentials tabs layout
This commit is contained in:
9 files changed
+185
-189
No files matched your search
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import TabButton from './switch/TabButton.svelte'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
interface Props {
|
||||
@@ -29,22 +31,14 @@
|
||||
>
|
||||
{#each options as option, index}
|
||||
{@const slctd = selected == option}
|
||||
<button
|
||||
class={[
|
||||
'px-2.5 py-1 rounded-xl text-sm font-medium transition-colors duration-75 relative cursor-pointer',
|
||||
slctd
|
||||
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-90 active:brightness-75'
|
||||
: ' border dark:bg-zinc-900/50 bg-white border-slate-200 dark:border-zinc-800 hover:bg-slate-100 hover:dark:bg-zinc-800 active:bg-slate-200 active:dark:bg-zinc-900',
|
||||
]}
|
||||
onclick={e => {
|
||||
e.preventDefault()
|
||||
selected = option
|
||||
}}
|
||||
disabled={disabled[index] ?? false}
|
||||
<TabButton
|
||||
selected={slctd}
|
||||
onselect={() => (selected = option)}
|
||||
disabled={disabled[index]}
|
||||
type="button"
|
||||
>
|
||||
{optionNames[index] || option}
|
||||
</button>
|
||||
</TabButton>
|
||||
{/each}
|
||||
</div>
|
||||
{@render children?.({ selected })}
|
||||
@@ -0,0 +1,35 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { HTMLButtonAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends HTMLButtonAttributes {
|
||||
selected?: boolean
|
||||
children: Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
selected = false,
|
||||
onselect,
|
||||
disabled,
|
||||
children,
|
||||
href,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={href ? 'a' : 'button'}
|
||||
class={[
|
||||
'px-2.5 py-1 rounded-xl text-sm font-medium transition-colors duration-75 relative cursor-pointer',
|
||||
selected
|
||||
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-90 active:brightness-75'
|
||||
: ' border dark:bg-zinc-900/50 bg-white border-slate-200 dark:border-zinc-800 hover:bg-slate-100 hover:dark:bg-zinc-800 active:bg-slate-200 active:dark:bg-zinc-900',
|
||||
]}
|
||||
onclick={href ? undefined : onselect}
|
||||
{disabled}
|
||||
{href}
|
||||
{...rest}
|
||||
>
|
||||
{@render children?.()}
|
||||
</svelte:element>
|
||||
@@ -1,12 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
interface Props {
|
||||
icon?: IconSource | undefined
|
||||
title: string
|
||||
description?: string | undefined
|
||||
class?: string
|
||||
class?: ClassValue
|
||||
children?: import('svelte').Snippet
|
||||
iconClass?: ClassValue
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -15,6 +17,7 @@
|
||||
description = undefined,
|
||||
class: clazz = '',
|
||||
children,
|
||||
iconClass,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
@@ -24,7 +27,12 @@
|
||||
<div class="flex flex-col gap-2 items-center max-w-sm">
|
||||
{#if icon}
|
||||
<div
|
||||
class="bg-slate-100 dark:bg-zinc-900 p-3 rounded-2xl text-primary-900 dark:text-primary-100"
|
||||
class={[
|
||||
,
|
||||
iconClass
|
||||
? iconClass
|
||||
: 'bg-slate-100 dark:bg-zinc-900 p-3 rounded-2xl text-primary-900 dark:text-primary-100',
|
||||
]}
|
||||
>
|
||||
<Icon src={icon} size="28" solid />
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { invalidateAll } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import TabButton from '$lib/components/input/switch/TabButton.svelte'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
@@ -11,6 +12,7 @@
|
||||
currentRoute?: SvelteURL | undefined
|
||||
buildUrl?: (currentRoute: SvelteURL | undefined, href: string) => string
|
||||
children?: import('svelte').Snippet
|
||||
style?: 'header' | 'subpage'
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -18,6 +20,7 @@
|
||||
currentRoute = undefined,
|
||||
buildUrl = (_, href) => href,
|
||||
children,
|
||||
style = 'header',
|
||||
}: Props = $props()
|
||||
|
||||
function isSelected(url: URL, href?: SvelteURL) {
|
||||
@@ -27,25 +30,34 @@
|
||||
</script>
|
||||
|
||||
<nav
|
||||
class="flex flex-row items-center gap-x-8 gap-y-4 p-1 justify-center sm:justify-start my-2 sm:mt-0 flex-wrap z-20"
|
||||
class={[
|
||||
'flex flex-row items-center justify-center sm:justify-start my-2 sm:mt-0 flex-wrap z-20',
|
||||
style == 'header' ? 'p-1 gap-x-8 gap-y-4' : 'gap-3',
|
||||
]}
|
||||
>
|
||||
{#each routes as route (route.href)}
|
||||
{@const selected = isSelected(
|
||||
page.url,
|
||||
new SvelteURL(`${page.url.origin}${route.href}`),
|
||||
)}
|
||||
<a
|
||||
onclick={() => invalidateAll()}
|
||||
href={buildUrl(currentRoute, route.href)}
|
||||
class={[
|
||||
'rounded-full font-medium transition-colors duration-100 relative z-0 shrink-0 hover:text-slate-900 hover:dark:text-zinc-100',
|
||||
selected
|
||||
? 'text-primary-900 dark:text-primary-100'
|
||||
: 'text-slate-500 dark:text-zinc-500',
|
||||
]}
|
||||
>
|
||||
{route.name}
|
||||
</a>
|
||||
{#if style == 'header'}
|
||||
<a
|
||||
onclick={() => invalidateAll()}
|
||||
href={buildUrl(currentRoute, route.href)}
|
||||
class={[
|
||||
'rounded-full font-medium transition-colors duration-100 relative z-0 shrink-0 hover:text-slate-900 hover:dark:text-zinc-100',
|
||||
selected
|
||||
? 'text-primary-900 dark:text-primary-100'
|
||||
: 'text-slate-500 dark:text-zinc-500',
|
||||
]}
|
||||
>
|
||||
{route.name}
|
||||
</a>
|
||||
{:else}
|
||||
<TabButton href={buildUrl(currentRoute, route.href)} {selected}>
|
||||
{route.name}
|
||||
</TabButton>
|
||||
{/if}
|
||||
{/each}
|
||||
{@render children?.()}
|
||||
</nav>
|
||||
Reference in new issue
Block a user