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/Modal] Datepicker bruker nå Modal på mobil og for nested Modal #2419

Merged
merged 51 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5014cc3
:art: Initial Modal-update
KenAJoh Oct 24, 2023
72da207
:bug: close(open handling for Modal
KenAJoh Oct 24, 2023
578ecf2
:fire: Fjernet openOnFocus
KenAJoh Oct 25, 2023
223f07d
:fire: Fjernet outsideclick og useEscape
KenAJoh Oct 25, 2023
4141ece
:bug: monthpicker onClose forwarding
KenAJoh Oct 25, 2023
0278f39
:art: Flyttet DateInput til egen parts-mappe
KenAJoh Oct 25, 2023
e98b38d
:label: DateInput imports
KenAJoh Oct 25, 2023
4bd08ee
:truck: Flyttet DateWrapper ut til egen komponent
KenAJoh Oct 25, 2023
353461b
:art: Monthpicker bruker dateWrapper
KenAJoh Oct 25, 2023
b553b44
:lipstick: Oppdatert styling for datepicker
KenAJoh Oct 25, 2023
1656f79
:memo: Oppdatert eksempler
KenAJoh Oct 25, 2023
d8fa01c
:memo: changeset
KenAJoh Oct 25, 2023
81f0c5d
:bug: Fikset imports i date-hooks
KenAJoh Oct 25, 2023
44db5d9
:recycle: Bedre context-bruk i Modal.tsx
KenAJoh Oct 25, 2023
0ea8986
:memo: Bedre tekster for deprecation
KenAJoh Oct 25, 2023
60ab3cd
:bug: Støtter nå jsdom
KenAJoh Oct 25, 2023
c06338f
Merge branch 'main' into dynamic-datepicker-modal
KenAJoh Oct 25, 2023
b018b93
Merge branch 'main' into dynamic-datepicker-modal
KenAJoh Oct 25, 2023
8d504c2
Merge branch 'main' into dynamic-datepicker-modal
KenAJoh Oct 27, 2023
1712cb9
Merge branch 'main' into dynamic-datepicker-modal
KenAJoh Oct 27, 2023
cebb89c
:bug: Fikset polyfill av datepicker
KenAJoh Oct 27, 2023
9ce9734
:art: closeOnBackdropClick i datepicker
KenAJoh Oct 27, 2023
663e3bf
Merge branch 'main' into dynamic-datepicker-modal
KenAJoh Oct 30, 2023
c4cd8f6
:label: :bug: Fikset outsideClick boundary + fjernet bubbleEscape-prop
KenAJoh Oct 30, 2023
571684f
:fire: Fjernet console.log
KenAJoh Oct 30, 2023
657203e
:fire: Fjernet bubbleEscape-prop
KenAJoh Oct 30, 2023
d428e3f
Update @navikt/core/react/src/date/hooks/useMonthPicker.tsx
KenAJoh Oct 31, 2023
dbebe21
Update @navikt/core/react/src/date/datepicker/datepicker.stories.tsx
KenAJoh Oct 31, 2023
0d26ce9
:art: Bedre className for nested modal
KenAJoh Oct 31, 2023
5c84125
:bug: Bedre check om popover er i datepicker
KenAJoh Oct 31, 2023
4fceddb
:fire: Fjernet unødvendig if rundt window-check
KenAJoh Oct 31, 2023
6799d65
:art: Bedre fallback for useMedia-hook
KenAJoh Oct 31, 2023
38a80ca
:art: bedre navn i useMedia
KenAJoh Oct 31, 2023
2447c16
:memo: Datepicker-stories for size har preset-values
KenAJoh Oct 31, 2023
7f4eda5
Update @navikt/core/react/src/date/hooks/useDatepicker.tsx
KenAJoh Oct 31, 2023
199791d
Merge branch 'main' into dynamic-datepicker-modal
KenAJoh Oct 31, 2023
b87503c
:art: DateContext er nå default null hvis ikke satt
KenAJoh Oct 31, 2023
95699f0
Update @navikt/core/react/src/date/parts/DateWrapper.tsx
KenAJoh Nov 1, 2023
0c6fbd0
Update @navikt/core/react/src/date/parts/DateWrapper.tsx
KenAJoh Nov 1, 2023
451a92d
Update @navikt/core/react/src/date/parts/DateWrapper.tsx
KenAJoh Nov 1, 2023
38c59f4
Update @navikt/core/react/src/date/utils/labels.ts
KenAJoh Nov 1, 2023
bef8939
:bug: Fikset small-size padding
KenAJoh Nov 1, 2023
f3ec0c2
:fire: Fjernet error-demo
KenAJoh Nov 1, 2023
e8ac8f7
fokusgreier
HalvorHaugan Nov 1, 2023
d55e555
:art: bedre onClose-handling av modal
KenAJoh Nov 1, 2023
d253ab9
:bug: Håndterer focus ved cancel og select nå
KenAJoh Nov 1, 2023
698a6de
:bug: Feil i typer for dateinput
KenAJoh Nov 1, 2023
82ee5e8
:bug: setAnchorRef var optional
KenAJoh Nov 1, 2023
ac70910
:bug: null-test
KenAJoh Nov 1, 2023
436a638
:art: Fjernet jsdom sjekk tester for useMedia
KenAJoh Nov 1, 2023
20d8032
Merge branch 'main' into dynamic-datepicker-modal
KenAJoh Nov 1, 2023
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
6 changes: 6 additions & 0 deletions .changeset/yellow-buckets-grab-copy-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-react": minor
"@navikt/ds-css": minor
---

Datepicker/Monthpicker: Hvis man bruker komponentene i Modal vil Popover bli erstattet med Modal uansett om man er på desktop eller mobil.
6 changes: 6 additions & 0 deletions .changeset/yellow-buckets-grab-copy-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-react": minor
"@navikt/ds-css": minor
---

Datepicker/Monthpicker/Popover: Fjernet `bubbleEscape`-prop.
6 changes: 6 additions & 0 deletions .changeset/yellow-buckets-grab-copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-react": minor
"@navikt/ds-css": minor
---

useDatepicker/useMonthPicker/useRangedpicker: Fjernet `openOnFocus`-prop, kan nå bare åpnes ved klikk på date-knapp i input.
6 changes: 6 additions & 0 deletions .changeset/yellow-buckets-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-react": minor
"@navikt/ds-css": minor
---

Datepicker/Monthpicker: Bytter nå automatisk til Modalvisning på mobil.
38 changes: 21 additions & 17 deletions @navikt/core/css/date.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,6 @@
width: fit-content;
}

/* Focus layering */
.navds-date__field-input:focus-visible,
.navds-date__field-button {
z-index: 1;
}

@supports not selector(:focus-visible) {
.navds-date__field-input:focus {
z-index: 1;
}
}

.navds-date .rdp-day_selected,
.navds-monthpicker__month--selected {
color: var(--ac-date-selected-text, var(--a-text-on-action));
Expand Down Expand Up @@ -201,7 +189,7 @@
}

.navds-date__field-input {
padding-right: var(--a-spacing-14);
padding-right: var(--a-spacing-12);
}

.navds-form-field--small .navds-date__field-input {
Expand Down Expand Up @@ -282,10 +270,6 @@
pointer-events: none;
}

.navds-date__popover:where(.navds-popover) {
border: none;
}

/* Readonly */
.navds-date__field--readonly .navds-date__field-button {
cursor: default;
Expand All @@ -310,11 +294,31 @@
margin: 0;
}

.navds-date__modal {
display: flex;
flex-direction: column;
align-items: flex-end;
padding: var(--a-spacing-4);
gap: var(--a-spacing-2);
}

.navds-date__modal > .navds-date {
padding: 0;
}

.navds-date__popover:where(.navds-popover) {
border: none;
}

@media (min-width: 480px) {
.navds-date {
padding: var(--a-spacing-5) var(--a-spacing-4);
}

.navds-date__modal {
padding: var(--a-spacing-6);
}

.navds-date__caption {
gap: var(--a-spacing-2);
}
Expand Down
8 changes: 8 additions & 0 deletions @navikt/core/css/modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@
margin-left: auto;
}

/* When Datepicker is used nested inside a Modal */
.navds-modal--polyfilled .navds-modal--polyfilled.navds-date--polyfilled-nested {
min-width: fit-content;
max-width: 100vw;
max-height: 100vh;
animation: none;
}

