Examples
Dashboard home
The first screen of a small shop's admin: four numbers with how they moved, a period to compare, the month's goal, and the latest orders in a table you can sort by total. On a phone the stats sit two by two and the table scrolls sideways; on a wide window everything spreads out.
Loading…
import { useState } from 'react'; import { ScrollView, StyleSheet, View } from 'react-native'; import { Badge, Card, CardContent, CardDescription, CardHeader, CardTitle, Heading, HStack, Progress, SegmentedControl, Stat, Table, Text, useTheme, } from 'patine-ui'; import type { TableColumn } from 'patine-ui'; import { Icon } from '@patine-ui/icons'; type Period = 'today' | 'week' | 'month'; type Order = { id: string; customer: string; total: number; status: 'Paid' | 'Shipped' | 'Refunded' }; const PERIODS = [ { label: 'Today', value: 'today' as Period }, { label: '7 days', value: 'week' as Period }, { label: '30 days', value: 'month' as Period }, ]; const STATS: Record<Period, { revenue: string; orders: string; aov: string; refunds: string; changes: number[] }> = { today: { revenue: '€1,284', orders: '23', aov: '€55.80', refunds: '0.8%', changes: [12.4, 9.1, 3.0, -0.4] }, week: { revenue: '€9,912', orders: '176', aov: '€56.30', refunds: '1.2%', changes: [6.8, 4.2, 2.5, 0.3] }, month: { revenue: '€38,240', orders: '691', aov: '€55.30', refunds: '1.6%', changes: [-2.1, -3.4, 1.3, 0.5] }, }; const ORDERS: Order[] = [ { id: '#2418', customer: 'Inês Costa', total: 113, status: 'Paid' }, { id: '#2417', customer: 'Rafael Mendes', total: 48.5, status: 'Shipped' }, { id: '#2416', customer: 'Lea Martin', total: 239, status: 'Shipped' }, { id: '#2415', customer: 'Omer Katz', total: 72, status: 'Refunded' }, { id: '#2414', customer: 'Yuki Tanaka', total: 156.9, status: 'Paid' }, ]; const STATUS_VARIANT = { Paid: 'success', Shipped: 'secondary', Refunded: 'destructive' } as const; const COLUMNS: TableColumn<Order>[] = [ { key: 'id', title: 'Order', width: 64 }, { key: 'customer', title: 'Customer', flex: 2 }, { key: 'total', title: 'Total', align: 'right', sortable: true, render: (o) => <Text>€{o.total.toFixed(2)}</Text> }, { key: 'status', title: 'Status', width: 96, render: (o) => <Badge variant={STATUS_VARIANT[o.status]}>{o.status}</Badge> }, ]; const GOAL = { raised: 38240, target: 50000 }; const pct = (n: number) => `${n > 0 ? '+' : ''}${n}%`; const trend = (n: number) => (n > 0 ? 'up' : n < 0 ? 'down' : 'neutral'); export default function Dashboard() { const { colors } = useTheme(); const [period, setPeriod] = useState<Period>('today'); const s = STATS[period]; return ( <ScrollView style={{ backgroundColor: colors.background }} contentContainerStyle={styles.content}> <View style={styles.titles}> <Text color="textSecondary">Tuesday, 18 November</Text> <Heading level={3}>Good morning, Ana</Heading> </View> <SegmentedControl items={PERIODS} value={period} onValueChange={setPeriod} accessibilityLabel="Period" /> <View style={styles.stats}> <Card style={styles.stat}> <Stat label="Revenue" value={s.revenue} change={pct(s.changes[0])} trend={trend(s.changes[0])} icon={<Icon name="wallet" size="sm" />} /> </Card> <Card style={styles.stat}> <Stat label="Orders" value={s.orders} change={pct(s.changes[1])} trend={trend(s.changes[1])} icon={<Icon name="package" size="sm" />} /> </Card> <Card style={styles.stat}> <Stat label="Avg. order" value={s.aov} change={pct(s.changes[2])} trend={trend(s.changes[2])} icon={<Icon name="receipt" size="sm" />} /> </Card> <Card style={styles.stat}> <Stat label="Refunds" value={s.refunds} change={pct(s.changes[3])} trend={trend(s.changes[3])} invertTrend icon={<Icon name="refresh" size="sm" />} /> </Card> </View> <Card> <CardHeader> <CardTitle>November goal</CardTitle> <CardDescription>12 days left · on track if you keep today’s pace</CardDescription> </CardHeader> <CardContent style={styles.goal}> <HStack justify="space-between" align="flex-end"> <Text weight="semibold" size="xl"> €{GOAL.raised.toLocaleString('en')} </Text> <Text color="textSecondary">of €{GOAL.target.toLocaleString('en')}</Text> </HStack> <Progress value={GOAL.raised} max={GOAL.target} accessibilityLabel="November goal" /> </CardContent> </Card> <Card> <CardHeader> <CardTitle>Latest orders</CardTitle> </CardHeader> <CardContent> <Table columns={COLUMNS} data={ORDERS} keyExtractor={(o) => o.id} minWidth={420} onRowPress={() => {}} /> </CardContent> </Card> </ScrollView> ); } const styles = StyleSheet.create({ content: { gap: 16, padding: 16 }, titles: { gap: 2 }, stats: { flexDirection: 'row', flexWrap: 'wrap', gap: 12 }, stat: { flexGrow: 1, flexBasis: '45%', padding: 14 }, goal: { gap: 10 }, });
Charts are in Pro
This screen stops at numbers. Patine Pro adds the charts a dashboard grows into, built the same way and themed by the same PatineProvider: a line or area chart of revenue, bars by channel, a sparkline inside each stat, and a stats row block that lays these four out for you.
Components used
- Stat: a label, the value, the change and its
trend;invertTrendmakes a rise in refunds red - Card: every tile, with
CardHeader,CardTitle,CardDescriptionandCardContent - Progress: the month's goal, with
valueandmax - Table:
columnswithrender,align,widthand asortabletotal;minWidthlets it scroll sideways on a phone - Badge: each order's status
- SegmentedControl: the period
- Heading, Text, HStack, Patine Icons
How it works
- The period swaps the numbers. Each period's figures sit in one object; a real app fetches them when
periodchanges. - Two by two, then a row. The stat cards wrap with
flexBasis: '45%', so they pair up on a phone and fill the width on a tablet. - Sort on the server for long lists: pass
sort,onSortChangeandmanualSortto the table and order the rows in your query.