## Getting Started
### Minimal Setup
1. **Install via Composer** (preferably in a Dockerized Symfony 8.4 environment):
```bash
composer require chrisdev/ux-components
Makefile for all commands:
make install # Installs dependencies (PHP, Node, etc.)
make dev # Starts dev server
Card) in a Twig template:
{{ include('ux_components::card.html.twig', {
title: 'Example Card',
content: 'This is a reusable Symfony UX Card component.'
}) }}
/home (demo route).templates/ux_components/ (Twig templates for reusable components).assets/controllers/ (Stimulus logic for interactivity).templates/demo/ (pre-built pages showcasing components).templates/ux_components/ for pre-built components (e.g., card.html.twig, modal.html.twig).grep or IDE search to find components by functionality (e.g., "dropdown" or "table").{{ include('ux_components::dropdown.html.twig', {
items: ['Option 1', 'Option 2'],
label: 'Select an item'
}) }}
templates/components/custom_card.html.twig) and modify it. Override Stimulus controllers if needed (e.g., assets/controllers/custom_card_controller.js).All components accept configuration via Twig parameters. Example for a Badge:
{{ include('ux_components::badge.html.twig', {
text: 'Warning',
type: 'warning', // 'primary', 'success', 'danger', etc.
pill: true
}) }}
// assets/controllers/modal_controller.js
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
connect() {
console.log('Custom modal logic');
}
}
<div data-controller="modal" data-action="click->modal#toggle">
{{ include('ux_components::modal.html.twig') }}
</div>
dark:bg-gray-800).<html class="{{ 'dark' if app.request.attributes.get('_route') == 'dark_mode' }}">
make lint # Runs Twig/PHP lint
make phpstan # Static analysis
make build # Compiles Tailwind/JS
make dev # Starts Symfony server with Vite HMR
/demo routes to test components in isolation. Example:
// templates/demo/card_demo.html.twig
{% extends 'ux_components::base.html.twig' %}
{% block body %}
{{ include('ux_components::card.html.twig', {
title: 'Demo Card',
content: 'This is a demo.'
}) }}
{% endblock %}
Direct Preline Usage
modal.html.twig) instead of copying Preline’s HTML.Bootstrap CSS
<!-- ❌ Avoid -->
<button class="btn btn-primary">Click</button>
<!-- ✅ Prefer -->
<button class="bg-blue-500 text-white px-4 py-2 rounded">Click</button>
Component Bloat
UserCard) violates the "one responsibility" rule.Card component with configurable props:
{{ include('ux_components::card.html.twig', {
title: 'User Profile',
content: user|json_encode,
icon: 'user'
}) }}
Stimulus Controller Naming
modal_controller.js for modal.html.twig).config/packages/stimulus.php:
stimulus:
controllers:
custom_modal: 'assets/controllers/modal_controller.js'
Dark Mode Inconsistencies
dark: variants to all background/color classes. Example:
<div class="bg-white dark:bg-gray-800">
Twig Component Not Rendering?
ux_components::card.html.twig).use statements in Twig:
{% use 'ux_components::_partials/macros.html.twig' %}
Stimulus Not Working?
assets/app.js:
import './controllers/modal_controller';
Tailwind Classes Not Applying?
make build to recompile assets.tailwind.config.js includes all necessary paths:
content: [
'./templates/**/*.html.twig',
'./assets/**/*.js'
],
Add a New Component
templates/ux_components/new_component.html.twig.assets/controllers/new_component_controller.js.README.md under docs/components/.templates/ux_components/
├── new_component.html.twig
└── _partials/
└── new_component_macros.html.twig
assets/controllers/
└── new_component_controller.js
Override Defaults Globally
templates/base.html.twig) to modify all components:
{% block ux_components %}
{{ parent() }} {# Renders default components #}
{{ include('ux_components::custom_partial.html.twig') }}
{% endblock %}
Customize Preline Behavior
assets/app.js:
import { initPreline } from './preline';
initPreline(); // Customize options here
Symfony UX Autocomplete
# config/routes.yaml
ux_autocomplete:
path: /_ux-autocomplete
controller: App\Controller\AutocompleteController::search
{{ include('ux_components::autocomplete.html.twig', {
endpoint: path('ux_autocomplete'),
placeholder: 'Search...'
}) }}
ChartJS Integration
symfony/ux-chartjs is installed and the component is initialized in assets/app.js:
import { initChartJS } from './chartjs';
initChartJS();
Icons
{{ include('ux_components::icon.html.twig', { name: 'person' }) }}
How can I help you explore Laravel packages today?