Component Library
This document provides an overview of the reusable components available in the Rhesis frontend application.
Component Organization
Components are organized in the following directory structure:
Core Components
Layout Components
AppLayout
The main application layout wrapper used for authenticated pages.
Usage:
AuthLayout
Layout for authentication pages (login, register, etc.).
Usage:
Navigation Components
Sidebar
Main navigation sidebar with collapsible sections.
Props:
isOpen
:boolean
- Controls whether the sidebar is expanded or collapsedonToggle
:() => void
- Callback when the sidebar toggle button is clicked
Navbar
Top navigation bar with user menu, notifications, and search.
Props:
user
:User
- Current user objectonSearch
:(query: string) => void
- Search callback
Data Display Components
DataTable
Reusable table component with sorting, filtering, and pagination.
Props:
columns
:Column[]
- Column definitionsdata
:any[]
- Table datapagination
:PaginationProps
- Pagination configurationonSort
:(field: string, direction: 'asc' | 'desc') => void
- Sort callbackonFilter
:(filters: Record<string, any>) => void
- Filter callback
DataGrid
Advanced data grid component using MUI X Data Grid.
Props:
rows
:any[]
- Grid datacolumns
:GridColDef[]
- Column definitionspageSize
:number
- Number of rows per pageloading
:boolean
- Loading state
Card
Wrapper component for content cards.
Props:
title
:string
- Card titlesubtitle
:string
- Optional card subtitleactions
:React.ReactNode
- Optional action buttons/menuchildren
:React.ReactNode
- Card content
Form Components
TextField
Enhanced text input component.
Props:
label
:string
- Input labelvalue
:string
- Input valueonChange
:(e: React.ChangeEvent<HTMLInputElement>) => void
- Change handlererror
:string
- Optional error messagehelperText
:string
- Optional helper text...MuiTextFieldProps
- All MUI TextField props are supported
Select
Enhanced select component.
Props:
label
:string
- Select labeloptions
:{ label: string, value: string | number }[]
- Select optionsvalue
:string | number
- Selected valueonChange
:(value: string | number) => void
- Change handler...MuiSelectProps
- All MUI Select props are supported
Button
Enhanced button component with variants.
Props:
variant
:'primary' | 'secondary' | 'danger' | 'ghost'
- Button variantsize
:'small' | 'medium' | 'large'
- Button sizeloading
:boolean
- Loading state...MuiButtonProps
- All MUI Button props are supported
Feedback Components
Alert
Component for displaying alerts and notifications.
Props:
severity
:'success' | 'info' | 'warning' | 'error'
- Alert typetitle
:string
- Alert titlemessage
:string
- Alert messageonClose
:() => void
- Close handler
Dialog
Modal dialog component.
Props:
open
:boolean
- Controls dialog visibilityonClose
:() => void
- Close handlertitle
:string
- Dialog titleactions
:React.ReactNode
- Dialog action buttonschildren
:React.ReactNode
- Dialog content
Visualization Components
LineChart
Line chart component using Recharts.
Props:
data
:any[]
- Chart dataxKey
:string
- X-axis data keyyKeys
:{ key: string, name: string, color: string }[]
- Y-axis data keysheight
:number
- Chart height
BarChart
Bar chart component using Recharts.
Props:
data
:any[]
- Chart dataxKey
:string
- X-axis data keyyKeys
:{ key: string, name: string, color: string }[]
- Y-axis data keysheight
:number
- Chart height
FlowChart
Interactive flow chart using React Flow.
Props:
nodes
:Node[]
- Flow nodesedges
:Edge[]
- Flow edgesonNodesChange
:(changes: NodeChange[]) => void
- Node change handleronEdgesChange
:(changes: EdgeChange[]) => void
- Edge change handler
Using Components
When using components from the library, import them directly from their respective directories:
Component Best Practices
- Use TypeScript Props Interfaces: Define clear prop interfaces for all components
- Component Documentation: Include JSDoc comments for all components
- Default Props: Provide sensible default props where applicable
- Error Handling: Include proper error states and fallbacks
- Accessibility: Ensure components meet WCAG accessibility standards
- Responsive Design: Components should work across different screen sizes
- Performance: Use React.memo for expensive components when appropriate
Creating New Components
When creating new components:
- Place them in the appropriate directory based on their purpose
- Create a clear and concise TypeScript interface for props
- Include comprehensive JSDoc documentation
- Add appropriate test cases
- Consider reusability and composability