Component

Floating Action Button

A primary compose action hovering over content. Circular, elevated (shadow-md), fixed to a corner. Icon + optional label (extended FAB). `aria-label` is required. Reserve one per screen for the primary creation action.

  • Component
  • React
  • TSX
  • Tailwind CSS
  • MIT

What it does

Capabilities

  • Semantic HTML
  • ARIA

Preview

Live component

Interactive preview
Open preview
9:41 100%
devsnips.site/library/react/components/buttons/floating-action-button/
fluid · no fixed width 100%
No dependencies Responsive · Light/dark · Focus-visible

Install

Add to your project

terminal
npx devsnips add React/Components/Buttons/floating-action-button
registry path: React/Components/Buttons/floating-action-button

Source

Implementation

code.tsx
import type { ButtonHTMLAttributes, ReactNode } from "react";

/* DevSnips React — FloatingActionButton
 * Primary compose action hovering over content. Circular, elevated,
 * fixed to a corner. aria-label required. One per screen.
 */

export type FabPosition = "bottom-right" | "bottom-left" | "top-right";

export interface FloatingActionButtonProps
  extends ButtonHTMLAttributes<HTMLButtonElement> {
  icon: ReactNode;
  label: string;
  position?: FabPosition;
  extended?: boolean;
}

function cx(...parts: Array<string | false | null | undefined>): string {
  return parts.filter(Boolean).join(" ");
}

const POS: Record<FabPosition, string> = {
  "bottom-right": "bottom-6 right-6",
  "bottom-left": "bottom-6 left-6",
  "top-right": "top-6 right-6",
};

export function FloatingActionButton({
  icon,
  label,
  position = "bottom-right",
  extended = false,
  disabled,
  className,
  type = "button",
  ...rest
}: FloatingActionButtonProps) {
  return (
    <button
      type={type}
      aria-label={label}
      className={cx(
        "fixed z-40 inline-flex items-center justify-center gap-2 rounded-full",
        "border border-transparent bg-[var(--ds-color-primary)] text-[var(--ds-color-primary-foreground)]",
        "shadow-[var(--ds-shadow-md)] transition-transform duration-150 ease-out motion-reduce:transition-none",
        "hover:-translate-y-0.5 active:translate-y-0",
        "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--ds-color-focus-ring)]",
        "disabled:pointer-events-none disabled:opacity-50",
        extended ? "h-12 px-5 text-sm [&_svg]:size-5" : "size-14 p-0 [&_svg]:size-5",
        POS[position],
        className,
      )}
      disabled={disabled}
      {...rest}
    >
      {icon}
      {extended && <span>{label}</span>}
    </button>
  );
}

export default FloatingActionButton;
62 lines UTF-8 · LF · Spaces: 2
DevSnips AI ready Claude · Cursor · Windsurf

Agent skill & Model Context Protocol

Pass this component straight into your AI workflow. DevSnips exposes each resource as a structured, addressable registry entry, so your agent installs the real files instead of approximating them.

devsnips://components/buttons/floating-action-button
Prompt instruction
I want to use this DevSnips resource in production:

Page:
https://devsnips.site/library/react/components/buttons/floating-action-button/

Install: npx devsnips add
React/Components/Buttons/floating-action-button

This is the Floating Action Button — A primary compose action hovering over content. Circular, elevated (shadow-md), fixed to a corner. Icon + optional label (extended FAB). `aria-label` is required. Reserve one per screen for the primary creation action.

Use this DevSnips resource as the starting point for my project.
Adapt it to my project's stack and conventions, fix any issues,
and make it production-ready while preserving its intended design
and behavior.

Paste into ChatGPT, Claude or your agent — it already carries the page URL and the exact install path.

Resource URI
devsnips://components/buttons/floating-action-button