|
| 1 | +<script lang="ts"> |
| 2 | + import { Avatar } from '$lib/ui'; |
| 3 | + import { cn } from '$lib/utils'; |
| 4 | + import { |
| 5 | + Message02Icon, |
| 6 | + MoreVerticalIcon, |
| 7 | + RecordIcon, |
| 8 | + ThumbsUpIcon |
| 9 | + } from '@hugeicons/core-free-icons'; |
| 10 | + import { HugeiconsIcon } from '@hugeicons/svelte'; |
| 11 | + import type { HTMLAttributes } from 'svelte/elements'; |
| 12 | +
|
| 13 | + interface IPostProps extends HTMLAttributes<HTMLElement> { |
| 14 | + avatar: string; |
| 15 | + username: string; |
| 16 | + imgUri: string; |
| 17 | + postAlt?: string; |
| 18 | + text: string; |
| 19 | + count: { |
| 20 | + likes: number; |
| 21 | + comments: number; |
| 22 | + }; |
| 23 | + callback: { |
| 24 | + menu: () => void; |
| 25 | + like: () => void; |
| 26 | + comment: () => void; |
| 27 | + }; |
| 28 | + time: string; |
| 29 | + } |
| 30 | +
|
| 31 | + const { |
| 32 | + avatar, |
| 33 | + username, |
| 34 | + imgUri, |
| 35 | + text, |
| 36 | + postAlt, |
| 37 | + count, |
| 38 | + callback, |
| 39 | + time, |
| 40 | + ...restProps |
| 41 | + }: IPostProps = $props(); |
| 42 | +</script> |
| 43 | + |
| 44 | +<article {...restProps} class={cn(['flex w-full flex-col gap-4', restProps.class])}> |
| 45 | + <div class="flex w-full items-center justify-between"> |
| 46 | + <div class="flex items-center justify-between gap-2"> |
| 47 | + <Avatar src={avatar} alt={username} size="sm"></Avatar> |
| 48 | + <h2>{username}</h2> |
| 49 | + </div> |
| 50 | + |
| 51 | + <button onclick={callback.menu} class="cursor-pointer rounded-full p-2 hover:bg-gray-100"> |
| 52 | + <HugeiconsIcon icon={MoreVerticalIcon} size={24} color="var(--color-black-500)" /> |
| 53 | + </button> |
| 54 | + </div> |
| 55 | + <img src={imgUri} alt={postAlt ?? text} class="rounded-4xl" /> |
| 56 | + <p class="text-black/80">{text}</p> |
| 57 | + <p class="text-black/60">{time}</p> |
| 58 | + <div class="flex w-full items-center justify-between"> |
| 59 | + <div class="flex gap-4"> |
| 60 | + <button |
| 61 | + class="cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 hover:bg-gray-200" |
| 62 | + onclick={callback.like} |
| 63 | + > |
| 64 | + <HugeiconsIcon |
| 65 | + icon={ThumbsUpIcon} |
| 66 | + size={24} |
| 67 | + color="var(--color-red-500)" |
| 68 | + strokeWidth={3} |
| 69 | + /> |
| 70 | + </button> |
| 71 | + <button |
| 72 | + class="cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 hover:bg-gray-200" |
| 73 | + onclick={callback.comment} |
| 74 | + > |
| 75 | + <HugeiconsIcon icon={Message02Icon} size={24} color="var(--color-black-500)" /> |
| 76 | + </button> |
| 77 | + </div> |
| 78 | + <div class="flex items-center justify-between gap-3 text-lg text-black/40"> |
| 79 | + <p>{count.likes} likes</p> |
| 80 | + <HugeiconsIcon |
| 81 | + icon={RecordIcon} |
| 82 | + size={5} |
| 83 | + strokeWidth={30} |
| 84 | + color="var(--color-black-400)" |
| 85 | + className="rounded-full" |
| 86 | + /> |
| 87 | + <p>{count.comments} comments</p> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | +</article> |
0 commit comments