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