Flux can be installed via npm from your project root:
npm install @fluxui-dev/react
Add the following to your app's main CSS file, such as resources/css/app.css:
@import 'tailwindcss';@import '@fluxui-dev/react/flux.css';@custom-variant dark (&:where(.dark, .dark *));
If you don't have Tailwind installed, you can learn how to install it on the
Tailwind website.
Import FluxProvider from @fluxui-dev/react/inertia. Wrap your Inertia app with it in createInertiaApp:
// resources/js/app.tsximport { FluxProvider } from '@fluxui-dev/react/inertia';import { createInertiaApp } from '@inertiajs/react';createInertiaApp({ withApp: (app) => <FluxProvider>{app}</FluxProvider>,});
This provider connects Flux to Inertia for links, forms, validation errors, and the current page. See
the Inertia guide for the details.
Render FluxProvider from @fluxui-dev/react in a client component. Pass it your framework's link component, such as Next's Link:
// app/providers.tsx'use client';import { FluxProvider } from '@fluxui-dev/react';import Link from 'next/link';import { usePathname } from 'next/navigation';export function Providers({ children }: { children: React.ReactNode }) { return ( <FluxProvider link={Link} currentUrl={usePathname}> {children} </FluxProvider> );}
Then use it in your root layout:
// app/layout.tsx<body> <Providers>{children}</Providers></body>
Server components can render Flux components directly. Inside a server component, use the flat part names like DropdownTrigger instead of Dropdown.Trigger.
Import FluxProvider from @fluxui-dev/react. Wrap your app with it where you render it, such as main.tsx:
// src/main.tsximport { FluxProvider } from '@fluxui-dev/react';import { createRoot } from 'react-dom/client';import App from './App';createRoot(document.getElementById('root')!).render( <FluxProvider> <App /> </FluxProvider>,);
If you use a router, pass its link component to FluxProvider. React Router's link component takes to instead of href, so wrap it in a small component first:
import type { ComponentProps } from 'react';import { Link } from 'react-router';type RouterLinkProps = ComponentProps<'a'> & { href: string };function RouterLink({ href, ...props }: RouterLinkProps) { return <Link to={href} {...props} />;}<FluxProvider link={RouterLink}>{children}</FluxProvider>
Flux links now navigate through your router. External links, downloads, and links that open in a new tab stay plain links.
To get your link component's props typed on Flux components, register it once with a module declaration:
import type Link from 'next/link';declare module '@fluxui-dev/react' { interface Register { link: typeof Link; }}
FluxProvider can also connect Flux to your router and form library:
-
currentUrl marks the current page in navigation.
-
errors shows validation errors on fields.
-
processing shows a loading state on submit buttons.
Add this to your head to set up dark mode and avoid flicker:
<script> (() => { let saved; try { saved = localStorage['flux.appearance']; } catch {} const media = matchMedia('(prefers-color-scheme: dark)'); const dark = saved ? saved === 'dark' : media.matches; const html = document.documentElement; html.classList.toggle('dark', dark); html.style.colorScheme = dark ? 'dark' : 'light'; })();</script>
React renders the whole page, so FluxProvider adds the script for you. Add suppressHydrationWarning to the html element in your root layout, because the script changes its class before React hydrates:
// app/layout.tsx<html lang="en" suppressHydrationWarning>
Add this to your head to set up dark mode and avoid flicker:
<script> (() => { let saved; try { saved = localStorage['flux.appearance']; } catch {} const media = matchMedia('(prefers-color-scheme: dark)'); const dark = saved ? saved === 'dark' : media.matches; const html = document.documentElement; html.classList.toggle('dark', dark); html.style.colorScheme = dark ? 'dark' : 'light'; })();</script>
5
Use the Inter font family
Although completely optional, we recommend using the
Inter font family.
@theme { --font-sans: Inter, ui-sans-serif, system-ui, sans-serif; ...}
Import components from @fluxui-dev/react and use them anywhere in your app:
import { Button } from '@fluxui-dev/react';<Button variant="primary">Get started</Button>