krystal-sf/ux-common

Common files for Krystal Symfony UX Projects

Maintainers

Package info

gitlab.com/krystal-sf/ux-common

Homepage

Issues

Type:symfony-bundle

pkg:composer/krystal-sf/ux-common

Transparency log

Statistics

Installs: 1 868

Dependents: 12

Suggesters: 0

Stars: 0

1.0.x-dev 2026-08-04 23:01 UTC

This package is auto-updated.

Last update: 2026-08-04 23:01:37 UTC


README

Core UX foundations for Krystal Symfony UX Projects: base component class, composable traits, presets dictionaries and Twig globals.

PHP Version Symfony

Installation

composer require krystal-sf/ux-common

Enable the bundle in config/bundles.php:

return [
    // ...
    Ksf\Core\UxCommon\KsfUxCommonBundle::class => ['all' => true],
];

Writing a Krystal Component

All Krystal Twig & Live components extend AbstractUxComponent, a plain class composed of traits (it does NOT extend AbstractController):

use Ksf\Core\UxCommon\Twig\AbstractUxComponent;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;

#[AsTwigComponent(name: 'Acme:MyCard', template: '@AcmeBundle/components/card.html.twig')]
class MyCard extends AbstractUxComponent
{
}

Available Traits

TraitPurpose
ComponentWithContentsTraitStandard content props: title, subtitle, icon, text, class...
ComponentWithTranslationsTraitAuto-translation of registered props (translationDomain)
ComponentWithAutoloadTraitAutoload of props from translations (autoload key)
ComponentWithPresetTraitPresets application (presets prop + AsPresetProcessor services)
ComponentWithRouterTraitRouter access & URL generation
ComponentWithLinkTraitLink props: route, url, anchor, jumpTo
ComponentWithAlternateTraitAlternate flag for even/odd items rendering (opt-in)
ComponentWithFlashesTraitSession flash messages from components (opt-in)
ComponentWithExecuteTraitLive action forwarding to controllers (opt-in, not in base class)
ComponentWithControllerActionTraitEncode controller actions for live components (opt-in)

NB: ComponentWithActionTrait (Knp Menu action props) lives in krystal-sf/ux-menus, to keep this package free of menus dependencies.

Presets & Dictionaries

Dictionaries expose their constants as the ux.* Twig global (via GlobalsVariablesCompiler):

<twig:Ksf:Alert presets="{{ [ux.presets.alerts.types.SUCCESS] }}"/>

Declare your own dictionaries with the provided attributes:

  • #[AsGlobalDictionary("name")]ux.name.*
  • #[AsPresetsDictionary("name")]ux.presets.name.*
  • #[AsRoutesDictionary("name")]ux.routes.name.*

Available presets dictionaries: AlertsTypesPresets, AlertsSizePresets, BtnStylesPresets, BtnSizesPresets, BtnFormatsPresets, CardsStylesPresets, CardsPlainStylesPresets.

Events dictionaries (PHP constants mirrored in templates via data attributes): ModalEvents, FlashBagEvents, ActionContext.

Stimulus & Assets

The package ships an importmap bridge (@krystal-sf/ux-common) that exposes jQuery globally for legacy libraries. Stimulus controllers of all Krystal packages are declared through the standard symfony.controllers convention: they are registered by the HOST application's Stimulus app — no global Stimulus instance is ever started by Krystal packages.

Profiler

In dev environment, the GlobalsCollector adds a "Krystal UX" entry to the debug toolbar AND a full profiler panel showing all ux.* globals exposed to Twig — click any key or value to copy it to the clipboard.

Testing

make phpunit          # run package tests
make verify           # containers + deps + quality + tests, all Symfony versions

License

MIT — see LICENSE.