add:modal component
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import Modal from './Modal.svelte';
|
||||
|
||||
interface Props {
|
||||
username: string;
|
||||
@@ -10,110 +11,47 @@
|
||||
|
||||
let { username, id, isOpen, onClose }: Props = $props();
|
||||
|
||||
// Close panel on escape key
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
if (event.key === 'Escape') {
|
||||
// Create a bindable showModal that syncs with isOpen
|
||||
let showModal = $derived(false);
|
||||
|
||||
// Sync showModal with isOpen prop
|
||||
$effect(() => {
|
||||
showModal = isOpen;
|
||||
});
|
||||
|
||||
// Handle modal close and sync back to parent
|
||||
$effect(() => {
|
||||
if (!showModal && isOpen) {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:window on:keydown={handleKeydown} />
|
||||
<Modal bind:showModal positioning="dropdown">
|
||||
{#snippet header()}
|
||||
<h2>Profile</h2>
|
||||
{/snippet}
|
||||
|
||||
{#if isOpen}
|
||||
<div class="backdrop" role="presentation">
|
||||
<div class="panel">
|
||||
<div class="panel-header">
|
||||
<h2>Profile</h2>
|
||||
<button class="close-button" onclick={onClose} type="button" aria-label="Close">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
|
||||
<path
|
||||
d="M18 6L6 18M6 6L18 18"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="panel-content">
|
||||
<div class="user-item">
|
||||
<span class="label">Username</span>
|
||||
<span class="value">{username}</span>
|
||||
</div>
|
||||
|
||||
<div class="panel-content">
|
||||
<div class="user-item">
|
||||
<span class="label">Username</span>
|
||||
<span class="value">{username}</span>
|
||||
</div>
|
||||
<div class="user-item">
|
||||
<span class="label">User ID</span>
|
||||
<span class="value">{id}</span>
|
||||
</div>
|
||||
|
||||
<div class="user-item">
|
||||
<span class="label">User ID</span>
|
||||
<span class="value">{id}</span>
|
||||
</div>
|
||||
|
||||
<div class="panel-actions">
|
||||
<form method="post" action="/logout" use:enhance>
|
||||
<button type="submit" class="signout-button"> Sign out </button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-actions">
|
||||
<form method="post" action="/logout" use:enhance>
|
||||
<button type="submit" class="signout-button"> Sign out </button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.panel {
|
||||
position: absolute;
|
||||
top: calc(100% + 8px);
|
||||
right: 0;
|
||||
background: white;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
|
||||
width: 320px;
|
||||
overflow: hidden;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-20px) scale(0.95);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 20px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.panel-header h2 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.close-button {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 4px;
|
||||
cursor: pointer;
|
||||
color: #666;
|
||||
border-radius: 4px;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.close-button:hover {
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.panel-content {
|
||||
padding: 0;
|
||||
display: flex;
|
||||
@@ -171,11 +109,14 @@
|
||||
background-color: #bd2130;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.panel {
|
||||
width: 280px;
|
||||
}
|
||||
:global(.modal h2) {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.user-item {
|
||||
padding: 14px 16px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user