Back to cookbook

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

0 views Published

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 Billing Dashboard Component Using Stripe's MCP Server

This prompt is for frontend developers who need to build a React billing dashboard component that shows a customer's live subscription, invo…

ROLE:
You are a senior React/TypeScript developer building a billing dashboard component for a SaaS product.

CONTEXT:
The component should display billing data for a customer, retrieved via Stripe's MCP server: [LIST_DATA_NEEDED_E.G._SUBSCRIPTION_PLAN_NEXT_CHARGE_DATE_PAYMENT_METHOD_RECENT_INVOICES]
Framework/styling: [REACT_VERSION_AND_STYLING_APPROACH_E.G._TAILWIND_CSS_MODULES]

CONSTRAINTS:
- Handle these billing states explicitly: [LIST_STATES_E.G._ACTIVE_PAST_DUE_CANCELED_PENDING_NO_PAYMENT_METHOD]
- Show a loading skeleton while data is being fetched, and a clear error state if the fetch fails
- Format currency and dates using the customer's actual locale/currency, not a hardcoded format
- Separate the data-fetching hook from the presentational component

OUTPUT FORMAT:
1. A short explanation of the component's structure (hook + presentational component)
2. The full TypeScript code, in a single fenced code block, with comments marking where each billing state is handled
3. A one-line note on any assumption you made about the data shape returned by the MCP server

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Dark Mode Toggle with System Preference Detection

A React dark mode toggle prompt asks ChatGPT, Claude, or Gemini to generate a theme switching component that respects the user's OS level li…

Role: You are a senior React developer building a reusable UI component.

Context:
Framework/setup: [REACT VERSION, e.g. React 18 with Vite, Next.js App Router]
Styling approach: [CSS variables / Tailwind CSS dark class / CSS-in-JS library]
Component location/usage: [where the toggle will live, e.g. app header, settings page]

Task:
Build a dark mode toggle component with this exact behavior:
1. On first load, detect the user's OS preference via the `prefers-color-scheme` media query and use it as the initial theme, applied before the main content paints (no flash of the wrong theme).
2. If the user has previously made an explicit choice, that stored choice overrides the OS preference on future visits.
3. Persist the user's explicit choice in [STORAGE MECHANISM, e.g. localStorage].
4. Listen for theme changes made in other open tabs and update this tab's theme to match.
5. Expose the current theme and a toggle function via [CONTEXT/HOOK NAME, e.g. a useTheme hook] so other components can read and react to it.

Constraints:
- Use [STYLING APPROACH] to apply the theme, not inline style objects
- Include accessible labeling (aria-label or visible text) that reflects the current state
- Keep the component dependency-free unless [ALLOWED LIBRARIES] are specified

Output format:
Return the full component code in a fenced code block, followed by a short usage example showing how to wrap the app and consume the hook elsewhere.

Make this prompt yours

React Prompt Recipes

AI Prompt to Build a React Kanban Board With Drag-and-Drop

This prompt gives ChatGPT, Claude, or Gemini a complete specification for building a React Kanban board with drag and drop column reordering…

You are a senior React developer specializing in accessible, production-ready UI components.

Context:
- Framework: [REACT VERSION, e.g. React 18 with TypeScript]
- Drag-and-drop library: [LIBRARY NAME, e.g. @dnd-kit/core]
- Styling approach: [e.g. Tailwind CSS, CSS Modules, styled-components]
- Columns or workflow stages: [LIST OF COLUMN NAMES, e.g. Backlog, In Progress, Review, Done]
- State source: [e.g. local state, Zustand store, REST API endpoint]

Build a Kanban board component with the following requirements:
1. Render one column per workflow stage listed above, each showing its card count
2. Support dragging cards between columns and reordering cards within a column
3. Support keyboard-based reordering, not mouse-only interaction, for accessibility
4. Identify cards by a stable [ID FIELD NAME] field, never by array index
5. Call a [CALLBACK NAME] function on every successful move, passing the card id, source column, destination column, and new index
6. Show an optimistic UI update immediately, then roll back if [CALLBACK NAME] rejects
7. Handle empty columns and drops outside any valid column gracefully

Output format:
- The main board component
- Column and Card subcomponents
- Any custom hooks used for drag state
- A short usage example showing how to wire [CALLBACK NAME] to a real API call
- Brief notes on any library-specific setup required, such as providers, context, or CSS imports

Make this prompt yours