Skip to content

RowActions

What can be done to one row, behind a single button, so a table does not fill up with buttons.

import { RowActions } from '@sypnia/ui/react'

On this page
  1. Actions of each key
  2. When to use it
  3. For everyone
  4. Props

Actions of each key

Open the … of a row. «Pause» is off for a key that was never used; «Delete» asks first.

NameKeyLast usedActions
Back officekey_live_01Today
Mobile appkey_live_02Yesterday
Testskey_test_03Never

Code
import { useState } from 'react';
import { ConfirmDialog, RowActions, Table, type Column } from '@sypnia/ui/react';

interface Key { id: string; name: string; used: string }
const start: Key[] = [
  { id: 'key_live_01', name: 'Back office', used: 'Today' },
  { id: 'key_live_02', name: 'Mobile app', used: 'Yesterday' },
  { id: 'key_test_03', name: 'Tests', used: 'Never' },
];

// Everything that can be done to one row, behind one button, so the table does not fill up with buttons.
// The button is named after its row, and deleting asks first.
export default function Basic() {
  const [keys, setKeys] = useState(start);
  const [doomed, setDoomed] = useState<Key | null>(null);
  const [said, setSaid] = useState('');
  const columns: Column<Key>[] = [
    { id: 'name', header: 'Name', cell: (k) => k.name },
    { id: 'id', header: 'Key', cell: (k) => <span className="sy-machine">{k.id}</span> },
    { id: 'used', header: 'Last used', cell: (k) => k.used },
    { id: 'actions', header: 'Actions', cell: (k) => (
      <RowActions label={`Actions for ${k.name}`} actions={[
        { id: 'copy', label: 'Copy the key', icon: 'copy', onAction: () => setSaid(`Copied ${k.id}`) },
        { id: 'rename', label: 'Rename', icon: 'edit', onAction: () => setSaid(`Rename ${k.name}`) },
        { id: 'pause', label: 'Pause', icon: 'pause', disabled: k.used === 'Never', onAction: () => setSaid(`Paused ${k.name}`) },
        { id: 'delete', label: 'Delete', icon: 'trash', danger: true, onAction: () => setDoomed(k) },
      ]} />
    ) },
  ];
  return (
    <div className="sy-stack">
      <Table label="API keys" columns={columns} rows={keys} rowKey={(k) => k.id} />
      <p role="status">{said}</p>
      <ConfirmDialog open={!!doomed} onClose={() => setDoomed(null)} title={`Delete the key «${doomed?.name}»?`}
        action="Delete key" onConfirm={() => { setKeys((all) => all.filter((k) => k.id !== doomed?.id)); setDoomed(null); }}>
        Apps that use it stop working at once. This cannot be undone.
      </ConfirmDialog>
    </div>
  );
}

When to use it

Use it when

  • A row has two or more actions: copy, rename, pause, delete.
  • Name the button after its row with label: «Actions for Back office».
  • The destructive action goes last, with danger, and asks first with a ConfirmDialog.

Do not use it when

  • There is one action that people use all the time: show it as its own button.
  • The action is for many rows: BulkActionBar.

For everyone

  • The button is a menu trigger named after its row; arrow keys move through the actions, Escape closes and focus goes back.
  • An action that cannot be used right now is disabled in the menu, and the menu still lists it so nobody wonders where it went.
  • On phones the button is at least 44 px.

Props

RowActionsTypeDefault
actionsrequired RowAction[]
label

The name of the button, saying which row it belongs to: «Actions for order 1042».

string
  1. Actions of each key
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms