Skip to content

Instantly share code, notes, and snippets.

@gitname
Created November 25, 2017 23:31
Show Gist options
  • Save gitname/3680a3c7354acff40eeb7a07206240eb to your computer and use it in GitHub Desktop.
Save gitname/3680a3c7354acff40eeb7a07206240eb to your computer and use it in GitHub Desktop.
CodeSandbox project demonstrating Issue #59 in `patientslikeme/react-calendar-heatmap`
<div id="root"></div>
import React from "react";
import { render } from "react-dom";
import CalendarHeatmap from "react-calendar-heatmap";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
heatmapData: [
{ date: new Date("2017-06-01") },
{ date: new Date("2017-06-02") }
],
activeYear: 2017
};
}
activatePrevYear() {
this.setState(prevState => {
return {
activeYear: prevState.activeYear - 1
};
});
}
activateNextYear() {
this.setState(prevState => {
return {
activeYear: prevState.activeYear + 1
};
});
}
render() {
const { activeYear, heatmapData } = this.state;
const startDate = new Date(`${activeYear}-01-01`);
const endDate = new Date(`${activeYear}-12-31`);
const heatmapDataListItems = heatmapData.map(item => (
<li><pre>{item.date.toString()}</pre></li>
));
return (
<div>
<h2>Heatmap Data</h2>
<p>This data is <strong>constant</strong>.</p>
<ol>{heatmapDataListItems}</ol>
<h2>Heatmap for the Year {activeYear}</h2>
<CalendarHeatmap
values={heatmapData}
startDate={startDate}
endDate={endDate}
/>
<h3>Year Changers</h3>
<p>Change the year shown on the heatmap.</p>
<button onClick={this.activatePrevYear.bind(this)}>
Show previous year
</button>
<button onClick={this.activateNextYear.bind(this)}>
Show next year
</button>
</div>
);
}
}
render(<App />, document.getElementById("root"));
{
"name": "demo-of-issue-in-react-calendar-heatmap",
"description": "Issue URL: https://github.com/patientslikeme/react-calendar-heatmap/issues/59",
"version": "0.0.11",
"dependencies": {
"react-dom": "16.0.0",
"react-calendar-heatmap": "1.6.1",
"react": "16.0.0"
},
"devDependencies": {
"react-scripts": "1.0.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment