AnalyticsDashboard
Full-featured analytics dashboard with multiple widgets
EventViewer
Real-time event stream viewer with filtering
StatsCard
Single metric display with trend indicator
StatsGrid
Grid layout for multiple stats cards
SimpleChart
Lightweight chart for line, bar, and area graphs
Installation
@sylphx/platform-sdk/react.AnalyticsDashboard
A comprehensive, customizable analytics dashboard that displays key metrics, charts, and event data. Supports real-time updates and custom date range selection.
Basic Usage
import { AnalyticsDashboard } from '@sylphx/platform-sdk/react'
export default function DashboardPage() {
return (
<AnalyticsDashboard
title="App Analytics"
dateRange="last_7_days"
/>
)
}Props
| Property | Type | Description |
|---|---|---|
title | string= "Analytics" | Dashboard title displayed at the top |
dateRange | DateRange= "last_7_days" | Initial date range for data |
widgets | Widget[] | Custom widgets to display |
refreshInterval | number= 30000 | Auto-refresh interval in milliseconds |
showDatePicker | boolean= true | Show date range picker |
showExport | boolean= true | Show export button for CSV/JSON |
events | string[] | Filter to specific event types |
userId | string | Filter to specific user |
onDateRangeChange | (range: DateRange) => void | Callback when date range changes |
className | string | Additional CSS classes |
Advanced Configuration
import { AnalyticsDashboard, type Widget } from '@sylphx/platform-sdk/react'
const customWidgets: Widget[] = [
{
id: 'total-users',
type: 'stat',
title: 'Total Users',
metric: 'users.total',
size: 'sm',
},
{
id: 'revenue',
type: 'stat',
title: 'Revenue',
metric: 'billing.revenue',
format: 'currency',
size: 'sm',
},
{
id: 'signups-chart',
type: 'chart',
title: 'Daily Signups',
metric: 'users.signups',
chartType: 'area',
size: 'lg',
},
{
id: 'top-events',
type: 'table',
title: 'Top Events',
metric: 'events.top',
size: 'md',
},
]
<AnalyticsDashboard
title="Business Metrics"
widgets={customWidgets}
dateRange="last_30_days"
/>EventViewer
A real-time event stream viewer that displays tracked events as they happen. Includes filtering, search, and detailed event inspection.
Basic Usage
import { EventViewer } from '@sylphx/platform-sdk/react'
export function RecentEvents() {
return (
<EventViewer
title="Recent Events"
limit={50}
/>
)
}Props
| Property | Type | Description |
|---|---|---|
title | string= "Events" | Title displayed above the event list |
limit | number= 100 | Maximum number of events to display |
events | string[] | Filter to specific event types |
userId | string | Filter to events from specific user |
realtime | boolean= true | Enable real-time event streaming |
showFilters | boolean= true | Show filter controls |
showSearch | boolean= true | Show search input |
showTimestamp | boolean= true | Show event timestamps |
showProperties | boolean= true | Show event properties in expanded view |
onEventClick | (event: AnalyticsEvent) => void | Callback when event is clicked |
emptyMessage | string= "No events found" | Message when no events found |
className | string | Additional CSS classes |
Advanced Usage
import { EventViewer } from '@sylphx/platform-sdk/react'
// Filter to specific event types
<EventViewer
title="Purchase Events"
events={['checkout_started', 'payment_submitted', 'order_completed']}
limit={25}
/>
// Filter to specific user
<EventViewer
title="User Activity"
userId={userId}
showFilters={false}
/>Performance
StatsCard
A compact card displaying a single metric with optional trend indicator, comparison values, and visual styling. Perfect for KPI displays and metric highlights.
Basic Usage
import { StatsCard } from '@sylphx/platform-sdk/react'
<StatsCard
title="Total Users"
value={12847}
change={12.5}
changeLabel="vs last month"
/>Props
| Property | Type | Description |
|---|---|---|
titlerequired | string | Label for the metric |
valuerequired | number | string | The primary metric value |
change | number | Percentage change (positive or negative) |
changeLabel | string= "vs previous period" | Label for the change value |
trend | "up" | "down" | "neutral" | Force trend direction (auto-detected from change) |
format | "number" | "currency" | "percent" | "compact"= "number" | Value formatting |
currency | string= "USD" | Currency code for currency format |
icon | ReactNode | Icon to display in the card |
loading | boolean= false | Show loading skeleton |
href | string | Link to detailed view |
variant | "default" | "primary" | "success" | "warning" | "danger"= "default" | Visual variant |
size | "sm" | "md" | "lg"= "md" | Card size |
className | string | Additional CSS classes |
Examples
import { StatsCard } from '@sylphx/platform-sdk/react'
import { Users, DollarSign, ShoppingCart, TrendingUp } from 'lucide-react'
<div className="grid grid-cols-4 gap-4">
<StatsCard
icon={<Users className="w-5 h-5" />}
title="Total Users"
value={12847}
change={12.5}
variant="primary"
/>
<StatsCard
icon={<DollarSign className="w-5 h-5" />}
title="Revenue"
value={84329}
format="currency"
change={8.2}
variant="success"
/>
<StatsCard
icon={<ShoppingCart className="w-5 h-5" />}
title="Orders"
value={1429}
change={-3.1}
variant="warning"
/>
<StatsCard
icon={<TrendingUp className="w-5 h-5" />}
title="Conversion"
value={3.24}
format="percent"
change={0.5}
/>
</div>StatsGrid
A responsive grid layout for displaying multiple StatsCards. Handles layout, spacing, and loading states for a collection of metrics.
Basic Usage
import { StatsGrid } from '@sylphx/platform-sdk/react'
const stats = [
{ title: 'Total Users', value: 12847, change: 12.5 },
{ title: 'Active Today', value: 1429, change: -3.1 },
{ title: 'Revenue', value: 84329, format: 'currency', change: 8.2 },
{ title: 'Conversion', value: 3.24, format: 'percent', change: 0.5 },
]
<StatsGrid stats={stats} />Props
| Property | Type | Description |
|---|---|---|
statsrequired | StatConfig[] | Array of stat configurations |
columns | 1 | 2 | 3 | 4 | 5 | 6= 4 | Number of columns in grid |
gap | "sm" | "md" | "lg"= "md" | Gap between cards |
loading | boolean= false | Show loading state for all cards |
variant | StatsCard variant | Default variant for all cards |
size | StatsCard size= "md" | Default size for all cards |
className | string | Additional CSS classes |
StatConfig Type
interface StatConfig {
title: string
value: number | string
change?: number
changeLabel?: string
format?: 'number' | 'currency' | 'percent' | 'compact'
currency?: string
icon?: ReactNode
variant?: 'default' | 'primary' | 'success' | 'warning' | 'danger'
href?: string
}Examples
import { StatsGrid } from '@sylphx/platform-sdk/react'
import { Users, DollarSign, ShoppingCart, Eye } from 'lucide-react'
const stats = [
{
icon: <Users className="w-5 h-5" />,
title: 'Total Users',
value: 12847,
change: 12.5,
variant: 'primary',
},
{
icon: <DollarSign className="w-5 h-5" />,
title: 'Revenue',
value: 84329,
format: 'currency',
change: 8.2,
variant: 'success',
},
{
icon: <ShoppingCart className="w-5 h-5" />,
title: 'Orders',
value: 1429,
change: -3.1,
variant: 'warning',
},
{
icon: <Eye className="w-5 h-5" />,
title: 'Page Views',
value: 284739,
format: 'compact',
change: 24.8,
},
]
<StatsGrid stats={stats} columns={4} />SimpleChart
A lightweight, performant chart component for displaying time-series data. Supports line, bar, and area chart types with minimal configuration.
Basic Usage
import { SimpleChart } from '@sylphx/platform-sdk/react'
const data = [
{ date: '2024-01-01', value: 100 },
{ date: '2024-01-02', value: 120 },
{ date: '2024-01-03', value: 115 },
{ date: '2024-01-04', value: 140 },
{ date: '2024-01-05', value: 135 },
{ date: '2024-01-06', value: 160 },
{ date: '2024-01-07', value: 175 },
]
<SimpleChart
data={data}
type="line"
title="Daily Active Users"
/>Props
| Property | Type | Description |
|---|---|---|
datarequired | ChartDataPoint[] | Array of data points with date and value |
type | "line" | "bar" | "area"= "line" | Chart type |
title | string | Chart title |
subtitle | string | Subtitle or description |
height | number= 300 | Chart height in pixels |
color | string= "primary" | Primary color for the chart |
gradient | boolean= true | Enable gradient fill for area charts |
showGrid | boolean= true | Show grid lines |
showXAxis | boolean= true | Show X axis labels |
showYAxis | boolean= true | Show Y axis labels |
showTooltip | boolean= true | Show tooltip on hover |
showLegend | boolean= false | Show chart legend |
xAxisKey | string= "date" | Key for X axis values |
yAxisKey | string= "value" | Key for Y axis values |
formatValue | (value: number) => string | Custom value formatter |
formatDate | (date: string) => string | Custom date formatter |
loading | boolean= false | Show loading skeleton |
emptyMessage | string= "No data available" | Message when no data |
className | string | Additional CSS classes |
ChartDataPoint Type
interface ChartDataPoint {
date: string // ISO date string or formatted date
value: number // Primary metric value
[key: string]: any // Additional data for multi-series charts
}Chart Types
import { SimpleChart } from '@sylphx/platform-sdk/react'
<SimpleChart
data={data}
type="line"
title="User Growth"
color="#6366f1"
showGrid={true}
height={350}
/>Multi-Series Charts
import { SimpleChart } from '@sylphx/platform-sdk/react'
const multiSeriesData = [
{ date: '2024-01-01', pageViews: 1200, uniqueVisitors: 450 },
{ date: '2024-01-02', pageViews: 1350, uniqueVisitors: 520 },
{ date: '2024-01-03', pageViews: 1180, uniqueVisitors: 480 },
{ date: '2024-01-04', pageViews: 1420, uniqueVisitors: 590 },
{ date: '2024-01-05', pageViews: 1560, uniqueVisitors: 640 },
]
<SimpleChart
data={multiSeriesData}
type="line"
title="Traffic Overview"
series={[
{ key: 'pageViews', label: 'Page Views', color: '#6366f1' },
{ key: 'uniqueVisitors', label: 'Unique Visitors', color: '#10b981' },
]}
showLegend={true}
/>Performance
@sylphx/charts package for more advanced visualization needs.Complete Example
Here is a complete example combining multiple analytics components into a dashboard:
'use client'
import {
AnalyticsDashboard,
StatsGrid,
SimpleChart,
EventViewer,
} from '@sylphx/platform-sdk/react'
import { useAnalytics } from '@sylphx/platform-sdk/react'
import { Users, DollarSign, Activity, TrendingUp } from 'lucide-react'
export default function AnalyticsPage() {
const { data, loading } = useAnalytics({
metrics: ['users.total', 'revenue.total', 'events.count', 'conversion.rate'],
dateRange: 'last_7_days',
})
const stats = [
{
icon: <Users className="w-5 h-5" />,
title: 'Total Users',
value: data?.users?.total ?? 0,
change: data?.users?.change ?? 0,
variant: 'primary' as const,
},
{
icon: <DollarSign className="w-5 h-5" />,
title: 'Revenue',
value: data?.revenue?.total ?? 0,
format: 'currency' as const,
change: data?.revenue?.change ?? 0,
variant: 'success' as const,
},
{
icon: <Activity className="w-5 h-5" />,
title: 'Events',
value: data?.events?.count ?? 0,
format: 'compact' as const,
change: data?.events?.change ?? 0,
},
{
icon: <TrendingUp className="w-5 h-5" />,
title: 'Conversion',
value: data?.conversion?.rate ?? 0,
format: 'percent' as const,
change: data?.conversion?.change ?? 0,
},
]
return (
<div className="space-y-8 p-6">
<h1 className="text-3xl font-bold">Analytics Dashboard</h1>
{/* Key Metrics */}
<StatsGrid stats={stats} loading={loading} columns={4} />
{/* Charts */}
<div className="grid grid-cols-2 gap-6">
<SimpleChart
data={data?.userGrowth ?? []}
type="area"
title="User Growth"
color="#6366f1"
height={300}
loading={loading}
/>
<SimpleChart
data={data?.revenue ?? []}
type="bar"
title="Daily Revenue"
color="#10b981"
formatValue={(v) => `$${v.toLocaleString()}`}
height={300}
loading={loading}
/>
</div>
{/* Event Stream */}
<EventViewer
title="Recent Events"
limit={25}
showFilters={true}
realtime={true}
/>
</div>
)
}Theming
All analytics components inherit theming from the SylphxProvider or can be customized individually:
import { SylphxProvider, StatsCard, SimpleChart } from '@sylphx/platform-sdk/react'
// Global theming via provider
<SylphxProvider
theme={{
colorPrimary: '#6366f1',
colorSuccess: '#10b981',
colorWarning: '#f59e0b',
colorDanger: '#ef4444',
borderRadius: '0.75rem',
}}
>
<StatsCard title="Revenue" value={12500} />
<SimpleChart data={data} type="line" />
</SylphxProvider>
// Individual component styling
<StatsCard
title="Custom Card"
value={100}
className="bg-gradient-to-br from-purple-500/10 to-pink-500/10"
/>
<SimpleChart
data={data}
type="area"
color="#8b5cf6"
className="rounded-2xl shadow-lg"
/>Need more charts?
@sylphx/charts package which provides a comprehensive charting library built on top of these primitives.