@navikt/ds-react 4.1.6 → 4.2.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.
Files changed (37) hide show
  1. package/_docs.json +87 -7
  2. package/cjs/chat/Bubble.js +4 -3
  3. package/cjs/chat/Chat.js +13 -10
  4. package/cjs/help-text/HelpText.js +2 -2
  5. package/cjs/timeline/Pin.js +4 -10
  6. package/cjs/timeline/TimelineRow.js +1 -1
  7. package/cjs/timeline/period/ClickablePeriod.js +4 -10
  8. package/esm/chat/Bubble.d.ts +1 -0
  9. package/esm/chat/Bubble.js +4 -3
  10. package/esm/chat/Bubble.js.map +1 -1
  11. package/esm/chat/Chat.d.ts +29 -13
  12. package/esm/chat/Chat.js +13 -10
  13. package/esm/chat/Chat.js.map +1 -1
  14. package/esm/form/error-summary/ErrorSummary.d.ts +12 -0
  15. package/esm/form/error-summary/ErrorSummary.js.map +1 -1
  16. package/esm/form/error-summary/ErrorSummaryItem.d.ts +4 -0
  17. package/esm/form/error-summary/ErrorSummaryItem.js.map +1 -1
  18. package/esm/help-text/HelpText.d.ts +4 -0
  19. package/esm/help-text/HelpText.js +2 -2
  20. package/esm/help-text/HelpText.js.map +1 -1
  21. package/esm/timeline/Pin.js +5 -11
  22. package/esm/timeline/Pin.js.map +1 -1
  23. package/esm/timeline/TimelineRow.js +1 -1
  24. package/esm/timeline/TimelineRow.js.map +1 -1
  25. package/esm/timeline/period/ClickablePeriod.js +5 -11
  26. package/esm/timeline/period/ClickablePeriod.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/chat/Bubble.tsx +9 -5
  29. package/src/chat/Chat.tsx +70 -52
  30. package/src/chat/chat.stories.tsx +148 -126
  31. package/src/form/error-summary/ErrorSummary.tsx +12 -0
  32. package/src/form/error-summary/ErrorSummaryItem.tsx +4 -0
  33. package/src/help-text/HelpText.tsx +6 -1
  34. package/src/help-text/help-text.stories.tsx +34 -1
  35. package/src/timeline/Pin.tsx +6 -25
  36. package/src/timeline/TimelineRow.tsx +1 -0
  37. package/src/timeline/period/ClickablePeriod.tsx +6 -19
@@ -29,6 +29,18 @@ interface ErrorSummaryComponent
29
29
  extends React.ForwardRefExoticComponent<
30
30
  ErrorSummaryProps & React.RefAttributes<HTMLDivElement>
31
31
  > {
32
+ /**
33
+ * Link to error
34
+ *
35
+ * @see [🤖 OverridableComponent](https://aksel.nav.no/grunnleggende/kode/overridablecomponent) support
36
+ *
37
+ * @example
38
+ * ```jsx
39
+ * <ErrorSummary.Item href="#1">
40
+ * Felt må fylles ut med alder
41
+ * </ErrorSummary.Item>
42
+ * ```
43
+ */
32
44
  Item: ErrorSummaryItemType;
33
45
  }
34
46
 
@@ -8,6 +8,10 @@ export interface ErrorSummaryItemProps
8
8
  * Link text
9
9
  */
10
10
  children: React.ReactNode;
11
+ /**
12
+ * Link to errormessage
13
+ */
14
+ href?: string;
11
15
  }
12
16
 
13
17
  export type ErrorSummaryItemType = OverridableComponent<
@@ -29,6 +29,10 @@ export interface HelpTextProps
29
29
  | "right-end"
30
30
  | "left-start"
31
31
  | "left-end";
32
+ /**
33
+ * Classname for wrapper
34
+ */
35
+ wrapperClassName?: string;
32
36
  }
33
37
 
