Practic BUI (Base UI) - v1.0.0
    Preparing search index...

    Practic BUI (Base UI) - v1.0.0

    @practic/bui

    Base UI components with a stable class on every part, so you style them once in a plain CSS theme instead of at every usage.

    npm types license

    Base UI gives you accessible, unstyled React components, and its examples style every usage with inline Tailwind classes. Nothing is reusable: each app restyles each part by hand. @practic/bui adds the missing layer. Every part of every component gets a predictable class (.DialogPopup, .SelectItem[data-highlighted]), and one CSS file styles them all. Change the file and the whole app changes with it. It also ships ready-made widgets and an app frame (header, colour mode, floating panels), so a new app looks finished from the first render.

    npm install @practic/bui @base-ui/react react react-dom
    

    Or bun add, pnpm add, yarn add.

    import { Dialog } from '@practic/bui'
    import '@practic/bui/themes/barebones.css'

    export function Notifications() {
    return (
    <Dialog.Root>
    <Dialog.Trigger>Open</Dialog.Trigger>
    <Dialog.Portal>
    <Dialog.Backdrop />
    <Dialog.Popup>
    <Dialog.Title>Notifications</Dialog.Title>
    <Dialog.Description>You are all caught up.</Dialog.Description>
    <Dialog.Close>Close</Dialog.Close>
    </Dialog.Popup>
    </Dialog.Portal>
    </Dialog.Root>
    )
    }

    The components have the same API as @base-ui/react. Each part renders with its class (.DialogTrigger, .DialogPopup, …), and the barebones theme styles them.

    • 🎨 A class on every part. 37 Base UI components, each part named after its component and part.
    • 📄 Themes are plain CSS. There is no build step and no Tailwind requirement, and you can swap themes by swapping one import.
    • 🧭 A template lists every class. Each part comes with its data-* states and Base UI's runtime variables.
    • 🧩 Ready-made widgets. Floating and settings panels, value selects, suggest inputs, copy, download and JSON file actions, and editors for every kind of CSS value.
    • 🖼️ App frame. A sticky translucent header with a colour-mode toggle, safe areas for floating UI, themed confirm dialogs, and isolated preview frames.
    • 💾 Pluggable persistence. Widgets remember their state in localStorage by default, or in any store you register.
    • 🌗 Light and dark. It follows the system or the user's choice through color-scheme and light-dark().
    • 🛡️ TypeScript native, with ES modules only.
    Do I need per-component imports for a smaller bundle?

    No. Import everything from the package root, such as import { Button, Dialog } from '@practic/bui'. The package ships ES modules, one per component, and declares its JavaScript free of side effects. So Vite, Rollup, esbuild and webpack drop every component you don't import. Importing Button from the root bundles exactly the same code as importing it from its own file, which is why there is no per-component entry point. That differs from the original CommonJS lodash, where per-method imports were needed; this package behaves like lodash-es.

    A theme is a copy of @practic/bui/themes/_template.css, which lists every part class with its states, commented out. To style a part, uncomment its rule where it is and fill it in:

    :root {
    --radius: 0.375rem;
    --surface: Canvas;
    }

    .DialogPopup {
    padding: 1.5rem;
    border-radius: var(--radius);
    background: var(--surface);
    }

    .SelectItem[data-highlighted] {
    background: color-mix(in srgb, currentColor 10%, transparent);
    }

    A button's role comes from a data-variant attribute, which the button passes through unchanged and themes style as an extension of .Button: primary for the one action a form or dialog exists for, and danger for actions that destroy or end something, as in <Button data-variant='danger'>Remove</Button>. barebones.css styles both.

    Import your theme instead of barebones.css. To edit a theme visually beside every widget, use @practic/bui-theme-editor.

    Import What it gives you
    @practic/bui Every Base UI component with a class on each part (Accordion, Dialog, Select, Tabs, Toast, …), plus PortalContainerProvider to choose where popups mount.
    @practic/bui/themes/*.css barebones.css, a minimal theme, and _template.css, every class unstyled.
    @practic/bui/widgets Ready-made widgets: one per multi-part Base UI component (AccordionWidget … TooltipWidget), PanelFloating (opened from a Toggle, pressed while open), PanelSettings, HelpDialog (TriggerChrome, the floating "?", and Popup, its title fixed above the scrolling help, with overrides, inside Dialog.Root), MarkdownContent (its values fill {name} placeholders once the Markdown is parsed; markdownCodeComponents highlights its code blocks), CtrlSelectOption, SettingColor, CtrlSelectValue, SuggestInput, ButtonCopy, ButtonIcon (an icon, and a spinner while pending), LoadingStatus (a spinner and what is loading, as a status), LoadingSpinner, JsonFileActions, …
    @practic/bui/widgets/css CssValueEditor and CssValuePanel: tools for each kind of CSS value. They load property data on first use.
    @practic/bui/app AppHeader, AppNavigation, AppDocsLink, AppFavicon, appLogo, ThemeToggle, useTheme, useConfirm, useHashRoute, SafeArea, IsolatedFrame, appChromeStyle
    @practic/bui/persist Persist.Root, usePersistedState and persistCreateState over the registered layer, and everything in @practic/persist/core, the contract it builds on: persistRegisterLayer, persistCreateStorageLayer, persistStorageKey and the persistence types.
    @practic/bui/lib Helpers without React, importable from server code too: cn (merges class names), widget overrides (WidgetOverrides, widgetOverride, widgetOverrideNoChildren), Markdown (markdownFill, the remark plugin behind values), colours (colorFormat, colorToOklab, colorToHue, colorToLinear, colorDetectNotation, colorHexPattern), numbers (numberFormat), CSS values (cssValueSplit, cssValueParseDimension, cssValueDimensionPattern, cssValueLoadTypes, …), files (downloadText, downloadJson, readJsonFile, jsonIsObject, isFiniteNumber), theme files (themeCssParse, themeCssRenderRule and the other themeCss* helpers), the shipped themes as text (themeSources) and the logo for drawing icons (appLogoSvg, appLogoBackground). See Helpers.
    @practic/bui/tailwind tailwindCompileRules and tailwindListClasses, which need the optional tailwindcss peer.
    @practic/bui/showcase ShowcasePage, showcaseList and showcasePageCss: a working example of every widget.
    @practic/bui/demo The package demo page, and PersistDemo, @practic/persist's examples it shows under #/persist.

    Wraps a page with a sticky header: the logo, title, optional navigation and actions, and the colour-mode toggle.

    import { AppHeader } from '@practic/bui/app'

    export function App() {
    return (
    <AppHeader title='My app'>
    <main>…</main>
    </AppHeader>
    )
    }
    Prop Type Description
    title ReactNode Page title, beside the logo.
    logo ReactNode Replaces the default logo.
    favicon boolean Sets the crow as the page's favicon (AppFavicon); on unless logo replaces the crow. Turn it off when the app declares its own icons.
    navigation ReactNode Content after the title, such as AppNavigation.
    actions ReactNode Extra actions, before the colour-mode toggle, such as AppDocsLink, which links to docs/ beside the page.
    children ReactNode The page, rendered below the header.

    Asks for confirmation in the theme's alert dialog, a themed replacement for window.confirm.

    import { useConfirm } from '@practic/bui/app'
    import { Button } from '@practic/bui'

    export function DeleteFile() {
    const [confirm, confirmDialog] = useConfirm()

    async function remove() {
    if (!(await confirm({ title: 'Delete this file?', confirmLabel: 'Delete', confirmVariant: 'danger' }))) return
    // …delete
    }

    return (
    <>
    {confirmDialog}
    <Button
    data-variant='danger'
    onClick={() => void remove()}
    >
    Delete
    </Button>
    </>
    )
    }
    Option Type Default Description
    title ReactNode (required) The question.
    description ReactNode none What the action does or affects.
    confirmLabel string Confirm The confirm button; name the action instead.
    confirmVariant 'primary' | 'danger' none The confirm button's role; danger when it destroys something.
    cancelLabel string Cancel The button that backs out.

    @practic/bui/widgets has a widget for each Base UI component made of several parts, from AccordionWidget to TooltipWidget, assembled from the themed parts so you do not rebuild them. Every widget works the same way:

    • The component's own props pass through, typed from Base UI: min, max, step and format on a number field, length on a one-time code, open and onOpenChange on a dialog, multiple on an accordion.
    • Choices are composed as parts. TabsWidget, AccordionWidget, RadioGroupWidget, CheckboxGroupWidget, ToggleGroupWidget, SelectWidget, ComboboxWidget and AutocompleteWidget hold only the parts that add something: Root, which keeps the value, and the item part that offers one (TabsWidget.Tab, AccordionWidget.Item, RadioGroupWidget.Radio, CheckboxGroupWidget.Checkbox, ToggleGroupWidget.Toggle). Every other part comes from the themed component (Tabs.List, Tabs.Panel, Select.Trigger), so each tab, section or option is an element you place, wrap or render conditionally. A stored value no part offers any more reads as none, and tabs fall back to the first; in development, a root whose items are plain themed parts warns. Select, Combobox and Autocomplete also take items on Root, as Base UI's own root does.
    • Common blocks are presets, with parts beside them. <FieldWidget label='Name' />, CheckboxWidget, CollapsibleWidget, NumberFieldWidget and SliderWidget render the usual arrangement, tuned element by element through overrides (overrides={{ propsControl: { type: 'email' } }}). For another arrangement, compose FieldWidget.Root with FieldWidget.Control and the themed Field.Label, Field.Error and Field.Description, or the other widgets' Root with their themed parts.
    • Arrangements are presets too. AlertDialogWidget, DialogWidget, DrawerWidget, PopoverWidget, PreviewCardWidget, TooltipWidget, the menus, ToolbarWidget, MeterWidget, ProgressWidget, AvatarWidget, ScrollAreaWidget, FieldsetWidget, FormWidget and ToastWidget take their content as props, such as a dialog's trigger and title or a menu's items, and every element they place through overrides: overrides={{ propsTrigger: { render: <Button /> }, propsPositioner: { side: 'right' } }} puts a tooltip on an existing button, to its right. A fieldset's or form's fields take overrides of their own, and a toolbar's items are the props of the parts they render. For another arrangement (two actions in a dialog, radio items in a menu, a submenu), compose the themed parts; the showcase shows each preset beside the same widget composed. ToastWidget.List renders a Toast.Root for each toast with the parts its children give ({(toast) => <><Toast.Title /><Toast.Action /></>}), for toasts with an action. The panels and controls (PanelFloating, PanelSettings, PanelSection, CtrlSelectOption, CtrlSelectValue, SettingNumber, JsonFileActions) take overrides for the elements they draw the same way, such as a panel's propsPositioner. Values keep their type through onValueChange.
    • Built-in wording has English defaults that labels replaces, for other languages or other words, such as a number field's − and +.
    • State can persist. Give data-key and data-attr to keep the value through the registered persistence layer, and initialValue to start from. Change handlers run after the value is stored.
    import { Radio } from '@practic/bui'
    import { NumberFieldWidget, OTPFieldWidget, RadioGroupWidget } from '@practic/bui/widgets'
    import { useState } from 'react'

    type Plan = 'free' | 'team'

    const plans: { value: Plan; label: string }[] = [
    { value: 'free', label: 'Free' },
    { value: 'team', label: 'Team, per seat' },
    ]

    export function SignUp() {
    const [plan, setPlan] = useState<Plan | null>(null)

    return (
    <>
    <NumberFieldWidget
    label='Age'
    min={18}
    max={120}
    initialValue={30}
    labels={{ decrement: 'less', increment: 'more' }}
    data-key='sign-up'
    data-attr='age'
    />
    <OTPFieldWidget
    aria-label='PIN'
    length={4}
    />
    <RadioGroupWidget.Root<Plan>
    aria-label='Plan'
    data-key='sign-up'
    data-attr='plan'
    onValueChange={(next) => setPlan(next)}
    >
    {plans.map(({ value, label }) => (
    <label key={value}>
    <RadioGroupWidget.Radio value={value}>
    <Radio.Indicator />
    </RadioGroupWidget.Radio>
    {label}
    </label>
    ))}
    </RadioGroupWidget.Root>
    <p>Plan: {plan ?? 'none chosen'}</p>
    </>
    )
    }

    Renders state that survives reloads through a render prop. Without data-attr, the state stays local.

    import { Slider } from '@practic/bui'
    import { Persist } from '@practic/bui/persist'

    export function Volume() {
    return (
    <Persist.Root
    data-key='my-app'
    data-attr='volume'
    initialValue={50}
    >
    {({ value, setValue }) => (
    <Slider.Root
    value={value}
    onValueChange={(next) => setValue(next)}
    >
    <Slider.Control>
    <Slider.Track>
    <Slider.Indicator />
    <Slider.Thumb aria-label='Volume' />
    </Slider.Track>
    </Slider.Control>
    </Slider.Root>
    )}
    </Persist.Root>
    )
    }
    Prop Type Description
    data-key string Storage key. Defaults to practic_bui_default.
    data-attr string Name of the value within the key; omit it for local state.
    initialValue storable T Value used until one is stored.
    children ({ value, setValue }) => … Renders the state.

    The value's type is inferred from initialValue. When the initial value cannot describe it, such as an empty list, pass the type as an argument after the component name: <Persist.Root<string[]> initialValue={[]}>.

    Outside a render prop, usePersistedState({ key, attr, initialValue }) returns the same { value, setValue }. To share a value with plain functions, declare it once at module scope with persistCreateState({ key, attr, initialValue }): components pass it to usePersistedState, and code anywhere calls its get(), set(…), subscribe(…) and ready(). Both go through the registered persistence layer.

    Values may be JSON data or the built-ins JSON cannot hold: Date, Map, Set, bigint, RegExp, URL, undefined in arrays, non-finite numbers, ArrayBuffer and typed arrays, nested in any combination. Each layer converts them when it writes and back when it reads (persistEncodeValue and persistDecodeValue), so a Date stored is a Date read back. Functions, symbols, class instances and cycles are refused.

    @practic/bui/lib holds the tools the widgets are built with, ready for your own code. None of them use React, so server code can import them too; only downloadText, downloadJson and readJsonFile need a browser to run.

    import { cn, colorFormat, cssValueSplit, type Rgba } from '@practic/bui/lib'

    export const ink: Rgba = { r: 20, g: 22, b: 28, a: 1 }

    export const inkCss = {
    hex: colorFormat(ink, 'hex'),
    oklch: colorFormat(ink, 'oklch'),
    }

    export const tabClass = (active: boolean, className?: string) => cn('px-3 font-normal', active && 'font-semibold', className)

    export const shadowLayers = cssValueSplit('0 1px 2px black, 0 0 0 1px white', ',')

    inkCss is { hex: '#14161c', oklch: 'oklch(0.201 0.012 270.7)' }, tabClass(true, 'px-4') gives 'font-semibold px-4' (the later utilities replace the ones they conflict with), and shadowLayers is ['0 1px 2px black', '0 0 0 1px white']. An app that imports only some helpers bundles only those: the themes' text stays out unless it uses themeSources.

    • Peer dependencies: react and react-dom 19, and @base-ui/react 1. tailwindcss 4 is optional, needed only for @practic/bui/tailwind.

    • @practic/persist installs with it. Its core holds the storage contract the widgets' state follows, and its usePersistedStateIn hook is the one usePersistedState uses.

    • Tailwind is not required. Components and widgets get their looks from the theme and their layout from inline styles.

    • Persistence store. By default, state goes to localStorage under the key practic_bui_default. To keep it somewhere else, register a layer once, at module scope, before anything renders. For example, use @practic/persist:

      import { persistRegisterLayer } from '@practic/bui/persist'
      import { persistLayer } from '@practic/persist'

      persistRegisterLayer(persistLayer)
    • Client components. Every entry starts with 'use client', except @practic/bui/lib, whose helpers have no React and are called from server code too.

    • One installed copy. Each copy of the package keeps its own hash route and React contexts, so components from two copies (two versions installed, or one bundled twice) do not see each other's providers or route changes. When a second copy starts its route or theme, the console warns once that @practic/bui is loaded more than once; install a single version.

    Floating UI over full-bleed content

    Content can run behind the translucent header while its controls stay clear of it. Set the inset on the container that sits under the header, then place controls in a SafeArea:

    .stage {
    position: fixed;
    inset: 0;
    /* the header covers the top of this container */
    --app-safe-top: var(--app-header-height);
    }
    import { SafeArea } from '@practic/bui/app'
    import { PanelSection, PanelSettings } from '@practic/bui/widgets'

    export function Stage() {
    return (
    <div className='stage'>
    {/* full-bleed content, such as a map or a WebGL scene */}
    <canvas style={{ width: '100%', height: '100%' }} />
    <SafeArea placement='top-right'>
    <PanelSettings label='Settings'>
    <PanelSection title='View'>Options for the content behind.</PanelSection>
    </PanelSettings>
    </SafeArea>
    </div>
    )
    }

    Popups opened inside a SafeArea stay within it. Pinned panels portal into it, so they hide with their page.

    The crow holding a hooked twig is there because crows make their own tools. Faced with food out of reach, a crow bends a twig or a piece of wire into a hook and fishes the food out, and keeps the tool for next time. That is what practic means: from the Greek praktikós, "fit for action", knowledge that gets put to work. This package works the same way: it takes the components Base UI already gives you and shapes them into tools that are ready to use.

    The logo ships with the package in both colour modes, as SVG and as PNG at 699 and 96 pixels: @practic/bui/assets/practic-logo-light.svg and @practic/bui/assets/practic-logo-dark.svg, with .png and -96.png versions of each. AppHeader shows it and sets it as the favicon (AppFavicon, with appLogo holding the 96-pixel images). To draw app icons from it on a server, such as Next.js's icon.tsx, @practic/bui/lib gives its SVG markup (appLogoSvg) and the colour of its circle (appLogoBackground) for icons that cannot be transparent.

    MIT © Felipe Penno. See LICENSE.