Skip to content

Commit

Permalink
[datetime2] feat: DatePicker3 using react-day-picker v8 (#5935)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Sep 6, 2023
1 parent fde7156 commit bdeff6e
Show file tree
Hide file tree
Showing 38 changed files with 2,415 additions and 31 deletions.
3 changes: 2 additions & 1 deletion packages/datetime/test/common/dateUtilsTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

import { expect } from "chai";

import { assertTimeIs, createTimeObject } from "@blueprintjs/test-commons";

import { DateRange } from "../../src/";
import * as DateUtils from "../../src/common/dateUtils";
import { Months } from "../../src/common/months";
import { assertTimeIs, createTimeObject } from "./dateTestUtils";

describe("DateUtils", () => {
it("isSameTime", () => {
Expand Down
33 changes: 33 additions & 0 deletions packages/datetime/test/common/dayPickerTestUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2016 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** @fileoverview test utils for react-day-picker v7 */

import { assert } from "chai";
import { ReactWrapper } from "enzyme";

import { Classes } from "../../src/common";

const isDayHidden = (day: ReactWrapper<any, any>): boolean =>
day.prop("empty") && !day.prop("ariaSelected") && day.prop("ariaDisabled");

export function assertDayDisabled(day: ReactWrapper<any, any>, expectDisabled: boolean = true) {
assert.equal(day.hasClass(Classes.DATEPICKER_DAY_DISABLED), expectDisabled);
}

export function assertDayHidden(day: ReactWrapper<any, any>, expectHidden: boolean = true) {
assert.equal(isDayHidden(day), expectHidden);
}
3 changes: 2 additions & 1 deletion packages/datetime/test/components/datePickerTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import ReactDayPicker from "react-day-picker";
import sinon from "sinon";

import { Button, Classes as CoreClasses, HTMLSelect, Menu, MenuItem } from "@blueprintjs/core";
import { assertDatesEqual } from "@blueprintjs/test-commons";

import { Classes, DatePicker, DatePickerModifiers, DatePickerProps, TimePicker, TimePrecision } from "../../src";
import { DateUtils, Months } from "../../src/common";
import * as Errors from "../../src/common/errors";
import { DatePickerState } from "../../src/components/date-picker/datePicker";
import { DatePickerShortcut, Shortcuts } from "../../src/components/shortcuts/shortcuts";
import { assertDatesEqual, assertDayDisabled, assertDayHidden } from "../common/dateTestUtils";
import { assertDayDisabled, assertDayHidden } from "../common/dayPickerTestUtils";

describe("<DatePicker>", () => {
it(`renders .${Classes.DATEPICKER}`, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/datetime/test/components/dateRangePickerTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { Months } from "../../src/common/months";
import { DatePickerNavbar } from "../../src/components/date-picker/datePickerNavbar";
import { DateRangePickerState } from "../../src/components/date-range-picker/dateRangePicker";
import { DateRangeShortcut, Shortcuts } from "../../src/components/shortcuts/shortcuts";
import { assertDayDisabled } from "../common/dateTestUtils";
import { assertDayDisabled } from "../common/dayPickerTestUtils";

describe("<DateRangePicker>", () => {
let onChangeSpy: sinon.SinonSpy;
Expand Down
2 changes: 1 addition & 1 deletion packages/datetime/test/components/timePickerTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import * as TestUtils from "react-dom/test-utils";
import sinon from "sinon";

import { Classes as CoreClasses, Intent } from "@blueprintjs/core";
import { assertTimeIs, createTimeObject } from "@blueprintjs/test-commons";

import { Classes, TimePicker, TimePickerProps, TimePrecision } from "../../src";
import { assertTimeIs, createTimeObject } from "../common/dateTestUtils";

describe("<TimePicker>", () => {
let testsContainerElement: Element;
Expand Down
13 changes: 8 additions & 5 deletions packages/datetime2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

Blueprint is a React UI toolkit for the web.

This package contains re-exports of components from @blueprintjs/datetime2. These "V2" components were
previously available in @blueprintjs/datetime2 v4.x, but they were promoted to the standard "V1" components in
@blueprintjs/datetime v5.x.

Once you upgrade to Blueprint v5.0, you should migrate your imports to the @blueprintjs/datetime package.
This package contains re-exports of some components from @blueprintjs/datetime v5.x. These "V2" APIs are backwards-compatible with @blueprintjs/datetime2 v0.x. Once you upgrade to Blueprint v5.0, you should migrate your
imports to reference @blueprintjs/datetime instead:

```diff
- import { DateInput2 } from "@blueprintjs/datetime2";
+ import { DateInput } from "@blueprintjs/datetime";
```

This package also contains next-generation "V3" components which support react-day-picker v8. This means that
installing @blueprintjs/datetime2 will install multiple versions of react-day-picker (v7.x via @blueprintjs/datetime
and v8.x as a direct dependency). Note that these two copies of react-day-picker can happily exist together in a single
JS bundle, and with the help of tree-shaking, you can avoid bundling both if you _only_ use the deprecated "V1" / "V2"
datetime components or _only_ use the new "V3" APIs.

### [Full Documentation](http://blueprintjs.com/docs) | [Source Code](https://github.com/palantir/blueprint)
3 changes: 3 additions & 0 deletions packages/datetime2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
"dependencies": {
"@blueprintjs/core": "^5.3.0",
"@blueprintjs/datetime": "^5.0.10",
"@blueprintjs/icons": "^5.1.6",
"classnames": "^2.3.1",
"date-fns": "^2.28.0",
"react-day-picker": "^8.5.1",
"tslib": "~2.5.0"
},
"peerDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/datetime2/src/blueprint-datetime2.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2022 Palantir Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0.

// This file intentionaly left blank
@import "common/react-day-picker-overrides";
@import "components/date-picker3/date-picker3";
35 changes: 35 additions & 0 deletions packages/datetime2/src/classes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Classes as DatetimeClasses } from "@blueprintjs/datetime";

const RDP_DAY = "rdp-day";
const DATEPICKER_NAV_BUTTON = `${DatetimeClasses.DATEPICKER}-nav-button`;

export const Classes = {
...DatetimeClasses,
// these classes need the "3" suffix because they overlap with DatePicker v1 / react-day-picker v7 classes
DATEPICKER3_DAY: RDP_DAY,
DATEPICKER3_DAY_DISABLED: `${RDP_DAY}_disabled`,
DATEPICKER3_DAY_IS_TODAY: `${RDP_DAY}_today`,
DATEPICKER3_DAY_OUTSIDE: `${RDP_DAY}_outside`,
DATEPICKER3_DAY_SELECTED: `${RDP_DAY}_selected`,
// these classes intentionally left without "3" suffix because they do not overlap with DatePicker v1, and this way we don't need to migrate them later, which reduces code churn
DATEPICKER_HIGHLIGHT_CURRENT_DAY: `${DatetimeClasses.DATEPICKER}-highlight-current-day`,
DATEPICKER_NAV_BUTTON,
DATEPICKER_NAV_BUTTON_NEXT: `${DATEPICKER_NAV_BUTTON}-next`,
DATEPICKER_NAV_BUTTON_PREVIOUS: `${DATEPICKER_NAV_BUTTON}-previous`,
};
26 changes: 26 additions & 0 deletions packages/datetime2/src/common/_react-day-picker-overrides.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2023 Palantir Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0.

@import "@blueprintjs/colors/lib/scss/colors";
@import "@blueprintjs/core/src/common/variables";

// omit file extension, otherwise this will emit a `@import url()` rule
@import "react-day-picker/dist/style";

.#{$ns}-datepicker-content .rdp {
--rdp-cell-size: #{$pt-grid-size * 3};
--rdp-accent-color: #{$blue3};
--rdp-background-color: #{$white};

/* Switch to dark colors for dark themes */
--rdp-accent-color-dark: #{$blue2};
--rdp-background-color-dark: #{$dark-gray3};

/* Outline border for focused elements */
--rdp-outline: 2px solid var(--rdp-accent-color);

/* Outline border for focused and selected elements */
--rdp-outline-selected: 2px solid rgba(0, 0, 0, 75%);

margin: 0;
}
Loading

1 comment on commit bdeff6e

@adidahiya
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[datetime2] feat: DatePicker3 using react-day-picker v8 (#5935)

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.