Advanced Workflow
Relevant source filesPurpose and Scope
This document covers non-standard scenarios where the 15 composite UI components from src/components/ui/ are insufficient for your use case. You will learn how to compose the five core primitives (Block, Box, Grid, Flex, Stack) from src/core/ui/ to build custom interfaces.
For typical component usage with ready-made composites, see Basic Workflow. For general usage guidelines and patterns, see Best Practices.
Sources: .devin/wiki.json191-198 src/components/GUIDE_CREATE_FORM.md1-10
When to Use Advanced Workflow
The library provides 15 composite components that cover ~80% of common UI scenarios. However, certain elements are intentionally absent from the library:| Missing Component Type | Reason for Absence | Advanced Solution |
|---|---|---|
| Form elements (Form, Label, Input) | HTML semantics vary widely | Compose Block + Box with component prop |
| Select dropdowns | Requires complex state management | Use Box component="select" with variants |
| Custom interactive widgets | Application-specific logic | Build with primitives + variants |
| Non-standard layouts | Unique structural requirements | Compose Grid, Flex, Stack directly |
Building Forms with Block and Box
The library does not include dedicated Form, Label, or Input components. Instead, use the polymorphiccomponent prop on Block and Box to render semantic HTML elements with the full variant system.
Component Prop Pattern
Thecomponent prop transforms primitives into any HTML element while maintaining type-safe variant props:
Form Structure Pattern
UseBlock with component="form" as the form wrapper, applying layout and styling variants:
Form Container Structure:
| Element | Component | Props | Purpose |
|---|---|---|---|
| Form wrapper | <Block component="form"> | w, maxW, p, rounded, shadow, bg | Semantic form container with layout |
| Field groups | <Block> | w="full", className="space-y-2" | Vertical field spacing |
| Labels | <Box component="label"> | c, className="text-sm font-medium" | Accessible field labels |
| Inputs | <Box component="input"> | w="full", p, rounded, border, borderColor | Form input fields |
| Textareas | <Box component="textarea"> | w="full", p, rounded, border, minH | Multi-line text input |
| Submit button | <Button> | w="full", size, variant | Form submission |
Input Field Patterns
All input types useBox with component="input" and standard HTML attributes:
Text Input (src/components/GUIDE_CREATE_FORM.md37-50):
Textarea Fields
UseBox with component="textarea" for multi-line text input:
Basic Textarea (src/components/GUIDE_CREATE_FORM.md99-115):
Complete Form Example
Contact Form Architecture:- Form event handling:
onSubmitprop on form Block - Field structure: Block wrapper → label → input in each group
- Spacing:
className="space-y-6"on form,className="space-y-2"on field groups - Validation:
requiredattribute on inputs - Focus states: Combine variants with
classNamefor focus rings
Multi-Column Form Layout
For complex forms, useBox with grid display (src/components/GUIDE_CREATE_FORM.md228-277):
Form Validation Pattern
Build reusable validated input components (src/components/GUIDE_CREATE_FORM.md311-339):- Conditional
borderColorandbgbased on error state - Dynamic focus ring colors via
className - Error message display with
Boxfor text color - Props spreading with
{...props}for HTML attributes
Available Variant Props for Primitives
All primitives support the 12 CVA variant categories. Key variants for form building:Spacing Variants
| Prop | Values | Purpose |
|---|---|---|
p, px, py, pt, pb, pl, pr | none, xs, sm, md, lg, xl, 2xl | Padding control |
m, mx, my, mt, mb, ml, mr | none, xs, sm, md, lg, xl, 2xl, auto | Margin control |
Layout Variants
| Prop | Values | Purpose |
|---|---|---|
w | auto, full, screen, fit, min, max, 1/2, 1/3, etc. | Width control |
h | auto, full, screen, fit, min, max | Height control |
minH | Numeric values like "32", "64" | Minimum height (useful for textareas) |
maxW | xs, sm, md, lg, xl, 2xl, 3xl, etc. | Maximum width (useful for centered forms) |
display | block, flex, grid, inline, none | Display type |
Border & Style Variants
| Prop | Values | Purpose |
|---|---|---|
border | none, default, 2, 4, 8 | Border width |
borderColor | All design system colors | Border color |
rounded | none, sm, md, lg, xl, 2xl, 3xl, full | Border radius |
shadow | none, sm, md, lg, xl, 2xl | Box shadow |
Color Variants
| Prop | Values | Purpose |
|---|---|---|
bg | All design system colors (e.g., white, card, gray-50) | Background color |
c | All design system colors (e.g., gray-700, red-600) | Text color |
Best Practices for Advanced Composition
Form Field Guidelines
- Always set
w="full"on input fields for consistent width (src/components/GUIDE_CREATE_FORM.md304) - Use
Blockfor form structure (form element, field groups) (src/components/GUIDE_CREATE_FORM.md305) - Use
Boxfor actual inputs (input, textarea, select) (src/components/GUIDE_CREATE_FORM.md306) - Combine variant props with Tailwind classes for focus states (src/components/GUIDE_CREATE_FORM.md307)
- Use
minHfor textarea instead of fixed height (src/components/GUIDE_CREATE_FORM.md308) - Apply
className="resize-none"to prevent textarea resizing if needed (src/components/GUIDE_CREATE_FORM.md309)
Variant + ClassName Hybrid Pattern
The variant system covers ~80% of styling needs. For remaining 20%, combine variants withclassName:
className:
- Interactive states (
:hover,:focus,:active) - Pseudo-elements (
:before,:after) - Complex animations
- Grid/flex utilities not covered by variants
- Responsive breakpoints beyond variant system
Custom Component Composition
Building Reusable Composites
When you need the same pattern repeatedly, extract it into a custom component: Pattern: Labeled Input Field- Accept variant props and HTML attributes via props spreading
- Handle conditional logic (error states, validation)
- Maintain accessibility (label associations, ARIA attributes)
- Return primitive composition (Block + Box)
Non-Form Custom Scenarios
Custom Interactive Widgets: When building application-specific widgets (sliders, pickers, custom controls):- Start with
BoxorBlockas container - Apply semantic
componentprop (<Box component="button">for clickable elements) - Use variant props for layout and styling
- Add event handlers (
onClick,onChange, etc.) - Combine with
classNamefor complex interactions
- Compose
Grid,Flex, orStackfrom src/core/ui/ - Apply layout variants (
cols,gap,align,justify) - Nest primitives for hierarchical structure
- Use
Blockwithcomponent="section"/component="aside"for semantic markup
Comparison: Basic vs Advanced Workflow
When to use each approach:| Feature | Basic Workflow | Advanced Workflow |
|---|---|---|
| Development speed | Fast (pre-built components) | Moderate (manual composition) |
| Flexibility | Limited to component props | Full control via primitives |
| Code maintenance | Easier (fewer components) | More complex (more code) |
| Type safety | Full (composite component types) | Full (primitive component types) |
| Variant support | Via prop forwarding | Direct application |
| Semantic HTML | Predefined structure | Full control via component prop |
| Best for | Standard UI patterns | Custom/unique requirements |
Summary
The advanced workflow enables building custom interfaces when the 15 composite components are insufficient:- Forms: Compose
Block+Boxwithcomponentprop for form elements, labels, and inputs - Custom widgets: Use primitives with semantic
componentprops and variant system - Unique layouts: Compose
Grid,Flex,Stackfor structural requirements - Hybrid approach: Combine variant props (~80% coverage) with
classNamefor edge cases