Documentation

DatastarUI component library with structured Datastar signals.

Signal Management

DatastarUI provides a structured way to manage Datastar signals using Go structs with JSON tags. This eliminates manual JSON construction and provides type-safe signal management.

Signal Helper Methods

The SignalManager provides helper methods for creating signal references and expressions:

Signal(property)

Returns a reference to a signal property

$[componentID].property

Toggle(property)

Creates a toggle expression for boolean properties

$[componentID].property = !$[componentID].property

Set(property, value)

Creates a set expression for any property

$[componentID].property = value

Conditional(property, trueValue, falseValue)

Creates conditional expressions

$[componentID].property ? trueValue : falseValue

ConditionalAction(condition, property, value)

Creates safe conditional actions for event handlers

condition ? ($[componentID].property = value) : void 0

ConditionalMultiAction(condition, actions...)

Creates safe conditional expressions with multiple actions

condition ? (action1, action2, ...) : void 0

Multi-Namespace Signals

For complex components that need multiple signal namespaces, use MultiSignals and MultiSignalRef:

MultiSignals(signalsMap)

Creates signals with multiple namespaces from a map

MultiSignals(signalsMap map[string]interface{})

MultiSignalRef(namespace, property)

Returns a reference to a signal property in a multi-signal context

$namespace.property

Benefits

  • Type Safety: Signal structures defined with Go structs
  • Maintainability: No manual JSON string construction
  • IDE Support: Autocomplete and type checking
  • Namespace Support: Automatic ID-based namespacing
  • Consistency: Standardized approach across components