@navikt/ds-react 7.33.5 → 7.34.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 (256) hide show
  1. package/cjs/alert/Alert.js +2 -4
  2. package/cjs/alert/Alert.js.map +1 -1
  3. package/cjs/alert/base-alert/close-button/BaseAlertCloseButton.d.ts +17 -0
  4. package/cjs/alert/base-alert/close-button/BaseAlertCloseButton.js +72 -0
  5. package/cjs/alert/base-alert/close-button/BaseAlertCloseButton.js.map +1 -0
  6. package/cjs/alert/base-alert/content/BaseAlertContent.d.ts +20 -0
  7. package/cjs/alert/base-alert/content/BaseAlertContent.js +70 -0
  8. package/cjs/alert/base-alert/content/BaseAlertContent.js.map +1 -0
  9. package/cjs/alert/base-alert/header/BaseAlertHeader.d.ts +22 -0
  10. package/cjs/alert/base-alert/header/BaseAlertHeader.js +77 -0
  11. package/cjs/alert/base-alert/header/BaseAlertHeader.js.map +1 -0
  12. package/cjs/alert/base-alert/index.d.ts +1 -0
  13. package/cjs/alert/base-alert/index.js +39 -0
  14. package/cjs/alert/base-alert/index.js.map +1 -0
  15. package/cjs/alert/base-alert/namespace.d.ts +10 -0
  16. package/cjs/alert/base-alert/namespace.js +14 -0
  17. package/cjs/alert/base-alert/namespace.js.map +1 -0
  18. package/cjs/alert/base-alert/root/BaseAlertRoot.context.d.ts +12 -0
  19. package/cjs/alert/base-alert/root/BaseAlertRoot.context.js +11 -0
  20. package/cjs/alert/base-alert/root/BaseAlertRoot.context.js.map +1 -0
  21. package/cjs/alert/base-alert/root/BaseAlertRoot.d.ts +43 -0
  22. package/cjs/alert/base-alert/root/BaseAlertRoot.js +65 -0
  23. package/cjs/alert/base-alert/root/BaseAlertRoot.js.map +1 -0
  24. package/cjs/alert/base-alert/root/BaseAlertRoot.utils.d.ts +9 -0
  25. package/cjs/alert/base-alert/root/BaseAlertRoot.utils.js +48 -0
  26. package/cjs/alert/base-alert/root/BaseAlertRoot.utils.js.map +1 -0
  27. package/cjs/alert/base-alert/title/BaseAlertTitle.d.ts +24 -0
  28. package/cjs/alert/base-alert/title/BaseAlertTitle.js +77 -0
  29. package/cjs/alert/base-alert/title/BaseAlertTitle.js.map +1 -0
  30. package/cjs/alert/global-alert/close-button/GlobalAlertCloseButton.d.ts +17 -0
  31. package/cjs/alert/global-alert/close-button/GlobalAlertCloseButton.js +19 -0
  32. package/cjs/alert/global-alert/close-button/GlobalAlertCloseButton.js.map +1 -0
  33. package/cjs/alert/global-alert/content/GlobalAlertContent.d.ts +18 -0
  34. package/cjs/alert/global-alert/content/GlobalAlertContent.js +20 -0
  35. package/cjs/alert/global-alert/content/GlobalAlertContent.js.map +1 -0
  36. package/cjs/alert/global-alert/header/GlobalAlertHeader.d.ts +17 -0
  37. package/cjs/alert/global-alert/header/GlobalAlertHeader.js +54 -0
  38. package/cjs/alert/global-alert/header/GlobalAlertHeader.js.map +1 -0
  39. package/cjs/alert/global-alert/index.d.ts +2 -0
  40. package/cjs/alert/global-alert/index.js +11 -0
  41. package/cjs/alert/global-alert/index.js.map +1 -0
  42. package/cjs/alert/global-alert/root/GlobalAlertRoot.d.ts +81 -0
  43. package/cjs/alert/global-alert/root/GlobalAlertRoot.js +69 -0
  44. package/cjs/alert/global-alert/root/GlobalAlertRoot.js.map +1 -0
  45. package/cjs/alert/global-alert/title/GlobalAlertTitle.d.ts +17 -0
  46. package/cjs/alert/global-alert/title/GlobalAlertTitle.js +19 -0
  47. package/cjs/alert/global-alert/title/GlobalAlertTitle.js.map +1 -0
  48. package/cjs/alert/info-card/content/InfoCardContent.d.ts +18 -0
  49. package/cjs/alert/info-card/content/InfoCardContent.js +20 -0
  50. package/cjs/alert/info-card/content/InfoCardContent.js.map +1 -0
  51. package/cjs/alert/info-card/header/InfoCardHeader.d.ts +16 -0
  52. package/cjs/alert/info-card/header/InfoCardHeader.js +18 -0
  53. package/cjs/alert/info-card/header/InfoCardHeader.js.map +1 -0
  54. package/cjs/alert/info-card/index.d.ts +2 -0
  55. package/cjs/alert/info-card/index.js +10 -0
  56. package/cjs/alert/info-card/index.js.map +1 -0
  57. package/cjs/alert/info-card/root/InfoCardRoot.d.ts +76 -0
  58. package/cjs/alert/info-card/root/InfoCardRoot.js +78 -0
  59. package/cjs/alert/info-card/root/InfoCardRoot.js.map +1 -0
  60. package/cjs/alert/info-card/title/InfoCardTitle.d.ts +17 -0
  61. package/cjs/alert/info-card/title/InfoCardTitle.js +19 -0
  62. package/cjs/alert/info-card/title/InfoCardTitle.js.map +1 -0
  63. package/cjs/alert/local-alert/close-button/LocalAlertCloseButton.d.ts +17 -0
  64. package/cjs/alert/local-alert/close-button/LocalAlertCloseButton.js +19 -0
  65. package/cjs/alert/local-alert/close-button/LocalAlertCloseButton.js.map +1 -0
  66. package/cjs/alert/local-alert/content/LocalAlertContent.d.ts +18 -0
  67. package/cjs/alert/local-alert/content/LocalAlertContent.js +20 -0
  68. package/cjs/alert/local-alert/content/LocalAlertContent.js.map +1 -0
  69. package/cjs/alert/local-alert/header/LocalAlertHeader.d.ts +17 -0
  70. package/cjs/alert/local-alert/header/LocalAlertHeader.js +54 -0
  71. package/cjs/alert/local-alert/header/LocalAlertHeader.js.map +1 -0
  72. package/cjs/alert/local-alert/index.d.ts +2 -0
  73. package/cjs/alert/local-alert/index.js +11 -0
  74. package/cjs/alert/local-alert/index.js.map +1 -0
  75. package/cjs/alert/local-alert/root/LocalAlertRoot.d.ts +81 -0
  76. package/cjs/alert/local-alert/root/LocalAlertRoot.js +81 -0
  77. package/cjs/alert/local-alert/root/LocalAlertRoot.js.map +1 -0
  78. package/cjs/alert/local-alert/title/LocalAlertTitle.d.ts +17 -0
  79. package/cjs/alert/local-alert/title/LocalAlertTitle.js +19 -0
  80. package/cjs/alert/local-alert/title/LocalAlertTitle.js.map +1 -0
  81. package/cjs/date/Date.locale.d.ts +5 -0
  82. package/cjs/index.d.ts +4 -0
  83. package/cjs/index.js +9 -1
  84. package/cjs/index.js.map +1 -1
  85. package/cjs/inline-message/icon/InlineMessageIcon.d.ts +5 -0
  86. package/cjs/inline-message/icon/InlineMessageIcon.js +24 -0
  87. package/cjs/inline-message/icon/InlineMessageIcon.js.map +1 -0
  88. package/cjs/inline-message/index.d.ts +2 -0
  89. package/cjs/inline-message/index.js +7 -0
  90. package/cjs/inline-message/index.js.map +1 -0
  91. package/cjs/inline-message/root/InlineMessage.d.ts +36 -0
  92. package/cjs/inline-message/root/InlineMessage.js +91 -0
  93. package/cjs/inline-message/root/InlineMessage.js.map +1 -0
  94. package/cjs/timeline/period/ClickablePeriod.js +3 -15
  95. package/cjs/timeline/period/ClickablePeriod.js.map +1 -1
  96. package/cjs/timeline/pin/PinInternal.js +3 -15
  97. package/cjs/timeline/pin/PinInternal.js.map +1 -1
  98. package/cjs/util/i18n/locales/en.d.ts +1 -4
  99. package/cjs/util/i18n/locales/en.js +1 -4
  100. package/cjs/util/i18n/locales/en.js.map +1 -1
  101. package/cjs/util/i18n/locales/nb.d.ts +2 -6
  102. package/cjs/util/i18n/locales/nb.js +2 -6
  103. package/cjs/util/i18n/locales/nb.js.map +1 -1
  104. package/cjs/util/i18n/locales/nn.d.ts +1 -4
  105. package/cjs/util/i18n/locales/nn.js +1 -4
  106. package/cjs/util/i18n/locales/nn.js.map +1 -1
  107. package/esm/alert/Alert.js +2 -4
  108. package/esm/alert/Alert.js.map +1 -1
  109. package/esm/alert/base-alert/close-button/BaseAlertCloseButton.d.ts +17 -0
  110. package/esm/alert/base-alert/close-button/BaseAlertCloseButton.js +36 -0
  111. package/esm/alert/base-alert/close-button/BaseAlertCloseButton.js.map +1 -0
  112. package/esm/alert/base-alert/content/BaseAlertContent.d.ts +20 -0
  113. package/esm/alert/base-alert/content/BaseAlertContent.js +34 -0
  114. package/esm/alert/base-alert/content/BaseAlertContent.js.map +1 -0
  115. package/esm/alert/base-alert/header/BaseAlertHeader.d.ts +22 -0
  116. package/esm/alert/base-alert/header/BaseAlertHeader.js +41 -0
  117. package/esm/alert/base-alert/header/BaseAlertHeader.js.map +1 -0
  118. package/esm/alert/base-alert/index.d.ts +1 -0
  119. package/esm/alert/base-alert/index.js +3 -0
  120. package/esm/alert/base-alert/index.js.map +1 -0
  121. package/esm/alert/base-alert/namespace.d.ts +10 -0
  122. package/esm/alert/base-alert/namespace.js +6 -0
  123. package/esm/alert/base-alert/namespace.js.map +1 -0
  124. package/esm/alert/base-alert/root/BaseAlertRoot.context.d.ts +12 -0
  125. package/esm/alert/base-alert/root/BaseAlertRoot.context.js +7 -0
  126. package/esm/alert/base-alert/root/BaseAlertRoot.context.js.map +1 -0
  127. package/esm/alert/base-alert/root/BaseAlertRoot.d.ts +43 -0
  128. package/esm/alert/base-alert/root/BaseAlertRoot.js +29 -0
  129. package/esm/alert/base-alert/root/BaseAlertRoot.js.map +1 -0
  130. package/esm/alert/base-alert/root/BaseAlertRoot.utils.d.ts +9 -0
  131. package/esm/alert/base-alert/root/BaseAlertRoot.utils.js +42 -0
  132. package/esm/alert/base-alert/root/BaseAlertRoot.utils.js.map +1 -0
  133. package/esm/alert/base-alert/title/BaseAlertTitle.d.ts +24 -0
  134. package/esm/alert/base-alert/title/BaseAlertTitle.js +38 -0
  135. package/esm/alert/base-alert/title/BaseAlertTitle.js.map +1 -0
  136. package/esm/alert/global-alert/close-button/GlobalAlertCloseButton.d.ts +17 -0
  137. package/esm/alert/global-alert/close-button/GlobalAlertCloseButton.js +16 -0
  138. package/esm/alert/global-alert/close-button/GlobalAlertCloseButton.js.map +1 -0
  139. package/esm/alert/global-alert/content/GlobalAlertContent.d.ts +18 -0
  140. package/esm/alert/global-alert/content/GlobalAlertContent.js +17 -0
  141. package/esm/alert/global-alert/content/GlobalAlertContent.js.map +1 -0
  142. package/esm/alert/global-alert/header/GlobalAlertHeader.d.ts +17 -0
  143. package/esm/alert/global-alert/header/GlobalAlertHeader.js +18 -0
  144. package/esm/alert/global-alert/header/GlobalAlertHeader.js.map +1 -0
  145. package/esm/alert/global-alert/index.d.ts +2 -0
  146. package/esm/alert/global-alert/index.js +3 -0
  147. package/esm/alert/global-alert/index.js.map +1 -0
  148. package/esm/alert/global-alert/root/GlobalAlertRoot.d.ts +81 -0
  149. package/esm/alert/global-alert/root/GlobalAlertRoot.js +30 -0
  150. package/esm/alert/global-alert/root/GlobalAlertRoot.js.map +1 -0
  151. package/esm/alert/global-alert/title/GlobalAlertTitle.d.ts +17 -0
  152. package/esm/alert/global-alert/title/GlobalAlertTitle.js +16 -0
  153. package/esm/alert/global-alert/title/GlobalAlertTitle.js.map +1 -0
  154. package/esm/alert/info-card/content/InfoCardContent.d.ts +18 -0
  155. package/esm/alert/info-card/content/InfoCardContent.js +17 -0
  156. package/esm/alert/info-card/content/InfoCardContent.js.map +1 -0
  157. package/esm/alert/info-card/header/InfoCardHeader.d.ts +16 -0
  158. package/esm/alert/info-card/header/InfoCardHeader.js +15 -0
  159. package/esm/alert/info-card/header/InfoCardHeader.js.map +1 -0
  160. package/esm/alert/info-card/index.d.ts +2 -0
  161. package/esm/alert/info-card/index.js +3 -0
  162. package/esm/alert/info-card/index.js.map +1 -0
  163. package/esm/alert/info-card/root/InfoCardRoot.d.ts +76 -0
  164. package/esm/alert/info-card/root/InfoCardRoot.js +40 -0
  165. package/esm/alert/info-card/root/InfoCardRoot.js.map +1 -0
  166. package/esm/alert/info-card/title/InfoCardTitle.d.ts +17 -0
  167. package/esm/alert/info-card/title/InfoCardTitle.js +16 -0
  168. package/esm/alert/info-card/title/InfoCardTitle.js.map +1 -0
  169. package/esm/alert/local-alert/close-button/LocalAlertCloseButton.d.ts +17 -0
  170. package/esm/alert/local-alert/close-button/LocalAlertCloseButton.js +16 -0
  171. package/esm/alert/local-alert/close-button/LocalAlertCloseButton.js.map +1 -0
  172. package/esm/alert/local-alert/content/LocalAlertContent.d.ts +18 -0
  173. package/esm/alert/local-alert/content/LocalAlertContent.js +17 -0
  174. package/esm/alert/local-alert/content/LocalAlertContent.js.map +1 -0
  175. package/esm/alert/local-alert/header/LocalAlertHeader.d.ts +17 -0
  176. package/esm/alert/local-alert/header/LocalAlertHeader.js +18 -0
  177. package/esm/alert/local-alert/header/LocalAlertHeader.js.map +1 -0
  178. package/esm/alert/local-alert/index.d.ts +2 -0
  179. package/esm/alert/local-alert/index.js +3 -0
  180. package/esm/alert/local-alert/index.js.map +1 -0
  181. package/esm/alert/local-alert/root/LocalAlertRoot.d.ts +81 -0
  182. package/esm/alert/local-alert/root/LocalAlertRoot.js +42 -0
  183. package/esm/alert/local-alert/root/LocalAlertRoot.js.map +1 -0
  184. package/esm/alert/local-alert/title/LocalAlertTitle.d.ts +17 -0
  185. package/esm/alert/local-alert/title/LocalAlertTitle.js +16 -0
  186. package/esm/alert/local-alert/title/LocalAlertTitle.js.map +1 -0
  187. package/esm/date/Date.locale.d.ts +5 -0
  188. package/esm/index.d.ts +4 -0
  189. package/esm/index.js +4 -0
  190. package/esm/index.js.map +1 -1
  191. package/esm/inline-message/icon/InlineMessageIcon.d.ts +5 -0
  192. package/esm/inline-message/icon/InlineMessageIcon.js +19 -0
  193. package/esm/inline-message/icon/InlineMessageIcon.js.map +1 -0
  194. package/esm/inline-message/index.d.ts +2 -0
  195. package/esm/inline-message/index.js +3 -0
  196. package/esm/inline-message/index.js.map +1 -0
  197. package/esm/inline-message/root/InlineMessage.d.ts +36 -0
  198. package/esm/inline-message/root/InlineMessage.js +52 -0
  199. package/esm/inline-message/root/InlineMessage.js.map +1 -0
  200. package/esm/timeline/period/ClickablePeriod.js +6 -18
  201. package/esm/timeline/period/ClickablePeriod.js.map +1 -1
  202. package/esm/timeline/pin/PinInternal.js +6 -18
  203. package/esm/timeline/pin/PinInternal.js.map +1 -1
  204. package/esm/util/i18n/locales/en.d.ts +1 -4
  205. package/esm/util/i18n/locales/en.js +1 -4
  206. package/esm/util/i18n/locales/en.js.map +1 -1
  207. package/esm/util/i18n/locales/nb.d.ts +2 -6
  208. package/esm/util/i18n/locales/nb.js +2 -6
  209. package/esm/util/i18n/locales/nb.js.map +1 -1
  210. package/esm/util/i18n/locales/nn.d.ts +1 -4
  211. package/esm/util/i18n/locales/nn.js +1 -4
  212. package/esm/util/i18n/locales/nn.js.map +1 -1
  213. package/package.json +45 -4
  214. package/src/alert/Alert.tsx +2 -10
  215. package/src/alert/base-alert/close-button/BaseAlertCloseButton.tsx +44 -0
  216. package/src/alert/base-alert/content/BaseAlertContent.tsx +43 -0
  217. package/src/alert/base-alert/header/BaseAlertHeader.tsx +61 -0
  218. package/src/alert/base-alert/index.ts +2 -0
  219. package/src/alert/base-alert/namespace.ts +11 -0
  220. package/src/alert/base-alert/root/BaseAlertRoot.context.tsx +17 -0
  221. package/src/alert/base-alert/root/BaseAlertRoot.tsx +102 -0
  222. package/src/alert/base-alert/root/BaseAlertRoot.utils.tsx +67 -0
  223. package/src/alert/base-alert/title/BaseAlertTitle.tsx +63 -0
  224. package/src/alert/global-alert/close-button/GlobalAlertCloseButton.tsx +20 -0
  225. package/src/alert/global-alert/content/GlobalAlertContent.tsx +21 -0
  226. package/src/alert/global-alert/header/GlobalAlertHeader.tsx +24 -0
  227. package/src/alert/global-alert/index.ts +16 -0
  228. package/src/alert/global-alert/root/GlobalAlertRoot.tsx +132 -0
  229. package/src/alert/global-alert/title/GlobalAlertTitle.tsx +20 -0
  230. package/src/alert/info-card/content/InfoCardContent.tsx +21 -0
  231. package/src/alert/info-card/header/InfoCardHeader.tsx +19 -0
  232. package/src/alert/info-card/index.ts +14 -0
  233. package/src/alert/info-card/root/InfoCardRoot.tsx +120 -0
  234. package/src/alert/info-card/title/InfoCardTitle.tsx +20 -0
  235. package/src/alert/local-alert/close-button/LocalAlertCloseButton.tsx +20 -0
  236. package/src/alert/local-alert/content/LocalAlertContent.tsx +21 -0
  237. package/src/alert/local-alert/header/LocalAlertHeader.tsx +24 -0
  238. package/src/alert/local-alert/index.ts +16 -0
  239. package/src/alert/local-alert/root/LocalAlertRoot.tsx +133 -0
  240. package/src/alert/local-alert/title/LocalAlertTitle.tsx +20 -0
  241. package/src/index.ts +24 -0
  242. package/src/inline-message/icon/InlineMessageIcon.tsx +33 -0
  243. package/src/inline-message/index.ts +3 -0
  244. package/src/inline-message/root/InlineMessage.tsx +92 -0
  245. package/src/timeline/period/ClickablePeriod.tsx +5 -34
  246. package/src/timeline/pin/PinInternal.tsx +5 -28
  247. package/src/util/i18n/locales/en.ts +1 -5
  248. package/src/util/i18n/locales/nb.ts +1 -5
  249. package/src/util/i18n/locales/nn.ts +1 -5
  250. package/cjs/util/renderStoriesForChromatic.d.ts +0 -5
  251. package/cjs/util/renderStoriesForChromatic.js +0 -21
  252. package/cjs/util/renderStoriesForChromatic.js.map +0 -1
  253. package/esm/util/renderStoriesForChromatic.d.ts +0 -5
  254. package/esm/util/renderStoriesForChromatic.js +0 -15
  255. package/esm/util/renderStoriesForChromatic.js.map +0 -1
  256. package/src/util/renderStoriesForChromatic.tsx +0 -26
