Example

Monthly metrics

Card, Text, Badge and Skeleton in a responsive grid.

Preview
Revenue
$128,400
Active customers
1,284
Churn
2.4%
Overdue invoices
17
Example.tsx
import { Badge, Button, Card, Skeleton, SimpleGrid, Stack, Text } from '@reactloom/ui';
import { useState } from 'react';

interface Metric {
  label: string;
  value: string;
  change: number;
  /** Is a rise good news? (Churn and costs: no.) */
  higherIsBetter: boolean;
  period: string;
}

const metrics: Metric[] = [
  { label: 'Revenue', value: '$128,400', change: 12.4, higherIsBetter: true, period: 'vs last month' },
  { label: 'Active customers', value: '1,284', change: 3.1, higherIsBetter: true, period: 'vs last month' },
  { label: 'Churn', value: '2.4%', change: 0.6, higherIsBetter: false, period: 'vs last month' },
  { label: 'Overdue invoices', value: '17', change: -22, higherIsBetter: false, period: 'vs last month' },
];

const pct = new Intl.NumberFormat('en-US', { maximumFractionDigits: 1, signDisplay: 'always' });

function Trend({ change, higherIsBetter, period }: Pick<Metric, 'change' | 'higherIsBetter' | 'period'>) {
  const good = change === 0 ? null : change > 0 === higherIsBetter;
  // Direction and judgement are words, not just colour or an arrow.
  const direction = change > 0 ? 'Up' : change < 0 ? 'Down' : 'No change';
  return (
    <Badge tone={good === null ? 'neutral' : good ? 'success' : 'danger'}>
      <span aria-hidden="true">{change > 0 ? '▲' : change < 0 ? '▼' : '•'} </span>
      {direction} {change !== 0 ? pct.format(change).replace(/^[+-]/, '') + '%' : ''} {period}
    </Badge>
  );
}

export default function Example() {
  const [loading, setLoading] = useState(false);
  return (
    <Stack gap="3" style={{ width: '100%' }}>
      <div>
        <Button size="sm" variant="secondary" onClick={() => setLoading((l) => !l)} aria-pressed={loading}>
          Show loading state
        </Button>
      </div>
      <SimpleGrid minChildWidth="13rem" gap="3" aria-busy={loading || undefined}>
        {metrics.map((m) => (
          <Card key={m.label}>
            {/* A description list: the label describes the value for screen readers. */}
            <dl style={{ margin: 0 }}>
              <dt>
                <Text as="span" size="sm" tone="muted">
                  {m.label}
                </Text>
              </dt>
              <dd style={{ margin: '4px 0 8px' }}>
                {loading ? <Skeleton width="60%" height="1.75rem" /> : <Text as="span" size="2xl" weight="semibold" tabularNums>{m.value}</Text>}
              </dd>
              <dd style={{ margin: 0 }}>{loading ? <Skeleton width="80%" /> : <Trend {...m} />}</dd>
            </dl>
          </Card>
        ))}
      </SimpleGrid>
    </Stack>
  );
}

Details that matter

  • Each card is a description list (dt label, dd value): screen readers pair the number with what it measures.
  • The trend says “Up 12.4% vs last month” in words. Colour shows whether that is good — and “up” is bad for churn — but never carries the meaning alone.
  • Values use tabular numbers so they line up and do not jiggle when they update.
  • While loading, keep the layout (Skeleton at the value’s size) and mark the grid aria-busy.
  • The grid wraps by available width (minChildWidth), so the same markup works from phones to wide screens.