Celerik\Ui\Theme
Console
final class Celerik\Ui\Theme\Console
The celerik-theme command: build a theme stylesheet from theme.json, check its contrast, or start a theme from a preset.
vendor/bin/celerik-theme preset tailwind > theme.json
vendor/bin/celerik-theme check theme.json
vendor/bin/celerik-theme build theme.json public/css/acme.cssExit codes: 0 done, 1 a contrast check failed, 2 invalid usage or an invalid theme.
Constants
| Constant | Value |
|---|---|
OK | 0 |
CONTRAST_FAILED | 1 |
INVALID | 2 |
Methods
__construct
__construct($out, $err)run
run(array $argv): int@param list<string> $argv Arguments without the script name.
Contrast
final class Celerik\Ui\Theme\Contrast
WCAG 2.x contrast checks for theme palettes. The pairs come from theme/contrast.json, which the ThemeBuilder and the tests use too.
Methods
ratio
static ratio(string $foreground, string $background): floatContrast ratio of two "#rrggbb" colors, from 1 to 21.
report
static report(Theme $theme): arrayEvery pair, in light then dark mode.
failures
static failures(Theme $theme): array@return list<ContrastResult> Only the pairs below their minimum.
pairs
static pairs(): array@return list<array{foreground: string, background: string, minimum: float, label: string, wcag: string}>
ContrastResult
final class Celerik\Ui\Theme\ContrastResult implements Stringable
The contrast of one color pair of a theme, in one mode.
Methods
__construct
__construct(string $mode, string $foreground, string $background, string $foregroundColor, string $backgroundColor, float $ratio, float $minimum, string $label, string $wcag)passes
passes(): boolStylesheet
final class Celerik\Ui\Theme\Stylesheet
Writes a theme's stylesheet: custom properties for the light and dark palettes and the shape tokens, loaded after celerik.css and the base theme's stylesheet.
The output is deterministic: resources/js/theme-css.js produces the same text in the ThemeBuilder, and the tests compare both. Every value comes from a validated Theme, so nothing in it can break out of a declaration.
Constants
| Constant | Value |
|---|---|
SHADOWS | ['none' => 'none', 'subtle' => '0 1px 2px rgba(0, 0, 0, 0.08)', 'elevated' => '0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15)', 'outlined' =… |
Methods
render
static render(Theme $theme): stringTheme
final class Celerik\Ui\Theme\Theme
A Celerik theme: design tokens on top of a base look (theme/theme.schema.json).
$theme = Theme::preset('tailwind')->name('Acme')->color('light', 'primary', '#0b5394');
$theme->contrast(); // WCAG report, see ContrastEvery value is validated against a strict format (hex colors, plain font names, numbers), so a theme loaded from user input can never inject CSS into the generated stylesheet.
Constants
| Constant | Value |
|---|---|
BASES | ['bootstrap', 'material', 'tailwind'] |
MODES | ['light', 'dark'] |
TOKENS | ['primary', 'primaryHover', 'onPrimary', 'bodyBg', 'bodyColor', 'muted', 'surface', 'border', 'inputBorder', 'danger'] |
SHADOWS | ['none', 'subtle', 'elevated', 'outlined'] |
Methods
preset
static preset(string $name): selfOne of the shipped themes, from theme/presets/{name}.json.
presetPath
static presetPath(string $name): stringfromArray
static fromArray(array $data): self$data: A theme as in theme/theme.schema.json.- Throws InvalidArgumentException When a value is missing, unknown or malformed.
fromJson
static fromJson(string $json): self@throws InvalidArgumentException When the JSON is invalid or the theme is malformed.
name
name(string $name): selfbase
base(string $base): selfcolor
color(string $mode, string $token, string $color): self@param string $color "#rrggbb"
radius
radius(?float $rem): selfCorner radius in rem (0 to 2), or null to keep the base theme's.
fontFamily
fontFamily(?string $stack): selfA font stack such as "Inter, system-ui, sans-serif", or null to keep the base theme's.
shadow
shadow(?string $shadow): selfnone, subtle, elevated or outlined, or null to keep the base theme's.
getName
getName(): stringgetBase
getBase(): stringpalette
palette(string $mode): array@return array<string, string> token => #rrggbb
rgb
rgb(string $mode, string $token): stringA color as "r, g, b", for Bootstrap's *-rgb custom properties.
getRadius
getRadius(): ?floatgetFontFamily
getFontFamily(): ?stringgetShadow
getShadow(): ?stringtoCss
toCss(): stringThe theme's stylesheet, to load after celerik.css and the base theme's stylesheet (Assets::tags(theme: $theme->getBase(), customTheme: '/css/acme.css')).
contrast
contrast(): array@return list<ContrastResult>
toArray
toArray(): array@return array<string, mixed> The theme as in theme/theme.schema.json.
toJson
toJson(): string