0.1.9 • Published 9 months ago

@betterstacks/toolbar-sdk v0.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@betterstacks/toolbar-sdk

A customizable floating toolbar SDK for React applications. Create a draggable interface with customizable actions that snaps to predefined hotspots on the screen.

Features

  • 🎯 Snap-to-grid with 9 predefined hotspots
  • 🔄 Automatic orientation switching (horizontal/vertical)
  • 🎨 Customizable actions and icons
  • 💾 Persistent position storage
  • 🌟 Smooth animations and transitions
  • 📱 Responsive and draggable interface
  • 🧠 Smart button management with first-button-always-pinned
  • 🎭 Simplified single-button display during drag operations
  • 📍 Tooltip with directional arrows for better visual connection
  • 🔄 Different animation types for expanding (spring) and collapsing (tween)
  • ⭕ Circular appearance when only one button is visible

Installation

npm install @betterstacks/toolbar-sdk
# or
yarn add @betterstacks/toolbar-sdk
# or
bun add @betterstacks/toolbar-sdk

Quick Start

React Applications

import { Toolbar } from '@betterstacks/toolbar-sdk';

function App() {
  return (
    <div>
      <Toolbar />
    </div>
  );
}

Next.js Applications

For Next.js applications, you need to use dynamic imports to disable SSR for the toolbar:

'use client';

import dynamic from 'next/dynamic';
import type { ToolbarProps, ToolbarButton } from '@betterstacks/toolbar-sdk';

const Toolbar = dynamic<ToolbarProps>(
  () => import('@betterstacks/toolbar-sdk').then(mod => mod.Toolbar),
  { ssr: false }
);

export function MyComponent() {
  return (
    <div>
      <Toolbar />
    </div>
  );
}

Note: The toolbar needs to be client-side rendered because it uses browser APIs like localStorage and window. Using dynamic import with ssr: false ensures proper functionality in Next.js applications.

Custom Actions

import { Toolbar } from '@betterstacks/toolbar-sdk';
import { Sparkles, MessageCircle, Settings } from 'lucide-react';

function App() {
  return (
    <div>
      <Toolbar
        buttons={[
          {
            id: 'ai',
            icon: <Sparkles size={16} />,
            tooltip: 'AI Assistant',
            onClick: () => console.log('AI clicked'),
          },
          {
            id: 'chat',
            icon: <MessageCircle size={16} />,
            tooltip: 'Chat',
            onClick: () => console.log('Chat clicked'),
          },
          {
            id: 'settings',
            icon: <Settings size={16} />,
            tooltip: 'Settings',
            onClick: () => console.log('Settings clicked'),
          },
        ]}
        defaultIcon={<Sparkles size={16} />}
      />
    </div>
  );
}

API Reference

Toolbar Props

PropTypeDefaultDescription
buttonsToolbarButton[]Default actionsArray of button configurations
defaultIconReactNode<Sparkles />Icon shown when toolbar is collapsed
classNamestring''Additional CSS classes

ToolbarButton

PropertyTypeDescription
idstringUnique identifier for the button
iconReactNodeIcon component to display
tooltipstringTooltip text shown on hover
onClick() => voidClick handler for the button
pinnedbooleanWhether the button is pinned (visible in collapsed state)

Behavior

  • The toolbar starts in a collapsed state with the default/first action icon
  • Hover to expand and show all actions
  • Drag to reposition (simplifies to a single button during drag)
  • Automatically snaps to the nearest hotspot
  • Persists position between page reloads
  • Automatically switches between horizontal/vertical orientation based on position
  • First button is always pinned by default
  • Displays as a circle when only one button is visible
  • Tooltips feature directional arrows that point to their associated buttons

Requirements

  • React 18 or higher
  • Modern browser support (uses CSS backdrop-filter)

Browser Support

  • Chrome/Edge ≥ 76
  • Firefox ≥ 70
  • Safari ≥ 9
  • iOS Safari ≥ 9

Contributing

We welcome contributions! Please see our contributing guide for details.

License

MIT © BetterStacks

Visit the demo:

http://localhost:3000
0.1.9

9 months ago

0.1.8

9 months ago

0.1.7

9 months ago

0.1.6

9 months ago

0.1.5

9 months ago

0.1.4

9 months ago

0.1.0

9 months ago