Skip to main content

Advanced Workflow

Relevant source files

Purpose 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: Decision Tree: Basic vs Advanced Workflow
Sources: src/components/README.md1-8 src/components/GUIDE_CREATE_FORM.md5-10

Building Forms with Block and Box

The library does not include dedicated Form, Label, or Input components. Instead, use the polymorphic component prop on Block and Box to render semantic HTML elements with the full variant system.

Component Prop Pattern

The component prop transforms primitives into any HTML element while maintaining type-safe variant props:
Sources: src/components/GUIDE_CREATE_FORM.md7-9

Form Structure Pattern

Use Block with component="form" as the form wrapper, applying layout and styling variants: Form Container Structure: Example form structure (see src/components/GUIDE_CREATE_FORM.md14-32):
Sources: src/components/GUIDE_CREATE_FORM.md11-33

Input Field Patterns

All input types use Box with component="input" and standard HTML attributes: Text Input (src/components/GUIDE_CREATE_FORM.md37-50):
Input with Focus States (src/components/GUIDE_CREATE_FORM.md54-67):
Password Input (src/components/GUIDE_CREATE_FORM.md70-82):
Number Input with Constraints (src/components/GUIDE_CREATE_FORM.md84-97):
Sources: src/components/GUIDE_CREATE_FORM.md35-97

Textarea Fields

Use Box with component="textarea" for multi-line text input: Basic Textarea (src/components/GUIDE_CREATE_FORM.md99-115):
Textarea with Minimum Height (src/components/GUIDE_CREATE_FORM.md117-129):
Sources: src/components/GUIDE_CREATE_FORM.md99-129

Complete Form Example

Contact Form Architecture:
Full implementation at src/components/GUIDE_CREATE_FORM.md134-226 Key patterns:
  1. Form event handling: onSubmit prop on form Block
  2. Field structure: Block wrapper → label → input in each group
  3. Spacing: className="space-y-6" on form, className="space-y-2" on field groups
  4. Validation: required attribute on inputs
  5. Focus states: Combine variants with className for focus rings
Sources: src/components/GUIDE_CREATE_FORM.md131-226

Multi-Column Form Layout

For complex forms, use Box with grid display (src/components/GUIDE_CREATE_FORM.md228-277):
Sources: src/components/GUIDE_CREATE_FORM.md228-277

Form Validation Pattern

Build reusable validated input components (src/components/GUIDE_CREATE_FORM.md311-339):
Pattern breakdown:
  • Conditional borderColor and bg based on error state
  • Dynamic focus ring colors via className
  • Error message display with Box for text color
  • Props spreading with {...props} for HTML attributes
Sources: src/components/GUIDE_CREATE_FORM.md311-339

Available Variant Props for Primitives

All primitives support the 12 CVA variant categories. Key variants for form building:

Spacing Variants

Layout Variants

Border & Style Variants

Color Variants

Sources: src/components/GUIDE_CREATE_FORM.md279-301 src/components/README.md205-222

Best Practices for Advanced Composition

Form Field Guidelines

  1. Always set w="full" on input fields for consistent width (src/components/GUIDE_CREATE_FORM.md304)
  2. Use Block for form structure (form element, field groups) (src/components/GUIDE_CREATE_FORM.md305)
  3. Use Box for actual inputs (input, textarea, select) (src/components/GUIDE_CREATE_FORM.md306)
  4. Combine variant props with Tailwind classes for focus states (src/components/GUIDE_CREATE_FORM.md307)
  5. Use minH for textarea instead of fixed height (src/components/GUIDE_CREATE_FORM.md308)
  6. 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 with className:
When to use className:
  • Interactive states (:hover, :focus, :active)
  • Pseudo-elements (:before, :after)
  • Complex animations
  • Grid/flex utilities not covered by variants
  • Responsive breakpoints beyond variant system
Sources: src/components/GUIDE_CREATE_FORM.md302-310 src/components/README.md237-244

Custom Component Composition

Building Reusable Composites

When you need the same pattern repeatedly, extract it into a custom component: Pattern: Labeled Input Field
Implementation approach:
  1. Accept variant props and HTML attributes via props spreading
  2. Handle conditional logic (error states, validation)
  3. Maintain accessibility (label associations, ARIA attributes)
  4. Return primitive composition (Block + Box)
Sources: src/components/GUIDE_CREATE_FORM.md311-339

Non-Form Custom Scenarios

Custom Interactive Widgets: When building application-specific widgets (sliders, pickers, custom controls):
  1. Start with Box or Block as container
  2. Apply semantic component prop (<Box component="button"> for clickable elements)
  3. Use variant props for layout and styling
  4. Add event handlers (onClick, onChange, etc.)
  5. Combine with className for complex interactions
Custom Layout Structures: For unique layout requirements not covered by DashLayout, LayoutBlock, or SplitBlock:
  1. Compose Grid, Flex, or Stack from src/core/ui/
  2. Apply layout variants (cols, gap, align, justify)
  3. Nest primitives for hierarchical structure
  4. Use Block with component="section"/component="aside" for semantic markup
Sources: src/components/README.md237-244 .devin/wiki.json191-198

Comparison: Basic vs Advanced Workflow

When to use each approach:
Capability matrix: Sources: src/components/README.md1-19 src/components/GUIDE_CREATE_FORM.md1-10

Summary

The advanced workflow enables building custom interfaces when the 15 composite components are insufficient:
  1. Forms: Compose Block + Box with component prop for form elements, labels, and inputs
  2. Custom widgets: Use primitives with semantic component props and variant system
  3. Unique layouts: Compose Grid, Flex, Stack for structural requirements
  4. Hybrid approach: Combine variant props (~80% coverage) with className for edge cases
For standard scenarios with existing components, use Basic Workflow. For general guidelines, see Best Practices. Sources: src/components/GUIDE_CREATE_FORM.md341-347 .devin/wiki.json191-198