Mastering Flux: A Guide to the Official Livewire UI Library
Overview: The Developer's Design Problem
Most developers suffer from a common affliction: we are functional experts but design amateurs. We rely on random fonts like or and default to massive text sizes for headings, missing the subtle nuances that professional designers like use to create polished interfaces. The UI library bridges this gap by providing a comprehensive set of components specifically tailored for the and ecosystem.
isn't just a collection of styled divs; it is an official toolkit that enforces design constraints and accessibility standards out of the box. It simplifies the creation of complex UI elements—like command palettes, searchable selects, and responsive layouts—using a "hand-done" approach that prioritizes performance. By using , you inherit the opinions of seasoned designers, ensuring your application looks professional without requiring you to manually tweak every pixel.
Prerequisites
To get the most out of this tutorial, you should have a solid foundation in the following:
- PHP & Laravel: Familiarity with the framework and its templating engine.
- Livewire: Basic knowledge of how handles state and component lifecycle.
- Tailwind CSS: Understanding utility-first CSS, as uses for all internal styling.
- Alpine.js: A grasp of syntax helps, as it powers the underlying interactivity of the components.
Key Libraries & Tools
- : The primary UI library featuring components and a JavaScript core.
- : The full-stack framework that handles the dynamic logic for components.
- : The default icon set used throughout the library (specifically the Micro, Mini, and Solid variants).
- : The sole external dependency, used for intelligent anchor positioning of popovers and dropdowns.
- : The engine for all visual treatments and responsive design.
Code Walkthrough: Building Modern Forms
approaches forms with a philosophy of composability. Instead of a monolithic input component with dozens of props, it breaks the field down into logical parts. This allows you to customize the "treatment" of each field without fighting the library.
<flux:field>
<flux:label>Username</flux:label>
<flux:description>Choose a unique name for your profile.</flux:description>
<flux:input wire:model="username" placeholder="e.g. dev_harper" />
<flux:error name="username" />
</flux:field>
In this example, the <flux:field> wrapper handles the relationship between the label and the input. If you decide to move the description below the input, uses CSS sibling selectors to automatically adjust margins. This prevents the awkward spacing issues that plague manual implementations.
For repetitive tasks, provides a clean shortcut. You can pass the label and description as props directly to the input, and it will wrap itself internally:
<flux:input label="Email" description="We will never share your email." wire:model="email" />
Advanced Input Features
Beyond simple text, handles complex patterns like input masking and clearable fields. Input masking is built directly into the core, keeping the bundle size tiny compared to massive third-party libraries.
<flux:input mask="(999) 999-9999" label="Phone Number" />
<flux:input type="password" viewable label="Password" />
<flux:input clearable icon="magnifying-glass" label="Search" />
Layouts and the Unified Field Theory
Layouts are often the most fragile part of a web application. introduces a declarative way to handle sidebars, headers, and footers using . The library detects the order of your components to determine the layout structure.
<flux:page>
<flux:sidebar sticky stashable>
<flux:brand logo="/logo.svg" name="Acme Corp" />
<flux:navlist>
<flux:navlist.item icon="home" href="#" current>Dashboard</flux:navlist.item>
<flux:navlist.item icon="users" href="#">Team</flux:navlist.item>
</flux:navlist>
</flux:sidebar>
<flux:header>
<flux:sidebar.toggle class="lg:hidden" />
<flux:spacer />
<flux:profile name="Dev Harper" />
</flux:header>
<flux:main>
<!-- Your Content Here -->
</flux:main>
</flux:page>
One notable feature is the sticky prop. Normally, position: sticky requires manual calculation of offsets. automatically calculates the height of the header or sidebar to ensure elements stick exactly where they should. Furthermore, the stashable attribute enables a mobile-ready sidebar that hides automatically, with larger touch targets for mobile accessibility.
The Power of the Popover API
Building dropdowns is notoriously difficult due to overflow: hidden and position: relative clipping. solves this by utilizing the native . This renders the dropdown in the "top layer" of the browser—above the entire tree—meaning it can never be cut off by a parent container.
<flux:dropdown>
<flux:button icon-trailing="chevron-down">Options</flux:button>
<flux:menu>
<flux:menu.item icon="pencil">Edit</flux:menu.item>
<flux:menu.item icon="trash" variant="danger">Delete</flux:menu.item>
</flux:menu>
</flux:dropdown>
also implements "safe areas" for submenus. If a user moves their mouse diagonally toward a submenu, the menu stays open rather than closing immediately. This small UX detail is what separates a developer-built menu from a professional-grade interface.
Syntax Notes: Attributes and Naming
- T-Shirt Sizing: uses standard sizing conventions (
xs,sm,base,lg). - Directional Naming: The library prefers
leadingandtrailingoverleftandright. This aligns with modern CSS logical properties and prepares your app for RTL (Right-to-Left) support. - Custom Web Elements: Under the hood, renders custom elements like
<ui-checkbox-group>. These are framework-agnostic and handle complex roles, roving tab indexes, and keyboard navigation automatically. - Inset Property: For ghost buttons or badges that need to align with a visual edge, the
insetprop compensates for internal padding, ensuring perfect optical alignment.
Practical Examples: Command Palettes
One of the most impressive components in the arsenal is the command palette. It combines a modal, an input, and a searchable list into a high-performance tool.
<flux:command.palette>
<flux:command.input placeholder="Search commands..." />
<flux:command.items>
<flux:command.item icon="plus">New Project</flux:command.item>
<flux:command.item icon="cog">Settings</flux:command.item>
</flux:command.items>
</flux:command.palette>
This palette is fully keyboard-accessible and integrates seamlessly with for server-side searching.
Tips & Gotchas
- Primary Button Fatigue: Avoid making every button
variant="primary". Professional design usually features only one primary action per view; the rest should use the default muted style. - Optical Alignment: If a component looks slightly "off" visually even though the pixels match, try using the
insetprop or 's built-in optical alignment features to fix the visual balance. - Bundle Size: Do not worry about the JavaScript overhead. The entire core is only 16KB minified, as it avoids bulky third-party dependencies in favor of hand-written web components.
- Livewire Integration: Remember that you can use
wire:modeldirectly on groups (like<flux:radio.group>or<flux:checkbox.group>) rather than binding to individual items. handles the array syncing for you.
- 42%· products
- 8%· products
- 8%· products
- 6%· products
- 4%· products
- Other topics
- 31%

Flux, the UI Library for Livewire | Caleb Porzio at Laracon US 2024 in Dallas, TX
WatchLaravel // 46:20
The official YouTube channel of Laravel, the clean stack for Artisans and agents. We will update you on what's new in the world of Laravel, from the framework to our products Cloud, Forge, and Nightwatch.