-
AI-powered Extensions
-
Data Grid
-
Tree List
-
Chat
-
HTML Editor
-
Form
-
-
Data Grids / Data Management
-
Data Grid
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Grouping
-
Selection
- Focused Row
- Paging
-
Scrolling
-
Columns
- AI Assistant
-
Master-Detail
-
Data Summaries
-
Drag & Drop
-
Export to PDF
-
Export to Excel
- Appearance
-
Customization
- State Persistence
-
Adaptability
-
Keyboard Navigation
- Right-To-Left Support
-
Tree List
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Selection
- Focused Row
- Paging
-
Columns
- Drag & Drop
- State Persistence
- Adaptability
-
Keyboard Navigation
-
Card View
-
Pivot Grid
- Overview
-
Data Binding
-
Field Management
-
Data Summaries
- Drill Down
- Filtering
-
Scrolling
-
Export to Excel
- Chart Integration
- Customization
- State Persistence
-
Filter Builder
-
-
Data Visualization
-
Charts
- Overview
-
Data Binding
-
Common Concepts
-
Axis
-
Aggregation
-
Tooltips
-
Selection
-
Customization
-
Zooming
-
Export
-
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Funnel and Pyramid Charts
-
Line Charts
- Pareto Chart
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
- Sankey Chart
-
Sparkline Charts
-
Tree Map
-
Gauges
- Overview
-
Runtime update
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
-
Scheduling / Planning
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Appointments
-
Timetable
- Editing
-
Grouping
- Virtual Scrolling
- Drag & Drop
-
Customization
- Adaptability
-
Gantt
- Overview
- Data Binding
-
Filtering
- Sorting
- Strip Lines
- Export to PDF
- Validation
-
Customization
-
-
Messaging
-
WYSIWYG Editor
-
Forms
-
Data Editors
- Overview
-
Common Concepts
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Number Box
- Radio Group
-
Range Selector
- Range Slider
- Slider
- Switch
- Text Area
- Text Box
-
Drop-Downs
- Autocomplete
-
Drop Down Box
-
Select Box
-
Tag Box
-
Lookup
-
Buttons
-
File Upload / File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Popup and Notifications
-
Navigation
- Overview
- Accordion
-
Action Sheet
-
Context Menu
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
-
Stepper
- Pagination
-
List
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Box
- Responsive Box
-
-
Interactive Wrappers
-
Sortable
- Resizable
-
-
Progress Indicators
-
Maps
- Overview
-
Map
-
Vector Map
-
Data Binding
- Multiple Layers
-
Markers
- Legend
-
Zooming and Panning
-
Customization
-
-
Localization
Related Demos:
Your search did not match any results.
React File Uploader - Custom Drop Zone
The FileUploader component supports the drag-and-drop functionality to upload files.
In this demo, the dropZone property specifies the HTML element in which you can drag and drop files for upload. The dropZoneEnter and dropZoneLeave events allow you to customize the drop zone when the mouse pointer enters and leaves this zone while dragging the file.
Backend API
import React, { useCallback, useState } from 'react';
import FileUploader from 'devextreme-react/file-uploader';
import type { FileUploaderTypes } from 'devextreme-react/file-uploader';
import ProgressBar from 'devextreme-react/progress-bar';
const allowedFileExtensions: string[] = ['.jpg', '.jpeg', '.gif', '.png'];
export default function App() {
const [isDropZoneActive, setIsDropZoneActive] = useState<boolean>(false);
const [imageSource, setImageSource] = useState<string>('');
const [textVisible, setTextVisible] = useState<boolean>(true);
const [progressVisible, setProgressVisible] = useState<boolean>(false);
const [progressValue, setProgressValue] = useState<number>(0);
const onDropZoneEnter = useCallback(({ component, dropZoneElement, event }): void => {
if (dropZoneElement.id === 'dropzone-external') {
const items = event.originalEvent.dataTransfer.items;
const currentAllowedFileExtensions = component.option('allowedFileExtensions');
const draggedFileExtension = `.${items[0].type.replace(/^image\//, '')}`;
const isSingleFileDragged = items.length === 1;
const isValidFileExtension = currentAllowedFileExtensions.includes(draggedFileExtension);
if (isSingleFileDragged && isValidFileExtension) {
setIsDropZoneActive(true);
}
}
}, []);
const onDropZoneLeave = useCallback((e: FileUploaderTypes.DropZoneLeaveEvent): void => {
if (e.dropZoneElement.id === 'dropzone-external') {
setIsDropZoneActive(false);
}
}, []);
const onUploaded = useCallback((e: FileUploaderTypes.UploadedEvent): void => {
const { file } = e;
const fileReader = new FileReader();
fileReader.onload = (): void => {
setIsDropZoneActive(false);
setImageSource(fileReader.result as string);
};
fileReader.readAsDataURL(file);
setTextVisible(false);
setProgressVisible(false);
setProgressValue(0);
}, []);
const onProgress = useCallback((e: FileUploaderTypes.ProgressEvent): void => {
setProgressValue((e.bytesLoaded / e.bytesTotal) * 100);
}, []);
const onUploadStarted = useCallback(() => {
setImageSource('');
setProgressVisible(true);
}, []);
return (
<div className="widget-container flex-box">
<span>Profile Picture</span>
<div id="dropzone-external" className={`flex-box ${isDropZoneActive ? 'dropzone-active' : ''}`}>
{imageSource && <img id="dropzone-image" src={imageSource} alt="" />}
{textVisible && (
<div id="dropzone-text" className="flex-box">
<span>Drag & Drop the desired file</span>
<span>…or click to browse for a file instead.</span>
</div>
)}
<ProgressBar
id="upload-progress"
min={0}
max={100}
width="30%"
showStatus={false}
visible={progressVisible}
value={progressValue}
></ProgressBar>
</div>
<FileUploader
id="file-uploader"
dialogTrigger="#dropzone-external"
dropZone="#dropzone-external"
multiple={false}
allowedFileExtensions={allowedFileExtensions}
uploadMode="instantly"
uploadUrl="https://js.devexpress.com/Demos/NetCore/FileUploader/Upload"
visible={false}
onDropZoneEnter={onDropZoneEnter}
onDropZoneLeave={onDropZoneLeave}
onUploaded={onUploaded}
onProgress={onProgress}
onUploadStarted={onUploadStarted}
></FileUploader>
</div>
);
}
import React, { useCallback, useState } from 'react';
import FileUploader from 'devextreme-react/file-uploader';
import ProgressBar from 'devextreme-react/progress-bar';
const allowedFileExtensions = ['.jpg', '.jpeg', '.gif', '.png'];
export default function App() {
const [isDropZoneActive, setIsDropZoneActive] = useState(false);
const [imageSource, setImageSource] = useState('');
const [textVisible, setTextVisible] = useState(true);
const [progressVisible, setProgressVisible] = useState(false);
const [progressValue, setProgressValue] = useState(0);
const onDropZoneEnter = useCallback(({ component, dropZoneElement, event }) => {
if (dropZoneElement.id === 'dropzone-external') {
const items = event.originalEvent.dataTransfer.items;
const currentAllowedFileExtensions = component.option('allowedFileExtensions');
const draggedFileExtension = `.${items[0].type.replace(/^image\//, '')}`;
const isSingleFileDragged = items.length === 1;
const isValidFileExtension = currentAllowedFileExtensions.includes(draggedFileExtension);
if (isSingleFileDragged && isValidFileExtension) {
setIsDropZoneActive(true);
}
}
}, []);
const onDropZoneLeave = useCallback((e) => {
if (e.dropZoneElement.id === 'dropzone-external') {
setIsDropZoneActive(false);
}
}, []);
const onUploaded = useCallback((e) => {
const { file } = e;
const fileReader = new FileReader();
fileReader.onload = () => {
setIsDropZoneActive(false);
setImageSource(fileReader.result);
};
fileReader.readAsDataURL(file);
setTextVisible(false);
setProgressVisible(false);
setProgressValue(0);
}, []);
const onProgress = useCallback((e) => {
setProgressValue((e.bytesLoaded / e.bytesTotal) * 100);
}, []);
const onUploadStarted = useCallback(() => {
setImageSource('');
setProgressVisible(true);
}, []);
return (
<div className="widget-container flex-box">
<span>Profile Picture</span>
<div
id="dropzone-external"
className={`flex-box ${isDropZoneActive ? 'dropzone-active' : ''}`}
>
{imageSource && (
<img
id="dropzone-image"
src={imageSource}
alt=""
/>
)}
{textVisible && (
<div
id="dropzone-text"
className="flex-box"
>
<span>Drag & Drop the desired file</span>
<span>…or click to browse for a file instead.</span>
</div>
)}
<ProgressBar
id="upload-progress"
min={0}
max={100}
width="30%"
showStatus={false}
visible={progressVisible}
value={progressValue}
></ProgressBar>
</div>
<FileUploader
id="file-uploader"
dialogTrigger="#dropzone-external"
dropZone="#dropzone-external"
multiple={false}
allowedFileExtensions={allowedFileExtensions}
uploadMode="instantly"
uploadUrl="https://js.devexpress.com/Demos/NetCore/FileUploader/Upload"
visible={false}
onDropZoneEnter={onDropZoneEnter}
onDropZoneLeave={onDropZoneLeave}
onUploaded={onUploaded}
onProgress={onProgress}
onUploadStarted={onUploadStarted}
></FileUploader>
</div>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.tsx';
// eslint-disable-next-line import/no-unresolved
import 'anti-forgery';
ReactDOM.render(
<App />,
document.getElementById('app'),
);
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
import 'anti-forgery';
ReactDOM.render(<App />, document.getElementById('app'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" />
<link rel="stylesheet" type="text/css" href="./bundle.css" />
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="app"></div>
</div>
<script src="bundles/vendor/react.vendor.js"></script>
<script src="./bundle.js"></script>
</body>
</html>
#dropzone-external {
width: 350px;
height: 350px;
background-color: rgba(0,0,0,0.08);
border-width: 2px;
border-style: dashed;
padding: 10px;
border-color: var(--dx-color-border);
}
#dropzone-external > * {
pointer-events: none;
}
#dropzone-external.dropzone-active {
border-style: solid;
border-color: var(--dx-color-primary);
}
.widget-container > span {
font-size: 22px;
font-weight: bold;
margin-bottom: 16px;
}
#dropzone-image {
max-width: 100%;
max-height: 100%;
}
#upload-progress {
display: flex;
margin-top: 10px;
}
.flex-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
Allowed file extensions: .jpg, .jpeg, .gif, .png
Maximum file size: 4 MB