@navikt/ds-react 5.8.0 → 5.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/_docs.json +1794 -1749
  2. package/cjs/date/context/useDateInputContext.js +1 -5
  3. package/cjs/date/datepicker/DatePicker.js +26 -25
  4. package/cjs/date/hooks/useDatepicker.js +9 -17
  5. package/cjs/date/hooks/useMonthPicker.js +9 -17
  6. package/cjs/date/hooks/useRangeDatepicker.js +9 -20
  7. package/cjs/date/monthpicker/MonthPicker.js +11 -6
  8. package/cjs/date/{DateInput.js → parts/DateInput.js} +14 -10
  9. package/cjs/date/parts/DateWrapper.js +55 -0
  10. package/cjs/date/utils/labels.js +77 -1
  11. package/cjs/form/combobox/Combobox.js +2 -2
  12. package/cjs/form/combobox/ComboboxProvider.js +1 -2
  13. package/cjs/form/combobox/FilteredOptions/FilteredOptions.js +15 -14
  14. package/cjs/form/combobox/FilteredOptions/filtered-options-util.js +24 -0
  15. package/cjs/form/combobox/FilteredOptions/filteredOptionsContext.js +23 -106
  16. package/cjs/form/combobox/FilteredOptions/useVirtualFocus.js +55 -0
  17. package/cjs/form/combobox/Input/Input.js +22 -13
  18. package/cjs/form/combobox/customOptionsContext.js +2 -3
  19. package/cjs/modal/Modal.js +4 -1
  20. package/cjs/popover/Popover.js +5 -7
  21. package/cjs/util/useMedia.js +30 -0
  22. package/esm/date/context/useDateInputContext.d.ts +6 -2
  23. package/esm/date/context/useDateInputContext.js +1 -5
  24. package/esm/date/context/useDateInputContext.js.map +1 -1
  25. package/esm/date/datepicker/DatePicker.d.ts +1 -1
  26. package/esm/date/datepicker/DatePicker.js +28 -27
  27. package/esm/date/datepicker/DatePicker.js.map +1 -1
  28. package/esm/date/datepicker/types.d.ts +0 -5
  29. package/esm/date/hooks/useDatepicker.d.ts +8 -5
  30. package/esm/date/hooks/useDatepicker.js +10 -18
  31. package/esm/date/hooks/useDatepicker.js.map +1 -1
  32. package/esm/date/hooks/useMonthPicker.d.ts +7 -4
  33. package/esm/date/hooks/useMonthPicker.js +10 -18
  34. package/esm/date/hooks/useMonthPicker.js.map +1 -1
  35. package/esm/date/hooks/useRangeDatepicker.d.ts +9 -3
  36. package/esm/date/hooks/useRangeDatepicker.js +10 -21
  37. package/esm/date/hooks/useRangeDatepicker.js.map +1 -1
  38. package/esm/date/index.d.ts +1 -1
  39. package/esm/date/index.js.map +1 -1
  40. package/esm/date/monthpicker/MonthPicker.d.ts +1 -1
  41. package/esm/date/monthpicker/MonthPicker.js +13 -8
  42. package/esm/date/monthpicker/MonthPicker.js.map +1 -1
  43. package/esm/date/monthpicker/types.d.ts +0 -5
  44. package/esm/date/{DateInput.d.ts → parts/DateInput.d.ts} +5 -1
  45. package/esm/date/{DateInput.js → parts/DateInput.js} +15 -11
  46. package/esm/date/parts/DateInput.js.map +1 -0
  47. package/esm/date/parts/DateWrapper.d.ts +15 -0
  48. package/esm/date/parts/DateWrapper.js +26 -0
  49. package/esm/date/parts/DateWrapper.js.map +1 -0
  50. package/esm/date/utils/labels.d.ts +2 -0
  51. package/esm/date/utils/labels.js +74 -0
  52. package/esm/date/utils/labels.js.map +1 -1
  53. package/esm/form/combobox/Combobox.js +2 -2
  54. package/esm/form/combobox/Combobox.js.map +1 -1
  55. package/esm/form/combobox/ComboboxProvider.js +1 -2
  56. package/esm/form/combobox/ComboboxProvider.js.map +1 -1
  57. package/esm/form/combobox/FilteredOptions/FilteredOptions.js +15 -14
  58. package/esm/form/combobox/FilteredOptions/FilteredOptions.js.map +1 -1
  59. package/esm/form/combobox/FilteredOptions/filtered-options-util.d.ts +12 -0
  60. package/esm/form/combobox/FilteredOptions/filtered-options-util.js +23 -0
  61. package/esm/form/combobox/FilteredOptions/filtered-options-util.js.map +1 -0
  62. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.d.ts +10 -13
  63. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js +24 -107
  64. package/esm/form/combobox/FilteredOptions/filteredOptionsContext.js.map +1 -1
  65. package/esm/form/combobox/FilteredOptions/useVirtualFocus.d.ts +15 -0
  66. package/esm/form/combobox/FilteredOptions/useVirtualFocus.js +54 -0
  67. package/esm/form/combobox/FilteredOptions/useVirtualFocus.js.map +1 -0
  68. package/esm/form/combobox/Input/Input.js +22 -13
  69. package/esm/form/combobox/Input/Input.js.map +1 -1
  70. package/esm/form/combobox/customOptionsContext.d.ts +4 -1
  71. package/esm/form/combobox/customOptionsContext.js +2 -3
  72. package/esm/form/combobox/customOptionsContext.js.map +1 -1
  73. package/esm/modal/Modal.js +4 -1
  74. package/esm/modal/Modal.js.map +1 -1
  75. package/esm/popover/Popover.d.ts +0 -5
  76. package/esm/popover/Popover.js +5 -7
  77. package/esm/popover/Popover.js.map +1 -1
  78. package/esm/util/useMedia.d.ts +8 -0
  79. package/esm/util/useMedia.js +27 -0
  80. package/esm/util/useMedia.js.map +1 -0
  81. package/package.json +3 -3
  82. package/src/date/context/useDateInputContext.tsx +5 -5
  83. package/src/date/datepicker/DatePicker.tsx +58 -65
  84. package/src/date/datepicker/datepicker.stories.tsx +37 -46
  85. package/src/date/datepicker/types.ts +0 -5
  86. package/src/date/hooks/useDatepicker.tsx +20 -25
  87. package/src/date/hooks/useMonthPicker.tsx +18 -24
  88. package/src/date/hooks/useRangeDatepicker.tsx +27 -30
  89. package/src/date/index.ts +1 -1
  90. package/src/date/monthpicker/MonthPicker.tsx +39 -43
  91. package/src/date/monthpicker/types.ts +0 -5
  92. package/src/date/{DateInput.tsx → parts/DateInput.tsx} +23 -12
  93. package/src/date/parts/DateWrapper.tsx +80 -0
  94. package/src/date/utils/labels.ts +83 -0
  95. package/src/form/combobox/Combobox.tsx +2 -2
  96. package/src/form/combobox/ComboboxProvider.tsx +1 -2
  97. package/src/form/combobox/FilteredOptions/FilteredOptions.tsx +28 -16
  98. package/src/form/combobox/FilteredOptions/filtered-options-util.ts +38 -0
  99. package/src/form/combobox/FilteredOptions/filteredOptionsContext.tsx +70 -140
  100. package/src/form/combobox/FilteredOptions/useVirtualFocus.ts +87 -0
  101. package/src/form/combobox/Input/Input.tsx +22 -18
  102. package/src/form/combobox/customOptionsContext.tsx +10 -5
  103. package/src/guide-panel/guidepanel.stories.tsx +2 -2
  104. package/src/modal/Modal.tsx +4 -1
  105. package/src/modal/modal.stories.tsx +93 -21
  106. package/src/popover/Popover.tsx +4 -12
  107. package/src/util/__tests__/useMedia.test.tsx +19 -0
  108. package/src/util/useMedia.ts +38 -0
  109. package/cjs/date/hooks/useEscape.js +0 -23
  110. package/cjs/date/hooks/useOutsideClickHandler.js +0 -26
  111. package/esm/date/DateInput.js.map +0 -1
  112. package/esm/date/hooks/useEscape.d.ts +0 -2
  113. package/esm/date/hooks/useEscape.js +0 -20
  114. package/esm/date/hooks/useEscape.js.map +0 -1
  115. package/esm/date/hooks/useOutsideClickHandler.d.ts +0 -1
  116. package/esm/date/hooks/useOutsideClickHandler.js +0 -23
  117. package/esm/date/hooks/useOutsideClickHandler.js.map +0 -1
  118. package/src/date/hooks/useEscape.tsx +0 -30
  119. package/src/date/hooks/useOutsideClickHandler.tsx +0 -34
