Layouts
Relevant source files- .devin/wiki.json
- README.md
- src/layouts/DashLayout.tsx
- src/layouts/LayoutBlock.tsx
- src/layouts/SplitBlock.tsx
@ui8kit/core architecture: DashLayout, LayoutBlock, and SplitBlock. These are template-level components (organisms) that orchestrate Layer 2 UI components and Layer 1 primitives into structural page layouts. This page focuses on layout composition patterns, content hook systems, and special considerations for building application structures.
For basic layout primitives (Grid, Flex, Stack), see Core Components.For UI components used within layouts, see UI Components.
For API details and prop references, see Layout Components API.
Layout Architecture Overview
The layout system operates at the highest architectural layer, composing UI components and primitives into complete page structures. The three layout components serve distinct structural purposes:DashLayout - Dashboard Template
DashLayout provides a complete dashboard structure with resizable panels, navigation header, and collapsible sidebar. It uses react-resizable-panels for interactive panel management.
Component Structure
Key Interfaces and Props
| Interface | Purpose | Key Props |
|---|---|---|
DashboardProps | Main layout configuration | page, children, sidebar, navbarProps |
NavbarProps | Header configuration | isDarkMode, toggleDarkMode, brand |
SidebarProps | Sidebar configuration | children, title, dataClass |
Implementation Details
TheDashboard component at src/layouts/DashLayout.tsx64-91 orchestrates the layout:
- Navbar renders at top with theme toggle at src/layouts/DashLayout.tsx34-49
- PanelGroup with
direction="horizontal"creates resizable layout at src/layouts/DashLayout.tsx75-88 - Panel components define sidebar (20% default, 10-40% range) and content area (80% default, 50% minimum) at src/layouts/DashLayout.tsx76-86
- PanelResizeHandle enables interactive resizing at src/layouts/DashLayout.tsx80
- Container wraps main content with responsive sizing at src/layouts/DashLayout.tsx84
Usage Pattern
autoSaveId="dashlayout-panels" at src/layouts/DashLayout.tsx75
Sources: src/layouts/DashLayout.tsx1-99 README.md155-168
LayoutBlock - Flexible Content Sections
LayoutBlock is a versatile layout component that renders content sections with three layout modes (grid, flex, stack) and a powerful content hook system for dynamic rendering.
Layout Modes and Configuration
Content Hook System
The content hook system at src/layouts/LayoutBlock.tsx22-30 allows replacing any part of the rendered content:| Hook | Purpose | Signature |
|---|---|---|
beforeHeader | Content before header section | (content: any) => ReactNode |
header | Custom header renderer | (content: any) => ReactNode |
afterHeader | Content after header section | (content: any) => ReactNode |
beforeItems | Content before items list | (content: any) => ReactNode |
item | Custom item renderer | (item: any, index: number) => ReactNode |
afterItems | Content after items list | (content: any) => ReactNode |
Default Renderers
The component provides default renderers at src/layouts/LayoutBlock.tsx123-227:- DefaultHeaderRenderer at src/layouts/LayoutBlock.tsx87-121 - Renders badge, title, and description with alignment
- DefaultItemRenderers.gridCard at src/layouts/LayoutBlock.tsx126-166 - Card-based grid items with images/icons
- DefaultItemRenderers.gridSimple at src/layouts/LayoutBlock.tsx169-196 - Minimal grid items without cards
- DefaultItemRenderers.flexItem at src/layouts/LayoutBlock.tsx199-226 - Horizontal group layout for flex/stack modes
Configuration Props
| Prop Category | Props | Purpose |
|---|---|---|
| Layout Control | layout, useContainer, containerSize | Mode and container settings |
| Grid Settings | cols, gridCols, gap, align, justify | CSS Grid configuration |
| Flex Settings | wrap, flexWrap | Flexbox wrapping behavior |
| Stack Settings | stackAlign | Vertical alignment |
| Header Settings | showHeader, headerAlign | Header display and alignment |
| Content Data | content, content.items | Data structure for rendering |
| Customization | contentHooks | Custom render functions |
Content Data Structure
Thecontent prop at src/layouts/LayoutBlock.tsx61-77 follows this schema:
Layout Mode Rendering
The rendering logic at src/layouts/LayoutBlock.tsx298-353 selects the appropriate layout component:data-class attributes for DOM targeting at src/layouts/LayoutBlock.tsx320-348
Usage Examples
Grid with Cards:SplitBlock - Two-Column Split Layout
SplitBlock creates two-column layouts with flexible media and content sections, commonly used for hero sections, feature showcases, and content/image combinations.
Layout Modes
Content Hook System
Similar toLayoutBlock, SplitBlock supports content hooks at src/layouts/SplitBlock.tsx11-15:
| Hook | Purpose | Signature |
|---|---|---|
beforeContent | Content before main section | (content: any) => ReactNode |
content | Main content renderer | (content: any) => ReactNode |
afterContent | Content after main section | (content: any) => ReactNode |
Slots API
The slots API at src/layouts/SplitBlock.tsx36-42 provides named overrides:Configuration Props
| Prop | Type | Default | Purpose |
|---|---|---|---|
mediaSection | ReactNode | - | Content for media column |
contentSection | ReactNode | - | Content for content column |
leftMedia | boolean | false | Position media on left side |
splitSection | boolean | true | Use full-width grid vs container |
containerSize | ContainerSizingProps["size"] | "lg" | Container size (when splitSection=false) |
gap | VariantGridProps["gap"] | "lg" | Gap between columns |
align | VariantGridProps["align"] | "center" | Vertical alignment |
Layout Rendering Logic
The rendering logic at src/layouts/SplitBlock.tsx94-136 creates two distinct layouts: Container Mode (splitSection=false) at src/layouts/SplitBlock.tsx96-111:
- Wraps grid in responsive
Container - Applies
containerSizeandpaddingprops - Suitable for standard page sections
splitSection=true) at src/layouts/SplitBlock.tsx115-135:
- Grid directly after
Blockwith no container - Uses
data-class="split-grid"for identification at src/layouts/SplitBlock.tsx129 - Applies
flex-1 items-centerfor full viewport height
Column Order
The column order is determined byleftMedia prop at src/layouts/SplitBlock.tsx106-107 and src/layouts/SplitBlock.tsx131-132:
leftMedia=true:[mediaSection, contentSection]leftMedia=false:[contentSection, mediaSection]
Usage Examples
Basic Split with Media:Layout Primitives Integration
Layout components extensively use Layer 1 primitives for structure. Understanding these primitives is essential for working with layouts.Grid Component
Used byLayoutBlock (grid mode) and SplitBlock for CSS Grid layouts:
cols="1-2-3"- Responsive 1/2/3 columnscols="2"- Fixed 2 columnsgap="lg"- Large gap between itemsalign="center"- Center items vertically
Stack Component
Used byLayoutBlock (stack mode) and within content sections for vertical layouts:
| Prop | Values | Purpose |
|---|---|---|
gap | "sm", "md", "lg", "xl", "2xl", "3xl" | Vertical spacing |
align | "start", "center", "end" | Horizontal alignment |
ta | "left", "center", "right" | Text alignment |
Block Component
All layout components useBlock as the root semantic container:
component prop at src/layouts/DashLayout.tsx16 src/layouts/DashLayout.tsx36 and src/layouts/DashLayout.tsx74 ensures semantic HTML structure (<section>, <nav>, <aside>, <main>).
Sources: src/layouts/LayoutBlock.tsx3-16 src/layouts/SplitBlock.tsx3-8 src/layouts/DashLayout.tsx2
Composition Patterns
Layout components follow specific composition patterns for building complex structures.Pattern 1: Nested Layout Composition
Layouts can be nested to create complex page structures:
Example:
Pattern 2: Container Management
Layouts useContainer component for responsive width control:
| Layout | Container Usage | When Used |
|---|---|---|
DashLayout | Always uses Container at src/layouts/DashLayout.tsx84 | Wraps main content panel |
LayoutBlock | Optional via useContainer prop at src/layouts/LayoutBlock.tsx259 | Default true, can disable for full-width |
SplitBlock | Conditional via splitSection prop at src/layouts/SplitBlock.tsx94-112 | Used when splitSection=false |
Pattern 3: Content Hook Override
The content hook system enables progressive enhancement:
Fallback Chain:
- Check for custom
contentHooks.itemat src/layouts/LayoutBlock.tsx302 - Fall back to default renderer at src/layouts/LayoutBlock.tsx285
- Apply layout-specific defaults at src/layouts/LayoutBlock.tsx230-254
Pattern 4: Slot-Based Overrides
SplitBlock slots provide targeted customization without full content hooks:
Pattern 5: Data-Driven Rendering
Layouts accept structured data and render automatically:- Header rendering from
content.badge/title/description - Item iteration and rendering from
content.items - Layout wrapping based on
layoutmode
Special Considerations
Semantic HTML Structure
Layout components enforce semantic HTML5 structure:| Component | Root Element | Purpose |
|---|---|---|
DashLayout | <nav> + <main> | Navigation header + main content at src/layouts/DashLayout.tsx36-74 |
DashLayout.Sidebar | <aside> | Sidebar navigation at src/layouts/DashLayout.tsx16 |
LayoutBlock | <section> | Content sections at src/layouts/LayoutBlock.tsx366 |
SplitBlock | <section> | Split content sections at src/layouts/SplitBlock.tsx97-117 |
Data-Class Attributes
All layouts applydata-class attributes for consistent DOM targeting:
| Component | Data-Class Value | Location |
|---|---|---|
DashLayout.Navbar | data-role="dash-navbar" | src/layouts/DashLayout.tsx36 |
DashLayout.Sidebar | Custom via prop | src/layouts/DashLayout.tsx16 |
LayoutBlock | data-class="layout-block" | src/layouts/LayoutBlock.tsx371 |
LayoutBlock Grid | data-class="layout-grid" | src/layouts/LayoutBlock.tsx320 |
LayoutBlock Flex | data-class="layout-flex" | src/layouts/LayoutBlock.tsx333 |
LayoutBlock Stack | data-class="layout-stack" | src/layouts/LayoutBlock.tsx344 |
SplitBlock Grid | data-class="split-grid" | src/layouts/SplitBlock.tsx129 |
Responsive Behavior
Layouts handle responsive design through variant props: Grid Responsive Columns:cols="1-2-3"creates mobile→tablet→desktop breakpoints- Automatically collapses to 1 column on mobile
- Scales to 2 columns on tablet (
md:) - Expands to 3 columns on desktop (
lg:)
containerSize="lg"appliesmax-w-7xlwith breakpoint adjustments- Automatically adds horizontal padding on mobile
- Centers content with
mx="auto"
- Sidebar:
defaultSize={20},minSize={10},maxSize={40}at src/layouts/DashLayout.tsx76 - Content:
defaultSize={80},minSize={50}at src/layouts/DashLayout.tsx82 - Sizes persisted via
autoSaveIdat src/layouts/DashLayout.tsx75
Performance Considerations
Item Key Management: TheLayoutBlock component requires unique id in content items at src/layouts/LayoutBlock.tsx66 for efficient React reconciliation. Keys are applied at src/layouts/LayoutBlock.tsx306
Memoization Opportunities: Content hooks and renderers are evaluated on every render. For expensive computations, wrap in useMemo:
DashLayout automatically persists panel sizes to localStorage via react-resizable-panels, reducing layout shift on reload.
External Dependencies
| Component | Dependency | Purpose | Installation |
|---|---|---|---|
DashLayout | react-resizable-panels | Resizable panel system | npm install react-resizable-panels |
| All layouts | lucide-react | Optional icon components | npm install lucide-react |