@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.
Files changed (80) hide show
  1. package/cjs/chat/Chat.js +4 -3
  2. package/cjs/chat/Chat.js.map +1 -1
  3. package/cjs/form/file-upload/parts/item/Item.d.ts +1 -1
  4. package/cjs/form/file-upload/parts/item/Item.js +10 -2
  5. package/cjs/form/file-upload/parts/item/Item.js.map +1 -1
  6. package/cjs/form/search/Search.js +5 -3
  7. package/cjs/form/search/Search.js.map +1 -1
  8. package/cjs/form/switch/Switch.js +23 -2
  9. package/cjs/form/switch/Switch.js.map +1 -1
  10. package/cjs/index.d.ts +1 -0
  11. package/cjs/index.js +3 -1
  12. package/cjs/index.js.map +1 -1
  13. package/cjs/link-card/LinkCard.d.ts +126 -0
  14. package/cjs/link-card/LinkCard.js +141 -0
  15. package/cjs/link-card/LinkCard.js.map +1 -0
  16. package/cjs/link-card/index.d.ts +2 -0
  17. package/cjs/link-card/index.js +13 -0
  18. package/cjs/link-card/index.js.map +1 -0
  19. package/cjs/link-panel/LinkPanel.d.ts +3 -11
  20. package/cjs/link-panel/LinkPanel.js +3 -11
  21. package/cjs/link-panel/LinkPanel.js.map +1 -1
  22. package/cjs/modal/ModalUtils.d.ts +2 -1
  23. package/cjs/modal/ModalUtils.js +21 -12
  24. package/cjs/modal/ModalUtils.js.map +1 -1
  25. package/cjs/table/Table.d.ts +5 -0
  26. package/cjs/table/Table.js +2 -1
  27. package/cjs/table/Table.js.map +1 -1
  28. package/cjs/util/link-anchor/LinkAnchor.d.ts +26 -0
  29. package/cjs/util/link-anchor/LinkAnchor.js +110 -0
  30. package/cjs/util/link-anchor/LinkAnchor.js.map +1 -0
  31. package/cjs/util/link-anchor/index.d.ts +2 -0
  32. package/cjs/util/link-anchor/index.js +9 -0
  33. package/cjs/util/link-anchor/index.js.map +1 -0
  34. package/esm/chat/Chat.js +4 -3
  35. package/esm/chat/Chat.js.map +1 -1
  36. package/esm/form/file-upload/parts/item/Item.d.ts +1 -1
  37. package/esm/form/file-upload/parts/item/Item.js +10 -2
  38. package/esm/form/file-upload/parts/item/Item.js.map +1 -1
  39. package/esm/form/search/Search.js +5 -3
  40. package/esm/form/search/Search.js.map +1 -1
  41. package/esm/form/switch/Switch.js +23 -2
  42. package/esm/form/switch/Switch.js.map +1 -1
  43. package/esm/index.d.ts +1 -0
  44. package/esm/index.js +1 -0
  45. package/esm/index.js.map +1 -1
  46. package/esm/link-card/LinkCard.d.ts +126 -0
  47. package/esm/link-card/LinkCard.js +105 -0
  48. package/esm/link-card/LinkCard.js.map +1 -0
  49. package/esm/link-card/index.d.ts +2 -0
  50. package/esm/link-card/index.js +3 -0
  51. package/esm/link-card/index.js.map +1 -0
  52. package/esm/link-panel/LinkPanel.d.ts +3 -11
  53. package/esm/link-panel/LinkPanel.js +3 -11
  54. package/esm/link-panel/LinkPanel.js.map +1 -1
  55. package/esm/modal/ModalUtils.d.ts +2 -1
  56. package/esm/modal/ModalUtils.js +20 -11
  57. package/esm/modal/ModalUtils.js.map +1 -1
  58. package/esm/table/Table.d.ts +5 -0
  59. package/esm/table/Table.js +2 -1
  60. package/esm/table/Table.js.map +1 -1
  61. package/esm/util/link-anchor/LinkAnchor.d.ts +26 -0
  62. package/esm/util/link-anchor/LinkAnchor.js +72 -0
  63. package/esm/util/link-anchor/LinkAnchor.js.map +1 -0
  64. package/esm/util/link-anchor/index.d.ts +2 -0
  65. package/esm/util/link-anchor/index.js +3 -0
  66. package/esm/util/link-anchor/index.js.map +1 -0
  67. package/package.json +13 -3
  68. package/src/chat/Chat.tsx +15 -13
  69. package/src/form/file-upload/parts/item/Item.tsx +20 -6
  70. package/src/form/search/Search.tsx +5 -1
  71. package/src/form/switch/Switch.tsx +79 -26
  72. package/src/index.ts +10 -0
  73. package/src/link-card/LinkCard.tsx +317 -0
  74. package/src/link-card/index.tsx +20 -0
  75. package/src/link-panel/LinkPanel.tsx +3 -11
  76. package/src/modal/Modal.test.tsx +12 -4
  77. package/src/modal/ModalUtils.ts +24 -7
  78. package/src/table/Table.tsx +7 -0
  79. package/src/util/link-anchor/LinkAnchor.tsx +153 -0
  80. package/src/util/link-anchor/index.tsx +7 -0
@@ -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 };
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ export { LinkAnchor, LinkAnchorOverlay, LinkAnchorArrow } from "./LinkAnchor";
3
+ export type {
4
+ LinkAnchorProps,
5
+ LinkAnchorOverlayProps,
6
+ LinkAnchorArrowProps,
7
+ } from "./LinkAnchor";