1.0.0 • Published 4 years ago

pk-image-uploader v1.0.0

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

Built With Stencil

Image Uploader Web Component

A side project for myself to create a reusable drag&drop image uploader web component and practice StencilJS.

Image uploader

You can check out a DEMO PEN here.

Properties

The component can receive the following properties as html attributes. Only the label is required. If the image is not set, the component will simply start off with an empty state (showing the drop box). All the requirement rule properties have default values thus they are not required.

PropertyAttributeDescriptionTypeDefault
imageimageThe URL of an already existing imagestringundefined
label*labelText label shown over the image boxstringundefined
maxFileSizesize-maxMaximum allowed file size in MBnumber5
maxImageHeightheight-maxMaximum allowed image height in pixelnumber4000
maxImageWidthwidth-maxMaximum allowed image width in pixelnumber6000
minImageHeightheight-minMinimum allowed image height in pixelnumber240
minImageWidthwidth-minMinimum allowed image width in pixelnumber320

For image dimensions (px) if either of the values are set to 0 that minimum or maximum size accordingly will NOT be validated.

Events

Every time the loaded image changes and the file is valid, an imagechange event is fired with the image file as the payload, or a null value if the images has been removed.

EventDescriptionType
imagechangePayload: the selected file or nullCustomEvent<File | null>

Styles

  • Component width is set to 100% of the parent element
  • Component height is 350px by default but can be easily overwritten by simply assigning a new height in CSS for the pk-image-uploader element
  • CSS variables can be set to overwrite some of the default settings:
CSS variableDescriptionDefault
--iu-primary-colorColor of the texts and borders#00000099
--iu-dragging-colorColor of the border while dragging#425AC9
--iu-error-colorColor of the border and the error message in case of invalid file#D20000
--iu-border-radiusBorder radius of the component box and buttons5px