Skip to content

UiTheme

Viames Marino edited this page May 10, 2026 · 1 revision

Pair framework: UiTheme

Pair\Html\UiTheme resolves the active UI renderer and preserves the legacy theme facade used by older Pair code.

It is the runtime bridge behind Application::uiFramework(...), UiRenderer, form controls, pagination helpers, alerts, badges, and LogBar chrome.

Built-in themes

Pair ships three built-in renderer names:

  • native
  • bootstrap
  • bulma

Native HTML is the default when no framework is selected or when an invalid non-strict value is normalized.

Main methods

current(): string

Returns the current renderer name.

$theme = \Pair\Html\UiTheme::current();

setCurrent(string $theme): void

Overrides the active renderer for the current runtime.

\Pair\Html\UiTheme::setCurrent('bootstrap');

Unknown renderer names raise InvalidArgumentException in this strict path.

reset(): void

Restores the default built-in renderer registration and clears cached renderer instances.

This is mostly useful in tests and long-running processes.

registerRenderer(UiRenderer $renderer): void

Registers a renderer instance immediately.

\Pair\Html\UiTheme::registerRenderer(new App\Html\TailwindRenderer());

registerRendererClass(string $name, string $className): void

Registers a renderer class by name. The class is instantiated only when that renderer is selected.

\Pair\Html\UiTheme::registerRendererClass('tailwind', App\Html\TailwindRenderer::class);

Prefer this method when the renderer does not require constructor arguments, because unselected framework classes stay unloaded.

renderer(?string $theme = null): UiRenderer

Returns the active renderer or a specific renderer by name.

$renderer = \Pair\Html\UiTheme::renderer('bulma');

renderers(): array

Returns all registered renderer instances, instantiating registered classes as needed.

Compatibility helpers

These methods preserve older theme checks:

  • isBootstrap(): bool
  • isBulma(): bool
  • isNative(): bool

Rendering helpers

UiTheme delegates UI output details to the active renderer:

  • controlClasses(FormControl $control): array
  • labelClasses(?string $customClasses = null): ?string
  • labelHelpTooltip(string $description): string
  • selectWrapperClasses(bool $multiple = false): ?string
  • alertClass(string $variant = 'primary'): string
  • badgeClass(string $variant = 'primary'): string
  • endAlignmentClass(): string
  • pagination(Router $router, int $page, int $pages): string

LogBar support

UiTheme also exposes optional LogBar hooks:

  • logBarChromeClasses(): array
  • supportsLogBarBreakpoints(): bool

If the selected renderer implements UiLogBarRenderer, Pair uses its LogBar methods. Otherwise, Pair falls back to the native renderer defaults.

Common pitfalls

  • Registering a renderer under a name that does not match UiRenderer::name().
  • Registering a class that does not implement UiRenderer.
  • Calling setCurrent() before registering a custom renderer name.
  • Putting framework-specific form or LogBar classes directly into controls instead of centralizing them in a renderer.

See also: UiRenderer, UiLogBarRenderer, Application, Form, FormControl, LogBar, Pagination.

Clone this wiki locally