Skip to content

Commit b21bf47

Browse files
authored
Feature/week day class name (#2113)
* Add week day class name feature * Extend docs for week day class name feature * Add test to week day class name feature
1 parent 279f9ff commit b21bf47

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

docs/datepicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ General datepicker component.
1717
| `dateFormat` | `union(string\|array)` | `'MM/dd/yyyy'` | |
1818
| `dateFormatCalendar` | `string` | `'LLLL yyyy'` | |
1919
| `dayClassName` | `func` | | |
20+
| `weekDayClassName` | `func` | | |
2021
| `disabled` | `bool` | `false` | |
2122
| `disabledKeyboardNavigation` | `bool` | `false` | |
2223
| `dropdownMode` (required) | `enum('scroll'\|'select')` | `'scroll'` | |

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| `dateFormat` | `union(string\|array)` | `"MM/dd/yyyy"` | |
2121
| `dateFormatCalendar` | `string` | `"LLLL yyyy"` | |
2222
| `dayClassName` | `func` | | |
23+
| `weekDayClassName` | `func` | | |
2324
| `disabled` | `bool` | `false` | |
2425
| `disabledDayAriaLabelPrefix` | `string` | | |
2526
| `disabledKeyboardNavigation` | `bool` | `false` | |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "HackerOne",
33
"name": "react-datepicker",
44
"description": "A simple and reusable datepicker component for React",
5-
"version": "2.14.1",
5+
"version": "2.14.2-SNAPSHOT",
66
"license": "MIT",
77
"homepage": "https://github.com/Hacker0x01/react-datepicker",
88
"main": "dist/index.js",

src/calendar.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default class Calendar extends React.Component {
7575
dateFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
7676
.isRequired,
7777
dayClassName: PropTypes.func,
78+
weekDayClassName: PropTypes.func,
7879
disabledDayAriaLabelPrefix: PropTypes.string,
7980
monthClassName: PropTypes.func,
8081
timeClassName: PropTypes.func,
@@ -336,8 +337,19 @@ export default class Calendar extends React.Component {
336337
[0, 1, 2, 3, 4, 5, 6].map(offset => {
337338
const day = addDays(startOfWeek, offset);
338339
const weekDayName = this.formatWeekday(day, this.props.locale);
340+
341+
const weekDayClassName = this.props.weekDayClassName
342+
? this.props.weekDayClassName(day)
343+
: undefined;
344+
339345
return (
340-
<div key={offset} className="react-datepicker__day-name">
346+
<div
347+
key={offset}
348+
className={classnames(
349+
"react-datepicker__day-name",
350+
weekDayClassName
351+
)}
352+
>
341353
{weekDayName}
342354
</div>
343355
);

src/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export default class DatePicker extends React.Component {
129129
dateFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
130130
dateFormatCalendar: PropTypes.string,
131131
dayClassName: PropTypes.func,
132+
weekDayClassName: PropTypes.func,
132133
disabledDayAriaLabelPrefix: PropTypes.string,
133134
monthClassName: PropTypes.func,
134135
timeClassName: PropTypes.func,
@@ -768,6 +769,7 @@ export default class DatePicker extends React.Component {
768769
onMonthChange={this.props.onMonthChange}
769770
onYearChange={this.props.onYearChange}
770771
dayClassName={this.props.dayClassName}
772+
weekDayClassName={this.props.weekDayClassName}
771773
monthClassName={this.props.monthClassName}
772774
timeClassName={this.props.timeClassName}
773775
showTimeSelect={this.props.showTimeSelect}

test/calendar_test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import sinon from "sinon";
1313
import * as utils from "../src/date_utils";
1414
import eo from "date-fns/locale/eo";
1515
import fi from "date-fns/locale/fi";
16+
import { isSunday } from "date-fns";
1617

1718
// TODO Possibly rename
1819
const DATE_FORMAT = "MM/dd/yyyy";
@@ -166,6 +167,23 @@ describe("Calendar", function() {
166167
.forEach(dayName => expect(dayName.text()).to.have.length(1));
167168
});
168169

170+
it("should contain the correct class when using the weekDayClassName prop", () => {
171+
const func = date => (isSunday(date) ? "sunday" : undefined);
172+
173+
const calendar = mount(
174+
<Calendar
175+
dateFormat={dateFormat}
176+
dropdownMode="scroll"
177+
onClickOutside={() => {}}
178+
onSelect={() => {}}
179+
weekDayClassName={func}
180+
/>
181+
);
182+
183+
const sunday = calendar.find(".react-datepicker__day-name.sunday");
184+
expect(sunday).to.have.length(1);
185+
});
186+
169187
it("should render the months correctly adjusted by monthSelectedIn", () => {
170188
const selected = utils.newDate("2018-11-19");
171189
const calendar = getCalendar({ inline: true, monthsShown: 2, selected });

0 commit comments

Comments
 (0)