NicolasCARPi / dropzone

Dropzone is an easy to use drag'n'drop library. It supports image previews and shows nice progress bars.
http://www.dropzone.dev/js
Other
55 stars 4 forks source link

Accept HTML template elements as previewTemplate option #18

Open MagnusOxlund opened 1 week ago

MagnusOxlund commented 1 week ago

Currently, options.previewTemplate expects a string (e.g., HTMLElement serialized using innerHTML):

https://github.com/NicolasCARPi/dropzone/blob/master/src/options.js#L553C1-L567C43:

  /**
   * A string that contains the template used for each dropped
   * file. Change it to fulfill your needs but make sure to properly
   * provide all elements.
   *
   * If you want to use an actual HTML element instead of providing a String
   * as a config option, you could create a div with the id `tpl`,
   * put the template inside it and provide the element like this:
   *
   *     document
   *       .querySelector('#tpl')
   *       .innerHTML
   *
   */
  previewTemplate: defaultPreviewTemplate,

I think it would be a natural progression to accept and automatically instantiate an HTMLTemplateElement here in addition to serialized HTML.

NicolasCARPi commented 1 week ago

Hello,

Yes, but I'd suggest to have it as another option, such as previewTemplateElement maybe. Want to work on a PR for this?

MagnusOxlund commented 1 week ago

My developer time is owed elsewhere for the next while, but I'll be happy to submit a PR later if it remains up for grabs.