-
Notifications
You must be signed in to change notification settings - Fork 0
メッセージにホバーしたときに色が変わるようにし、右クリックでドロップダウンメニューを出せるようにした #3
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
Conversation
| let clientX = $state(0); | ||
| let clientY = $state(0); | ||
| let onclick_dropdown_reply = $state(() => {}); |
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.
JavaScript の命名規則はほとんどの場合スネークケース variable_name ではなくキャメルケース variableName なので、そのような名前にしてね。
| class="menu dropdown-content bg-base-100 absolute z-[1] w-40 rounded-md border p-2 shadow" | ||
| > | ||
| <li> | ||
| <button onclick={onclick_reply}>返信</button> |
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.
ドロップダウンのメニューをこちら側で再実装するのではなく、 MessageList の方で #snippet を使って作ってやると onclick_ボタン名 みたいなのをボタンごとに渡さなくてもよくなりそう
そうすると MessageDropdown が複数 HTML に出てくることになるので、 visibility: hidden ではなく {#if visible}...{/if} で表示を操作してやると、やりたいことができると思う
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.
例
<!-- MessageDropdown.svelte -->
<script lang="ts">
import type { Snippet } from "svelte";
const {
x,
y,
visible,
children,
}: { children: Snippet; x: number; y: number; visible: boolean } = $props();
</script>
{#if visible}
<div
style={`top: ${y}px; left: ${x}px; visibility: ${visible ? "visible" : "hidden"}`}
class="fixed"
>
{@render children()}
</div>
{/if}<!-- MessageList.svelte (抜粋) -->
<script lang="ts">
// 適切なタイミングで変更するハンドラを入れる
let dropdownVisibleOn = $state<Id<"messages"> | null>(null);
</script>
{#each messages as message (message._id)}
<MessageDropdown visible={dropdownVisibleOn === message._id}>
{@render dropdownContent()}
</MessageDropdown>
{#snippet dropdownContent()}
<ul>...</ul>
{/snippet}
{/each}
aster-void
left a comment
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.
よさそう
No description provided.