Created
February 13, 2021 18:13
-
-
Save TiagoSilvaPereira/afc5b916aba37133fce582106ac566e4 to your computer and use it in GitHub Desktop.
Alpine.js Image Viewer template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div x-data="imageViewer()"> | |
<div class="mb-2"> | |
<!-- Show the image --> | |
<template x-if="imageUrl"> | |
<img :src="imageUrl" | |
class="object-cover rounded border border-gray-200" | |
style="width: 100px; height: 100px;" | |
> | |
</template> | |
<!-- Show the gray box when image is not available --> | |
<template x-if="!imageUrl"> | |
<div | |
class="border rounded border-gray-200 bg-gray-100" | |
style="width: 100px; height: 100px;" | |
></div> | |
</template> | |
<!-- Image file selector --> | |
<input class="mt-2" type="file" accept="image/*"> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment