Skip to content

SortMenu

How a list or a set of cards is ordered: by which field, and which way. One button says the order in use and opens a menu of fields and directions.

import { SortMenu, SortMenuSkeleton } from '@sypnia/ui/react'

On this page
  1. Cards in order
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

Cards in order

  • Shop
    Tables
    14
    Last change
    2026-11-16
  • Customers
    Tables
    22
    Last change
    2026-11-12
  • Blog
    Tables
    3
    Last change
    2026-11-02
  • Operations
    Tables
    8
    Last change
    2026-10-28
Code
import { useMemo, useState } from 'react';
import { DataCards, SortMenu, type DataSort } from '@sypnia/ui/react';

// Cards have no headers to press: the SortMenu says the order in use and changes it.
const projects = [
  { id: 'shop', name: 'Shop', tables: 14, updated: '2026-11-16' },
  { id: 'blog', name: 'Blog', tables: 3, updated: '2026-11-02' },
  { id: 'crm', name: 'Customers', tables: 22, updated: '2026-11-12' },
  { id: 'ops', name: 'Operations', tables: 8, updated: '2026-10-28' },
];
type P = (typeof projects)[number];
const by: Record<string, (p: P) => string | number> = { name: (p) => p.name, tables: (p) => p.tables, updated: (p) => p.updated };
export default function Projects() {
  const [sort, setSort] = useState<DataSort | null>({ id: 'updated', dir: 'descending' });
  const rows = useMemo(() => {
    if (!sort) return projects;
    const key = by[sort.id];
    return [...projects].sort((a, b) => (key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0) * (sort.dir === 'ascending' ? 1 : -1));
  }, [sort]);
  return (
    <div className="sy-stack">
      <div className="sy-row"><SortMenu options={[{ id: 'name', label: 'Name' }, { id: 'tables', label: 'Tables' }, { id: 'updated', label: 'Last change' }]} value={sort} onChange={setSort} /></div>
      <DataCards label="Projects" rows={rows} rowKey={(p) => p.id} title={(p) => p.name} min="12rem"
        fields={[{ id: 'tables', label: 'Tables', numeric: true, value: (p) => p.tables }, { id: 'updated', label: 'Last change', value: (p) => p.updated }]} />
    </div>
  );
}

Skeleton

Code
import { SortMenu, SortMenuSkeleton } from '@sypnia/ui/react';

// The button keeps its place while the fields are not known.
export default function Skeleton() {
  return (
    <div className="sy-row">
      <SortMenu options={[{ id: 'name', label: 'Name' }]} value={{ id: 'name', dir: 'ascending' }} onChange={() => {}} />
      <SortMenuSkeleton />
    </div>
  );
}

When to use it

Use it when

  • Lists and cards, which have no headers to press.
  • Pass none={false} when the data has no order of its own to go back to.

Do not use it when

  • Tables: their headers sort.
  • Filters: that is FilterBar.

For everyone

  • The button's name says the whole order: «Sort by Size, ascending».
  • The menu has two groups of choices read as radio items; the arrows move, Enter chooses.

Props

SortMenuTypeDefault
onChangerequired (sort: DataSort | null) => void
optionsrequired SortOption[]
valuerequired DataSort | null
none

Offers «No order», which goes back to the order the data came in.

boolean true
size "sm" | "md" sm
SortMenuSkeletonTypeDefault
size "sm" | "md" sm
  1. Cards in order
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms