blog/src/components/Widgets/BackButton.astro
2025-05-26 12:03:12 +01:00

29 lines
801 B
Text

---
import GoBackIcon from '@/assets/icons/go-back.svg';
---
<button
id="back-button"
class="hidden"
lg="fixed left-[max(2.5rem,calc(50vw-37.5rem))] top-24 block aspect-square w-4.5 c-secondary/40 transition-colors ease-out hover:c-secondary/80 active:scale-90!"
aria-label="Go back"
>
<GoBackIcon
aria-hidden="true"
fill="currentColor"
/>
</button>
<!-- Go Back Script >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -->
<script>
function setupBackButton() {
document.getElementById('back-button')?.addEventListener('click', () => {
if (window.history.length > 1) {
window.history.back()
}
})
}
setupBackButton()
document.addEventListener('astro:after-swap', setupBackButton)
</script>