Usage Guide
This guide covers the core components and conventions used to build interfaces with Zen.
This guide covers the core components and conventions used to build interfaces with Zen.
Component Categories#
Zen components fall into two categories, each with a distinct purpose:
Layout Components#
Layout components handle positioning, spacing, and structure. They accept a full set of styling props.
| Component | Purpose |
|---|---|
| Box | General-purpose container with all styling props |
| Row | Horizontal flex layout |
| Column | Vertical flex layout |
| Grid | CSS grid layout |
| Container | Centered, max-width container |
Interactive Components#
Interactive components handle user interaction and display. They focus on their core functionality and delegate layout concerns to their parent.
Examples: Button, TextField, Select, Checkbox, Tabs, etc.
The Composition Pattern#
A key principle in Zen is separation of concerns: interactive components handle behavior, layout components handle positioning.
Positioning with Box#
When you need to position or add spacing to an interactive component, wrap it in a layout component:
Why This Pattern?#
- Focused APIs - Button handles button concerns, Box handles layout concerns
- Flexibility - Any component can be positioned any way without special props
- Predictability - Layout is always handled by layout components
- Smaller bundle - Interactive components don't carry unused layout prop logic
Building Layouts#
Use Semantic Layout Components#
Prefer Row and Column over Box with flex direction:
Spacing with Gap#
Use gap for consistent spacing between children instead of individual margins:
Container for Page Content#
Use Container to center and constrain page content:
Responsive Design#
Responsive Props#
Most style props accept responsive objects. Use base for mobile-first styles:
Breakpoints#
| Name | Min Width | Typical Device |
|---|---|---|
base | 0px | All devices (mobile-first) |
sm | 640px | Large phones, small tablets |
md | 768px | Tablets |
lg | 1024px | Laptops |
xl | 1280px | Desktops |
2xl | 1536px | Large desktops |
Styling Props#
Common Props by Category#
Spacing:
Layout:
Visual:
Position:
Using className#
For styles not covered by props, use className with Tailwind utilities:
Forms#
Basic Form Layout#
Use Column with consistent gap for form fields:
Form with react-hook-form#
Zen provides form integration components:
Theming#
Light and Dark Mode#
Zen supports light and dark modes out of the box. Use ZenProvider to initialize:
Toggle programmatically with the useTheme hook:
Semantic Colors#
Use semantic color tokens that adapt to the theme:
| Token | Purpose |
|---|---|
surface | Page background |
surface-raised | Cards, elevated elements |
surface-sunken | Inset areas |
primary | Primary text |
muted | Secondary text |
disabled | Disabled state |
Composition Examples#
Cards#
Card Title
Card description or content goes here.Page Header#
Dashboard
Welcome back, here's what's happening.Empty State#
No items yet
Get started by creating your first item.
Tips#
- Start with layout - Build the structure with Row/Column/Grid first, then add content
- Use gap over margin - Cleaner and more maintainable for spacing between siblings
- Wrap for positioning - Use Box to position interactive components
- Think responsive - Use responsive objects for props that should adapt
- Leverage semantics - Use semantic colors and tokens for theme compatibility
- Keep it simple - Compose simple components rather than configuring complex ones
