Sina UI

Navigation

Stat tabs

Headline numbers in a row above a chart. Each one is a choice: pick a number and the chart below shows it.

Installation

npx sinaui add stat-tabs

Examples

Above a chart

Inside a flush Card: the chosen number sits on the panel with an underline, the others on a faint fill. On narrow screens they go two to a row.

Loans this week One point per day.
One point per day.
<script lang="ts">
	import { defineChart, lineY } from '@tanstack/charts';
	import { scaleLinear } from '@tanstack/charts/scales/linear';
	import { scalePoint } from '@tanstack/charts/scales/point';
	import { tooltip } from '@tanstack/charts/tooltip';
	import Card from '#lib/ui/Card.svelte';
	import Chart from '#lib/ui/Chart.svelte';
	import StatTabs from '#lib/ui/StatTabs.svelte';

	const days = ['Sat', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
	const series: Record<string, { label: string; points: number[] }> = {
		loans: { label: 'Loans', points: [412, 380, 455, 498, 471, 520, 506] },
		visits: { label: 'Visits', points: [1820, 1610, 1905, 2040, 1987, 2112, 2230] },
		members: { label: 'New members', points: [31, 28, 40, 36, 44, 39, 47] },
		overdue: { label: 'Overdue', points: [16, 15, 14, 14, 12, 13, 11] }
	};
	const count = new Intl.NumberFormat('en-US');
	const pct = new Intl.NumberFormat('en-US', { style: 'percent', signDisplay: 'exceptZero' });
	const items = Object.entries(series).map(([value, s]) => {
		const moved = s.points[6] / s.points[0] - 1;
		return {
			value,
			label: s.label,
			display: count.format(s.points.reduce((a, b) => a + b, 0)),
			change: `${pct.format(moved)} since Saturday`,
			trend: moved > 0 ? 'up' : moved < 0 ? 'down' : 'flat'
		} as const;
	});

	let metric = $state('loans');
	const chosen = $derived(series[metric]);
	const chart = $derived(
		defineChart({
			marks: [
				lineY(
					chosen.points.map((v, i) => ({ day: days[i], v })),
					{ x: 'day', y: 'v', strokeWidth: 2 }
				)
			],
			scales: {
				x: { scale: () => scalePoint<string>().padding(0.2) },
				y: { scale: scaleLinear, nice: true, grid: true, axis: { ticks: { count: 4 } } }
			},
			tooltip
		})
	);
</script>

<Card flush class="stats-card">
	<StatTabs label="Chart metric" {items} bind:value={metric} />
	<div class="chart">
		<Chart
			title="{chosen.label} this week"
			description="One point per day."
			definition={chart}
			aspectRatio={2.6}
		/>
	</div>
</Card>

<style>
	:global(.stats-card) {
		inline-size: 100%;
	}
	.chart {
		padding: 1rem;
	}
</style>

Props

PropTypeDefault
labelstring (required): names the group
items{ value, label, display, change?, trend? }[]: display is the number as shown, formatted with Intl; change is a short line under it ("+12% on last week") and trend (up, down, flat) draws its arrow, without color
valuestring, bindablethe first item
namestringa unique id

Accessibility

  • Native radios in a named radio group: one Tab stop, and each one is read as its label and number, such as “Loans 3,242”, then its change when there is one; the arrow is decoration, so word the change to read on its own.
  • Correct before hydration: the chosen number is marked in the server HTML.
  • When a number changes (a new period, a filter), its digits roll to the new value in 400ms, so it's clear which figures moved. With reduced motion, the new value simply replaces the old.
  • Give the chart a title that names the chosen metric, so the change is announced with it.
KeyAction
TabMoves into the row at the chosen number.
← / →Chooses the previous / next number.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Theme toggle
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Account menu
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Sparkline
World map
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Docs navigation
Menubar
Navigation menu
Pagination
Sidebar layout
Stat tabs
Stepper
Tabs
Table of contents
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
Docs
File explorer
Messaging
Notifications
Settings
Studio
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme