Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using the showWeekdayLabels parameter #93

Closed
maodaisuki opened this issue Jun 5, 2024 · 3 comments
Closed

Error when using the showWeekdayLabels parameter #93

maodaisuki opened this issue Jun 5, 2024 · 3 comments

Comments

@maodaisuki
Copy link

Hi, I'm having some trouble. Here is my code.

"use client";
import styles from "./heatmap.module.css";
import React from "react";
import { Tooltip as ReactTooltip } from "react-tooltip";
import "react-tooltip/dist/react-tooltip.css";
import ActivityCalendar from "react-activity-calendar";
const HeatmapBlock = () => {
  const data = [
    {
      date: "2024-01-01",
      count: 2,
      level: 1,
    },
  ];
  return (
    <div className={styles.container}>
      <ActivityCalendar
        blockRadius={2}
        blockMargin={2}
        blockSize={12}
        theme={{
          light: ["#edeff2", "#646e93", "#646e93", "#798bc5", "#8ea9fa"],
          dark: ['#636466', '#646e93', '#646e93', '#798bc5', '#8ea9fa'],
        }}
        data={data}
        labels={{
          weekdays: ["S", "M", "T", "W", "T", "F", "S"],
        }}
        showWeekdayLabels
        renderBlock={(block, activity) =>
          React.cloneElement(block, {
            "data-tooltip-id": "react-tooltip",
            "data-tooltip-html": `${activity.count} activities on ${activity.date}`,
          })
        }
      />
      <ReactTooltip id="react-tooltip" />
    </div>
  );
};

export default HeatmapBlock;

Although it is able to run, the console outputs an error.

⨯ ..\src\utils\calendar.ts (195:11) @ calcTextDimensions
 ⨯ Error: calcTextDimensions() requires browser APIs
    at Array.reduce (<anonymous>)
digest: "2520002460"
  193 | function calcTextDimensions(text: string, fontSize: number) {
  194 |   if (typeof document === 'undefined' || typeof window === 'undefined') {
> 195 |     throw new Error('calcTextDimensions() requires browser APIs');
      |           ^
  196 |   }
  197 |
  198 |   if (fontSize < 1) {
 GET / 500 in 583ms
@maodaisuki
Copy link
Author

By the way, I am using nextjs14, and the react-activity-calendar version is 2.2.8

@grubersjoe
Copy link
Owner

grubersjoe commented Jun 5, 2024

Heyo. Thanks for reporting this bug!

Fixed in react-activity-calendar@2.2.9, please try this version. Tested successfully with Next.js 14.2.3.

@maodaisuki
Copy link
Author

It worked, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants