/** * Radix UI Component Template * * This template provides a starting point for creating * custom components with Radix UI primitives. * * Replace [PRIMITIVE] with actual primitive name: * Dialog, DropdownMenu, Select, Tabs, Tooltip, etc. */ import * as [PRIMITIVE] from '@radix-ui/react-[primitive]'; import { cva, type VariantProps } from 'class-variance-authority'; import { cn } from '@/lib/utils'; // ============================================================================ // Variants Definition (using CVA) // ============================================================================ const [component]Variants = cva( // Base styles (always applied) "base-styles-here", { variants: { // Define your variants variant: { default: "default-styles", secondary: "secondary-styles", destructive: "destructive-styles", }, size: { sm: "small-size-styles", md: "medium-size-styles", lg: "large-size-styles", }, }, defaultVariants: { variant: "default", size: "md", }, } ); // ============================================================================ // TypeScript Interfaces // ============================================================================ interface [Component]Props extends React.ComponentPropsWithoutRef, VariantProps { // Add custom props here } // ============================================================================ // Component Implementation // ============================================================================ export function [Component]({ variant, size, className, children, ...props }: [Component]Props) { return ( <[PRIMITIVE].Root {...props}> {/* Trigger */} <[PRIMITIVE].Trigger asChild> {/* Portal (if needed) */} <[PRIMITIVE].Portal> {/* Overlay (for Dialog, etc.) */} <[PRIMITIVE].Overlay className="overlay-styles" /> {/* Content */} <[PRIMITIVE].Content className="content-styles"> {/* Required accessibility parts */} <[PRIMITIVE].Title className="title-styles"> Title <[PRIMITIVE].Description className="description-styles"> Description {/* Your content */}
{/* ... */}
{/* Close button */} <[PRIMITIVE].Close asChild> ); } // ============================================================================ // Sub-components (if needed) // ============================================================================ [Component].[SubComponent] = function [SubComponent]({ className, ...props }: React.ComponentPropsWithoutRef) { return ( <[PRIMITIVE].[SubComponent] className={cn("subcomponent-styles", className)} {...props} /> ); }; // ============================================================================ // Usage Example // ============================================================================ /* import { [Component] } from './[component]'; function App() { return ( <[Component] variant="default" size="md"> Trigger Content