# Darwin UI - Complete Documentation > Darwin UI is a macOS-inspired React component library featuring glass-morphism aesthetics, dark theme (with light mode support), and Tailwind CSS integration. It provides 36+ production-ready components with Framer Motion animations and full accessibility support. ## Quick Reference | Resource | URL | |----------|-----| | Documentation | https://darwin-ui.mandalsuraj.com | | GitHub | https://github.com/surajmandalcell/darwin-ui | | NPM | https://www.npmjs.com/package/@pikoloo/darwin-ui | | Context7 (AI) | https://context7.com/surajmandalcell/darwin-ui | ## Installation ```bash npm install @pikoloo/darwin-ui # or pnpm add @pikoloo/darwin-ui # or yarn add @pikoloo/darwin-ui ``` ### Setup Import the CSS in your app entry point: ```tsx // app.tsx or main.tsx import '@pikoloo/darwin-ui/styles.css'; import { Button, Card, Window } from '@pikoloo/darwin-ui'; ``` The stylesheet is precompiled in v2.1 and later; no Tailwind `@source` directive is required. --- ## Layout & Navigation Components ### Accordion Collapsible content sections with smooth Framer Motion animations **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/accordion](https://darwin-ui.mandalsuraj.com/docs/components/accordion) **Props**: - `items: { title, content }[]` - `defaultOpen?: number` - `allowMultiple?: boolean` **Example**: ```tsx ``` ### Card Glass-morphism container with header, content, and footer sections **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/card](https://darwin-ui.mandalsuraj.com/docs/components/card) **Props**: - `children` - `className?: string` - `variant?: "default" | "glass"` **Example**: ```tsx Title Body content Footer actions ``` ### Sidebar Navigation sidebar with collapsible mode, tooltips, and active state indicators **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/sidebar](https://darwin-ui.mandalsuraj.com/docs/components/sidebar) **Props**: - `items: SidebarItem[]` - `collapsed?: boolean` - `onCollapse?: () => void` **Example**: ```tsx ``` ### Tabs Tabbed navigation with animated indicator and keyboard support **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/tabs](https://darwin-ui.mandalsuraj.com/docs/components/tabs) **Props**: - `tabs: { label, content }[]` - `defaultIndex?: number` - `onChange?: (index) => void` **Example**: ```tsx Content 1 }, { label: 'Tab 2', content: Content 2 } ]} /> ``` ### Window macOS-style window chrome with traffic light buttons (close, minimize, maximize) **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/window](https://darwin-ui.mandalsuraj.com/docs/components/window) **Props**: - `title?: string` - `children` - `onClose?: () => void` - `onMinimize?: () => void` **Example**: ```tsx Window content goes here ``` --- ## Form & Input Components ### Button Versatile button with 10 variants (primary, secondary, ghost, etc.) and 3 sizes **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/button](https://darwin-ui.mandalsuraj.com/docs/components/button) **Props**: - `variant?: ButtonVariant` - `size?: "sm" | "md" | "lg"` - `disabled?: boolean` - `loading?: boolean` **Example**: ```tsx Click Me ``` ### Checkbox Checkbox with indeterminate state support and spring animations **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/checkbox](https://darwin-ui.mandalsuraj.com/docs/components/checkbox) **Props**: - `checked?: boolean` - `indeterminate?: boolean` - `onChange?: (checked) => void` - `label?: string` **Example**: ```tsx ``` ### Input Text input with validation states (error, success), icons, and clear button **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/input](https://darwin-ui.mandalsuraj.com/docs/components/input) **Props**: - `value?: string` - `onChange?: (e) => void` - `error?: string` - `success?: boolean` - `icon?: ReactNode` **Example**: ```tsx setEmail(e.target.value)} error={errors.email} /> ``` ### SearchInput Search input with magnifying glass icon and clear functionality **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/search-input](https://darwin-ui.mandalsuraj.com/docs/components/search-input) **Props**: - `value?: string` - `onChange?: (value) => void` - `onSearch?: (value) => void` - `placeholder?: string` **Example**: ```tsx console.log(query)} /> ``` ### Select Dropdown select with custom styling and keyboard navigation **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/select](https://darwin-ui.mandalsuraj.com/docs/components/select) **Props**: - `options: { value, label }[]` - `value?: string` - `onChange?: (value) => void` - `placeholder?: string` **Example**: ```tsx ``` ### MultiSelect Multi-selection dropdown with tag display and search filtering **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/multi-select](https://darwin-ui.mandalsuraj.com/docs/components/multi-select) **Props**: - `options: Option[]` - `value?: string[]` - `onChange?: (values) => void` - `searchable?: boolean` **Example**: ```tsx ``` ### Slider Range slider with customizable track, thumb, and step values **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/slider](https://darwin-ui.mandalsuraj.com/docs/components/slider) **Props**: - `value?: number` - `onChange?: (value) => void` - `min?: number` - `max?: number` - `step?: number` **Example**: ```tsx ``` ### Switch Toggle switch with spring physics animation **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/switch](https://darwin-ui.mandalsuraj.com/docs/components/switch) **Props**: - `checked?: boolean` - `onChange?: (checked) => void` - `disabled?: boolean` - `label?: string` **Example**: ```tsx ``` ### Textarea Multi-line text input with auto-resize and character count **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/textarea](https://darwin-ui.mandalsuraj.com/docs/components/textarea) **Props**: - `value?: string` - `onChange?: (e) => void` - `autoResize?: boolean` - `maxLength?: number` **Example**: ```tsx setDescription(e.target.value)} autoResize placeholder="Enter description..." /> ``` ### DateSelect Date picker with calendar interface and range selection support **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/date-select](https://darwin-ui.mandalsuraj.com/docs/components/date-select) **Props**: - `value?: Date` - `onChange?: (date) => void` - `minDate?: Date` - `maxDate?: Date` **Example**: ```tsx ``` ### Upload File upload with drag-and-drop support and file type validation **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/upload](https://darwin-ui.mandalsuraj.com/docs/components/upload) **Props**: - `accept?: string` - `multiple?: boolean` - `onUpload?: (files) => void` - `maxSize?: number` **Example**: ```tsx handleUpload(files)} multiple /> ``` ### ContactForm Pre-built contact form with name, email, message fields and validation **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/contact-form](https://darwin-ui.mandalsuraj.com/docs/components/contact-form) **Props**: - `onSubmit?: (data) => void` - `loading?: boolean` **Example**: ```tsx { await sendMessage(data); }} /> ``` --- ## Feedback & Overlay Components ### Alert Inline alerts and modal-style alert dialogs with semantic variants **Documentation**: [https://darwin-ui.mandalsuraj.com/docs#alert](https://darwin-ui.mandalsuraj.com/docs#alert) **Props**: - `variant?: "info" | "success" | "warning" | "error"` - `title?: string` - `children` **Example**: ```tsx Your changes have been saved. ``` ### Badge Status badges with semantic colors and optional dot indicator **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/badge](https://darwin-ui.mandalsuraj.com/docs/components/badge) **Props**: - `variant?: BadgeVariant` - `size?: "sm" | "md"` - `dot?: boolean` **Example**: ```tsx Active Pending ``` ### Dialog Modal dialog with focus trap, portal rendering, and backdrop click dismiss **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/dialog](https://darwin-ui.mandalsuraj.com/docs/components/dialog) **Props**: - `open?: boolean` - `onClose?: () => void` - `title?: string` - `children` **Example**: ```tsx setIsOpen(false)} title="Confirm"> Are you sure? Yes ``` ### DropdownMenu Full-featured dropdown menu with keyboard navigation, submenus, and separators **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/dropdown-menu](https://darwin-ui.mandalsuraj.com/docs/components/dropdown-menu) **Props**: - `trigger: ReactNode` - `items: MenuItem[]` - `align?: "start" | "end"` **Example**: ```tsx Actions} items={[ { label: 'Edit', onClick: handleEdit }, { label: 'Delete', onClick: handleDelete, variant: 'danger' } ]} /> ``` ### Modal Modal dialog with glass-morphism backdrop and smooth animations **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/modal](https://darwin-ui.mandalsuraj.com/docs/components/modal) **Props**: - `isOpen?: boolean` - `onClose?: () => void` - `size?: "sm" | "md" | "lg"` **Example**: ```tsx setShowModal(false)}> Modal Title Content here ``` ### Popover Flexible popover with portal support and multiple placement options **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/popover](https://darwin-ui.mandalsuraj.com/docs/components/popover) **Props**: - `content: ReactNode` - `trigger: ReactNode` - `placement?: Placement` **Example**: ```tsx Show Info} content={Popover content} placement="bottom" /> ``` ### Toast Toast notification system with auto-dismiss and action buttons **Documentation**: [https://darwin-ui.mandalsuraj.com/docs#toast](https://darwin-ui.mandalsuraj.com/docs#toast) **Props**: - `message: string` - `variant?: ToastVariant` - `duration?: number` - `action?: { label, onClick }` **Example**: ```tsx // Using the toast function toast.success('File uploaded successfully'); toast.error('Failed to save changes'); toast.info('Processing...', { duration: 5000 }); ``` ### Tooltip Accessible tooltip with multiple positions and delay options **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/tooltip](https://darwin-ui.mandalsuraj.com/docs/components/tooltip) **Props**: - `content: string | ReactNode` - `children` - `side?: "top" | "bottom" | "left" | "right"` **Example**: ```tsx } /> ``` ### ContextMenu Right-click context menu with keyboard support **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/context-menu](https://darwin-ui.mandalsuraj.com/docs/components/context-menu) **Props**: - `items: MenuItem[]` - `children` **Example**: ```tsx Right-click me ``` --- ## Data Display Components ### Avatar User avatar with image fallback to initials and group stacking **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/avatar](https://darwin-ui.mandalsuraj.com/docs/components/avatar) **Props**: - `src?: string` - `alt?: string` - `fallback?: string` - `size?: "sm" | "md" | "lg"` **Example**: ```tsx ``` ### Charts SVG-based charts: Line, Bar, Area, Pie, Donut, and Stacked Bar with animations **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/charts](https://darwin-ui.mandalsuraj.com/docs/components/charts) **Props**: - `data: ChartData[]` - `width?: number` - `height?: number` - `colors?: string[]` **Example**: ```tsx ``` ### Image Image component with lazy loading and click-to-enlarge lightbox **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/image](https://darwin-ui.mandalsuraj.com/docs/components/image) **Props**: - `src: string` - `alt: string` - `enlargeable?: boolean` - `aspectRatio?: string` **Example**: ```tsx ``` ### Progress Linear and circular progress indicators with animated fill **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/progress](https://darwin-ui.mandalsuraj.com/docs/components/progress) **Props**: - `value: number` - `max?: number` - `variant?: "linear" | "circular"` - `showLabel?: boolean` **Example**: ```tsx ``` ### Skeleton Loading placeholder with shimmer animation effect **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/skeleton](https://darwin-ui.mandalsuraj.com/docs/components/skeleton) **Props**: - `width?: string | number` - `height?: string | number` - `variant?: "text" | "circular" | "rectangular"` **Example**: ```tsx ``` ### Table Data table with sorting, selection, and loading states **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/table](https://darwin-ui.mandalsuraj.com/docs/components/table) **Props**: - `columns: Column[]` - `data: T[]` - `sortable?: boolean` - `selectable?: boolean` - `loading?: boolean` **Example**: ```tsx ``` --- ## Utility Components ### CloseButton Red close button matching macOS traffic light style **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/close-button](https://darwin-ui.mandalsuraj.com/docs/components/close-button) **Props**: - `onClick?: () => void` - `size?: "sm" | "md"` **Example**: ```tsx handleClose()} /> ``` ### MdEditor Markdown editor with live preview and toolbar **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/md-editor](https://darwin-ui.mandalsuraj.com/docs/components/md-editor) **Props**: - `value?: string` - `onChange?: (value) => void` - `preview?: boolean` **Example**: ```tsx ``` ### Reveal Scroll-triggered reveal animations with multiple effects **Documentation**: [https://darwin-ui.mandalsuraj.com/docs/components/reveal](https://darwin-ui.mandalsuraj.com/docs/components/reveal) **Props**: - `children` - `animation?: "fade" | "slide" | "scale"` - `delay?: number` - `once?: boolean` **Example**: ```tsx Content that animates in on scroll ``` --- ## Animation System Darwin UI uses Framer Motion with a configurable animation system. ### Duration Presets | Key | Duration | Use Case | |-----|----------|----------| | instant | 0s | No animation | | fast | 0.1s | Quick interactions | | normal | 0.15s | Standard transitions | | slow | 0.2s | Deliberate animations | | reveal | 0.4s | Page reveals | ### Spring Presets | Preset | Description | |--------|-------------| | snappy | Quick, responsive feel | | smooth | Natural, fluid motion | | gentle | Soft, subtle movement | ### Configuration ```tsx import { configureAnimations } from '@pikoloo/darwin-ui'; // Disable all animations (e.g., for testing) configureAnimations({ enabled: false }); // Customize durations configureAnimations({ durations: { fast: 0.05, normal: 0.1, slow: 0.15 } }); // Disable specific animation types configureAnimations({ disable: { hover: true, scale: true } }); ``` The library automatically respects the `prefers-reduced-motion` system preference. --- ## Theming Darwin UI uses CSS custom properties (HSL format) for theming. ### Color Variables ```css :root { --background: 0 0% 100%; --foreground: 0 0% 3.9%; --card: 0 0% 100%; --primary: 0 0% 9%; --secondary: 0 0% 96.1%; --muted: 0 0% 96.1%; --accent: 0 0% 96.1%; --border: 0 0% 89.8%; } .dark { --background: 0 0% 3.9%; --foreground: 0 0% 98%; /* ... dark theme values */ } ``` ### Usage in Components ```tsx Themed content ``` --- ## Hooks ### useMediaQuery `useMediaQuery(query: string): boolean` Responsive design hook that returns true when media query matches ### useIsMobile `useIsMobile(): boolean` Returns true when viewport is below 768px (mobile breakpoint) ### useEscapeKey `useEscapeKey(callback: () => void): void` Calls callback when Escape key is pressed, useful for modal dismissal ### useContactForm `useContactForm(config): FormState` Form handling hook with built-in validation for contact forms --- ## Utility Functions ### cn `cn(...classes): string` Tailwind class merging utility using clsx and tailwind-merge ### prefersReducedMotion `prefersReducedMotion(): boolean` Check if user prefers reduced motion ### getDuration `getDuration(key): number` Get animation duration respecting reduced motion preference ### getSpring `getSpring(preset): SpringConfig` Get spring animation config (snappy, smooth, gentle) ### configureAnimations `configureAnimations(config): void` Configure global animation settings (disable, customize durations) --- ## Common Patterns ### Form with Validation ```tsx import { Input, Button, Alert } from '@pikoloo/darwin-ui'; function LoginForm() { const [email, setEmail] = useState(""); const [error, setError] = useState(""); const handleSubmit = (e: FormEvent) => { e.preventDefault(); if (!email.includes("@")) { setError("Invalid email address"); return; } // Submit logic }; return ( setEmail(e.target.value)} error={error} placeholder="Email" /> Sign In ); } ``` ### Modal with Confirmation ```tsx import { Modal, Button } from '@pikoloo/darwin-ui'; function ConfirmDialog({ isOpen, onClose, onConfirm }) { return ( Confirm Action Are you sure you want to proceed? Cancel Delete ); } ``` --- *Generated automatically. For the most up-to-date documentation, visit the links above.*
Window content goes here
Are you sure?
Are you sure you want to proceed?