Version: 5.xx.xx
Source CodeList
<ListView /> provides us a layout to display the page. It does not contain any logic but adds extra functionalities like action buttons and giving titles to the page.
The ListView component is designed for displaying a list of records with automatic resource detection, breadcrumb navigation, and an optional create button.
Installationβ
npx shadcn@latest add https://ui.refine.dev/r/views.json
This will install all view components including ListView.
Usageβ
import {
ListView,
ListViewHeader,
} from "@/components/refine-ui/views/list-view";
import { LoadingOverlay } from "@/components/refine-ui/layout/loading-overlay";
export default function PostListPage() {
const isLoading = false; // or true, based on your data fetching state
const error = null; // or object, based on your data fetching state
if (error) {
return (
<ListView>
<ListViewHeader />
{/* Error content */}
</ListView>
);
}
return (
<ListView>
<ListViewHeader />
<LoadingOverlay loading={isLoading}>
{/* Record content (e.g., DataTable) */}
</LoadingOverlay>
</ListView>
);
}
Featuresβ
- Resource Integration: Automatic resource detection and title generation
- Breadcrumb Navigation: Built-in breadcrumb component
- Optional Create Button:
CreateButton(frombuttonspackage) is displayed based on resource definition orcanCreateprop
API Referenceβ
ListView Propertiesβ
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Content to render inside the view |
className | string | - | Additional CSS classes for the container |
ListViewHeader Propertiesβ
| Prop | Type | Default | Description |
|---|---|---|---|
resource | string | Current resource | Override the resource name for title and actions |
title | string | Auto-generated | Custom title for the header |
hideBreadcrumb | boolean | false | Set to true to hide the breadcrumb |
wrapperClassName | string | - | CSS classes for the header's main wrapper div |
headerClassName | string | - | CSS classes for the div containing title and actions |
canCreate | boolean | Resource default | Manually control visibility of the create button |
Advanced Usageβ
Custom Title and Actionsβ
import {
ListView,
ListViewHeader,
} from "@/components/refine-ui/views/list-view";
import { Button } from "@/components/ui/button";
export default function PostListPage() {
return (
<ListView>
<ListViewHeader title="My Custom Posts List" canCreate={false} />
{/* Your list content */}
</ListView>
);
}
Hide Breadcrumbβ
<ListViewHeader hideBreadcrumb={true} />
Custom CSS Classesβ
<ListView className="my-custom-list">
<ListViewHeader
wrapperClassName="custom-header-wrapper"
headerClassName="custom-header-content"
/>
</ListView>