@@ -0,0 +1,44 @@
1
+ import React, { forwardRef } from "react";
2
+ import { XMarkIcon } from "@navikt/aksel-icons";
3
+ import { Button } from "../../../button";
4
+ import { useRenameCSS } from "../../../theme/Theme";
5
+ import { useI18n } from "../../../util/i18n/i18n.hooks";
6
+
7
+ type BaseAlertCloseButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>;
8
+
9
+ /**
10
+ * @see 🏷️ {@link BaseAlertCloseButtonProps}
11
+ * @example
12
+ * ```jsx
13
+ * <BaseAlert>
14
+ * <BaseAlert.Header>
15
+ * <BaseAlert.Title>Info title</BaseAlert.Title>
16
+ * <BaseAlert.CloseButton onClick={...} />
17
+ * </BaseAlert.Header>
18
+ * </BaseAlert>
19
+ * ```
20
+ */
21
+ const BaseAlertCloseButton = forwardRef<
22
+ HTMLButtonElement,
23
+ BaseAlertCloseButtonProps
24
+ >(({ className, ...restProps }: BaseAlertCloseButtonProps, forwardedRef) => {
25
+ const { cn } = useRenameCSS();
26
+ const translate = useI18n("global");
27
+
28
+ return (
29
+ <Button
30
+ ref={forwardedRef}
31
+ type="button"
32
+ {...restProps}
33
+ data-color="neutral"
34
+ variant="tertiary-neutral"
35
+ className={cn(className, "navds-base-alert__close-button")}
36
+ size="small"
37
+ title={translate("close")}
38
+ icon={<XMarkIcon aria-hidden />}
39
+ />
40
+ );
41
+ });
42
+
43
+ export { BaseAlertCloseButton };
44
+ export type { BaseAlertCloseButtonProps };
@@ -0,0 +1,43 @@
1
+ import React, { forwardRef } from "react";
2
+ import { useRenameCSS, useThemeInternal } from "../../../theme/Theme";
3
+
4
+ interface BaseAlertContentProps extends React.HTMLAttributes<HTMLDivElement> {
5
+ children: React.ReactNode;
6
+ }
7
+
8
+ /**
9
+ * @see 🏷️ {@link BaseAlertContentProps}
10
+ * @example
11
+ * ```jsx
12
+ * <BaseAlert>
13
+ * <BaseAlert.Header>
14
+ * <BaseAlert.Title>Info title</BaseAlert.Title>
15
+ * </BaseAlert.Header>
16
+ *
17
+ * <BaseAlert.Content>Content</BaseAlert.Content>
18
+ * </BaseAlert>
19
+ * ```
20
+ */
21
+ const BaseAlertContent = forwardRef<HTMLDivElement, BaseAlertContentProps>(
22
+ (
23
+ { children, className, ...restProps }: BaseAlertContentProps,
24
+ forwardedRef,
25
+ ) => {
26
+ const { cn } = useRenameCSS();
27
+ const themeContext = useThemeInternal(false);
28
+
29
+ return (
30
+ <div
31
+ ref={forwardedRef}
32
+ data-color={themeContext?.color}
33
+ {...restProps}
34
+ className={cn(className, "navds-base-alert__content")}
35
+ >
36
+ {children}
37
+ </div>
38
+ );
39
+ },
40
+ );
41
+
42
+ export { BaseAlertContent };
43
+ export type { BaseAlertContentProps };
@@ -0,0 +1,61 @@
1
+ import React, { forwardRef } from "react";
2
+ import { useRenameCSS } from "../../../theme/Theme";
3
+ import { BodyShort } from "../../../typography";
4
+ import { useI18n } from "../../../util/i18n/i18n.hooks";
5
+ import { useBaseAlert } from "../root/BaseAlertRoot.context";
6
+ import { BaseAlertStatusIcon } from "../root/BaseAlertRoot.utils";
7
+
8
+ interface BaseAlertHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
9
+ children: React.ReactNode;
10
+ /**
11
+ * Icon to display in the header.
12
+ */
13
+ icon?: React.ReactNode;
14
+ }
15
+
16
+ /**
17
+ * @see 🏷️ {@link BaseAlertHeaderProps}
18
+ * @example
19
+ * ```jsx
20
+ * <BaseAlert>
21
+ * <BaseAlert.Header icon={<InformationSquareIcon aria-hidden />}>
22
+ * <BaseAlert.Title>Info title</BaseAlert.Title>
23
+ * </BaseAlert.Header>
24
+ * </BaseAlert>
25
+ * ```
26
+ */
27
+ const BaseAlertHeader = forwardRef<HTMLDivElement, BaseAlertHeaderProps>(
28
+ (
29
+ { children, className, icon, ...restProps }: BaseAlertHeaderProps,
30
+ forwardedRef,
31
+ ) => {
32
+ const { cn } = useRenameCSS();
33
+ const { status, color, statusId } = useBaseAlert();
34
+ const translate = useI18n("global");
35
+
36
+ const headerIcon =
37
+ icon ?? (status ? <BaseAlertStatusIcon status={status} /> : null);
38
+
39
+ return (
40
+ <div
41
+ ref={forwardedRef}
42
+ {...restProps}
43
+ data-color={color}
44
+ className={cn(className, "navds-base-alert__header")}
45
+ >
46
+ {headerIcon && (
47
+ <div className={cn("navds-base-alert__icon")}>{headerIcon}</div>
48
+ )}
49
+ {status && (
50
+ <BodyShort id={statusId} aria-hidden visuallyHidden>
51
+ {`${translate(status)}: `}
52
+ </BodyShort>
53
+ )}
54
+ {children}
55
+ </div>
56
+ );
57
+ },
58
+ );
59
+
60
+ export { BaseAlertHeader };
61
+ export type { BaseAlertHeaderProps };
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ export * as BaseAlert from "./namespace";
@@ -0,0 +1,11 @@
1
+ export { BaseAlertCloseButton as CloseButton } from "./close-button/BaseAlertCloseButton";
2
+ export { BaseAlertContent as Content } from "./content/BaseAlertContent";
3
+ export { BaseAlertTitle as Title } from "./title/BaseAlertTitle";
4
+ export { BaseAlertHeader as Header } from "./header/BaseAlertHeader";
5
+ export { BaseAlert as Root } from "./root/BaseAlertRoot";
6
+
7
+ export type { BaseAlertCloseButtonProps as CloseButtonProps } from "./close-button/BaseAlertCloseButton";
8
+ export type { BaseAlertContentProps as ContentProps } from "./content/BaseAlertContent";
9
+ export type { BaseAlertTitleProps as TitleProps } from "./title/BaseAlertTitle";
10
+ export type { BaseAlertHeaderProps as HeaderProps } from "./header/BaseAlertHeader";
11
+ export type { BaseAlertProps as RootProps } from "./root/BaseAlertRoot";
@@ -0,0 +1,17 @@
1
+ import { AkselColor } from "../../../types";
2
+ import { createContext } from "../../../util/create-context";
3
+
4
+ type BaseAlertContextProps = {
5
+ size: "medium" | "small";
6
+ status?: "announcement" | "success" | "warning" | "error";
7
+ color: AkselColor | undefined;
8
+ statusId: string;
9
+ };
10
+
11
+ const [BaseAlertProvider, useBaseAlert] = createContext<BaseAlertContextProps>({
12
+ name: "BaseAlert",
13
+ errorMessage: "useBaseAlert must be used within a BaseAlertProvider",
14
+ });
15
+
16
+ export { BaseAlertProvider, useBaseAlert };
17
+ export type { BaseAlertContextProps };
@@ -0,0 +1,102 @@
1
+ import React, { forwardRef } from "react";
2
+ import { useRenameCSS } from "../../../theme/Theme";
3
+ import { AkselColor } from "../../../types";
4
+ import { useId } from "../../../util";
5
+ import { useI18n } from "../../../util/i18n/i18n.hooks";
6
+ import {
7
+ type BaseAlertContextProps,
8
+ BaseAlertProvider,
9
+ } from "./BaseAlertRoot.context";
10
+ import { baseAlertStatusToDataColor } from "./BaseAlertRoot.utils";
11
+
12
+ interface BaseAlertProps extends React.HTMLAttributes<HTMLDivElement> {
13
+ /**
14
+ * Component content.
15
+ */
16
+ children: React.ReactNode;
17
+ /**
18
+ * Changes the size.
19
+ * @default "medium"
20
+ */
21
+ size?: BaseAlertContextProps["size"];
22
+ /**
23
+ * Overrides color
24
+ */
25
+ "data-color"?: AkselColor;
26
+ /**
27
+ * Intensity of the alert
28
+ */
29
+ type: "moderate" | "strong";
30
+ /**
31
+ * Centers content and removes border-radius
32
+ * @default false
33
+ */
34
+ global?: boolean;
35
+ /**
36
+ * Type of alert
37
+ */
38
+ status?: BaseAlertContextProps["status"];
39
+ /**
40
+ * Changes the HTML element used for the root element.
41
+ *
42
+ * **Testing**: When using `axe-core` for accessibility testing, `section` might warn about unique landmarks if you have multiple Alerts on page with the same status.
43
+ * In those cases, consider using `div` as the root element, or adding unique `aria-label` or `aria-labelledby` props.
44
+ * @see [📝 Landmarks unique](https://dequeuniversity.com/rules/axe/4.6/landmark-unique)
45
+ * @default "section"
46
+ */
47
+ as?: "section" | "div";
48
+ }
49
+
50
+ const BaseAlert = forwardRef<HTMLDivElement, BaseAlertProps>(
51
+ (
52
+ {
53
+ children,
54
+ className,
55
+ size = "medium",
56
+ "data-color": dataColor,
57
+ type,
58
+ global = false,
59
+ status,
60
+ as: Component = "section",
61
+ "aria-label": ariaLabel,
62
+ role,
63
+ ...restProps
64
+ }: BaseAlertProps,
65
+ forwardedRef,
66
+ ) => {
67
+ const { cn } = useRenameCSS();
68
+
69
+ const statusId = useId();
70
+ const translate = useI18n("global");
71
+
72
+ const alertColor = status ? baseAlertStatusToDataColor(status) : dataColor;
73
+
74
+ return (
75
+ <BaseAlertProvider
76
+ size={size}
77
+ status={status}
78
+ color={alertColor}
79
+ statusId={statusId}
80
+ >
81
+ <Component
82
+ aria-label={
83
+ ariaLabel ??
84
+ (!status || Component === "div" ? undefined : translate(status))
85
+ }
86
+ ref={forwardedRef}
87
+ {...restProps}
88
+ className={cn(className, "navds-base-alert")}
89
+ data-size={size}
90
+ data-color={alertColor}
91
+ data-variant={type}
92
+ data-global={global}
93
+ >
94
+ <div role={role}>{children}</div>
95
+ </Component>
96
+ </BaseAlertProvider>
97
+ );
98
+ },
99
+ );
100
+
101
+ export { BaseAlert };
102
+ export type { BaseAlertProps };
@@ -0,0 +1,67 @@
1
+ import React from "react";
2
+ import {
3
+ CheckmarkCircleFillIcon,
4
+ CheckmarkCircleIcon,
5
+ ExclamationmarkTriangleFillIcon,
6
+ ExclamationmarkTriangleIcon,
7
+ MegaphoneSpeakingFillIcon,
8
+ MegaphoneSpeakingIcon,
9
+ XMarkOctagonFillIcon,
10
+ XMarkOctagonIcon,
11
+ } from "@navikt/aksel-icons";
12
+ import type { AkselColor } from "../../../types";
13
+ import type { BaseAlertContextProps } from "../root/BaseAlertRoot.context";
14
+
15
+ function baseAlertStatusToDataColor(
16
+ status: BaseAlertContextProps["status"],
17
+ ): AkselColor {
18
+ switch (status) {
19
+ case "announcement":
20
+ return "neutral";
21
+ case "success":
22
+ return "success";
23
+ case "warning":
24
+ return "warning";
25
+ case "error":
26
+ return "danger";
27
+ }
28
+
29
+ return "neutral";
30
+ }
31
+
32
+ const STATUS_ICONS = {
33
+ announcement: {
34
+ fill: MegaphoneSpeakingFillIcon,
35
+ outline: MegaphoneSpeakingIcon,
36
+ },
37
+ success: {
38
+ fill: CheckmarkCircleFillIcon,
39
+ outline: CheckmarkCircleIcon,
40
+ },
41
+ warning: {
42
+ fill: ExclamationmarkTriangleFillIcon,
43
+ outline: ExclamationmarkTriangleIcon,
44
+ },
45
+ error: {
46
+ fill: XMarkOctagonFillIcon,
47
+ outline: XMarkOctagonIcon,
48
+ },
49
+ } as const;
50
+
51
+ function BaseAlertStatusIcon({
52
+ status,
53
+ fill = true,
54
+ }: {
55
+ status: BaseAlertContextProps["status"];
56
+ fill?: boolean;
57
+ }) {
58
+ if (!status) {
59
+ return null;
60
+ }
61
+
62
+ const Icon = fill ? STATUS_ICONS[status].fill : STATUS_ICONS[status].outline;
63
+
64
+ return <Icon aria-hidden />;
65
+ }
66
+
67
+ export { BaseAlertStatusIcon, baseAlertStatusToDataColor };
@@ -0,0 +1,63 @@
1
+ import cl from "clsx";
2
+ import React, { forwardRef } from "react";
3
+ import { useRenameCSS } from "../../../theme/Theme";
4
+ import { BodyShort } from "../../../typography";
5
+ import { useId } from "../../../util";
6
+ import { useBaseAlert } from "../root/BaseAlertRoot.context";
7
+
8
+ interface BaseAlertTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {
9
+ children: React.ReactNode;
10
+ /**
11
+ * Changes the HTML element used for the title.
12
+ * @default "h2"
13
+ */
14
+ as?: "h2" | "h3" | "h4" | "h5" | "h6" | "div";
15
+ }
16
+
17
+ /**
18
+ * Title component for BaseAlert. Remember to use correct heading-level with the `as` prop.
19
+ * @see 🏷️ {@link BaseAlertTitleProps}
20
+ * @example
21
+ * ```jsx
22
+ * <BaseAlert>
23
+ * <BaseAlert.Header>
24
+ * <BaseAlert.Title as="h2">Info title</BaseAlert.Title>
25
+ * </BaseAlert.Header>
26
+ * </BaseAlert>
27
+ * ```
28
+ */
29
+ const BaseAlertTitle = forwardRef<HTMLHeadingElement, BaseAlertTitleProps>(
30
+ (
31
+ {
32
+ children,
33
+ className,
34
+ as = "h2",
35
+ id: idProp,
36
+ ...restProps
37
+ }: BaseAlertTitleProps,
38
+ forwardedRef,
39
+ ) => {
40
+ const { cn } = useRenameCSS();
41
+ const { size, statusId } = useBaseAlert();
42
+
43
+ const titleId = useId(idProp);
44
+
45
+ return (
46
+ <BodyShort
47
+ ref={forwardedRef}
48
+ {...restProps}
49
+ as={as}
50
+ size={size === "medium" ? "large" : "medium"}
51
+ weight="semibold"
52
+ className={cn(className, "navds-base-alert__title")}
53
+ id={titleId}
54
+ aria-labelledby={cl(statusId, titleId)}
55
+ >
56
+ {children}
57
+ </BodyShort>
58
+ );
59
+ },
60
+ );
61
+
62
+ export { BaseAlertTitle };
63
+ export type { BaseAlertTitleProps };
@@ -0,0 +1,20 @@
1
+ import { BaseAlert } from "../../base-alert";
2
+
3
+ type GlobalAlertCloseButtonProps = BaseAlert.CloseButtonProps;
4
+
5
+ /**
6
+ * @see 🏷️ {@link GlobalAlertCloseButtonProps}
7
+ * @example
8
+ * ```jsx
9
+ * <GlobalAlert>
10
+ * <GlobalAlert.Header>
11
+ * <GlobalAlert.Title>Info title</GlobalAlert.Title>
12
+ * <GlobalAlert.CloseButton onClick={() => alert("Closed!")} />
13
+ * </GlobalAlert.Header>
14
+ * </GlobalAlert>
15
+ * ```
16
+ */
17
+ const GlobalAlertCloseButton = BaseAlert.CloseButton;
18
+
19
+ export { GlobalAlertCloseButton };
20
+ export type { GlobalAlertCloseButtonProps };
@@ -0,0 +1,21 @@
1
+ import { BaseAlert } from "../../base-alert";
2
+
3
+ type GlobalAlertContentProps = BaseAlert.ContentProps;
4
+
5
+ /**
6
+ * @see 🏷️ {@link GlobalAlertContentProps}
7
+ * @example
8
+ * ```jsx
9
+ * <GlobalAlert>
10
+ * <GlobalAlert.Header>
11
+ * <GlobalAlert.Title>Info title</GlobalAlert.Title>
12
+ * </GlobalAlert.Header>
13
+ *
14
+ * <GlobalAlert.Content>Content</GlobalAlert.Content>
15
+ * </GlobalAlert>
16
+ * ```
17
+ */
18
+ const GlobalAlertContent = BaseAlert.Content;
19
+
20
+ export { GlobalAlertContent };
21
+ export type { GlobalAlertContentProps };
@@ -0,0 +1,24 @@
1
+ import React, { forwardRef } from "react";
2
+ import { BaseAlert } from "../../base-alert";
3
+
4
+ type GlobalAlertHeaderProps = Omit<BaseAlert.HeaderProps, "icon">;
5
+
6
+ /**
7
+ * @see 🏷️ {@link GlobalAlertHeaderProps}
8
+ * @example
9
+ * ```jsx
10
+ * <GlobalAlert status="success">
11
+ * <GlobalAlert.Header>
12
+ * <GlobalAlert.Title>Info title</GlobalAlert.Title>
13
+ * </GlobalAlert.Header>
14
+ * </GlobalAlert>
15
+ * ```
16
+ */
17
+ const GlobalAlertHeader = forwardRef<HTMLDivElement, GlobalAlertHeaderProps>(
18
+ (props, forwardedRef) => {
19
+ return <BaseAlert.Header ref={forwardedRef} {...props} />;
20
+ },
21
+ );
22
+
23
+ export { GlobalAlertHeader };
24
+ export type { GlobalAlertHeaderProps };
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ export {
3
+ GlobalAlert,
4
+ GlobalAlertHeader,
5
+ GlobalAlertTitle,
6
+ GlobalAlertContent,
7
+ GlobalAlertCloseButton,
8
+ } from "./root/GlobalAlertRoot";
9
+
10
+ export type {
11
+ GlobalAlertProps,
12
+ GlobalAlertHeaderProps,
13
+ GlobalAlertTitleProps,
14
+ GlobalAlertContentProps,
15
+ GlobalAlertCloseButtonProps,
16
+ } from "./root/GlobalAlertRoot";
@@ -0,0 +1,132 @@
1
+ import React, { forwardRef } from "react";
2
+ import { BaseAlert } from "../../base-alert";
3
+ import {
4
+ GlobalAlertCloseButton,
5
+ type GlobalAlertCloseButtonProps,
6
+ } from "../close-button/GlobalAlertCloseButton";
7
+ import {
8
+ GlobalAlertContent,
9
+ type GlobalAlertContentProps,
10
+ } from "../content/GlobalAlertContent";
11
+ import {
12
+ GlobalAlertHeader,
13
+ type GlobalAlertHeaderProps,
14
+ } from "../header/GlobalAlertHeader";
15
+ import {
16
+ GlobalAlertTitle,
17
+ type GlobalAlertTitleProps,
18
+ } from "../title/GlobalAlertTitle";
19
+
20
+ interface GlobalAlertProps
21
+ extends Omit<BaseAlert.RootProps, "type" | "global" | "data-color"> {
22
+ status: Exclude<BaseAlert.RootProps["status"], undefined>;
23
+ }
24
+
25
+ interface GlobalAlertComponent
26
+ extends React.ForwardRefExoticComponent<
27
+ GlobalAlertProps & React.RefAttributes<HTMLDivElement>
28
+ > {
29
+ /**
30
+ * @see 🏷️ {@link GlobalAlertHeaderProps}
31
+ * @example
32
+ * ```jsx
33
+ * <GlobalAlert>
34
+ * <GlobalAlert.Header>
35
+ * <GlobalAlert.Title>Info title</GlobalAlert.Title>
36
+ * </GlobalAlert.Header>
37
+ * </GlobalAlert>
38
+ * ```
39
+ */
40
+ Header: typeof GlobalAlertHeader;
41
+
42
+ /**
43
+ * Title component for GlobalAlert. Remember to use correct heading-level with the `as` prop.
44
+ * @see 🏷️ {@link GlobalAlertTitleProps}
45
+ * @example
46
+ * ```jsx
47
+ * <GlobalAlert>
48
+ * <GlobalAlert.Header>
49
+ * <GlobalAlert.Title as="h2">Info title</GlobalAlert.Title>
50
+ * </GlobalAlert.Header>
51
+ * </GlobalAlert>
52
+ * ```
53
+ */
54
+ Title: typeof GlobalAlertTitle;
55
+
56
+ /**
57
+ * @see 🏷️ {@link GlobalAlertContentProps}
58
+ * @example
59
+ * ```jsx
60
+ * <GlobalAlert>
61
+ * <GlobalAlert.Header>
62
+ * <GlobalAlert.Title>Info title</GlobalAlert.Title>
63
+ * </GlobalAlert.Header>
64
+ *
65
+ * <GlobalAlert.Content>Content</GlobalAlert.Content>
66
+ * </GlobalAlert>
67
+ * ```
68
+ */
69
+ Content: typeof GlobalAlertContent;
70
+
71
+ /**
72
+ * @see 🏷️ {@link GlobalAlertCloseProps}
73
+ * @example
74
+ * ```jsx
75
+ * <GlobalAlert>
76
+ * <GlobalAlert.Header>
77
+ * <GlobalAlert.Title>Info title</GlobalAlert.Title>
78
+ * <GlobalAlert.CloseButton onClick={() => alert("Closed!")} />
79
+ * </GlobalAlert.Header>
80
+ * </GlobalAlert>
81
+ * ```
82
+ */
83
+ CloseButton: typeof GlobalAlertCloseButton;
84
+ }
85
+
86
+ /**
87
+ * A component for displaying alerts about your app.
88
+ * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/globalalert)
89
+ * @see 🏷️ {@link GlobalAlertProps}
90
+ * @example
91
+ * ```jsx
92
+ * <GlobalAlert status="error">
93
+ * <GlobalAlert.Header>
94
+ * <GlobalAlert.Title>Alert title</GlobalAlert.Title>
95
+ * </GlobalAlert.Header>
96
+ * <GlobalAlert.Content>Content</GlobalAlert.Content>
97
+ * </GlobalAlert>
98
+ * ```
99
+ */
100
+ export const GlobalAlert = forwardRef<HTMLDivElement, GlobalAlertProps>(
101
+ (props: GlobalAlertProps, forwardedRef) => {
102
+ return (
103
+ <BaseAlert.Root
104
+ ref={forwardedRef}
105
+ role="alert"
106
+ {...props}
107
+ type="strong"
108
+ global
109
+ />
110
+ );
111
+ },
112
+ ) as GlobalAlertComponent;
113
+
114
+ GlobalAlert.Header = GlobalAlertHeader;
115
+ GlobalAlert.Title = GlobalAlertTitle;
116
+ GlobalAlert.Content = GlobalAlertContent;
117
+ GlobalAlert.CloseButton = GlobalAlertCloseButton;
118
+
119
+ export default GlobalAlert;
120
+ export {
121
+ GlobalAlertCloseButton,
122
+ GlobalAlertContent,
123
+ GlobalAlertHeader,
124
+ GlobalAlertTitle,
125
+ };
126
+ export type {
127
+ GlobalAlertCloseButtonProps,
128
+ GlobalAlertContentProps,
129
+ GlobalAlertHeaderProps,
130
+ GlobalAlertProps,
131
+ GlobalAlertTitleProps,
132
+ };
@@ -0,0 +1,20 @@
1
+ import { BaseAlert } from "../../base-alert";
2
+
3
+ type GlobalAlertTitleProps = BaseAlert.TitleProps;
4
+
5
+ /**
6
+ * Title component for GlobalAlert. Remember to use correct heading-level with the `as` prop.
7
+ * @see 🏷️ {@link GlobalAlertTitleProps}
8
+ * @example
9
+ * ```jsx
10
+ * <GlobalAlert>
11
+ * <GlobalAlert.Header>
12
+ * <GlobalAlert.Title as="h2">Info title</GlobalAlert.Title>
13
+ * </GlobalAlert.Header>
14
+ * </GlobalAlert>
15
+ * ```
16
+ */
17
+ const GlobalAlertTitle = BaseAlert.Title;
18
+
19
+ export { GlobalAlertTitle };
20
+ export type { GlobalAlertTitleProps };
@@ -0,0 +1,21 @@
1
+ import { BaseAlert } from "../../base-alert";
2
+
3
+ type InfoCardContentProps = BaseAlert.ContentProps;
4
+
5
+ /**
6
+ * @see 🏷️ {@link InfoCardContentProps}
7
+ * @example
8
+ * ```jsx
9
+ * <InfoCard>
10
+ * <InfoCard.Header>
11
+ * <InfoCard.Title>Info title</InfoCard.Title>
12
+ * </InfoCard.Header>
13
+ *
14
+ * <InfoCard.Content>Content</InfoCard.Content>
15
+ * </InfoCard>
16
+ * ```
17
+ */
18
+ const InfoCardContent = BaseAlert.Content;
19
+
20
+ export { InfoCardContent };
21
+ export type { InfoCardContentProps };