blast-project/ui
UI package for Blast Project: reusable Laravel front-end components, layouts, and styles to speed up building consistent admin and app interfaces. Includes shared views, assets, and helpers for rapid prototyping and integration with Blast Project apps.
Pattern: Replace hardcoded Blade includes with dynamic UI components. Example:
<!-- Before: Static include -->
@include('components.button', ['text' => 'Submit'])
<!-- After: Dynamic registration -->
@ui('primary-button', ['text' => 'Submit'])
Workflow:
AppServiceProvider:
UI::register('primary-button', function () {
return new \BlastProject\UI\Components\Button(
text: 'Submit',
type: 'primary'
);
});
@ui() directive in Blade with optional data:
@ui('primary-button', ['text' => 'Save', 'disabled' => true])
Pattern: Use doctrine/collections to manage dynamic UI state (e.g., form data, filters).
Example:
use Doctrine\Common\Collections\ArrayCollection;
// Register a component with state
UI::register('user-list', function () {
$users = new ArrayCollection(User::all());
return new UserListComponent($users);
});
// Modify state via facade
UI::get('user-list')->getUsers()->filter(fn ($user) => $user->isActive());
Use Cases:
doctrine/collections for UI-specific logic.Pattern: Bind UI components to Laravel’s service container for dependency injection. Example:
// In AppServiceProvider
$this->app->bind(\App\Components\Dashboard::class, function ($app) {
return new Dashboard(
$app->make(AnalyticsService::class),
$app->make(UserRepository::class)
);
});
// Register with UI facade
UI::register('dashboard', \App\Components\Dashboard::class);
Benefits:
Pattern: Override UI themes globally via config/ui.php.
Example:
// config/ui.php
'themes' => [
'default' => [
'colors' => ['primary' => '#3b82f6'],
'fonts' => ['body' => 'Inter'],
],
'dark' => [
'colors' => ['primary' => '#60a5fa'],
],
],
// Apply theme in Blade
@ui('dashboard', ['theme' => 'dark'])
Implementation:
BlastProject\UI\Contracts\Themeable in your components.UI::setTheme('dark') to switch themes globally.Pattern: Trigger UI updates via Laravel events. Example:
// In an event listener
public function handle(UserUpdated $event) {
UI::trigger('user-profile', $event->user);
}
// In component
UI::listen('user-profile', function ($user) {
$this->user = $user;
$this->render();
});
Use Cases:
Pattern: Dynamically load tenant-specific UI configurations. Example:
// In a middleware
public function handle($request, Closure $next) {
$tenant = Tenant::find($request->tenantId);
UI::setConfig($tenant->ui_config);
return $next($request);
}
// Tenant config example
[
'components' => [
'header' => \App\Components\TenantHeader::class,
],
'theme' => 'tenant-branding',
]
Pattern: Create custom Blade directives to simplify UI usage. Example:
// In AppServiceProvider
Blade::directive('ui', function ($expression) {
return "<?php echo app('ui')->render({$expression}); ?>";
});
// Usage in Blade
@ui('dashboard', ['tab' => 'analytics'])
Advanced: Extend with conditional logic:
@ui(auth()->check() ? 'admin-panel' : 'guest-dashboard')
Pattern: Use UI components to render API responses. Example:
// Controller
public function show(User $user) {
return UI::render('user-card', ['user' => $user]);
}
// Blade
@ui('user-card', ['user' => $user])
Benefits:
Pattern: Test components in isolation using Laravel’s testing tools. Example:
public function test_dashboard_component()
{
$component = new DashboardComponent(new AnalyticsService());
$this->assertStringContainsString('Analytics', $component->render());
// Test with mock dependencies
$mockService = Mockery::mock(AnalyticsService::class);
$mockService->shouldReceive('getData')->andReturn([]);
$component = new DashboardComponent($mockService);
$this->assertStringContainsString('No data', $component->render());
}
Pattern: Cache frequently used UI components. Example:
// Register with caching
UI::register('header', function () {
return Cache::remember('ui.header', now()->addHours(1), function () {
return new HeaderComponent();
});
});
// Clear cache when needed
Cache::forget('ui.header');
Doctrine Collections Overhead
doctrine/collections can consume significant memory for large datasets.ArrayCollection::toArray() for rendering or switch to native arrays.memory_get_usage() in critical paths.Blade Caching Conflicts
php artisan view:clear
@verbatim in Blade for dynamic content:
@verbatim
@ui('dynamic-content')
@endverbatim
Service Provider Boot Order
UIServiceProvider is loaded early in config/app.php.Missing Type Safety
/** @var \BlastProject\UI\ComponentInterface */
$component = UI::get('dashboard');
Event Listener Conflicts
UI::listen('ui.user-profile', function ($user) { ... });
Configuration Overrides
config/ui.php may be overwritten during updates.php artisan vendor:publish --tag="ui-config"
Lazy Loading Pitfalls
UI::preload('dashboard');
Middleware Integration
UI::register('admin-panel', function () {
if (!auth()->check()) abort(403);
return new AdminPanel();
});
Log UI Events Add logging to track UI interactions:
UI::listen('*', function ($event) {
\Log::debug("UI Event: {$event->name}", $event->data);
});
Inspect Component State Dump component data for debugging:
dd(UI::get('dashboard')->getState());
Check for Circular Dependencies
Use composer why-not blast-project/ui to diagnose dependency conflicts.
Validate Blade Directives Ensure directives are registered before use:
Blade::if('ui', function () {
return UI::has('dashboard');
});
Profile Memory Usage
Monitor doctrine/collections memory impact:
$collection = new ArrayCollection(User::all());
\Log::info('Collection memory: ' . memory_get_usage() / 1024 / 1024 .
How can I help you explore Laravel packages today?