### Toast Component Setup with Tailwind CSS Source: https://base-ui.com/react/components/toast.md Complete example showing Toast.Provider setup, viewport configuration, and toast list rendering with Tailwind CSS classes. Includes swipe direction support and CSS custom properties for animation and positioning. ```tsx /* index.tsx */ 'use client'; import * as React from 'react'; import { Toast } from '@base-ui/react/toast'; export default function ExampleToast() { return ( ); } function ToastButton() { const toastManager = Toast.useToastManager(); const [count, setCount] = React.useState(0); function createToast() { setCount((prev) => prev + 1); toastManager.add({ title: `Toast ${count + 1} created`, description: 'This is a toast notification.', }); } return ( ); } function ToastList() { const { toasts } = Toast.useToastManager(); return toasts.map((toast) => (
``` -------------------------------- ### Tooltip Component React Implementation Start Source: https://base-ui.com/react/components/tooltip.md Initial setup for a React component using TypeScript, demonstrating the basic structure for a client-side component. ```tsx /* index.tsx */ 'use client'; import * as React from 'react'; ``` -------------------------------- ### Install Base UI library Source: https://base-ui.com/react/overview/quick-start.md Commands to install the `@base-ui/react` package using different package managers. ```bash pnpm add @base-ui/react ``` ```bash npm i @base-ui/react ``` ```bash yarn add @base-ui/react ``` ```bash bun add @base-ui/react ``` -------------------------------- ### PreviewCard with Detached Triggers and Tailwind CSS (React) Source: https://base-ui.com/react/components/preview-card.md This example demonstrates a complete PreviewCard setup using Tailwind CSS for styling. It shows how to create a handle, define different card contents, and use multiple detached triggers to display those contents. ```tsx /* index.tsx */ 'use client'; import * as React from 'react'; import { PreviewCard } from '@base-ui/react/preview-card'; const demoPreviewCard = PreviewCard.createHandle(); const cardContents = { typography: (
Station Hofplein signage in Rotterdam, Netherlands

Typography is the art and science of arranging type.

), design: (
Braun ABW30

A design is the concept or proposal for an object, process, or system.

), art: (
Mona Lisa

Art is a diverse range of cultural activity centered around works utilizing creative or imaginative talents, which are expected to evoke a worthwhile experience, generally through an expression of emotional power, conceptual ideas, technical proficiency, or beauty.

) }; export default function PreviewCardDetachedTriggersFullDemo() { return (

Discover{' '} typography ,{' '} design , or{' '} art .

{({ payload }) => ( ``` -------------------------------- ### Install canary release by commit hash Source: https://base-ui.com/react/overview/releases.md Install a canary release from pkg.pr.new using a master commit hash. Canary releases may contain breaking changes. ```bash npm i https://pkg.pr.new/@base-ui/react@ad745f1 ``` -------------------------------- ### Install canary release by PR number Source: https://base-ui.com/react/overview/releases.md Install a canary release from pkg.pr.new using a pull request number. Canary releases may contain breaking changes. ```bash npm i https://pkg.pr.new/@base-ui/react@3713 ``` -------------------------------- ### Implement PreviewCard with CSS Modules (React) Source: https://base-ui.com/react/components/preview-card.md This example demonstrates how to integrate the `PreviewCard` component with CSS Modules in a React application, applying styles to its various parts. ```tsx /* index.tsx */ import { PreviewCard } from '@base-ui/react/preview-card'; import styles from './demos.module.css'; export default function ExamplePreviewCard() { return (

The principles of good{' '} typography {' '} remain in the digital age.

Station Hofplein signage in Rotterdam, Netherlands

Typography is the art and science of arranging type to make written language clear, visually appealing, and effective in communication.

); } ``` -------------------------------- ### Integrating Menu with Toolbar.Button Source: https://base-ui.com/react/components/toolbar.md This example shows how to integrate a Base UI Menu component with a Toolbar by passing the Menu.Trigger to Toolbar.Button using the render prop. ```tsx return ( {/* @highlight */} } /> {/* prettier-ignore */} {/* Compose the rest of the menu */} ; ) ``` -------------------------------- ### Navigation Menu Configuration Objects Source: https://base-ui.com/react/components/navigation-menu.md TypeScript configuration for navigation structure with component categories, guide panels, and guide links. Use const assertions to ensure type safety and immutability. ```typescript export const guidesPanel = { title: 'Where teams usually start', description: 'These are the docs people reach for first when they are turning a prototype into shared UI.', } as const; ``` ```typescript export const guideLinks = [ { href: '/react/overview/accessibility', title: 'Accessibility handbook', description: 'Take a practical pass over focus order, semantics, and keyboard support.', }, { href: '/react/handbook/composition', title: 'Composition handbook', description: 'Learn when to wrap parts, share behavior, and expose flexible APIs.', }, { href: '/react/handbook/styling', title: 'Styling handbook', description: 'Apply tokens and state styles without fighting the underlying markup.', }, ] as const; ``` -------------------------------- ### Generate region strings using cartesian product Source: https://base-ui.com/react/handbook/forms.md This example demonstrates how to use the `cartesian` function to create a list of formatted region strings. ```tsx const REGIONS = cartesian(['us', 'eu', 'ap'], ['central', 'east', 'west'], ['1', '2', '3']).map( (part) => part.join('-'), ); ``` -------------------------------- ### React Autocomplete Command Palette Example Source: https://base-ui.com/react/components/autocomplete.md Demonstrates a React component implementing an Autocomplete-based command palette within a Dialog, utilizing CSS Modules for styling. ```tsx /* index.tsx */ 'use client'; import * as React from 'react'; import { Dialog } from '@base-ui/react/dialog'; import { Autocomplete } from '@base-ui/react/autocomplete'; import { ScrollArea } from '@base-ui/react/scroll-area'; import styles from './index.module.css'; export default function ExampleAutocompleteCommandPalette() { const [open, setOpen] = React.useState(false); function handleItemClick() { setOpen(false); } return ( Open command palette Close command palette
No results found.
{(group: Group) => ( {group.value} {(item: Item) => ( {item.label} ``` -------------------------------- ### Integrating NumberField with Toolbar.Input Source: https://base-ui.com/react/components/toolbar.md This example demonstrates how to use a NumberField component within a Toolbar by passing NumberField.Input to Toolbar.Input using the render prop. ```tsx return ( {/* @highlight */} } /> ; ) ``` -------------------------------- ### Generate server type options using cartesian product Source: https://base-ui.com/react/handbook/forms.md This example uses the `cartesian` function to generate a list of server type options, suitable for a dropdown or selection component. ```tsx const SERVER_TYPES = [ { label: 'Select server type', value: null }, ...cartesian(['t', 'm'], ['1', '2'], ['small', 'medium', 'large']).map((part) => { const value = part.join('.').replace('.', ''); return { label: value, value }; }), ]; ``` -------------------------------- ### Drawer Component with Tailwind CSS (React) Source: https://base-ui.com/react/components/drawer.md This example demonstrates how to implement a Drawer component using `@base-ui/react/drawer` and style it with Tailwind CSS, including portal and swipe functionality. ```tsx /* index.tsx */ 'use client'; import * as React from 'react'; import { Drawer } from '@base-ui/react/drawer'; export default function ExampleDrawer() { const [portalContainer, setPortalContainer] = React.useState(null); return (
Open drawer
Notifications You are all caught up. Good job!
``` -------------------------------- ### Implementing Toast with Tailwind CSS in React Source: https://base-ui.com/react/components/toast.md This example demonstrates a complete React component setup for using the Base UI Toast component with Tailwind CSS. It includes both stacked and anchored toast implementations, showing how to manage toast states and integrate with other components like Tooltip. ```tsx /* index.tsx */ 'use client'; import * as React from 'react'; import { Toast } from '@base-ui/react/toast'; import { Button } from '@base-ui/react/button'; import { Tooltip } from '@base-ui/react/tooltip'; const stackedToastManager = Toast.createToastManager(); const anchoredToastManager = Toast.createToastManager(); export default function ExampleToast() { return (
); } function StackedToastButton() { function createToast() { stackedToastManager.add({ description: 'Copied', }); } return ( ); } function CopyButton() { const [copied, setCopied] = React.useState(false); const buttonRef = React.useRef(null); function handleCopy() { setCopied(true); anchoredToastManager.add({ description: 'Copied', positionerProps: { anchor: buttonRef.current, sideOffset: 10, }, timeout: 1500, onClose() { setCopied(false); }, }); } return ( } > {copied ? : } Copy ); } function AnchoredToasts() { const { toasts } = Toast.useToastManager(); return ( {toasts.map((toast) => ( Overview
    {overviewLinks.map((item) => (
  • {item.title}

    {item.description}

  • ))}
Handbook
    {handbookLinks.map((item) => (
  • {item.title}

    {item.description}

  • ))}
GitHub
); } function Link(props: NavigationMenu.Link.Props) { return ( ` instead of ``. } {...props} /> ); } function CaretDownIcon(props: React.ComponentProps<'svg'>) { return ( ); } ``` -------------------------------- ### Swipe-to-open Drawer with Tailwind CSS Source: https://base-ui.com/react/components/drawer.md This example demonstrates how to implement a Drawer with a swipe-to-open gesture using `Drawer.SwipeArea`, styled with Tailwind CSS. It includes a `useState` hook to manage the portal container. ```tsx /* index.tsx */ 'use client'; import * as React from 'react'; import { Drawer } from '@base-ui/react/drawer'; export default function ExampleDrawerSwipeArea() { const [portalContainer, setPortalContainer] = React.useState(null); return (
Swipe here

Swipe from the right edge to open the drawer.

Library Swipe from the edge whenever you want to jump back into your playlists.
Close
); } ``` -------------------------------- ### React Nested Drawer Component Example Source: https://base-ui.com/react/components/drawer.md This React TypeScript example demonstrates how to implement nested Drawer components using the `@base-ui/react/drawer` library. It shows a main drawer with a trigger that opens a second, nested drawer, utilizing CSS Modules for styling. ```tsx /* index.tsx */ 'use client'; import { Drawer } from '@base-ui/react/drawer'; import styles from './index.module.css'; export default function ExampleDrawerNested() { return ( Open drawer stack
Account Nested drawers can be styled to stack, while each drawer remains independently focus managed.
Security settings
Security Review sign-in activity and update your security preferences. ``` -------------------------------- ### React Drawer with Dynamic Snap Points Source: https://base-ui.com/react/components/drawer.md Illustrates the implementation of a React Drawer component using @base-ui/react/drawer, demonstrating how to define and apply dynamic snap points for controlled height adjustments. ```tsx /* index.tsx */ 'use client'; import * as React from 'react'; import { Drawer } from '@base-ui/react/drawer'; import styles from './index.module.css'; const TOP_MARGIN_REM = 1; const VISIBLE_SNAP_POINTS_REM = [30]; function toViewportSnapPoint(heightRem: number) { return `${heightRem + TOP_MARGIN_REM}rem`; } const snapPoints = [...VISIBLE_SNAP_POINTS_REM.map(toViewportSnapPoint), 1]; export default function ExampleDrawerSnapPoints() { return ( Open snap drawer
Snap points
Drag the sheet to snap between a compact peek and a near full-height view.
{Array.from({ length: 20 }, (_, index) => (
))}
Close
); } ``` -------------------------------- ### Implement Collapsible with Tailwind CSS Source: https://base-ui.com/react/components/collapsible.md This example demonstrates how to integrate the Collapsible component with Tailwind CSS for styling. ```tsx /* index.tsx */ import * as React from 'react'; import { Collapsible } from '@base-ui/react/collapsible'; export default function ExampleCollapsible() { return ( Recovery keys
alien-bean-pasta
wild-irish-burrito
horse-battery-staple
); } export function CaretRightIcon(props: React.ComponentProps<'svg'>) { return ( ); } ``` -------------------------------- ### Select Component React Implementation Source: https://base-ui.com/react/components/select.md React component implementation using Base UI Select component with CSS Modules. Demonstrates basic setup with an apple options list and Select.Root initialization. ```tsx /* index.tsx */ import * as React from 'react'; import { Select } from '@base-ui/react/select'; import styles from './index.module.css'; const apples = [ { label: 'Gala', value: 'gala' }, { label: 'Fuji', value: 'fuji' }, { label: 'Honeycrisp', value: 'honeycrisp' }, { label: 'Granny Smith', value: 'granny-smith' }, { label: 'Pink Lady', value: 'pink-lady' }, ]; export default function ExampleSelect() { return (
``` -------------------------------- ### Basic Usage of useRender Hook Source: https://base-ui.com/react/utils/use-render.md This example demonstrates how to call the `useRender` hook to obtain a rendered React element. ```tsx const element = useRender({ // Input parameters }); ``` -------------------------------- ### Define OverflowEdges Type Source: https://base-ui.com/react/components/scroll-area.md This utility type describes the overflow status at the start and end edges for both horizontal and vertical axes. ```typescript type OverflowEdges = { xStart: boolean; xEnd: boolean; yStart: boolean; yEnd: boolean }; ```