Documentation
¶
Overview ¶
Package components provides layout components for the BubblyUI framework.
Package components provides layout components for the BubblyUI framework.
Package components provides layout components for the BubblyUI framework.
Package components provides layout components for the BubblyUI framework.
Package components provides a comprehensive library of production-ready TUI components following atomic design principles.
Overview ¶
The components package offers a complete set of pre-built, type-safe, and well-tested TUI components that leverage all BubblyUI framework features (reactivity, lifecycle, composition API, directives) to provide a consistent foundation for building terminal applications.
Atomic Design Hierarchy ¶
Components are organized into four levels following atomic design principles:
- Atoms: Basic building blocks (Button, Text, Icon, Spacer, Badge, Spinner)
- Molecules: Simple combinations (Input, Checkbox, Select, TextArea, Radio, Toggle)
- Organisms: Complex features (Form, Table, List, Modal, Card, Menu, Tabs, Accordion)
- Templates: Layout structures (AppLayout, PageLayout, PanelLayout, GridLayout)
Quick Start ¶
Import the components package:
import (
"github.com/newbpydev/bubblyui/pkg/bubbly"
"github.com/newbpydev/bubblyui/pkg/components"
)
Use built-in components:
button := components.Button(components.ButtonProps{
Label: "Submit",
Variant: components.ButtonPrimary,
OnClick: func() {
handleSubmit()
},
})
Theming ¶
All components use a consistent theming system based on Lipgloss:
theme := components.DefaultTheme
// Customize theme colors
theme.Primary = lipgloss.Color("63")
Provide theme to your application:
Setup(func(ctx *bubbly.Context) {
ctx.Provide("theme", theme)
})
Components automatically inject and use the provided theme.
Type Safety ¶
All components use Go generics for type-safe props and state:
// Type-safe form with generic data type
form := components.Form(components.FormProps[UserData]{
Initial: UserData{},
Validate: validateUser,
OnSubmit: saveUser,
})
// Type-safe table with generic row type
table := components.Table(components.TableProps[User]{
Data: usersRef,
Columns: userColumns,
})
Component Composition ¶
Components compose naturally to build complex UIs:
// Compose atoms into molecules
input := components.Input(components.InputProps{
Value: nameRef,
Placeholder: "Enter name",
})
// Compose molecules into organisms
form := components.Form(components.FormProps[Data]{
Fields: []components.FormField{
{Name: "name", Label: "Name", Component: input},
},
})
// Compose organisms into templates
app := components.AppLayout(components.AppLayoutProps{
Header: headerComponent,
Content: form,
})
Reactivity Integration ¶
Components integrate seamlessly with BubblyUI's reactivity system:
// Create reactive state
value := bubbly.NewRef("")
// Bind to input component
input := components.Input(components.InputProps{
Value: value, // Two-way binding
})
// Watch for changes
bubbly.Watch(value, func(newVal, oldVal string) {
fmt.Printf("Value changed: %s\n", newVal)
})
Event Handling ¶
Components emit events for user interactions:
button := components.Button(components.ButtonProps{
Label: "Click me",
OnClick: func() {
// Handle click event
},
})
input := components.Input(components.InputProps{
OnChange: func(value string) {
// Handle value change
},
OnBlur: func() {
// Handle blur event
},
})
Validation ¶
Input components support validation:
input := components.Input(components.InputProps{
Value: emailRef,
Validate: func(value string) error {
if !strings.Contains(value, "@") {
return errors.New("invalid email")
}
return nil
},
})
Form components aggregate validation:
form := components.Form(components.FormProps[UserData]{
Validate: func(data UserData) map[string]string {
errors := make(map[string]string)
if data.Email == "" {
errors["email"] = "Email is required"
}
return errors
},
})
Accessibility ¶
All components follow TUI accessibility best practices:
- Keyboard navigation for all interactive components
- Focus indicators visible with distinct styling
- Screen reader hints where applicable
- Semantic structure with clear visual hierarchy
- High contrast color schemes
Performance ¶
Components are optimized for terminal rendering:
- Button: < 1ms render time
- Input: < 2ms render time
- Form: < 10ms render time
- Table (100 rows): < 50ms render time
- List (1000 items): < 100ms with virtual scrolling
Examples ¶
See the examples directory for complete applications:
- Todo app: Form and List composition
- Dashboard: Table and Card layout
- Settings: Tabs and Form integration
- Data browser: Table with Modal
Package Structure ¶
The package is organized by atomic design level:
- doc.go: Package documentation
- types.go: Common types and interfaces
- theme.go: Theming system
- button.go, text.go, icon.go: Atom components
- input.go, checkbox.go, select.go: Molecule components
- form.go, table.go, list.go: Organism components
- app_layout.go, page_layout.go: Template components
Design Philosophy ¶
Components follow these principles:
- Type Safety: Leverage Go generics for compile-time checking
- Consistency: Unified styling and behavior across all components
- Composability: Build complex UIs from simple building blocks
- Accessibility: Usable by everyone, keyboard-first design
- Performance: Optimized for terminal rendering
- Integration: Seamless integration with BubblyUI framework
Compatibility ¶
- Requires Go 1.22+ (generics)
- Requires BubblyUI framework (features 01-05)
- Uses Lipgloss for styling
- Compatible with Bubbletea v1.0+
License ¶
See the LICENSE file in the repository root.
Package components provides layout components for the BubblyUI framework.
Package components provides layout components for the BubblyUI framework.
Package components provides layout type constants for the BubblyUI advanced layout system.
Package components provides layout components for the BubblyUI framework.
Index ¶
- Constants
- Variables
- func Accordion(props AccordionProps) bubbly.Component
- func AppLayout(props AppLayoutProps) bubbly.Component
- func Badge(props BadgeProps) bubbly.Component
- func Box(props BoxProps) bubbly.Component
- func Button(props ButtonProps) bubbly.Component
- func Card(props CardProps) bubbly.Component
- func Center(props CenterProps) bubbly.Component
- func Checkbox(props CheckboxProps) bubbly.Component
- func Container(props ContainerProps) bubbly.Component
- func Divider(props DividerProps) bubbly.Component
- func Flex(props FlexProps) bubbly.Component
- func Form[T any](props FormProps[T]) bubbly.Component
- func GridLayout(props GridLayoutProps) bubbly.Component
- func HStack(props StackProps) bubbly.Component
- func Icon(props IconProps) bubbly.Component
- func Input(props InputProps) bubbly.Component
- func List[T any](props ListProps[T]) bubbly.Component
- func Menu(props MenuProps) bubbly.Component
- func Modal(props ModalProps) bubbly.Component
- func PageLayout(props PageLayoutProps) bubbly.Component
- func PanelLayout(props PanelLayoutProps) bubbly.Component
- func Radio[T any](props RadioProps[T]) bubbly.Component
- func Select[T any](props SelectProps[T]) bubbly.Component
- func Spacer(props SpacerProps) bubbly.Component
- func Spinner(props SpinnerProps) bubbly.Component
- func Table[T any](props TableProps[T]) bubbly.Component
- func Tabs(props TabsProps) bubbly.Component
- func Text(props TextProps) bubbly.Component
- func TextArea(props TextAreaProps) bubbly.Component
- func Toggle(props ToggleProps) bubbly.Component
- func VStack(props StackProps) bubbly.Component
- type AccordionItem
- type AccordionProps
- type AlignItems
- type Alignment
- type AppLayoutProps
- type BadgeProps
- type BoxProps
- type ButtonProps
- type ButtonVariant
- type CardProps
- type CenterProps
- type CheckboxProps
- type ClassName
- type CommonProps
- type ComponentID
- type ContainerProps
- type ContainerSize
- type DividerProps
- type EventHandler
- type FlexDirection
- type FlexProps
- type FormField
- type FormProps
- type GridLayoutProps
- type IconProps
- type InputProps
- type InputType
- type JustifyContent
- type ListProps
- type MenuItem
- type MenuProps
- type ModalProps
- type PageLayoutProps
- type PanelLayoutProps
- type Position
- type RadioProps
- type RenderFunc
- type SelectProps
- type Size
- type SpacerProps
- type SpinnerProps
- type StackProps
- type Tab
- type TableColumn
- type TableProps
- type TabsProps
- type TextAreaProps
- type TextProps
- type Theme
- type ToggleProps
- type ValidateFunc
- type Variant
Constants ¶
const ( CheckboxUnchecked = "☐" // Unchecked box (U+2610) CheckboxChecked = "☑" // Checked box (U+2611) )
Checkbox indicator constants
const ( // DefaultHorizontalChar is the default character for horizontal dividers. DefaultHorizontalChar = "─" // DefaultVerticalChar is the default character for vertical dividers. DefaultVerticalChar = "│" // DefaultDividerLength is the default length when not specified. DefaultDividerLength = 20 )
Default divider characters for horizontal and vertical orientations.
const DefaultHStackDividerChar = "│"
DefaultHStackDividerChar is the default divider character for HStack. Uses vertical line since HStack renders horizontally.
const DefaultStackSpacing = 1
DefaultStackSpacing is the default spacing between items in a stack.
const DefaultVStackDividerChar = "─"
DefaultVStackDividerChar is the default divider character for VStack. Uses horizontal line since VStack renders vertically.
Variables ¶
var DarkTheme = Theme{ Primary: lipgloss.Color("75"), Secondary: lipgloss.Color("245"), Success: lipgloss.Color("82"), Warning: lipgloss.Color("220"), Danger: lipgloss.Color("203"), Info: lipgloss.Color("51"), Background: lipgloss.Color("234"), Foreground: lipgloss.Color("255"), Muted: lipgloss.Color("243"), Border: lipgloss.RoundedBorder(), BorderColor: lipgloss.Color("243"), Padding: 1, Margin: 1, Radius: 1, }
DarkTheme provides a theme optimized for dark terminal backgrounds. It uses higher contrast colors for better visibility on dark backgrounds.
var DefaultTheme = Theme{ Primary: lipgloss.Color("75"), Secondary: lipgloss.Color("240"), Success: lipgloss.Color("46"), Warning: lipgloss.Color("226"), Danger: lipgloss.Color("196"), Info: lipgloss.Color("39"), Background: lipgloss.Color("235"), Foreground: lipgloss.Color("255"), Muted: lipgloss.Color("240"), Border: lipgloss.RoundedBorder(), BorderColor: lipgloss.Color("240"), Padding: 1, Margin: 1, Radius: 1, }
DefaultTheme provides a carefully crafted default color scheme optimized for terminal readability and accessibility.
Color choices:
- Primary (75): Bright blue for main actions (>3:1 contrast)
- Secondary (240): Neutral gray for alternatives
- Success (46): Bright green for positive feedback
- Warning (226): Yellow for caution
- Danger (196): Red for errors and destructive actions
- Info (39): Cyan for informational content
- Background (235): Dark gray for backgrounds
- Foreground (255): White for primary text
- Muted (240): Gray for secondary text
This theme works well in both light and dark terminal backgrounds with sufficient contrast for accessibility (WCAG AA compliant).
var HighContrastTheme = Theme{ Primary: lipgloss.Color("15"), Secondary: lipgloss.Color("250"), Success: lipgloss.Color("10"), Warning: lipgloss.Color("11"), Danger: lipgloss.Color("9"), Info: lipgloss.Color("14"), Background: lipgloss.Color("0"), Foreground: lipgloss.Color("15"), Muted: lipgloss.Color("7"), Border: lipgloss.NormalBorder(), BorderColor: lipgloss.Color("15"), Padding: 1, Margin: 1, Radius: 0, }
HighContrastTheme provides maximum contrast for accessibility. Ideal for users with visual impairments or in bright environments.
var LightTheme = Theme{ Primary: lipgloss.Color("27"), Secondary: lipgloss.Color("240"), Success: lipgloss.Color("28"), Warning: lipgloss.Color("136"), Danger: lipgloss.Color("160"), Info: lipgloss.Color("31"), Background: lipgloss.Color("255"), Foreground: lipgloss.Color("235"), Muted: lipgloss.Color("245"), Border: lipgloss.RoundedBorder(), BorderColor: lipgloss.Color("245"), Padding: 1, Margin: 1, Radius: 1, }
LightTheme provides a theme optimized for light terminal backgrounds. It uses darker colors for better visibility on light backgrounds.
Functions ¶
func Accordion ¶
func Accordion(props AccordionProps) bubbly.Component
Accordion creates an accordion collapsible panels component. The accordion displays a list of panels that can be expanded/collapsed.
Features:
- Multiple collapsible panels
- Expand/collapse functionality
- Single or multiple expansion modes
- Reactive expanded state
- OnToggle callback
- String or Component content
- Theme integration
- Custom style override
Example:
expanded := bubbly.NewRef([]int{0})
accordion := Accordion(AccordionProps{
Items: []AccordionItem{
{Title: "Section 1", Content: "Content for section 1"},
{Title: "Section 2", Content: "Content for section 2"},
{Title: "Section 3", Content: "Content for section 3"},
},
ExpandedIndexes: expanded,
AllowMultiple: true,
})
func AppLayout ¶
func AppLayout(props AppLayoutProps) bubbly.Component
AppLayout creates a full application layout template component. The layout positions Header, Sidebar, Content, and Footer sections using Lipgloss layout functions.
Layout Structure:
┌─────────────────────────────────┐ │ Header (full width) │ ├──────────┬──────────────────────┤ │ Sidebar │ Content │ │ │ │ ├──────────┴──────────────────────┤ │ Footer (full width) │ └─────────────────────────────────┘
Features:
- Full application layout with four sections
- Responsive to terminal size
- Configurable dimensions for each section
- Theme integration for consistent styling
- Custom style override support
- Lipgloss-based layout positioning
Example:
layout := AppLayout(AppLayoutProps{
Header: Text(TextProps{Content: "My App"}),
Sidebar: Menu(MenuProps{Items: menuItems}),
Content: Card(CardProps{Title: "Dashboard"}),
Footer: Text(TextProps{Content: "© 2024"}),
})
func Badge ¶
func Badge(props BadgeProps) bubbly.Component
Badge creates a new Badge atom component.
Badge is a small status indicator component that displays short text labels with colored backgrounds. Commonly used for status indicators, counts, labels, and notifications.
The badge component automatically integrates with the theme system via the composition API's Provide/Inject mechanism. If no theme is provided, it uses DefaultTheme.
Example:
badge := components.Badge(components.BadgeProps{
Label: "Active",
Variant: components.VariantSuccess,
})
// Initialize and use with Bubbletea
badge.Init()
view := badge.View()
Common use cases:
- Status indicators (Active, Inactive, Pending)
- Notification counts (5 new messages)
- Category labels (Bug, Feature, Documentation)
- Priority markers (High, Medium, Low)
Accessibility:
- Clear visual distinction with variant colors
- High contrast for readability
- Compact design for inline use
func Box ¶
Box creates a generic container component. The box provides a flexible container with optional padding, border, title, and background color. It can contain either a child component or text content.
Features:
- Optional child component or text content
- Configurable padding (uniform or per-axis)
- Optional border with customizable style
- Optional title header
- Fixed or auto dimensions
- Background color support
- Theme integration for consistent styling
- Custom style override support
Example:
box := Box(BoxProps{
Content: "Hello, World!",
Padding: 1,
Border: true,
Title: "Greeting",
})
// With child component
box := Box(BoxProps{
Child: myComponent,
Border: true,
Width: 40,
})
func Button ¶
func Button(props ButtonProps) bubbly.Component
Button creates a new Button atom component.
Button is a fundamental interactive element that triggers actions when clicked. It supports multiple visual variants, disabled states, and custom click handlers.
The button automatically integrates with the theme system via the composition API's Provide/Inject mechanism. If no theme is provided, it uses DefaultTheme.
Example:
button := components.Button(components.ButtonProps{
Label: "Save Changes",
Variant: components.ButtonPrimary,
OnClick: func() {
fmt.Println("Saving...")
},
})
// Initialize and use with Bubbletea
button.Init()
view := button.View()
Keyboard interaction:
- Enter/Space: Trigger click event (when focused)
Accessibility:
- Clear visual distinction between enabled/disabled states
- Keyboard accessible
- High contrast variants available via theme
func Card ¶
Card creates a card container component. The card displays a bordered box with optional title, content, footer, and child components.
Features:
- Optional title header
- Content text or child components
- Optional footer
- Configurable width, height, and padding
- Border can be toggled on/off
- Theme integration for consistent styling
- Custom style override support
Example:
card := Card(CardProps{
Title: "User Profile",
Content: "Name: John Doe\nEmail: john@example.com",
Footer: "Last updated: 2024-01-01",
Width: 50,
})
func Center ¶
func Center(props CenterProps) bubbly.Component
Center creates a centering layout component. The component centers its child horizontally and/or vertically within a container of specified dimensions.
Features:
- Centers content horizontally within container
- Centers content vertically within container
- Centers both directions by default
- Supports fixed or auto dimensions
- Theme integration for consistent styling
- Custom style override support
Centering Behavior:
- When neither Horizontal nor Vertical is set: centers both directions (default)
- When Horizontal=true: centers only horizontally
- When Vertical=true: centers only vertically
- When both are true: centers both directions
Dimension Requirements:
- Horizontal centering requires Width > 0
- Vertical centering requires Height > 0
- Auto-sizing (0) uses content dimensions
Example:
// Center both directions (default)
center := Center(CenterProps{
Child: myComponent,
Width: 80,
Height: 24,
})
// Center horizontally only
center := Center(CenterProps{
Child: myComponent,
Width: 80,
Horizontal: true,
})
// Center vertically only
center := Center(CenterProps{
Child: myComponent,
Height: 24,
Vertical: true,
})
// Modal centering pattern
modal := Center(CenterProps{
Child: Card(CardProps{
Title: "Confirm",
Content: "Are you sure?",
}),
Width: 80,
Height: 24,
})
func Checkbox ¶
func Checkbox(props CheckboxProps) bubbly.Component
Checkbox creates a new Checkbox molecule component.
Checkbox is an interactive toggle element that allows users to select or deselect an option. It supports reactive state binding, callbacks, and disabled states.
The checkbox automatically integrates with the theme system via the composition API's Provide/Inject mechanism. If no theme is provided, it uses DefaultTheme.
Example:
checkedRef := bubbly.NewRef(false)
checkbox := components.Checkbox(components.CheckboxProps{
Label: "Enable notifications",
Checked: checkedRef,
OnChange: func(checked bool) {
if checked {
enableNotifications()
} else {
disableNotifications()
}
},
})
// Initialize and use with Bubbletea
checkbox.Init()
view := checkbox.View()
Features:
- Reactive checked state binding with Ref[bool]
- Toggle functionality via "toggle" event
- OnChange callback support
- Disabled state support
- Label display
- Theme integration
- Custom style override
Keyboard interaction:
- Space/Enter: Toggle checkbox (when focused)
Visual indicators:
- Unchecked: ☐ (or [ ])
- Checked: ☑ (or [x])
Accessibility:
- Clear visual distinction between checked/unchecked states
- Disabled state clearly indicated
- Keyboard accessible
func Container ¶
func Container(props ContainerProps) bubbly.Component
Container creates a width-constrained container component. The component limits content width to improve readability and optionally centers the content horizontally.
Features:
- Preset sizes for common widths (sm=40, md=60, lg=80, xl=100)
- Custom max-width override
- Horizontal centering (enabled by default)
- Full-width mode (no constraint)
- Theme integration for consistent styling
- Custom style override support
Width Behavior:
- Size preset determines default width
- MaxWidth > 0 overrides Size preset
- ContainerFull disables width constraint
Centering Behavior:
- Centered=true (default): content is horizontally centered
- Centered=false: content is left-aligned
Example:
// Default container (60 chars, centered)
container := Container(ContainerProps{
Child: myContent,
})
// Large container, not centered
container := Container(ContainerProps{
Child: myContent,
Size: ContainerLg,
Centered: false,
})
// Custom width
container := Container(ContainerProps{
Child: myContent,
MaxWidth: 50,
})
// Full width (no constraint)
container := Container(ContainerProps{
Child: myContent,
Size: ContainerFull,
})
// Readable content layout pattern
page := VStack(StackProps{
Items: []bubbly.Component{
header,
Container(ContainerProps{
Child: article,
Size: ContainerLg,
}),
footer,
},
})
func Divider ¶
func Divider(props DividerProps) bubbly.Component
Divider creates a separator line component. The divider can be horizontal or vertical, with an optional centered label.
Features:
- Horizontal or vertical orientation
- Configurable length
- Optional centered label text
- Customizable divider character
- Theme integration (uses theme.Muted for color)
- Custom style override support
Example:
// Simple horizontal divider
divider := Divider(DividerProps{
Length: 40,
})
// Divider with label
divider := Divider(DividerProps{
Label: "OR",
Length: 30,
})
// Vertical divider
divider := Divider(DividerProps{
Vertical: true,
Length: 10,
})
// Custom character
divider := Divider(DividerProps{
Char: "═",
Length: 40,
})
func Flex ¶
Flex creates a flexbox-style layout component. Items are arranged in a row or column with configurable alignment and spacing.
Features:
- Row or column direction
- Main-axis alignment (justify): start, center, end, space-between, space-around, space-evenly
- Cross-axis alignment (align): start, center, end, stretch
- Configurable gap between items
- Fixed or auto dimensions
- Theme integration
- Custom style override support
Example:
// Toolbar with space-between
toolbar := Flex(FlexProps{
Items: []bubbly.Component{
Text(TextProps{Content: "Title"}),
Spacer(SpacerProps{Flex: true}),
Button(ButtonProps{Label: "Action"}),
},
Justify: JustifySpaceBetween,
Width: 80,
})
// Centered card grid
grid := Flex(FlexProps{
Items: cards,
Direction: FlexRow,
Justify: JustifyCenter,
Gap: 2,
})
// Vertical form layout
form := Flex(FlexProps{
Items: []bubbly.Component{input1, input2, submitBtn},
Direction: FlexColumn,
Align: AlignItemsStretch,
Gap: 1,
})
func Form ¶
Form creates a new Form organism component with generic type support.
Form is a container component that manages multiple input fields, validation, and submission. It integrates with the UseForm composable for state management and provides a consistent layout for forms.
The form automatically integrates with the theme system via the composition API's Provide/Inject mechanism. If no theme is provided, it uses DefaultTheme.
Example:
type LoginData struct {
Username string
Password string
}
usernameRef := bubbly.NewRef("")
passwordRef := bubbly.NewRef("")
form := components.Form(components.FormProps[LoginData]{
Initial: LoginData{},
Fields: []components.FormField{
{
Name: "Username",
Label: "Username",
Component: components.Input(components.InputProps{
Value: usernameRef,
}),
},
{
Name: "Password",
Label: "Password",
Component: components.Input(components.InputProps{
Value: passwordRef,
Type: components.InputPassword,
}),
},
},
Validate: func(data LoginData) map[string]string {
errors := make(map[string]string)
if data.Username == "" {
errors["Username"] = "Username is required"
}
if len(data.Password) < 8 {
errors["Password"] = "Password must be at least 8 characters"
}
return errors
},
OnSubmit: func(data LoginData) {
authenticate(data.Username, data.Password)
},
})
// Initialize and use with Bubbletea
form.Init()
view := form.View()
Features:
- Generic type support for any form data struct
- Field collection with labels
- Validation with error display per field
- Submit/cancel handlers
- Integration with UseForm composable
- Theme integration
- Custom style override
Keyboard interaction:
- Tab: Navigate between fields
- Enter: Submit form (if valid)
- Escape: Cancel form
The form uses the UseForm composable internally for state management, providing reactive validation and dirty tracking.
func GridLayout ¶
func GridLayout(props GridLayoutProps) bubbly.Component
GridLayout creates a grid-based layout template component. The layout arranges items in a grid with configurable columns, gaps, and cell dimensions.
Layout Structure (3 columns example):
┌─────────┬─────────┬─────────┐ │ Cell 1 │ Cell 2 │ Cell 3 │ ├─────────┼─────────┼─────────┤ │ Cell 4 │ Cell 5 │ Cell 6 │ └─────────┴─────────┴─────────┘
Features:
- Configurable number of columns
- Adjustable gap between cells
- Custom cell width and height
- Automatic row wrapping
- Theme integration for consistent styling
- Custom style override support
- Perfect for dashboards and card grids
Example:
layout := GridLayout(GridLayoutProps{
Items: []bubbly.Component{
Card(CardProps{Title: "Card 1"}),
Card(CardProps{Title: "Card 2"}),
Card(CardProps{Title: "Card 3"}),
},
Columns: 3,
Gap: 2,
CellWidth: 25,
})
func HStack ¶
func HStack(props StackProps) bubbly.Component
HStack creates a horizontal stack layout component. Items are arranged horizontally (left to right) with configurable spacing and cross-axis (vertical) alignment.
Features:
- Horizontal arrangement of child components
- Configurable spacing between items
- Cross-axis alignment (start/center/end/stretch)
- Optional dividers between items
- Theme integration for divider styling
- Custom style override support
Example:
// Simple horizontal stack
hstack := HStack(StackProps{
Items: []interface{}{button1, button2, button3},
Spacing: 2,
})
// With alignment and dividers
hstack := HStack(StackProps{
Items: []interface{}{logo, spacer, menuItems},
Align: AlignItemsCenter,
Divider: true,
})
// Toolbar pattern with flexible spacer
hstack := HStack(StackProps{
Items: []interface{}{
Text(TextProps{Content: "Title"}),
Spacer(SpacerProps{Flex: true}),
Button(ButtonProps{Label: "Action"}),
},
})
func Icon ¶
Icon creates a new Icon atom component.
Icon is a fundamental display element for rendering symbolic glyphs and indicators in the terminal. It supports Unicode characters, emojis, and special symbols with customizable colors and sizes.
The icon component automatically integrates with the theme system via the composition API's Provide/Inject mechanism. If no theme is provided, it uses DefaultTheme.
Example:
icon := components.Icon(components.IconProps{
Symbol: "⚠",
Color: lipgloss.Color("226"),
Size: components.SizeLarge,
})
// Initialize and use with Bubbletea
icon.Init()
view := icon.View()
Common icon symbols:
- Checkmark: ✓
- Cross: ✗
- Warning: ⚠
- Info: ℹ
- Star: ★
- Heart: ♥
- Arrows: → ← ↑ ↓
- Shapes: ● ■ ◆
Accessibility:
- Clear visual distinction with colors
- High contrast colors available via theme
- Supports all terminal color profiles
func Input ¶
func Input(props InputProps) bubbly.Component
func Menu ¶
Menu creates a menu navigation component. The menu displays a list of selectable items with keyboard navigation support.
Features:
- List of menu items with labels
- Selected item highlighting
- Disabled item support
- Reactive selection state
- OnSelect callback
- Theme integration
- Custom style override
Example:
selected := bubbly.NewRef("")
menu := Menu(MenuProps{
Items: []MenuItem{
{Label: "Home", Value: "home"},
{Label: "Settings", Value: "settings"},
{Label: "Logout", Value: "logout"},
},
Selected: selected,
OnSelect: func(value string) {
navigate(value)
},
})
func Modal ¶
func Modal(props ModalProps) bubbly.Component
Modal creates a modal dialog overlay component. The modal displays a centered dialog box with title, content, and optional buttons. It can be shown/hidden by toggling the Visible ref.
Features:
- Overlay background that dims the content behind
- Centered dialog box with border
- Title, content, and optional buttons
- Keyboard controls: Esc to close, Enter to confirm
- Theme integration for consistent styling
- Custom style override support
Example:
visible := bubbly.NewRef(true)
modal := Modal(ModalProps{
Title: "Confirm Delete",
Content: "Are you sure you want to delete this item?",
Visible: visible,
OnConfirm: func() {
// Handle confirmation
visible.Set(false)
},
OnClose: func() {
visible.Set(false)
},
})
func PageLayout ¶
func PageLayout(props PageLayoutProps) bubbly.Component
PageLayout creates a simple page structure template component. The layout positions Title, Content, and Actions sections vertically using Lipgloss layout functions.
Layout Structure:
┌─────────────────────────────────┐ │ Title │ │ │ │ Content │ │ (main area) │ │ │ │ Actions │ └─────────────────────────────────┘
Features:
- Simple vertical page structure with three sections
- Configurable width and spacing
- Theme integration for consistent styling
- Custom style override support
- Lipgloss-based layout positioning
Example:
layout := PageLayout(PageLayoutProps{
Title: Text(TextProps{Content: "Dashboard"}),
Content: Card(CardProps{Title: "Stats"}),
Actions: Button(ButtonProps{Label: "Refresh"}),
})
func PanelLayout ¶
func PanelLayout(props PanelLayoutProps) bubbly.Component
PanelLayout creates a split panel layout template component. The layout splits the space either horizontally (left/right) or vertically (top/bottom).
Layout Structure (Horizontal):
┌──────────┬──────────────────────┐ │ │ │ │ Left │ Right │ │ │ │ └──────────┴──────────────────────┘
Layout Structure (Vertical):
┌─────────────────────────────────┐ │ Top │ ├─────────────────────────────────┤ │ Bottom │ └─────────────────────────────────┘
Features:
- Horizontal or vertical split panels
- Configurable split ratio
- Optional borders
- Theme integration for consistent styling
- Custom style override support
- Perfect for master-detail views
Example:
layout := PanelLayout(PanelLayoutProps{
Left: List(ListProps{Items: items}),
Right: Card(CardProps{Title: "Details"}),
SplitRatio: 0.3, // 30% left, 70% right
})
func Spacer ¶
func Spacer(props SpacerProps) bubbly.Component
Spacer creates a new Spacer atom component.
Spacer is a layout utility component that creates empty space in the terminal. It can create horizontal space (width), vertical space (height), or both. When Flex=true, the spacer acts as a marker for parent layouts (HStack, VStack, Flex) to fill remaining available space.
Example:
// Fixed horizontal spacer
hSpacer := components.Spacer(components.SpacerProps{
Width: 10,
})
// Fixed vertical spacer
vSpacer := components.Spacer(components.SpacerProps{
Height: 3,
})
// Both dimensions
spacer := components.Spacer(components.SpacerProps{
Width: 20,
Height: 5,
})
// Flexible spacer - fills available space in parent layout
flexSpacer := components.Spacer(components.SpacerProps{
Flex: true,
})
// Flexible spacer with minimum width
flexMinSpacer := components.Spacer(components.SpacerProps{
Flex: true,
Width: 5, // minimum 5 characters, parent can expand
})
// Initialize and use with Bubbletea
spacer.Init()
view := spacer.View()
Use cases:
- Creating margins between components
- Adding padding in layouts
- Vertical spacing between sections
- Horizontal spacing in rows
- Pushing items to opposite ends (Flex=true in HStack)
- Creating flexible gaps in toolbars
Accessibility:
- Invisible but affects layout
- Helps create visual hierarchy
- Improves readability
func Spinner ¶
func Spinner(props SpinnerProps) bubbly.Component
Spinner creates a new Spinner atom component.
Spinner is a loading indicator component that shows an animated symbol to indicate background activity or loading states. It can optionally display a label describing the operation.
The spinner component automatically integrates with the theme system via the composition API's Provide/Inject mechanism. If no theme is provided, it uses DefaultTheme.
Example:
spinner := components.Spinner(components.SpinnerProps{
Label: "Loading data...",
Active: true,
Color: lipgloss.Color("99"),
})
// Initialize and use with Bubbletea
spinner.Init()
view := spinner.View()
Common use cases:
- Loading indicators
- Background processing
- Data fetching states
- Long-running operations
Note: This is a simplified spinner implementation. For advanced animations with Bubbletea tick messages, consider using the bubbles/spinner package directly.
Accessibility:
- Clear visual indication of activity
- Optional label for context
- Can be hidden when inactive
func Tabs ¶
Tabs creates a tabbed interface component. The tabs component displays multiple content panels with tab buttons for switching.
Features:
- Multiple tabs with labels
- Active tab highlighting
- Reactive active index
- OnTabChange callback
- String or Component content
- Theme integration
- Custom style override
Example:
activeIndex := bubbly.NewRef(0)
tabs := Tabs(TabsProps{
Tabs: []Tab{
{Label: "Profile", Content: "User profile content"},
{Label: "Settings", Content: "Settings content"},
{Label: "Security", Content: "Security content"},
},
ActiveIndex: activeIndex,
OnTabChange: func(index int) {
loadTabContent(index)
},
})
func Text ¶
Text creates a new Text atom component.
Text is a fundamental display element for rendering styled text in the terminal. It supports various formatting options including bold, italic, underline, strikethrough, colors, and alignment.
The text component automatically integrates with the theme system via the composition API's Provide/Inject mechanism. If no theme is provided, it uses DefaultTheme.
Example:
text := components.Text(components.TextProps{
Content: "Welcome to BubblyUI!",
Bold: true,
Color: lipgloss.Color("99"),
Alignment: components.AlignCenter,
Width: 40,
})
// Initialize and use with Bubbletea
text.Init()
view := text.View()
Formatting options:
- Bold: Makes text bold
- Italic: Makes text italic
- Underline: Underlines text
- Strikethrough: Strikes through text
- Color: Sets text color
- Background: Sets background color
- Alignment: Aligns text (requires Width)
- Width/Height: Constrains text dimensions
Accessibility:
- Clear visual distinction with formatting options
- High contrast colors available via theme
- Supports all terminal color profiles
func TextArea ¶
func TextArea(props TextAreaProps) bubbly.Component
func Toggle ¶
func Toggle(props ToggleProps) bubbly.Component
Toggle creates a new Toggle molecule component.
Toggle is an interactive switch element that allows users to turn a feature on or off. It supports reactive state binding, callbacks, and disabled states.
The toggle automatically integrates with the theme system via the composition API's Provide/Inject mechanism. If no theme is provided, it uses DefaultTheme.
Example:
valueRef := bubbly.NewRef(false)
toggle := components.Toggle(components.ToggleProps{
Label: "Enable notifications",
Value: valueRef,
OnChange: func(enabled bool) {
if enabled {
enableNotifications()
} else {
disableNotifications()
}
},
})
// Initialize and use with Bubbletea
toggle.Init()
view := toggle.View()
Features:
- Reactive on/off state binding with Ref[bool]
- Toggle functionality via "toggle" event
- OnChange callback support
- Disabled state support
- Label display
- Theme integration
- Custom style override
Keyboard interaction:
- Space/Enter: Toggle switch (when focused)
Visual indicators:
- Off: [OFF] or [─●]
- On: [ON ] or [●─]
Accessibility:
- Clear visual distinction between on/off states
- Disabled state clearly indicated
- Keyboard accessible
func VStack ¶
func VStack(props StackProps) bubbly.Component
VStack creates a vertical stack layout component. Items are arranged vertically (top to bottom) with configurable spacing and cross-axis (horizontal) alignment.
Features:
- Vertical arrangement of child components
- Configurable spacing between items (in lines)
- Cross-axis alignment (start/center/end/stretch)
- Optional dividers between items
- Theme integration for divider styling
- Custom style override support
Example:
// Simple vertical stack
vstack := VStack(StackProps{
Items: []interface{}{header, content, footer},
Spacing: 1,
})
// With alignment and dividers
vstack := VStack(StackProps{
Items: []interface{}{title, description, actions},
Align: AlignItemsCenter,
Divider: true,
})
// Form layout pattern
vstack := VStack(StackProps{
Items: []interface{}{
HStack(StackProps{Items: []interface{}{label1, input1}}),
HStack(StackProps{Items: []interface{}{label2, input2}}),
HStack(StackProps{Items: []interface{}{cancelBtn, submitBtn}}),
},
Spacing: 1,
})
Types ¶
type AccordionItem ¶
type AccordionItem struct {
// Title is the panel header text.
Title string
// Content is the panel body text.
Content string
// Component is an optional component to render as content.
// If provided, takes precedence over Content string.
Component bubbly.Component
}
AccordionItem represents a single accordion panel.
type AccordionProps ¶
type AccordionProps struct {
// Items is the list of accordion panels.
// Required - should not be empty.
Items []AccordionItem
// ExpandedIndexes is the reactive reference to the list of expanded panel indexes.
// Optional - if nil, no panels are expanded initially.
ExpandedIndexes *bubbly.Ref[[]int]
// AllowMultiple allows multiple panels to be expanded simultaneously.
// If false, expanding a panel collapses others.
// Default is false.
AllowMultiple bool
// OnToggle is called when a panel is toggled.
// Receives the panel index and new expanded state.
// Optional - if nil, no callback is executed.
OnToggle func(int, bool)
// Width sets the accordion width in characters.
// Default is 50 if not specified.
Width int
// CommonProps for styling and identification.
CommonProps
}
AccordionProps defines the properties for the Accordion component. Accordion is an organism component that displays collapsible panels.
type AlignItems ¶
type AlignItems string
AlignItems specifies how items are aligned along the cross axis. This follows CSS flexbox align-items semantics.
const ( // AlignItemsStart aligns items to the start of the cross axis. AlignItemsStart AlignItems = "start" // AlignItemsCenter centers items along the cross axis. AlignItemsCenter AlignItems = "center" // AlignItemsEnd aligns items to the end of the cross axis. AlignItemsEnd AlignItems = "end" // AlignItemsStretch stretches items to fill the cross axis. AlignItemsStretch AlignItems = "stretch" )
func (AlignItems) IsValid ¶
func (a AlignItems) IsValid() bool
IsValid returns true if the AlignItems is a valid constant.
type AppLayoutProps ¶
type AppLayoutProps struct {
// Header is the top section component (optional).
// Typically contains application title, navigation, or branding.
Header bubbly.Component
// Sidebar is the left section component (optional).
// Typically contains navigation menu or secondary content.
Sidebar bubbly.Component
// Content is the main center section component (required).
// Contains the primary application content.
Content bubbly.Component
// Typically contains copyright, links, or status information.
Footer bubbly.Component
// Width sets the total layout width in characters.
// Default is 80 if not specified.
Width int
// Height sets the total layout height in lines.
// Default is 24 if not specified.
Height int
// SidebarWidth sets the sidebar width in characters.
// Default is 20 if not specified.
SidebarWidth int
// HeaderHeight sets the header height in lines.
// Default is 3 if not specified.
HeaderHeight int
// Default is 2 if not specified.
FooterHeight int
// CommonProps for styling and identification.
CommonProps
}
AppLayoutProps defines the properties for the AppLayout component. AppLayout is a template component that provides a full application layout structure.
type BadgeProps ¶
type BadgeProps struct {
// Label is the text content to display in the badge.
// Required - the main text to show.
Label string
// Variant determines the visual style of the badge.
// Valid values: VariantPrimary, VariantSecondary, VariantSuccess, VariantWarning, VariantDanger, VariantInfo.
// Optional - defaults to VariantPrimary if not specified.
Variant Variant
// Color sets a custom foreground color for the badge.
// Overrides the variant color if specified.
// Optional - if not specified, uses variant color from theme.
Color lipgloss.Color
// Common props for all components
CommonProps
}
BadgeProps defines the configuration properties for a Badge component.
Example usage:
badge := components.Badge(components.BadgeProps{
Label: "New",
Variant: components.VariantSuccess,
})
type BoxProps ¶
type BoxProps struct {
// Child is an optional child component to render inside the box.
// If provided, it takes precedence over Content.
Child bubbly.Component
// Content is the text content to display inside the box.
// Used when Child is nil.
Content string
// Padding sets uniform padding on all sides (in characters/lines).
// Default is 0 (no padding).
Padding int
// PaddingX sets horizontal padding (left and right).
// If set, overrides Padding for horizontal sides.
PaddingX int
// PaddingY sets vertical padding (top and bottom).
// If set, overrides Padding for vertical sides.
PaddingY int
// Border enables a border around the box.
// Default is false (no border).
Border bool
// BorderStyle specifies the border style to use.
// Default is lipgloss.NormalBorder() when Border is true.
BorderStyle lipgloss.Border
// Title is optional text displayed at the top of the box.
// Rendered as a styled header line inside the box.
Title string
// Width sets the fixed width of the box in characters.
// Default is 0 (auto-width based on content).
Width int
// Height sets the fixed height of the box in lines.
// Default is 0 (auto-height based on content).
Height int
// Background sets the background color inside the box.
// Default is no background color.
Background lipgloss.Color
// CommonProps for styling and identification.
CommonProps
}
BoxProps defines the properties for the Box container component. Box is an atom component that provides a generic container with padding, border, and title support. It serves as a building block for higher-level layouts.
type ButtonProps ¶
type ButtonProps struct {
// Label is the text displayed on the button.
// Required - should not be empty for usability.
Label string
// Variant determines the visual style of the button.
// Defaults to ButtonPrimary if not specified.
// Valid values: ButtonPrimary, ButtonSecondary, ButtonDanger, ButtonSuccess, ButtonWarning, ButtonInfo.
Variant ButtonVariant
// Disabled indicates whether the button is disabled.
// Disabled buttons do not respond to click events and are styled differently.
// Default: false (enabled).
Disabled bool
// OnClick is the callback function executed when the button is clicked.
// Only called if the button is not disabled.
// Optional - if nil, button will not respond to clicks.
OnClick func()
// NoBorder removes the border if true.
// Default is false (border is shown).
// Useful when embedding in other bordered containers.
NoBorder bool
// Common props for all components
CommonProps
}
ButtonProps defines the configuration properties for a Button component.
Example usage:
button := components.Button(components.ButtonProps{
Label: "Submit",
Variant: components.ButtonPrimary,
OnClick: func() {
handleSubmit()
},
})
type ButtonVariant ¶
type ButtonVariant string
ButtonVariant defines the visual style variant of a button. Variants map to theme colors for consistent styling across the application.
const ( // ButtonPrimary represents the primary/default button variant. // Used for main actions and primary calls-to-action. ButtonPrimary ButtonVariant = "primary" // ButtonSecondary represents a secondary/alternative button variant. // Used for less prominent actions. ButtonSecondary ButtonVariant = "secondary" // ButtonDanger represents a destructive/dangerous action variant. // Used for delete, remove, or other destructive operations. ButtonDanger ButtonVariant = "danger" // ButtonSuccess represents a successful/positive action variant. // Used for confirmations and positive actions. ButtonSuccess ButtonVariant = "success" // ButtonWarning represents a warning/caution variant. // Used for actions that require user attention. ButtonWarning ButtonVariant = "warning" // ButtonInfo represents an informational variant. // Used for neutral informational actions. ButtonInfo ButtonVariant = "info" )
Button variant constants.
type CardProps ¶
type CardProps struct {
// Title is the card header text.
// Optional - if empty, no title is displayed.
Title string
// Content is the main body text of the card.
// Optional - can be empty if using Children instead.
Content string
// Optional - if empty, no footer is displayed.
Footer string
// Children are optional child components rendered in the card body.
// These are rendered after Content if both are provided.
// Optional - if empty, only Content is displayed.
Children []bubbly.Component
// Width sets the card width in characters.
// Default is 40 if not specified.
Width int
// Height sets the card height in lines.
// Default is auto-height based on content if not specified.
Height int
// Padding sets the internal padding.
// Default is 1 if not specified.
Padding int
// NoBorder removes the border if true.
// Default is false (border is shown).
NoBorder bool
// CommonProps for styling and identification.
CommonProps
}
CardProps defines the properties for the Card component. Card is an organism component that displays a content container with optional title and footer.
type CenterProps ¶
type CenterProps struct {
// Child is the component to center within the container.
// If nil, the Center component renders an empty container.
Child bubbly.Component
// Width sets the container width in characters.
// Default is 0 (auto-width based on content).
// Horizontal centering requires a Width > 0.
Width int
// Height sets the container height in lines.
// Default is 0 (auto-height based on content).
// Vertical centering requires a Height > 0.
Height int
// Horizontal enables horizontal-only centering when true.
// When false and Vertical is also false, centers both directions (default).
// Default is false.
Horizontal bool
// Vertical enables vertical-only centering when true.
// When false and Horizontal is also false, centers both directions (default).
// Default is false.
Vertical bool
// CommonProps for styling and identification.
CommonProps
}
CenterProps defines the properties for the Center layout component. Center is a molecule component that centers its child component horizontally and/or vertically within a container of specified dimensions.
By default, when neither Horizontal nor Vertical flags are set, the component centers content in both directions. Setting either flag to true enables centering only in that specific direction.
type CheckboxProps ¶
type CheckboxProps struct {
// Label is the text displayed next to the checkbox.
// Optional - if empty, only the checkbox indicator is shown.
Label string
// Checked is the reactive reference to the checkbox's checked state.
// Required - must be a valid Ref[bool].
// Changes to this ref will update the checkbox display.
Checked *bubbly.Ref[bool]
// OnChange is a callback function executed when the checkbox is toggled.
// Receives the new checked state as a parameter.
// Optional - if nil, no callback is executed.
OnChange func(bool)
// Disabled indicates whether the checkbox is disabled.
// Disabled checkboxes do not respond to toggle events and are styled differently.
// Default: false (enabled).
Disabled bool
// Common props for all components
CommonProps
}
CheckboxProps defines the configuration properties for a Checkbox component.
Example usage:
checkedRef := bubbly.NewRef(false)
checkbox := components.Checkbox(components.CheckboxProps{
Label: "Accept terms and conditions",
Checked: checkedRef,
OnChange: func(checked bool) {
fmt.Println("Checkbox is now:", checked)
},
})
type CommonProps ¶
type CommonProps struct {
// ID is a unique identifier for the component instance.
// Optional - if not provided, components generate their own IDs.
ID ComponentID
// ClassName allows applying custom styling classes.
// Optional - used for custom theming and styling overrides.
ClassName ClassName
// Style provides direct Lipgloss style overrides.
// Optional - takes precedence over theme and className styles.
Style *lipgloss.Style
}
CommonProps contains properties shared by all components. These props provide consistent styling and identification across the component library.
type ComponentID ¶
type ComponentID string
ComponentID is a unique identifier for a component instance.
type ContainerProps ¶
type ContainerProps struct {
// Child is the component to render inside the container.
// If nil, the Container renders an empty space with the specified width.
Child bubbly.Component
// Size is a preset container size that determines the max-width.
// Available sizes: ContainerSm (40), ContainerMd (60), ContainerLg (80),
// ContainerXl (100), ContainerFull (no constraint).
// Default is ContainerMd (60 characters).
Size ContainerSize
// MaxWidth overrides Size with a custom maximum width in characters.
// When MaxWidth > 0, it takes precedence over the Size preset.
// Default is 0 (use Size preset).
MaxWidth int
// Centered horizontally centers the content within the container width.
// When true, content is centered using Lipgloss alignment.
// Default is true.
// Use CenteredSet to explicitly disable centering (set Centered=false, CenteredSet=true).
Centered bool
// CenteredSet indicates whether Centered was explicitly set.
// This allows distinguishing between "not set" (default true) and "explicitly false".
CenteredSet bool
// CommonProps for styling and identification.
CommonProps
}
ContainerProps defines the properties for the Container layout component. Container is a molecule component that constrains content width and optionally centers it horizontally within the available space.
Container is useful for creating readable content layouts by limiting line length to comfortable reading widths (typically 60-80 characters).
type ContainerSize ¶
type ContainerSize string
ContainerSize specifies preset container widths for readable content. These sizes are optimized for terminal layouts.
const ( // ContainerSm is a small container (40 characters wide). ContainerSm ContainerSize = "sm" // ContainerMd is a medium container (60 characters wide). ContainerMd ContainerSize = "md" // ContainerLg is a large container (80 characters wide). ContainerLg ContainerSize = "lg" // ContainerXl is an extra-large container (100 characters wide). ContainerXl ContainerSize = "xl" // ContainerFull uses full available width (100%). ContainerFull ContainerSize = "full" )
func (ContainerSize) IsValid ¶
func (s ContainerSize) IsValid() bool
IsValid returns true if the ContainerSize is a valid constant.
func (ContainerSize) Width ¶
func (s ContainerSize) Width() int
Width returns the preset width in characters for the ContainerSize. Returns 0 for ContainerFull (meaning 100%/auto) or unknown sizes.
type DividerProps ¶
type DividerProps struct {
// Vertical renders a vertical divider if true.
// Default: false (horizontal)
Vertical bool
// Length is the divider length in characters (horizontal) or lines (vertical).
// Default: 20
Length int
// Label is optional text centered on the divider.
// For horizontal dividers, the label appears in the middle of the line.
// For vertical dividers, the label appears in the middle row.
Label string
// Char is the divider character.
// Default: "─" (horizontal) or "│" (vertical)
Char string
// CommonProps for styling and identification.
CommonProps
}
DividerProps defines the properties for the Divider component. Divider is an atom component that renders a horizontal or vertical separator line with optional label text.
type EventHandler ¶
type EventHandler func(data interface{})
EventHandler is a generic event handler function. It receives event data and performs an action.
type FlexDirection ¶
type FlexDirection string
FlexDirection specifies the main axis direction for Flex layouts. Use FlexRow for horizontal layouts and FlexColumn for vertical layouts.
const ( // FlexRow arranges items horizontally (left to right). FlexRow FlexDirection = "row" // FlexColumn arranges items vertically (top to bottom). FlexColumn FlexDirection = "column" )
func (FlexDirection) IsValid ¶
func (d FlexDirection) IsValid() bool
IsValid returns true if the FlexDirection is a valid constant.
type FlexProps ¶
type FlexProps struct {
// Items are the child components to arrange.
Items []bubbly.Component
// Direction specifies row (horizontal) or column (vertical).
// Default: FlexRow
Direction FlexDirection
// Justify controls main-axis distribution.
// Default: JustifyStart
Justify JustifyContent
// Align controls cross-axis alignment.
// Default: AlignItemsStart
Align AlignItems
// Gap is the spacing between items in characters.
// Default: 0
Gap int
// Wrap enables wrapping items to next row/column when they exceed
// the container size. Requires Width (for row) or Height (for column).
// Default: false
Wrap bool
// Width sets fixed container width. 0 = auto.
Width int
// Height sets fixed container height. 0 = auto.
Height int
// CommonProps for styling and identification.
CommonProps
}
FlexProps defines properties for the Flex layout component. Flex provides flexbox-style layout with direction, justify, and align options.
Example:
// Row layout with space-between
flex := Flex(FlexProps{
Items: []bubbly.Component{btn1, btn2, btn3},
Direction: FlexRow,
Justify: JustifySpaceBetween,
Gap: 2,
})
// Column layout centered
flex := Flex(FlexProps{
Items: []bubbly.Component{header, content, footer},
Direction: FlexColumn,
Justify: JustifyCenter,
Align: AlignItemsCenter,
})
type FormField ¶
type FormField struct {
// Name is the unique identifier for this field.
// Used for validation error mapping.
// Required - must be unique within the form.
Name string
// Label is the display text shown above the field.
// Optional - if empty, no label is displayed.
Label string
// Component is the input component for this field.
// Can be Input, Checkbox, Select, TextArea, Radio, Toggle, etc.
// Required - must be a valid component.
Component bubbly.Component
}
FormField represents a single field in a form. Each field has a name (for identification), a label (for display), and a component (the actual input/select/checkbox/etc.).
type FormProps ¶
type FormProps[T any] struct { // Initial is the initial form data. // Used to populate the form on first render and for reset functionality. // Required - must be a valid struct of type T. Initial T // Validate is a function that validates the entire form. // Returns a map of field names to error messages. // Optional - if nil, no validation is performed. // Called on submit and optionally on field changes. Validate func(T) map[string]string // OnSubmit is a callback function executed when the form is submitted. // Only called if validation passes (no errors). // Receives the validated form data as a parameter. // Optional - if nil, no callback is executed. OnSubmit func(T) // OnCancel is a callback function executed when the form is canceled. // Optional - if nil, no callback is executed. OnCancel func() // Fields is the list of form fields to display. // Each field includes a name, label, and component. // Required - should not be empty for usability. Fields []FormField // Common props for all components CommonProps }
FormProps defines the configuration properties for a Form component.
Form is a generic component that works with any struct type T. It manages form state, validation, and submission.
Example usage:
type UserData struct {
Name string
Email string
Age int
}
nameRef := bubbly.NewRef("")
emailRef := bubbly.NewRef("")
form := components.Form(components.FormProps[UserData]{
Initial: UserData{},
Fields: []components.FormField{
{
Name: "Name",
Label: "Full Name",
Component: components.Input(components.InputProps{
Value: nameRef,
Placeholder: "Enter your name",
}),
},
{
Name: "Email",
Label: "Email Address",
Component: components.Input(components.InputProps{
Value: emailRef,
Type: components.InputEmail,
}),
},
},
Validate: func(data UserData) map[string]string {
errors := make(map[string]string)
if data.Name == "" {
errors["Name"] = "Name is required"
}
if data.Email == "" {
errors["Email"] = "Email is required"
}
return errors
},
OnSubmit: func(data UserData) {
saveUser(data)
},
})
type GridLayoutProps ¶
type GridLayoutProps struct {
// Items are the components to arrange in the grid.
// Required - the components to display in grid cells.
Items []bubbly.Component
// Columns sets the number of columns in the grid.
// Default is 1 if not specified.
Columns int
// Gap sets the spacing between grid cells in characters.
// Default is 1 if not specified.
Gap int
// CellWidth sets the width of each grid cell in characters.
// Default is 20 if not specified.
CellWidth int
// CellHeight sets the height of each grid cell in lines.
// Default is 0 (auto-height based on content) if not specified.
CellHeight int
// CommonProps for styling and identification.
CommonProps
}
GridLayoutProps defines the properties for the GridLayout component. GridLayout is a template component that provides a grid-based layout system.
type IconProps ¶
type IconProps struct {
// Symbol is the icon character or glyph to display.
// Can be any Unicode character, emoji, or symbol.
// Required - the main icon to render.
Symbol string
// Color sets the foreground color of the icon.
// Supports ANSI colors, 256-color palette, and true color.
// Optional - if not specified, uses theme foreground color.
Color lipgloss.Color
// Size determines the visual size of the icon.
// Valid values: SizeSmall, SizeMedium, SizeLarge.
// Optional - if not specified, uses natural size.
Size Size
// Common props for all components
CommonProps
}
IconProps defines the configuration properties for an Icon component.
Example usage:
icon := components.Icon(components.IconProps{
Symbol: "✓",
Color: lipgloss.Color("46"),
Size: components.SizeMedium,
})
type InputProps ¶
type InputProps struct {
// Value is the reactive reference to the input's value.
// Required - must be a valid Ref[string].
// Changes to this ref will update the input display.
Value *bubbly.Ref[string]
// Placeholder is the text displayed when the input is empty.
// Optional - if empty, no placeholder is shown.
Placeholder string
// Type determines the input field type.
// Valid values: InputText, InputPassword, InputEmail.
// Default: InputText.
Type InputType
// Validate is a function called when the value changes.
// If it returns an error, the error message is displayed below the input.
// Optional - if nil, no validation is performed.
Validate func(string) error
// OnChange is a callback function executed when the value changes.
// Called after validation.
// Optional - if nil, no callback is executed.
OnChange func(string)
// OnBlur is a callback function executed when the input loses focus.
// Optional - if nil, no callback is executed.
OnBlur func()
// Width sets the width of the input field in characters.
// Optional - if 0, defaults to 30 characters.
Width int
// CharLimit sets the maximum number of characters allowed.
// Optional - if 0, no limit is enforced.
CharLimit int
// ShowCursorPosition displays the cursor position indicator [pos/len].
// Optional - defaults to false.
ShowCursorPosition bool
// NoBorder removes the border if true.
// Default is false (border is shown).
// Useful when embedding in other bordered containers.
NoBorder bool
// Common props for all components
CommonProps
}
InputProps defines the configuration properties for an Input component.
Example usage:
valueRef := bubbly.NewRef("")
input := components.Input(components.InputProps{
Value: valueRef,
Placeholder: "Enter your name",
Type: components.InputText,
Validate: func(s string) error {
if len(s) < 3 {
return errors.New("name must be at least 3 characters")
}
return nil
},
})
type InputType ¶
type InputType string
InputType defines the type of input field. Different types may have different validation and display behavior.
const ( // InputText represents a standard text input field. // Displays characters as typed. InputText InputType = "text" // InputPassword represents a password input field. // Masks characters with asterisks for security. InputPassword InputType = "password" // InputEmail represents an email input field. // Displays characters as typed, intended for email addresses. InputEmail InputType = "email" )
Input type constants.
type JustifyContent ¶
type JustifyContent string
JustifyContent specifies how items are distributed along the main axis. This follows CSS flexbox justify-content semantics.
const ( // JustifyStart aligns items to the start of the container. JustifyStart JustifyContent = "start" // JustifyCenter centers items in the container. JustifyCenter JustifyContent = "center" // JustifyEnd aligns items to the end of the container. JustifyEnd JustifyContent = "end" // JustifySpaceBetween distributes items with equal space between them. // First item at start, last item at end. JustifySpaceBetween JustifyContent = "space-between" // JustifySpaceAround distributes items with equal space around them. // Half-size space on the edges. JustifySpaceAround JustifyContent = "space-around" // JustifySpaceEvenly distributes items with equal space everywhere. // Equal space between items and on edges. JustifySpaceEvenly JustifyContent = "space-evenly" )
func (JustifyContent) IsValid ¶
func (j JustifyContent) IsValid() bool
IsValid returns true if the JustifyContent is a valid constant.
type ListProps ¶
type ListProps[T any] struct { // Items is a reactive reference to the list data. // Must be a slice of type T. // Required - updates trigger re-renders. Items *bubbly.Ref[[]T] // RenderItem is a function that renders each item. // Receives the item and its index as parameters. // Required - defines how each item is displayed. RenderItem func(T, int) string // Height is the visible height of the list in lines. // Items beyond this height require scrolling. // Optional - defaults to 10 if not specified. Height int // Virtual enables virtual scrolling for large lists. // When true, only visible items are rendered for performance. // Recommended for lists with 100+ items. // Optional - defaults to false. Virtual bool // OnSelect is a callback function executed when an item is selected. // Receives the selected item and its index as parameters. // Optional - if nil, no callback is executed. OnSelect func(T, int) // Common props for all components CommonProps }
ListProps defines the configuration properties for a List component.
List is a generic component that works with any slice type []T. It displays a scrollable list of items with optional virtual scrolling for performance, keyboard navigation, and item selection.
Example usage:
type Todo struct {
Title string
Completed bool
}
todosData := bubbly.NewRef([]Todo{
{Title: "Buy groceries", Completed: false},
{Title: "Write code", Completed: true},
})
list := components.List(components.ListProps[Todo]{
Items: todosData,
RenderItem: func(todo Todo, index int) string {
checkbox := "☐"
if todo.Completed {
checkbox = "☑"
}
return fmt.Sprintf("%s %s", checkbox, todo.Title)
},
Height: 10,
Virtual: true,
})
type MenuItem ¶
type MenuItem struct {
// Label is the display text for the menu item.
Label string
// Value is the unique identifier for the menu item.
Value string
// Disabled indicates if the menu item is disabled.
Disabled bool
}
MenuItem represents a single menu item.
type MenuProps ¶
type MenuProps struct {
// Items is the list of menu items to display.
// Required - should not be empty.
Items []MenuItem
// Selected is the reactive reference to the currently selected item value.
// Optional - if nil, no item is selected initially.
Selected *bubbly.Ref[string]
// OnSelect is called when a menu item is selected.
// Receives the selected item's value.
// Optional - if nil, no callback is executed.
OnSelect func(string)
// Width sets the menu width in characters.
// Default is 30 if not specified.
Width int
// CommonProps for styling and identification.
CommonProps
}
MenuProps defines the properties for the Menu component. Menu is an organism component that displays a navigable list of items.
type ModalProps ¶
type ModalProps struct {
// Title is the modal header text.
Title string
// Content is the main body text of the modal.
Content string
// Visible controls whether the modal is displayed.
// When false, the modal renders nothing.
Visible *bubbly.Ref[bool]
// Width sets the modal width in characters.
// Default is 50 if not specified.
Width int
// Buttons are optional action buttons displayed at the bottom.
Buttons []bubbly.Component
// OnClose is called when the modal is closed (Esc key).
OnClose func()
// OnConfirm is called when Enter key is pressed.
OnConfirm func()
// CommonProps for styling and identification.
CommonProps
}
ModalProps defines the properties for the Modal component. Modal is an organism component that displays an overlay dialog.
type PageLayoutProps ¶
type PageLayoutProps struct {
// Title is the page title section component (optional).
// Typically contains page heading or breadcrumbs.
Title bubbly.Component
// Content is the main page content section component (required).
// Contains the primary page content.
Content bubbly.Component
// Actions is the page actions section component (optional).
// Typically contains buttons or action controls at the bottom.
Actions bubbly.Component
// Width sets the total layout width in characters.
// Default is 80 if not specified.
Width int
// Spacing sets the vertical spacing between sections in lines.
// Default is 2 if not specified.
Spacing int
// CommonProps for styling and identification.
CommonProps
}
PageLayoutProps defines the properties for the PageLayout component. PageLayout is a template component that provides a simple page structure.
type PanelLayoutProps ¶
type PanelLayoutProps struct {
// Left is the left panel component (or top panel in vertical mode).
// Optional - if empty, only Right panel is displayed.
Left bubbly.Component
// Right is the right panel component (or bottom panel in vertical mode).
// Optional - if empty, only Left panel is displayed.
Right bubbly.Component
// Direction sets the split direction: "horizontal" (left/right) or "vertical" (top/bottom).
// Default is "horizontal" if not specified.
Direction string
// SplitRatio sets the ratio between left/right (or top/bottom) panels.
// Value between 0.0 and 1.0. Default is 0.5 (50/50 split).
// For example, 0.3 means 30% left, 70% right.
SplitRatio float64
// Width sets the total layout width in characters.
// Default is 80 if not specified.
Width int
// Height sets the total layout height in lines.
// Default is 24 if not specified.
Height int
// ShowBorder enables borders around panels.
// Default is false.
ShowBorder bool
// CommonProps for styling and identification.
CommonProps
}
PanelLayoutProps defines the properties for the PanelLayout component. PanelLayout is a template component that provides a split panel layout.
type Position ¶
type Position string
Position represents the position of an element.
const ( // PositionTop positions element at the top. PositionTop Position = "top" // PositionBottom positions element at the bottom. PositionBottom Position = "bottom" // PositionLeft positions element on the left. PositionLeft Position = "left" // PositionRight positions element on the right. PositionRight Position = "right" )
Common position constants.
type RadioProps ¶
type RadioProps[T any] struct { // Value is the reactive reference to the selected value. // Required - must be a valid Ref[T]. // Changes to this ref will update the radio display. Value *bubbly.Ref[T] // Options is the list of available options to choose from. // Required - should not be empty for usability. Options []T // OnChange is a callback function executed when the selection changes. // Receives the newly selected value as a parameter. // Optional - if nil, no callback is executed. OnChange func(T) // Disabled indicates whether the radio is disabled. // Disabled radios do not respond to events and are styled differently. // Default: false (enabled). Disabled bool // RenderOption is a custom function to render each option as a string. // Optional - if nil, uses fmt.Sprintf("%v", option) for default rendering. // Useful for complex types that need custom display logic. RenderOption func(T) string // Common props for all components CommonProps }
RadioProps defines the configuration properties for a Radio component.
Radio is a generic component that works with any type T.
Example usage:
valueRef := bubbly.NewRef("option1")
radio := components.Radio(components.RadioProps[string]{
Value: valueRef,
Options: []string{"option1", "option2", "option3"},
OnChange: func(value string) {
fmt.Println("Selected:", value)
},
})
type RenderFunc ¶
type RenderFunc func() string
RenderFunc is a function that renders content to a string. Used for custom rendering in components like List and Table.
type SelectProps ¶
type SelectProps[T any] struct { // Value is the reactive reference to the selected value. // Required - must be a valid Ref[T]. // Changes to this ref will update the select display. Value *bubbly.Ref[T] // Options is the list of available options to choose from. // Required - should not be empty for usability. Options []T // OnChange is a callback function executed when the selection changes. // Receives the newly selected value as a parameter. // Optional - if nil, no callback is executed. OnChange func(T) // Placeholder is the text displayed when no value is selected. // Optional - if empty, shows the first option or empty string. Placeholder string // Disabled indicates whether the select is disabled. // Disabled selects do not respond to events and are styled differently. // Default: false (enabled). Disabled bool // RenderOption is a custom function to render each option as a string. // Optional - if nil, uses fmt.Sprintf("%v", option) for default rendering. // Useful for complex types that need custom display logic. RenderOption func(T) string // Width sets the width of the select in characters. // Optional - if 0, defaults to 30 characters. Width int // NoBorder removes the border if true. // Default is false (border is shown). // Useful when embedding in other bordered containers. NoBorder bool // Common props for all components CommonProps }
SelectProps defines the configuration properties for a Select component.
Select is a generic component that works with any type T.
Example usage:
valueRef := bubbly.NewRef("option1")
selectComp := components.Select(components.SelectProps[string]{
Value: valueRef,
Options: []string{"option1", "option2", "option3"},
OnChange: func(value string) {
fmt.Println("Selected:", value)
},
})
type Size ¶
type Size string
Size represents the size of a component. Common sizes include "small", "medium", "large".
type SpacerProps ¶
type SpacerProps struct {
// Flex makes the spacer fill available space in parent layouts.
// When true, the spacer expands to fill remaining space in HStack/VStack/Flex.
// Width and Height become minimum dimensions when Flex is true.
// Default: false (fixed-size spacer)
Flex bool
// Width sets the horizontal space in characters.
// When Flex=false: exact width to render.
// When Flex=true: minimum width (parent layout may expand beyond this).
// Optional - if 0, no horizontal space is added (or auto when Flex=true).
Width int
// Height sets the vertical space in lines.
// When Flex=false: exact height to render.
// When Flex=true: minimum height (parent layout may expand beyond this).
// Optional - if 0, no vertical space is added (or auto when Flex=true).
Height int
// Common props for all components
CommonProps
}
SpacerProps defines the configuration properties for a Spacer component.
Example usage:
// Fixed-size spacer
spacer := components.Spacer(components.SpacerProps{
Width: 20,
Height: 3,
})
// Flexible spacer (fills available space in parent layout)
flexSpacer := components.Spacer(components.SpacerProps{
Flex: true,
})
func (SpacerProps) IsFlex ¶
func (p SpacerProps) IsFlex() bool
IsFlex returns true if this spacer should fill available space. Parent layouts (HStack, VStack, Flex) use this to detect flexible spacers and distribute remaining space accordingly.
type SpinnerProps ¶
type SpinnerProps struct {
// Label is optional text to display next to the spinner.
// Typically used to describe what is loading.
// Optional - if empty, only the spinner animation is shown.
Label string
// Active determines whether the spinner is animating.
// When false, the spinner is hidden or shows a static state.
// Default: false.
Active bool
// Color sets the foreground color of the spinner.
// Optional - if not specified, uses theme primary color.
Color lipgloss.Color
// Common props for all components
CommonProps
}
SpinnerProps defines the configuration properties for a Spinner component.
Example usage:
spinner := components.Spinner(components.SpinnerProps{
Label: "Loading...",
Active: true,
Color: lipgloss.Color("99"),
})
type StackProps ¶
type StackProps struct {
// Items are the child components to stack.
// Each item can be any bubbly.Component.
Items []interface{}
// Spacing between items in characters (HStack) or lines (VStack).
// Default: 1
Spacing int
// Align controls cross-axis alignment.
// For HStack: vertical alignment (top/center/bottom)
// For VStack: horizontal alignment (left/center/right)
// Default: AlignItemsStart
Align AlignItems
// Divider optionally renders a divider between items.
// Default: false
Divider bool
// DividerChar is the character for dividers.
// Default: "│" for HStack, "─" for VStack
DividerChar string
// CommonProps for styling and identification.
CommonProps
}
StackProps defines the properties for HStack and VStack components. Stack components provide simplified stacking layouts with spacing and alignment.
type Tab ¶
type Tab struct {
// Label is the tab button text.
Label string
// Content is the content to display when tab is active.
// Can be a string or use a Component for dynamic content.
Content string
// Component is an optional component to render as content.
// If provided, takes precedence over Content string.
Component bubbly.Component
}
Tab represents a single tab with label and content.
type TableColumn ¶
type TableColumn[T any] struct { // Header is the display text shown in the table header row. // Required - should be descriptive of the column content. Header string // Field is the name of the struct field to display in this column. // Must match an exported field name in type T. // Required - used with reflection to extract values. Field string // Width is the column width in characters. // Values longer than this will be truncated with "...". // Required - should be > 0 for proper layout. Width int // Sortable indicates if this column can be sorted. // When true and table Sortable is true, clicking header sorts by this column. // Optional - defaults to false. Sortable bool // Render is an optional custom rendering function. // If provided, it overrides the default field value extraction. // Useful for formatting dates, numbers, or complex types. // Optional - if nil, uses default fmt.Sprintf("%v", value). Render func(T) string }
TableColumn defines a single column in a table. Each column has a header, field name, width, and optional custom render function.
type TableProps ¶
type TableProps[T any] struct { // Data is a reactive reference to the table data. // Must be a slice of type T. // Required - updates trigger re-renders. Data *bubbly.Ref[[]T] // Columns defines the table columns to display. // Each column specifies header, field, width, and optional render function. // Required - should not be empty for usability. Columns []TableColumn[T] // Sortable enables sorting functionality for the entire table. // When true, columns with Sortable=true can be sorted by clicking headers. // Clicking a sorted column toggles between ascending/descending. // Optional - defaults to false. Sortable bool // OnRowClick is a callback function executed when a row is clicked. // Receives the row data and index as parameters. // Optional - if nil, no callback is executed. OnRowClick func(T, int) // Common props for all components CommonProps }
TableProps defines the configuration properties for a Table component.
Table is a generic component that works with any slice type []T. It displays tabular data with columns, supports row selection, and integrates with the reactive system for dynamic data updates.
Example usage:
type User struct {
Name string
Email string
Age int
}
usersData := bubbly.NewRef([]User{
{Name: "Alice", Email: "alice@example.com", Age: 30},
{Name: "Bob", Email: "bob@example.com", Age: 25},
})
table := components.Table(components.TableProps[User]{
Data: usersData,
Columns: []components.TableColumn[User]{
{Header: "Name", Field: "Name", Width: 20},
{Header: "Email", Field: "Email", Width: 30},
{Header: "Age", Field: "Age", Width: 10},
},
OnRowClick: func(user User, index int) {
showUserDetails(user)
},
})
type TabsProps ¶
type TabsProps struct {
// Tabs is the list of tabs to display.
// Required - should not be empty.
Tabs []Tab
// ActiveIndex is the reactive reference to the currently active tab index.
// Optional - defaults to 0 (first tab).
ActiveIndex *bubbly.Ref[int]
// OnTabChange is called when the active tab changes.
// Receives the new tab index.
// Optional - if nil, no callback is executed.
OnTabChange func(int)
// Width sets the tabs container width in characters.
// Default is 60 if not specified.
Width int
// CommonProps for styling and identification.
CommonProps
}
TabsProps defines the properties for the Tabs component. Tabs is an organism component that displays tabbed interface.
type TextAreaProps ¶
type TextAreaProps struct {
// Value is the reactive reference to the textarea's text content.
// Required - must be a valid Ref[string].
// Changes to this ref will update the textarea display.
// Supports multi-line text with \n for line breaks.
Value *bubbly.Ref[string]
// Placeholder is the text displayed when the textarea is empty.
// Optional - if empty, no placeholder is shown.
Placeholder string
// Rows is the height of the textarea in lines.
// Default: 3 if not specified or <= 0.
Rows int
// MaxLength is the maximum number of characters allowed.
// Optional - if 0, no limit is enforced.
MaxLength int
// OnChange is a callback function executed when the text changes.
// Receives the new text value as a parameter.
// Optional - if nil, no callback is executed.
OnChange func(string)
// Validate is a function to validate the current text.
// Returns an error if validation fails, nil if valid.
// Optional - if nil, no validation is performed.
Validate func(string) error
// Disabled indicates whether the textarea is disabled.
// Disabled textareas do not respond to events and are styled differently.
// Default: false (enabled).
Disabled bool
// Width sets the width of the textarea in characters.
// Optional - if 0, defaults to 40 characters.
Width int
// NoBorder removes the border if true.
// Default is false (border is shown).
// Useful when embedding in other bordered containers.
NoBorder bool
// Common props for all components
CommonProps
}
TextAreaProps defines the configuration properties for a TextArea component.
Example usage:
valueRef := bubbly.NewRef("Enter your\nmulti-line\ntext here")
textarea := components.TextArea(components.TextAreaProps{
Value: valueRef,
Placeholder: "Type something...",
Rows: 5,
OnChange: func(value string) {
fmt.Println("Text changed:", value)
},
})
type TextProps ¶
type TextProps struct {
// Content is the text content to display.
// Required - the main text to render.
Content string
// Bold applies bold formatting to the text.
// Default: false.
Bold bool
// Italic applies italic formatting to the text.
// Default: false.
Italic bool
// Underline applies underline formatting to the text.
// Default: false.
Underline bool
// Strikethrough applies strikethrough formatting to the text.
// Default: false.
Strikethrough bool
// Color sets the foreground color of the text.
// Supports ANSI colors, 256-color palette, and true color.
// Optional - if not specified, uses theme foreground color.
Color lipgloss.Color
// Background sets the background color of the text.
// Optional - if not specified, uses transparent background.
Background lipgloss.Color
// Alignment sets the horizontal alignment of the text.
// Valid values: AlignLeft, AlignCenter, AlignRight.
// Only applies when Width is set.
// Default: AlignLeft.
Alignment Alignment
// Width sets the width constraint for the text.
// When set, text will be aligned according to Alignment.
// Optional - if 0, text uses natural width.
Width int
// Height sets the height constraint for the text.
// Optional - if 0, text uses natural height.
Height int
// Common props for all components
CommonProps
}
TextProps defines the configuration properties for a Text component.
Example usage:
text := components.Text(components.TextProps{
Content: "Hello, World!",
Bold: true,
Color: lipgloss.Color("63"),
Alignment: components.AlignCenter,
})
type Theme ¶
type Theme struct {
// Primary color for main actions and emphasis.
// Used for: primary buttons, active states, focus indicators.
Primary lipgloss.Color
// Secondary color for alternative actions.
// Used for: secondary buttons, less prominent elements.
Secondary lipgloss.Color
// Success color for positive actions and states.
// Used for: success messages, confirmation buttons, positive indicators.
Success lipgloss.Color
// Warning color for caution and attention.
// Used for: warning messages, caution buttons, alerts.
Warning lipgloss.Color
// Danger color for destructive actions and errors.
// Used for: error messages, delete buttons, critical alerts.
Danger lipgloss.Color
// Info color for informational content.
// Used for: info messages, help text, neutral notifications.
Info lipgloss.Color
// Background color for component backgrounds.
// Used for: panel backgrounds, card backgrounds, modal overlays.
Background lipgloss.Color
// Foreground color for primary text.
// Used for: body text, labels, default content.
Foreground lipgloss.Color
// Muted color for secondary text and disabled states.
// Used for: placeholders, disabled text, subtle elements.
Muted lipgloss.Color
// Border style for component borders.
// Used for: input borders, card borders, dividers.
Border lipgloss.Border
// BorderColor for default border color.
// Used for: neutral borders, dividers, separators.
BorderColor lipgloss.Color
// Padding is the default padding value for components.
// Used for: internal spacing in buttons, cards, panels.
Padding int
// Margin is the default margin value for components.
// Used for: spacing between components.
Margin int
// Radius for rounded corners (not directly supported in terminals,
// but used to select appropriate border styles).
// 0 = sharp borders, 1 = rounded borders.
Radius int
}
Theme defines the color scheme and styling properties for all components. It provides a consistent visual language across the component library.
Themes can be customized and provided to components via the BubblyUI composition API's Provide/Inject mechanism:
Setup(func(ctx *bubbly.Context) {
ctx.Provide("theme", CustomTheme)
})
Components automatically inject the theme and use it for styling.
func GetThemeFromContext ¶
GetThemeFromContext retrieves the theme from component context with fallback to DefaultTheme
func (Theme) GetBorderStyle ¶
GetBorderStyle returns the appropriate border style based on theme radius. Returns RoundedBorder for radius > 0, NormalBorder otherwise.
type ToggleProps ¶
type ToggleProps struct {
// Label is the text displayed next to the toggle switch.
// Optional - if empty, only the toggle indicator is shown.
Label string
// Value is the reactive reference to the toggle's on/off state.
// Required - must be a valid Ref[bool].
// Changes to this ref will update the toggle display.
Value *bubbly.Ref[bool]
// OnChange is a callback function executed when the toggle is switched.
// Receives the new state as a parameter.
// Optional - if nil, no callback is executed.
OnChange func(bool)
// Disabled indicates whether the toggle is disabled.
// Disabled toggles do not respond to toggle events and are styled differently.
// Default: false (enabled).
Disabled bool
// Common props for all components
CommonProps
}
ToggleProps defines the configuration properties for a Toggle component.
Example usage:
valueRef := bubbly.NewRef(false)
toggle := components.Toggle(components.ToggleProps{
Label: "Enable dark mode",
Value: valueRef,
OnChange: func(enabled bool) {
if enabled {
activateDarkMode()
}
},
})
type ValidateFunc ¶
ValidateFunc is a validation function that returns an error if validation fails.
type Variant ¶
type Variant string
Variant represents a visual variant of a component. Common variants include "primary", "secondary", "danger", "success", "warning".
const ( // VariantPrimary represents the primary/default variant. VariantPrimary Variant = "primary" // VariantSecondary represents a secondary/alternative variant. VariantSecondary Variant = "secondary" // VariantDanger represents a destructive/dangerous action variant. VariantDanger Variant = "danger" // VariantSuccess represents a successful/positive action variant. VariantSuccess Variant = "success" // VariantWarning represents a warning/caution variant. VariantWarning Variant = "warning" // VariantInfo represents an informational variant. VariantInfo Variant = "info" )
Common variant constants used across multiple components.
Source Files
¶
- accordion.go
- app_layout.go
- badge.go
- box.go
- button.go
- card.go
- center.go
- checkbox.go
- container.go
- divider.go
- doc.go
- flex.go
- form.go
- grid_layout.go
- hstack.go
- icon.go
- input.go
- layout_types.go
- list.go
- menu.go
- modal.go
- page_layout.go
- panel_layout.go
- radio.go
- select.go
- spacer.go
- spinner.go
- table.go
- tabs.go
- text.go
- textarea.go
- theme.go
- toggle.go
- types.go
- vstack.go