composables

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package composables provides Vue-inspired composable functions for BubblyUI.

Composables are reusable functions that encapsulate stateful logic using the Composition API pattern. They provide a clean way to extract and share reactive state management across components.

This package is an alias for github.com/newbpydev/bubblyui/pkg/bubbly/composables, providing a cleaner import path for users.

Core Composables

  • UseState: Simple reactive state with getter/setter
  • UseEffect: Side effects with automatic cleanup
  • UseDebounce: Debounced reactive values
  • UseThrottle: Throttled callback execution
  • UseEventListener: Event subscription management

Data Composables

  • UseList: Reactive list operations (add, remove, filter)
  • UseHistory: Undo/redo state management
  • UseForm: Form state with validation
  • UseLocalStorage: Persistent storage integration

UI Composables

  • UseFocus: Focus management with tab order
  • UseWindowSize: Responsive breakpoint tracking
  • UseCounter: Numeric counter with min/max/step
  • UseInterval: Periodic callback execution

Example

import "github.com/newbpydev/bubblyui/composables"

func setup(ctx *bubbly.Context) {
    // State management
    count := composables.UseState(ctx, 0)
    count.Set(count.Get() + 1)

    // Debounced search
    query := bubbly.NewRef("")
    debouncedQuery := composables.UseDebounce(ctx, query, 300*time.Millisecond)

    // Focus management
    focus := composables.UseFocus(ctx, "input1", []string{"input1", "input2", "submit"})
}

Index

Constants

View Source
const (
	BreakpointXS = composables.BreakpointXS
	BreakpointSM = composables.BreakpointSM
	BreakpointMD = composables.BreakpointMD
	BreakpointLG = composables.BreakpointLG
	BreakpointXL = composables.BreakpointXL
)

Breakpoint constants for responsive design.

View Source
const (
	LogLevelDebug = composables.LogLevelDebug
	LogLevelInfo  = composables.LogLevelInfo
	LogLevelWarn  = composables.LogLevelWarn
	LogLevelError = composables.LogLevelError
)

Log level constants.

Variables

BlinkCmd returns a Bubbletea command for cursor blinking.

View Source
var ErrComposableOutsideSetup = composables.ErrComposableOutsideSetup

ErrComposableOutsideSetup is returned when a composable is used outside Setup.

View Source
var NewFileStorage = composables.NewFileStorage

NewFileStorage creates a new file-based storage.

UseCounter provides a numeric counter with min/max/step options.

UseEffect registers a side effect that runs when dependencies change.

View Source
var UseEventListener = composables.UseEventListener

UseEventListener registers an event listener with automatic cleanup.

View Source
var UseInterval = composables.UseInterval

UseInterval provides periodic callback execution.

UseLogger provides component logging utilities.

View Source
var UseThrottle = composables.UseThrottle

UseThrottle creates a throttled version of a callback function.

View Source
var UseWindowSize = composables.UseWindowSize

UseWindowSize provides responsive breakpoint tracking.

WithMax sets the maximum value for the counter.

WithMin sets the minimum value for the counter.

WithStep sets the increment/decrement step for the counter.

Functions

func CreateShared

func CreateShared[T any](factory func(*bubbly.Context) T) func(*bubbly.Context) T

CreateShared creates a shared composable instance across components.

func UseDebounce

func UseDebounce[T any](ctx *bubbly.Context, value *bubbly.Ref[T], delay time.Duration) *bubbly.Ref[T]

UseDebounce creates a debounced version of a reactive value.

Types

type Breakpoint

type Breakpoint = composables.Breakpoint

Breakpoint represents a responsive breakpoint.

type BreakpointConfig

type BreakpointConfig = composables.BreakpointConfig

BreakpointConfig configures responsive breakpoints.

type CounterOption

type CounterOption = composables.CounterOption

CounterOption configures UseCounter behavior.

type CounterReturn

type CounterReturn = composables.CounterReturn

CounterReturn is the return type for UseCounter.

type FileStorage

type FileStorage = composables.FileStorage

FileStorage provides file-based storage implementation.

type FocusReturn

type FocusReturn[T comparable] = composables.FocusReturn[T]

FocusReturn is the return type for UseFocus.

func UseFocus

func UseFocus[T comparable](ctx *bubbly.Context, initial T, order []T) *FocusReturn[T]

UseFocus provides focus management with tab order.

type HistoryReturn

type HistoryReturn[T any] = composables.HistoryReturn[T]

HistoryReturn is the return type for UseHistory.

func UseHistory

func UseHistory[T any](ctx *bubbly.Context, initial T, maxSize int) *HistoryReturn[T]

UseHistory provides undo/redo state management.

type IntervalReturn

type IntervalReturn = composables.IntervalReturn

IntervalReturn is the return type for UseInterval.

type ListReturn

type ListReturn[T any] = composables.ListReturn[T]

ListReturn is the return type for UseList.

func UseList

func UseList[T any](ctx *bubbly.Context, initial []T) *ListReturn[T]

UseList provides reactive list operations.

type LogEntry

type LogEntry = composables.LogEntry

LogEntry represents a single log entry.

type LogLevel

type LogLevel = composables.LogLevel

LogLevel represents logging severity levels.

type LoggerReturn

type LoggerReturn = composables.LoggerReturn

LoggerReturn is the return type for UseLogger.

type Storage

type Storage = composables.Storage

Storage defines the interface for persistent storage.

type UseAsyncReturn

type UseAsyncReturn[T any] = composables.UseAsyncReturn[T]

UseAsyncReturn is the return type for UseAsync.

func UseAsync

func UseAsync[T any](ctx *bubbly.Context, fetcher func() (*T, error)) UseAsyncReturn[T]

UseAsync provides async operation handling.

type UseEffectCleanup

type UseEffectCleanup = composables.UseEffectCleanup

UseEffectCleanup is the cleanup function type for UseEffect.

type UseFormReturn

type UseFormReturn[T any] = composables.UseFormReturn[T]

UseFormReturn is the return type for UseForm.

func UseForm

func UseForm[T any](ctx *bubbly.Context, initial T, validate func(T) map[string]string) UseFormReturn[T]

UseForm provides form state management with validation.

type UseStateReturn

type UseStateReturn[T any] = composables.UseStateReturn[T]

UseStateReturn is the return type for UseState.

func UseLocalStorage

func UseLocalStorage[T any](ctx *bubbly.Context, key string, initial T, storage Storage) UseStateReturn[T]

UseLocalStorage provides persistent storage integration.

func UseState

func UseState[T any](ctx *bubbly.Context, initial T) UseStateReturn[T]

UseState creates a simple reactive state with getter and setter methods.

type WindowSizeReturn

type WindowSizeReturn = composables.WindowSizeReturn

WindowSizeReturn is the return type for UseWindowSize.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL