@symbiot.dev/react-native-heatmap
Version:
A lightweight and customizable activity graph for React Native, perfect for visualizing user engagement, habits, streaks, or productivity over time.
288 lines (202 loc) β’ 14.5 kB
Markdown
<div align="center">
<h1>React Native Heatmap π₯π</h1>
</div>
> **react-native-heatmap** is a lightweight and customizable activity graph for React Native. Perfect for visualizing user engagement, habits, streaks, or productivity over time.
> It supports **iOS**, **Android**, **Web**, and **Expo**, making it easy to drop into any cross-platform app.
<div align="center">
<img alt="NPM downloads" src="https://img.shields.io/npm/dw/@symbiot.dev/react-native-heatmap?logo=npm&label=npm&cacheSeconds=3600"/>
<img alt="NPM version" src="https://img.shields.io/npm/v/@symbiot.dev/react-native-heatmap?logo=npm&label=npm&cacheSeconds=3600"/>
<img alt="Bundle size" src="https://img.shields.io/bundlephobia/minzip/@symbiot.dev/react-native-heatmap?label=size&cacheSeconds=3600"/>
<img alt="Typescript" src="https://img.shields.io/static/v1?label=&message=TS&color=blue"/>
</div>
## [π± Demo](#demo)
<div>
<h3 align="center">WeeklyHeatMap</h3>
<div align="center">
<img alt="Demo 1" src="https://github.com/symbiotdev/react-native-heatmap/blob/main/assets/1.png" width="200px" height="400px" />
<img alt="Demo 2" src="https://github.com/symbiotdev/react-native-heatmap/blob/main/assets/2.png" width="200px" height="400px" />
<img alt="Demo 3" src="https://github.com/symbiotdev/react-native-heatmap/blob/main/assets/3.png" width="200px" height="400px" />
<img alt="Demo 4" src="https://github.com/symbiotdev/react-native-heatmap/blob/main/assets/4.png" width="200px" height="400px" />
</div>
<h3 align="center">MonthlyHeatMap</h3>
<div align="center">
<img alt="Demo 5" src="https://github.com/symbiotdev/react-native-heatmap/blob/main/assets/5.png" width="200px" height="400px" />
<img alt="Demo 6" src="https://github.com/symbiotdev/react-native-heatmap/blob/main/assets/6.png" width="200px" height="400px" />
<img alt="Demo 7" src="https://github.com/symbiotdev/react-native-heatmap/blob/main/assets/7.png" width="200px" height="400px" />
<img alt="Demo 8" src="https://github.com/symbiotdev/react-native-heatmap/blob/main/assets/8.png" width="200px" height="400px" />
</div>
</div>
___
## [β¨ Key Features](#features)
π₯ **Activity Grid** β Clean, familiar visual language
π¨ **Themeable & Flexible** β Customize color levels, spacing & more
π **Date-Aware** β Renders accurate calendar heatmaps over weeks/months
π± **Cross-Platform** β Fully supports:
- iOS & Android
- Web via React Native Web
- Expo & Expo Go
π‘ **Use Cases**
- Habit tracking
- Productivity dashboards
- Wellness streaks
- Learning progress (e.g. courses, coding)
- Daily user activity insights
## [π©πΏβπ» Installation](#installation)
```bash
npm install @symbiot.dev/react-native-heatmap date-fns react-native-svg
# or
yarn add @symbiot.dev/react-native-heatmap date-fns react-native-svg
# for web support
npm i react-native-web
# or
yarn add react-native-web
```
## [π§© Components](#components)
The package provides **two** main heatmap components out of the box:
- `MonthlyHeatMap` β Displays activity heatmaps aggregated by month.
- `WeeklyHeatMap` β Displays activity heatmaps aggregated by week.
## π
`HeatMapDailyProps` β [Daily Data Configuration](#daily)
Provide daily activity data for the heatmap.
Accepts either an array of dates or a record mapping dates to activity counts.
| Property | Type | Description | π Web | π iOS | π€ Android |
|----------|------------------------------------------------|-----------------------------------------------------------|:------:|:------:|:----------:|
| `data` | `(Date \| string)[] \| Record<string, number>` | Array of dates or object with date keys and count values. | β
| β
| β
|
## π `HeatMapWeeklyProps` β [Weekly Data Configuration](#weekly)
Customize weekly layout and cell content display.
Set which day the week starts on and choose to show date or count inside cells.
| Property | Type | Description | π Web | π iOS | π€ Android |
|----------------|---------------------|---------------------------------------------------------|:------:|:------:|:----------:|
| `weekStartsOn` | `Day` | Day to start the week (e.g. Sunday or Monday). | β
| β
| β
|
| `cellText` | `'date' \| 'count'` | Content shown inside cells: the date or activity count. | β
| β
| β
|
> The components is fully customizable, offering a flexible theming system to align with your appβs look and feel. You can fine-tune the color palette, layout behavior, and styling for both light and dark modes.
## π₯ `HeatMapScheme` β [Color Scheme Configuration](#colorscheme)
```ts
type HeatMapScheme = 'light' | 'dark';
```
Defines the visual scheme used by the heatmap. Useful when supporting multiple themes.
- `light` β Light mode colors
- `dark` β Dark mode colors
```ts
type HeatMapColor = {
headerTextColor?: string;
cellDefaultColor?: string;
cellTextColor?: string;
cellColor?: Record<number, string>;
sidebarTextColor?: string;
};
```
Defines the color palette for different parts of the heatmap UI.
| Property | Type | Description | Web | iOS | Android |
|--------------------|--------------------------|---------------------------------------------------------------------|:---:|:---:|:-------:|
| `headerTextColor` | `string` | Color of the top header labels (e.g. days of the week). | β
| β
| β
|
| `cellDefaultColor` | `string` | Background color used when no activity level is defined. | β
| β
| β
|
| `cellTextColor` | `string` | Text color inside individual cells (if used). | β
| β
| β
|
| `cellColor` | `Record<number, string>` | Maps activity levels (e.g. 1β5) to specific cell background colors. | β
| β
| β
|
| `sidebarTextColor` | `string` | Color for sidebar text (e.g. month or week labels). | β
| β
| β
|
## π¨ `HeatMapThemeProps` β [Theme & Colors](#theme)
Supports global styling with per-scheme overrides (light/dark). The scheme property determines the active theme. You can define a base theme and override specific properties for each mode.
```ts
type HeatMapThemeProps = HeatMapColor & {
scheme?: HeatMapScheme;
} & {
[key in HeatMapScheme]?: HeatMapColor;
};
```
## π¨ `HeatMapStyle` β [Style Customization](#style)
```ts
type HeatMapStyle = {
scrollStyle?: StyleProp<ViewStyle>;
headerTextAlign?: TextStyle['textAlign'];
};
```
Defines optional style overrides for layout and header alignment in the heatmap component.
Use this type to customize the scroll container and control how the header text is aligned.
| Property | Type | Description | Web | iOS | Android |
|-------------------|--------------------------|--------------------------------------------------------------------|:---:|:---:|:-------:|
| `scrollStyle` | `StyleProp<ViewStyle>` | Style for the scrollable container that wraps the heatmap grid. | β
| β
| β
|
| `headerTextAlign` | `TextStyle['textAlign']` | Controls alignment of the header text (`left`, `center`, `right`). | β
| β
| β
|
## π `HeatMapDimensionsProps` β [Dimensions & Sizing](#dimensions)
Customize sizing and spacing to perfectly fit your design and layout needs.
Adjust fonts, cell size, gaps, and radius for a tailored heatmap appearance.
| Property | Type | Description | π Web | π iOS | π€ Android |
|-----------------------|----------|---------------------------------------------------------|:------:|:------:|:----------:|
| `headerTextFontSize` | `number` | Font size for the header text (e.g. days of week). | β
| β
| β
|
| `headerBottomSpace` | `number` | Space below the header area. | β
| β
| β
|
| `cellSize` | `number` | Width and height of each heatmap cell. | β
| β
| β
|
| `cellRadius` | `number` | Border radius of each heatmap cell for rounded corners. | β
| β
| β
|
| `cellGap` | `number` | Gap between individual cells. | β
| β
| β
|
| `cellTextFontSize` | `number` | Font size of the text inside each cell (if any). | β
| β
| β
|
| `sideBarTextFontSize` | `number` | Font size for the sidebar text (e.g. month labels). | β
| β
| β
|
## ποΈ `HeatMapControllerProps` β [Controller & Interaction](#controller)
Control interaction and visibility options for the heatmap component.
Toggle press, hover, scrolling behaviors, layout direction, and UI element visibility.
| Property | Type | Description | π Web | π iOS | π€ Android |
|---------------------|-----------|----------------------------------------------------------|:------:|:------:|:----------:|
| `pressable` | `boolean` | Enables pressing (tap) on heatmap cells. | β
| β
| β
|
| `hoverable` | `boolean` | Enables hover effect on cells (primarily for web). | β
| β | β |
| `scrollable` | `boolean` | Enables scrolling of the heatmap container. | β
| β
| β
|
| `rtl` | `boolean` | Enables right-to-left layout support for RTL languages. | β
| β
| β
|
| `isHeaderVisible` | `boolean` | Toggles visibility of the header row (e.g. days labels). | β
| β
| β
|
| `isCellTextVisible` | `boolean` | Toggles visibility of text inside cells. | β
| β
| β
|
| `isSidebarVisible` | `boolean` | Toggles visibility of the sidebar (e.g. month labels). | β
| β
| β
|
## π `HeatMapFormatterProps` β [Text Formatting & Localization](#formatter)
Customize text formatting and localization for headers and sidebars.
Format date labels and apply locale-specific formatting for better internationalization.
| Property | Type | Description | π Web | π iOS | π€ Android |
|---------------------|----------|--------------------------------------------------------|:------:|:------:|:----------:|
| `headerTextFormat` | `string` | Format string for header text (e.g. days of the week). | β
| β
| β
|
| `sidebarTextFormat` | `string` | Format string for sidebar text (e.g. month labels). | β
| β
| β
|
| `locale` | `Locale` | Locale object for date localization (from `date-fns`). | β
| β
| β
|
## β³ `HeatMapDatetimeProps` β [Date & Time Configuration](#datetime)
Configure the date range and visibility of specific days in the heatmap.
Control which days are displayed and the start/end boundaries of the activity grid.
| Property | Type | Description | π Web | π iOS | π€ Android |
|--------------|---------|--------------------------------------------|:------:|:------:|:----------:|
| `startDate` | `Date` | The starting date for the heatmap display. | β
| β
| β
|
| `endDate` | `Date` | The ending date for the heatmap display. | β
| β
| β
|
| `hiddenDays` | `Day[]` | Array of days to hide (e.g., weekends). | β
| β
| β
|
## π― `HeatMapActionsProps` β [User Actions & Events](#actions)
Handle user interactions with the heatmap cells, including taps and mouse events.
Useful for adding custom behaviors like tooltips, navigation, or analytics tracking.
| Property | Type | Description | π Web | π iOS | π€ Android |
|----------------|-------------------------------------------------------------------------|-----------------------------------------------------|:------:|:------:|:----------:|
| `onCellPress` | `(params: { date: Date; count: number }) => void` | Callback fired when a cell is pressed/tapped. | β
| β
| β
|
| `onMouseEnter` | `(params: { date: Date; x: number; y: number; count: number }) => void` | Callback fired when mouse enters a cell (web only). | β
| β | β |
| `onMouseLeave` | `() => void` | Callback fired when mouse leaves a cell (web only). | β
| β | β |
### [π **Platform Support**](#support)
- β
iOS
- β
Android
- β
Web
- β
Expo & Expo Go
### [π¦ **Bundle Size**](#size)
Lightweight and fast β see actual size on [Bundlephobia](https://bundlephobia.com/package/@symbiot.dev/react-native-heatmap).
### [π¬ Contributing](#contributing)
Contributions welcome! Feel free to open issues, discussions, or suggestions.
### [π Who's Using This?](#usage)
Using `react-native-heatmap` in your app or product?
Feel free to share your project β it might be featured in this section!
> βοΈ Open pull request, or reach out directly to get included.
___
### [π Got Ideas or Gaps to Fill?](#ideas)
Know of existing libraries or functionality that could be improved?
Have an idea for something completely new?
**Symbiot** is ready to take on the challenge β feedback, feature requests, or collaboration ideas are always welcome!
> π§ Letβs build better tools together. Start the conversation or contact via [email](mailto:info@symbiot.dev).
___
### [π§Ύ License](#license)
MIT β Made with β€οΈ by [Symbiot](https://symbiot.dev)