@keyframes akselModalFadeIn {
from {
opacity: 0;
Expand Down
122 changes: 57 additions & 65 deletions @navikt/core/react/src/date/datepicker/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import cl from "clsx";
import isWeekend from "date-fns/isWeekend";
import React, { forwardRef, useRef, useState } from "react";
import React, { forwardRef, useMemo, useRef, useState } from "react";
import { DateRange, DayPicker, isMatch } from "react-day-picker";
import { Popover } from "../../popover";
import { omit, useId } from "../../util";
import { DatePickerInput } from "../DateInput";
import { mergeRefs, omit, useId } from "../../util";
import { DateContext } from "../context";
import { DatePickerInput } from "../parts/DateInput";
import { DateWrapper } from "../parts/DateWrapper";
import { getLocaleFromString, labels } from "../utils";
import DatePickerStandalone from "./DatePickerStandalone";
import Caption from "./parts/Caption";
Expand Down Expand Up @@ -79,7 +79,6 @@ export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
onClose,
onOpenToggle,
strategy,
bubbleEscape = false,
onWeekNumberClick,
...rest
},
Expand All @@ -89,6 +88,7 @@ export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
const [open, setOpen] = useState(_open ?? false);

const wrapperRef = useRef<HTMLDivElement | null>(null);
const mergedRef = useMemo(() => mergeRefs([wrapperRef, ref]), [ref]);
KenAJoh marked this conversation as resolved.
Show resolved Hide resolved

const [selectedDates, setSelectedDates] = React.useState<
Date | Date[] | DateRange | undefined
Expand All @@ -110,6 +110,44 @@ export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
rest?.onSelect?.(newSelected);
};

const DatePickerComponent = (
<DayPicker
locale={getLocaleFromString(locale)}
mode={mode}
onSelect={handleSelect}
selected={selected ?? selectedDates}
components={{
Caption: dropdownCaption ? DropdownCaption : Caption,
Head: TableHead,
HeadRow,
WeekNumber,
Row,
Day: DayButton,
}}
className={cl("navds-date", className)}
classNames={{
vhidden: "navds-sr-only",
}}
disabled={(day) => {
return (disableWeekends && isWeekend(day)) || isMatch(day, disabled);
}}
weekStartsOn={1}
initialFocus={false}
labels={labels as any}
modifiers={{
weekend: (day) => disableWeekends && isWeekend(day),
}}
modifiersClassNames={{
weekend: "rdp-day__weekend",
}}
showWeekNumber={showWeekNumber}
onWeekNumberClick={mode === "multiple" ? onWeekNumberClick : undefined}
fixedWeeks
showOutsideDays
{...omit(rest, ["onSelect"])}
/>
);

return (
<DateContext.Provider
value={{
Expand All @@ -122,69 +160,23 @@ export const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>(
}}
>
<div
ref={wrapperRef}
ref={mergedRef}
className={cl("navds-date__wrapper", wrapperClassName)}
>
{children}
{(_open ?? open) && (
<Popover
arrow={false}
anchorEl={wrapperRef.current}
open={_open ?? open}
onClose={() => {
onClose?.() ?? setOpen(false);
}}
placement="bottom-start"
id={ariaId}
role="dialog"
ref={ref}
strategy={strategy}
className="navds-date__popover"
bubbleEscape={bubbleEscape}
flip={false}
>
<DayPicker
locale={getLocaleFromString(locale)}
mode={mode}
onSelect={handleSelect}
selected={selected ?? selectedDates}
components={{
Caption: dropdownCaption ? DropdownCaption : Caption,
Head: TableHead,
HeadRow,
WeekNumber,
Row,
Day: DayButton,
}}
className={cl("navds-date", className)}
classNames={{
vhidden: "navds-sr-only",
}}
disabled={(day) => {
return (
(disableWeekends && isWeekend(day)) ||
isMatch(day, disabled)
);
}}
weekStartsOn={1}
initialFocus={false}
labels={labels as any}
modifiers={{
weekend: (day) => disableWeekends && isWeekend(day),
}}
modifiersClassNames={{
weekend: "rdp-day__weekend",
}}
showWeekNumber={showWeekNumber}
onWeekNumberClick={
mode === "multiple" ? onWeekNumberClick : undefined
}
fixedWeeks
showOutsideDays
{...omit(rest, ["onSelect"])}
/>
</Popover>
)}
<DateWrapper
open={_open ?? open}
anchor={wrapperRef.current}
onClose={() => onClose?.() ?? setOpen(false)}
locale={locale}
variant={mode}
popoverProps={{
id: ariaId,
strategy,
}}
>
{DatePickerComponent}
</DateWrapper>
</div>
</DateContext.Provider>
);
Expand Down
59 changes: 16 additions & 43 deletions @navikt/core/react/src/date/datepicker/datepicker.stories.tsx
KenAJoh marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Meta, StoryObj } from "@storybook/react";
import isSameDay from "date-fns/isSameDay";
import React, { useId, useState } from "react";
import { useDatepicker, useRangeDatepicker } from "..";
import { BodyLong, Button, HGrid, HStack, Modal, VStack } from "../..";
import { BodyLong, Button, HGrid, Modal, VStack } from "../..";
import DatePicker, { DatePickerProps } from "./DatePicker";

