-
Notifications
You must be signed in to change notification settings - Fork 4
feat: added post fragment. #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { ComponentProps } from "svelte"; | ||
import Post from "./Post.svelte"; | ||
|
||
export default { | ||
title: "Fragments/Post", | ||
component: Post, | ||
tags: ["autodocs"], | ||
render: (args: { | ||
Component: Post; | ||
props: ComponentProps<typeof Post>; | ||
}) => ({ | ||
Component: Post, | ||
props: args, | ||
}), | ||
}; | ||
|
||
export const Primary = { | ||
args: { | ||
avatar: "https://www.gravatar.com/avatar/2c7d99fe281ecd3bcd65ab915bac6dd5?s=250", | ||
username: "blurryface", | ||
imgUri: "https://graphicsfamily.com/wp-content/uploads/edd/2023/01/Free-Photographer-Social-Media-Post-Design-Template-870x870.jpg", | ||
postAlt: "Sample", | ||
text: "Took some pictures today! Really love how this one in particular turned out! ", | ||
time: "2 hours ago", | ||
count: { | ||
likes: 100, | ||
comments: 50, | ||
}, | ||
callback: { | ||
like: () => { | ||
alert("Like clicked"); | ||
}, | ||
comment: () => { | ||
alert("Comment clicked"); | ||
}, | ||
menu: () => { | ||
alert("Menu clicked"); | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<script lang="ts"> | ||
import { Avatar } from '$lib/ui'; | ||
import { cn } from '$lib/utils'; | ||
import { | ||
Message02Icon, | ||
MoreVerticalIcon, | ||
RecordIcon, | ||
ThumbsUpIcon | ||
} from '@hugeicons/core-free-icons'; | ||
import { HugeiconsIcon } from '@hugeicons/svelte'; | ||
import type { HTMLAttributes } from 'svelte/elements'; | ||
|
||
interface IPostProps extends HTMLAttributes<HTMLElement> { | ||
avatar: string; | ||
username: string; | ||
imgUri: string; | ||
postAlt?: string; | ||
text: string; | ||
count: { | ||
likes: number; | ||
comments: number; | ||
}; | ||
callback: { | ||
menu: () => void; | ||
like: () => void; | ||
comment: () => void; | ||
}; | ||
time: string; | ||
} | ||
|
||
const { | ||
avatar, | ||
username, | ||
imgUri, | ||
text, | ||
postAlt, | ||
count, | ||
callback, | ||
time, | ||
...restProps | ||
}: IPostProps = $props(); | ||
</script> | ||
|
||
<article {...restProps} class={cn(['flex w-full flex-col gap-4', restProps.class])}> | ||
<div class="flex w-full items-center justify-between"> | ||
<div class="flex items-center justify-between gap-2"> | ||
<Avatar src={avatar} alt={username} size="sm"></Avatar> | ||
<h2>{username}</h2> | ||
</div> | ||
|
||
<button onclick={callback.menu} class="cursor-pointer rounded-full p-2 hover:bg-gray-100"> | ||
<HugeiconsIcon icon={MoreVerticalIcon} size={24} color="var(--color-black-500)" /> | ||
</button> | ||
</div> | ||
<img src={imgUri} alt={postAlt ?? text} class="rounded-4xl" /> | ||
<p class="text-black/80">{text}</p> | ||
<p class="text-black/60">{time}</p> | ||
<div class="flex w-full items-center justify-between"> | ||
<div class="flex gap-4"> | ||
<button | ||
class="cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 hover:bg-gray-200" | ||
onclick={callback.like} | ||
> | ||
<HugeiconsIcon | ||
icon={ThumbsUpIcon} | ||
size={24} | ||
color="var(--color-red-500)" | ||
strokeWidth={3} | ||
/> | ||
</button> | ||
<button | ||
class="cursor-pointer rounded-2xl bg-gray-100 px-4 py-3 hover:bg-gray-200" | ||
onclick={callback.comment} | ||
> | ||
<HugeiconsIcon icon={Message02Icon} size={24} color="var(--color-black-500)" /> | ||
</button> | ||
</div> | ||
<div class="flex items-center justify-between gap-3 text-lg text-black/40"> | ||
<p>{count.likes} likes</p> | ||
<HugeiconsIcon | ||
icon={RecordIcon} | ||
size={5} | ||
strokeWidth={30} | ||
color="var(--color-black-400)" | ||
className="rounded-full" | ||
/> | ||
<p>{count.comments} comments</p> | ||
</div> | ||
</div> | ||
</article> |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix event handler in like and comment buttons
Similar to the menu button, replace 'onclick' with 'on:click' in both action buttons.
Also applies to: 71-76