|
1 | 1 | <script lang="ts"> |
2 | 2 | import { Avatar, Input } from '$lib/ui'; |
3 | 3 | import { cn } from '$lib/utils'; |
4 | | - import { ImageAdd02Icon } from '@hugeicons/core-free-icons'; |
| 4 | + import { ImageAdd02Icon, PlusSignIcon, SentIcon } from '@hugeicons/core-free-icons'; |
5 | 5 | import { HugeiconsIcon } from '@hugeicons/svelte'; |
6 | 6 | import type { HTMLAttributes } from 'svelte/elements'; |
7 | 7 |
|
8 | 8 | interface IMessageInputProps extends HTMLAttributes<HTMLElement> { |
| 9 | + variant: 'comment' | 'dm'; |
9 | 10 | src: string; |
10 | 11 | value: string; |
11 | 12 | placeholder?: string; |
12 | 13 | files?: FileList | undefined; |
| 14 | + handleAdd?: () => void; |
| 15 | + handleSend: () => Promise<void>; |
13 | 16 | } |
14 | 17 |
|
15 | 18 | let { |
| 19 | + variant = 'comment', |
16 | 20 | src = 'https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250', |
17 | 21 | value, |
18 | 22 | placeholder, |
19 | 23 | files = $bindable(), |
| 24 | + handleAdd, |
| 25 | + handleSend, |
20 | 26 | ...restProps |
21 | 27 | }: IMessageInputProps = $props(); |
22 | 28 |
|
23 | 29 | const cBase = 'flex items-center justify-between gap-2'; |
24 | 30 | </script> |
25 | 31 |
|
26 | 32 | <div {...restProps} class={cn([cBase, restProps.class].join(' '))}> |
27 | | - <Avatar size="sm" {src} /> |
| 33 | + {#if variant === 'comment'} |
| 34 | + <Avatar size="sm" {src} /> |
| 35 | + {:else} |
| 36 | + <!-- svelte-ignore a11y_click_events_have_key_events --> |
| 37 | + <!-- svelte-ignore a11y_no_static_element_interactions --> |
| 38 | + <div |
| 39 | + class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full" |
| 40 | + onclick={handleAdd} |
| 41 | + > |
| 42 | + <HugeiconsIcon size="24px" icon={PlusSignIcon} color="var(--color-black-400)" /> |
| 43 | + </div> |
| 44 | + {/if} |
28 | 45 | <Input type="text" bind:value {placeholder} /> |
29 | | - <div class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full"> |
30 | | - <input id="add-image" type="file" class="hidden" accept="image/*" bind:files /> |
31 | | - <label for="add-image"> |
32 | | - <HugeiconsIcon size="24px" icon={ImageAdd02Icon} color="var(--color-black-400)" /> |
33 | | - </label> |
34 | | - </div> |
| 46 | + {#if value || variant === 'dm'} |
| 47 | + <!-- svelte-ignore a11y_click_events_have_key_events --> |
| 48 | + <!-- svelte-ignore a11y_no_static_element_interactions --> |
| 49 | + <div |
| 50 | + class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full" |
| 51 | + onclick={handleSend} |
| 52 | + > |
| 53 | + <HugeiconsIcon size="24px" icon={SentIcon} color="var(--color-black-400)" /> |
| 54 | + </div> |
| 55 | + {:else} |
| 56 | + <div class="bg-grey flex aspect-square h-13 w-13 items-center justify-center rounded-full"> |
| 57 | + <input id="add-image" type="file" class="hidden" accept="image/*" bind:files /> |
| 58 | + <label for="add-image"> |
| 59 | + <HugeiconsIcon size="24px" icon={ImageAdd02Icon} color="var(--color-black-400)" /> |
| 60 | + </label> |
| 61 | + </div> |
| 62 | + {/if} |
35 | 63 | </div> |
0 commit comments