Floating Toolbar
A customizable floating toolbar component with Modus icons, supporting buttons, toggles, dropdowns, and selects.
Examples
Default Text Editor Toolbar
A complete toolbar with text formatting, alignment, lists, insert options, and view controls.
Interactive toolbar demo - click buttons to see active states
Content area with floating toolbar
Active States:
Vertical Toolbar
A compact vertical toolbar with 7 essential buttons for space-efficient layouts.
Content area with vertical toolbar
Active States:
Fixed Toolbar
A fixed toolbar that takes the full width of its container, perfect for app headers.
Content area with fixed toolbar above
Active States:
Component Location
The floating toolbar component is located in the @/components/toolbars
directory.
components/
├── toolbars/
│ ├── floating-toolbar.tsx # Main toolbar component
│ └── index.ts # Export file
├── ui/
│ ├── button.tsx
│ ├── dropdown-menu.tsx
│ ├── toggle.tsx
│ ├── select.tsx
│ ├── separator.tsx
│ ├── tooltip.tsx
│ └── ...
└── ...
Usage:
import { FloatingToolbar, createDefaultToolbarSections } from "@/components/toolbars"
Custom Configuration
Create custom toolbar sections with different item types.
const customSections = [
{
id: "formatting",
items: [
{
id: "bold",
label: "Bold",
icon: <i className="modus-icons">text_bold</i>,
shortcut: "Ctrl+B",
type: "toggle"
},
{
id: "colors",
label: "Text Color",
icon: <i className="modus-icons">palette</i>,
type: "dropdown",
items: [
{ id: "black", label: "Black" },
{ id: "red", label: "Red" },
{ id: "blue", label: "Blue" }
]
}
]
}
]
Vertical Toolbar Configuration
Use the pre-configured vertical toolbar with 7 essential buttons.
import { FloatingToolbar, createVerticalToolbarSections } from "@/components/toolbars"
function MyVerticalToolbar() {
return (
<FloatingToolbar
sections={createVerticalToolbarSections()}
position="contained"
orientation="vertical"
onAction={handleAction}
activeStates={activeStates}
showTooltips={true}
/>
)
}
Fixed Toolbar Configuration
Use the fixed variant for toolbars that should take the full width of their container.
import { FloatingToolbar, createDefaultToolbarSections } from "@/components/toolbars"
function MyFixedToolbar() {
return (
<FloatingToolbar
sections={createDefaultToolbarSections()}
position="contained"
variant="fixed"
onAction={handleAction}
activeStates={activeStates}
showTooltips={true}
/>
)
}
Positioning
The toolbar supports multiple positioning options.
// Floating toolbar (default)
<FloatingToolbar position="top" sections={sections} />
// Fixed toolbar (full width)
<FloatingToolbar
position="contained"
variant="fixed"
sections={sections}
/>
// Vertical toolbar
<FloatingToolbar
position="contained"
orientation="vertical"
sections={createVerticalToolbarSections()}
/>
// Bottom positioning (fixed to viewport)
<FloatingToolbar position="bottom" sections={sections} />
// Contained positioning (relative to parent)
<FloatingToolbar position="contained" sections={sections} />
// Custom positioning
<FloatingToolbar
position="custom"
customPosition={{ top: "20px", right: "20px" }}
sections={sections}
/>
Usage
import { FloatingToolbar, createDefaultToolbarSections } from "@/components/toolbars"
function MyEditor() {
const [activeStates, setActiveStates] = useState({})
const handleAction = (actionId: string) => {
console.log('Action:', actionId)
// Handle toolbar actions
}
return (
<FloatingToolbar
sections={createDefaultToolbarSections()}
position="top"
onAction={handleAction}
activeStates={activeStates}
showTooltips={true}
/>
)
}
API Reference
FloatingToolbar
Prop | Type | Default | Description |
---|---|---|---|
sections | ToolbarSection[] | [] | Array of toolbar sections to display |
position | "top" | "bottom" | "custom" | "contained" | "top" | Toolbar positioning |
orientation | "horizontal" | "vertical" | "horizontal" | Toolbar layout orientation |
variant | "floating" | "fixed" | "floating" | Toolbar display variant - floating has rounded corners and shadow, fixed takes full container width |
onAction | (actionId: string) => void | - | Callback when toolbar action is triggered |
activeStates | Record<string, boolean> | {} | Active states for toolbar items |
showTooltips | boolean | true | Whether to show tooltips |
responsive | boolean | true | Enable responsive behavior |
ToolbarAction
Prop | Type | Description |
---|---|---|
id | string | Unique identifier for the action |
label | string | Label for the action (shown in tooltip) |
icon | React.ReactNode | Icon to display |
type | "button" | "toggle" | "dropdown" | "select" | Type of toolbar item |
shortcut | string | Keyboard shortcut (optional) |