PHP Classes

File: site/components/theme-builder.md

Recommend this page to a friend!
  Packages of Boss Ibrahim Mussa   Caelrik   site/components/theme-builder.md   Download  
File: site/components/theme-builder.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Caelrik
Build Web user interface from PHP components
Author: By
Last change:
Date: 8 days ago
Size: 1,674 bytes
 

 

Contents

Class file image Download

Theme builder

Edit a theme's design tokens with a live preview of your own components and a WCAG contrast report, then export the stylesheet or the theme JSON. The demo below runs entirely in your browser: try Download CSS.

<Demo name="theme-builder" :min-height="900" />

<<< @/demos/theme-builder.php

Options

| Method | Use | |---|---| | theme(Theme $theme) | The theme to start from, and the one Reset returns to (default: the Bootstrap preset). | | preview(...$components) | Components (or trusted HTML) shown in the preview. | | saveUrl($url), csrf($token, $field = '_token') | Adds a Save button posting the theme. | | labels([...]) | Translate the builder (keys of ThemeBuilder::LABELS, or token names). |

Saving

// POST /admin/theme (check authorization and the CSRF token first)
$theme = ThemeBuilder::fromRequest($_POST, file_get_contents('php://input'));
file_put_contents('theme.json', $theme->toJson());
file_put_contents('public/css/theme.css', $theme->toCss());

fromRequest() reads the JSON sent by the Save button, or the form fields posted without JavaScript, and throws InvalidArgumentException for an invalid theme (answer 422).

The builder is a development tool: put it behind authorization or a local-only route. Tokens, Theme in PHP and the caelrik-theme command are described in Theming.

Accessibility

Every color has a labelled hex field (the color pickers are skipped in the Tab order), the report says Pass or Fail in text and announces only its summary, and invalid values are reported on their field. Without JavaScript it is a form with a contrast report computed in PHP.