Back to cookbook

ChatGPT Prompt to Build a React Drag-and-Drop File Upload Component With Progress Bar

0 views Updated

Make this prompt yours

Share

This React drag-and-drop file upload component prompt is built for developers who need a working uploader with a drop zone, file previews, and a live progress bar without hand-rolling the drag events, validation, and state logic from scratch. It's aimed at anyone building a form, dashboard, or admin panel in React who wants ChatGPT, Claude, or Gemini to generate a component that handles drag-over styling, multiple file selection, type and size validation, and upload progress in one pass.

The prompt pushes the model to think through the parts developers usually forget: what happens when a user drags a file type that isn't allowed, how the drop zone should look mid-hover versus at rest, how progress updates while an upload is in flight, and how errors surface without crashing the form. It asks for accessible markup (a keyboard-triggerable file input and an ARIA live region for status updates) alongside the drag-and-drop behavior, so the output works for more than mouse-only users.

If you already have a visual reference for how the upload zone should look, such as a Figma frame or a live page with a drop zone you like, Site to Prompt can turn that rendered design into a prompt you can merge with this one, so the component's behavior and its visual spec come from the same source.

Prompt template

Make this prompt yours

prompt-template
385 tokens
ROLE You are a senior front-end engineer who specializes in React component architecture and accessible UI. CONTEXT I'm building a [FORM / DASHBOARD / ADMIN PANEL] in React using [REACT VERSION, e.g. React 18 with function components] and [STYLING APPROACH, e.g. Tailwind CSS / CSS Modules / styled-components]. I need a file upload component that supports drag-and-drop in addition to a standard click-to-browse input. REQUIREMENTS - Accept these file types: [ALLOWED FILE TYPES, e.g. .png, .jpg, .pdf] - Enforce a max file size of [MAX FILE SIZE] and a max file count of [MAX FILE COUNT] - Show a visually distinct drop zone state when a file is dragged over it - Display a progress bar per file while it uploads, using [UPLOAD METHOD, e.g. an onUploadProgress callback from axios, or XMLHttpRequest progress events] - Show clear success and error states per file, including a retry option on failure - Accept the actual upload function as a prop so the component is backend-agnostic - Be keyboard accessible: the file input must be triggerable without a mouse, and status changes must be announced via an ARIA live region CONSTRAINTS - Use only [ALLOWED LIBRARIES, e.g. no third-party upload libraries, or "react-dropzone is allowed"] - Keep the component in [SINGLE FILE / SPLIT INTO SUBCOMPONENTS] - Match this file naming and folder convention: [YOUR CONVENTION] OUTPUT FORMAT 1. The complete component code in a single fenced code block, with inline comments explaining the drag event handlers and progress logic 2. A short list of the props the component expects and what each one does 3. One sentence noting any edge case the implementation does not handle, if any

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
302 tokens
ROLE You are a senior front-end engineer who specializes in React component architecture and accessible UI. CONTEXT I'm building an admin panel in React using React 18 with function components and Tailwind CSS. I need a file upload component that supports drag-and-drop in addition to a standard click-to-browse input. REQUIREMENTS - Accept these file types: .png, .jpg, .pdf - Enforce a max file size of 5MB and a max file count of 10 - Show a visually distinct drop zone state when a file is dragged over it - Display a progress bar per file while it uploads, using an onUploadProgress callback from axios - Show clear success and error states per file, including a retry option on failure - Accept the actual upload function as a prop so the component is backend-agnostic - Be keyboard accessible: the file input must be triggerable without a mouse, and status changes must be announced via an ARIA live region CONSTRAINTS - Use only built-in React hooks, no third-party upload libraries - Keep the component in a single file - Match this file naming convention: FileUploadZone.jsx OUTPUT FORMAT 1. The complete component code in a single fenced code block, with inline comments explaining the drag event handlers and progress logic 2. A short list of the props the component expects and what each one does 3. One sentence noting any edge case the implementation does not handle, if any

When to use it

  • You're adding a file upload field to a React form and want drag-and-drop on top of the standard file picker
  • You need to show per-file upload progress instead of a single spinner for the whole batch
  • You're building an admin panel or CMS where editors upload images, PDFs, or CSVs regularly
  • You want validation (file type, size limits, max file count) handled in the component instead of on the server only

Best practices

  • Specify the exact file types and size limits you need (e.g. "PNG/JPG under 5MB, max 10 files") instead of letting the model guess generic defaults
  • Tell the model which state library you're using (plain useState, Zustand, Redux) so the generated hooks match your codebase instead of introducing a new pattern
  • Ask for the upload function to be passed in as a prop or callback rather than hardcoded, so the component stays reusable across different backends
  • Request separate states for "dragging over", "uploading", "success", and "error" explicitly, since models often collapse these into a single boolean and lose useful UI feedback

Common mistakes

  • Not specifying whether uploads should be sequential or parallel, which leads to a progress bar that jumps erratically when multiple files are uploading at once
  • Leaving out keyboard accessibility requirements, so the model ships a drop zone that only works with a mouse
  • Forgetting to ask for cleanup logic (removing object URLs, aborting in-flight requests) when a component unmounts mid-upload
  • Accepting the first draft without testing drag-over behavior when a file is dragged from outside the browser window, which some generated handlers miss

FAQs

How do I make a React drag-and-drop upload component accessible?

Explicitly ask the model for a keyboard-triggerable file input (role="button" with tabIndex and an Enter key handler) and an ARIA live region that announces status changes. Without that instruction, most generated drop zones only respond to mouse drag events.

Should I use react-dropzone or build the drag-and-drop logic myself?

