|
1 | 1 | <script lang="ts"> |
2 | 2 | import MainLayout from './MainLayout.svelte' |
3 | | - import { page, inertia, useForm } from '@inertiajs/svelte' |
| 3 | + import { page } from '@inertiajs/svelte' |
4 | 4 | import UserSidebar from '@/Components/UserSidebar.svelte' |
5 | 5 | import { Button, Icon, ThemeSwitcher } from '@/Components' |
| 6 | + import { onMount } from 'svelte' |
| 7 | + import { slide } from 'svelte/transition' |
| 8 | + import { quintOut } from 'svelte/easing' |
6 | 9 |
|
7 | 10 | $: auth = $page.props.auth.user |
8 | 11 |
|
9 | | - let form = useForm() |
| 12 | + let isMobile = false |
| 13 | + let isDrawerShown = false |
| 14 | + let x = 0 |
10 | 15 |
|
11 | | - function handleLogout(e) { |
12 | | - e.preventDefault() |
13 | | -
|
14 | | - $form.post(route('logout')) |
| 16 | + $: if (x > 768) { |
| 17 | + isMobile = false |
| 18 | + } else { |
| 19 | + isMobile = true |
15 | 20 | } |
16 | 21 |
|
17 | | - function drawerOpen(): void { |
18 | | - // drawerStore.open({}) |
| 22 | + onMount(() => { |
| 23 | + isMobile = window.innerWidth < 768 |
| 24 | + }) |
| 25 | +
|
| 26 | + function closeDrawer() { |
| 27 | + isDrawerShown = false |
19 | 28 | } |
20 | 29 | </script> |
21 | 30 |
|
| 31 | +<svelte:window bind:innerWidth={x} /> |
| 32 | + |
22 | 33 | <MainLayout> |
23 | | - <div class="user-dashboard flex flex-wrap"> |
24 | | - <div class="w-full md:w-72 hidden md:block"> |
25 | | - <div class=" bg-gray-100 dark:bg-gray-800 h-full w-full"> |
26 | | - <div class="p-5 pt-6"> |
27 | | - <UserSidebar /> |
28 | | - </div> |
| 34 | + <div class="user-dashboard flex flex-wrap relative"> |
| 35 | + <!-- desktop --> |
| 36 | + <div class="hidden md:block md:w-72 h-full bg-gray-100 dark:bg-gray-800"> |
| 37 | + <div class="p-5 pt-6"> |
| 38 | + <UserSidebar on:click={closeDrawer} /> |
29 | 39 | </div> |
30 | 40 | </div> |
31 | 41 |
|
| 42 | + <!-- mobile --> |
| 43 | + {#if isMobile && isDrawerShown} |
| 44 | + <div |
| 45 | + class="md:hidden absolute w-full h-full z-20" |
| 46 | + in:slide={{ axis: 'x', duration: 300, easing: quintOut }} |
| 47 | + > |
| 48 | + <div class="relative"> |
| 49 | + <div class="w-[100vw] h-[100vh] bg-gray-800/50 dark:bg-gray-600/50" on:click={closeDrawer}> |
| 50 | + <div class="absolute top-5 right-5"> |
| 51 | + <Icon name="x-circle" classes="text-3xl text-white" /> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + <div class="w-72 z-20 h-full bg-gray-100 dark:bg-gray-800 absolute top-0 left-0"> |
| 55 | + <div class="p-5 pt-6"> |
| 56 | + <UserSidebar on:click={closeDrawer} /> |
| 57 | + </div> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + {/if} |
| 62 | + |
32 | 63 | <div class="w-full md:flex-1 bg-white dark:bg-gray-900"> |
33 | 64 | <div class="px-4 py-3 border-b border-gray-200 dark:border-gray-700 flex items-center justify-between"> |
34 | 65 | <h3 class="text-xl font-semibold"> |
|
38 | 69 | <div class="flex gap-2 items-center"> |
39 | 70 | <Icon name="bell" classes="text-2xl text-gray-600 dark:text-gray-300" /> |
40 | 71 | <Icon name="message" classes="text-2xl text-gray-600 dark:text-gray-300" /> |
41 | | - <ThemeSwitcher /> |
42 | | - <Button size="sm">Share</Button> |
43 | | - <Button size="sm" color="secondary">Create</Button> |
| 72 | + <div class="hidden md:block"> |
| 73 | + <ThemeSwitcher /> |
| 74 | + </div> |
| 75 | + <div class="hidden md:block"> |
| 76 | + <Button size="sm">Share</Button> |
| 77 | + </div> |
| 78 | + <div class="hidden md:block"> |
| 79 | + <Button size="sm" color="secondary">Create</Button> |
| 80 | + </div> |
| 81 | + <button |
| 82 | + type="button" |
| 83 | + class="inline-flex items-center p-2 text-sm rounded-lg md:hidden lg:hover:bg-primary-100 focus:outline-none focus:ring-2 focus:ring-primary-200" |
| 84 | + aria-controls="navbar-sticky" |
| 85 | + aria-expanded="false" |
| 86 | + on:click={() => (isDrawerShown = !isDrawerShown)} |
| 87 | + > |
| 88 | + <span class="sr-only">Open main menu</span> |
| 89 | + <svg |
| 90 | + class="w-6 h-6" |
| 91 | + aria-hidden="true" |
| 92 | + fill="currentColor" |
| 93 | + viewBox="0 0 20 20" |
| 94 | + xmlns="http://www.w3.org/2000/svg" |
| 95 | + ><path |
| 96 | + fill-rule="evenodd" |
| 97 | + d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 15a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z" |
| 98 | + clip-rule="evenodd" |
| 99 | + /></svg |
| 100 | + > |
| 101 | + </button> |
44 | 102 | </div> |
45 | 103 | </div> |
46 | 104 |
|
|
0 commit comments