OnFrameDragEnter: function(event): Callback when the user begins dragging over the frame. Not available in IE :(įrame: document || HTMLElement (default: document): This is the scope or "frame" that the user must drag some file(s) over to kick things off. OnTargetClick: function(event): Callback when the user clicks anywhere on the target.ĭropEffect - string "copy" || "move" || "link" || "none" (default: "copy"): Learn more about HTML5 dropEffects. Removes the file-drop-dragging-over-target class from the file-drop-target. OnDragLeave: function(event): Callback when the user leaves the target. Also adds the file-drop-dragging-over-target class to the file-drop-target. OnDragOver: function(event): Callback when the user is dragging over the target. OnDrop: function(files, event): Callback when the user drops files onto the target file-drop-target.file-drop-dragging-over-target: This class will be added to the target whenever the user begins dragging a file over the target, and it will be removed when they leave Props file-drop-target.file-drop-dragging-over-frame: This class will be added to the target whenever the user begins dragging a file over the frame, and it will be removed when they leave file-drop-target: This is the target the user has to drag their files to. You can grab the demo CSS to get started.įor custom class names (if you're using something like JSS) you can use the following props: Stylingīy default, the component comes with no styles. Below you can find instruction how to do that. You can also define an onTargetClick prop if you want to let user browse their files from disk. Next, define an onDrop prop, whenever a user drops their files onto the target, this callback will be triggered. Import from 'react-file-drop' How it worksįirst, you define the frame prop (default is the document), whenever the user begins dragging file(s) anywhere over this frame, the target will get a file-drop-dragging-over-frame class name, and the onFrameDragEnter callback will fire. None! (well, just prop-types, but that should already be removed from your prod bundle anyway) Browser support I couldn't find any React component that already did this, so, I made one! Dependencies have where a part of the page highlights immediately when you start dragging a file anywhere on the window. I wanted that behavior that facebook, gmail, etc. A very simple live demo with example code and sample CSS Why? Drag files anywhere onto the window (or user defined 'frame' prop)! Very extensible, provides a hook for every event so you can use it to develop any custom behavior that you want. It is not recommended to use this option if you plan on sending the file contents to a server via AJAX.Įxample Usage: $('#myElement').Zero dependency React component for Gmail or Facebook -like drag and drop file uploader. This is useful for pure JavaScript applications where you might want to parse file contents directly in the browser. Enabling this option will decode the base64 data into the raw file contents. When JavaScript reads the file data, it comes back as base64 encoded data. It is recommended to keep this option enabled unless you need to work with dropped images in JavaScript. When this option is enabled, this will be removed from the base64 string so that the pure base64 data can be processed or sent to a server. When JavaScript reads the file data, it comes back as base64 encoded data which begins with something like 'data:text/plain base64,'. Of course, you can specify a different element with this option if needed. By default whatever you select with jQuery to will also have addClassTo applied to it. This is the element that will have the CSS class set with the overClass option applied to it. When files are dragged over the browser window, this is the CSS class that will be applied to the selected element or the element specified with the addClassTo option. This function can optionally be the only argument passed if you do not need to specify any other options. This option is required! You must provide a function to process the collection of file object that will be returned as the only argument. You may either pass in a function to loop over the collection of file (as in the example above) or you may pass in an option object if you need to be more specific.
0 Comments
Leave a Reply. |