Skip to content

Instantly share code, notes, and snippets.

@StefanNieuwenhuis
Last active December 27, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanNieuwenhuis/dafabcbd3499cc082aa71cffb0aa6414 to your computer and use it in GitHub Desktop.
Save StefanNieuwenhuis/dafabcbd3499cc082aa71cffb0aa6414 to your computer and use it in GitHub Desktop.
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