@molecule/app-habit-streak-card-svelte

Feature · habit-streak-card · App (browser) · v1.1.3 · Apache-2.0

Habit / streak card with current streak, best streak, completion heatmap

npm install @molecule/app-habit-streak-card-svelte

npm · Source on GitHub

How it works

@molecule/app-habit-streak-card-svelte is a ready-made habit-streak-card feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

<script lang="ts">
  import type { StreakDay } from '@molecule/app-habit-streak-card-svelte'
  import { HabitStreakCard } from '@molecule/app-habit-streak-card-svelte'

  const recentDays: StreakDay[] = [
    { date: '2026-07-01', count: 1 },
    { date: '2026-07-02', count: 3 },
  ]
</script>

<HabitStreakCard
  name="Morning Run"
  currentStreak={14}
  bestStreak={30}
  totalCompletions={87}
  heatmap={recentDays}
>
  {#snippet icon()}<span>🏃</span>{/snippet}
</HabitStreakCard>

Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte

Reference

Svelte habit / streak summary card — current streak, best streak, total completions, and an optional per-day heatmap strip. Use for habit trackers, meditation streaks, daily-task widgets.

Exports HabitStreakCard and the StreakDay / HabitStreakCardProps types.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

<script lang="ts">
  import type { StreakDay } from '@molecule/app-habit-streak-card-svelte'
  import { HabitStreakCard } from '@molecule/app-habit-streak-card-svelte'

  const recentDays: StreakDay[] = [
    { date: '2026-07-01', count: 1 },
    { date: '2026-07-02', count: 3 },
  ]
</script>

<HabitStreakCard
  name="Morning Run"
  currentStreak={14}
  bestStreak={30}
  totalCompletions={87}
  heatmap={recentDays}
>
  {#snippet icon()}<span>🏃</span>{/snippet}
</HabitStreakCard>

Type

feature

Installation

npm install @molecule/app-habit-streak-card-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

StreakDay

Represents a single day's completion data for the heatmap strip.

interface StreakDay {
  /** ISO date (yyyy-mm-dd). */
  date: string
  /** Completion count for the day (0 = not done, >0 = intensity). */
  count: number
}

HabitStreakCardProps

Props accepted by the HabitStreakCard component (React's names).

interface HabitStreakCardProps {
  /** Habit name — a snippet or a plain string. */
  name: Snippet | string
  /** Optional leading icon — a snippet or a plain string. */
  icon?: Snippet | string
  /** Current streak (days). */
  currentStreak: number
  /** Best streak (days). */
  bestStreak?: number
  /** Total completions. */
  totalCompletions?: number
  /** Optional heatmap days — rendered as a strip of squares. */
  heatmap?: StreakDay[]
  /** Days the heatmap should display (truncates `heatmap` from the end). Defaults to 30. */
  heatmapDays?: number
  /** Extra classes. */
  className?: string
}

Constants

HabitStreakCard

const HabitStreakCard: LegacyComponentType

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-svelte ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-svelte ^1.1.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-svelte

  • @molecule/app-ui

  • @molecule/app-ui-svelte

  • svelte

  • Requires the Svelte binding's i18n provider (useTranslation() THROWS without it) and a bonded ClassMap for getClassMap(). Stat labels come from the @molecule/app-locales-habit-streak-card companion bond.

  • The heatmap strip uses a fixed green ramp with a light-only zero color (rgba(0,0,0,0.08)) rendered as inline styles — on dark themes the empty cells are nearly invisible. For a theme-aware year grid use @molecule/app-heatmap-svelte with a custom colorScale instead.

  • heatmapDays truncates heatmap from the END (most recent days win).

  • The name and icon props are snippets (or plain strings).

Translations

Translation strings are provided by @molecule/app-locales-habit-streak-card.