Components
bio-health-metrics
<bio-health-metrics>
A self-contained health metrics widget that manages OAuth provider connections (starting with Fitbit) and displays synced metrics — steps, sleep, heart rate/HRV, stress, active minutes, and calories.
<bio-health-metrics></bio-health-metrics>How It Works
When <bio-health-metrics> receives context from a parent <bio-provider>:
- Resolves provider list — in profile-driven mode, reads enabled health providers from the episode profile's
spec.sdk.healthMetricssection; in static mode, uses theprovidersattribute - Shows connection state — for each provider, displays a "Connect" button (disconnected) or the provider name with a status badge (connected)
- Handles OAuth — clicking "Connect" initiates the OAuth flow for that provider; on success, stores the connection and emits
anybio:health:connected - Fetches metrics — once connected, pulls the latest metrics for the requested
dateand renders metric cards for steps, sleep, heart rate/HRV, stress, active minutes, and calories - Supports refresh — a refresh button re-fetches metrics from the provider and emits
anybio:health:refreshed - Supports disconnect — an "Unlink" action removes the provider connection and emits
anybio:health:disconnected
Modes
Profile-Driven Mode
Omit all attributes. The widget reads its configuration from the episode profile's spec.sdk.healthMetrics section:
<bio-health-metrics></bio-health-metrics>The profile defines:
providers— array of enabled provider slugs (e.g.,["fitbit"])metrics— array of metric keys to display (e.g.,["steps", "sleep", "heartRate"])compact— whether to use the compact layout
Static Mode
Pass configuration directly:
<bio-health-metrics
providers='["fitbit"]'
metrics='["steps","sleep","heartRate","hrv"]'
date="2025-06-15"
episode-id="ep_abc123">
</bio-health-metrics>Attributes
| Attribute | Type | Required | Description |
|---|---|---|---|
episode-id | string | No | Falls back to <bio-provider> resolved episode. |
date | string | No | Date for metrics (YYYY-MM-DD). Defaults to today. |
providers | string | No | JSON array of provider slugs. Omit for profile-driven mode. |
metrics | string | No | JSON array of metric keys to show. Defaults to all six. |
show-header | boolean | No | Show/hide header bar. Defaults to true. |
compact | boolean | No | Compact 4-metric grid without progress bars or breakdowns. |
Events
| Event | Detail | Description |
|---|---|---|
anybio:health:connected | { provider, providerUserId } | OAuth completed. |
anybio:health:disconnected | { provider } | Provider unlinked. |
anybio:health:refreshed | { provider, date, metrics } | Metrics refreshed. |
anybio:health:error | { error, action } | Error. action: "connect", "disconnect", "refresh", "fetch". |
bio-health-connected | (alias) | Backward-compatible. |
bio-health-disconnected | (alias) | Backward-compatible. |
CSS Classes
The widget renders with semantic CSS classes for styling. No Shadow DOM — standard CSS selectors work.
Layout
| Class | Element |
|---|---|
.bio-hm-container | Outermost wrapper |
.bio-hm-header | Header bar with title and refresh button |
.bio-hm-title | Widget title text |
.bio-hm-refresh-btn | Refresh button |
Provider Connection
| Class | Element |
|---|---|
.bio-hm-providers | Provider list container |
.bio-hm-provider-row | Single provider row (name + action) |
.bio-hm-provider-name | Provider display name |
.bio-hm-provider-badge | Connection status badge |
.bio-hm-connect-btn | "Connect" button (disconnected state) |
.bio-hm-unlink-btn | "Unlink" action button |
Metrics Grid
| Class | Element |
|---|---|
.bio-hm-metrics | Metrics card grid |
.bio-hm-card | Individual metric card |
.bio-hm-card-icon | Metric icon |
.bio-hm-card-label | Metric label (e.g., "Steps") |
.bio-hm-card-value | Primary metric value |
.bio-hm-card-unit | Unit text (e.g., "bpm", "hrs") |
.bio-hm-card-progress | Progress bar wrapper |
.bio-hm-card-bar | Progress bar fill |
.bio-hm-card-breakdown | Breakdown details (e.g., sleep stages) |
States
| Class | Element |
|---|---|
.bio-hm-loading | Applied to container while fetching |
.bio-hm-empty | Applied when no metrics available |
.bio-hm-error | Applied on fetch/connection error |
.bio-hm-compact | Applied when compact attribute is set |
Code Examples
Profile-Driven
<bio-provider
api-key="org_your_key"
project-key="proj_your_key"
xuser-id="user-123">
<h3>Your Health Metrics</h3>
<bio-health-metrics></bio-health-metrics>
</bio-provider>With Event Handling
<bio-health-metrics id="hm"></bio-health-metrics>
<script>
document.addEventListener('anybio:health:connected', (e) => {
const { provider, providerUserId } = e.detail;
console.log(`Connected to ${provider} (${providerUserId})`);
showToast(`${provider} connected!`);
});
document.addEventListener('anybio:health:refreshed', (e) => {
const { provider, date, metrics } = e.detail;
console.log(`Refreshed ${provider} metrics for ${date}:`, metrics);
});
document.addEventListener('anybio:health:error', (e) => {
const { error, action } = e.detail;
console.error(`Health metrics ${action} failed:`, error);
showToast(`Error: ${error}`, 'error');
});
</script>Custom Styling
/* Match your app's design system */
bio-health-metrics {
--bio-primary: #1a73e8;
--bio-surface: #ffffff;
--bio-radius: 12px;
}
/* Style the metric cards */
.bio-hm-card {
border: 1px solid var(--bio-border);
border-radius: var(--bio-radius);
padding: 16px;
}
/* Custom connect button */
.bio-hm-connect-btn {
background: var(--bio-primary);
color: white;
border-radius: 8px;
padding: 8px 16px;
}Compact Mode
<bio-health-metrics
compact
metrics='["steps","sleep","heartRate","calories"]'>
</bio-health-metrics>Compact mode renders a 4-metric grid without progress bars or breakdown details — useful for dashboard summaries or sidebar widgets.
Roadmap
<bio-provider-link>standalone widget — Extract the provider connection UI into a reusable standalone component for use outside of<bio-health-metrics>.- Additional providers — Garmin, Apple Health, Oura, Dexcom.
- Caregiver view — Read-only metrics display for caregiver-monitored patients.
- Weekly trend charts — Inline sparklines or bar charts showing 7-day trends per metric.