This document provides step-by-step instructions and requirements for adding new UI components to the Themed component library.
template/bs5/components (Bootstrap 5).ThemedComponent, which loads parameters and renders the Twig template.<yourprojectfolder>/template/<yourthemename>/components/. Category names should be lowercase, hyphen-separated (e.g., cards, buttons, form-elements).awesome-widget, create files:
<yourprojectfolder>/template/<yourthemename>/components/<category>/awesome-widget.twig<yourprojectfolder>/template/<yourthemename>/components/<category>/awesome-widget.css<yourprojectfolder>/template/<yourthemename>/components/<category>/awesome-widget.jsThemedComponent::make(). E.g., ThemedComponent::make('buttons/awesome-widget') renders <yourprojectfolder>/template/<yourthemename>/components/buttons/awesome-widget.twig.{# Awesome Widget Component
- title: string - Widget title text (required)
- items: array - List of items to display (optional)
- class: string - Additional CSS classes (optional)
#}content map: {{ content.title }}, content.items, etc.|default('value') or null-coalescing (content.param ?? fallback) for defaults.component('category/name', { /* params */ }).{# ... #} block is parsed by ThemedComponent::extractParameters() to generate API docs and examples.- <paramName>: <type> - <description>.awesome-widget.css and write plain CSS.
<style> tags in the page header.awesome-widget.js.
<script> tags in header or footer depending on directory.Themed::loadScripts() when rendering the component.Themed::getSvgContent('icon-name') or use the built-in icons/icon.twig component.<yourprojectfolder>/template/<yourthemename>/icons/ or icons/ inside component folder.tests/Components/<Category>/<ComponentName>Test.php.BaseTwigTestCase to get a preconfigured Twig environment..twig file with minimal required context and asserts:
$output = $this->twig->render(
'components/<category>/<component>.twig',
['content' => [ /* required params */ ]]
);
$this->assertIsString($output);
$this->assertNotEmpty(trim($output));vendor/bin/phpunit.examples/<category>/<component>.php script:
componentDocumentation() and fullExample() to auto-generate docs and code snippets.ThemedComponent::make() with various parameter combinations.src/ThemedComponent.php when initializing the Twig Environment.aria- attributes, role, and semantic HTML where appropriate.To create a custom theme for the Themed library that replaces the default Bootstrap 5 theme, follow these steps:
template/bs5/. This includes:
components/: For Twig partials of UI components.css/: For global stylesheets.js/: For global scripts to be loaded in the header.js/footer/: For scripts to be loaded in the footer.icons/: For SVG icon files.components/ directory, organize your custom components by category (e.g., buttons/, navigation/). Follow the same naming and structure conventions as outlined in earlier sections.THEMED_TEMPLATE_PATH environment variable to point to your theme's root directory. For example:
export THEMED_TEMPLATE_PATH=/path/to/your/custom/theme
This tells the Themed framework to load templates and assets from your custom location instead of the default template/bs5/.
ThemedComponent::make() method for calling components.By creating a custom theme, you can completely redefine the look and feel of the components while still leveraging the rendering and management capabilities of the Themed framework.
By following these guidelines, new components will seamlessly integrate with the Themed library, maintain consistency, and support automated documentation and testing.