Skip to main content

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:
  1. Imports variant functions from @ui8kit/core
  2. Accepts typed variant props in its interface
  3. Applies variants using the cn() utility
  4. 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

The Badge 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:

How Variants Work

When you use variant props, UI8Kit automatically converts them to Tailwind classes:
This generates the final className: "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 ..."
You never need to write Tailwind classes manually. Just use typed variant props and let UI8Kit handle the rest.

Data Attributes

Each UI component includes stable data-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.
string
default:"div"
HTML element to render as the container

Container

Responsive container with size presets and centering options.
string
default:"md"
Container width preset
boolean
Center the container horizontally

Stack

Vertical flex layout for stacking elements with consistent spacing.
string
Spacing between child elements
string
Vertical alignment of children

Group

Horizontal flex layout for arranging elements in a row.
string
Spacing between child elements
string
default:"start"
Horizontal distribution of children

Grid

CSS Grid layout with responsive column presets.
string
default:"1"
Responsive column configuration
string
Spacing between grid items

Card

Card component with compound structure for headers, content, and footers. Compound Components:
  • Card: Root container
  • CardHeader: Top section
  • CardTitle: Heading
  • CardDescription: Subtitle
  • CardContent: Main content area
  • CardFooter: Bottom section

Button

Interactive button with variants, sizes, and loading states.
string
default:"default"
Button style variant
string
default:"default"
Button size preset
ReactNode
Content to display on the left side
ReactNode
Content to display on the right side
boolean
Show loading state

Badge

Small status indicators with dots and sections.
string
default:"default"
Badge style variant
string
default:"default"
Badge size preset
boolean
Show status indicator dot
ReactNode
Content before the badge text
ReactNode
Content after the badge text

Title

Semantic heading elements with typography control. Key Props:
  • order: 1 | 2 | 3 | 4 | 5 | 6 (maps to h1-h6)
  • size: Font size variant
  • fw: Font weight
  • c: Text color
  • Supports spacing variants
Location: src/components/ui/Title/ (referenced in src/components/README.md150-163)

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
Location: src/components/ui/Text/ (referenced in src/components/README.md165-177)

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
Location: src/components/ui/Image/ (referenced in src/components/README.md179-191)

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
Location: src/components/ui/Icon/ (referenced in src/components/README.md193-203)

Accordion

Expandable/collapsible sections with state management. Structure:
  • Accordion: Root with controlled/uncontrolled state
  • AccordionItem: Individual collapsible section
  • AccordionTrigger: Clickable header (uses Button)
  • AccordionContent: Collapsible content area
Key Props (Accordion):
  • type: 'single' | 'multiple'
  • collapsible: Boolean for closing active item
  • value, onValueChange, defaultValue: State control
  • w: Width variant
Key Props (AccordionItem):
  • value: Unique identifier (required)
  • w: Width variant
  • gap, direction: Flex variants
Key Props (AccordionTrigger):
  • Extends all ButtonProps
  • w: Width variant (defaults to 'full')
Key Props (AccordionContent):
  • w: Width variant
  • Automatic animation via CSS transitions
Implementation: src/components/ui/Accordion/Accordion.tsx1-184 Sources: src/components/README.md94-203 src/components/ui/Badge/Badge.tsx1-97 src/components/ui/Accordion/Accordion.tsx1-184

Universal Props

All UI components support these universal props through the variant system:

Spacing Props

Visual Props

Layout Props

Usage Examples

Basic Components

Compound Components

Layout Patterns

Next Steps

Core Components

Learn about the base primitives that power UI components

Layout Components

Build responsive page layouts with layout components
UI components eliminate manual Tailwind classes through typed variant props. Start with Badge, Button, and Card for common use cases.