# Fluid UI Full Documentation > Fluid UI is an open-source React component library providing styled UI primitives, customizable themes, and a fast CSS compilation workflow. > For version release notes and breaking changes, see [changelog.md](https://fluid.infinityfx.dev/docs/changelog.md). ## Getting Started ### Installation ```bash npm install @infinityfx/fluid ``` ### Adding the Fluid Provider Wrap your application root with `` so all components are styled correctly and theming functions properly. `` is a polymorphic component that renders as a wrapper element supplying its children with selected theme data. By default it renders as an HTML `` element (used in place of your normal `` tag). If your framework does not allow manually rendering a `` tag, use the `as` prop to render it as a different element, such as a `
`: ```tsx // app/layout.tsx (Next.js App Router) import { FluidProvider } from '@infinityfx/fluid'; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( {children} ); } ``` ```tsx // App.tsx (Using 'as' prop for custom wrapper) import { FluidProvider } from '@infinityfx/fluid'; export default function App() { return ( Hello world! ); } ``` ### Compilation Before running your application, compile component styles to CSS: ```bash # Production compilation (tree-shakes unused component styles) npx fluid compile # Development compilation (includes all styles to prevent missing classes during dev) npx fluid compile -d ``` Prepend compilation to your `package.json` scripts: ```json { "scripts": { "dev": "npx fluid compile -d && next dev", "build": "npx fluid compile && next build" } } ``` ## Configuration Create a `fluid.config.js` or `fluid.config.mjs` file in your project root: ```js /** @type {import('@infinityfx/fluid').FluidConfig} */ module.exports = { // Configure scanned paths (default patterns) paths: [ './src/**/*.{jsx,tsx}', './app/**/*.{jsx,tsx}', './pages/**/*.{jsx,tsx}', './components/**/*.{jsx,tsx}' ], // Recommended for Next.js to prevent stale cached styles in node_modules cssOutput: 'manual' }; ``` ### Custom Icons Override internal component icons by assigning React components (e.g. from `react-icons/lu`): ```js const { LuPlus, LuCheck, LuX, LuChevronDown, LuSearch, LuMoon, LuSun } = require('react-icons/lu'); module.exports = { icons: { add: LuPlus, check: LuCheck, close: LuX, down: LuChevronDown, search: LuSearch, dark: LuMoon, light: LuSun } }; ``` ## Theming & Styling ### CSS Variable Naming & Token Schema Fluid UI uses strict CSS variable naming schemas. When writing styles or overriding component colors and spacing, strictly adhere to the following rules: - **Color Variables (`--f-clr-[palette]-[step]`)**: Color variables **MUST** include a numeric step suffix (`-100` to `-900`). Index `0` of a palette array maps to `-100` (`-200` is index 1, up to `-900`). Never omit the step (e.g., use `--f-clr-primary-100`, never `--f-clr-primary`). - **Spacing & Size Variables (`--f-spacing-[size]`)**: Size suffixes span from `-xxs` to `-xxl` (`-xxs`, `-xsm`, `-sml`, `-med`, `-lrg`, `-xlg`, `-xxl`). Do NOT use standard Tailwind/web suffixes (`-sm`, `-md`, `-lg`, `-xl`). - **Component Size Availability**: Note that individual components may support only a subset of the full `xxs`–`xxl` size range (e.g., `xsm` to `lrg`). Always verify supported sizes via component prop types. | Pattern | Invalid | Valid Fluid Variable | | :--- | :--- | :--- | | **Color** (Step required) | `var(--f-clr-primary)` | `var(--f-clr-primary-100)` | | **Spacing / Size** (Fluid suffixes) | `var(--f-spacing-lg)` | `var(--f-spacing-lrg)` | ### Color Palettes & mixColors() Customize or add color palettes in `fluid.config.js`. Use `mixColors()` from `@infinityfx/fluid/utils` to auto-generate color scales: ```js const { mixColors } = require('@infinityfx/fluid/utils'); module.exports = { theme: { palettes: { light: { primary: mixColors('#22e39f', '#ffffff', 6) }, myCustomPalette: { primary: ['#22e39f', '#45e6ad', '#60f0bd', '#8cf5d0', '#baf7e2', '#dcfcf1'], myCustomColor: mixColors('#22e39f', '#ffffff', 6) } } } }; ``` ### Switching Themes with useFluid() Use the `useFluid` hook to toggle themes or read the active color scheme: ```tsx import { useFluid } from '@infinityfx/fluid/hooks'; export function ThemeToggle() { const { colorScheme, appliedColorScheme, setColorScheme } = useFluid(); // colorScheme can be 'light', 'dark', 'myCustomPalette', or 'system' return ( ); } ``` ### Server-Side Rendering (SSR) Cookie Setup To prevent theme flashes on page load in SSR frameworks (like Next.js), read the `COLOR_SCHEME_COOKIE` on the server and pass it to `initialColorScheme`: ```tsx // app/layout.tsx import { COLOR_SCHEME_COOKIE } from '@infinityfx/fluid/utils'; import { FluidProvider } from '@infinityfx/fluid'; import { cookies } from 'next/headers'; export default async function RootLayout({ children }: { children: React.ReactNode }) { const cookieStore = await cookies(); const colorScheme = cookieStore.get(COLOR_SCHEME_COOKIE)?.value; return ( {children} ); } ``` ### Per-Instance Styling with the `cc` Prop All Fluid UI components accept a `cc` (custom classes) prop to target specific internal component sub-elements or variant states: ```tsx } options={[ { label: 'Light', value: 'light' }, { label: 'Dark', value: 'dark' }, { label: 'Retro', value: 'retro' }, { label: 'Secret', value: 'secret', disabled: true } ]} /> ``` ##### With annotation ```tsx } virtualItemHeight={36} options={new Array(500).fill(0).map((_, i) => ({ label: `Item ${i + 1}`, value: i }))} /> ``` #### API Reference ##### Select Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `options` | `{ label: React.ReactNode; value: T extends string | number | string[]; key?: string; disabled?: boolean; }[]` | `required` | The list of options to display. | | `variant` | 'default' \| 'inverted' \| 'minimal' | `default` | - | | `searchable` | `boolean` | `false` | Enables a search field in the dropdown. | | `limit` | `number` | - | Maximum number of options that can be selected at a time when multiple is true. | | `emptyMessage` | `string` | `"Nothing found"` | Text shown when no options match the search. | | `contentSize` | 'xsm' \| 'sml' \| 'med' \| 'lrg' | `med` | Size of the dropdown content. | | `mobileContainer` | 'popover' \| 'modal' | `popover` | How to display the Select content on mobile devices. | | `virtualItemHeight` | `number` | - | When set to a number greater than 0, enables virtual scrolling for better performance with large option lists. | | `value` | `T` | - | Controlled selected value or array of values. | | `defaultValue` | `T` | - | Default selected value or array of values. | | `onChange` | `(value: T) => void` | - | Callback function triggered when selection changes. | | `disabled` | `boolean` | `false` | - | --- ### Sidebar A collapsible sidebar. #### Importing ```tsx import { SidebarHeading, SidebarItem, SidebarRoot, SidebarToggle, SidebarUser } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx My account } active /> }> } size="sml" /> } size="sml" /> } size="sml" /> } /> Sign out ``` ##### Tree navigation ```tsx
``` #### API Reference ##### SidebarRoot Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `collapsed` | `boolean` | - | Whether the sidebar is collapsed. | | `setCollapsed` | `(value: boolean) => void` | - | Callback function triggered when the collapsed state changes. | ##### SidebarToggle Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `toggle` | 'square' \| 'round' \| 'none' | `square` | The visual style of the toggle button. | ##### SidebarItem Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `label` | `string` | - | The text label displayed on the item. | | `icon` | `React.ReactNode` | - | An optional icon displayed on the left. | | `right` | `React.ReactNode` | - | Custom element shown on the right side of the label when there are no child items. | | `size` | 'sml' \| 'med' | `med` | - | | `active` | `boolean` | `false` | Marks the item as currently selected. | | `variant` | 'default' \| 'inverted' | `default` | - | | `round` | `boolean` | `false` | - | | `compact` | `boolean` | `false` | Renders a smaller, compact variant of the item. | | `defaultOpen` | `boolean` | `false` | Whether the nested child items are expanded by default. | ##### SidebarUser Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `name` | `string` | - | The name of the user. | | `status` | `string` | - | An optional status message shown below the user name. | | `indicator` | `string | number | boolean` | `false` | Visual status indicator badge content shown over the avatar. | | `round` | `boolean` | `false` | Makes the user avatar round. | | `icon` | `React.ReactNode` | - | Action icon shown on the right (defaults to a "more options" icon). | --- ### Skeleton Used to show a placeholder while content is loading. #### Importing ```tsx import { Skeleton } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx ``` ##### Aspect ratio ```tsx ``` #### API Reference ##### Skeleton Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `w` | 'number' \| 'string' | - | The width of the skeleton loader. | | `h` | 'number' \| 'string' | - | The height of the skeleton loader. | | `ar` | `number` | - | The aspect ratio of the skeleton loader. | | `radius` | 'xsm' \| 'sml' \| 'med' \| 'lrg' \| 'max' | `sml` | The border radius size. | --- ### Slider An input that allows for selecting 1 or multiple values from a given range. #### Importing ```tsx import { Slider } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx `${value}db`} defaultValue={[60]} /> ``` #### API Reference ##### Slider Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `handles` | `number` | `1` | The number of handles this slider should have. | | `vertical` | `boolean` | `false` | Renders the slider vertically. | | `tooltips` | 'never' \| 'interact' \| 'always' | `interact` | When to display a tooltip above each handle. | | `formatTooltip` | `(value: number) => string` | - | Custom formatter function for the tooltip value. | | `label` | `string` | - | Label displayed above the slider track. | | `value` | `number[]` | - | Controlled values for each handle. | | `defaultValue` | `number[]` | - | Default values for uncontrolled usage. | | `onChange` | `(values: number[]) => void` | - | - | | `disabled` | `boolean` | `false` | - | --- ### Spinner A spinning loading indicator. #### Importing ```tsx import { Spinner } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx ``` #### API Reference ##### Spinner Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `color` | `string` | - | Custom stroke color for the spinner animation. | --- ### Stepper An ordered list of completable steps. #### Importing ```tsx import { Stepper } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx }, { name: 'Shipping', icon: , error: true }, { name: 'Payment', icon: } ]} /> ``` #### API Reference ##### Stepper Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `steps` | `{ name: string; icon: React.ReactNode; label?: string; error?: boolean; }[]` | - | An array of steps configs. label defaults to a 0-padded index. | | `completed` | `number` | - | The number of completed steps (0-indexed). | | `setCompleted` | `(value: number) => void` | - | Callback function triggered when clicking a navigatable step. | | `navigation` | 'none' \| 'forwards' \| 'backwards' \| 'both' | `backwards` | Controls which steps are navigatable relative to the current completed step. | | `variant` | 'default' \| 'compact' \| 'vertical' | `default` | - | --- ### Swatch Displays one or multiple colors. #### Importing ```tsx import { Swatch } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx ``` ##### Multiple colors ```tsx ``` #### API Reference ##### Swatch Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `round` | `boolean` | `false` | - | | `size` | 'xsm' \| 'sml' \| 'med' \| 'lrg' | `med` | - | | `color` | 'string' \| 'string[]' | `['transparent']` | A single color or an array of colors to display in segments. | --- ### Switch An input that switches between an on and off state. #### Importing ```tsx import { Switch } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx ``` ##### With icons ```tsx } iconOn={} /> ``` #### API Reference ##### Switch Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `size` | 'xsm' \| 'sml' \| 'med' \| 'lrg' | `med` | - | | `color` | `string` | - | Custom accent color for the switch when checked. | | `round` | `boolean` | `true` | - | | `error` | `any` | - | Marks the switch as invalid when truthy. | | `iconOn` | `React.ReactNode` | - | Icon shown in the on/checked position. | | `iconOff` | `React.ReactNode` | - | Icon shown in the off/unchecked position. | | `disabled` | `boolean` | `false` | - | --- ### Table A table displaying data. #### Importing ```tsx import { Table } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx ``` ##### Column formatters ```tsx
[ Inspect #{row.id} , Refund \${row.value.toFixed(2)} ]}/> ``` ##### Empty Table ```tsx
``` #### API Reference ##### Table Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `data` | `(T extends { [key: string]: string | number | Date; })[]` | `required` | The array of row data objects to display. | | `columns` | `(keyof T)[]` | `required` | The keys of row data objects that represent columns. | | `maxColumnWidth` | `string` | `auto` | The maximum width of a table column. | | `selectable` | `boolean` | `false` | Allows rows to be selected using checkboxes. | | `sortable` | 'boolean' \| '(keyof T)[]' | `false` | Enables sorting columns when clicked. Can specify an array of sortable column keys. | | `selected` | `number[]` | - | Controlled array of selected row indices. | | `onSelect` | `(selected: number[]) => void` | - | Callback function triggered when row selection changes. | | `columnFormatters` | `{ [column in keyof T]: (value: T[column]) => React.ReactNode }` | - | Custom formatting functions for specific columns. | | `rowActions` | `(row: T, index: number) => React.ReactNode` | - | A function that returns action menu items for a row. | | `emptyMessage` | `string` | `"Nothing to display"` | Text shown when the table data is empty. | --- ### Tabs An input with multiple options of which only 1 can be selected at a time. #### Importing ```tsx import { Tabs } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx ``` #### API Reference ##### Tabs Props | Prop | Type | Default | Description | | :--- | :--- | :--- | :--- | | `options` | `{ label: string; value: (T extends string | number | string[]); disabled?: boolean; panelId?: string; }[]` | `required` | The array of tab options. | | `variant` | 'default' \| 'minimal' | `default` | - | | `value` | `T` | - | Controlled value of the currently selected tab. | | `defaultValue` | `T` | - | Default selected tab value. | | `onChange` | `(value: T) => void` | - | Callback function triggered when tab selection changes. | --- ### Textarea A form textarea. #### Importing ```tsx import { Textarea } from '@infinityfx/fluid'; ``` #### Examples ##### Usage ```tsx