impr: restructure src/lib
This commit is contained in:
376 files changed
+1000
-1033
No files matched your search
@@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { TextInput, Select, Option } from 'mono-svelte'
|
||||
|
||||
const multipliers = {
|
||||
minute: 60,
|
||||
hour: 60 * 60,
|
||||
day: 60 * 60 * 24,
|
||||
month: 60 * 60 * 24 * 30,
|
||||
year: 60 * 60 * 24 * 365,
|
||||
permanent: -1,
|
||||
}
|
||||
|
||||
type Duration = keyof typeof multipliers
|
||||
|
||||
function calculateValue(number: number, duration: Duration): number {
|
||||
return number * multipliers[duration]
|
||||
}
|
||||
|
||||
interface Props {
|
||||
value: number
|
||||
max?: number
|
||||
min?: number
|
||||
}
|
||||
|
||||
let { value = $bindable(), max, min = 0 }: Props = $props()
|
||||
|
||||
let number = $state<number>(0)
|
||||
let duration = $state<Duration>(value == -1 ? 'permanent' : 'day')
|
||||
|
||||
$effect(() => {
|
||||
value = calculateValue(number, duration)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row items-end gap-2">
|
||||
{#if duration != 'permanent'}
|
||||
<TextInput
|
||||
{min}
|
||||
{max}
|
||||
type="number"
|
||||
label="Number"
|
||||
class="w-24"
|
||||
bind:value={number}
|
||||
></TextInput>
|
||||
{/if}
|
||||
<Select
|
||||
selectClass="h-[38px]"
|
||||
baseClass="flex-1"
|
||||
label={$t('form.time.duration')}
|
||||
bind:value={duration}
|
||||
>
|
||||
<Option value="minute">{$t('form.time.minutes')}</Option>
|
||||
<Option value="hour">{$t('form.time.hours')}</Option>
|
||||
<Option value="day">{$t('form.time.days')}</Option>
|
||||
<Option value="month">{$t('form.time.months')}</Option>
|
||||
<Option value="year">{$t('form.time.years')}</Option>
|
||||
<Option value="permanent">{$t('form.time.permanent')}</Option>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte'
|
||||
import type { HTMLAttributes } from 'svelte/elements'
|
||||
|
||||
let textarea: HTMLTextAreaElement | undefined = $state()
|
||||
|
||||
async function adjustHeight() {
|
||||
await tick()
|
||||
if (textarea) {
|
||||
textarea.style.height = 'auto' // Reset height to auto to calculate new height
|
||||
textarea.style.height = `${textarea.scrollHeight}px` // Set height to the scrollHeight
|
||||
}
|
||||
}
|
||||
interface Props extends HTMLAttributes<HTMLTextAreaElement> {
|
||||
label?: string | undefined
|
||||
value: string
|
||||
required?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let {
|
||||
label = undefined,
|
||||
value = $bindable(),
|
||||
required = false,
|
||||
class: clazz = '',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
$effect(() => {
|
||||
if (value) adjustHeight()
|
||||
})
|
||||
</script>
|
||||
|
||||
<label class="w-full">
|
||||
{#if label}
|
||||
<div class="text-sm font-medium">
|
||||
{label}
|
||||
{#if required}
|
||||
<span class="text-red-600 font-bold">*</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<textarea
|
||||
bind:this={textarea}
|
||||
oninput={() => adjustHeight()}
|
||||
bind:value
|
||||
{required}
|
||||
{...rest}
|
||||
rows={1}
|
||||
class="font-semibold text-2xl focus:outline-hidden w-full bg-transparent resize-none {clazz}"
|
||||
></textarea>
|
||||
</label>
|
||||
@@ -0,0 +1,128 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/app/auth.svelte.js'
|
||||
import ProgressBar from '$lib/ui/info/ProgressBar.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
import { Button, toast } from 'mono-svelte'
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { slide } from 'svelte/transition'
|
||||
|
||||
interface Props {
|
||||
image?: FileList | null
|
||||
preview?: boolean
|
||||
multiple?: boolean
|
||||
onupload?: (urls: string[]) => void
|
||||
}
|
||||
|
||||
let {
|
||||
image = $bindable(null),
|
||||
preview = true,
|
||||
multiple = true,
|
||||
onupload,
|
||||
}: Props = $props()
|
||||
let progress = $state(1)
|
||||
|
||||
let previewURLs = $derived(
|
||||
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined,
|
||||
)
|
||||
|
||||
async function upload() {
|
||||
if (!profile.current?.jwt || image == null) return
|
||||
|
||||
progress = 0
|
||||
|
||||
try {
|
||||
const uploaded = (
|
||||
await Promise.all(
|
||||
Array.from(image).map((i) =>
|
||||
uploadImage(i, profile.current.instance, profile.current.jwt!)
|
||||
.then((uploaded) => {
|
||||
progress += 1 / (image?.length ?? 0)
|
||||
return uploaded
|
||||
})
|
||||
.catch((err) => {
|
||||
toast({ content: errorMessage(err), type: 'error' })
|
||||
return 'Failed to upload'
|
||||
}),
|
||||
),
|
||||
)
|
||||
).filter((i) => i != undefined)
|
||||
|
||||
if (!uploaded) throw new Error('Image upload returned undefined')
|
||||
|
||||
onupload?.(uploaded)
|
||||
progress = 1
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: errorMessage(err),
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
progress = 1
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if progress != 1}
|
||||
<div transition:slide={{ duration: 500, easing: expoOut }} class="w-full">
|
||||
<ProgressBar {progress} />
|
||||
</div>
|
||||
{/if}
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
upload()
|
||||
}}
|
||||
>
|
||||
<label
|
||||
for="image-input"
|
||||
class="p-4 border-2 border-dashed rounded-xl cursor-pointer transition-colors
|
||||
border-slate-300 dark:border-zinc-700 hover:border-primary-900 dark:hover:border-primary-100"
|
||||
>
|
||||
{#if previewURLs}
|
||||
<div
|
||||
class="grid gap-x-2 gap-y-px max-h-64 overflow-auto
|
||||
{multiple ? 'grid-cols-3 grid-rows-2' : 'grid-cols-1 grid-rows-1'}"
|
||||
>
|
||||
{#each previewURLs as file}
|
||||
<img
|
||||
src={file}
|
||||
onload={() => URL.revokeObjectURL(file)}
|
||||
alt={file}
|
||||
class="w-full rounded-md h-full object-cover transition-all
|
||||
border border-slate-200 dark:border-zinc-800 ring-1
|
||||
ring-slate-50 dark:ring-zinc-950 bg-white dark:bg-zinc-950"
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="flex flex-col justify-center w-full items-center gap-2
|
||||
text-slate-600 dark:text-zinc-400"
|
||||
>
|
||||
<Icon src={DocumentPlus} size="32" />
|
||||
<span class="font-medium text-sm">{$t('form.post.selectFile')}</span>
|
||||
</div>
|
||||
{/if}
|
||||
<input
|
||||
{multiple}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
class="hidden"
|
||||
id="image-input"
|
||||
bind:files={image}
|
||||
/>
|
||||
</label>
|
||||
<Button
|
||||
loading={progress != 1}
|
||||
disabled={progress != 1 || image == null}
|
||||
submit
|
||||
color="primary"
|
||||
size="lg"
|
||||
>
|
||||
Upload
|
||||
</Button>
|
||||
</form>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts">
|
||||
import { Button, Modal, TextInput } from 'mono-svelte'
|
||||
import Switch from '../input/Switch.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import ImageAttachForm from './ImageAttachForm.svelte'
|
||||
|
||||
let {
|
||||
open = $bindable(),
|
||||
imageUrl: passedImageUrl = $bindable(),
|
||||
}: { open: boolean; imageUrl?: string } = $props()
|
||||
|
||||
let imageUrl = $derived(passedImageUrl)
|
||||
let customUrl = $state(false)
|
||||
</script>
|
||||
|
||||
<Modal bind:open title={$t('form.post.uploadImage')}>
|
||||
<div class="flex justify-between gap-1 flex-wrap">
|
||||
<Switch
|
||||
options={[false, true]}
|
||||
optionNames={[$t('common.attach'), $t('content.url')]}
|
||||
bind:selected={customUrl}
|
||||
/>
|
||||
|
||||
<Button
|
||||
onclick={() => {
|
||||
passedImageUrl = undefined
|
||||
open = false
|
||||
}}
|
||||
size="xs"
|
||||
rounding="xl"
|
||||
>
|
||||
{$t('common.remove')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#if customUrl}
|
||||
<form
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
if (!imageUrl) throw new Error('missing imageurl')
|
||||
|
||||
if (URL.canParse != undefined) {
|
||||
if (!URL.canParse(imageUrl)) throw new Error('invalid URL')
|
||||
}
|
||||
|
||||
passedImageUrl = imageUrl
|
||||
open = false
|
||||
}}
|
||||
class="contents"
|
||||
>
|
||||
<TextInput
|
||||
label={$t('content.url')}
|
||||
bind:value={imageUrl}
|
||||
pattern="http(s)?:\/\/(.*).(png|jpg|gif|avif|webp|jpeg|jxl|svg|bmp)"
|
||||
/>
|
||||
<Button submit color="primary" size="lg">
|
||||
{$t('form.submit')}
|
||||
</Button>
|
||||
</form>
|
||||
{:else}
|
||||
<ImageAttachForm
|
||||
multiple={false}
|
||||
onupload={(uploaded) => {
|
||||
open = false
|
||||
passedImageUrl = uploaded[0]
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</Modal>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { Label } from 'mono-svelte'
|
||||
import { DocumentPlus, Icon, Plus } from 'svelte-hero-icons'
|
||||
import ImageInputModal from './ImageInputModal.svelte'
|
||||
|
||||
let {
|
||||
imageUrl: passedImageUrl = $bindable(),
|
||||
label,
|
||||
}: {
|
||||
imageUrl?: string
|
||||
label?: string
|
||||
} = $props()
|
||||
|
||||
let imageUrl = $derived(passedImageUrl)
|
||||
|
||||
let open = $state(false)
|
||||
</script>
|
||||
|
||||
<div>
|
||||
<Label>{label}</Label>
|
||||
|
||||
<button
|
||||
class={[
|
||||
'flex flex-col items-center justify-center px-8 py-4 mx-auto w-full rounded-xl',
|
||||
'border border-slate-200 dark:border-zinc-800 border-dashed hover:border-slate-300 hover:dark:border-zinc-700',
|
||||
'cursor-pointer min-h-36 transition-colors bg-white dark:bg-zinc-950 relative',
|
||||
]}
|
||||
type="button"
|
||||
onclick={() => (open = !open)}
|
||||
>
|
||||
{#if imageUrl}
|
||||
<div>
|
||||
<Icon
|
||||
src={Plus}
|
||||
class="text-slate-400 dark:text-zinc-500 absolute top-0 left-0 m-2"
|
||||
size="20"
|
||||
micro
|
||||
/>
|
||||
</div>
|
||||
<img src={imageUrl} alt="" class="rounded-md mx-auto h-full" />
|
||||
{:else}
|
||||
<Icon
|
||||
src={DocumentPlus}
|
||||
class="text-slate-400 dark:text-zinc-500"
|
||||
size="36"
|
||||
solid
|
||||
/>
|
||||
<p class="text-slate-600 dark:text-zinc-400 font-medium">
|
||||
{$t('common.attach')}
|
||||
</p>
|
||||
{/if}
|
||||
<ImageInputModal bind:open bind:imageUrl={passedImageUrl} />
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,65 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { DocumentPlus, Icon } from 'svelte-hero-icons'
|
||||
import { Label, TextInput } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
accept?: string
|
||||
files?: FileList | undefined | null
|
||||
label?: string | undefined
|
||||
url?: string | undefined
|
||||
}
|
||||
|
||||
let {
|
||||
accept = 'image/*',
|
||||
files = $bindable(null),
|
||||
label = undefined,
|
||||
url = undefined,
|
||||
}: Props = $props()
|
||||
|
||||
let dragover = $state(false)
|
||||
|
||||
let previewURL = $derived(files ? URL.createObjectURL(files[0]) : undefined)
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col">
|
||||
<Label text={label} class="mb-1" />
|
||||
<label
|
||||
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-xl
|
||||
border border-slate-200 dark:border-zinc-800 bg-white dark:bg-black
|
||||
cursor-pointer min-h-36 transition-colors {dragover
|
||||
? 'border-sky-500 text-sky-500'
|
||||
: ''}
|
||||
{url != undefined ? 'rounded-b-none' : ''}
|
||||
"
|
||||
ondrop={preventDefault((event) => (files = event.dataTransfer?.files))}
|
||||
ondragover={preventDefault((event) => {
|
||||
if (event.dataTransfer) {
|
||||
event.dataTransfer.dropEffect = 'copy'
|
||||
dragover = true
|
||||
}
|
||||
})}
|
||||
ondragleave={preventDefault(() => (dragover = false))}
|
||||
>
|
||||
{#if files}
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={previewURL}
|
||||
onload={() => {
|
||||
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||
}}
|
||||
class="w-full max-w-sm h-full rounded-lg"
|
||||
/>
|
||||
{:else if url}
|
||||
<img src={url} />
|
||||
{:else}
|
||||
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
||||
<p class="text-sm opacity-50">Attach a file</p>
|
||||
{/if}
|
||||
<input type="file" bind:files {accept} class="hidden" />
|
||||
</label>
|
||||
{#if url != undefined}
|
||||
<TextInput class="rounded-t-none border-t-0 rounded-xl" />
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script lang="ts" module>
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
return new URL(href)
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import type { HTMLAnchorAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends HTMLAnchorAttributes {
|
||||
href: string
|
||||
highlight?: boolean
|
||||
children?: import('svelte').Snippet
|
||||
class?: string
|
||||
icon?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
href,
|
||||
highlight = false,
|
||||
children,
|
||||
class: clazz = '',
|
||||
icon,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<a
|
||||
{...rest}
|
||||
{href}
|
||||
class={[
|
||||
'hover:underline max-w-full inline-flex items-center gap-1',
|
||||
highlight && 'text-blue-600 dark:text-blue-400',
|
||||
clazz,
|
||||
]}
|
||||
>
|
||||
{@render icon?.()}
|
||||
{@render children?.()}
|
||||
</a>
|
||||
@@ -0,0 +1,125 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/ui/generic/Avatar.svelte'
|
||||
import { getClient } from '$lib/api/client.svelte'
|
||||
import type { Community, ListingType } from '$lib/api/types'
|
||||
import { MenuButton, Search } from 'mono-svelte'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { Icon, ServerStack, XCircle } from 'svelte-hero-icons'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
interface Props {
|
||||
type?: 'community' | 'instance'
|
||||
q?: string
|
||||
instance?: string | undefined
|
||||
listing_type?: ListingType
|
||||
showWhenEmpty?: boolean
|
||||
placeholder?: string
|
||||
onselect?: (item: any) => void
|
||||
label?: string
|
||||
}
|
||||
|
||||
let {
|
||||
type = 'community',
|
||||
q = $bindable(''),
|
||||
instance = undefined,
|
||||
listing_type = 'Subscribed',
|
||||
showWhenEmpty = false,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ select: Community | undefined }>()
|
||||
let instances = $derived(
|
||||
type == 'instance' && getClient().getFederatedInstances(),
|
||||
)
|
||||
</script>
|
||||
|
||||
{#if type == 'community'}
|
||||
<Search
|
||||
search={async (q) => {
|
||||
const results = await getClient(instance).search({
|
||||
q: q || ' ',
|
||||
type_: 'Communities',
|
||||
limit: 20,
|
||||
listing_type: listing_type,
|
||||
sort: 'TopAll',
|
||||
})
|
||||
|
||||
return results.communities
|
||||
}}
|
||||
extractName={(c) =>
|
||||
`${c.community.name}@${new URL(c.community.actor_id).hostname}`}
|
||||
bind:query={q}
|
||||
{...rest}
|
||||
>
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton onclick={() => dispatcher('select', undefined)}>
|
||||
<Icon src={XCircle} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet children({ item, select })}
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
<Avatar
|
||||
url={item.community.icon}
|
||||
alt={item.community.title}
|
||||
width={24}
|
||||
/>
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.community.title}</span>
|
||||
<span class="text-xs opacity-80">
|
||||
{new URL(item.community.actor_id).hostname}
|
||||
</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
{:else if type == 'instance'}
|
||||
<Search
|
||||
search={async (q) => {
|
||||
const results = (await instances) || {}
|
||||
|
||||
return q
|
||||
? (results.federated_instances?.linked || []).filter(
|
||||
(i) => i.software === 'lemmy' && i.domain.includes(q),
|
||||
)
|
||||
: []
|
||||
}}
|
||||
extractName={(i) => `${i.domain}`}
|
||||
bind:query={q}
|
||||
{...rest}
|
||||
>
|
||||
{#snippet noresults()}
|
||||
<div class="w-full h-full">
|
||||
{#if q == '' && showWhenEmpty}
|
||||
<MenuButton onclick={() => dispatcher('select', undefined)}>
|
||||
<div class="flex flex-col text-left">
|
||||
<span>None (Start typing to search)</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<span class="mx-auto my-auto">No results.</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/snippet}
|
||||
{#snippet children({ item, select })}
|
||||
<div in:fly|global={{ y: -4, opacity: 0 }}>
|
||||
<MenuButton onclick={() => select(item)}>
|
||||
<Icon src={ServerStack} size="16" mini />
|
||||
<div class="flex flex-col text-left">
|
||||
<span>{item.domain}</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Search>
|
||||
{/if}
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts">
|
||||
import TabButton from './TabButton.svelte'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
interface Props {
|
||||
options: T[]
|
||||
disabled?: boolean[]
|
||||
optionNames?: string[]
|
||||
selected: T
|
||||
children?: import('svelte').Snippet<[{ selected: T }]>
|
||||
onselect?: (item: T) => void
|
||||
}
|
||||
|
||||
let {
|
||||
options,
|
||||
disabled = [],
|
||||
optionNames = [],
|
||||
selected = $bindable(),
|
||||
children,
|
||||
onselect,
|
||||
}: Props = $props()
|
||||
|
||||
let selectedIndex = $state(0)
|
||||
let id = $props.id()
|
||||
|
||||
/* you see id like this to be a super simple
|
||||
|
||||
*/
|
||||
$effect(() => {
|
||||
const newIndex = options.findIndex((i) => i === selected)
|
||||
if (newIndex !== -1) {
|
||||
selectedIndex = newIndex
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
const newSelected = options[selectedIndex]
|
||||
if (newSelected !== undefined && newSelected !== selected) {
|
||||
selected = newSelected
|
||||
onselect?.(newSelected)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<fieldset
|
||||
class="flex items-center gap-1 w-max max-w-full z-0 relative overflow-auto"
|
||||
>
|
||||
{#each options as option, index}
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
bind:group={selectedIndex}
|
||||
value={index}
|
||||
name={id}
|
||||
id="{id}-{option?.toString()}"
|
||||
class="hidden"
|
||||
/>
|
||||
<TabButton
|
||||
selected={selectedIndex == index}
|
||||
disabled={disabled[index]}
|
||||
element="div"
|
||||
>
|
||||
{optionNames[index] || option}
|
||||
</TabButton>
|
||||
</label>
|
||||
{/each}
|
||||
</fieldset>
|
||||
{@render children?.({ selected })}
|
||||
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { HTMLButtonAttributes } from 'svelte/elements'
|
||||
|
||||
const sizes = {
|
||||
sm: 'px-2.5 py-1',
|
||||
md: 'py-1.5 px-3.5',
|
||||
}
|
||||
|
||||
interface Props extends HTMLButtonAttributes {
|
||||
selected?: boolean
|
||||
children: Snippet
|
||||
size?: keyof typeof sizes
|
||||
element?: 'div' | 'a' | 'button'
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
selected = false,
|
||||
onselect,
|
||||
disabled,
|
||||
children,
|
||||
href,
|
||||
size = 'sm',
|
||||
element = href ? 'a' : 'button',
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={element}
|
||||
class={[
|
||||
sizes[size],
|
||||
'rounded-xl text-sm font-medium transition-colors duration-75 relative cursor-pointer border shadow-xs',
|
||||
selected
|
||||
? 'border-transparent bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-90 active:brightness-75'
|
||||
: ' 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>
|
||||
Reference in new issue
Block a user