Theming
How an app's colours are chosen. A Theme pairs a Palette with any per-component colour overrides, and is set on the Screen or swapped at runtime through $this->themes.
Theme
final class Phui\Style\Theme
Holds a Palette and any per-component colour overrides, keyed by their class. The constructor is private; use make().
public readonly Palette $paletteThe palette the theme derives its colours from.
static make(?Palette $palette = null): selfCreates a theme. Uses Palette::default() when $palette is null.
override(object $colours): selfRegisters $colours against its own class, replacing any existing entry for that class, and returns the same theme.
Theme::make(Palette::nord())->override(
new ButtonColours(background: Hex::from('#88c0d0')),
)has(string $class): boolReturns whether an override is registered for $class.
resolve(string $class): objectReturns the colours object registered for $class. When none is registered, returns $class::for($palette) and caches it, throwing MissingColoursException if $class has no static for() method.
Palette
readonly class Phui\Style\Palette
Eight semantic colours that built-in components derive their own colours from.
__construct(
public Colour $accent,
public Colour $text,
public Colour $muted,
public Colour $surface,
public Colour $success,
public Colour $warning,
public Colour $danger,
public Colour $info,
)Creates a palette. Every colour is required.
static default(): self
static dracula(): self
static nord(): self
static gruvboxDark(): self
static solarizedDark(): self
static catppuccinMocha(): self
static everforestDark(): self
static tokyoNight(): selfReturn the built-in palettes.
Recolourable
trait Phui\Style\Recolourable
Used by the built-in *Colours classes.
with(Colour ...$overrides): staticReturns a copy with just the given colours replaced. Pass any subset of the constructor's parameters as named arguments.
$colours->with(background: Hex::from('#88c0d0'))