@@ -1,17 +1,19 @@
1
1
  import { FileIcon } from "@navikt/aksel-icons";
2
+ import { Meta, StoryFn } from "@storybook/react";
2
3
  import React, { useRef, useState } from "react";
3
4
  import { BodyLong, Button, Heading, Tooltip } from "..";
4
5
  import Modal from "./Modal";
5
6
 
6
- export default {
7
+ const meta: Meta<typeof Modal> = {
7
8
  title: "ds-react/Modal",
8
9
  component: Modal,
9
10
  parameters: {
10
11
  chromatic: { pauseAnimationAtEnd: true },
11
12
  },
12
13
  };
14
+ export default meta;
13
15
 
14
- export const WithUseRef = () => {
16
+ export const WithUseRef: StoryFn = () => {
15
17
  const ref = useRef<HTMLDialogElement>(null);
16
18
  const ref2 = useRef<HTMLDialogElement>(null);
17
19
 
@@ -87,7 +89,7 @@ export const WithUseRef = () => {
87
89
  };
88
90
  WithUseRef.storyName = "With useRef";
89
91
 
90
- export const WithUseState = () => {
92
+ export const WithUseState: StoryFn = () => {
91
93
  const [open, setOpen] = useState(true);
92
94
  const [open2, setOpen2] = useState(false);
93
95
 
@@ -140,36 +142,43 @@ export const WithUseState = () => {
140
142
  };
141
143
  WithUseState.storyName = "With useState";
142
144
 
143
- export const EmptyHeader = () => (
144
- <div style={{ minWidth: "800px", minHeight: "600px" } /* For Chromatic */}>
145
- <Modal open>
146
- <Modal.Header />
147
- <Modal.Body>
148
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
149
- tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
150
- veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
151
- commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
152
- velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
153
- occaecat cupidatat non proident, sunt in culpa qui officia deserunt
154
- mollit anim id est laborum.
155
- </Modal.Body>
156
- </Modal>
157
- </div>
145
+ export const EmptyHeader: StoryFn = () => (
146
+ <Modal open>
147
+ <Modal.Header />
148
+ <Modal.Body>
149
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
150
+ tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
151
+ veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
152
+ commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
153
+ velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
154
+ cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
155
+ est laborum.
156
+ </Modal.Body>
157
+ </Modal>
158
158
  );
159
159
 
160
- export const Small = () => (
160
+ export const Small: StoryFn = () => (
161
161
  <Modal open width="small" header={{ heading: "Simple header" }}>
162
162
  <Modal.Body>Lorem ipsum dolor sit amet.</Modal.Body>
163
163
  </Modal>
164
164
  );
165
+ Small.storyName = "Size = Small";
165
166
 
166
- export const MediumWithPortal = () => (
167
+ export const MediumWithPortal: StoryFn = () => (
167
168
  <Modal open portal width="medium" header={{ heading: "Simple header" }}>
168
169
  <Modal.Body>Lorem ipsum dolor sit amet.</Modal.Body>
169
170
  </Modal>
170
171
  );
172
+ MediumWithPortal.storyName = "Size = Medium (with portal)";
173
+
174
+ export const Large800: StoryFn = () => (
175
+ <Modal open width={800} header={{ heading: "Simple header" }}>
176
+ <Modal.Body>Lorem ipsum dolor sit amet.</Modal.Body>
177
+ </Modal>
178
+ );
179
+ Large800.storyName = "Size = 800px";
171
180
 
172
- export const WithTooltip = () => {
181
+ export const WithTooltip: StoryFn = () => {
173
182
  const ref = useRef<HTMLDialogElement>(null);
174
183
 
175
184
  return (
@@ -193,3 +202,66 @@ export const WithTooltip = () => {
193
202
  </div>
194
203
  );
195
204
  };
205
+
206
+ export const ChromaticViewportTesting: StoryFn = () => (
207
+ <div id="modal-story-wrapper" style={{ width: "100vw", height: "100vh" }}>
208
+ <style>{`#storybook-root { padding: 0 !important }`}</style>
209
+ <Modal
210
+ open
211
+ header={{ heading: "Chromatic Viewports Testing", label: "Test" }}
212
+ >
213
+ <Modal.Body>
214
+ <BodyLong spacing>
215
+ This story is tailored for testing the breakpoints with Chromatic.
216
+ </BodyLong>
217
+ <BodyLong spacing>
218
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
219
+ eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
220
+ minim veniam, quis nostrud exercitation ullamco laboris nisi ut
221
+ aliquip ex ea commodo consequat.
222
+ </BodyLong>
223
+ <BodyLong spacing>
224
+ Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
225
+ dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
226
+ proident, sunt in culpa qui officia deserunt mollit anim id est
227
+ laborum.
228
+ </BodyLong>
229
+ <BodyLong>
230
+ Sed ut perspiciatis unde omnis iste natus error sit voluptatem
231
+ accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae
232
+ ab illo inventore veritatis et quasi architecto beatae vitae dicta
233
+ sunt explicabo.
234
+ </BodyLong>
235
+ </Modal.Body>
236
+ <Modal.Footer>
237
+ <Button>Primary</Button>
238
+ <Button variant="secondary">Secondary</Button>
239
+ <Button variant="tertiary">Tertiary</Button>
240
+ </Modal.Footer>
241
+ </Modal>
242
+ </div>
243
+ );
244
+ ChromaticViewportTesting.parameters = {
245
+ chromatic: {
246
+ modes: {
247
+ mobile_portrait: {
248
+ viewport: {
249
+ width: 400,
250
+ height: 850,
251
+ },
252
+ },
253
+ mobile_landscape: {
254
+ viewport: {
255
+ width: 850,
256
+ height: 400,
257
+ },
258
+ },
259
+ desktop: {
260
+ viewport: {
261
+ width: 1280,
262
+ height: 960,
263
+ },
264
+ },
265
+ },
266
+ },
267
+ };
@@ -18,6 +18,7 @@ import React, {
18
18
  useMemo,
19
19
  useRef,
20
20
  } from "react";
21
+ import { DateContext } from "../date/context";
21
22
  import { ModalContext } from "../modal/ModalContext";
22
23
  import { mergeRefs, useClientLayoutEffect, useEventListener } from "../util";
23
24
  import PopoverContent, { PopoverContentType } from "./PopoverContent";
@@ -73,11 +74,6 @@ export interface PopoverProps extends HTMLAttributes<HTMLDivElement> {
73
74
  * @default "absolute"
74
75
  */
75
76
  strategy?: "absolute" | "fixed";
76
- /**
77
- * Bubbles Escape keydown-event up trough DOM-tree. This is set to false by default to prevent closing components like Modal on Escape
78
- * @default false
79
- */
80
- bubbleEscape?: boolean;
81
77
  /**
82
78
  * Changes placement of the floating element in order to keep it in view.
83
79
  * @default true
@@ -124,7 +120,6 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
124
120
  placement = "top",
125
121
  offset,
126
122
  strategy: userStrategy,
127
- bubbleEscape = false,
128
123
  flip: _flip = true,
129
124
  ...rest
130
125
  },
@@ -132,8 +127,9 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
132
127
  ) => {
133
128
  const arrowRef = useRef<HTMLDivElement | null>(null);
134
129
  const isInModal = useContext(ModalContext) !== null;
130
+ const isInDatepicker = useContext(DateContext) !== null;
135
131
  const chosenStrategy = userStrategy ?? (isInModal ? "fixed" : "absolute");
136
- const chosenFlip = isInModal ? true : _flip;
132
+ const chosenFlip = isInDatepicker ? false : _flip;
137
133
 
138
134
  const {
139
135
  x,
@@ -160,11 +156,7 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
160
156
 
161
157
  const { getFloatingProps } = useInteractions([
162
158
  useClick(context),
163
- useDismiss(context, {
164
- bubbles: {
165
- escapeKey: bubbleEscape,
166
- },
167
- }),
159
+ useDismiss(context),
168
160
  ]);
169
161
 
170
162
  useClientLayoutEffect(() => {
@@ -0,0 +1,19 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import React from "react";
3
+ import { useMedia } from "../useMedia";
4
+
5
+ function TestComponent({ fallback }: { fallback?: boolean }) {
6
+ const media = useMedia("screen and (min-width: 1024px)", fallback);
7
+ return <div data-testid="media-id">{`${media}`}</div>;
8
+ }
9
+
10
+ describe("useMedia", () => {
11
+ test("Should return 'undefined' when no fallback is given", async () => {
12
+ render(<TestComponent />);
13
+ expect(screen.getByTestId("media-id").innerHTML).toEqual("undefined");
14
+ });
15
+ test("Should return fallback", async () => {
16
+ render(<TestComponent fallback={true} />);
17
+ expect(screen.getByTestId("media-id").innerHTML).toEqual("true");
18
+ });
19
+ });
@@ -0,0 +1,38 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ export const noMatchMedia =
4
+ typeof window !== "undefined" && window.matchMedia === undefined;
5
+
6
+ /**
7
+ * @example useMedia("screen and (min-width: 1024px)")
8
+ * @param media string
9
+ * @param fallback boolean
10
+ * @returns boolean | undefined
11
+ */
12
+ export const useMedia = (
13
+ media: string,
14
+ fallback?: boolean
15
+ ): boolean | undefined => {
16
+ const [matches, setMatches] = useState(fallback);
17
+
18
+ useEffect(() => {
19
+ if (noMatchMedia) {
20
+ return;
21
+ }
22
+ const mediaQueryList = window.matchMedia(media);
23
+
24
+ setMatches(mediaQueryList.matches);
25
+
26
+ const listener = (evt: MediaQueryListEvent) => {
27
+ setMatches(evt.matches);
28
+ };
29
+
30
+ mediaQueryList.addEventListener("change", listener);
31
+
32
+ return () => {
33
+ mediaQueryList.removeEventListener("change", listener);
34
+ };
35
+ }, [media]);
36
+
37
+ return matches;
38
+ };
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useEscape = void 0;
4
- const react_1 = require("react");
5
- const useEscape = (open, setOpen, focusRef) => {
6
- const handleClose = (0, react_1.useCallback)(() => {
7
- setOpen(false);
8
- (focusRef === null || focusRef === void 0 ? void 0 : focusRef.current) && focusRef.current.focus();
9
- }, [focusRef, setOpen]);
10
- const escape = (0, react_1.useCallback)((event) => {
11
- if (open && event.key === "Escape") {
12
- event.preventDefault(); // This prevents modal from closing when using datepicker inside modal
13
- handleClose();
14
- }
15
- }, [handleClose, open]);
16
- (0, react_1.useEffect)(() => {
17
- window.addEventListener("keydown", escape, false);
18
- return () => {
19
- window.removeEventListener("keydown", escape, false);
20
- };
21
- }, [escape]);
22
- };
23
- exports.useEscape = useEscape;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useOutsideClickHandler = void 0;
4
- const react_1 = require("react");
5
- const useOutsideClickHandler = (open, setOpen, refs) => {
6
- const handleFocusIn = (0, react_1.useCallback)((e) => {
7
- var _a, _b, _c;
8
- const composed = (_b = (_a = e.composedPath) === null || _a === void 0 ? void 0 : _a.call(e)) === null || _b === void 0 ? void 0 : _b[0];
9
- if (!(e === null || e === void 0 ? void 0 : e.target) || !((_c = e === null || e === void 0 ? void 0 : e.target) === null || _c === void 0 ? void 0 : _c.nodeType) || !composed) {
10
- return;
11
- }
12
- if (!refs.some((element) => (element === null || element === void 0 ? void 0 : element.contains(e.target)) || (element === null || element === void 0 ? void 0 : element.contains(composed)))) {
13
- open && setOpen(false);
14
- }
15
- }, [open, refs, setOpen]);
16
- (0, react_1.useEffect)(() => {
17
- window.addEventListener("focusin", handleFocusIn);
18
- window.addEventListener("pointerdown", handleFocusIn);
19
- return () => {
20
- var _a, _b;
21
- (_a = window === null || window === void 0 ? void 0 : window.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(window, "focusin", handleFocusIn);
22
- (_b = window === null || window === void 0 ? void 0 : window.removeEventListener) === null || _b === void 0 ? void 0 : _b.call(window, "pointerdown", handleFocusIn);
23
- };
24
- }, [handleFocusIn]);
25
- };
26
- exports.useOutsideClickHandler = useOutsideClickHandler;
@@ -1 +0,0 @@
1
- {"version":3,"file":"DateInput.js","sourceRoot":"","sources":["../../src/date/DateInput.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAuB,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAkB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAyB/B,MAAM,SAAS,GAAG,UAAU,CAAmC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IAC5E,MAAM,EACJ,SAAS,EACT,SAAS,GAAG,KAAK,EACjB,KAAK,EACL,WAAW,EACX,OAAO,GAAG,YAAY,KAEpB,KAAK,EADJ,IAAI,UACL,KAAK,EAPH,6DAOL,CAAQ,CAAC;IAEV,MAAM,mBAAmB,GAAG,OAAO,KAAK,YAAY,CAAC;IAErD,MAAM,oBAAoB,GAAG;QAC3B,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,mBAAmB;QACtE,SAAS,EAAE;YACT,IAAI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,oBAAC,SAAS,oBAAK,KAAK,IAAE,GAAG,EAAE,GAAG,IAAI,CACnD,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CACxC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,oBAAC,SAAS,oBAAK,KAAK,IAAE,OAAO,EAAC,aAAa,EAAC,GAAG,EAAE,GAAG,IAAI,CACzE,CAAC"}
@@ -1,2 +0,0 @@
1
- import { RefObject } from "react";
2
- export declare const useEscape: (open: boolean, setOpen: (openState: boolean) => void, focusRef: RefObject<HTMLElement>) => void;
@@ -1,20 +0,0 @@
1
- import { useCallback, useEffect } from "react";
2
- export const useEscape = (open, setOpen, focusRef) => {
3
- const handleClose = useCallback(() => {
4
- setOpen(false);
5
- (focusRef === null || focusRef === void 0 ? void 0 : focusRef.current) && focusRef.current.focus();
6
- }, [focusRef, setOpen]);
7
- const escape = useCallback((event) => {
8
- if (open && event.key === "Escape") {
9
- event.preventDefault(); // This prevents modal from closing when using datepicker inside modal
10
- handleClose();
11
- }
12
- }, [handleClose, open]);
13
- useEffect(() => {
14
- window.addEventListener("keydown", escape, false);
15
- return () => {
16
- window.removeEventListener("keydown", escape, false);
17
- };
18
- }, [escape]);
19
- };
20
- //# sourceMappingURL=useEscape.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useEscape.js","sourceRoot":"","sources":["../../../src/date/hooks/useEscape.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAE1D,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,IAAa,EACb,OAAqC,EACrC,QAAgC,EAChC,EAAE;IACF,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE;QACnC,OAAO,CAAC,KAAK,CAAC,CAAC;QACf,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,KAAI,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAChD,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAExB,MAAM,MAAM,GAAG,WAAW,CACxB,CAAC,KAAoB,EAAE,EAAE;QACvB,IAAI,IAAI,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE;YAClC,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,sEAAsE;YAC9F,WAAW,EAAE,CAAC;SACf;IACH,CAAC,EACD,CAAC,WAAW,EAAE,IAAI,CAAC,CACpB,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAElD,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QACvD,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AACf,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export declare const useOutsideClickHandler: (open: boolean, setOpen: (openState: boolean) => void, refs: Array<any>) => void;
@@ -1,23 +0,0 @@
1
- import { useCallback, useEffect } from "react";
2
- export const useOutsideClickHandler = (open, setOpen, refs) => {
3
- const handleFocusIn = useCallback((e) => {
4
- var _a, _b, _c;
5
- const composed = (_b = (_a = e.composedPath) === null || _a === void 0 ? void 0 : _a.call(e)) === null || _b === void 0 ? void 0 : _b[0];
6
- if (!(e === null || e === void 0 ? void 0 : e.target) || !((_c = e === null || e === void 0 ? void 0 : e.target) === null || _c === void 0 ? void 0 : _c.nodeType) || !composed) {
7
- return;
8
- }
9
- if (!refs.some((element) => (element === null || element === void 0 ? void 0 : element.contains(e.target)) || (element === null || element === void 0 ? void 0 : element.contains(composed)))) {
10
- open && setOpen(false);
11
- }
12
- }, [open, refs, setOpen]);
13
- useEffect(() => {
14
- window.addEventListener("focusin", handleFocusIn);
15
- window.addEventListener("pointerdown", handleFocusIn);
16
- return () => {
17
- var _a, _b;
18
- (_a = window === null || window === void 0 ? void 0 : window.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(window, "focusin", handleFocusIn);
19
- (_b = window === null || window === void 0 ? void 0 : window.removeEventListener) === null || _b === void 0 ? void 0 : _b.call(window, "pointerdown", handleFocusIn);
20
- };
21
- }, [handleFocusIn]);
22
- };
23
- //# sourceMappingURL=useOutsideClickHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useOutsideClickHandler.js","sourceRoot":"","sources":["../../../src/date/hooks/useOutsideClickHandler.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE/C,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,IAAa,EACb,OAAqC,EACrC,IAAgB,EAChB,EAAE;IACF,MAAM,aAAa,GAAG,WAAW,CAC/B,CAAC,CAAC,EAAE,EAAE;;QACJ,MAAM,QAAQ,GAAG,MAAA,MAAA,CAAC,CAAC,YAAY,iDAAI,0CAAG,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,CAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,MAAM,CAAA,IAAI,CAAC,CAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,MAAM,0CAAE,QAAQ,CAAA,IAAI,CAAC,QAAQ,EAAE;YACnD,OAAO;SACR;QACD,IACE,CAAC,IAAI,CAAC,IAAI,CACR,CAAC,OAAO,EAAE,EAAE,CACV,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA,CAC7D,EACD;YACA,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;SACxB;IACH,CAAC,EACD,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CACtB,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;QACtD,OAAO,GAAG,EAAE;;YACV,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,mBAAmB,uDAAG,SAAS,EAAE,aAAa,CAAC,CAAC;YACxD,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,mBAAmB,uDAAG,aAAa,EAAE,aAAa,CAAC,CAAC;QAC9D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;AACtB,CAAC,CAAC"}
@@ -1,30 +0,0 @@
1
- import { useCallback, useEffect, RefObject } from "react";
2
-
3
- export const useEscape = (
4
- open: boolean,
5
- setOpen: (openState: boolean) => void,
6
- focusRef: RefObject<HTMLElement>
7
- ) => {
8
- const handleClose = useCallback(() => {
9
- setOpen(false);
10
- focusRef?.current && focusRef.current.focus();
11
- }, [focusRef, setOpen]);
12
-
13
- const escape = useCallback(
14
- (event: KeyboardEvent) => {
15
- if (open && event.key === "Escape") {
16
- event.preventDefault(); // This prevents modal from closing when using datepicker inside modal
17
- handleClose();
18
- }
19
- },
20
- [handleClose, open]
21
- );
22
-
23
- useEffect(() => {
24
- window.addEventListener("keydown", escape, false);
25
-
26
- return () => {
27
- window.removeEventListener("keydown", escape, false);
28
- };
29
- }, [escape]);
30
- };
@@ -1,34 +0,0 @@
1
- import { useCallback, useEffect } from "react";
2
-
3
- export const useOutsideClickHandler = (
4
- open: boolean,
5
- setOpen: (openState: boolean) => void,
6
- refs: Array<any>
7
- ) => {
8
- const handleFocusIn = useCallback(
9
- (e) => {
10
- const composed = e.composedPath?.()?.[0];
11
- if (!e?.target || !e?.target?.nodeType || !composed) {
12
- return;
13
- }
14
- if (
15
- !refs.some(
16
- (element) =>
17
- element?.contains(e.target) || element?.contains(composed)
18
- )
19
- ) {
20
- open && setOpen(false);
21
- }
22
- },
23
- [open, refs, setOpen]
24
- );
25
-
26
- useEffect(() => {
27
- window.addEventListener("focusin", handleFocusIn);
28
- window.addEventListener("pointerdown", handleFocusIn);
29
- return () => {
30
- window?.removeEventListener?.("focusin", handleFocusIn);
31
- window?.removeEventListener?.("pointerdown", handleFocusIn);
32
- };
33
- }, [handleFocusIn]);
34
- };