Skip to main content
astrocraft-ui/ components · 101

Floating Action Button

Free · MIT

Headless, accessible, and styled entirely through the attribute surface below — bring your own CSS system, or start from the reference theme.

Install

Without a flag you get no styling at all — plain HTML carrying the attribute surface below. --theme copies the same theme in two dialects;--bridge lumos re-points either one onto Lumos for Astro's tokens (it needs a theme to re-point, and Lumos itself, already in your project).

Unstyled — behavior only, you write the CSS

Install command
npx astrocraft-ui add overlays/floating-action-button

Plain-CSS theme — no build step

Install command
npx astrocraft-ui add overlays/floating-action-button --theme css

Tailwind theme — needs Tailwind v4

Install command
npx astrocraft-ui add overlays/floating-action-button --theme tailwind

Plain-CSS theme, re-pointed onto Lumos tokens

Install command
npx astrocraft-ui add overlays/floating-action-button --theme css --bridge lumos

Tailwind theme, re-pointed onto Lumos tokens

Install command
npx astrocraft-ui add overlays/floating-action-button --theme tailwind --bridge lumos

Live demo

FloatingActionButton

Pinned bottom-right of the window. It ships no script: popovertarget opens the menu, and whichever controller already drives that panel places it and syncsaria-expanded.

Attribute surface

With no class-merging machinery, these attributes are the whole extension point. State is a data-attribute or a native attribute; visibility is the hiddenattribute. Generated from source by pnpm slots.

ComponentSlotsVariantsRuntime stateNative state
`FloatingActionButton.astro``floating-action-button``data-position`: `bottom-right` · `bottom-left` · `top-right` · `top-left`
`data-size`: `sm` · `md` · `lg`
—`[aria-expanded]`

Source

What the command copies — 2 files, alias-free so the copy lands standing alone. This is the whole component; there is nothing else.

src/components/ui/overlays/floating-action-button/FloatingActionButton.astro
---
// src/components/ui/overlays/floating-action-button/FloatingActionButton.astro — headless primitive
// (see ../../README.md).
//
// A plain floating button would not earn a file here: it is a <button> with `position: fixed`, and
// this library ships no positioning. What earns it one is the EXPAND-TO-MENU behavior — and the
// honest version of that turned out to be no JavaScript at all.
//
// Point `for` at any menu surface in the library (a DropdownMenu, a MenubarContent, a PopoverContent)
// and the platform's `popovertarget` opens it, while whichever controller already drives that panel
// places it and syncs the `aria-expanded` below. So the component is the ARIA and the attribute
// surface: `aria-haspopup="menu"`, an expanded state a theme can rotate an icon off, and a
// `data-position` for a theme to pin the corner — because a FAB that is not fixed still works, and
// this library does not ship looks.
import type { HTMLAttributes } from "astro/types";

type Props = HTMLAttributes<"button"> & {
  for: string;
  label: string;
  position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
  size?: "sm" | "md" | "lg";
};

const {
  for: target,
  label,
  position = "bottom-right",
  size = "lg",
  class: className,
  ...rest
} = Astro.props;
---

<button
  type="button"
  popovertarget={target}
  aria-label={label}
  aria-haspopup="menu"
  aria-expanded="false"
  data-slot="floating-action-button"
  data-position={position}
  data-size={size}
  class={className}
  {...rest}
>
  <slot />
</button>
src/components/ui/overlays/floating-action-button/index.ts
import FloatingActionButton from "./FloatingActionButton.astro";

export { FloatingActionButton };
export default FloatingActionButton;

What you get

The component source, copied into your project by npx astrocraft-ui add overlays/floating-action-button — no package dependency, no CSS to fight. Whatever the paid blocks compose, this is it.