design: improve file attachments
This commit is contained in:
4 files changed
+82
-67
No files matched your search
@@ -0,0 +1,57 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { t } from '$lib/i18n/translations'
|
||||||
|
import { DocumentPlus, Icon, Plus } from 'svelte-hero-icons'
|
||||||
|
import ImageUploadModal from '../lemmy/modal/ImageUploadModal.svelte'
|
||||||
|
import { Label } from 'mono-svelte'
|
||||||
|
|
||||||
|
let { imageUrl = $bindable(), label }: { imageUrl?: string; label?: string } =
|
||||||
|
$props()
|
||||||
|
|
||||||
|
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}
|
||||||
|
{#if open}
|
||||||
|
<ImageUploadModal
|
||||||
|
bind:open
|
||||||
|
multiple={false}
|
||||||
|
onupload={uploaded => {
|
||||||
|
open = false
|
||||||
|
imageUrl = uploaded[0]
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
import { DocumentPlus, GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
|
import { DocumentPlus, GlobeAlt, Icon, MapPin, Plus } from 'svelte-hero-icons'
|
||||||
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
|
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
|
||||||
import { errorMessage } from '$lib/lemmy/error'
|
import { errorMessage } from '$lib/lemmy/error'
|
||||||
|
import ImageInputUpload from '$lib/components/form/ImageInputUpload.svelte'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
/**
|
/**
|
||||||
@@ -168,62 +169,14 @@
|
|||||||
bind:value={formData.displayName}
|
bind:value={formData.displayName}
|
||||||
/>
|
/>
|
||||||
<div class="flex flex-row gap-4 flex-wrap *:flex-1">
|
<div class="flex flex-row gap-4 flex-wrap *:flex-1">
|
||||||
<div class="flex flex-col gap-1">
|
<ImageInputUpload
|
||||||
<Label>{$t('routes.admin.config.icon')}</Label>
|
imageUrl={formData.icon}
|
||||||
<button
|
label={$t('routes.admin.config.icon')}
|
||||||
type="button"
|
/>
|
||||||
onclick={() => (uploading.icon = !uploading.icon)}
|
<ImageInputUpload
|
||||||
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
imageUrl={formData.banner}
|
||||||
>
|
label={$t('routes.admin.config.banner')}
|
||||||
{#if formData.icon}
|
/>
|
||||||
<img src={formData.icon} alt="" class="rounded-md mx-auto h-full" />
|
|
||||||
{:else}
|
|
||||||
<Icon
|
|
||||||
src={DocumentPlus}
|
|
||||||
size="48"
|
|
||||||
class="text-slate-500 dark:text-zinc-500 mx-auto my-auto"
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
{#if uploading.icon}
|
|
||||||
<ImageUploadModal
|
|
||||||
bind:open={uploading.icon}
|
|
||||||
multiple={false}
|
|
||||||
onupload={uploaded => {
|
|
||||||
uploading.icon = false
|
|
||||||
formData.icon = uploaded[0]
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
<div class="flex flex-col gap-1">
|
|
||||||
<Label>{$t('routes.admin.config.banner')}</Label>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onclick={() => (uploading.banner = !uploading.banner)}
|
|
||||||
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
|
|
||||||
>
|
|
||||||
{#if formData.banner}
|
|
||||||
<img src={formData.banner} alt="" class="rounded-md mx-auto h-full" />
|
|
||||||
{:else}
|
|
||||||
<Icon
|
|
||||||
src={DocumentPlus}
|
|
||||||
size="48"
|
|
||||||
class="text-slate-500 dark:text-zinc-500 mx-auto my-auto"
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
{#if uploading.banner}
|
|
||||||
<ImageUploadModal
|
|
||||||
bind:open={uploading.banner}
|
|
||||||
multiple={false}
|
|
||||||
onupload={uploaded => {
|
|
||||||
uploading.banner = false
|
|
||||||
formData.banner = uploaded[0]
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<MarkdownEditor
|
<MarkdownEditor
|
||||||
previewButton
|
previewButton
|
||||||
|
|||||||
@@ -652,7 +652,8 @@
|
|||||||
"send": "Send",
|
"send": "Send",
|
||||||
"general": "General",
|
"general": "General",
|
||||||
"remove": "Remove",
|
"remove": "Remove",
|
||||||
"download": "Download"
|
"download": "Download",
|
||||||
|
"attach": "Attach file"
|
||||||
},
|
},
|
||||||
"message": {
|
"message": {
|
||||||
"success": "Success",
|
"success": "Success",
|
||||||
@@ -965,4 +966,4 @@
|
|||||||
"body": "What do you have to say?",
|
"body": "What do you have to say?",
|
||||||
"comments": "Join the conversation"
|
"comments": "Join the conversation"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,13 +34,12 @@
|
|||||||
</Label>
|
</Label>
|
||||||
{/if}
|
{/if}
|
||||||
<label
|
<label
|
||||||
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-xl
|
class={[
|
||||||
border border-slate-200 dark:border-zinc-800 bg-white dark:bg-black
|
'flex flex-col items-center justify-center px-8 py-4 mx-auto w-full rounded-xl',
|
||||||
cursor-pointer min-h-36 transition-colors {dragover
|
'border border-slate-200 dark:border-zinc-800 border-dashed hover:border-slate-300 hover:dark:border-zinc-700',
|
||||||
? 'border-sky-500 text-sky-500'
|
'cursor-pointer min-h-36 transition-colors bg-white dark:bg-zinc-950',
|
||||||
: ''}
|
dragover && 'border-sky-500 text-sky-500',
|
||||||
{url != undefined ? 'rounded-b-none' : ''}
|
]}
|
||||||
"
|
|
||||||
ondrop={event => {
|
ondrop={event => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
files = event.dataTransfer?.files ?? null
|
files = event.dataTransfer?.files ?? null
|
||||||
@@ -68,8 +67,13 @@
|
|||||||
class="w-full max-w-sm h-full rounded-lg"
|
class="w-full max-w-sm h-full rounded-lg"
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
<Icon
|
||||||
<p class="text-sm opacity-50">Attach a file</p>
|
src={DocumentPlus}
|
||||||
|
class="text-slate-400 dark:text-zinc-500"
|
||||||
|
size="36"
|
||||||
|
solid
|
||||||
|
/>
|
||||||
|
<p class="text-slate-600 dark:text-zinc-400 font-medium">Attach a file</p>
|
||||||
{/if}
|
{/if}
|
||||||
<input type="file" bind:files {accept} class="hidden" />
|
<input type="file" bind:files {accept} class="hidden" />
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
Reference in new issue
Block a user