class ToggleTheme extends BeartropyComponent

ToggleTheme component.

A dark/light mode toggle that persists to localStorage and syncs via a custom theme-change event. Three display modes: bare icon, rounded button, or square button. Includes a global <script> that applies the saved theme before CSS loads (prevents FOUC) and re-applies on Livewire navigation. An Alpine.js x-data block handles the toggle interaction, rotation animation, and external event synchronization.

Traits

Trait HasPresets.

Trait HasErrorBag.

Properties

string $size

Size preset (xs, sm, md, lg, xl, 2xl).

string $mode

Display mode: icon, button, square-button.

string $class

Additional wrapper classes.

bool $inheritColor

Inherit parent text color instead of defaults.

string|null $iconColorLight

Tailwind color class for the light-mode icon.

string|null $iconColorDark

Tailwind color class for the dark-mode icon.

string|null $borderColorLight

Border classes in light mode (button/square-button).

string|null $borderColorDark

Border classes in dark mode (button/square-button).

string|null $iconLight

Heroicon name for light mode (replaces default SVG).

string|null $iconDark

Heroicon name for dark mode (replaces default SVG).

string|null $label

Visible label text (button mode only).

string $labelPosition

Label position: left or right.

string|null $labelClass

Custom label CSS classes.

string|null $ariaLabel

Custom aria-label (defaults to localized 'Toggle theme').

Methods

array
getComponentPresets(string|null $componentName = null, ComponentAttributeBag|null $attributes = null)

Compute component presets based on context.

array
loadPresets(string $componentName)

No description

array
loadComponentDefaults(string $componentName)

No description

bool
detectHasVariants(array $colors)

No description

array
computeSupports(array $sizes, array $colorsArray, array $defaults, array $magicProps)

No description

array
resolveSize(array $supports, array $sizes, array $defaults, array $magicProps)

No description

array
resolveVariant(array $supports, array $colorsArray, array $componentPresets, array $defaults, array $magicProps, bool $hasVariants)

No description

array
resolveColor(array $supports, array $colorsArray, array $componentPresets, array $defaults, array $magicProps, string|null $variant, bool $hasVariants)

No description

array
resolveFill(array $supports, array $attributes, array $defaults)

No description

string
buildCacheKey(string $component, array $supports, string|null $size, string|null $variant, string|null $color, bool $shouldFill)

No description

void
syncInstanceProps(array $supports, string|null $size, string|null $variant, string|null $color)

No description

array
buildPresetNames(array $supports, string|null $size, string|null $variant, string|null $color, bool $shouldFill, string $sizeOrigin, string $variantOrigin, string $colorOrigin, string $fillOrigin)

No description

void
debugWarnings(array $supports, array $sizePreset, array $colorPreset, string $componentName, string|null $variant, string|null $color)

No description

array
getErrorState(ComponentAttributeBag|null $attributes = null, ViewErrorBag|MessageBag|null $errors = null, string|null $error = null)

Determine the error state for a specific field.

array
getWireModelState(ComponentAttributeBag|null $attributes = null)

Analyze wire:model attributes to determine binding state.

array
getSizePreset(string|null $componentName = null, array|ComponentAttributeBag|null $attributes = null, string $defaultSize = 'md')

Resolve the size preset for the component.

__construct(string $size = 'md', string $mode = 'icon', string $class = '', bool $inheritColor = false, string|null $iconColorLight = null, string|null $iconColorDark = null, string|null $borderColorLight = null, string|null $borderColorDark = null, string|null $iconLight = null, string|null $iconDark = null, string|null $label = null, string $labelPosition = 'right', string|null $labelClass = null, string|null $ariaLabel = null)

Create a new ToggleTheme component instance.

object
getViewData(array $__data = [])

Get view data for the component.

View
render()

Get the view / contents that represent the component.

Details

in HasPresets at line 21
array getComponentPresets(string|null $componentName = null, ComponentAttributeBag|null $attributes = null)

Compute component presets based on context.

Parameters

string|null $componentName

Component key.

ComponentAttributeBag|null $attributes

Attributes bag.

Return Value

array

[colorPreset, sizePreset, shouldFill, presetNames]

in HasPresets at line 59
protected array loadPresets(string $componentName)

No description

Parameters

string $componentName

Return Value

array

in HasPresets at line 73
protected array loadComponentDefaults(string $componentName)

No description

Parameters

string $componentName

Return Value

array

in HasPresets at line 88
protected bool detectHasVariants(array $colors)

No description

Parameters

array $colors

Return Value

bool

in HasPresets at line 116
protected array computeSupports(array $sizes, array $colorsArray, array $defaults, array $magicProps)

No description

Parameters

array $sizes
array $colorsArray
array $defaults
array $magicProps

Return Value

