Installation Add the package via Composer:
composer require dahromy/fusion-ui
Publish assets (if using Blade):
php artisan vendor:publish --provider="Dahromy\FusionUI\FusionUIServiceProvider" --tag=fusion-ui-assets
First Use Case Include the CSS/JS in your layout:
@vite(['resources/css/fusion-ui.css', 'resources/js/fusion-ui.js'])
Or use the Blade directive (if published):
@fusionUi
Basic Component Usage Copy-paste a component from the docs into your Blade view:
<fusion-button type="primary">Click Me</fusion-button>
Or use the JS API for dynamic rendering:
import { FusionButton } from 'fusion-ui';
new FusionButton({ text: 'Click Me', type: 'primary' }).mount('#app');
Component Library Approach
fusion-ui as a "copy-paste" library. Store components in a components/ directory (e.g., resources/views/components/fusion/).resources/
├── views/
│ ├── components/
│ │ ├── fusion/
│ │ │ ├── button.blade.php
│ │ │ ├── modal.blade.php
│ │ │ └── ...
│ └── layouts/
│ └── app.blade.php (include @fusionUi)
Dynamic Rendering with JS
// Initialize components on DOM ready
document.addEventListener('DOMContentLoaded', () => {
new FusionModal({ title: 'Confirm', content: 'Are you sure?' }).mount('#modal-target');
});
import { FusionDropdown } from 'fusion-ui';
Theming and Customization
:root {
--fusion-primary: #3b82f6; /* Tailwind blue-500 */
}
Form Integration
<fusion-form>
<fusion-input name="email" label="Email"></fusion-input>
<fusion-button type="submit">Save</fusion-button>
</fusion-form>
new FusionButton({
text: 'Update',
onClick: () => @this.updateData()
});
Accessibility (a11y) Patterns
aria-* attributes, keyboard navigation).<fusion-tooltip content="Help text" aria-label="Additional details">
Hover me
</fusion-tooltip>
Asset Conflicts
.fusion-ui { /* Scope all Fusion UI styles */
--fusion-primary: #your-color;
}
Dynamic Component Initialization
document.body.addEventListener('ajaxComplete', () => {
document.querySelectorAll('[data-fusion-component]').forEach(el => {
const component = FusionUI.getComponent(el.dataset.fusionComponent);
new component(el).init();
});
});
Blade vs. JS API
Missing Documentation
// Undocumented: Disable a button programmatically
const button = new FusionButton({ text: 'Submit' });
button.disable(); // Not in docs, but works
Livewire/Alpine Integration
wire:ignore or custom event names:
<div wire:ignore>
<fusion-dropdown @fusion:open="handleOpen"></fusion-dropdown>
</div>
Console Logging Enable debug logs for Fusion UI:
FusionUI.debug = true; // Logs component lifecycle
Inspecting Components Use browser dev tools to inspect rendered components. Look for:
fusion-button--primary).Common Errors
FusionUI is not defined.
Fix: Ensure JS is loaded after the DOM is ready or use defer:
<script src="fusion-ui.js" defer></script>
Custom Components
Extend the base FusionComponent class to create reusable variants:
class CustomButton extends FusionButton {
constructor(options) {
super({ ...options, type: 'custom' });
}
mounted() {
this.el.classList.add('custom-button');
}
}
Event System
Listen to custom events (e.g., @fusion:click in Blade or addEventListener in JS):
document.addEventListener('fusion:modal:open', (e) => {
console.log('Modal opened:', e.detail);
});
Configuration
Override defaults globally via FusionUI.config:
FusionUI.config = {
transitionDuration: '0.3s',
defaultTheme: 'dark'
};
Server-Side Rendering (SSR) For Inertia.js or SSR frameworks, pre-render components in Blade and hydrate with JS:
<!-- Blade -->
<fusion-modal id="my-modal" data-content="{{ $content }}"></fusion-modal>
<!-- JS -->
const modal = new FusionModal({
content: document.getElementById('my-modal').dataset.content
});
How can I help you explore Laravel packages today?