Skip to content

Instantly share code, notes, and snippets.

@alaminfirdows
Created February 17, 2021 10:13
Show Gist options
  • Save alaminfirdows/c721f8e61ab164c7f9764a2e81532ccd to your computer and use it in GitHub Desktop.
Save alaminfirdows/c721f8e61ab164c7f9764a2e81532ccd to your computer and use it in GitHub Desktop.
<div class="relative flex justify-center" x-data="snackBarData()" x-init="hideAlert()">
<div class="fixed bottom-10 transition duration-300" x-show="isOpen" x-transition:leave="ease-in" x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0">
<div class="bg-red-500 text-white flex items-center space-x-5 text-sm font-bold px-4 py-3 rounded shadow" role="alert">
<span class="flex">alertMessage</span>
<button class="focus:outline-none" @click="isOpen = false">
<x-icons.x />
</button>
</div>
</div>
</div>
<script>
window.snackBarData = function () {
return {
isOpen: true,
openAlert: function () {
this.isOpen = true
},
hideAlert: function () {
setTimeout(() => {
this.isOpen = false
}, 3000);
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment