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

[Datepicker] Bumped react-day-picker to v9. #3525

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
20a4bcb
:memo: Bumped date-fns to v4
KenAJoh Jan 23, 2025
3399c08
TEMP UPDATES
KenAJoh Jan 23, 2025
1bcaadb
TEMP CSS UPDATES
KenAJoh Jan 23, 2025
0b96047
:sparkles: New Caption component for datepicker
KenAJoh Jan 23, 2025
1ab2ff9
:recycle: Extract util
KenAJoh Jan 24, 2025
3a5a1cb
:recycle: Refactor standalone datepicker
KenAJoh Jan 24, 2025
421bc68
:recycle: Refactor dialog datepicker
KenAJoh Jan 24, 2025
cea218b
:recycle: Migrated weekday-click
KenAJoh Jan 24, 2025
7313da8
:recycle: Migrated mobile-view week-click
KenAJoh Jan 24, 2025
897fb11
:coffin: Removed old code
KenAJoh Jan 24, 2025
e27550e
:truck: Re-strucutre project
KenAJoh Jan 24, 2025
a391d34
:bug: Fix imports
KenAJoh Jan 24, 2025
bec0ab6
:recycle: New MonthPicker context
KenAJoh Jan 25, 2025
b7d6866
:recycle: Replace use to MonthPickerContext
KenAJoh Jan 25, 2025
1b9ee3a
:recycle: Migrated standalone monthpicker
KenAJoh Jan 25, 2025
9cb13a3
:recycle: Remove react-day-picker connection for utils
KenAJoh Jan 25, 2025
9b33b6c
:truck: Re-structure MonthPicker
KenAJoh Jan 25, 2025
971c0c2
:memo: rename context
KenAJoh Jan 25, 2025
4c07cac
:truck: Re-structure DatePicker
KenAJoh Jan 25, 2025
17f6d4d
:bug: Fix imports and nb
KenAJoh Jan 25, 2025
f0a0973
:recycle: Parts restructure
KenAJoh Jan 25, 2025
318decf
:truck: Move inputcontext
KenAJoh Jan 25, 2025
044dcfb
:truck: Co-locate date-spesific context
KenAJoh Jan 25, 2025
094b465
:truck: Co-locate date-hooks
KenAJoh Jan 25, 2025
00b06d7
:bug: Update missing import-updates
KenAJoh Jan 25, 2025
a5dc45e
:bug: Use new input-context in modal, popover
KenAJoh Jan 25, 2025
f5ced13
:truck: Moved new utils into date-utils
KenAJoh Jan 25, 2025
7fce62c
:recycle: simplified calendar-range logic
KenAJoh Jan 25, 2025
ca26f54
:bug: Fix test-runs
KenAJoh Jan 25, 2025
043fd9a
:test_tube: Storybook tests for monthpicker
KenAJoh Jan 25, 2025
5a6c97d
:test_tube: Storybook tests for monthpicker
KenAJoh Jan 25, 2025
43287e6
:lipstick: Lock datepicker dialog to top of screen
KenAJoh Jan 25, 2025
703da27
:bug: Don't re-open modal
KenAJoh Jan 25, 2025
c7e4fcd
:bug: Avoid double open-toggle
KenAJoh Jan 25, 2025
9730697
:test_tube: Storybook tests for DatePicker
KenAJoh Jan 25, 2025
c3e07bd
:recycle: Use local dateRange-handler
KenAJoh Jan 25, 2025
4e3be53
:bug: month-update caused custom-components to re-render
KenAJoh Jan 25, 2025
6e65228
:bug: casings
KenAJoh Jan 25, 2025
efd03b1
:bug: casings 2
KenAJoh Jan 25, 2025
ff26d14
:bug: casings 3
KenAJoh Jan 25, 2025
4c105ca
:bug: casings 4
KenAJoh Jan 25, 2025
324bf5f
:test_tube: Added tests for legacy dom-structure
KenAJoh Jan 25, 2025
5f9f994
:bug: Resolved re-render causing tests to fail
KenAJoh Jan 26, 2025
dc4fcbd
:test_tube: More datepicker tests, daypicker now requires us to handl…
KenAJoh Jan 26, 2025
42affdf
:memo: Changeset
KenAJoh Jan 26, 2025
07c7b5f
Update @navikt/core/react/src/date/datepicker/parts/DatePicker.RDP.tsx
KenAJoh Jan 27, 2025
7464f21
:bug: Added weekend-className for backwards compat support
KenAJoh Jan 27, 2025
a5c33f5
Merge branch 'main' into react-datepicker-19
KenAJoh Jan 31, 2025
d9aecbd
Merge branch 'main' into react-datepicker-19
KenAJoh Feb 7, 2025
50458a3
:memo: yarn lock sync
KenAJoh Feb 7, 2025
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
5 changes: 5 additions & 0 deletions .changeset/neat-pumas-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": minor
---

DatePicker: Refactored locally to support `react-day-picker v9`. No external API has been changed.
5 changes: 5 additions & 0 deletions .changeset/neat-pumas-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": minor
---

MonthPicker: Refactored locally and no longer depends on `react-day-picker v9`. No external API has been changed.
5 changes: 5 additions & 0 deletions .changeset/neat-pumas-5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-css": minor
---

DatePicker: Updated `date.css` to support `react-day-picker v9`.
5 changes: 5 additions & 0 deletions .changeset/neat-pumas-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": minor
---

Dependencies: `react-day-picker` bumped to `v9.5.0`.
5 changes: 5 additions & 0 deletions .changeset/neat-pumas-tros.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": minor
---

Dependencies: `date-fns` bumped to `^4.0.0`.
32 changes: 11 additions & 21 deletions @navikt/core/css/date.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,13 @@
font-size: var(--a-font-size-small);
}

.navds-date .rdp-weeknumber {
font-size: var(--a-font-size-small);
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
border-radius: var(--a-border-radius-medium);
margin: var(--a-spacing-2);
color: var(--a-text-subtle);
}

.navds-date .rdp-weeknumber.rdp-button {
width: 2rem;
height: 2rem;
box-shadow: 0 0 0 1px var(--a-border-default);
.navds-date__weeknumber-number {
font-size: 0.875rem;
color: var(--a-text-subtle);
font-size: var(--a-font-size-small);
}

.navds-date .rdp-weeknumber.rdp-button:active {
background-color: var(--a-surface-action-active);
color: var(--a-text-on-action);
box-shadow: none;
.navds-date__weeknumber:active .navds-date__weeknumber-number {
color: var(--a-text-on-neutral);
}

.navds-date__caption__month .navds-select__container select {
Expand Down Expand Up @@ -303,6 +286,13 @@
margin: 0;
}

span.rdp-weeknumber {
display: grid;
place-content: center;
width: 2rem;
height: 2rem;
}

.navds-date__modal.navds-date {
padding: 0;
}
Expand Down
4 changes: 2 additions & 2 deletions @navikt/core/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@
"@navikt/aksel-icons": "^7.12.2",
"@navikt/ds-tokens": "^7.12.2",
"clsx": "^2.1.0",
"date-fns": "^3.0.0",
"react-day-picker": "8.10.1"
"date-fns": "^4.0.0",
"react-day-picker": "9.5.0"
},
"devDependencies": {
"@testing-library/dom": "10.4.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import cl from "clsx";
import React, { useRef } from "react";
import { Button } from "../../button";
import { Modal } from "../../modal";
import { useModalContext } from "../../modal/Modal.context";
import { Popover } from "../../popover";
import { useMedia } from "../../util/hooks";
import { useI18n } from "../../util/i18n/i18n.hooks";
import { TFunction } from "../../util/i18n/i18n.types";
import { getGlobalTranslations } from "../utils";
import { Button } from "../button";
import { Modal } from "../modal";
import { useModalContext } from "../modal/Modal.context";
import { Popover } from "../popover";
import { useMedia } from "../util/hooks";
import { useI18n } from "../util/i18n/i18n.hooks";
import { TFunction } from "../util/i18n/i18n.types";
import { getGlobalTranslations } from "./Date.locale";

const variantToLabel = {
single: "chooseDate",
Expand All @@ -31,7 +31,7 @@ type DateWrapperProps = {
};
};

export const DateWrapper = ({
const DateDialog = ({
open,
children,
onClose,
Expand Down Expand Up @@ -66,6 +66,7 @@ export const DateWrapper = ({
</Popover>
);
}

return (
<Modal
ref={modalRef}
Expand All @@ -80,6 +81,7 @@ export const DateWrapper = ({
"navds-date": variant === "month",
})}
closeOnBackdropClick
placement="top"
>
<div className="navds-date__modal-body">
{children}
Expand All @@ -95,3 +97,4 @@ export const DateWrapper = ({
</Modal>
);
};
export { DateDialog };
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import cl from "clsx";
import React, { InputHTMLAttributes, forwardRef, useRef } from "react";
import { CalendarIcon } from "@navikt/aksel-icons";
import { ReadOnlyIcon } from "../../form/ReadOnlyIcon";
import { FormFieldProps, useFormField } from "../../form/useFormField";
import { BodyShort, ErrorMessage, Label } from "../../typography";
import { omit } from "../../util";
import { useDateInputContext, useDateTranslationContext } from "../context";
import { ReadOnlyIcon } from "../form/ReadOnlyIcon";
import { FormFieldProps, useFormField } from "../form/useFormField";
import { BodyShort, ErrorMessage, Label } from "../typography";
import { omit } from "../util";
import { createContext } from "../util/create-context";
import { useDateTranslationContext } from "./Date.locale";

interface DateInputContextProps {
/**
* Open state for popover
*/
open: boolean;
/**
* Callback for onOpen toggle
*/
onOpen: () => void;
/**
* Aria-connected ID
*/
ariaId?: string;
/**
* Flag for enabled-check
*/
defined: boolean;
}

export const [DateInputContextProvider, useDateInputContext] =
createContext<DateInputContextProps>({
errorMessage: "useDateInputContext must be used with DateInputContext",
});

export interface DateInputProps
extends FormFieldProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { enGB, nb, nn } from "date-fns/locale";
import en_translations from "../../util/i18n/locales/en";
import nn_translations from "../../util/i18n/locales/nn";
import { createContext } from "../util/create-context";
import { TFunction } from "../util/i18n/i18n.types";
import en_translations from "../util/i18n/locales/en";
import nn_translations from "../util/i18n/locales/nn";

/** @private */
export const getLocaleFromString = (locale: "nb" | "nn" | "en" = "nb") => {
Expand Down Expand Up @@ -45,3 +47,10 @@ export const getGlobalTranslations = (locale: string | undefined) => {
return undefined;
}
};

interface DateTranslationContextProps {
translate: TFunction<"DatePicker">;
}

export const [DateTranslationContextProvider, useDateTranslationContext] =
createContext<DateTranslationContextProps>();
32 changes: 32 additions & 0 deletions @navikt/core/react/src/date/Date.typeutils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export type DateRange = {
from: Date | undefined;
to?: Date | undefined;
};

export type DateBefore = {
before: Date;
};

export type DateAfter = {
after: Date;
};

export function isDateAfterType(value: unknown): value is DateAfter {
return Boolean(value && typeof value === "object" && "after" in value);
}

export function isDateBeforeType(value: unknown): value is DateBefore {
return Boolean(value && typeof value === "object" && "before" in value);
}

export function isDateRange(value: unknown): value is DateRange {
return Boolean(value && typeof value === "object" && "from" in value);
}

export type Matcher =
| ((date: Date) => boolean)
| Date
| Date[]
| DateRange
| DateBefore
| DateAfter;
9 changes: 0 additions & 9 deletions @navikt/core/react/src/date/context/index.ts

This file was deleted.

34 changes: 0 additions & 34 deletions @navikt/core/react/src/date/context/useDateInputContext.tsx

This file was deleted.

This file was deleted.

68 changes: 0 additions & 68 deletions @navikt/core/react/src/date/context/useSharedMonthContext.tsx

This file was deleted.

Loading
Loading