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

Add showAllWeekdayLabels option to show all weekdays. #87

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@
"rimraf": "^2.0.0",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.0.0"
},
"jest": {
"testURL": "http://localhost"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be in jest.config.js instead?

}
}
4 changes: 3 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class CalendarHeatmap extends React.Component {
const [x, y] = this.getWeekdayLabelCoordinates(dayIndex);
const cssClasses = `${this.latestProps.horizontal ? '' : `${CSS_PSEDUO_NAMESPACE}small-text`} ${CSS_PSEDUO_NAMESPACE}weekday-label`;
// eslint-disable-next-line no-bitwise
return dayIndex & 1 ? (
return this.latestProps.showAllWeekdayLabels || dayIndex & 1 ? (
<text key={`${x}${y}`} x={x} y={y} className={cssClasses}>
{weekdayLabel}
</text>
Expand Down Expand Up @@ -333,6 +333,7 @@ CalendarHeatmap.propTypes = {
horizontal: PropTypes.bool, // whether to orient horizontally or vertically
showMonthLabels: PropTypes.bool, // whether to show month labels
showWeekdayLabels: PropTypes.bool, // whether to show weekday labels
showAllWeekdayLabels: PropTypes.bool, // whether to show all weekday labels
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also document this prop in the readme?

showOutOfRangeDays: PropTypes.bool, // whether to render squares for extra days in week after endDate, and before start date
tooltipDataAttrs: PropTypes.oneOfType([PropTypes.object, PropTypes.func]), // data attributes to add to square for setting 3rd party tooltips, e.g. { 'data-toggle': 'tooltip' } for bootstrap tooltips
titleForValue: PropTypes.func, // function which returns title text for value
Expand All @@ -352,6 +353,7 @@ CalendarHeatmap.defaultProps = {
horizontal: true,
showMonthLabels: true,
showWeekdayLabels: false,
showAllWeekdayLabels: false,
showOutOfRangeDays: false,
monthLabels: MONTH_LABELS,
weekdayLabels: DAY_LABELS,
Expand Down
22 changes: 22 additions & 0 deletions test/CalendarHeatmap.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ describe('CalendarHeatmap props', () => {
expect(vertical.find('text.react-calendar-heatmap-small-text')).toHaveLength(3);
});

it('showAllWeekdayLabels true', () => {
const calendar = shallow(<CalendarHeatmap
startDate={dateNDaysAgo(7)}
values={[]}
showWeekdayLabels={true}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think folks should have to pass both showWeekdayLabels and showAllWeekdayLabels or should just showAllWeekdayLabels be enough? I like the idea of just passing showAllWeekdayLabels by itself rather than 2 props, I think you have to update this line https://github.com/patientslikeme/react-calendar-heatmap/pull/87/files#diff-73642d587163f2eb4d72f0fa6ebfba02L293 to make a single prop enough

showAllWeekdayLabels={true}
/>);

expect(calendar.find('text').length).toEqual(7);
});

it('showAllWeekdayLabels false', () => {
const calendar = shallow(<CalendarHeatmap
startDate={dateNDaysAgo(7)}
values={[]}
showWeekdayLabels={true}
showAllWeekdayLabels={false}
/>);

expect(calendar.find('text').length).toEqual(3);
});

it('transformDayElement', () => {
const transform = rect => React.cloneElement(rect, { 'data-test': 'ok' });
const today = new Date();
Expand Down