MCPcopy
hub / github.com/umami-software/umami / SortableLabel

Function SortableLabel

src/components/common/SortableLabel.tsx:16–90  ·  view source on GitHub ↗
({ label, sortKey, defaultDirection = 'asc' }: SortableLabelProps)

Source from the content-addressed store, hash-verified

14}
15
16export function SortableLabel({ label, sortKey, defaultDirection = 'asc' }: SortableLabelProps) {
17 const { router, query, updateParams } = useNavigation();
18 const isActive = query.orderBy === sortKey;
19 const isDescending = query.sortDescending === 'true';
20 const direction = isActive ? (isDescending ? 'desc' : 'asc') : undefined;
21 const activeColor = 'var(--text-primary)';
22
23 const getNextDirection = (): SortDirection => {
24 if (!isActive) {
25 return defaultDirection;
26 }
27
28 return direction === 'desc' ? 'asc' : 'desc';
29 };
30
31 const handleSort = () => {
32 const nextDirection = getNextDirection();
33
34 router.push(
35 updateParams({
36 orderBy: sortKey,
37 sortDescending: nextDirection === 'desc' ? 'true' : undefined,
38 page: 1,
39 }),
40 );
41 };
42
43 return (
44 <button
45 type="button"
46 onClick={handleSort}
47 className="inline-flex appearance-none items-center gap-1 border-0 bg-transparent p-0 text-inherit"
48 aria-pressed={isActive}
49 >
50 <span>{label}</span>
51 <span
52 aria-hidden
53 style={{
54 display: 'inline-flex',
55 flexDirection: 'column',
56 gap: 0,
57 lineHeight: 0,
58 color: 'var(--text-muted)',
59 opacity: 0.8,
60 }}
61 >
62 <span
63 style={{
64 color: direction === 'asc' ? activeColor : undefined,
65 opacity: direction === 'asc' ? 1 : 0.55,
66 transform: 'scale(0.9)',
67 transformOrigin: 'center',
68 }}
69 >
70 <Icon size="sm" color={direction === 'asc' ? undefined : 'muted'}>
71 <ChevronUp />
72 </Icon>
73 </span>

Callers

nothing calls this directly

Calls 1

useNavigationFunction · 0.90

Tested by

no test coverage detected