@navikt/ds-react 7.23.2 → 7.25.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.
- package/cjs/chat/Chat.js +4 -3
- package/cjs/chat/Chat.js.map +1 -1
- package/cjs/form/file-upload/parts/item/Item.d.ts +1 -1
- package/cjs/form/file-upload/parts/item/Item.js +10 -2
- package/cjs/form/file-upload/parts/item/Item.js.map +1 -1
- package/cjs/form/search/Search.js +5 -3
- package/cjs/form/search/Search.js.map +1 -1
- package/cjs/form/switch/Switch.js +23 -2
- package/cjs/form/switch/Switch.js.map +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.js +3 -1
- package/cjs/index.js.map +1 -1
- package/cjs/link-card/LinkCard.d.ts +126 -0
- package/cjs/link-card/LinkCard.js +141 -0
- package/cjs/link-card/LinkCard.js.map +1 -0
- package/cjs/link-card/index.d.ts +2 -0
- package/cjs/link-card/index.js +13 -0
- package/cjs/link-card/index.js.map +1 -0
- package/cjs/link-panel/LinkPanel.d.ts +3 -11
- package/cjs/link-panel/LinkPanel.js +3 -11
- package/cjs/link-panel/LinkPanel.js.map +1 -1
- package/cjs/modal/ModalUtils.d.ts +2 -1
- package/cjs/modal/ModalUtils.js +21 -12
- package/cjs/modal/ModalUtils.js.map +1 -1
- package/cjs/table/Table.d.ts +5 -0
- package/cjs/table/Table.js +2 -1
- package/cjs/table/Table.js.map +1 -1
- package/cjs/util/link-anchor/LinkAnchor.d.ts +26 -0
- package/cjs/util/link-anchor/LinkAnchor.js +110 -0
- package/cjs/util/link-anchor/LinkAnchor.js.map +1 -0
- package/cjs/util/link-anchor/index.d.ts +2 -0
- package/cjs/util/link-anchor/index.js +9 -0
- package/cjs/util/link-anchor/index.js.map +1 -0
- package/esm/chat/Chat.js +4 -3
- package/esm/chat/Chat.js.map +1 -1
- package/esm/form/file-upload/parts/item/Item.d.ts +1 -1
- package/esm/form/file-upload/parts/item/Item.js +10 -2
- package/esm/form/file-upload/parts/item/Item.js.map +1 -1
- package/esm/form/search/Search.js +5 -3
- package/esm/form/search/Search.js.map +1 -1
- package/esm/form/switch/Switch.js +23 -2
- package/esm/form/switch/Switch.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/link-card/LinkCard.d.ts +126 -0
- package/esm/link-card/LinkCard.js +105 -0
- package/esm/link-card/LinkCard.js.map +1 -0
- package/esm/link-card/index.d.ts +2 -0
- package/esm/link-card/index.js +3 -0
- package/esm/link-card/index.js.map +1 -0
- package/esm/link-panel/LinkPanel.d.ts +3 -11
- package/esm/link-panel/LinkPanel.js +3 -11
- package/esm/link-panel/LinkPanel.js.map +1 -1
- package/esm/modal/ModalUtils.d.ts +2 -1
- package/esm/modal/ModalUtils.js +20 -11
- package/esm/modal/ModalUtils.js.map +1 -1
- package/esm/table/Table.d.ts +5 -0
- package/esm/table/Table.js +2 -1
- package/esm/table/Table.js.map +1 -1
- package/esm/util/link-anchor/LinkAnchor.d.ts +26 -0
- package/esm/util/link-anchor/LinkAnchor.js +72 -0
- package/esm/util/link-anchor/LinkAnchor.js.map +1 -0
- package/esm/util/link-anchor/index.d.ts +2 -0
- package/esm/util/link-anchor/index.js +3 -0
- package/esm/util/link-anchor/index.js.map +1 -0
- package/package.json +13 -3
- package/src/chat/Chat.tsx +15 -13
- package/src/form/file-upload/parts/item/Item.tsx +20 -6
- package/src/form/search/Search.tsx +5 -1
- package/src/form/switch/Switch.tsx +79 -26
- package/src/index.ts +10 -0
- package/src/link-card/LinkCard.tsx +317 -0
- package/src/link-card/index.tsx +20 -0
- package/src/link-panel/LinkPanel.tsx +3 -11
- package/src/modal/Modal.test.tsx +12 -4
- package/src/modal/ModalUtils.ts +24 -7
- package/src/table/Table.tsx +7 -0
- package/src/util/link-anchor/LinkAnchor.tsx +153 -0
- package/src/util/link-anchor/index.tsx +7 -0
package/src/table/Table.tsx
CHANGED
|
@@ -22,6 +22,11 @@ export interface TableProps
|
|
|
22
22
|
* @default false
|
|
23
23
|
*/
|
|
24
24
|
zebraStripes?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Makes the header sticky
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
stickyHeader?: boolean;
|
|
25
30
|
/**
|
|
26
31
|
* Sort state
|
|
27
32
|
*/
|
|
@@ -85,6 +90,7 @@ export const Table = forwardRef(
|
|
|
85
90
|
size = "medium",
|
|
86
91
|
onSortChange,
|
|
87
92
|
sort,
|
|
93
|
+
stickyHeader = false,
|
|
88
94
|
...rest
|
|
89
95
|
},
|
|
90
96
|
ref,
|
|
@@ -97,6 +103,7 @@ export const Table = forwardRef(
|
|
|
97
103
|
ref={ref}
|
|
98
104
|
className={cn("navds-table", `navds-table--${size}`, className, {
|
|
99
105
|
"navds-table--zebra-stripes": zebraStripes,
|
|
106
|
+
"navds-table--sticky-header": stickyHeader,
|
|
100
107
|
})}
|
|
101
108
|
/>
|
|
102
109
|
</TableContext.Provider>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
AnchorHTMLAttributes,
|
|
3
|
+
HTMLAttributes,
|
|
4
|
+
SVGProps,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useRef,
|
|
7
|
+
} from "react";
|
|
8
|
+
import { ArrowRightIcon } from "@navikt/aksel-icons";
|
|
9
|
+
import { Slot } from "../../slot/Slot";
|
|
10
|
+
import { useRenameCSS } from "../../theme/Theme";
|
|
11
|
+
import { composeEventHandlers } from "../composeEventHandlers";
|
|
12
|
+
import { createContext } from "../create-context";
|
|
13
|
+
import { useMergeRefs } from "../hooks/useMergeRefs";
|
|
14
|
+
import { AsChildProps } from "../types";
|
|
15
|
+
|
|
16
|
+
type LinkAnchorOverlayContextProps = {
|
|
17
|
+
anchorRef: React.RefObject<HTMLAnchorElement>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const [LinkAnchorContextProvider, useLinkAnchorContext] =
|
|
21
|
+
createContext<LinkAnchorOverlayContextProps>({
|
|
22
|
+
name: "LinkAnchorOverlayContext",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
type LinkAnchorOverlayProps = HTMLAttributes<HTMLDivElement> & AsChildProps;
|
|
26
|
+
|
|
27
|
+
const LinkAnchorOverlay = forwardRef<HTMLDivElement, LinkAnchorOverlayProps>(
|
|
28
|
+
(
|
|
29
|
+
{
|
|
30
|
+
children,
|
|
31
|
+
asChild,
|
|
32
|
+
className,
|
|
33
|
+
onClick,
|
|
34
|
+
...restProps
|
|
35
|
+
}: LinkAnchorOverlayProps,
|
|
36
|
+
forwardedRef,
|
|
37
|
+
) => {
|
|
38
|
+
const { cn } = useRenameCSS();
|
|
39
|
+
const anchorRef = useRef<HTMLAnchorElement>(null);
|
|
40
|
+
|
|
41
|
+
const Component = asChild ? Slot : "div";
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<LinkAnchorContextProvider anchorRef={anchorRef}>
|
|
45
|
+
<Component
|
|
46
|
+
ref={forwardedRef}
|
|
47
|
+
{...restProps}
|
|
48
|
+
className={cn("navds-link-anchor__overlay", className)}
|
|
49
|
+
onClick={composeEventHandlers(onClick, (e) => {
|
|
50
|
+
if (e.target === anchorRef.current || isTextSelected()) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const event = new MouseEvent("click", {
|
|
55
|
+
bubbles: true,
|
|
56
|
+
cancelable: true,
|
|
57
|
+
view: window,
|
|
58
|
+
ctrlKey: e.ctrlKey,
|
|
59
|
+
shiftKey: e.shiftKey,
|
|
60
|
+
altKey: e.altKey,
|
|
61
|
+
metaKey: e.metaKey,
|
|
62
|
+
button: e.button,
|
|
63
|
+
screenX: e.screenX,
|
|
64
|
+
screenY: e.screenY,
|
|
65
|
+
clientX: e.clientX,
|
|
66
|
+
clientY: e.clientY,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
anchorRef.current?.dispatchEvent(event);
|
|
70
|
+
})}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</Component>
|
|
74
|
+
</LinkAnchorContextProvider>
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
/* ------------------------------- LinkAnchor ------------------------------- */
|
|
80
|
+
type LinkAnchorProps = AnchorHTMLAttributes<HTMLAnchorElement> &
|
|
81
|
+
(
|
|
82
|
+
| {
|
|
83
|
+
children: React.ReactElement | false | null;
|
|
84
|
+
/**
|
|
85
|
+
* Renders the component and its child as a single element,
|
|
86
|
+
* merging the props of the component with the props of the child.
|
|
87
|
+
*/
|
|
88
|
+
asChild: true;
|
|
89
|
+
as?: never;
|
|
90
|
+
}
|
|
91
|
+
| {
|
|
92
|
+
children: React.ReactNode;
|
|
93
|
+
/**
|
|
94
|
+
* Renders the component and its child as a single element,
|
|
95
|
+
* merging the props of the component with the props of the child.
|
|
96
|
+
*/
|
|
97
|
+
asChild?: false;
|
|
98
|
+
href: string;
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const LinkAnchor = forwardRef<HTMLAnchorElement, LinkAnchorProps>(
|
|
103
|
+
(
|
|
104
|
+
{ children, asChild, className, ...restProps }: LinkAnchorProps,
|
|
105
|
+
forwardedRef,
|
|
106
|
+
) => {
|
|
107
|
+
const { cn } = useRenameCSS();
|
|
108
|
+
|
|
109
|
+
const context = useLinkAnchorContext(false);
|
|
110
|
+
const mergedRefs = useMergeRefs(forwardedRef, context?.anchorRef);
|
|
111
|
+
|
|
112
|
+
const Component = asChild ? Slot : "a";
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<Component
|
|
116
|
+
ref={mergedRefs}
|
|
117
|
+
{...restProps}
|
|
118
|
+
className={cn("navds-link-anchor", className)}
|
|
119
|
+
>
|
|
120
|
+
{children}
|
|
121
|
+
</Component>
|
|
122
|
+
);
|
|
123
|
+
},
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
/* ---------------------------- LinkAnchor Arrow ---------------------------- */
|
|
127
|
+
type LinkAnchorArrowProps = Omit<SVGProps<SVGSVGElement>, "ref">;
|
|
128
|
+
|
|
129
|
+
const LinkAnchorArrow = forwardRef<SVGSVGElement, LinkAnchorArrowProps>(
|
|
130
|
+
({ className, ...restProps }: LinkAnchorArrowProps, forwardedRef) => {
|
|
131
|
+
const { cn } = useRenameCSS();
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<ArrowRightIcon
|
|
135
|
+
ref={forwardedRef}
|
|
136
|
+
aria-hidden
|
|
137
|
+
className={cn("navds-link-anchor__arrow", className)}
|
|
138
|
+
{...restProps}
|
|
139
|
+
/>
|
|
140
|
+
);
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
/* -------------------------- LinkAnchor Utilities -------------------------- */
|
|
145
|
+
function isTextSelected(): boolean {
|
|
146
|
+
if (typeof window === "undefined") {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
return !!window.getSelection()?.toString();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { LinkAnchor, LinkAnchorArrow, LinkAnchorOverlay };
|
|
153
|
+
export type { LinkAnchorArrowProps, LinkAnchorOverlayProps, LinkAnchorProps };
|