6.3 KiB
Component & Hook Library
Overview
WorkForce Pro now includes an extensive library of custom React hooks and UI components designed to streamline development and provide consistent user experiences across the platform.
📚 Custom Hooks Library
Categories
🔄 State Management (3 hooks)
useToggle- Boolean state with toggle functionusePrevious- Access previous state valueuseLocalStorage- Persist state in browser storage
⏱️ Async & Timing (3 hooks)
useAsync- Manage async operations with loading/error statesuseDebounce- Delay state updates for performanceuseThrottle- Limit function execution frequency
🖥️ UI & Interaction (8 hooks)
useMediaQuery- Responsive breakpoint detectionuseIsMobile- Mobile device detectionuseWindowSize- Window dimension trackinguseScrollPosition- Scroll position monitoringuseOnClickOutside- Outside click detectionuseIntersectionObserver- Element visibility detectionuseKeyboardShortcut- Global keyboard shortcutsuseIdleTimer- User idle state detection
📊 Data Management (4 hooks)
useFilter- Array filtering with debouncinguseSort- Array sorting with direction controlusePagination- Dataset paginationuseSelection- Multi-item selection management
📝 Forms (2 hooks)
useFormValidation- Form validation with error trackinguseWizard- Multi-step form/wizard management
🛠️ Utilities (2 hooks)
useCopyToClipboard- Clipboard operationsuseNotifications- Application notifications
Total: 22 Custom Hooks
🎨 Extended UI Components
New Components (17)
Display Components
- EmptyState - Empty state placeholder with customizable content
- StatusBadge - Status indicator with icon and label
- StatCard - Metric display card with trend indicators
- DataList - Key-value pair display
- Timeline - Event timeline with completion tracking
Input Components
- SearchInput - Search field with clear button
- FileUpload - Drag-and-drop file upload area
Navigation Components
- Stepper - Multi-step progress indicator
Feedback Components
- LoadingSpinner - Animated loading indicator
- LoadingOverlay - Full-screen loading state
- InfoBox - Contextual information display
Utility Components
- Chip - Removable tag component
- CopyButton - Copy-to-clipboard button
- CodeBlock - Code display with syntax highlighting
- Divider - Section divider with optional label
- Kbd - Keyboard shortcut display
- SortableHeader - Sortable table header
Existing shadcn Components (46)
- Accordion, Alert Dialog, Alert, Aspect Ratio, Avatar
- Badge, Breadcrumb, Button, Calendar, Card
- Carousel, Chart, Checkbox, Collapsible, Command
- Context Menu, Dialog, Drawer, Dropdown Menu, Form
- Hover Card, Input OTP, Input, Label, Menubar
- Navigation Menu, Pagination, Popover, Progress, Radio Group
- Resizable, Scroll Area, Select, Separator, Sheet
- Sidebar, Skeleton, Slider, Sonner, Switch
- Table, Tabs, Textarea, Toggle Group, Toggle, Tooltip
Total: 63 UI Components
🚀 Quick Start
Using Hooks
import { useDebounce, usePagination, useSelection } from '@/hooks'
function MyComponent() {
const [search, setSearch] = useState('')
const debouncedSearch = useDebounce(search, 300)
const { paginatedItems, nextPage, previousPage } = usePagination(items, 10)
const { selectedIds, toggleSelection, selectAll } = useSelection(items)
return (
// Your component JSX
)
}
Using UI Components
import { EmptyState, StatusBadge, SearchInput } from '@/components/ui'
import { FileX } from '@phosphor-icons/react'
function MyView() {
return (
<div>
<SearchInput
value={search}
onChange={(e) => setSearch(e.target.value)}
onClear={() => setSearch('')}
/>
<StatusBadge status="success" label="Active" />
<EmptyState
icon={<FileX size={48} />}
title="No results found"
description="Try adjusting your search"
/>
</div>
)
}
📖 Documentation
Detailed documentation available:
/src/hooks/README.md- Complete hook documentation with examples/src/components/ui/README.md- UI component reference
🎯 Common Use Cases
Data Tables
Combine useFilter, useSort, usePagination, and useSelection for full-featured data tables.
Multi-Step Forms
Use useWizard with Stepper component for intuitive form flows.
Search Functionality
Pair useDebounce with SearchInput for optimized search experiences.
Loading States
Use LoadingOverlay or LoadingSpinner with useAsync for async operations.
Status Display
Use StatusBadge consistently across the platform for status indicators.
Empty States
Always show meaningful EmptyState components when data is not available.
🔧 Development Guidelines
- Consistency - Use library components before creating custom ones
- Composition - Combine hooks and components for complex functionality
- Performance - Leverage
useDebounceanduseThrottlefor expensive operations - Accessibility - All components include ARIA attributes and keyboard support
- Styling - Extend components with Tailwind classes via
classNameprop
📦 Import Paths
// Hooks
import { hookName } from '@/hooks'
// UI Components
import { ComponentName } from '@/components/ui/component-name'
// Or use existing barrel exports
import { Button, Card, Dialog } from '@/components/ui'
🎨 Theming
All components respect the application theme defined in /src/index.css:
- Primary, secondary, accent colors
- Success, warning, error, info colors
- Border radius and spacing
- Typography scale
🔍 Finding Components
Need a component? Check these locations in order:
- New extended components:
/src/components/ui/README.md - shadcn components:
/src/components/ui/directory - Custom hooks:
/src/hooks/README.md
🤝 Contributing
When adding new hooks or components:
- Follow existing patterns and conventions
- Add TypeScript types for all props
- Include forwardRef for DOM components
- Support className for styling
- Document usage in respective README
- Export from index files