array

in HasPresets at line 137
protected array resolveSize(array $supports, array $sizes, array $defaults, array $magicProps)

No description

Parameters

array $supports
array $sizes
array $defaults
array $magicProps

Return Value

array

in HasPresets at line 174
protected array resolveVariant(array $supports, array $colorsArray, array $componentPresets, array $defaults, array $magicProps, bool $hasVariants)

No description

Parameters

array $supports
array $colorsArray
array $componentPresets
array $defaults
array $magicProps
bool $hasVariants

Return Value

array

in HasPresets at line 223
protected array resolveColor(array $supports, array $colorsArray, array $componentPresets, array $defaults, array $magicProps, string|null $variant, bool $hasVariants)

No description

Parameters

array $supports
array $colorsArray
array $componentPresets
array $defaults
array $magicProps
string|null $variant
bool $hasVariants

Return Value

array

in HasPresets at line 293
protected array resolveFill(array $supports, array $attributes, array $defaults)

No description

Parameters

array $supports
array $attributes
array $defaults

Return Value

array

in HasPresets at line 338
protected string buildCacheKey(string $component, array $supports, string|null $size, string|null $variant, string|null $color, bool $shouldFill)

No description

Parameters

string $component
array $supports
string|null $size
string|null $variant
string|null $color
bool $shouldFill

Return Value

string

in HasPresets at line 349
protected void syncInstanceProps(array $supports, string|null $size, string|null $variant, string|null $color)

No description

Parameters

array $supports
string|null $size
string|null $variant
string|null $color

Return Value

void

in HasPresets at line 365
protected array buildPresetNames(array $supports, string|null $size, string|null $variant, string|null $color, bool $shouldFill, string $sizeOrigin, string $variantOrigin, string $colorOrigin, string $fillOrigin)

No description

Parameters

array $supports
string|null $size
string|null $variant
string|null $color
bool $shouldFill
string $sizeOrigin
string $variantOrigin
string $colorOrigin
string $fillOrigin

Return Value

array

in HasPresets at line 384
protected void debugWarnings(array $supports, array $sizePreset, array $colorPreset, string $componentName, string|null $variant, string|null $color)

No description

Parameters

array $supports
array $sizePreset
array $colorPreset
string $componentName
string|null $variant
string|null $color

Return Value

void

in HasErrorBag at line 24
array getErrorState(ComponentAttributeBag|null $attributes = null, ViewErrorBag|MessageBag|null $errors = null, string|null $error = null)

Determine the error state for a specific field.

Checks both the session error bag and specific error attributes. Looks up errors by wire:model value or name attribute.

Parameters

ComponentAttributeBag|null $attributes

Component attributes.

ViewErrorBag|MessageBag|null $errors

Global error bag.

string|null $error

Specific error message override.

Return Value

array

[hasError, firstErrorMessage]

in BeartropyComponent at line 33
array getWireModelState(ComponentAttributeBag|null $attributes = null)

Analyze wire:model attributes to determine binding state.

Detects if wire:model is present and if it uses dot notation (e.g., user.name).

Parameters

ComponentAttributeBag|null $attributes

Component attributes.

Return Value

array

[hasWireModel, wireModelValue, hasDotNotation, parsedDotNotationValue]

in BeartropyComponent at line 64
array getSizePreset(string|null $componentName = null, array|ComponentAttributeBag|null $attributes = null, string $defaultSize = 'md')

Resolve the size preset for the component.

Checks:

  1. Explicit $this->size.
  2. Magic attributes (e.g., <x-button sm />).
  3. Default size.

Parameters

string|null $componentName

Component name (used for context).

array|ComponentAttributeBag|null $attributes

Attributes array or bag.

string $defaultSize

Default size key.

Return Value

array

The resolved size preset configuration.

at line 64
__construct(string $size = 'md', string $mode = 'icon', string $class = '', bool $inheritColor = false, string|null $iconColorLight = null, string|null $iconColorDark = null, string|null $borderColorLight = null, string|null $borderColorDark = null, string|null $iconLight = null, string|null $iconDark = null, string|null $label = null, string $labelPosition = 'right', string|null $labelClass = null, string|null $ariaLabel = null)

Create a new ToggleTheme component instance.

Parameters

string $size
string $mode
string $class
bool $inheritColor
string|null $iconColorLight
string|null $iconColorDark
string|null $borderColorLight
string|null $borderColorDark
string|null $iconLight
string|null $iconDark
string|null $label
string $labelPosition
string|null $labelClass
string|null $ariaLabel

at line 87
object getViewData(array $__data = [])

Get view data for the component.

Parameters

array $__data

Blade data attributes.

Return Value

object

View data object.

at line 170
View render()

Get the view / contents that represent the component.

Return Value

View