Last active
December 27, 2018 09:37
-
-
Save StefanNieuwenhuis/dafabcbd3499cc082aa71cffb0aa6414 to your computer and use it in GitHub Desktop.
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
import { Component} from '@stencil/core'; | |
@Component({ | |
tag: 'my-component', | |
styleUrl: 'my-component.css', | |
shadow: true | |
}) | |
export class MyComponent { | |
public onInputChange(files: FileList) { | |
// check if 1 image is uploaded | |
if (files.length === 1) { | |
}else{ | |
console.error(files.length === 0 ? 'NO IMAGE UPLOADED' : 'YOU CAN ONLY UPLOAD ONE IMAGE AT THE TIME'); | |
return false; | |
} | |
} | |
render() { | |
return <div class="image-upload"> | |
<div class="image-upload__edit"> | |
<label htmlFor="file"></label> | |
<input type="file" name="files[]" id="file" accept="image/*" class="image-upload__input" | |
onChange={($event: any) => this.onInputChange($event.target.files)} /> | |
</div> | |
<div class="image-upload__preview"> | |
<div id="image-preview"></div> | |
</div> | |
</div>; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment