Skip to content

Feature/week day class name #2113

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

Merged
merged 3 commits into from
Apr 16, 2020
Merged
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
1 change: 1 addition & 0 deletions docs/datepicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ General datepicker component.
| `dateFormat` | `union(string\|array)` | `'MM/dd/yyyy'` | |
| `dateFormatCalendar` | `string` | `'LLLL yyyy'` | |
| `dayClassName` | `func` | | |
| `weekDayClassName` | `func` | | |
| `disabled` | `bool` | `false` | |
| `disabledKeyboardNavigation` | `bool` | `false` | |
| `dropdownMode` (required) | `enum('scroll'\|'select')` | `'scroll'` | |
Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
| `dateFormat` | `union(string\|array)` | `"MM/dd/yyyy"` | |
| `dateFormatCalendar` | `string` | `"LLLL yyyy"` | |
| `dayClassName` | `func` | | |
| `weekDayClassName` | `func` | | |
| `disabled` | `bool` | `false` | |
| `disabledDayAriaLabelPrefix` | `string` | | |
| `disabledKeyboardNavigation` | `bool` | `false` | |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "HackerOne",
"name": "react-datepicker",
"description": "A simple and reusable datepicker component for React",
"version": "2.14.1",
"version": "2.14.2-SNAPSHOT",
"license": "MIT",
"homepage": "https://github.com/Hacker0x01/react-datepicker",
"main": "dist/index.js",
Expand Down
14 changes: 13 additions & 1 deletion src/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class Calendar extends React.Component {
dateFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
.isRequired,
dayClassName: PropTypes.func,
weekDayClassName: PropTypes.func,
disabledDayAriaLabelPrefix: PropTypes.string,
monthClassName: PropTypes.func,
timeClassName: PropTypes.func,
Expand Down Expand Up @@ -336,8 +337,19 @@ export default class Calendar extends React.Component {
[0, 1, 2, 3, 4, 5, 6].map(offset => {
const day = addDays(startOfWeek, offset);
const weekDayName = this.formatWeekday(day, this.props.locale);

const weekDayClassName = this.props.weekDayClassName
? this.props.weekDayClassName(day)
: undefined;

return (
<div key={offset} className="react-datepicker__day-name">
<div
key={offset}
className={classnames(
"react-datepicker__day-name",
weekDayClassName
)}
>
{weekDayName}
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default class DatePicker extends React.Component {
dateFormat: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
dateFormatCalendar: PropTypes.string,
dayClassName: PropTypes.func,
weekDayClassName: PropTypes.func,
disabledDayAriaLabelPrefix: PropTypes.string,
monthClassName: PropTypes.func,
timeClassName: PropTypes.func,
Expand Down Expand Up @@ -768,6 +769,7 @@ export default class DatePicker extends React.Component {
onMonthChange={this.props.onMonthChange}
onYearChange={this.props.onYearChange}
dayClassName={this.props.dayClassName}
weekDayClassName={this.props.weekDayClassName}
monthClassName={this.props.monthClassName}
timeClassName={this.props.timeClassName}
showTimeSelect={this.props.showTimeSelect}
Expand Down
18 changes: 18 additions & 0 deletions test/calendar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import sinon from "sinon";
import * as utils from "../src/date_utils";
import eo from "date-fns/locale/eo";
import fi from "date-fns/locale/fi";
import { isSunday } from "date-fns";

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

it("should contain the correct class when using the weekDayClassName prop", () => {
const func = date => (isSunday(date) ? "sunday" : undefined);

const calendar = mount(
<Calendar
dateFormat={dateFormat}
dropdownMode="scroll"
onClickOutside={() => {}}
onSelect={() => {}}
weekDayClassName={func}
/>
);

const sunday = calendar.find(".react-datepicker__day-name.sunday");
expect(sunday).to.have.length(1);
});

it("should render the months correctly adjusted by monthSelectedIn", () => {
const selected = utils.newDate("2018-11-19");
const calendar = getCalendar({ inline: true, monthsShown: 2, selected });
Expand Down