34
38
  /**
@@ -53,6 +57,7 @@ export const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(
53
57
  strategy = "absolute",
54
58
  title = "hjelp",
55
59
  onClick,
60
+ wrapperClassName,
56
61
  ...rest
57
62
  },
58
63
  ref
@@ -62,7 +67,7 @@ export const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(
62
67
  const [open, setOpen] = useState(false);
63
68
 
64
69
  return (
65
- <div className="navds-help-text">
70
+ <div className={cl("navds-help-text", wrapperClassName)}>
66
71
  <button
67
72
  {...rest}
68
73
  ref={mergedRef}
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useRef } from "react";
2
- import { HelpText } from "..";
2
+ import { BodyLong, Heading, HelpText } from "..";
3
3
 
4
4
  export default {
5
5
  title: "ds-react/HelpText",
@@ -65,3 +65,36 @@ export const Open = () => {
65
65
  </HelpText>
66
66
  );
67
67
  };
68
+
69
+ export const WrapperClassName = {
70
+ render: () => {
71
+ return (
72
+ <div>
73
+ <BodyLong spacing>
74
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta
75
+ perspiciatis vero voluptatum, asperiores cumque, deserunt accusantium
76
+ ullam ipsa accusamus officia cupiditate quae unde esse culpa, ratione
77
+ ab quam ea quas?
78
+ </BodyLong>
79
+
80
+ <Heading level="2" size="medium">
81
+ 67 år og 1 måneder øklasdjkl askdak døkasøk daøkdkølasøkld asølkdøka
82
+ <HelpText wrapperClassName="testClass">
83
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta
84
+ perspiciatis vero voluptatum, asperiores cumque, deserunt
85
+ accusantium ullam ipsa accusamus officia cupiditate quae unde esse
86
+ culpa, ratione ab quam ea quas?
87
+ </HelpText>
88
+ <style>{`.testClass {display: inline-block; margin-left: 0.5rem; vertical-align: middle;}`}</style>
89
+ </Heading>
90
+
91
+ <BodyLong spacing>
92
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta
93
+ perspiciatis vero voluptatum, asperiores cumque, deserunt accusantium
94
+ ullam ipsa accusamus officia cupiditate quae unde esse culpa, ratione
95
+ ab quam ea quas?
96
+ </BodyLong>
97
+ </div>
98
+ );
99
+ },
100
+ };
@@ -11,15 +11,9 @@ import {
11
11
  useHover,
12
12
  useInteractions,
13
13
  } from "@floating-ui/react";
14
- import { useEventListener, mergeRefs } from "../util";
15
14
  import { format } from "date-fns";
16
- import React, {
17
- forwardRef,
18
- useCallback,
19
- useMemo,
20
- useRef,
21
- useState,
22
- } from "react";
15
+ import React, { forwardRef, useMemo, useRef, useState } from "react";
16
+ import { mergeRefs } from "../util";
23
17
  import { useTimelineContext } from "./hooks/useTimelineContext";
24
18
  import { position } from "./utils/calc";
25
19
  import { TimelineComponentTypes } from "./utils/types.internal";
@@ -83,23 +77,6 @@ export const Pin = forwardRef<HTMLButtonElement, TimelinePinProps>(
83
77
  [ref, refs.setReference]
84
78
  );
85
79
 
86
- useEventListener(
87
- "focusin",
88
- useCallback(
89
- (e: FocusEvent) => {
90
- if (
91
- ![
92
- refs.reference.current as HTMLButtonElement | null,
93
- refs?.floating?.current,
94
- ].some((element) => element?.contains(e.target as Node))
95
- ) {
96
- open && setOpen(false);
97
- }
98
- },
99
- [open, refs.reference, refs?.floating]
100
- )
101
- );
102
-
103
80
  const staticSide = {
104
81
  top: "bottom",
105
82
  right: "left",
@@ -140,6 +117,10 @@ export const Pin = forwardRef<HTMLButtonElement, TimelinePinProps>(
140
117
  ref={refs.setFloating}
141
118
  {...getFloatingProps({
142
119
  tabIndex: -1,
120
+ onBlur: (e) =>
121
+ e.target.previousSibling !== document.activeElement &&
122
+ open &&
123
+ setOpen(false),
143
124
  })}
144
125
  style={{
145
126
  ...floatingStyles,
@@ -72,6 +72,7 @@ export const TimelineRow = forwardRef<HTMLOListElement, TimelineRowProps>(
72
72
  >
73
73
  <ol
74
74
  {...rest}
75
+ tabIndex={-1}
75
76
  ref={ref}
76
77
  aria-label={
77
78
  periods.length === 0
@@ -11,9 +11,9 @@ import {
11
11
  useHover,
12
12
  useInteractions,
13
13
  } from "@floating-ui/react";
14
- import { useEventListener, mergeRefs } from "../../util";
15
14
  import cl from "clsx";
16
- import React, { useCallback, useMemo, useRef, useState } from "react";
15
+ import React, { useMemo, useRef, useState } from "react";
16
+ import { mergeRefs } from "../../util";
17
17
  import { usePeriodContext } from "../hooks/usePeriodContext";
18
18
  import { useRowContext } from "../hooks/useRowContext";
19
19
  import { useTimelineContext } from "../hooks/useTimelineContext";
@@ -85,23 +85,6 @@ const ClickablePeriod = React.memo(
85
85
  [periodRef, refs.setReference]
86
86
  );
87
87
 
88
- useEventListener(
89
- "focusin",
90
- useCallback(
91
- (e: FocusEvent) => {
92
- if (
93
- ![
94
- refs.reference.current as HTMLButtonElement | null,
95
- refs?.floating?.current,
96
- ].some((element) => element?.contains(e.target as Node))
97
- ) {
98
- open && setOpen(false);
99
- }
100
- },
101
- [open, refs.reference, refs?.floating]
102
- )
103
- );
104
-
105
88
  const staticSide = {
106
89
  top: "bottom",
107
90
  right: "left",
@@ -166,6 +149,10 @@ const ClickablePeriod = React.memo(
166
149
  ref={refs.setFloating}
167
150
  {...getFloatingProps({
168
151
  tabIndex: -1,
152
+ onBlur: (e) =>
153
+ e.target.previousSibling !== document.activeElement &&
154
+ open &&
155
+ setOpen(false),
169
156
  })}
170
157
  style={{
171
158
  ...floatingStyles,