Either works; state your preference in the prompt. Asking for a library-free version keeps the component dependency-light and easier to audit, while naming react-dropzone saves time if your project already uses it elsewhere.

How do I get per-file progress bars instead of one overall progress bar?

Specify that each file needs its own progress state tied to its own upload call, and name the progress mechanism you're using (axios onUploadProgress, fetch with a ReadableStream, or XMLHttpRequest). Leaving this unspecified is the most common reason generated components default to a single shared progress value.

Which Cuelara tool can help me catch edge cases this prompt might miss?

Prompt Debugger — run this prompt through it before using it to surface missing constraints like concurrent upload limits, duplicate file handling, or what happens on a dropped non-file drag event (like dragging a browser tab).

Found this prompt useful? Share it.

Share

More in React Prompt Recipes

React Prompt Recipes

AI Prompt to Turn a Design Screenshot into a React Component

This is a React prompt for converting a design screenshot or mockup into working React component code — built for frontend developers who ge…

ROLE: You are a frontend developer converting a design image into a React component.

CONTEXT: I'm attaching a design screenshot/mockup. Tech stack: [REACT VERSION, STYLING APPROACH e.g. Tailwind/CSS Modules/styled-components, COMPONENT LIBRARY IF ANY]

TASK:
1. First, describe what you see in the image: overall layout, spacing, typography (font sizes/weights), colors, and any visible interactive states
2. Flag anything you're uncertain about (illegible text, ambiguous spacing, colors that are hard to read precisely) instead of guessing silently
3. Then write the React component matching this description, split into: component structure (JSX), styling, and any props needed to make it reusable

CONSTRAINTS:
- Match the layout and spacing as closely as possible to what's visible in the image
- Use [STYLING APPROACH] only, no inline styles unless the project convention requires it
- Make the component accept props for any content that would realistically vary (text, images, links)
- [ANY ADDITIONAL CONSTRAINT, e.g. must be accessible, must support dark mode]

OUTPUT FORMAT:
1. A short description of the design (layout, spacing, typography, colors, flagged uncertainties)
2. The complete component code in a fenced code block
3. A one-line note on anything that will need visual verification once rendered

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Multi-Step Form Wizard With Validation

This is an AI prompt for building a React multi step form wizard : a form split across several steps with a progress indicator, per step val…

ROLE: You are a senior frontend engineer who specializes in React form architecture.

CONTEXT:
- Framework: [REACT VERSION, e.g. React 18 with hooks]
- Styling approach: [CSS MODULES / TAILWIND / STYLED-COMPONENTS]
- Form library preference: [NONE - PLAIN STATE / REACT HOOK FORM / FORMIK]
- Steps needed: [LIST EACH STEP AND ITS FIELDS, e.g. Step 1: Account (email, password). Step 2: Profile (name, company). Step 3: Preferences (plan, notifications)]
- Validation rules: [LIST RULES PER FIELD, e.g. email must be valid format, password min 8 characters]

TASK:
Build a multi-step form wizard component with the following requirements:
1. A shared state object holding data from all steps, so navigating back and forth never loses entered values
2. Per-step validation that blocks the "Next" button until the current step's required fields are valid, with inline error messages
3. A progress indicator showing the current step out of the total number of steps
4. Back and Next navigation, with Back always enabled (except on step 1) and Next disabled until validation passes
5. A final review step before submission showing a summary of all entered data, with the ability to jump back to any step to edit it
6. A loading/submitting state on final submit that disables the submit button to prevent double submission
7. Clear separation between step configuration (data) and the rendering logic, so adding or removing a step does not require rewriting the component

CONSTRAINTS:
- [SPECIFY ACCESSIBILITY REQUIREMENTS, e.g. keyboard navigable, ARIA labels on progress indicator]
- [SPECIFY WHETHER STATE SHOULD PERSIST ACROSS PAGE REFRESH, e.g. using localStorage or session state]
- [SPECIFY IF STEPS ARE CONDITIONAL, e.g. step 3 only appears if plan = enterprise]

OUTPUT FORMAT:
Provide the complete component code, broken into logical files or sections (step config, main wizard component, individual step components, validation logic). Add brief comments explaining the state flow between steps. After the code, list any assumptions made about fields or behavior that were not specified above.

Make this prompt yours

React Prompt Recipes

AI Prompt to Generate a React Component From a Figma File Using MCP

This prompt is for front end developers who want to turn a Figma design into working React code by connecting an AI model to Figma's MCP ser…

Role: You are a front-end developer with access to a Figma MCP connection.

Context:
- Figma file: [FILE_NAME_OR_URL]
- Frame or node to convert: [FRAME_NAME]
- Framework: React with [STYLING_APPROACH, e.g. Tailwind CSS]
- Component name: [COMPONENT_NAME]

Task:
1. Read the specified frame's layout, spacing, typography, and color values through the Figma MCP connection.
2. Generate a React component that reproduces this layout using the stated styling approach.
3. Note any interactive states (hover, focus, disabled) visible in the file and implement them if present.

Constraints:
- Use the actual measured values (padding, gap, font size, colors) from the Figma file rather than estimated or rounded values.
- Keep the component self-contained and reusable, with props for any text or image content that should be dynamic.
- Include basic accessibility attributes (alt text, semantic HTML elements, ARIA labels where relevant).
- Flag anything in the design that can't be cleanly translated to code (e.g. a custom font not available in the project).

Output format:
- Component code in a fenced code block
- Brief notes on any values that couldn't be read directly from Figma and were estimated
- List of interactive states implemented, or "None found in this frame"

Make this prompt yours