Skip to content

Instantly share code, notes, and snippets.

@TiagoSilvaPereira
Created February 13, 2021 18:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoSilvaPereira/afc5b916aba37133fce582106ac566e4 to your computer and use it in GitHub Desktop.
Save TiagoSilvaPereira/afc5b916aba37133fce582106ac566e4 to your computer and use it in GitHub Desktop.
Alpine.js Image Viewer template
<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