Generate one React function component from your requirements, with typed props, accessible markup, relevant loading/error/empty states, a usage example and tests.
You are a React developer. Write one component from the requirements below. Match the project's styling and conventions, make it usable with a keyboard and screen reader, and include tests. Scaffolding tools that generate many components are a separate task.
## Inputs
Component purpose, props and behaviour: [REQUIREMENTS]
React version and framework (Vite, Next.js App Router, Remix): [REACT_STACK]
Styling approach (Tailwind CSS, CSS Modules, a component library): [STYLING]
Data source: props only, or fetched data with loading and error states: [DATA_SOURCE]
Existing conventions (file naming, exports, testing library): [CONVENTIONS]
## Instructions
1. Write a function component with a TypeScript props interface. Mark optional props and document defaults.
2. Keep the component focused on one responsibility; extract a custom hook only if logic is reused or complex.
3. Include loading, error and empty states only when the component loads data or can receive empty data.
4. Use semantic HTML and the ARIA attributes the pattern requires; make every interaction keyboard accessible.
5. Decide whether inputs are controlled or uncontrolled and say why.
6. In Next.js App Router, mark the file with `"use client"` only if it uses state, effects or browser APIs.
7. Style with [STYLING].
## Return
1. Component code with the props interface.
2. Usage example.
3. Custom hook, if any.
4. Tests with React Testing Library (or [CONVENTIONS]) covering rendering, interaction and accessibility roles.
5. Brief notes on key design decisions.
## Example output format
```tsx
interface PaginationProps {
// Props here
}
export function Pagination({ page, totalPages, onPageChange }: PaginationProps) {
// Implementation
}
```
## Acceptance checks
- Props are typed without `any`.
- Every interactive element is reachable and operable by keyboard and has an accessible name.
- Tests query by role or label rather than CSS classes.
- Behaviour at boundaries (first, last, empty) is defined.Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Requirements: Pagination control; props page (1-based), totalPages, onPageChange(page), optional siblingCount (default 1); shows first, last, current with siblings, and ellipses; Previous/Next buttons React stack: React 19 with Next.js App Router Styling: Tailwind CSS Data source: props only Conventions: named exports, Vitest + React Testing Library
A "use client" Pagination component inside <nav aria-label="Pagination"> with button elements, aria-current="page" on the current page, Previous disabled on page 1 and Next disabled on the last page, ellipses rendered as non-interactive text hidden from assistive technology, siblingCount defaulting to 1, nothing rendered (or a defined fallback) when totalPages is 0 or 1, and tests that click page buttons by accessible name and assert onPageChange arguments. No loading or error state because data comes from props. Illustrative expectation, not a recorded model run.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts:
Author-supplied tool and model tags; confirm behavior with your own examples.
IDEs
Models