const disabledDays = [
Expand All @@ -18,7 +18,6 @@ export default {

type DefaultStoryProps = DatePickerProps & {
size: "medium" | "small";
openOnFocus: boolean;
inputfield: boolean;
standalone: boolean;
};
Expand All @@ -30,13 +29,11 @@ export const Default: StoryObj<DefaultStoryProps> = {
const rangeCtx = useRangeDatepicker({
fromDate: new Date("Aug 23 2020"),
toDate: new Date("Aug 23 2023"),
openOnFocus: props.openOnFocus,
});

const singleCtx = useDatepicker({
fromDate: new Date("Aug 23 2020"),
toDate: new Date("Aug 23 2023"),
openOnFocus: props.openOnFocus,
});

const newProps = {
Expand Down Expand Up @@ -111,7 +108,6 @@ export const Default: StoryObj<DefaultStoryProps> = {
disableWeekends: false,
showWeekNumber: false,
mode: "single",
openOnFocus: true,
inputfield: true,
standalone: false,
},
Expand Down Expand Up @@ -186,21 +182,6 @@ export const UseRangedDatepicker = () => {
);
};

export const OpenOnFocus = () => {
const { datepickerProps, inputProps } = useDatepicker({
onDateChange: console.log,
openOnFocus: false,
});

return (
<div style={{ display: "flex", gap: "1rem" }}>
<DatePicker {...datepickerProps}>
<DatePicker.Input {...inputProps} label="Velg dato" />
</DatePicker>
</div>
);
};

export const NB = () => (
<DatePicker.Standalone locale="nb" today={new Date("2006-07-01")} />
);
Expand Down Expand Up @@ -441,33 +422,25 @@ export const ModalDemo = () => {
});

return (
<Modal open header={{ heading: "Modal-demo" }} width="1024px">
<Modal open header={{ heading: "Modal-demo" }}>
<Modal.Body style={{ position: "relative" }}>
<BodyLong>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Maiores nisi
incidunt ipsum cupiditate nostrum nesciunt, corrupti nihil at atque
animi ab aut. Quam iusto harum eligendi magnam nulla repudiandae
molestias.
<BodyLong spacing>
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
</BodyLong>

<HGrid gap="6" columns={{ xs: 1, lg: 2 }}>
<HStack justify="center" align="start">
<DatePicker.Standalone
fromDate={new Date("Aug 23 2019")}
toDate={new Date("Feb 23 2024")}
/>
</HStack>
<DatePicker {...datepickerProps} dropdownCaption>
<DatePicker.Input {...inputProps} label="Velg dato" />
</DatePicker>
<HStack justify="center">
<DatePicker.Standalone
fromDate={new Date("Aug 23 2019")}
toDate={new Date("Feb 23 2024")}
/>
</HStack>
</HGrid>
<DatePicker {...datepickerProps} dropdownCaption>
<DatePicker.Input
{...inputProps}
label="Velg dato"
description="Format: dd.mm.yyyy"
/>
</DatePicker>
</Modal.Body>
<Modal.Footer>
<Button>Neste</Button>
<Button variant="secondary">Tilbake</Button>
<Button variant="tertiary">Avbryt</Button>
</Modal.Footer>
</Modal>
);
};
KenAJoh marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 0 additions & 5 deletions @navikt/core/react/src/date/datepicker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,4 @@ export interface DatePickerDefaultProps
* @default See Popover
*/
strategy?: "absolute" | "fixed";
/**
* Bubbles Escape keydown-event up trough DOM-tree. This is set to false by default to prevent closing components like Modal on Escape
* @default false
*/
bubbleEscape?: boolean;
}
Loading
Loading