Introduction
Refine provides an integration with shadcn/ui components through a registry system. This integration offers a collection of pre-built components that seamlessly work with Refine's features while maintaining shadcn/ui's design principles and accessibility standards.
Unlike traditional package installations, shadcn/ui components are added to your project's source code, giving you full control over styling and customization.
Installation
The easiest way to get started is by using Refine's CLI to scaffold a new project with shadcn/ui:
npm create refine-app@latest my-app -- --preset vite-shadcn
Manual Setup
If you want to add shadcn/ui to an existing Refine project:
Install shadcn/ui in your project
Follow the shadcn/ui installation guide based on the React framework you're using with Refine:
Add Refine-specific components from the registry:
npx shadcn@latest add https://ui.refine.dev/r/auto-save-indicator.json
npx shadcn@latest add https://ui.refine.dev/r/create-view.json
npx shadcn@latest add https://ui.refine.dev/r/edit-view.json
Usage
Refine's shadcn/ui components are designed to work seamlessly with Refine's data hooks and provide common UI patterns needed in admin panels and data-heavy applications.
import { useForm } from "@refinedev/react-hook-form";
import { AutoSaveIndicator } from "@/components/refine-ui/form/auto-save-indicator";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
export function EditProduct() {
const {
register,
refineCore: { autoSaveProps },
} = useForm({
refineCoreProps: {
autoSave: { enabled: true, debounce: 1000 },
},
});
return (
<Card>
<CardHeader className="flex flex-row items-center justify-between">
<h2>Edit Product</h2>
<AutoSaveIndicator {...autoSaveProps} />
</CardHeader>
<CardContent className="space-y-4">
<div>
<label htmlFor="name">Product Name</label>
<Input id="name" {...register("name")} />
</div>
<div>
<label htmlFor="price">Price</label>
<Input id="price" type="number" {...register("price")} />
</div>
<Button type="submit">Save Product</Button>
</CardContent>
</Card>
);
}
Refine Component Registry
Refine provides a growing collection of components through the shadcn/ui registry system. Each component can be installed individually:
Form Components
- Forms - Complete form building guide with validation
- Auto Save Indicator - Visual feedback for auto-save operations
Data Components
- Data Table - Advanced data table with sorting, filtering, and pagination
Authentication Components
- Sign In Form - Ready-to-use sign-in form with validation
- Sign Up Form - Ready-to-use sign-up form with validation
- Forgot Password - Password reset form component
Layout Components
- Themed Layout - Complete layout wrapper with sidebar navigation, dark/light theme and responsive design.
View Components
- Create View - Create page layout with navigation and breadcrumb
- Edit View - Edit page layout with navigation and breadcrumb
- List View - List page layout with navigation and breadcrumb
- Show View - Detail page layout with navigation and breadcrumb
Button Components
- Create Button - Navigation button to create pages
- Edit Button - Navigation button to edit pages
- Delete Button - Button with delete confirmation dialog
- Show Button - Navigation button to show pages
- List Button - Navigation button to list pages
- Clone Button - Button to clone/duplicate records
- Refresh Button - Button to refresh data
Utility Components
- Error Component - Error boundary and error display component
- Notification Provider - Toast notification system
Key Features
🎨 Full Source Code Access: shadcn/ui components are copied directly into your project, giving you complete control over styling, behavior, and structure without package dependencies.
♿ Accessibility First: Built on Radix UI primitives with WAI-ARIA standards, ensuring robust accessibility support including keyboard navigation and screen reader compatibility.
🔧 Deep Refine Integration: Seamlessly works with Refine's data hooks, authentication, routing, and form handling - less boilerplate, more productivity.
📱 Responsive Design: Built with Tailwind CSS and mobile-first principles, components automatically adapt to any screen size.
🌙 Advanced Theming: Full light/dark theme support using CSS custom properties with flexible customization options.
🌍 Internationalization: Built-in support for Refine's i18n system with RTL languages, localization, and proper formatting.
Styling and Theming
Since components are added to your source code, you have complete control over styling. The components use shadcn/ui's theming system based on CSS variables, making it easy to customize colors, spacing, and appearance.
CSS Variables
The theme system uses HSL color values defined as CSS custom properties. These variables are automatically generated during the shadcn init
process and can be found in your globals.css
file:
:root {
--background: 0 0% 100%;
--foreground: 222.2 84% 4.9%;
--primary: 222.2 47.4% 11.2%;
--primary-foreground: 210 40% 98%;
--secondary: 210 40% 96%;
--muted: 210 40% 96%;
--accent: 210 40% 96%;
--destructive: 0 84.2% 60.2%;
--border: 214.3 31.8% 91.4%;
--input: 214.3 31.8% 91.4%;
--ring: 222.2 47.4% 11.2%;
--radius: 0.5rem;
}
.dark {
--background: 222.2 84% 4.9%;
--foreground: 210 40% 98%;
--primary: 210 40% 98%;
--primary-foreground: 222.2 47.4% 11.2%;
--secondary: 217.2 32.6% 17.5%;
--muted: 217.2 32.6% 17.5%;
--accent: 217.2 32.6% 17.5%;
--destructive: 0 62.8% 30.6%;
--border: 217.2 32.6% 17.5%;
--input: 217.2 32.6% 17.5%;
--ring: 212.7 26.8% 83.9%;
}
Theme Customization
You can customize your theme in several ways:
- Manual Editing: Modify the CSS variables in your
globals.css
file directly - Theme Generator: Use the shadcn/ui theme editor to generate custom themes
- Interactive Editor: Try the TweakCN Theme Editor for a visual approach to theme creation
Adding Custom Themes
To add additional themes beyond light and dark:
[data-theme="blue"] {
--primary: 221.2 83.2% 53.3%;
--primary-foreground: 210 40% 98%;
/* ... other variables */
}
[data-theme="green"] {
--primary: 142.1 76.2% 36.3%;
--primary-foreground: 355.7 100% 97.3%;
/* ... other variables */
}
For more detailed theming options, refer to the shadcn/ui theming documentation.