|
2 | 2 | import BackToTop from '@/custom/components/pages/BackToTop.astro' |
3 | 3 |
|
4 | 4 | import type { SiteMeta } from 'astro-pure/types' |
5 | | -import { Button } from 'astro-pure/user' |
| 5 | +import { Button, Icon } from 'astro-pure/user' |
6 | 6 | import { cn } from 'astro-pure/utils' |
7 | 7 | import PageLayout from '@/layouts/BaseLayout.astro' |
8 | 8 | import { integ } from '@/site-config' |
@@ -74,5 +74,96 @@ const { meta, highlightColor, back = '/', ...props } = Astro.props |
74 | 74 | </div> |
75 | 75 | </div> |
76 | 76 |
|
77 | | - <BackToTop header='content-header' content='content' /> |
| 77 | + <BackToTop header='content-header' content='content'> |
| 78 | + <button |
| 79 | + slot='other-icons' |
| 80 | + aria-label='Toggle sidebar' |
| 81 | + class='size-10 flex items-center justify-center rounded-full border-2 border-transparent bg-muted text-muted-foreground duration-300 hover:border-border/75 md:hidden sm:size-12' |
| 82 | + id='sidebar-btn' |
| 83 | + > |
| 84 | + <Icon name='list' /> |
| 85 | + </button> |
| 86 | + </BackToTop> |
78 | 87 | </PageLayout> |
| 88 | + |
| 89 | +<script> |
| 90 | + // Toggle sidebar visibility on button click |
| 91 | + const sidebarButton = document.getElementById('sidebar-btn') |
| 92 | + const sidebar = document.getElementById('sidebar') |
| 93 | + const sidebarShade = document.getElementById('sidebar-shade') as HTMLElement |
| 94 | + |
| 95 | + if (sidebarShade) { |
| 96 | + sidebarShade.addEventListener('click', () => { |
| 97 | + toggleSidebar() |
| 98 | + }) |
| 99 | + } |
| 100 | + |
| 101 | + function toggleSidebar() { |
| 102 | + if (sidebar && sidebar.classList.contains('show')) { |
| 103 | + sidebar.classList.remove('show') |
| 104 | + sidebarShade.style.display = 'none' |
| 105 | + } else if (sidebar) { |
| 106 | + sidebar.classList.add('show') |
| 107 | + sidebarShade.style.display = 'block' |
| 108 | + } else { |
| 109 | + console.error('Sidebar element not found.') |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + sidebarButton?.addEventListener('click', () => { |
| 114 | + toggleSidebar() |
| 115 | + }) |
| 116 | +</script> |
| 117 | +<style> |
| 118 | + @media (min-width: 769px) { |
| 119 | + #sidebar-shade { |
| 120 | + display: none !important; |
| 121 | + } |
| 122 | + } |
| 123 | + @media (max-width: 769px) { |
| 124 | + aside.show { |
| 125 | + display: block !important; |
| 126 | + opacity: 1; |
| 127 | + } |
| 128 | + |
| 129 | + @keyframes fade-in-side { |
| 130 | + 0% { |
| 131 | + transform: translateX(50%); |
| 132 | + opacity: 0; |
| 133 | + } |
| 134 | + 100% { |
| 135 | + transform: translateX(0); |
| 136 | + opacity: 1; |
| 137 | + } |
| 138 | + } |
| 139 | + @keyframes fade-in { |
| 140 | + 0% { |
| 141 | + opacity: 0; |
| 142 | + } |
| 143 | + 100% { |
| 144 | + opacity: 1; |
| 145 | + } |
| 146 | + } |
| 147 | + aside { |
| 148 | + animation: 300ms fade-in-side !important; |
| 149 | + animation-fill-mode: forwards; |
| 150 | + right: 0; |
| 151 | + top: 0 !important; |
| 152 | + height: 100vh !important; |
| 153 | + min-width: 40vw !important; |
| 154 | + max-width: 75vw !important; |
| 155 | + border-top-right-radius: 0 !important; |
| 156 | + border-bottom-right-radius: 0 !important; |
| 157 | + padding-top: 1.5rem !important; |
| 158 | + padding-bottom: 1.5rem !important; |
| 159 | + } |
| 160 | + #sidebar-shade { |
| 161 | + animation: 300ms fade-in; |
| 162 | + } |
| 163 | + } |
| 164 | + @media (max-width: 640px) { |
| 165 | + aside { |
| 166 | + min-width: 55vw !important; |
| 167 | + } |
| 168 | + } |
| 169 | +</style> |
0 commit comments