Skip to content

Commit e4594b0

Browse files
authored
feat: added post fragment. (#137)
1 parent 7c6b917 commit e4594b0

File tree

3 files changed

+132
-1
lines changed

3 files changed

+132
-1
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
},
2424
"[svelte]": {
25-
"editor.defaultFormatter": "biomejs.biome",
25+
"editor.defaultFormatter": "svelte.svelte-vscode",
2626
"editor.codeActionsOnSave": {
2727
"source.organizeImports.biome": "explicit",
2828
"source.fixAll.biome": "explicit"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { ComponentProps } from "svelte";
2+
import Post from "./Post.svelte";
3+
4+
export default {
5+
title: "Fragments/Post",
6+
component: Post,
7+
tags: ["autodocs"],
8+
render: (args: {
9+
Component: Post;
10+
props: ComponentProps<typeof Post>;
11+
}) => ({
12+
Component: Post,
13+
props: args,
14+
}),
15+
};
16+
17+
export const Primary = {
18+
args: {
19+
avatar: "https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250",
20+
username: "blurryface",
21+
imgUri: "https://graphicsfamily.com/wp-content/uploads/edd/2023/01/Free-Photographer-Social-Media-Post-Design-Template-870x870.jpg",
22+
postAlt: "Sample",
23+
text: "Took some pictures today! Really love how this one in particular turned out! ",
24+
time: "2 hours ago",
25+
count: {
26+
likes: 100,
27+
comments: 50,
28+
},
29+
callback: {
30+
like: () => {
31+
alert("Like clicked");
32+
},
33+
comment: () => {
34+
alert("Comment clicked");
35+
},
36+
menu: () => {
37+
alert("Menu clicked");
38+
},
39+
},
40+
},
41+
};
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)