renatovdemoura/blade-elements-ui
Laravel package providing reusable Blade UI elements (components/tags) to speed up building consistent interfaces. Drop-in Blade elements help standardize layout and styling across your app with minimal setup.
Installation
composer require renatovdemoura/blade-elements-ui
Add the service provider to config/app.php under providers:
RenatoVdemoura\BladeElementsUI\BladeElementsUIServiceProvider::class,
First Use Case
Create a simple UI element in a Blade file (e.g., resources/views/components/alert.blade.php):
@element('alert', [
'type' => 'success',
'message' => 'Operation completed successfully!'
])
Use it in your Blade template:
@includeElements(['alert'])
Basic Configuration Publish the config file (if available) and customize default settings:
php artisan vendor:publish --provider="RenatoVdemoura\BladeElementsUI\BladeElementsUIServiceProvider"
Component-Based UI
resources/views/components/.resources/views/components/card.blade.php
@element('card', [
'title' => 'User Profile',
'content' => 'User details go here...'
])
@includeElements(['card'])
Dynamic Data Binding Pass data from controllers or services:
return view('dashboard', [
'elements' => [
'alert' => ['type' => 'warning', 'message' => 'Pending tasks found!']
]
]);
@includeElements($elements)
Conditional Rendering Use Blade directives to conditionally include elements:
@if($showSuccess)
@includeElements(['alert' => ['type' => 'success', 'message' => 'Success!']])
@endif
@verbatim if needed.@element('modal', [
'title' => 'Confirm Action',
'content' => 'Are you sure?',
'wire:model' => 'confirmAction'
])
$this->view->share('elements', ['alert' => ['message' => 'Test']]);
Caching Issues
php artisan view:clear
@includeElements dynamically.Namespace Conflicts
@element directive (e.g., alert.blade.php for @element('alert')).alert-message.blade.php), but adjust the directive accordingly.Data Overwriting
@includeElements(['alert' => ['type' => 'info'], 'alert' => ['type' => 'error']])
Result: Only the error alert renders.resources/views/components/ and the directive matches the filename.@element or @includeElements. Use {{ dd($elements) }} to debug passed data.Custom Directives
Extend the package by adding global Blade directives in AppServiceProvider:
Blade::directive('elementIf', function ($expression) {
return "<?php if({$expression}): ?>@includeElements(['{$expression}'])<?php endif; ?>";
});
Usage:
@elementIf($showAlert)
Element Factories Create a helper class to generate elements programmatically:
class ElementFactory {
public static function alert(string $message, string $type = 'info') {
return ['alert' => compact('message', 'type')];
}
}
Usage:
@includeElements(ElementFactory::alert('Hello!'))
Event-Based Triggers Use Laravel events to dynamically add elements:
// In an event listener
event(new ElementAdded('alert', ['message' => 'Event triggered!']));
@includeElements(app('elements')->get())
How can I help you explore Laravel packages today?