Skip to content

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().

php
public readonly Palette $palette

The palette the theme derives its colours from.

php
static make(?Palette $palette = null): self

Creates a theme. Uses Palette::default() when $palette is null.

php
override(object $colours): self

Registers $colours against its own class, replacing any existing entry for that class, and returns the same theme.

php
Theme::make(Palette::nord())->override(
    new ButtonColours(background: Hex::from('#88c0d0')),
)
php
has(string $class): bool

Returns whether an override is registered for $class.

php
resolve(string $class): object

Returns 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.

php
__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.

php
static default(): self
static dracula(): self
static nord(): self
static gruvboxDark(): self
static solarizedDark(): self
static catppuccinMocha(): self
static everforestDark(): self
static tokyoNight(): self

Return the built-in palettes.

Recolourable

trait Phui\Style\Recolourable

Used by the built-in *Colours classes.

php
with(Colour ...$overrides): static

Returns a copy with just the given colours replaced. Pass any subset of the constructor's parameters as named arguments.

php
$colours->with(background: Hex::from('#88c0d0'))

Released under the MIT License.