UI Components
UI8Kit provides a comprehensive set of composite components that extend base primitives with typed variant props. These components eliminate manual className management while providing full customization through a consistent API.Quick Start
Get started with UI components by importing them from the core package:All UI components support universal props like
p, m, rounded, and shadow through the variant system. See Universal Props for the complete list.Component Overview
UI components are organized into two categories: Layout Components - Structural elements for page composition UI Components - Interactive elements and content containers Each component provides a developer-friendly API that forwards variant props to underlying primitives while adding component-specific functionality.Component Architecture
UI components form the middle layer of UI8Kit’s three-layer architecture:- Foundation Layer: CVA variant functions that generate Tailwind classes
- Primitive Layer: Base HTML elements with minimal styling
- Component Layer: Composite components with typed variant props
Prop Forwarding Pattern
UI components extend primitives through prop forwarding. Each component:- Imports variant functions from
@ui8kit/core - Accepts typed variant props in its interface
- Applies variants using the
cn()utility - Forwards remaining props to the base primitive
This pattern provides type safety while eliminating manual className management. Components like
Badge and Button inherit spacing, color, and visual variants from the foundation layer.Badge Component Example
TheBadge component demonstrates prop forwarding in action:
Variant System
UI components access 12 variant categories from the foundation layer. Each component selectively imports only the variants it needs:| Variant Category | Props | Values | Common Components |
|---|---|---|---|
| Spacing | p, px, py, pt, pb, pl, pr, m, mx, my, mt, mb, ml, mr | none, xs, sm, md, lg, xl, 2xl, auto | All components |
| Rounded | rounded | none, sm, md, lg, xl, 2xl, 3xl, full | Card, Badge, Button, Image |
| Shadow | shadow | none, sm, md, lg, xl, 2xl | Card, Badge, Image |
| Border | border, borderTop, borderBottom, borderLeft, borderRight | none, default, border | Card, Badge |
| Colors | bg, c, borderColor | Design system colors | Card, Badge, Title, Text |
| Layout | w, h, minH, maxW, position | auto, full, screen, fit, min, max | Accordion, Container, Stack |
| Typography | size, weight, align, leading | Font properties | Title, Text |
| Badge Style | variant | default, secondary, destructive, outline, success, warning | Badge |
| Button Style | variant, size, contentAlign | Button-specific variants | Button |
| Flexbox | gap, direction, align, justify | Flex properties | Group, Stack, AccordionItem |
| Grid | cols, gap | Grid properties | Grid, GridCol |
| Effects | Various visual effects | Component-specific | Multiple |
How Variants Work
When you use variant props, UI8Kit automatically converts them to Tailwind classes:"inline-flex items-center font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring p-8 rounded-xl shadow-md bg-green-500 text-green-50 ..."
Data Attributes
Each UI component includes stabledata-class attributes for reliable targeting:
Use
data-class attributes for CSS selectors, testing, and DOM queries. These remain stable even when component styles change.TypeScript Support
All UI components provide full TypeScript support with:- Typed variant props with autocomplete
- HTML attribute forwarding for standard DOM props
- Ref forwarding for direct DOM access
- Compound component patterns for complex UI structures
Layout Components
Block
Section wrapper component with full styling control. Perfect for content sections and custom layouts.HTML element to render as the container
Container
Responsive container with size presets and centering options.Container width preset
Center the container horizontally
Stack
Vertical flex layout for stacking elements with consistent spacing.Spacing between child elements
Vertical alignment of children
Group
Horizontal flex layout for arranging elements in a row.Spacing between child elements
Horizontal distribution of children
Grid
CSS Grid layout with responsive column presets.Responsive column configuration
Spacing between grid items
Card
Card component with compound structure for headers, content, and footers. Compound Components:Card: Root containerCardHeader: Top sectionCardTitle: HeadingCardDescription: SubtitleCardContent: Main content areaCardFooter: Bottom section
Button
Interactive button with variants, sizes, and loading states.Button style variant
Button size preset
Content to display on the left side
Content to display on the right side
Show loading state
Badge
Small status indicators with dots and sections.Badge style variant
Badge size preset
Show status indicator dot
Content before the badge text
Content after the badge text
Title
Semantic heading elements with typography control. Key Props:-
order:1|2|3|4|5|6(maps toh1-h6) -
size: Font size variant -
fw: Font weight -
c: Text color - Supports spacing variants
Text
Text elements with full typography control. Key Props:-
size: Font size variant -
c: Text color -
ta: Text alignment ('left'|'center'|'right'|'justify') -
truncate: Boolean for text truncation - Supports spacing variants
Image
Enhanced image component with aspect ratio and fit control. Key Props:-
src,alt: Standard image attributes -
aspect:'square'|'video'|'portrait'|'landscape' -
fit:'contain'|'cover'|'fill'|'none' - Supports rounded and shadow variants
Icon
Icon wrapper for lucide-react icons with size and color control. Key Props:-
lucideIcon: Lucide icon component -
size: Size variant -
c: Color variant - Supports spacing variants
Accordion
Expandable/collapsible sections with state management. Structure:-
Accordion: Root with controlled/uncontrolled state -
AccordionItem: Individual collapsible section -
AccordionTrigger: Clickable header (usesButton) -
AccordionContent: Collapsible content area
-
type:'single'|'multiple' -
collapsible: Boolean for closing active item -
value,onValueChange,defaultValue: State control -
w: Width variant
-
value: Unique identifier (required) -
w: Width variant -
gap,direction: Flex variants
-
Extends all
ButtonProps -
w: Width variant (defaults to'full')
-
w: Width variant - Automatic animation via CSS transitions
Universal Props
All UI components support these universal props through the variant system:Spacing Props
| Prop | Description | Values |
|---|---|---|
p | Padding (all sides) | none, xs, sm, md, lg, xl, 2xl |
px, py | Padding horizontal/vertical | Same as p |
pt, pb, pl, pr | Padding individual sides | Same as p |
m | Margin (all sides) | none, xs, sm, md, lg, xl, 2xl, auto |
mx, my | Margin horizontal/vertical | Same as m |
mt, mb, ml, mr | Margin individual sides | Same as m |
Visual Props
| Prop | Description | Values |
|---|---|---|
rounded | Border radius | none, sm, md, lg, xl, 2xl, 3xl, full |
shadow | Box shadow | none, sm, md, lg, xl, 2xl |
bg | Background color | Design system colors |
c | Text color | Design system colors |
border | Border styles | none, default, border |
Layout Props
| Prop | Description | Values |
|---|---|---|
w | Width | auto, full, screen, fit, min, max |
h | Height | Same as w |
minH, maxW | Min/max dimensions | Same as w |
position | CSS position | static, relative, absolute, fixed, sticky |