blog/src/components/Widgets/BackButton.astro

29 lines
815 B
Text

---
import GoBackIcon from '@/assets/icons/go-back.svg';
---
<button
id="back-button"
class="hidden"
lg="block absolute c-secondary/40 left--10 top-1/2 aspect-square w-4.5 translate-y--1/2 transition-colors duration-300 ease-out c-secondary active:scale-90 hover:c-primary/80"
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>