@navikt/ds-react 5.17.4 → 5.18.0
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.
- package/_docs.json +544 -64
- package/cjs/index.js +1 -0
- package/cjs/overlays/index.js +5 -0
- package/cjs/overlays/package.json +6 -0
- package/cjs/overlays/portal/Portal.js +55 -0
- package/cjs/tooltip/Tooltip.js +3 -7
- package/cjs/util/Slot.js +5 -2
- package/cjs/util/types/AsChildProps.js +2 -0
- package/esm/date/hooks/useDatepicker.d.ts +1 -1
- package/esm/date/hooks/useMonthPicker.d.ts +1 -1
- package/esm/date/parts/DateInput.d.ts +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/overlays/index.d.ts +2 -0
- package/esm/overlays/index.js +2 -0
- package/esm/overlays/index.js.map +1 -0
- package/esm/overlays/portal/Portal.d.ts +11 -0
- package/esm/overlays/portal/Portal.js +27 -0
- package/esm/overlays/portal/Portal.js.map +1 -0
- package/esm/tooltip/Tooltip.js +4 -8
- package/esm/tooltip/Tooltip.js.map +1 -1
- package/esm/util/Slot.js +5 -2
- package/esm/util/Slot.js.map +1 -1
- package/esm/util/types/AsChildProps.d.ts +36 -0
- package/esm/util/types/AsChildProps.js +2 -0
- package/esm/util/types/AsChildProps.js.map +1 -0
- package/esm/util/types/index.d.ts +1 -0
- package/package.json +3 -3
- package/src/date/hooks/useDatepicker.tsx +1 -1
- package/src/date/hooks/useMonthPicker.tsx +1 -1
- package/src/date/parts/DateInput.tsx +1 -1
- package/src/index.ts +1 -0
- package/src/overlays/index.ts +2 -0
- package/src/overlays/portal/Portal.stories.tsx +99 -0
- package/src/overlays/portal/Portal.tsx +32 -0
- package/src/tooltip/Tooltip.tsx +4 -8
- package/src/util/Slot.tsx +4 -2
- package/src/util/types/AsChildProps.ts +37 -0
- package/src/util/types/index.ts +1 -0
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
FloatingPortal,
|
|
3
2
|
autoUpdate,
|
|
4
3
|
arrow as flArrow,
|
|
5
4
|
flip,
|
|
@@ -21,7 +20,7 @@ import React, {
|
|
|
21
20
|
useRef,
|
|
22
21
|
} from "react";
|
|
23
22
|
import { ModalContext } from "../modal/ModalContext";
|
|
24
|
-
import
|
|
23
|
+
import Portal from "../overlays/portal/Portal";
|
|
25
24
|
import { Detail } from "../typography";
|
|
26
25
|
import { useId } from "../util/hooks";
|
|
27
26
|
import { useControllableState } from "../util/hooks/useControllableState";
|
|
@@ -123,10 +122,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
123
122
|
|
|
124
123
|
const arrowRef = useRef<HTMLDivElement | null>(null);
|
|
125
124
|
const modalContext = useContext(ModalContext);
|
|
126
|
-
const
|
|
127
|
-
const rootElement = modalContext
|
|
128
|
-
? modalContext.ref.current
|
|
129
|
-
: providerRootElement;
|
|
125
|
+
const rootElement = modalContext ? modalContext.ref.current : undefined;
|
|
130
126
|
|
|
131
127
|
const {
|
|
132
128
|
x,
|
|
@@ -199,7 +195,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
199
195
|
: children?.props["aria-describedby"],
|
|
200
196
|
}),
|
|
201
197
|
)}
|
|
202
|
-
<
|
|
198
|
+
<Portal rootElement={rootElement}>
|
|
203
199
|
{_open && (
|
|
204
200
|
<div
|
|
205
201
|
{...getFloatingProps({
|
|
@@ -253,7 +249,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
|
|
|
253
249
|
)}
|
|
254
250
|
</div>
|
|
255
251
|
)}
|
|
256
|
-
</
|
|
252
|
+
</Portal>
|
|
257
253
|
</>
|
|
258
254
|
);
|
|
259
255
|
},
|
package/src/util/Slot.tsx
CHANGED
|
@@ -20,10 +20,12 @@ export const Slot = React.forwardRef<HTMLElement, SlotProps>(
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (React.Children.count(children) > 1) {
|
|
23
|
-
|
|
23
|
+
const error = new Error(
|
|
24
24
|
"Aksel: Components using 'asChild' expects to recieve a single React element child.",
|
|
25
25
|
);
|
|
26
|
-
|
|
26
|
+
error.name = "SlotError";
|
|
27
|
+
Error.captureStackTrace?.(error, Slot);
|
|
28
|
+
throw error;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
return null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type AsChildProps =
|
|
2
|
+
| {
|
|
3
|
+
children: React.ReactElement | false | null;
|
|
4
|
+
/**
|
|
5
|
+
* Renders the component and its child as a single element,
|
|
6
|
+
* merging the props of the component with the props of the child.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <Component asChild data-prop>
|
|
11
|
+
* <ChildComponent data-child />
|
|
12
|
+
* </Component>
|
|
13
|
+
*
|
|
14
|
+
* // Renders
|
|
15
|
+
* <MergedComponent data-prop data-child />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
asChild: true;
|
|
19
|
+
}
|
|
20
|
+
| {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* Renders the component and its child as a single element,
|
|
24
|
+
* merging the props of the component with the props of the child.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <Component asChild data-prop>
|
|
29
|
+
* <ChildComponent data-child />
|
|
30
|
+
* </Component>
|
|
31
|
+
*
|
|
32
|
+
* // Renders
|
|
33
|
+
* <MergedComponent data-prop data-child />
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
asChild?: false;
|
|
37
|
+
};
|
package/src/util/types/index.ts
CHANGED