Back to cookbook

ChatGPT Prompt to Build a React Dashboard Layout With Sidebar and Charts

0 views Updated

Make this prompt yours

Share

This React dashboard layout prompt helps developers get a working admin or analytics dashboard scaffold out of ChatGPT, Claude, or Gemini in one pass, instead of assembling a sidebar, header, and chart grid from scratch. It is built for frontend developers and indie hackers who need a responsive dashboard shell — collapsible sidebar navigation, a top bar, and a content grid that holds chart widgets and summary cards — without re-explaining layout rules every time they prompt.

The prompt forces the model to commit to specific decisions up front: a CSS layout strategy (flexbox or CSS grid), a breakpoint behavior for the sidebar on mobile, and a charting library choice, rather than leaving those as vague suggestions buried in prose. It also asks for the component broken into clearly named pieces (Sidebar, Topbar, ChartCard, StatCard) so the output drops into an existing codebase instead of arriving as one monolithic file.

Because dashboard layouts are judged as much by how they look as by how the JSX is structured, it helps to start from an actual visual reference rather than a text description alone. If you already have a dashboard design, mockup, or a competitor's live dashboard you want to match, Site to Prompt can turn that rendered page into a structured prompt describing its layout, spacing, and component breakdown, which you can then merge with this prompt's constraints.

Prompt template

Make this prompt yours

prompt-template
364 tokens
Role: You are a senior frontend engineer specializing in React and responsive dashboard UIs. Context: - Framework: [REACT VERSION, e.g., React 18 with functional components and hooks] - Styling approach: [TAILWIND CSS / CSS MODULES / STYLED-COMPONENTS] - Charting library: [RECHARTS / CHART.JS / NIVO] - Dashboard purpose: [e.g., SaaS analytics dashboard showing revenue, active users, and churn] Task: Build a dashboard layout with the following structure: 1. A collapsible sidebar with navigation links: [LIST OF NAV ITEMS] 2. A top bar with [e.g., page title, search input, user avatar menu] 3. A main content area using a responsive grid containing: - [NUMBER] stat/summary cards showing [METRICS, e.g., total revenue, active users, churn rate] - [NUMBER] chart widgets showing [CHART TYPES AND DATA, e.g., a line chart of revenue over time, a bar chart of signups by month] Constraints: - Break the output into separate components: Sidebar, Topbar, ChartCard, StatCard, and a parent DashboardLayout component. - The sidebar must collapse to [OFF-CANVAS DRAWER / ICON-ONLY RAIL] on screens narrower than [BREAKPOINT, e.g., 768px]. - Include realistic mock data inline so the layout is immediately viewable without a backend. - Use semantic HTML where applicable (nav, main, aside, header). Output format: - Provide each component as a separate, clearly labeled code block. - List any npm packages that need to be installed before the code will run. - End with a short note on what to replace with real API data.

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
288 tokens
Role: You are a senior frontend engineer specializing in React and responsive dashboard UIs. Context: - Framework: React 18 with functional components and hooks - Styling approach: Tailwind CSS - Charting library: Recharts - Dashboard purpose: SaaS analytics dashboard showing revenue, active users, and churn Task: Build a dashboard layout with the following structure: 1. A collapsible sidebar with navigation links: Overview, Customers, Revenue, Settings 2. A top bar with page title, a search input, and a user avatar menu 3. A main content area using a responsive grid containing: - 3 stat cards showing total revenue, active users, and churn rate - 2 chart widgets showing a line chart of revenue over the last 12 months and a bar chart of new signups by month Constraints: - Break the output into separate components: Sidebar, Topbar, ChartCard, StatCard, and a parent DashboardLayout component. - The sidebar must collapse to an off-canvas drawer on screens narrower than 768px. - Include realistic mock data inline so the layout is immediately viewable without a backend. - Use semantic HTML where applicable. Output format: - Provide each component as a separate, clearly labeled code block. - List any npm packages that need to be installed before the code will run. - End with a short note on what to replace with real API data.

When to use it

  • You're starting a new internal tool, admin panel, or analytics dashboard and need a working layout scaffold fast.
  • You want a responsive sidebar-plus-content layout that collapses to a mobile nav without hand-rolling the breakpoint logic.
  • You need chart and stat-card placeholders wired up with a specific charting library (Recharts, Chart.js, or Nivo) instead of generic divs.
  • You're prototyping a dashboard concept for a client or stakeholder demo and need something visually presentable within the hour.

Best practices

  • Name the exact charting library you want (Recharts, Chart.js, Nivo) — leaving it open usually gets you a library you don't already have installed.
  • Specify the sidebar's collapsed-state behavior on mobile (off-canvas drawer vs. icon-only rail) since models default inconsistently between the two.
  • Ask for mock/sample data inline in the component so you can see the layout render immediately, then swap in real API data afterward.
  • Request Tailwind or plain CSS explicitly to match your project's existing styling approach rather than letting the model pick.

