1.0.1 • Published 5 years ago

af-image-uploader v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

AppFeel Image Uploader WebComponentLicense NPM version NPM downloads Built With Stencil

This web component implements a drag and drop component to upload and preview images. Example of use:

<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0">
    <title>AppFeel Image Uploader WebComponent</title>
    <script src='https://unpkg.com/af-image-uploader@latest/dist/af-image-uploader.js'></script>

</head>

<body>

    <af-image-uploader id="imageUploader" width="300px" height="100px" onchange="onChange(event)" onload="onLoad(event)"></af-image-uploader>
    <button onclick="reset()">Reset</button>
    <button onclick="getFile()">Get File</button>
</body>
<script>
    const imageUploader = document.getElementById('imageUploader');
    function reset() {
        imageUploader.reset();
    }
    function onChange(image) {
        console.log('Image selected', image.detail);
    }
    function onLoad(image) {
        console.log('Image preview completed', image.detail);
    }
    async function getFile() {
        console.log('Selected image', await imageUploader.getFile());
    }
</script>
</html>

Properties

PropertyAttributeDescriptionTypeDefault
activeColoractive-colorThe color when it is activestring'green'
baseColorbase-colorThe default colorstring'#ccc'
heightheightHeight of the componentstring'300px'
hoverOutlineColorhover-outline-colorThe hover outline colorstring'#aaa'
iconSrcicon-srcIcon source image (svg, png, jpg, gif, ...)string'./assets/upload-cloud-flat.svg'
overlayColoroverlay-colorThe overlay colorstring'rgba(255,255,255,0.5)'
widthwidthWidth of the componentstring'100%'

Events

EventDescriptionType
changeRaised when the upload has finishedCustomEvent<File>
invalidformatRaised when the file tried to upload was in wrong formatCustomEvent<string>
loadRaised when the image has finished to loadCustomEvent<File>

Methods

getFile() => Promise<File>

Obtains the selected or dropped file if any, or undefined if none available

Returns

Type: Promise<File>

selected or dropped file

reset() => void

Reset the component to void state

Returns

Type: void

Using this component

Script tag

  • Publish to NPM
  • Put a script tag similar to this <script src='https://unpkg.com/af-image-uploader@latest/dist/af-image-uploader.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

Node Modules

  • Run npm install af-image-uploader --save
  • Put a script tag similar to this <script src='node_modules/af-image-uploader/dist/af-image-uploader.js'></script> in the head of your index.html
  • Then you can use the element anywhere in your template, JSX, html etc

In a stencil-starter app

  • Run npm install af-image-uploader --save
  • Add an import to the npm packages import af-image-uploader;
  • Then you can use the element anywhere in your template, JSX, html etc
1.0.1

5 years ago

1.0.0

5 years ago