react-filepond icon indicating copy to clipboard operation
react-filepond copied to clipboard

[feature request] Allow labelIdle to be a component

Open kino90 opened this issue 4 years ago • 10 comments

Hello, thanks for this repo, it's really awesome.

I'm trying to use it in a project, but my template is a little different and I'd have to customize the labelIdle prop with something more than a static markup (e.g a custom <Button> component)

Is it possible? I didn't see anything in the docs..

👍

kino90 avatar Sep 06 '19 10:09 kino90

Hi, this is currently not possible, you can only set a label

rikschennink avatar Sep 09 '19 07:09 rikschennink

Ok, I see. Will it be added sooner or later? shouldn't be a problem to accept a component OR a string 😉

kino90 avatar Sep 09 '19 07:09 kino90

Well, it's not a "native" React component so the React render loop stops at the FilePond init. So there's currently no way to "wrap" a React component.

rikschennink avatar Sep 09 '19 07:09 rikschennink

That said, I am exploring ways to add it but that will probably not be anytime soon.

rikschennink avatar Sep 09 '19 07:09 rikschennink

Oh, I see.. Thank you for your quick reply!

kino90 avatar Sep 09 '19 07:09 kino90

Maybe we could use the ReactDOM.createPortal method to render the component if it is supplied as prop to the Filepond component.

romainbessugesmeusy avatar Sep 17 '19 18:09 romainbessugesmeusy

@romainbessugesmeusy feel free to submit a PR

rikschennink avatar Sep 18 '19 05:09 rikschennink

If it helps anyone stumbling on this. I solved this for myself by rendering the component as a string and setting that string as the label.

You should be able to do this using different frameworks or libraries. Here is an example in React.

import { renderToString } from 'react-dom/server';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStar } from "@fortawesome/free-solid-svg-icons";

const ImagePicker: React.FC<_Props> = () => {
  const pond = useRef<FilePond | null>(null);

  function genLabel() {
    return renderToString(
      <FontAwesomeIcon
        style={{
          height: "4em",
          width: "4em",
        }}
        className="event-image-picker-icon" icon={faStar} size="2x" />
    )
  }

return (

    <FilePond
      ref={ref => { pond.current = ref }}
      labelIdle={genLabel()}
      ...
      />

multidest avatar May 20 '20 01:05 multidest

or just keep it simple. Just put a svg file there..

       <file-pond
  name="test"
  ref="pond"
  class="filepond"
  label-idle='<svg class="w-10 h-10 dark:text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 14l9-5-9-5-9 5 9 5z"></path><path d="M12 14l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 14l9-5-9-5-9 5 9 5zm0 0l6.16-3.422a12.083 12.083 0 01.665 6.479A11.952 11.952 0 0012 20.055a11.952 11.952 0 00-6.824-2.998 12.078 12.078 0 01.665-6.479L12 14zm-4 6v-7.5l4-2.222"></path></svg>'
  v-bind:allow-multiple="multiple"
  accepted-file-types="image/jpeg, image/png"
  :server="server"
  @addfile="addFile"
  @processfiles="processfiles"
  v-bind:files="myFiles"
  v-on:init="handleFilePondInit"
/>

thunderwin avatar Jan 18 '22 05:01 thunderwin

Is this dead?

oalexdoda avatar Jun 23 '22 17:06 oalexdoda