feat: Add menu origin classes

This commit is contained in:
Xyphyn committed 2023-07-15 17:24:04 -07:00
1 parent ad0023260d
commit 8eef99cc18
8 files changed
+238 -48

No files matched your search

+1 -16
View File
@@ -1,27 +1,12 @@
<script lang="ts">
import type { PostView } from 'lemmy-js-client'
import {
ChatBubbleOvalLeft,
EllipsisHorizontal,
Icon,
Square2Stack,
Trash,
} from 'svelte-hero-icons'
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
import { isImage } from '$lib/ui/image.js'
import PostVote from '$lib/components/lemmy/PostVote.svelte'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import UserLink from '$lib/components/user/UserLink.svelte'
import Card from '$lib/components/ui/Card.svelte'
import { authData, getClient, getInstance, user } from '$lib/lemmy.js'
import Menu from '$lib/components/ui/menu/Menu.svelte'
import Button from '$lib/components/input/Button.svelte'
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
import { Color } from '$lib/ui/colors.js'
import { page } from '$app/stores'
import { getInstance } from '$lib/lemmy.js'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Link from '$lib/components/input/Link.svelte'
import PostActions from '$lib/components/lemmy/PostActions.svelte'
let postRes: PostView
+1 -5
View File
@@ -55,11 +55,7 @@
<Icon slot="icon" src={ChatBubbleOvalLeft} mini width={16} height={16} />
<FormattedNumber number={post.counts.comments} />
</Link>
<Menu
top={bottomMenu ? false : true}
class="ml-auto overflow-auto"
let:toggleOpen
>
<Menu origin="top-right" class="ml-auto overflow-auto" let:toggleOpen>
<Button slot="button" label="Post actions" on:click={toggleOpen}>
<Icon src={EllipsisHorizontal} width={16} mini />
</Button>
@@ -18,6 +18,7 @@
import Markdown from '$lib/components/markdown/Markdown.svelte'
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
import { userSettings } from '$lib/settings.js'
import CommentActions from '$lib/components/lemmy/comment/CommentActions.svelte'
export let node: CommentNodeI
export let postId: number
@@ -81,21 +82,7 @@
<Markdown source={node.comment_view.comment.content} />
</div>
<div class="flex flex-row gap-2 items-center mt-1 h-[26px]">
<CommentVote
bind:score={node.comment_view.counts.score}
bind:vote={node.comment_view.my_vote}
commentId={node.comment_view.comment.id}
/>
<button
class="{$userSettings.newComments
? Color.borderDark
: 'hover:bg-slate-200 hover:dark:bg-zinc-800'} h-full px-2 flex flex-row items-center gap-1
rounded-md transition-colors"
on:click={() => (replying = !replying)}
>
<Icon src={ChatBubbleOvalLeft} width={16} height={16} mini />
<span class="text-xs">Reply</span>
</button>
<CommentActions comment={node.comment_view} bind:replying />
</div>
</div>
{#if replying}
@@ -0,0 +1,80 @@
<script lang="ts">
import type { CommentView } from 'lemmy-js-client'
import CommentVote from '$lib/components/lemmy/comment/CommentVote.svelte'
import { userSettings } from '$lib/settings.js'
import { Color } from '$lib/ui/colors.js'
import {
Bookmark,
BookmarkSlash,
ChatBubbleOvalLeft,
EllipsisHorizontal,
Icon,
} from 'svelte-hero-icons'
import { authData, getClient } from '$lib/lemmy.js'
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
import Menu from '$lib/components/ui/menu/Menu.svelte'
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
export let comment: CommentView
export let replying: boolean = false
async function save() {
if (!$authData) return
const saved = comment.saved
comment.saved = !saved
try {
await getClient().saveComment({
auth: $authData.token,
comment_id: comment.comment.id,
save: !saved,
})
} catch (error) {
comment.saved = saved
toast({
content: error as any,
type: ToastType.error,
})
}
}
</script>
<div class="flex flex-row gap-2 items-center mt-1 h-[26px] relative">
<CommentVote
bind:score={comment.counts.score}
bind:vote={comment.my_vote}
commentId={comment.comment.id}
/>
<button
class="{$userSettings.newComments
? Color.borderDark
: 'hover:bg-slate-200 hover:dark:bg-zinc-800'} h-full px-2 flex flex-row items-center gap-1
rounded-md transition-colors"
on:click={() => (replying = !replying)}
>
<Icon src={ChatBubbleOvalLeft} width={16} height={16} mini />
<span class="text-xs">Reply</span>
</button>
<div class="h-full relative">
<Menu let:toggleOpen class="h-[26px] top-0" absolute origin="bottom-center">
<button
slot="button"
class="{Color.borderDark} h-full px-1 flex flex-row items-center gap-1
rounded-md transition-colors"
on:click={toggleOpen}
>
<Icon src={EllipsisHorizontal} width={16} height={16} mini />
</button>
<span class="opacity-80 my-1 py-1 text-xs mx-4">Comment actions</span>
{#if $authData?.token}
<MenuButton on:click={save}>
<Icon src={comment.saved ? BookmarkSlash : Bookmark} mini size="16" />
<span>{comment.saved ? 'Unsave' : 'Save'}</span>
</MenuButton>
{/if}
</Menu>
</div>
</div>