Action Bar

PreviousNext

Fixed action bar for confirming deletions.

"use client";

import { Trash2 } from "lucide-react";
import { useState } from "react";
import { ActionBar } from "@/components/matos-ui/action-bar";
import { Button } from "@/components/matos-ui/button";

export function ActionBarDemo() {
  const [isEnabled, setIsEnabled] = useState(false);
  const [isLoading, setIsLoading] = useState(false);

  function handleConfirm() {
    setIsLoading(true);

    window.setTimeout(() => {
      setIsLoading(false);
      setIsEnabled(false);
    }, 1200);
  }

  return (
    <div className="relative  space-y-4">
      <div className="flex gap-2">
        <Button
          type="button"
          variant="outline"
          size="sm"
          onClick={() => setIsEnabled((v) => !v)}
        >
          {isEnabled ? "Desativar" : "Ativar"} Action Bar
        </Button>
      </div>

      {isEnabled && (
        <ActionBar
          placement="bottomCenter"
          tone="destructive"
          subject="Meu Workspace"
          icon={<Trash2 className="size-4 text-destructive" aria-hidden />}
          confirmLabel="Excluir"
          confirmLabelLoading="Excluindo..."
          actions={{
            onCancel: () => setIsEnabled(false),
            onConfirm: handleConfirm,
            isLoading,
          }}
        />
      )}
    </div>
  );
}

Installation

pnpm dlx shadcn@latest add https://matos-ui.com/r/action-bar.json

Usage

import { ActionBar } from '@/components/matos-ui/action-bar'
<ActionBar
  subject="My Workspace"
  tone="destructive"
  placement="bottomCenter"
  actions={{
    onConfirm: () => {},
    onCancel: () => {},
    isLoading: false
  }}
/>

Reference

Props

PropTypeDefault
subjectstring—
placement"bottomCenter" | "bottomRight" | "bottomLeft""bottomCenter"
tone"default" | "destructive""default"
size"sm" | "md""md"
actions{ onConfirm: () => void; onCancel: () => void; isDeleting?: boolean }—

ActionBar also accepts all props from <div>.