forked from nayarahilton/vue-pwa-profil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Photo Uploader component nayarahilton#1
- Loading branch information
lucasjs
committed
Nov 11, 2017
1 parent
9ca4573
commit 54028ce
Showing
3 changed files
with
150 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<template> | ||
<div class="photo-upload"> | ||
<div class="file-upload-form"> | ||
<input | ||
type="file" | ||
@change="previewThumbnail" | ||
name="photo-upload-button" | ||
id="photo-upload-button" | ||
accept="image/*" | ||
class="input-file" | ||
/> | ||
<label for="photo-upload-button">{{ labelText }}</label> | ||
</div> | ||
<div | ||
class="image-preview" | ||
v-if="imageData.length > 0" | ||
> | ||
<img | ||
:src="imageData" | ||
class="image-preview__img" | ||
> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data: function returnImageData() { | ||
return { | ||
imageData: '', | ||
}; | ||
}, | ||
props: { | ||
labelText: { | ||
required: true, | ||
type: String, | ||
}, | ||
}, | ||
methods: { | ||
previewThumbnail: function getPreview(event) { | ||
const input = event.target; | ||
if (input.files && input.files[0]) { | ||
const reader = new FileReader(); | ||
reader.onload = (e) => { | ||
this.imageData = e.target.result; | ||
}; | ||
reader.readAsDataURL(input.files[0]); | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="stylus" scoped> | ||
@import '../assets/styles/_colors' | ||
* | ||
box-sizing border-box | ||
.photo-upload | ||
height auto | ||
margin 20px 0 | ||
position relative | ||
text-align center | ||
width 100% | ||
.input-file | ||
height 0.1px | ||
opacity 0 | ||
overflow hidden | ||
position absolute | ||
width 0.1px | ||
z-index -1 | ||
&:focus + label | ||
border-color $dark-blue | ||
& + label | ||
background transparent | ||
border 2px solid $pink | ||
border-radius 50% | ||
color $dark-gray | ||
display inline-block | ||
font-size 12pt | ||
font-weight 500 | ||
height 150px | ||
line-height 150px | ||
text-align center | ||
width 150px | ||
&:hover, | ||
&:focus | ||
border-color $dark-blue | ||
cursor pointer | ||
.image-preview | ||
border-radius 50% | ||
height 150px | ||
left 0 | ||
margin 0 auto | ||
pointer-events none | ||
position: absolute | ||
right 0 | ||
top 0 | ||
width 150px | ||
&__img | ||
border 2px solid $pink | ||
border-radius 50% | ||
height 150px | ||
object-fit cover | ||
object-position center | ||
width 150px | ||
</style> |
This file contains 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