Common mistakes

  • Asking for "a dashboard" with no component breakdown, which produces one giant unmaintainable file instead of separate Sidebar, Topbar, and ChartCard components.
  • Forgetting to specify a state management approach for sidebar collapse/expand, leading to prop-drilling that's painful to refactor later.
  • Not specifying a charting library, which often results in placeholder divs labeled "chart goes here" instead of actual chart code.
  • Skipping responsive breakpoints entirely, so the sidebar overlaps content or disappears completely on smaller viewports.

FAQs

How do I get ChatGPT to generate a React dashboard that's actually responsive?

Be explicit about the breakpoint and the exact collapse behavior you want (off-canvas drawer vs. icon rail), since without that detail the model often writes CSS that looks fine on desktop but breaks or overlaps content on narrower screens.

Which charting library works best for AI-generated React dashboards?

Recharts tends to produce the cleanest AI-generated code because its component API maps closely to plain English descriptions of charts, but Chart.js and Nivo both work well if you name them explicitly in the prompt rather than leaving the choice open.

Can I get the dashboard split into separate component files instead of one big file?

Yes — ask directly for named components (Sidebar, Topbar, ChartCard, StatCard) as separate code blocks, since models default to a single monolithic component unless the file structure is specified.

How do I turn an existing dashboard design into a prompt instead of describing it from scratch?

If you have a live reference dashboard or a rendered design you want to match, measuring its actual layout is more reliable than describing it from memory in text.

Site to Prompt — measures a real rendered webpage's layout, spacing, and components and turns it into a structured prompt, which pairs well with this template when you're matching an existing dashboard's look. Prompt Builder — turns a plain description of the dashboard you want into a complete structured prompt if you'd rather start from a description than this template.

Found this prompt useful? Share it.

Share

More in React Prompt Recipes

React Prompt Recipes

AI Prompt to Build a React Authentication Flow With Protected Routes

This AI prompt for a React authentication flow generates the pieces a typical app needs to gate pages behind a login: a login form, an auth…

ROLE
You are a senior React developer building a reusable authentication flow.

CONTEXT
Framework: [REACT_VERSION, e.g. React 18]
Routing library: [ROUTING_LIBRARY_AND_VERSION, e.g. React Router v6]
Backend auth endpoints: [LOGIN_ENDPOINT], [LOGOUT_ENDPOINT], [SESSION_CHECK_ENDPOINT]
Token storage method: [TOKEN_STORAGE_METHOD, e.g. httpOnly cookie set by the server]
Styling approach: [STYLING_APPROACH, e.g. Tailwind CSS]

TASK
Generate the following, using functional components and hooks:
1. An AuthContext and AuthProvider that exposes the current user, a loading flag, and login/logout functions.
2. A login form component that calls the login function and displays validation and API errors.
3. A ProtectedRoute component that redirects unauthenticated users to [LOGIN_ROUTE_PATH], preserving the originally requested URL for post-login redirect.
4. On initial app load, verify any existing session before rendering protected routes, showing a loading indicator during the check.

CONSTRAINTS
- Do not render protected page content until the session check has completed.
- Handle network and 401 errors from the auth endpoints gracefully, with user-facing messages.
- Keep components small and composable; do not put API calls directly inside UI components.

OUTPUT FORMAT
Provide each file separately with a filename comment at the top, followed by a 2-3 sentence summary of how the pieces connect together.

Make this prompt yours

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 an Accessible React Modal Component

This prompt generates an accessible React modal component , built for frontend developers who need a dialog that actually works with keyboar…

ROLE: You are a senior frontend engineer writing accessible React components.

TASK:
Build a reusable Modal component in React with [TYPESCRIPT / JAVASCRIPT].

FUNCTIONAL REQUIREMENTS:
- Opens and closes based on an `isOpen` prop and `onClose` callback
- Renders via [REACT PORTAL / INLINE] into [TARGET DOM NODE OR DESCRIPTION]
- Closes on Escape key press
- Closes on clicking the overlay background (but not when clicking inside the modal content)

ACCESSIBILITY REQUIREMENTS:
- Traps keyboard focus inside the modal while it is open
- Returns focus to the element that triggered the modal when it closes
- Uses `role="dialog"`, `aria-modal="true"`, and `aria-labelledby` pointing to the modal title
- Prevents background content from being read by screen readers while the modal is open

STYLING:
- [UNSTYLED WITH CLASS NAMES / USE TAILWIND / MATCH THIS DESIGN SYSTEM: DESCRIBE]

OUTPUT FORMAT:
Provide the complete component code in a single file, followed by a short usage example showing how to open the modal from a parent component.

Make this prompt yours