@helsenorge/designsystem-react 2.3.0 → 2.5.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 (383) hide show
  1. package/Button.js +1 -1
  2. package/Button.js.map +1 -1
  3. package/CHANGELOG.md +22 -2
  4. package/FormGroup.js +1 -1
  5. package/FormGroup.js.map +1 -1
  6. package/HelpBubble.js +1 -1
  7. package/HelpBubble.js.map +1 -1
  8. package/Input.js +1 -1
  9. package/Input.js.map +1 -1
  10. package/Modal.js +1 -1
  11. package/Modal.js.map +1 -1
  12. package/Panel.js +1 -1
  13. package/Panel.js.map +1 -1
  14. package/Select.js +2 -0
  15. package/Select.js.map +1 -0
  16. package/Textarea.js +1 -1
  17. package/Textarea.js.map +1 -1
  18. package/Tooltip.js +1 -1
  19. package/Tooltip.js.map +1 -1
  20. package/TooltipWord.js +2 -0
  21. package/TooltipWord.js.map +1 -0
  22. package/__mocks__/uuid.js +1 -1
  23. package/__mocks__/uuid.js.map +1 -1
  24. package/components/AnchorLink/index.js +1 -1
  25. package/components/Avatar/index.js +1 -1
  26. package/components/Avatar/index.js.map +1 -1
  27. package/components/Button/index.js +1 -1
  28. package/components/ButtonWithModal/index.js +1 -1
  29. package/components/ButtonWithModal/index.js.map +1 -1
  30. package/components/Checkbox/index.js +1 -1
  31. package/components/Close/index.js +1 -1
  32. package/components/Dropdown/index.js +1 -1
  33. package/components/Dropdown/index.js.map +1 -1
  34. package/components/Duolist/Duolist.d.ts +6 -4
  35. package/components/Duolist/Duolist.d.ts.map +1 -1
  36. package/components/Duolist/componentdata.json +1 -1
  37. package/components/Duolist/index.js +1 -1
  38. package/components/Duolist/index.js.map +1 -1
  39. package/components/Duolist/styles.module.scss +0 -1
  40. package/components/Expander/index.js +1 -1
  41. package/components/Expander/index.js.map +1 -1
  42. package/components/ExpanderList/index.js +1 -1
  43. package/components/ExpanderList/index.js.map +1 -1
  44. package/components/FormExample/FormExample.d.ts +2 -1
  45. package/components/FormExample/FormExample.d.ts.map +1 -1
  46. package/components/FormExample/componentdata.json +1 -1
  47. package/components/FormExample/index.js +3 -3
  48. package/components/FormExample/index.js.map +1 -1
  49. package/components/FormGroup/FormGroup.d.ts.map +1 -1
  50. package/components/FormGroup/index.js +1 -1
  51. package/components/HelpBubble/HelpBubble.d.ts +8 -5
  52. package/components/HelpBubble/HelpBubble.d.ts.map +1 -1
  53. package/components/HelpBubble/componentdata.json +1 -1
  54. package/components/HelpBubble/index.js +1 -1
  55. package/components/HelpBubble/styles.module.scss +41 -34
  56. package/components/HelpBubble/styles.module.scss.d.ts +9 -10
  57. package/components/HelpBubble/utils.d.ts +27 -0
  58. package/components/HelpBubble/utils.d.ts.map +1 -0
  59. package/components/HelpBubbleExample/componentdata.json +1 -1
  60. package/components/HelpBubbleExample/index.js +1 -1
  61. package/components/HelpBubbleExample/index.js.map +1 -1
  62. package/components/HighlightBox/index.js +1 -1
  63. package/components/HighlightBox/index.js.map +1 -1
  64. package/components/HorizontalScroll/index.js +1 -1
  65. package/components/HorizontalScroll/styles.module.scss +2 -2
  66. package/components/Icons/AcupunctureBack.js +1 -1
  67. package/components/Icons/AcupunctureBack.js.map +1 -1
  68. package/components/Icons/AlarmClock.js +1 -1
  69. package/components/Icons/AlarmClock.js.map +1 -1
  70. package/components/Icons/AlertSignFill.js +1 -1
  71. package/components/Icons/AlertSignFill.js.map +1 -1
  72. package/components/Icons/AlertSignStroke.js +1 -1
  73. package/components/Icons/AlertSignStroke.js.map +1 -1
  74. package/components/Icons/Archive.js +1 -1
  75. package/components/Icons/Archive.js.map +1 -1
  76. package/components/Icons/ArrowDown.js +1 -1
  77. package/components/Icons/ArrowDown.js.map +1 -1
  78. package/components/Icons/ArrowLeft.js +1 -1
  79. package/components/Icons/ArrowLeft.js.map +1 -1
  80. package/components/Icons/ArrowRight.js +1 -1
  81. package/components/Icons/ArrowRight.js.map +1 -1
  82. package/components/Icons/ArrowUp.js +1 -1
  83. package/components/Icons/ArrowUp.js.map +1 -1
  84. package/components/Icons/ArrowUpRight.js +1 -1
  85. package/components/Icons/ArrowUpRight.js.map +1 -1
  86. package/components/Icons/Attachment.js +1 -1
  87. package/components/Icons/Attachment.js.map +1 -1
  88. package/components/Icons/Avatar.js +1 -1
  89. package/components/Icons/Avatar.js.map +1 -1
  90. package/components/Icons/Bus.js +1 -1
  91. package/components/Icons/Bus.js.map +1 -1
  92. package/components/Icons/Calendar.js +1 -1
  93. package/components/Icons/Calendar.js.map +1 -1
  94. package/components/Icons/CalendarChange.js +1 -1
  95. package/components/Icons/CalendarChange.js.map +1 -1
  96. package/components/Icons/CalendarCheck.js +1 -1
  97. package/components/Icons/CalendarCheck.js.map +1 -1
  98. package/components/Icons/CalendarSave.js +1 -1
  99. package/components/Icons/CalendarSave.js.map +1 -1
  100. package/components/Icons/Change.js +1 -1
  101. package/components/Icons/Change.js.map +1 -1
  102. package/components/Icons/Check.js +1 -1
  103. package/components/Icons/Check.js.map +1 -1
  104. package/components/Icons/CheckFill.js +1 -1
  105. package/components/Icons/CheckFill.js.map +1 -1
  106. package/components/Icons/ChevronDown.js +1 -1
  107. package/components/Icons/ChevronDown.js.map +1 -1
  108. package/components/Icons/ChevronLeft.js +1 -1
  109. package/components/Icons/ChevronLeft.js.map +1 -1
  110. package/components/Icons/ChevronRight.js +1 -1
  111. package/components/Icons/ChevronRight.js.map +1 -1
  112. package/components/Icons/ChevronUp.js +1 -1
  113. package/components/Icons/ChevronUp.js.map +1 -1
  114. package/components/Icons/ChevronsDown.js +1 -1
  115. package/components/Icons/ChevronsDown.js.map +1 -1
  116. package/components/Icons/ChevronsUp.js +1 -1
  117. package/components/Icons/ChevronsUp.js.map +1 -1
  118. package/components/Icons/Contacts.js +1 -1
  119. package/components/Icons/Contacts.js.map +1 -1
  120. package/components/Icons/Copy.js +1 -1
  121. package/components/Icons/Copy.js.map +1 -1
  122. package/components/Icons/Download.js +1 -1
  123. package/components/Icons/Download.js.map +1 -1
  124. package/components/Icons/EChat.js +1 -1
  125. package/components/Icons/EChat.js.map +1 -1
  126. package/components/Icons/EnterFullScreen.js +1 -1
  127. package/components/Icons/EnterFullScreen.js.map +1 -1
  128. package/components/Icons/Envelope.js +1 -1
  129. package/components/Icons/Envelope.js.map +1 -1
  130. package/components/Icons/Eraser.js +1 -1
  131. package/components/Icons/Eraser.js.map +1 -1
  132. package/components/Icons/ErrorSignFill.js +1 -1
  133. package/components/Icons/ErrorSignFill.js.map +1 -1
  134. package/components/Icons/ErrorSignStroke.js +1 -1
  135. package/components/Icons/ErrorSignStroke.js.map +1 -1
  136. package/components/Icons/ExitFullScreen.js +1 -1
  137. package/components/Icons/ExitFullScreen.js.map +1 -1
  138. package/components/Icons/Eye.js +1 -1
  139. package/components/Icons/Eye.js.map +1 -1
  140. package/components/Icons/Form.js +1 -1
  141. package/components/Icons/Form.js.map +1 -1
  142. package/components/Icons/Forward.js +1 -1
  143. package/components/Icons/Forward.js.map +1 -1
  144. package/components/Icons/Gallery.js +1 -1
  145. package/components/Icons/Gallery.js.map +1 -1
  146. package/components/Icons/Globe.js +1 -1
  147. package/components/Icons/Globe.js.map +1 -1
  148. package/components/Icons/Group.js +1 -1
  149. package/components/Icons/Group.js.map +1 -1
  150. package/components/Icons/Heart.js +1 -1
  151. package/components/Icons/Heart.js.map +1 -1
  152. package/components/Icons/HelpSign.js +1 -1
  153. package/components/Icons/HelpSign.js.map +1 -1
  154. package/components/Icons/History.js +1 -1
  155. package/components/Icons/History.js.map +1 -1
  156. package/components/Icons/Home.js +1 -1
  157. package/components/Icons/Home.js.map +1 -1
  158. package/components/Icons/Hospital.js +1 -1
  159. package/components/Icons/Hospital.js.map +1 -1
  160. package/components/Icons/Hourglass.js +1 -1
  161. package/components/Icons/Hourglass.js.map +1 -1
  162. package/components/Icons/Icon.js +1 -1
  163. package/components/Icons/Icon.js.map +1 -1
  164. package/components/Icons/InfoSignFill.js +1 -1
  165. package/components/Icons/InfoSignFill.js.map +1 -1
  166. package/components/Icons/InfoSignStroke.js +1 -1
  167. package/components/Icons/InfoSignStroke.js.map +1 -1
  168. package/components/Icons/Journal.js +1 -1
  169. package/components/Icons/Journal.js.map +1 -1
  170. package/components/Icons/List.js +1 -1
  171. package/components/Icons/List.js.map +1 -1
  172. package/components/Icons/Location.js +1 -1
  173. package/components/Icons/Location.js.map +1 -1
  174. package/components/Icons/Lock.js +1 -1
  175. package/components/Icons/Lock.js.map +1 -1
  176. package/components/Icons/Medicine.js +1 -1
  177. package/components/Icons/Medicine.js.map +1 -1
  178. package/components/Icons/Menu.js +1 -1
  179. package/components/Icons/Menu.js.map +1 -1
  180. package/components/Icons/Minus.js +1 -1
  181. package/components/Icons/Minus.js.map +1 -1
  182. package/components/Icons/MobilePhone.js +1 -1
  183. package/components/Icons/MobilePhone.js.map +1 -1
  184. package/components/Icons/NoAccess.js +1 -1
  185. package/components/Icons/NoAccess.js.map +1 -1
  186. package/components/Icons/NoEye.js +1 -1
  187. package/components/Icons/NoEye.js.map +1 -1
  188. package/components/Icons/NoFilter.js +1 -1
  189. package/components/Icons/NoFilter.js.map +1 -1
  190. package/components/Icons/PaperPlane.js +1 -1
  191. package/components/Icons/PaperPlane.js.map +1 -1
  192. package/components/Icons/Pause.js +1 -1
  193. package/components/Icons/Pause.js.map +1 -1
  194. package/components/Icons/Pencil.js +1 -1
  195. package/components/Icons/Pencil.js.map +1 -1
  196. package/components/Icons/PersonalPlan.js +1 -1
  197. package/components/Icons/PersonalPlan.js.map +1 -1
  198. package/components/Icons/Play.js +1 -1
  199. package/components/Icons/Play.js.map +1 -1
  200. package/components/Icons/PlusLarge.js +1 -1
  201. package/components/Icons/PlusLarge.js.map +1 -1
  202. package/components/Icons/PlusSmall.js +1 -1
  203. package/components/Icons/PlusSmall.js.map +1 -1
  204. package/components/Icons/Printer.js +1 -1
  205. package/components/Icons/Printer.js.map +1 -1
  206. package/components/Icons/QrCode.js +1 -1
  207. package/components/Icons/QrCode.js.map +1 -1
  208. package/components/Icons/Receptionist.js +1 -1
  209. package/components/Icons/Receptionist.js.map +1 -1
  210. package/components/Icons/Referral.js +1 -1
  211. package/components/Icons/Referral.js.map +1 -1
  212. package/components/Icons/Refresh.js +1 -1
  213. package/components/Icons/Refresh.js.map +1 -1
  214. package/components/Icons/Reply.js +1 -1
  215. package/components/Icons/Reply.js.map +1 -1
  216. package/components/Icons/Save.js +1 -1
  217. package/components/Icons/Save.js.map +1 -1
  218. package/components/Icons/Search.js +1 -1
  219. package/components/Icons/Search.js.map +1 -1
  220. package/components/Icons/SectionSign.js +1 -1
  221. package/components/Icons/SectionSign.js.map +1 -1
  222. package/components/Icons/Settings.js +1 -1
  223. package/components/Icons/Settings.js.map +1 -1
  224. package/components/Icons/Share.js +1 -1
  225. package/components/Icons/Share.js.map +1 -1
  226. package/components/Icons/SpeechBubble.js +1 -1
  227. package/components/Icons/SpeechBubble.js.map +1 -1
  228. package/components/Icons/Stopwatch.js +1 -1
  229. package/components/Icons/Stopwatch.js.map +1 -1
  230. package/components/Icons/SupportingPerson.js +1 -1
  231. package/components/Icons/SupportingPerson.js.map +1 -1
  232. package/components/Icons/Syringe.js +1 -1
  233. package/components/Icons/Syringe.js.map +1 -1
  234. package/components/Icons/TimePassing.js +1 -1
  235. package/components/Icons/TimePassing.js.map +1 -1
  236. package/components/Icons/Toolbox.js +1 -1
  237. package/components/Icons/Toolbox.js.map +1 -1
  238. package/components/Icons/TrashCan.js +1 -1
  239. package/components/Icons/TrashCan.js.map +1 -1
  240. package/components/Icons/Undo.js +1 -1
  241. package/components/Icons/Undo.js.map +1 -1
  242. package/components/Icons/Upload.js +1 -1
  243. package/components/Icons/Upload.js.map +1 -1
  244. package/components/Icons/Vaccine.js +1 -1
  245. package/components/Icons/Vaccine.js.map +1 -1
  246. package/components/Icons/VerticalDots.js +1 -1
  247. package/components/Icons/VerticalDots.js.map +1 -1
  248. package/components/Icons/VideoCamera.js +1 -1
  249. package/components/Icons/VideoCamera.js.map +1 -1
  250. package/components/Icons/VideoChat.js +1 -1
  251. package/components/Icons/VideoChat.js.map +1 -1
  252. package/components/Icons/Wallet.js +1 -1
  253. package/components/Icons/Wallet.js.map +1 -1
  254. package/components/Icons/Watch.js +1 -1
  255. package/components/Icons/Watch.js.map +1 -1
  256. package/components/Icons/X.js +1 -1
  257. package/components/Icons/X.js.map +1 -1
  258. package/components/Icons/Zoom.js +1 -1
  259. package/components/Icons/Zoom.js.map +1 -1
  260. package/components/Icons/index.js +1 -1
  261. package/components/Input/Input.d.ts +0 -1
  262. package/components/Input/Input.d.ts.map +1 -1
  263. package/components/Input/index.js +1 -1
  264. package/components/LinkList/LinkList.d.ts +4 -0
  265. package/components/LinkList/LinkList.d.ts.map +1 -1
  266. package/components/LinkList/index.js +1 -1
  267. package/components/LinkList/index.js.map +1 -1
  268. package/components/Loader/index.js +1 -1
  269. package/components/Loader/index.js.map +1 -1
  270. package/components/Modal/Modal.d.ts.map +1 -1
  271. package/components/Modal/index.js +1 -1
  272. package/components/NotificationPanel/index.js +1 -1
  273. package/components/NotificationPanel/index.js.map +1 -1
  274. package/components/Panel/index.js +1 -1
  275. package/components/PanelList/index.js +1 -1
  276. package/components/PanelList/index.js.map +1 -1
  277. package/components/Progressbar/index.js +1 -1
  278. package/components/Progressbar/index.js.map +1 -1
  279. package/components/RadioButton/index.js +1 -1
  280. package/components/Select/Select.d.ts +30 -0
  281. package/components/Select/Select.d.ts.map +1 -0
  282. package/components/Select/componentdata.json +1 -0
  283. package/components/Select/index.d.ts +4 -0
  284. package/components/Select/index.d.ts.map +1 -0
  285. package/components/Select/index.js +2 -0
  286. package/components/Select/index.js.map +1 -0
  287. package/components/Select/styles.module.scss +125 -0
  288. package/components/Select/styles.module.scss.d.ts +21 -0
  289. package/components/Slider/index.js +1 -1
  290. package/components/Slider/index.js.map +1 -1
  291. package/components/StatusDot/index.js +1 -1
  292. package/components/StatusDot/index.js.map +1 -1
  293. package/components/Table/TableExpandedRow/index.js +1 -1
  294. package/components/Table/TableExpanderCell/index.js +1 -1
  295. package/components/Table/TableHeadCell/index.js +1 -1
  296. package/components/Table/TableRow/index.js +1 -1
  297. package/components/Table/index.js +1 -1
  298. package/components/Table/index.js.map +1 -1
  299. package/components/Tag/index.js +1 -1
  300. package/components/Tag/index.js.map +1 -1
  301. package/components/Textarea/Textarea.d.ts.map +1 -1
  302. package/components/Textarea/index.js +1 -1
  303. package/components/Tile/index.js +1 -1
  304. package/components/Tile/index.js.map +1 -1
  305. package/components/Tooltip/Tooltip.d.ts +11 -12
  306. package/components/Tooltip/Tooltip.d.ts.map +1 -1
  307. package/components/Tooltip/TooltipWord/TooltipWord.d.ts +20 -0
  308. package/components/Tooltip/TooltipWord/TooltipWord.d.ts.map +1 -0
  309. package/components/Tooltip/TooltipWord/componentdata.json +1 -0
  310. package/components/Tooltip/TooltipWord/index.d.ts +4 -0
  311. package/components/Tooltip/TooltipWord/index.d.ts.map +1 -0
  312. package/components/Tooltip/TooltipWord/index.js +2 -0
  313. package/components/Tooltip/TooltipWord/index.js.map +1 -0
  314. package/components/Tooltip/{styles.module.scss → TooltipWord/styles.module.scss} +3 -6
  315. package/components/Tooltip/{styles.module.scss.d.ts → TooltipWord/styles.module.scss.d.ts} +0 -0
  316. package/components/Tooltip/componentdata.json +1 -1
  317. package/components/Tooltip/index.js +1 -1
  318. package/components/TooltipExample/TooltipExample.d.ts.map +1 -1
  319. package/components/TooltipExample/componentdata.json +1 -1
  320. package/components/TooltipExample/index.js +1 -1
  321. package/components/TooltipExample/index.js.map +1 -1
  322. package/components/Validation/index.js +1 -1
  323. package/constants.d.ts +2 -0
  324. package/constants.d.ts.map +1 -1
  325. package/constants.js +1 -1
  326. package/constants.js.map +1 -1
  327. package/hooks/useDelayedState.d.ts +9 -0
  328. package/hooks/useDelayedState.d.ts.map +1 -0
  329. package/hooks/useDelayedState.js +2 -0
  330. package/hooks/useDelayedState.js.map +1 -0
  331. package/hooks/useFocusTrap.d.ts +2 -1
  332. package/hooks/useFocusTrap.d.ts.map +1 -1
  333. package/hooks/useFocusTrap.js +1 -1
  334. package/hooks/useFocusTrap.js.map +1 -1
  335. package/hooks/useFocusableElements.js +1 -1
  336. package/hooks/useFocusableElements.js.map +1 -1
  337. package/hooks/useIntersectionObserver.d.ts +1 -1
  338. package/hooks/useIntersectionObserver.d.ts.map +1 -1
  339. package/hooks/useIntersectionObserver.js.map +1 -1
  340. package/hooks/useInterval.d.ts +9 -0
  341. package/hooks/useInterval.d.ts.map +1 -0
  342. package/hooks/useInterval.js +2 -0
  343. package/hooks/useInterval.js.map +1 -0
  344. package/hooks/useIsVisible.d.ts +1 -1
  345. package/hooks/useIsVisible.d.ts.map +1 -1
  346. package/hooks/useIsVisible.js +1 -1
  347. package/hooks/useIsVisible.js.map +1 -1
  348. package/hooks/useLayoutEvent.js +1 -1
  349. package/hooks/useLayoutEvent.js.map +1 -1
  350. package/hooks/useSize.d.ts +2 -1
  351. package/hooks/useSize.d.ts.map +1 -1
  352. package/hooks/useSize.js +1 -1
  353. package/hooks/useSize.js.map +1 -1
  354. package/hooks/useSticky.js +1 -1
  355. package/hooks/useSticky.js.map +1 -1
  356. package/hooks/useUuid.js +1 -1
  357. package/hooks/useUuid.js.map +1 -1
  358. package/index.js +1 -1
  359. package/package.json +1 -1
  360. package/utils/accessibility.js +2 -0
  361. package/utils/accessibility.js.map +1 -0
  362. package/utils/debounce.js +2 -0
  363. package/utils/debounce.js.map +1 -0
  364. package/utils/environment.js +2 -0
  365. package/utils/environment.js.map +1 -0
  366. package/utils/loremtext.js +2 -0
  367. package/utils/loremtext.js.map +1 -0
  368. package/utils/refs.js +2 -0
  369. package/utils/refs.js.map +1 -0
  370. package/utils/uuid.js +2 -0
  371. package/utils/uuid.js.map +1 -0
  372. package/utils/viewport.js +2 -0
  373. package/utils/viewport.js.map +1 -0
  374. package/uuid.js +1 -1
  375. package/uuid.js.map +1 -1
  376. package/accessibility.js +0 -2
  377. package/accessibility.js.map +0 -1
  378. package/debounce.js +0 -2
  379. package/debounce.js.map +0 -1
  380. package/hooks/useGetDOMRect.d.ts +0 -11
  381. package/hooks/useGetDOMRect.d.ts.map +0 -1
  382. package/hooks/useGetDOMRect.js +0 -2
  383. package/hooks/useGetDOMRect.js.map +0 -1
package/Button.js CHANGED
@@ -1,2 +1,2 @@
1
- import e,{useRef as lt,useEffect as it}from"react";import{AnalyticsId as V,IconSize as k}from"./constants.js";import{i as ct}from"./uuid.js";import{getColor as i}from"./theme/currys/color.js";import{Icon as ut}from"./components/Icons/Icon.js";import{useHover as $}from"./hooks/useHover.js";import{useIcons as mt}from"./hooks/useIcons.js";import{useBreakpoint as dt}from"./hooks/useBreakpoint.js";import{breakpoints as bt}from"./theme/grid.js";import w from"classnames";import t from"./components/Button/styles.module.scss";import pt from"./components/Icons/ArrowRight.js";import{useSize as ft}from"./hooks/useSize.js";const ht=(o,n,a,d,s,v)=>v&&a?!s||o?i("neutral",n?500:700):i("white"):a?!s||o?i("neutral",500):`${i("white")}b3`:o&&!s||!o&&s?"white":d==="normal"?i("blueberry",600):i("cherry",500),N=(o,n)=>n&&o?k.Small:o?k.Medium:k.XSmall,gt=(o,n,a)=>{if(!a&&o&&(n===void 0||n===""))throw new Error("Fyll inn ariaLabel prop p\xE5 Button uten tekst for \xE5 opprettholde UU krav")},Mt=e.forwardRef(function(n,a){const{ariaLabel:d,id:s,children:v,wrapperClassName:j,className:q,arrow:E=!1,concept:B="normal",disabled:b=!1,ellipsis:x=!1,fluid:D=!1,htmlMarkup:C="button",mode:P="onlight",onClick:R,size:X="medium",variant:I="fill",href:G,tabIndex:S,testId:z,target:M,type:J="button",...A}=n,[p,f,F]=mt(e.Children.toArray(v)),{hoverRef:W,isHovered:K}=C==="button"?$(a):$(a),H=lt(null),c=ft(H),l=!!(p||f)&&!F,Q=p&&(f||E)&&!l,y=P==="ondark",h=dt()<bt.md,L=B==="destructive"&&!b,Y=I==="outline",u=I==="borderless",Z=ht(I==="fill",u,b,B,y,h),O=E&&!u,m=X==="large"&&!L&&!u,tt={...A},T=w(t["button-wrapper"],{[t["button-wrapper--fluid"]]:D||x},j),et=w(t.button,{[t["button--destructive"]]:L,[t["button--normal"]]:!m,[t["button--large"]]:m,[t["button--outline"]]:Y,[t["button--borderless"]]:u,[t["button--left-icon"]]:p&&!l,[t["button--right-icon"]]:f&&!l,[t["button--both-icons"]]:Q,[t["button--only-icon"]]:l,[t["button--arrow"]]:O,[t["button--on-dark"]]:y},q),ot=w(t.button__text,{[t["button__text--ellipsis"]]:x}),rt=w(t.diagonal,{[t["diagonal--on-dark"]]:y});it(()=>{gt(l,d,ct())},[]);const _=(r,g,at)=>{const st=r&&r.props&&r.props.color?r.props.color:Z;return r&&Object.keys(r).length>0?e.cloneElement(r,{size:g,color:st,isHovered:K,className:at}):null},nt=()=>{let r,g;return c&&(r=Math.atan2(c.height,c.width),g=Math.sqrt(Math.pow(c.width,2)+Math.pow(c.height,2))),e.createElement("div",{className:ot,ref:H},b&&u&&e.createElement("div",{className:rt},e.createElement("div",{style:{transform:`rotate(${r}rad)`,width:g},className:t.diagonal__line})),e.createElement("span",null,l?d:F))},U=()=>e.createElement(e.Fragment,null,e.createElement("div",{className:et},_(p,N(m,h),l?void 0:t["button__left-icon"]),nt(),O?_(e.createElement(ut,{svgIcon:pt}),N(m,h),t.button__arrow):_(f,N(m,h),t["button__right-icon"])));return e.createElement(e.Fragment,null,C==="button"&&e.createElement("button",{id:s,onClick:R,disabled:b,"data-testid":z,"data-analyticsid":V.Button,className:T,ref:W,tabIndex:S,type:J,...tt},U()),C==="a"&&e.createElement("a",{id:s,onClick:R,"data-testid":z,"data-analyticsid":V.Button,className:T,href:G,target:M,rel:M==="_blank"?"noopener noreferrer":n.rel,ref:W,tabIndex:S,...A},U()))});export{Mt as B};
1
+ import e,{useRef as lt,useEffect as it}from"react";import{AnalyticsId as V,IconSize as k}from"./constants.js";import{isTest as ct}from"./utils/environment.js";import{getColor as i}from"./theme/currys/color.js";import{Icon as ut}from"./components/Icons/Icon.js";import{useHover as $}from"./hooks/useHover.js";import{useIcons as mt}from"./hooks/useIcons.js";import{useBreakpoint as dt}from"./hooks/useBreakpoint.js";import{breakpoints as bt}from"./theme/grid.js";import w from"classnames";import t from"./components/Button/styles.module.scss";import pt from"./components/Icons/ArrowRight.js";import{useSize as ft}from"./hooks/useSize.js";const ht=(o,n,a,d,s,v)=>v&&a?!s||o?i("neutral",n?500:700):i("white"):a?!s||o?i("neutral",500):`${i("white")}b3`:o&&!s||!o&&s?"white":d==="normal"?i("blueberry",600):i("cherry",500),N=(o,n)=>n&&o?k.Small:o?k.Medium:k.XSmall,gt=(o,n,a)=>{if(!a&&o&&(n===void 0||n===""))throw new Error("Fyll inn ariaLabel prop p\xE5 Button uten tekst for \xE5 opprettholde UU krav")},Mt=e.forwardRef(function(n,a){const{ariaLabel:d,id:s,children:v,wrapperClassName:j,className:q,arrow:E=!1,concept:B="normal",disabled:b=!1,ellipsis:x=!1,fluid:D=!1,htmlMarkup:C="button",mode:P="onlight",onClick:R,size:X="medium",variant:I="fill",href:G,tabIndex:S,testId:z,target:M,type:J="button",...A}=n,[p,f,F]=mt(e.Children.toArray(v)),{hoverRef:W,isHovered:K}=C==="button"?$(a):$(a),H=lt(null),c=ft(H),l=!!(p||f)&&!F,Q=p&&(f||E)&&!l,y=P==="ondark",h=dt()<bt.md,L=B==="destructive"&&!b,Y=I==="outline",u=I==="borderless",Z=ht(I==="fill",u,b,B,y,h),O=E&&!u,m=X==="large"&&!L&&!u,tt={...A},T=w(t["button-wrapper"],{[t["button-wrapper--fluid"]]:D||x},j),et=w(t.button,{[t["button--destructive"]]:L,[t["button--normal"]]:!m,[t["button--large"]]:m,[t["button--outline"]]:Y,[t["button--borderless"]]:u,[t["button--left-icon"]]:p&&!l,[t["button--right-icon"]]:f&&!l,[t["button--both-icons"]]:Q,[t["button--only-icon"]]:l,[t["button--arrow"]]:O,[t["button--on-dark"]]:y},q),ot=w(t.button__text,{[t["button__text--ellipsis"]]:x}),rt=w(t.diagonal,{[t["diagonal--on-dark"]]:y});it(()=>{gt(l,d,ct())},[]);const _=(r,g,at)=>{const st=r&&r.props&&r.props.color?r.props.color:Z;return r&&Object.keys(r).length>0?e.cloneElement(r,{size:g,color:st,isHovered:K,className:at}):null},nt=()=>{let r,g;return c&&(r=Math.atan2(c.height,c.width),g=Math.sqrt(Math.pow(c.width,2)+Math.pow(c.height,2))),e.createElement("div",{className:ot,ref:H},b&&u&&e.createElement("div",{className:rt},e.createElement("div",{style:{transform:`rotate(${r}rad)`,width:g},className:t.diagonal__line})),e.createElement("span",null,l?d:F))},U=()=>e.createElement(e.Fragment,null,e.createElement("div",{className:et},_(p,N(m,h),l?void 0:t["button__left-icon"]),nt(),O?_(e.createElement(ut,{svgIcon:pt}),N(m,h),t.button__arrow):_(f,N(m,h),t["button__right-icon"])));return e.createElement(e.Fragment,null,C==="button"&&e.createElement("button",{id:s,onClick:R,disabled:b,"data-testid":z,"data-analyticsid":V.Button,className:T,ref:W,tabIndex:S,type:J,...tt},U()),C==="a"&&e.createElement("a",{id:s,onClick:R,"data-testid":z,"data-analyticsid":V.Button,className:T,href:G,target:M,rel:M==="_blank"?"noopener noreferrer":n.rel,ref:W,tabIndex:S,...A},U()))});export{Mt as B};
2
2
  //# sourceMappingURL=Button.js.map
package/Button.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Button.js","sources":["../src/components/Button/Button.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\n\nimport { HTMLButtonProps, HTMLAnchorProps, AnalyticsId } from '../../constants';\nimport { isTest } from '../../utils/environment';\nimport { getColor } from '../../theme/currys/color';\nimport Icon, { IconProps, IconSize } from './../Icons/';\nimport { useHover } from '../../hooks/useHover';\nimport { useIcons } from '../../hooks/useIcons';\nimport { useBreakpoint } from '../../hooks/useBreakpoint';\nimport { breakpoints } from '../../theme/grid';\nimport classNames from 'classnames';\n\nimport buttonStyles from './styles.module.scss';\nimport ArrowRight from '../Icons/ArrowRight';\nimport { useSize } from '../../hooks/useSize';\n\nexport type ButtonConcept = 'normal' | 'destructive';\nexport type ButtonVariant = 'fill' | 'outline' | 'borderless';\nexport type ButtonSize = 'medium' | 'large';\nexport type ButtonMode = 'onlight' | 'ondark';\nexport type ButtonTags = 'button' | 'a';\n\nexport interface ButtonProps extends HTMLButtonProps, HTMLAnchorProps {\n /** Sets the aria-label of the button, use when the button only includes an icon */\n ariaLabel?: string;\n /** Gives a unique id to the button */\n id?: string;\n /** Sets the content of the button. */\n children: React.ReactNode;\n /** Adds custom classes to the wrapper element. */\n wrapperClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Enables an arrow icon to the right inside the button (Not available in borderless variant) */\n arrow?: boolean;\n /** Changes the intent of the button. Mostly changes the color profile. */\n concept?: ButtonConcept;\n /** Disables text wrapping and enables ellipsis. */\n ellipsis?: boolean;\n /** Makes the button scale to full width of its parent element. */\n fluid?: boolean;\n /** Changes the underlying element of the button. */\n htmlMarkup?: ButtonTags;\n /** Changes the button colors for different backgrounds. */\n mode?: ButtonMode;\n /** Function that is called when clicked */\n onClick?: (e?: React.MouseEvent<HTMLElement, MouseEvent> | React.FormEvent<{}> | React.KeyboardEvent<HTMLUListElement> | null) => void;\n /** Changes the button colors for different backgrounds. (Large not available in borderless variant) */\n size?: ButtonSize;\n /** Changes the visual representation of the button. */\n variant?: ButtonVariant;\n /** Specifies the focus order relative to the other buttons or controls on the page */\n tabIndex?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Button type. Default: button */\n type?: React.ButtonHTMLAttributes<HTMLButtonElement>['type'];\n}\n\nconst getIconColor = (\n fill: boolean,\n borderless: boolean,\n disabled: boolean,\n concept: ButtonConcept,\n ondark: boolean,\n mobile: boolean\n): string => {\n if (mobile && disabled) {\n return !ondark || fill ? getColor('neutral', !borderless ? 700 : 500) : getColor('white');\n }\n if (disabled) {\n return !ondark || fill ? getColor('neutral', 500) : `${getColor('white')}b3`;\n }\n if ((fill && !ondark) || (!fill && ondark)) {\n return 'white';\n }\n\n return concept === 'normal' ? getColor('blueberry', 600) : getColor('cherry', 500);\n};\nconst getLargeIconSize = (large: boolean, mobile: boolean): IconSize => {\n if (mobile && large) return IconSize.Small;\n if (large) return IconSize.Medium;\n return IconSize.XSmall;\n};\n\nconst checkOnlyIconAria = (onlyIcon: boolean, ariaLabel: string | undefined, testEnv: boolean) => {\n if (!testEnv && onlyIcon && (ariaLabel === undefined || ariaLabel === '')) {\n throw new Error('Fyll inn ariaLabel prop på Button uten tekst for å opprettholde UU krav');\n }\n};\n\nconst Button = React.forwardRef(function ButtonForwardedRef(\n props: ButtonProps,\n ref: React.ForwardedRef<HTMLButtonElement | HTMLAnchorElement>\n) {\n const {\n ariaLabel,\n id,\n children,\n wrapperClassName,\n className,\n arrow = false,\n concept = 'normal',\n disabled = false,\n ellipsis = false,\n fluid = false,\n htmlMarkup = 'button',\n mode = 'onlight',\n onClick,\n size = 'medium',\n variant = 'fill',\n href,\n tabIndex,\n testId,\n target,\n type = 'button',\n ...restProps\n } = props;\n\n const [leftIcon, rightIcon, restChildren] = useIcons(React.Children.toArray(children));\n const { hoverRef, isHovered } =\n htmlMarkup === 'button'\n ? useHover<HTMLButtonElement>(ref as React.RefObject<HTMLButtonElement>)\n : useHover<HTMLAnchorElement>(ref as React.RefObject<HTMLAnchorElement>);\n const buttonContentRef = useRef<HTMLDivElement>(null);\n const buttonContentSize = useSize(buttonContentRef);\n const onlyIcon = !!(leftIcon || rightIcon) && !restChildren;\n const bothIcons = leftIcon && (rightIcon || arrow) && !onlyIcon;\n const onDark = mode === 'ondark';\n const breakpoint = useBreakpoint();\n const mobile = breakpoint < breakpoints.md;\n const destructive = concept === 'destructive' && !disabled;\n const outlineVariant = variant === 'outline';\n const borderlessVariant = variant === 'borderless';\n const iconColor = getIconColor(variant === 'fill', borderlessVariant, disabled, concept, onDark, mobile);\n const hasArrow = arrow && !borderlessVariant;\n const large = size === 'large' && !destructive && !borderlessVariant;\n const rest = { ...(restProps as React.HtmlHTMLAttributes<HTMLButtonElement>) };\n\n const buttonWrapperClasses = classNames(\n buttonStyles['button-wrapper'],\n { [buttonStyles['button-wrapper--fluid']]: fluid || ellipsis },\n wrapperClassName\n );\n const buttonClasses = classNames(\n buttonStyles.button,\n {\n [buttonStyles['button--destructive']]: destructive,\n [buttonStyles['button--normal']]: !large,\n [buttonStyles['button--large']]: large,\n [buttonStyles['button--outline']]: outlineVariant,\n [buttonStyles['button--borderless']]: borderlessVariant,\n [buttonStyles['button--left-icon']]: leftIcon && !onlyIcon,\n [buttonStyles['button--right-icon']]: rightIcon && !onlyIcon,\n [buttonStyles['button--both-icons']]: bothIcons,\n [buttonStyles['button--only-icon']]: onlyIcon,\n [buttonStyles['button--arrow']]: hasArrow,\n [buttonStyles['button--on-dark']]: onDark,\n },\n className\n );\n const buttonTextClasses = classNames(buttonStyles['button__text'], {\n [buttonStyles['button__text--ellipsis']]: ellipsis,\n });\n const diagonalClasses = classNames(buttonStyles['diagonal'], {\n [buttonStyles['diagonal--on-dark']]: onDark,\n });\n\n useEffect(() => {\n checkOnlyIconAria(onlyIcon, ariaLabel, isTest());\n }, []);\n\n const renderIcon = (\n iconElement: React.ReactElement<IconProps> | {} | undefined | null,\n iconSize: number,\n iconClassName?: string\n ): React.ReactElement<IconProps> | React.Component<IconProps> | null => {\n const color =\n iconElement && (iconElement as React.ReactElement<IconProps>).props && (iconElement as React.ReactElement<IconProps>).props.color\n ? (iconElement as React.ReactElement<IconProps>).props.color\n : iconColor;\n return iconElement && Object.keys(iconElement).length > 0\n ? React.cloneElement(iconElement as React.ReactElement<IconProps>, { size: iconSize, color, isHovered, className: iconClassName })\n : null;\n };\n\n const renderButtonContent = () => {\n let angle;\n let diagonalWidth;\n if (buttonContentSize) {\n angle = Math.atan2(buttonContentSize.height, buttonContentSize.width);\n diagonalWidth = Math.sqrt(Math.pow(buttonContentSize.width, 2) + Math.pow(buttonContentSize.height, 2));\n }\n\n return (\n <div className={buttonTextClasses} ref={buttonContentRef}>\n {disabled && borderlessVariant && (\n <div className={diagonalClasses}>\n <div style={{ transform: `rotate(${angle}rad)`, width: diagonalWidth }} className={buttonStyles['diagonal__line']} />\n </div>\n )}\n <span>{onlyIcon ? ariaLabel : restChildren}</span>\n </div>\n );\n };\n\n const renderbuttonContentWrapper = () => {\n return (\n <>\n <div className={buttonClasses}>\n {renderIcon(leftIcon, getLargeIconSize(large, mobile), !onlyIcon ? buttonStyles['button__left-icon'] : undefined)}\n {renderButtonContent()}\n {hasArrow\n ? renderIcon(<Icon svgIcon={ArrowRight} />, getLargeIconSize(large, mobile), buttonStyles['button__arrow'])\n : renderIcon(rightIcon, getLargeIconSize(large, mobile), buttonStyles['button__right-icon'])}\n </div>\n </>\n );\n };\n\n return (\n <>\n {htmlMarkup === 'button' && (\n <button\n id={id}\n onClick={onClick}\n disabled={disabled}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n ref={hoverRef as React.ForwardedRef<HTMLButtonElement>}\n tabIndex={tabIndex}\n type={type}\n {...rest}\n >\n {renderbuttonContentWrapper()}\n </button>\n )}\n {htmlMarkup === 'a' && (\n <a\n id={id}\n onClick={onClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n href={href}\n target={target}\n rel={target === '_blank' ? 'noopener noreferrer' : props.rel}\n ref={hoverRef as React.ForwardedRef<HTMLAnchorElement>}\n tabIndex={tabIndex}\n {...restProps}\n >\n {renderbuttonContentWrapper()}\n </a>\n )}\n </>\n );\n});\n\nexport default Button;\n"],"names":["getIconColor","fill","borderless","disabled","concept","ondark","mobile","getColor","getLargeIconSize","large","IconSize","checkOnlyIconAria","onlyIcon","ariaLabel","testEnv","Button","React","props","ref","id","children","wrapperClassName","className","arrow","ellipsis","fluid","htmlMarkup","mode","onClick","size","variant","href","tabIndex","testId","target","type","restProps","leftIcon","rightIcon","restChildren","useIcons","hoverRef","isHovered","useHover","buttonContentRef","useRef","buttonContentSize","useSize","bothIcons","onDark","useBreakpoint","breakpoints","destructive","outlineVariant","borderlessVariant","iconColor","hasArrow","rest","buttonWrapperClasses","classNames","buttonStyles","buttonClasses","buttonTextClasses","diagonalClasses","useEffect","isTest","renderIcon","iconElement","iconSize","iconClassName","color","renderButtonContent","angle","diagonalWidth","renderbuttonContentWrapper","Icon","ArrowRight","AnalyticsId"],"mappings":"0mBA2DA,MAAMA,GAAe,CACnBC,EACAC,EACAC,EACAC,EACAC,EACAC,IAEIA,GAAUH,EACL,CAACE,GAAUJ,EAAOM,EAAS,UAAYL,EAAmB,IAAN,GAAS,EAAIK,EAAS,OAAO,EAEtFJ,EACK,CAACE,GAAUJ,EAAOM,EAAS,UAAW,GAAG,EAAI,GAAGA,EAAS,OAAO,MAEpEN,GAAQ,CAACI,GAAY,CAACJ,GAAQI,EAC1B,QAGFD,IAAY,SAAWG,EAAS,YAAa,GAAG,EAAIA,EAAS,SAAU,GAAG,EAE7EC,EAAmB,CAACC,EAAgBH,IACpCA,GAAUG,EAAcC,EAAS,MACjCD,EAAcC,EAAS,OACpBA,EAAS,OAGZC,GAAoB,CAACC,EAAmBC,EAA+BC,IAAqB,CAChG,GAAI,CAACA,GAAWF,IAAaC,IAAc,QAAaA,IAAc,IAC9D,MAAA,IAAI,MAAM,+EAAyE,CAE7F,EAEME,GAASC,EAAM,WAAW,SAC9BC,EACAC,EACA,CACM,KAAA,CACJ,UAAAL,EACA,GAAAM,EACA,SAAAC,EACA,iBAAAC,EACA,UAAAC,EACA,MAAAC,EAAQ,GACR,QAAAnB,EAAU,SACV,SAAAD,EAAW,GACX,SAAAqB,EAAW,GACX,MAAAC,EAAQ,GACR,WAAAC,EAAa,SACb,KAAAC,EAAO,UACP,QAAAC,EACA,KAAAC,EAAO,SACP,QAAAC,EAAU,OACV,KAAAC,EACA,SAAAC,EACA,OAAAC,EACA,OAAAC,EACA,KAAAC,EAAO,YACJC,CACD,EAAAnB,EAEE,CAACoB,EAAUC,EAAWC,CAAY,EAAIC,GAASxB,EAAM,SAAS,QAAQI,CAAQ,CAAC,EAC/E,CAAE,S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,CACF,EAKF,OAAA5C,EAAA,cAAAA,EAAA,SAAA,KACGU,IAAe,UACbV,EAAA,cAAA,SAAA,CACC,GAAAG,EACA,QAAAS,EACA,SAAAzB,EACA,cAAa8B,EACb,mBAAkB4C,EAAY,OAC9B,UAAWnB,EACX,IAAKjB,EACL,SAAAT,EACA,KAAAG,EACC,GAAGsB,EAAA,EAEHiB,EACH,CAAA,EAEDhD,IAAe,KACbV,EAAA,cAAA,IAAA,CACC,GAAAG,EACA,QAAAS,EACA,cAAaK,EACb,mBAAkB4C,EAAY,OAC9B,UAAWnB,EACX,KAAA3B,EACA,OAAAG,EACA,IAAKA,IAAW,SAAW,sBAAwBjB,EAAM,IACzD,IAAKwB,EACL,SAAAT,EACC,GAAGI,CAAA,EAEHsC,EACH,CAAA,CAEJ,CAEJ,CAAC"}
1
+ {"version":3,"file":"Button.js","sources":["../src/components/Button/Button.tsx"],"sourcesContent":["import React, { useEffect, useRef } from 'react';\n\nimport { HTMLButtonProps, HTMLAnchorProps, AnalyticsId } from '../../constants';\nimport { isTest } from '../../utils/environment';\nimport { getColor } from '../../theme/currys/color';\nimport Icon, { IconProps, IconSize } from './../Icons/';\nimport { useHover } from '../../hooks/useHover';\nimport { useIcons } from '../../hooks/useIcons';\nimport { useBreakpoint } from '../../hooks/useBreakpoint';\nimport { breakpoints } from '../../theme/grid';\nimport classNames from 'classnames';\n\nimport buttonStyles from './styles.module.scss';\nimport ArrowRight from '../Icons/ArrowRight';\nimport { useSize } from '../../hooks/useSize';\n\nexport type ButtonConcept = 'normal' | 'destructive';\nexport type ButtonVariant = 'fill' | 'outline' | 'borderless';\nexport type ButtonSize = 'medium' | 'large';\nexport type ButtonMode = 'onlight' | 'ondark';\nexport type ButtonTags = 'button' | 'a';\n\nexport interface ButtonProps extends HTMLButtonProps, HTMLAnchorProps {\n /** Sets the aria-label of the button, use when the button only includes an icon */\n ariaLabel?: string;\n /** Gives a unique id to the button */\n id?: string;\n /** Sets the content of the button. */\n children: React.ReactNode;\n /** Adds custom classes to the wrapper element. */\n wrapperClassName?: string;\n /** Adds custom classes to the element. */\n className?: string;\n /** Enables an arrow icon to the right inside the button (Not available in borderless variant) */\n arrow?: boolean;\n /** Changes the intent of the button. Mostly changes the color profile. */\n concept?: ButtonConcept;\n /** Disables text wrapping and enables ellipsis. */\n ellipsis?: boolean;\n /** Makes the button scale to full width of its parent element. */\n fluid?: boolean;\n /** Changes the underlying element of the button. */\n htmlMarkup?: ButtonTags;\n /** Changes the button colors for different backgrounds. */\n mode?: ButtonMode;\n /** Function that is called when clicked */\n onClick?: (e?: React.MouseEvent<HTMLElement, MouseEvent> | React.FormEvent<{}> | React.KeyboardEvent<HTMLUListElement> | null) => void;\n /** Changes the button colors for different backgrounds. (Large not available in borderless variant) */\n size?: ButtonSize;\n /** Changes the visual representation of the button. */\n variant?: ButtonVariant;\n /** Specifies the focus order relative to the other buttons or controls on the page */\n tabIndex?: number;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Button type. Default: button */\n type?: React.ButtonHTMLAttributes<HTMLButtonElement>['type'];\n}\n\nconst getIconColor = (\n fill: boolean,\n borderless: boolean,\n disabled: boolean,\n concept: ButtonConcept,\n ondark: boolean,\n mobile: boolean\n): string => {\n if (mobile && disabled) {\n return !ondark || fill ? getColor('neutral', !borderless ? 700 : 500) : getColor('white');\n }\n if (disabled) {\n return !ondark || fill ? getColor('neutral', 500) : `${getColor('white')}b3`;\n }\n if ((fill && !ondark) || (!fill && ondark)) {\n return 'white';\n }\n\n return concept === 'normal' ? getColor('blueberry', 600) : getColor('cherry', 500);\n};\nconst getLargeIconSize = (large: boolean, mobile: boolean): IconSize => {\n if (mobile && large) return IconSize.Small;\n if (large) return IconSize.Medium;\n return IconSize.XSmall;\n};\n\nconst checkOnlyIconAria = (onlyIcon: boolean, ariaLabel: string | undefined, testEnv: boolean) => {\n if (!testEnv && onlyIcon && (ariaLabel === undefined || ariaLabel === '')) {\n throw new Error('Fyll inn ariaLabel prop på Button uten tekst for å opprettholde UU krav');\n }\n};\n\nconst Button = React.forwardRef(function ButtonForwardedRef(\n props: ButtonProps,\n ref: React.ForwardedRef<HTMLButtonElement | HTMLAnchorElement>\n) {\n const {\n ariaLabel,\n id,\n children,\n wrapperClassName,\n className,\n arrow = false,\n concept = 'normal',\n disabled = false,\n ellipsis = false,\n fluid = false,\n htmlMarkup = 'button',\n mode = 'onlight',\n onClick,\n size = 'medium',\n variant = 'fill',\n href,\n tabIndex,\n testId,\n target,\n type = 'button',\n ...restProps\n } = props;\n\n const [leftIcon, rightIcon, restChildren] = useIcons(React.Children.toArray(children));\n const { hoverRef, isHovered } =\n htmlMarkup === 'button'\n ? useHover<HTMLButtonElement>(ref as React.RefObject<HTMLButtonElement>)\n : useHover<HTMLAnchorElement>(ref as React.RefObject<HTMLAnchorElement>);\n const buttonContentRef = useRef<HTMLDivElement>(null);\n const buttonContentSize = useSize(buttonContentRef);\n const onlyIcon = !!(leftIcon || rightIcon) && !restChildren;\n const bothIcons = leftIcon && (rightIcon || arrow) && !onlyIcon;\n const onDark = mode === 'ondark';\n const breakpoint = useBreakpoint();\n const mobile = breakpoint < breakpoints.md;\n const destructive = concept === 'destructive' && !disabled;\n const outlineVariant = variant === 'outline';\n const borderlessVariant = variant === 'borderless';\n const iconColor = getIconColor(variant === 'fill', borderlessVariant, disabled, concept, onDark, mobile);\n const hasArrow = arrow && !borderlessVariant;\n const large = size === 'large' && !destructive && !borderlessVariant;\n const rest = { ...(restProps as React.HtmlHTMLAttributes<HTMLButtonElement>) };\n\n const buttonWrapperClasses = classNames(\n buttonStyles['button-wrapper'],\n { [buttonStyles['button-wrapper--fluid']]: fluid || ellipsis },\n wrapperClassName\n );\n const buttonClasses = classNames(\n buttonStyles.button,\n {\n [buttonStyles['button--destructive']]: destructive,\n [buttonStyles['button--normal']]: !large,\n [buttonStyles['button--large']]: large,\n [buttonStyles['button--outline']]: outlineVariant,\n [buttonStyles['button--borderless']]: borderlessVariant,\n [buttonStyles['button--left-icon']]: leftIcon && !onlyIcon,\n [buttonStyles['button--right-icon']]: rightIcon && !onlyIcon,\n [buttonStyles['button--both-icons']]: bothIcons,\n [buttonStyles['button--only-icon']]: onlyIcon,\n [buttonStyles['button--arrow']]: hasArrow,\n [buttonStyles['button--on-dark']]: onDark,\n },\n className\n );\n const buttonTextClasses = classNames(buttonStyles['button__text'], {\n [buttonStyles['button__text--ellipsis']]: ellipsis,\n });\n const diagonalClasses = classNames(buttonStyles['diagonal'], {\n [buttonStyles['diagonal--on-dark']]: onDark,\n });\n\n useEffect(() => {\n checkOnlyIconAria(onlyIcon, ariaLabel, isTest());\n }, []);\n\n const renderIcon = (\n iconElement: React.ReactElement<IconProps> | {} | undefined | null,\n iconSize: number,\n iconClassName?: string\n ): React.ReactElement<IconProps> | React.Component<IconProps> | null => {\n const color =\n iconElement && (iconElement as React.ReactElement<IconProps>).props && (iconElement as React.ReactElement<IconProps>).props.color\n ? (iconElement as React.ReactElement<IconProps>).props.color\n : iconColor;\n return iconElement && Object.keys(iconElement).length > 0\n ? React.cloneElement(iconElement as React.ReactElement<IconProps>, { size: iconSize, color, isHovered, className: iconClassName })\n : null;\n };\n\n const renderButtonContent = () => {\n let angle;\n let diagonalWidth;\n if (buttonContentSize) {\n angle = Math.atan2(buttonContentSize.height, buttonContentSize.width);\n diagonalWidth = Math.sqrt(Math.pow(buttonContentSize.width, 2) + Math.pow(buttonContentSize.height, 2));\n }\n\n return (\n <div className={buttonTextClasses} ref={buttonContentRef}>\n {disabled && borderlessVariant && (\n <div className={diagonalClasses}>\n <div style={{ transform: `rotate(${angle}rad)`, width: diagonalWidth }} className={buttonStyles['diagonal__line']} />\n </div>\n )}\n <span>{onlyIcon ? ariaLabel : restChildren}</span>\n </div>\n );\n };\n\n const renderbuttonContentWrapper = () => {\n return (\n <>\n <div className={buttonClasses}>\n {renderIcon(leftIcon, getLargeIconSize(large, mobile), !onlyIcon ? buttonStyles['button__left-icon'] : undefined)}\n {renderButtonContent()}\n {hasArrow\n ? renderIcon(<Icon svgIcon={ArrowRight} />, getLargeIconSize(large, mobile), buttonStyles['button__arrow'])\n : renderIcon(rightIcon, getLargeIconSize(large, mobile), buttonStyles['button__right-icon'])}\n </div>\n </>\n );\n };\n\n return (\n <>\n {htmlMarkup === 'button' && (\n <button\n id={id}\n onClick={onClick}\n disabled={disabled}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n ref={hoverRef as React.ForwardedRef<HTMLButtonElement>}\n tabIndex={tabIndex}\n type={type}\n {...rest}\n >\n {renderbuttonContentWrapper()}\n </button>\n )}\n {htmlMarkup === 'a' && (\n <a\n id={id}\n onClick={onClick}\n data-testid={testId}\n data-analyticsid={AnalyticsId.Button}\n className={buttonWrapperClasses}\n href={href}\n target={target}\n rel={target === '_blank' ? 'noopener noreferrer' : props.rel}\n ref={hoverRef as React.ForwardedRef<HTMLAnchorElement>}\n tabIndex={tabIndex}\n {...restProps}\n >\n {renderbuttonContentWrapper()}\n </a>\n )}\n </>\n );\n});\n\nexport default Button;\n"],"names":["getIconColor","fill","borderless","disabled","concept","ondark","mobile","getColor","getLargeIconSize","large","IconSize","checkOnlyIconAria","onlyIcon","ariaLabel","testEnv","Button","React","props","ref","id","children","wrapperClassName","className","arrow","ellipsis","fluid","htmlMarkup","mode","onClick","size","variant","href","tabIndex","testId","target","type","restProps","leftIcon","rightIcon","restChildren","useIcons","hoverRef","isHovered","useHover","buttonContentRef","useRef","buttonContentSize","useSize","bothIcons","onDark","useBreakpoint","breakpoints","destructive","outlineVariant","borderlessVariant","iconColor","hasArrow","rest","buttonWrapperClasses","classNames","buttonStyles","buttonClasses","buttonTextClasses","diagonalClasses","useEffect","isTest","renderIcon","iconElement","iconSize","iconClassName","color","renderButtonContent","angle","diagonalWidth","renderbuttonContentWrapper","Icon","ArrowRight","AnalyticsId"],"mappings":"4nBA2DA,MAAMA,GAAe,CACnBC,EACAC,EACAC,EACAC,EACAC,EACAC,IAEIA,GAAUH,EACL,CAACE,GAA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,cAAA,IAAA,CACC,GAAAG,EACA,QAAAS,EACA,cAAaK,EACb,mBAAkB4C,EAAY,OAC9B,UAAWnB,EACX,KAAA3B,EACA,OAAAG,EACA,IAAKA,IAAW,SAAW,sBAAwBjB,EAAM,IACzD,IAAKwB,EACL,SAAAT,EACC,GAAGI,CAAA,EAEHsC,EACH,CAAA,CAEJ,CAEJ,CAAC"}
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## [2.4.0](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/branchCompare?baseVersion=GTv2.3.0&targetVersion=GTv2.4.0) (2022-11-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * linklist.link har prop for linkRef ([b86370c](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/b86370ccb3576c44c7ade357022b801d1407a9af)), closes [#287467](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/287467)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * hjelpeboble plasseres riktig i scrollbar tabell ([6b96b04](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/6b96b046782494e2b2586cb158874e46602c5249)), closes [#288142](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/288142)
12
+ * modal setter fokus automatisk til første fokuserbare element ([88bb15c](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/88bb15cd9de0fb0f2a78db7a4621da1e16f31374)), closes [#286778](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/286778)
13
+
14
+ ## [2.3.0](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/branchCompare?baseVersion=GTv2.2.1&targetVersion=GTv2.3.0) (2022-10-31)
15
+
16
+
17
+ ### Features
18
+
19
+ * ny hook useFocusableElement ([3294609](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/32946099ab996597d1a1696a8f8d3d983da9c97e)), closes [#286778](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/286778)
20
+
1
21
  ## [2.2.1](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/branchCompare?baseVersion=GTv2.2.0&targetVersion=GTv2.2.1) (2022-10-25)
2
22
 
3
23
 
@@ -111,7 +131,7 @@
111
131
 
112
132
  ## 2.0.0-beta.1 (2022-09-15)
113
133
 
114
- ## 2.0.0-beta.0 (2022-09-12)
134
+ ## 2.0.0-beta.0 (2022-09-15)
115
135
 
116
136
 
117
137
  ### Features
@@ -213,8 +233,8 @@
213
233
 
214
234
  ### Bug Fixes
215
235
 
216
- * økt kontrast på understreking av lenker ([50b7fa4](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/50b7fa47fb44cb7d75fb877bd53e2309b35e1e21)), closes [#229049](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/229049)
217
236
  * panel har avstand fra tittel til badge ([09034c4](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/09034c4844408c7cfe8f65d7a1a0d82a7828c2ef)), closes [#282359](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/282359)
237
+ * økt kontrast på understreking av lenker ([50b7fa4](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/50b7fa47fb44cb7d75fb877bd53e2309b35e1e21)), closes [#229049](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/229049)
218
238
 
219
239
  ## [1.2.2](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/branchCompare?baseVersion=GTv1.2.1&targetVersion=GTv1.2.2) (2022-08-31)
220
240
 
package/FormGroup.js CHANGED
@@ -1,2 +1,2 @@
1
- import e from"react";import i from"classnames";import a from"./components/FormGroup/styles.module.scss";import{C as g}from"./Checkbox.js";import{FormMode as E,FormVariant as _,AnalyticsId as b}from"./constants.js";import{R as y}from"./RadioButton.js";import{I as k}from"./Input.js";import{T as x}from"./Title.js";import{F as G}from"./FormLayout.js";import{E as I}from"./ErrorWrapper.js";const S=e.forwardRef((r,v)=>{const{className:C,mode:s=E.onwhite,variant:n=_.normal,error:m,name:o,htmlMarkup:d="fieldset"}=r,f=s===E.ondark,c=n===_.bigform,N=i(a["form-group-wrapper"],{[a["form-group-wrapper--on-dark"]]:f,[a["form-group-wrapper--invalid"]]:m},C),w=i(a["form-group-wrapper__title"],{[a["form-group-wrapper__title--on-dark"]]:f&&!m,[a["form-group-wrapper__title--bigform"]]:c}),F=i(a["form-group"]),u=i(a["field-set__legend"],{[a["field-set__legend--on-dark"]]:f&&!m,[a["field-set__legend--bigform"]]:c}),p=t=>{if(t.type===G)return e.cloneElement(t,{variant:n,mapHelper:p});if(t.type===g){let l=t.type===g;return e.cloneElement(t,{name:o!=null?o:l.valueOf.name,mode:s,variant:n,error:!!m})}else if(t.type===y){let l=t.type===y;return e.cloneElement(t,{name:o!=null?o:l.valueOf.name,mode:s,variant:n,error:!!m})}else if(t.type===k){let l=t.type===k;return e.cloneElement(t,{name:o!=null?o:l.valueOf.name,mode:s,variant:n,error:!!m})}return t};return e.createElement("div",{"data-testid":r.testId,"data-analyticsid":b.FormGroup,className:N,ref:v,tabIndex:-1},r.title&&e.createElement(x,{className:w,htmlMarkup:"h4",appearance:"title4",margin:{marginTop:0,marginBottom:m?1:2}},r.title),e.createElement(I,{errorText:m},e.createElement("div",{className:F},d==="div"&&e.createElement("div",{id:r.title,className:a["field-set"]},r.legend&&e.createElement("h5",{className:u},r.legend),e.Children.map(r.children,p)),d==="fieldset"&&e.createElement("fieldset",{name:r.title,className:a["field-set"]},r.legend&&e.createElement("legend",{className:u},r.legend),e.Children.map(r.children,p)))))});export{S as F};
1
+ import e from"react";import i from"classnames";import o from"./components/FormGroup/styles.module.scss";import{C as g}from"./Checkbox.js";import{FormMode as E,FormVariant as y,AnalyticsId as x}from"./constants.js";import{R as _}from"./RadioButton.js";import{I as v}from"./Input.js";import{T as G}from"./Title.js";import{F as I}from"./FormLayout.js";import{E as O}from"./ErrorWrapper.js";import{S as k}from"./Select.js";const j=e.forwardRef((t,C)=>{const{className:N,mode:l=E.onwhite,variant:s=y.normal,error:m,name:a,htmlMarkup:u="fieldset"}=t,f=l===E.ondark,d=s===y.bigform,w=i(o["form-group-wrapper"],{[o["form-group-wrapper--on-dark"]]:f,[o["form-group-wrapper--invalid"]]:m},N),F=i(o["form-group-wrapper__title"],{[o["form-group-wrapper__title--on-dark"]]:f&&!m,[o["form-group-wrapper__title--bigform"]]:d}),b=i(o["form-group"]),c=i(o["field-set__legend"],{[o["field-set__legend--on-dark"]]:f&&!m,[o["field-set__legend--bigform"]]:d}),p=r=>{if(r.type===I)return e.cloneElement(r,{variant:s,mapHelper:p});if(r.type===g){let n=r.type===g;return e.cloneElement(r,{name:a!=null?a:n.valueOf.name,mode:l,variant:s,error:!!m})}else if(r.type===_){let n=r.type===_;return e.cloneElement(r,{name:a!=null?a:n.valueOf.name,mode:l,variant:s,error:!!m})}else if(r.type===v){let n=r.type===v;return e.cloneElement(r,{name:a!=null?a:n.valueOf.name,mode:l,variant:s,error:!!m})}else if(r.type===k){let n=r.type===k;return e.cloneElement(r,{name:a!=null?a:n.valueOf.name,mode:l,error:!!m})}return r};return e.createElement("div",{"data-testid":t.testId,"data-analyticsid":x.FormGroup,className:w,ref:C,tabIndex:-1},t.title&&e.createElement(G,{className:F,htmlMarkup:"h4",appearance:"title4",margin:{marginTop:0,marginBottom:m?1:2}},t.title),e.createElement(O,{errorText:m},e.createElement("div",{className:b},u==="div"&&e.createElement("div",{id:t.title,className:o["field-set"]},t.legend&&e.createElement("h5",{className:c},t.legend),e.Children.map(t.children,p)),u==="fieldset"&&e.createElement("fieldset",{name:t.title,className:o["field-set"]},t.legend&&e.createElement("legend",{className:c},t.legend),e.Children.map(t.children,p)))))});export{j as F};
2
2
  //# sourceMappingURL=FormGroup.js.map
package/FormGroup.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"FormGroup.js","sources":["../src/components/FormGroup/FormGroup.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport formGroupStyles from './styles.module.scss';\nimport Checkbox, { CheckboxProps } from '../Checkbox/Checkbox';\nimport { AnalyticsId, FormMode, FormVariant } from '../../constants';\nimport RadioButton, { RadioButtonProps } from '../RadioButton/RadioButton';\nimport Input, { InputProps } from '../Input/Input';\nimport Title from '../Title';\nimport FormLayout, { FormLayoutProps } from '../FormLayout';\nimport ErrorWrapper from '../ErrorWrapper';\n\nexport type FormGroupTags = 'fieldset' | 'div';\n\nexport interface FormGroupProps {\n /** title for the the fieldset */\n title?: string;\n /** text placed in the legend tag of the fieldset */\n legend?: string;\n /** Items in the FormGroup component */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Changes the visuals of the formgroup */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the formgroup */\n variant?: keyof typeof FormVariant;\n /** Error message */\n error?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Unique identifyer for the child input tags */\n name?: string;\n /** Sets div instead of fieldset tag */\n htmlMarkup?: FormGroupTags;\n}\n\nexport const FormGroup = React.forwardRef((props: FormGroupProps, ref: React.ForwardedRef<HTMLDivElement>) => {\n const { className, mode = FormMode.onwhite, variant = FormVariant.normal, error, name, htmlMarkup = 'fieldset' } = props;\n const onDark = mode === FormMode.ondark;\n const bigform = variant === FormVariant.bigform;\n const formGroupWrapperClasses = classNames(\n formGroupStyles['form-group-wrapper'],\n {\n [formGroupStyles['form-group-wrapper--on-dark']]: onDark,\n [formGroupStyles['form-group-wrapper--invalid']]: error,\n },\n className\n );\n const titleClasses = classNames(formGroupStyles['form-group-wrapper__title'], {\n [formGroupStyles['form-group-wrapper__title--on-dark']]: onDark && !error,\n [formGroupStyles['form-group-wrapper__title--bigform']]: bigform,\n });\n const formGroupClasses = classNames(formGroupStyles['form-group']);\n\n const legendClasses = classNames(formGroupStyles['field-set__legend'], {\n [formGroupStyles['field-set__legend--on-dark']]: onDark && !error,\n [formGroupStyles['field-set__legend--bigform']]: bigform,\n });\n\n const mapFormComponent = (child: React.ReactNode): React.ReactNode => {\n if ((child as React.ReactElement<FormLayoutProps>).type === FormLayout) {\n return React.cloneElement(child as React.ReactElement<FormLayoutProps>, {\n variant,\n mapHelper: mapFormComponent,\n });\n } else if ((child as React.ReactElement<CheckboxProps>).type === Checkbox) {\n let checkbox = (child as React.ReactElement<CheckboxProps>).type === Checkbox;\n return React.cloneElement(child as React.ReactElement<CheckboxProps>, {\n name: name ?? checkbox.valueOf.name,\n mode,\n variant,\n error: !!error,\n });\n } else if ((child as React.ReactElement<RadioButtonProps>).type === RadioButton) {\n let radioButton = (child as React.ReactElement<RadioButtonProps>).type === RadioButton;\n return React.cloneElement(child as React.ReactElement<RadioButtonProps>, {\n name: name ?? radioButton.valueOf.name,\n mode,\n variant,\n error: !!error,\n });\n } else if ((child as React.ReactElement<InputProps>).type === Input) {\n let input = (child as React.ReactElement<InputProps>).type === Input;\n return React.cloneElement(child as React.ReactElement<InputProps>, {\n name: name ?? input.valueOf.name,\n mode,\n variant,\n error: !!error,\n });\n }\n return child;\n };\n\n return (\n <div data-testid={props.testId} data-analyticsid={AnalyticsId.FormGroup} className={formGroupWrapperClasses} ref={ref} tabIndex={-1}>\n {props.title && (\n <Title className={titleClasses} htmlMarkup={'h4'} appearance={'title4'} margin={{ marginTop: 0, marginBottom: error ? 1 : 2 }}>\n {props.title}\n </Title>\n )}\n <ErrorWrapper errorText={error}>\n <div className={formGroupClasses}>\n {htmlMarkup === 'div' && (\n <div id={props.title} className={formGroupStyles['field-set']}>\n {props.legend && <h5 className={legendClasses}>{props.legend}</h5>}\n {React.Children.map(props.children, mapFormComponent)}\n </div>\n )}\n {htmlMarkup === 'fieldset' && (\n <fieldset name={props.title} className={formGroupStyles['field-set']}>\n {props.legend && <legend className={legendClasses}>{props.legend}</legend>}\n {React.Children.map(props.children, mapFormComponent)}\n </fieldset>\n )}\n </div>\n </ErrorWrapper>\n </div>\n );\n});\n\nexport default FormGroup;\n"],"names":["FormGroup","React","props","ref","className","mode","FormMode","variant","FormVariant","error","name","htmlMarkup","onDark","bigform","formGroupWrapperClasses","classNames","formGroupStyles","titleClasses","formGroupClasses","legendClasses","mapFormComponent","child","FormLayout","Checkbox","checkbox","RadioButton","radioButton","Input","input","AnalyticsId","Title","ErrorWrapper"],"mappings":"mYAsCO,MAAMA,EAAYC,EAAM,WAAW,CAACC,EAAuBC,IAA4C,CAC5G,KAAM,CAAE,UAAAC,EAAW,KAAAC,EAAOC,EAAS,QAAS,QAAAC,EAAUC,EAAY,OAAQ,MAAAC,EAAO,KAAAC,EAAM,WAAAC,EAAa,UAAA,EAAeT,EAC7GU,EAASP,IAASC,EAAS,OAC3BO,EAAUN,IAAYC,EAAY,QAClCM,EAA0BC,EAC9BC,EAAgB,sBAChB,CACE,CAACA,EAAgB,gCAAiCJ,EAClD,CAACI,EAAgB,gCAAiCP,CACpD,EACAL,CAAA,EAEIa,EAAeF,EAAWC,EAAgB,6BAA8B,CAC5E,CAACA,EAAgB,uCAAwCJ,GAAU,CAACH,EACpE,CAACO,EAAgB,uCAAwCH,CAAA,CAC1D,EACKK,EAAmBH,EAAWC,EAAgB,aAAa,EAE3DG,EAAgBJ,EAAWC,EAAgB,qBAAsB,CACrE,CAACA,EAAgB,+BAAgCJ,GAAU,CAACH,EAC5D,CAACO,EAAgB,+BAAgCH,CAAA,CAClD,EAEKO,EAAoBC,GAA4C,CAC/D,GAAAA,EAA8C,OAASC,EACnD,OAAArB,EAAM,aAAaoB,EAA8C,CACtE,QAAAd,EACA,UAAWa,CAAA,CACZ,EACH,GAAYC,EAA4C,OAASE,EAAU,CACrE,IAAAC,EAAYH,EAA4C,OAASE,EAC9D,OAAAtB,EAAM,aAAaoB,EAA4C,CACpE,KAAMX,GAAA,KAAAA,EAAQc,EAAS,QAAQ,KAC/B,KAAAnB,EACA,QAAAE,EACA,MAAO,CAAC,CAAC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AAIC,EAAM,SAAUkB,CAAgB,CACtD,CAEJ,CACF,CACF,CAEJ,CAAC"}
1
+ {"version":3,"file":"FormGroup.js","sources":["../src/components/FormGroup/FormGroup.tsx"],"sourcesContent":["import React from 'react';\n\nimport classNames from 'classnames';\n\nimport formGroupStyles from './styles.module.scss';\nimport Checkbox, { CheckboxProps } from '../Checkbox/Checkbox';\nimport { AnalyticsId, FormMode, FormVariant } from '../../constants';\nimport RadioButton, { RadioButtonProps } from '../RadioButton/RadioButton';\nimport Input, { InputProps } from '../Input/Input';\nimport Title from '../Title';\nimport FormLayout, { FormLayoutProps } from '../FormLayout';\nimport ErrorWrapper from '../ErrorWrapper';\nimport Select, { SelectProps } from '../Select';\n\nexport type FormGroupTags = 'fieldset' | 'div';\n\nexport interface FormGroupProps {\n /** title for the the fieldset */\n title?: string;\n /** text placed in the legend tag of the fieldset */\n legend?: string;\n /** Items in the FormGroup component */\n children?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Changes the visuals of the formgroup */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the formgroup */\n variant?: keyof typeof FormVariant;\n /** Error message */\n error?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Unique identifyer for the child input tags */\n name?: string;\n /** Sets div instead of fieldset tag */\n htmlMarkup?: FormGroupTags;\n}\n\nexport const FormGroup = React.forwardRef((props: FormGroupProps, ref: React.ForwardedRef<HTMLDivElement>) => {\n const { className, mode = FormMode.onwhite, variant = FormVariant.normal, error, name, htmlMarkup = 'fieldset' } = props;\n const onDark = mode === FormMode.ondark;\n const bigform = variant === FormVariant.bigform;\n const formGroupWrapperClasses = classNames(\n formGroupStyles['form-group-wrapper'],\n {\n [formGroupStyles['form-group-wrapper--on-dark']]: onDark,\n [formGroupStyles['form-group-wrapper--invalid']]: error,\n },\n className\n );\n const titleClasses = classNames(formGroupStyles['form-group-wrapper__title'], {\n [formGroupStyles['form-group-wrapper__title--on-dark']]: onDark && !error,\n [formGroupStyles['form-group-wrapper__title--bigform']]: bigform,\n });\n const formGroupClasses = classNames(formGroupStyles['form-group']);\n\n const legendClasses = classNames(formGroupStyles['field-set__legend'], {\n [formGroupStyles['field-set__legend--on-dark']]: onDark && !error,\n [formGroupStyles['field-set__legend--bigform']]: bigform,\n });\n\n const mapFormComponent = (child: React.ReactNode): React.ReactNode => {\n if ((child as React.ReactElement<FormLayoutProps>).type === FormLayout) {\n return React.cloneElement(child as React.ReactElement<FormLayoutProps>, {\n variant,\n mapHelper: mapFormComponent,\n });\n } else if ((child as React.ReactElement<CheckboxProps>).type === Checkbox) {\n let checkbox = (child as React.ReactElement<CheckboxProps>).type === Checkbox;\n return React.cloneElement(child as React.ReactElement<CheckboxProps>, {\n name: name ?? checkbox.valueOf.name,\n mode,\n variant,\n error: !!error,\n });\n } else if ((child as React.ReactElement<RadioButtonProps>).type === RadioButton) {\n let radioButton = (child as React.ReactElement<RadioButtonProps>).type === RadioButton;\n return React.cloneElement(child as React.ReactElement<RadioButtonProps>, {\n name: name ?? radioButton.valueOf.name,\n mode,\n variant,\n error: !!error,\n });\n } else if ((child as React.ReactElement<InputProps>).type === Input) {\n let input = (child as React.ReactElement<InputProps>).type === Input;\n return React.cloneElement(child as React.ReactElement<InputProps>, {\n name: name ?? input.valueOf.name,\n mode,\n variant,\n error: !!error,\n });\n } else if ((child as React.ReactElement<SelectProps>).type === Select) {\n let select = (child as React.ReactElement<SelectProps>).type === Select;\n return React.cloneElement(child as React.ReactElement<SelectProps>, {\n name: name ?? select.valueOf.name,\n mode,\n error: !!error,\n });\n }\n return child;\n };\n\n return (\n <div data-testid={props.testId} data-analyticsid={AnalyticsId.FormGroup} className={formGroupWrapperClasses} ref={ref} tabIndex={-1}>\n {props.title && (\n <Title className={titleClasses} htmlMarkup={'h4'} appearance={'title4'} margin={{ marginTop: 0, marginBottom: error ? 1 : 2 }}>\n {props.title}\n </Title>\n )}\n <ErrorWrapper errorText={error}>\n <div className={formGroupClasses}>\n {htmlMarkup === 'div' && (\n <div id={props.title} className={formGroupStyles['field-set']}>\n {props.legend && <h5 className={legendClasses}>{props.legend}</h5>}\n {React.Children.map(props.children, mapFormComponent)}\n </div>\n )}\n {htmlMarkup === 'fieldset' && (\n <fieldset name={props.title} className={formGroupStyles['field-set']}>\n {props.legend && <legend className={legendClasses}>{props.legend}</legend>}\n {React.Children.map(props.children, mapFormComponent)}\n </fieldset>\n )}\n </div>\n </ErrorWrapper>\n </div>\n );\n});\n\nexport default FormGroup;\n"],"names":["FormGroup","React","props","ref","className","mode","FormMode","variant","FormVariant","error","name","htmlMarkup","onDark","bigform","formGroupWrapperClasses","classNames","formGroupStyles","titleClasses","formGroupClasses","legendClasses","mapFormComponent","child","FormLayout","Checkbox","checkbox","RadioButton","radioButton","Input","input","Select","select","AnalyticsId","Title","ErrorWrapper"],"mappings":"maAuCO,MAAMA,EAAYC,EAAM,WAAW,CAACC,EAAuBC,IAA4C,CAC5G,KAAM,CAAE,UAAAC,EAAW,KAAAC,EAAOC,EAAS,QAAS,QAAAC,EAAUC,EAAY,OAAQ,MAAAC,EAAO,KAAAC,EAAM,WAAAC,EAAa,UAAA,EAAeT,EAC7GU,EAASP,IAASC,EAAS,OAC3BO,EAAUN,IAAYC,EAAY,QAClCM,EAA0BC,EAC9BC,EAAgB,sBAChB,CACE,CAACA,EAAgB,gCAAiCJ,EAClD,CAACI,EAAgB,gCAAiCP,CACpD,EACAL,CAAA,EAEIa,EAAeF,EAAWC,EAAgB,6BAA8B,CAC5E,CAACA,EAAgB,uCAAwCJ,GAAU,CAACH,EACpE,CAACO,EAAgB,uCAAwCH,CAAA,CAC1D,EACKK,EAAmBH,EAAWC,EAAgB,aAAa,EAE3DG,EAAgBJ,EAAWC,EAAgB,qBAAsB,CACrE,CAACA,EAAgB,+BAAgCJ,GAAU,CAACH,EAC5D,CAACO,EAAgB,+BAAgCH,CAAA,CAClD,EAEKO,EAAoBC,GAA4C,CAC/D,GAAAA,EAA8C,OAASC,EACnD,OAAArB,EAAM,aA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AAA,EACtBR,EAAA,cAAA,MAAA,CAAI,UAAWiB,CACb,EAAAP,IAAe,OACbV,EAAA,cAAA,MAAA,CAAI,GAAIC,EAAM,MAAO,UAAWc,EAAgB,YAC9C,EAAAd,EAAM,QAAWD,EAAA,cAAA,KAAA,CAAG,UAAWkB,CAAA,EAAgBjB,EAAM,MAAO,EAC5DD,EAAM,SAAS,IAAIC,EAAM,SAAUkB,CAAgB,CACtD,EAEDT,IAAe,YACbV,EAAA,cAAA,WAAA,CAAS,KAAMC,EAAM,MAAO,UAAWc,EAAgB,YACrD,EAAAd,EAAM,QAAWD,EAAA,cAAA,SAAA,CAAO,UAAWkB,CAAA,EAAgBjB,EAAM,MAAO,EAChED,EAAM,SAAS,IAAIC,EAAM,SAAUkB,CAAgB,CACtD,CAEJ,CACF,CACF,CAEJ,CAAC"}
package/HelpBubble.js CHANGED
@@ -1,2 +1,2 @@
1
- import y from"classnames";import t,{useRef as T,useState as E,useCallback as P,useEffect as R}from"react";import{AnalyticsId as de}from"./constants.js";import{useEventListenerState as j}from"./hooks/useEventListenerState.js";import{useGetDOMRect as pe}from"./hooks/useGetDOMRect.js";import{A as he}from"./AnchorLink.js";import{C as me}from"./Close.js";import e from"./components/HelpBubble/styles.module.scss";var fe=(s=>(s.positionautomatic="positionautomatic",s.positionbelow="positionbelow",s.positionabove="positionabove",s))(fe||{});const Le=s=>{const{helpBubbleId:F,children:H,controllerRef:n,className:U="",variant:a="positionautomatic",showBubble:b,noCloseButton:L,linkText:f="Mer hjelp",linkUrl:A,onLinkClick:W,onClose:G,closeAriaLabel:Y,testId:q}=s,J=373,w=12,_=3;let C,k;const u=T(null),x=T(null),[d,K]=pe(n,b,100),[S,X]=E(!0),[Q,V]=j(a),[Z,ee]=E(0),[v,te]=E({x:0,y:0}),[N,ne]=E({x:0,y:0}),[g,I]=j(a!=="positionbelow"),oe=y(e.helpbubble,{[e["helpbubble--initial-render"]]:S},U),re=y(e["helpbubble-arrow"],{[e["helpbubble-arrow--initial-render"]]:S,[e["helpbubble-arrow--under"]]:g.current,[e["helpbubble-arrow--over"]]:!g.current}),le=()=>{if(Q.current==="positionautomatic"&&u.current&&n.current){const o=n.current.getBoundingClientRect().y,r=u.current.getBoundingClientRect().height;I(o>r)}},O=()=>document.documentElement.clientWidth>J+w*2,$=()=>{if(n.current&&u.current&&x.current){const o=document.documentElement.clientWidth,r=d.x>0?d.x:n.current.getBoundingClientRect().x,l=d.y>0?d.y:n.current.getBoundingClientRect().y,h=n.current.getBoundingClientRect(),c=u.current.getBoundingClientRect(),i=x.current.getBoundingClientRect(),m=h.width/2,B=ie(c.width,r,m,o);O()||ee(o-w*2),te({x:B,y:g.current?l-i.height-c.height+_:l+h.height+i.height-_}),ne({x:r+m-i.width/2,y:g.current?l-i.height:l+h.height})}},ie=(o,r,l,h)=>{const c=o/2,i=r+l,m=i-c,B=h-i-c,be=m<0?m-w:0,ue=B<0?B-w:0;return r+l-c-be+ue},se=()=>{O()?C={left:`${v.x}px`,top:`${v.y}px`}:C={left:`${v.x}px`,top:`${v.y}px`,width:`${Z}px`},k={left:`${N.x}px`,top:`${N.y}px`}},p=()=>{le(),$()},z=P(()=>{p()},[]),D=P(()=>{p()},[]),ce=()=>{window.addEventListener("scroll",z,!1),window.addEventListener("resize",D,!1)},M=()=>{window.removeEventListener("scroll",z,!1),window.removeEventListener("resize",D,!1)};R(()=>($(),()=>{M()}),[]),R(()=>{p()},[d]),R(()=>{b?(X(!1),ce(),p()):b||(X(!0),M(),K())},[b]),R(()=>{V(a),I(a!=="positionbelow"),p()},[a]),se();const ae=()=>{if(W&&f)return t.createElement("button",{className:e["helpbubble__link-button"],onClick:W},f);if(A&&f)return t.createElement(he,{href:A},f)};return b?t.createElement(t.Fragment,null,t.createElement("div",{id:F,ref:u,style:C,className:oe,"data-testid":q,"data-analyticsid":de.HelpBubble,role:"tooltip"},t.createElement("div",{className:y(e["helpbubble__child-wrapper"],{[e["helpbubble__child-wrapper--no-close-button"]]:L})},H,ae()),!L&&t.createElement("div",{className:e["helpbubble__close-wrapper"]},t.createElement(me,{small:!0,onClick:G,ariaLabel:Y}))),t.createElement("div",{ref:x,style:k,className:re})):null};export{Le as H,fe as a};
1
+ import _ from"classnames";import s,{useRef as I,useState as J,useEffect as K}from"react";import{AnalyticsId as Q}from"./constants.js";import{useInterval as Y}from"./hooks/useInterval.js";import{useIsVisible as $}from"./hooks/useIsVisible.js";import{useLayoutEvent as z}from"./hooks/useLayoutEvent.js";import{useSize as S}from"./hooks/useSize.js";import{A as tt}from"./AnchorLink.js";import{C as et}from"./Close.js";import l from"./components/HelpBubble/styles.module.scss";const ot=373,c=12,d=16,T=20,nt=4,W=12,k=(t,e,i)=>i!==b.positionautomatic?i:t.top>e.height+d?b.positionabove:b.positionbelow,y=t=>t.left+t.width/2,it=t=>document.documentElement.clientWidth-t.right+t.width/2,g=(t,e)=>y(t)-e.width/2,rt=(t,e)=>g(t,e)+e.width,st=(t,e)=>g(t,e)>c,lt=(t,e)=>rt(t,e)<document.documentElement.clientWidth-c,bt=(t,e)=>lt(t,e)?st(t,e)?"floating":"left":"right",v=(t,e)=>t.top-d-e.height,x=t=>t.bottom+d,ct=()=>document.documentElement.clientWidth-c*2,ut=()=>document.documentElement.clientWidth>ot+c*2,N=t=>t.top-d-nt,at=t=>y(t)-T/2,ft=t=>it(t)-T/2,ht=(t,e,i)=>{const n=bt(t,e),o=k(t,e,i);return n==="left"?o===b.positionabove?"leftabove":"leftbelow":n==="right"?o===b.positionabove?"rightabove":"rightbelow":o===b.positionabove?"floatingabove":"floatingbelow"},mt=(t,e,i)=>{const n=ht(t,e,i),o=ut()?void 0:ct();return n==="leftabove"?{left:c,top:v(t,e),width:o}:n==="leftbelow"?{left:c,top:x(t),width:o}:n==="rightabove"?{right:c,top:v(t,e),width:o}:n==="rightbelow"?{right:c,top:x(t),width:o}:n==="floatingbelow"?{left:g(t,e),top:x(t),width:o}:{left:g(t,e),top:v(t,e),width:o}},pt=(t,e,i)=>{const n=at(e),o=ft(e),u=t.left+W,r=t.right+W;return t.right?i===b.positionabove?{right:o>r?o:r,top:N(e)}:{right:o>r?o:r,top:e.bottom}:i===b.positionabove?{left:n>u?n:u,top:N(e)}:{left:n>u?n:u,top:e.bottom}};var b=(t=>(t.positionautomatic="positionautomatic",t.positionbelow="positionbelow",t.positionabove="positionabove",t))(b||{});const Et=t=>{const{helpBubbleId:e,children:i,controllerRef:n,className:o="",variant:u="positionautomatic",showBubble:r,noCloseButton:R,linkText:h="Mer hjelp",linkUrl:B,onLinkClick:C,onClose:O,closeAriaLabel:H,role:E,testId:F}=t,L=I(null),X=I(null),m=S(L),[a,V]=J(),D=$(n,0),w=()=>{var A;V((A=n.current)==null?void 0:A.getBoundingClientRect())};Y(w,500),z(w,["scroll","resize"],10),K(()=>{r&&w()},[r]);const f=E==="tooltip";if(!r&&!f)return null;const M=_(l.helpbubble,{[l["helpbubble--visible"]]:!f&&D||f&&r},o),p=a&&m&&k(a,m,u),U=_(l.helpbubble__arrow,{[l["helpbubble__arrow--over"]]:p==="positionbelow",[l["helpbubble__arrow--under"]]:p==="positionabove"}),G=_(l.helpbubble__content,{[l["helpbubble__content--close"]]:!R&&!f}),P=a&&m&&mt(a,m,u),j=P&&a&&p&&pt(P,a,p),Z=()=>{if(!f){if(C&&h)return s.createElement("button",{className:l.helpbubble__link,onClick:C,type:"button"},h);if(B&&h)return s.createElement(tt,{href:B},h)}},q=()=>{if(!(R||f))return s.createElement("div",{className:l.helpbubble__close},s.createElement(et,{small:!0,onClick:O,ariaLabel:H}))};return s.createElement(s.Fragment,null,s.createElement("div",{id:e,ref:L,className:M,style:P,"data-testid":F,"data-analyticsid":Q.HelpBubble,role:E},q(),s.createElement("div",{className:G},i,Z())),s.createElement("div",{ref:X,className:U,style:j}))};export{Et as H,b as a};
2
2
  //# sourceMappingURL=HelpBubble.js.map
package/HelpBubble.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"HelpBubble.js","sources":["../src/components/HelpBubble/HelpBubble.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { AnalyticsId } from '../../constants';\nimport { useEventListenerState } from '../../hooks/useEventListenerState';\nimport { useGetDOMRect } from '../../hooks/useGetDOMRect';\nimport AnchorLink from '../AnchorLink';\nimport Close from '../Close';\n\nimport styles from './styles.module.scss';\n\nexport enum HelpBubbleVariant {\n positionautomatic = 'positionautomatic',\n positionbelow = 'positionbelow',\n positionabove = 'positionabove',\n}\n\nexport interface HelpBubbleProps {\n /** Id of the HelpBubble */\n helpBubbleId?: string;\n /** Name to display in the avatar. Will be truncated to the first two characters. */\n children: React.ReactNode;\n /** Ref for the element the HelpBubble is placed upon */\n controllerRef: React.RefObject<HTMLElement | SVGSVGElement>;\n /** Adds custom classes to the element. */\n className?: string;\n /** Determines the placement of the helpbubble */\n variant?: keyof typeof HelpBubbleVariant;\n /** Visible text on the link */\n showBubble?: boolean;\n /** Visible text on the link */\n noCloseButton?: boolean;\n /** Visible text on the link */\n linkText?: string;\n /** Url the link leads to */\n linkUrl?: string;\n /** Function is called when link is clicked */\n onLinkClick?: () => void;\n /** Function is called when user clicks the button */\n onClose?: () => void;\n /** aria-label to be passed onto Close */\n closeAriaLabel?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst HelpBubble: React.FC<HelpBubbleProps> = props => {\n const {\n helpBubbleId,\n children,\n controllerRef,\n className = '',\n variant = HelpBubbleVariant.positionautomatic,\n showBubble,\n noCloseButton,\n linkText = 'Mer hjelp',\n linkUrl,\n onLinkClick,\n onClose,\n closeAriaLabel,\n testId,\n } = props;\n\n /* Bredde på HelpBubble */\n const BUBBLE_WIDTH_PX = 373;\n /* Hjelpeboblen skal holde avstand til venstre/høyre kant på vinduet */\n const WINDOW_MARGIN_PX = 12;\n /* Y akse Offset på HelpBubble arrow */\n const ARROW_Y_OFFSET = 3;\n\n let bubblePositionStyle = undefined;\n let arrowPositionStyle = undefined;\n const bubbleRef = useRef<HTMLDivElement>(null);\n const arrowRef = useRef<HTMLDivElement>(null);\n const [controllerDOM, resetControllerDOM] = useGetDOMRect(controllerRef, showBubble, 100);\n const [initialRender, setInitialRender] = useState(true);\n const [eventListenerVariant, setEventListenerVariant] = useEventListenerState(variant);\n const [customBubbleWidth, setCustomBubbleWidth] = useState(0);\n const [translateBubble, setTranslateBubble] = useState({ x: 0, y: 0 });\n const [translateArrow, setTranslateArrow] = useState({ x: 0, y: 0 });\n const [bubbleAbove, setBubbleAbove] = useEventListenerState(variant !== HelpBubbleVariant.positionbelow);\n\n const helpBubbleClasses = classNames(\n styles.helpbubble,\n {\n [styles['helpbubble--initial-render']]: initialRender,\n },\n className\n );\n const arrowClasses = classNames(styles['helpbubble-arrow'], {\n [styles['helpbubble-arrow--initial-render']]: initialRender,\n [styles['helpbubble-arrow--under']]: bubbleAbove.current,\n [styles['helpbubble-arrow--over']]: !bubbleAbove.current,\n });\n\n const checkSpaceAbove = () => {\n if (eventListenerVariant.current === HelpBubbleVariant.positionautomatic && bubbleRef.current && controllerRef.current) {\n const controllerBottom = controllerRef.current.getBoundingClientRect().y;\n const bubbleHeight = bubbleRef.current.getBoundingClientRect().height;\n setBubbleAbove(controllerBottom > bubbleHeight);\n }\n };\n\n const checkBubbleFitsScreenWidth = () => {\n const windowWidth = document.documentElement.clientWidth;\n return windowWidth > BUBBLE_WIDTH_PX + WINDOW_MARGIN_PX * 2;\n };\n\n const updateTranslate = () => {\n if (controllerRef.current && bubbleRef.current && arrowRef.current) {\n // Henter ut størrelser og posisjoner som trengs til kalkulering av HelpBubble posisjonering\n const clientWidth = document.documentElement.clientWidth;\n const controllerX = controllerDOM.x > 0 ? controllerDOM.x : controllerRef.current.getBoundingClientRect().x;\n const controllerY = controllerDOM.y > 0 ? controllerDOM.y : controllerRef.current.getBoundingClientRect().y;\n const controllerSize = controllerRef.current.getBoundingClientRect();\n const bubbleSize = bubbleRef.current.getBoundingClientRect();\n const arrowSize = arrowRef.current.getBoundingClientRect();\n const controllerHalfWidth = controllerSize.width / 2;\n const newBubbleX = getBubbleXAdjustment(bubbleSize.width, controllerX, controllerHalfWidth, clientWidth);\n\n if (!checkBubbleFitsScreenWidth()) {\n setCustomBubbleWidth(clientWidth - WINDOW_MARGIN_PX * 2);\n }\n\n setTranslateBubble({\n x: newBubbleX,\n y: bubbleAbove.current\n ? controllerY - arrowSize.height - bubbleSize.height + ARROW_Y_OFFSET\n : controllerY + controllerSize.height + arrowSize.height - ARROW_Y_OFFSET,\n });\n setTranslateArrow({\n x: controllerX + controllerHalfWidth - arrowSize.width / 2,\n y: bubbleAbove.current ? controllerY - arrowSize.height : controllerY + controllerSize.height,\n });\n }\n };\n\n const getBubbleXAdjustment = (bubbleWidth: number, controllerX: number, controllerHalf: number, clientWidth: number) => {\n const bubbleHalfWidth = bubbleWidth / 2;\n\n // Kalkulerer om HelpBubble går utenfor viewporten\n const controllerXMiddle = controllerX + controllerHalf;\n const bubbleControllerDifferenceX = controllerXMiddle - bubbleHalfWidth;\n const bubbleRightOverlap = clientWidth - controllerXMiddle - bubbleHalfWidth;\n\n // Justerer x akse posisjon utifra funnene over\n const viewportXLeftAdjustment = bubbleControllerDifferenceX < 0 ? bubbleControllerDifferenceX - WINDOW_MARGIN_PX : 0;\n const viewportXRightAdjustment = bubbleRightOverlap < 0 ? bubbleRightOverlap - WINDOW_MARGIN_PX : 0;\n\n // Returnerer den justerte x posisjonen\n const tempBubbleX = controllerX + controllerHalf - bubbleHalfWidth;\n return tempBubbleX - viewportXLeftAdjustment + viewportXRightAdjustment;\n };\n\n const updatePositionStyle = () => {\n if (checkBubbleFitsScreenWidth()) {\n bubblePositionStyle = {\n left: `${translateBubble.x}px`,\n top: `${translateBubble.y}px`,\n };\n } else {\n bubblePositionStyle = {\n left: `${translateBubble.x}px`,\n top: `${translateBubble.y}px`,\n width: `${customBubbleWidth}px`,\n };\n }\n\n arrowPositionStyle = {\n left: `${translateArrow.x}px`,\n top: `${translateArrow.y}px`,\n };\n };\n\n const handleBubbleUpdate = () => {\n checkSpaceAbove();\n updateTranslate();\n };\n\n const handleScroll = useCallback((): void => {\n handleBubbleUpdate();\n }, []);\n\n const handleResize = useCallback((): void => {\n handleBubbleUpdate();\n }, []);\n\n const addEventListeners = () => {\n window.addEventListener('scroll', handleScroll, false);\n window.addEventListener('resize', handleResize, false);\n };\n\n const removeEventListeners = () => {\n window.removeEventListener('scroll', handleScroll, false);\n window.removeEventListener('resize', handleResize, false);\n };\n\n useEffect(() => {\n updateTranslate();\n\n return (): void => {\n removeEventListeners();\n };\n }, []);\n\n useEffect(() => {\n handleBubbleUpdate();\n }, [controllerDOM]);\n\n useEffect(() => {\n if (showBubble) {\n setInitialRender(false);\n addEventListeners();\n handleBubbleUpdate();\n } else if (!showBubble) {\n setInitialRender(true);\n removeEventListeners();\n resetControllerDOM();\n }\n }, [showBubble]);\n\n useEffect(() => {\n setEventListenerVariant(variant);\n setBubbleAbove(variant !== HelpBubbleVariant.positionbelow);\n handleBubbleUpdate();\n }, [variant]);\n\n updatePositionStyle();\n\n const renderLink = () => {\n if (onLinkClick && linkText) {\n return (\n <button className={styles['helpbubble__link-button']} onClick={onLinkClick}>\n {linkText}\n </button>\n );\n } else if (linkUrl && linkText) {\n return <AnchorLink href={linkUrl}>{linkText}</AnchorLink>;\n }\n };\n\n return showBubble ? (\n <>\n <div\n id={helpBubbleId}\n ref={bubbleRef}\n style={bubblePositionStyle}\n className={helpBubbleClasses}\n data-testid={testId}\n data-analyticsid={AnalyticsId.HelpBubble}\n role={'tooltip'}\n >\n <div\n className={classNames(styles['helpbubble__child-wrapper'], {\n [styles['helpbubble__child-wrapper--no-close-button']]: noCloseButton,\n })}\n >\n {children}\n {renderLink()}\n </div>\n {!noCloseButton && (\n <div className={styles['helpbubble__close-wrapper']}>\n <Close small onClick={onClose} ariaLabel={closeAriaLabel} />\n </div>\n )}\n </div>\n <div ref={arrowRef} style={arrowPositionStyle} className={arrowClasses} />\n </>\n ) : null;\n};\n\nexport default HelpBubble;\n"],"names":["HelpBubbleVariant","HelpBubble","props","helpBubbleId","children","controllerRef","className","variant","showBubble","noCloseButton","linkText","linkUrl","onLinkClick","onClose","closeAriaLabel","testId","BUBBLE_WIDTH_PX","WINDOW_MARGIN_PX","ARROW_Y_OFFSET","bubblePositionStyle","arrowPositionStyle","bubbleRef","useRef","arrowRef","controllerDOM","resetControllerDOM","useGetDOMRect","initialRender","setInitialRender","useState","eventListenerVariant","setEventListenerVariant","useEventListenerState","customBubbleWidth","setCustomBubbleWidth","translateBubble","setTranslateBubble","translateArrow","setTranslateArrow","bubbleAbove","setBubbleAbove","helpBubbleClasses","classNames","styles","arrowClasses","checkSpaceAbove","controllerBottom","bubbleHeight","checkBubbleFitsScreenWidth","updateTranslate","clientWidth","controllerX","controllerY","controllerSize","bubbleSize","arrowSize","controllerHalfWidth","newBubbleX","getBubbleXAdjustment","bubbleWidth","controllerHalf","bubbleHalfWidth","controllerXMiddle","bubbleControllerDifferenceX","bubbleRightOverlap","viewportXLeftAdjustment","viewportXRightAdjustment","updatePositionStyle","handleBubbleUpdate","handleScroll","useCallback","handleResize","addEventListeners","removeEventListeners","useEffect","renderLink","React","AnchorLink","AnalyticsId","Close"],"mappings":"0ZAWY,IAAAA,IAAAA,IACVA,EAAA,kBAAoB,oBACpBA,EAAA,cAAgB,gBAChBA,EAAA,cAAgB,gBAHNA,IAAAA,IAAA,CAAA,CAAA,EAmCZ,MAAMC,GAAiDC,GAAA,CAC/C,KAAA,CACJ,aAAAC,EACA,SAAAC,EACA,cAAAC,EACA,UAAAC,EAAY,GACZ,QAAAC,EAAU,oBACV,WAAAC,EACA,cAAAC,EACA,SAAAC,EAAW,YACX,QAAAC,EACA,YAAAC,EACA,QAAAC,EACA,eAAAC,EACA,OAAAC,CACE,EAAAb,EAGEc,EAAkB,IAElBC,EAAmB,GAEnBC,EAAiB,EAEvB,IAAIC,EACAC,EACE,MAAAC,EAAYC,EAAuB,IAAI,EACvCC,EAAWD,EAAuB,IAAI,EACtC,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WC,CAAgB,CAAA,CAC5D,CAEJ,EACC8D,EAAA,cAAA,MAAA,CAAI,IAAKrD,EAAU,MAAOH,EAAoB,UAAWwB,EAAA,CAAc,CAC1E,EACE,IACN"}
1
+ {"version":3,"file":"HelpBubble.js","sources":["../src/components/HelpBubble/utils.ts","../src/components/HelpBubble/HelpBubble.tsx"],"sourcesContent":["import { CSSProperties } from 'react';\nimport { HelpBubbleVariant } from './HelpBubble';\n\ntype HorizontalPosition = 'left' | 'right' | 'floating';\ntype BubblePosition = 'leftabove' | 'leftbelow' | 'rightabove' | 'rightbelow' | 'floatingabove' | 'floatingbelow';\n\n/** Bredde på hjelpeboble */\nconst BUBBLE_WIDTH_PX = 373;\n/** Hjelpeboblen skal holde avstand til venstre/høyre kant på vinduet */\nconst WINDOW_MARGIN_PX = 12;\n/** Vertikal avstand fra hjelpeboble til kontroller */\nconst BUBBLE_VERTICAL_OFFSET_PX = 16;\n/** Høyde/bredde på pil */\nconst ARROW_WIDTH_PX = 20;\n/** Avstand fra pil til hjelpeboble */\nconst ARROW_VERTICAL_OFFSET_PX = 4;\n/** Pilen skal holde avstand til venstre/høyre kant av hjelpeboblen */\nconst ARROW_HORIZONTAL_MARGIN_PX = 12;\n\n/**\n * Beregn om hjelpeboblen skal vises over eller under kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under/automatisk)\n * @returns Om hjelpeboblen skal vises over eller under\n */\nexport const getVerticalPosition = (\n controllerSize: DOMRect,\n bubbleSize: DOMRect,\n variant: keyof typeof HelpBubbleVariant\n): keyof typeof HelpBubbleVariant => {\n if (variant !== HelpBubbleVariant.positionautomatic) {\n return variant;\n }\n if (controllerSize.top > bubbleSize.height + BUBBLE_VERTICAL_OFFSET_PX) {\n return HelpBubbleVariant.positionabove;\n } else {\n return HelpBubbleVariant.positionbelow;\n }\n};\n\n/**\n * Finn horisontalt midtpunkt på kontrolleren i forhold til venstre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Horisontalt senter av controlleren i px\n */\nconst getControllerLeftCenterPx = (controllerSize: DOMRect): number => controllerSize.left + controllerSize.width / 2;\n\n/**\n * Finn horisontalt midtpunkt på kontrolleren i forhold til høyre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Horisontalt senter av controlleren i px\n */\nconst getControllerRightCenterPx = (controllerSize: DOMRect): number =>\n document.documentElement.clientWidth - controllerSize.right + controllerSize.width / 2;\n\n/**\n * Finn venstre kant av hjelpeboblen i forhold til kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns Venstre kant av hjelpeboblen i px\n */\nconst getBubbleLeftPx = (controllerSize: DOMRect, bubbleSize: DOMRect): number => {\n const controllerHorizontalCenterPx = getControllerLeftCenterPx(controllerSize);\n\n return controllerHorizontalCenterPx - bubbleSize.width / 2;\n};\n\n/**\n * Finn høyre kant av hjelpeboblen i forhold til kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns Høyre kant av hjelpeboblen i px\n */\nconst getBubbleRightPx = (controllerSize: DOMRect, bubbleSize: DOMRect): number => {\n const bubbleLeftPx = getBubbleLeftPx(controllerSize, bubbleSize);\n\n return bubbleLeftPx + bubbleSize.width;\n};\n\n/**\n * Sjekk om venstre kant av hjelpeboblen er innenfor vinduet\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns true dersom venstre kant er innenfor vinduet\n */\nconst getBubbleLeftVisible = (controllerSize: DOMRect, bubbleSize: DOMRect): boolean => {\n const bubbleLeftPx = getBubbleLeftPx(controllerSize, bubbleSize);\n\n return bubbleLeftPx > WINDOW_MARGIN_PX;\n};\n\n/**\n * Sjekk om høyre kant av hjelpeboblen er innenfor vinduet\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns true dersom høyre kant er innenfor vinduet\n */\nconst getBubbleRightIsVisible = (controllerSize: DOMRect, bubbleSize: DOMRect): boolean => {\n const bubbleRightPx = getBubbleRightPx(controllerSize, bubbleSize);\n\n return bubbleRightPx < document.documentElement.clientWidth - WINDOW_MARGIN_PX;\n};\n\n/**\n * Finn riktig horisontal plassering til hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns left, right eller floating\n */\nconst getHorizontalPosition = (controllerSize: DOMRect, bubbleSize: DOMRect): HorizontalPosition => {\n if (!getBubbleRightIsVisible(controllerSize, bubbleSize)) {\n return 'right';\n }\n if (!getBubbleLeftVisible(controllerSize, bubbleSize)) {\n return 'left';\n }\n\n return 'floating';\n};\n\n/**\n * Finn vertikal plassering av hjelpeboblen når den skal vises over\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns \"Top\" for hjelpeboblen i px\n */\nconst getBubbleAbovePx = (controllerSize: DOMRect, bubbleSize: DOMRect): number =>\n controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - bubbleSize.height;\n\n/**\n * Finn vertikal plassering av hjelpeboblen når den skal vises under\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns \"Top\" for hjelpeboblen i px\n */\nconst getBubbleBelowPx = (controllerSize: DOMRect): number => controllerSize.bottom + BUBBLE_VERTICAL_OFFSET_PX;\n\n/**\n * Finn maks bredde på hjelpeboblen i forhold til vinduet\n * @returns Bredde på hjelpeboblen i px\n */\nconst getBubbleWidth = (): number => document.documentElement.clientWidth - WINDOW_MARGIN_PX * 2;\n\n/**\n * Sjekk om hjelpeboblen har plass i vinduet\n * @returns true dersom det er plass til hjelpeboblen i vinduet\n */\nconst getBubbleFitsInWindow = (): boolean => {\n return document.documentElement.clientWidth > BUBBLE_WIDTH_PX + WINDOW_MARGIN_PX * 2;\n};\n\n/**\n * Finn vertikal plassering av pilen når den skal vises over\n * @param controllerSize DOMRect for controlleren\n * @returns \"Top\" for pilen i px\n */\nconst getArrowTopxPx = (controllerSize: DOMRect): number => controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - ARROW_VERTICAL_OFFSET_PX;\n\n/**\n * Finn horisontal plassering av pilen i forhold til venstre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Venstre kant av pilen i px\n */\nconst getArrowLeftPx = (controllerSize: DOMRect): number => getControllerLeftCenterPx(controllerSize) - ARROW_WIDTH_PX / 2;\n\n/**\n * Finn horisontal plassering av pilen\n * @param controllerSize DOMRect for controlleren\n * @returns Venstre kant av pilen i px\n */\nconst getArrowRightPx = (controllerSize: DOMRect): number => getControllerRightCenterPx(controllerSize) - ARROW_WIDTH_PX / 2;\n\n/**\n * Finn riktig plassering av hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under)\n * @returns Beste mulige plassering av hjelpeboblen\n */\nconst getBubblePosition = (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof HelpBubbleVariant): BubblePosition => {\n const horizontalPosition = getHorizontalPosition(controllerSize, bubbleSize);\n const verticalPosition = getVerticalPosition(controllerSize, bubbleSize, variant);\n\n if (horizontalPosition === 'left') {\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return 'leftabove';\n }\n return 'leftbelow';\n }\n\n if (horizontalPosition === 'right') {\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return 'rightabove';\n }\n return 'rightbelow';\n }\n\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return 'floatingabove';\n }\n\n return 'floatingbelow';\n};\n\n/**\n * Finn riktig plassering av hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under)\n * @returns CSSProperties som plasserer hjelpeboblen riktig\n */\nexport const getBubbleStyle = (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof HelpBubbleVariant): CSSProperties => {\n const bubblePosition = getBubblePosition(controllerSize, bubbleSize, variant);\n const bubbleWidth = !getBubbleFitsInWindow() ? getBubbleWidth() : undefined;\n\n if (bubblePosition === 'leftabove') {\n return {\n left: WINDOW_MARGIN_PX,\n top: getBubbleAbovePx(controllerSize, bubbleSize),\n width: bubbleWidth,\n };\n }\n if (bubblePosition === 'leftbelow') {\n return { left: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n if (bubblePosition === 'rightabove') {\n return { right: WINDOW_MARGIN_PX, top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };\n }\n if (bubblePosition === 'rightbelow') {\n return { right: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n\n if (bubblePosition === 'floatingbelow') {\n return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n\n return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };\n};\n\n/**\n * Finn riktig plassering av pilen\n * @param bubbleStyle CSSProperties for hjelpeboblen\n * @param controllerSize DOMRect for kontrolleren\n * @param verticalPosition Ønsket plassering av hjelpeboblen (over/under)\n * @returns CSSProperties som plasserer pilen riktig\n */\nexport const getArrowStyle = (\n bubbleStyle: CSSProperties,\n controllerSize: DOMRect,\n verticalPosition: keyof typeof HelpBubbleVariant\n): CSSProperties => {\n const leftPx = getArrowLeftPx(controllerSize);\n const rightPx = getArrowRightPx(controllerSize);\n const minLeftPx = (bubbleStyle.left as number) + ARROW_HORIZONTAL_MARGIN_PX;\n const minRightPx = (bubbleStyle.right as number) + ARROW_HORIZONTAL_MARGIN_PX;\n\n if (bubbleStyle.right) {\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return {\n right: rightPx > minRightPx ? rightPx : minRightPx,\n top: getArrowTopxPx(controllerSize),\n };\n }\n\n return {\n right: rightPx > minRightPx ? rightPx : minRightPx,\n top: controllerSize.bottom,\n };\n }\n\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return {\n left: leftPx > minLeftPx ? leftPx : minLeftPx,\n top: getArrowTopxPx(controllerSize),\n };\n }\n\n return {\n left: leftPx > minLeftPx ? leftPx : minLeftPx,\n top: controllerSize.bottom,\n };\n};\n","import classNames from 'classnames';\nimport React, { useEffect, useRef, useState } from 'react';\n\nimport { AnalyticsId } from '../../constants';\nimport { useInterval } from '../../hooks/useInterval';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useLayoutEvent } from '../../hooks/useLayoutEvent';\nimport { useSize } from '../../hooks/useSize';\nimport AnchorLink from '../AnchorLink';\nimport Close from '../Close';\n\nimport styles from './styles.module.scss';\nimport { getArrowStyle, getBubbleStyle, getVerticalPosition } from './utils';\n\nexport enum HelpBubbleVariant {\n positionautomatic = 'positionautomatic',\n positionbelow = 'positionbelow',\n positionabove = 'positionabove',\n}\n\ntype HelpBubbleRole = 'tooltip';\n\nexport interface HelpBubbleProps {\n /** Id of the HelpBubble */\n helpBubbleId?: string;\n /** Content shown inside HelpBubble. Note that if role=\"tooltip\", you must not include interactive/focusable elements. */\n children: React.ReactNode;\n /** Ref for the element the HelpBubble is placed upon */\n controllerRef: React.RefObject<HTMLElement | SVGSVGElement>;\n /** Adds custom classes to the element. */\n className?: string;\n /** Determines the placement of the helpbubble. Default: automatic positioning. */\n variant?: keyof typeof HelpBubbleVariant;\n /** Show the bubble. Default: false. */\n showBubble?: boolean;\n /** Hide the close button in the bubble. Close button is never rendered if role=\"tooltip\". */\n noCloseButton?: boolean;\n /** Visible text on the link. Link is never rendered if role=\"tooltip\". */\n linkText?: string;\n /** Url the link leads to */\n linkUrl?: string;\n /** Function is called when link is clicked */\n onLinkClick?: () => void;\n /** Function is called when user clicks the button */\n onClose?: () => void;\n /** aria-label to be passed onto Close */\n closeAriaLabel?: string;\n /** Sets role of the HelpBubble element. If set to \"tooltip\", */\n role?: HelpBubbleRole;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst HelpBubble: React.FC<HelpBubbleProps> = props => {\n const {\n helpBubbleId,\n children,\n controllerRef,\n className = '',\n variant = HelpBubbleVariant.positionautomatic,\n showBubble,\n noCloseButton,\n linkText = 'Mer hjelp',\n linkUrl,\n onLinkClick,\n onClose,\n closeAriaLabel,\n role,\n testId,\n } = props;\n\n const bubbleRef = useRef<HTMLDivElement>(null);\n const arrowRef = useRef<HTMLDivElement>(null);\n const bubbleSize = useSize(bubbleRef);\n const [controllerSize, setControllerSize] = useState<DOMRect>();\n const controllerisVisible = useIsVisible(controllerRef, 0);\n\n const updateControllerSize = (): void => {\n setControllerSize(controllerRef.current?.getBoundingClientRect());\n };\n\n useInterval(updateControllerSize, 500);\n useLayoutEvent(updateControllerSize, ['scroll', 'resize'], 10);\n\n useEffect(() => {\n if (showBubble) {\n updateControllerSize();\n }\n }, [showBubble]);\n\n const isTooltip = role === 'tooltip';\n\n if (!showBubble && !isTooltip) {\n return null;\n }\n\n const helpBubbleClasses = classNames(\n styles.helpbubble,\n { [styles['helpbubble--visible']]: (!isTooltip && controllerisVisible) || (isTooltip && showBubble) },\n className\n );\n const verticalPosition = controllerSize && bubbleSize && getVerticalPosition(controllerSize, bubbleSize, variant);\n const arrowClasses = classNames(styles.helpbubble__arrow, {\n [styles['helpbubble__arrow--over']]: verticalPosition === HelpBubbleVariant.positionbelow,\n [styles['helpbubble__arrow--under']]: verticalPosition === HelpBubbleVariant.positionabove,\n });\n const contentClasses = classNames(styles.helpbubble__content, {\n [styles['helpbubble__content--close']]: !noCloseButton && !isTooltip,\n });\n\n const bubbleStyle = controllerSize && bubbleSize && getBubbleStyle(controllerSize, bubbleSize, variant);\n const arrowStyle = bubbleStyle && controllerSize && verticalPosition && getArrowStyle(bubbleStyle, controllerSize, verticalPosition);\n\n const renderLink = (): JSX.Element | undefined => {\n // Det er ikke tillatt med interaktive/fokuserbare elementer i role=\"tooltip\"\n if (isTooltip) {\n return;\n }\n if (onLinkClick && linkText) {\n return (\n <button className={styles.helpbubble__link} onClick={onLinkClick} type=\"button\">\n {linkText}\n </button>\n );\n } else if (linkUrl && linkText) {\n return <AnchorLink href={linkUrl}>{linkText}</AnchorLink>;\n }\n };\n\n const renderCloseButton = (): JSX.Element | undefined => {\n if (noCloseButton || isTooltip) {\n return;\n }\n return (\n <div className={styles.helpbubble__close}>\n <Close small onClick={onClose} ariaLabel={closeAriaLabel} />\n </div>\n );\n };\n\n return (\n <>\n <div\n id={helpBubbleId}\n ref={bubbleRef}\n className={helpBubbleClasses}\n style={bubbleStyle}\n data-testid={testId}\n data-analyticsid={AnalyticsId.HelpBubble}\n role={role}\n >\n {renderCloseButton()}\n <div className={contentClasses}>\n {children}\n {renderLink()}\n </div>\n </div>\n <div ref={arrowRef} className={arrowClasses} style={arrowStyle} />\n </>\n );\n};\n\nexport default HelpBubble;\n"],"names":["BUBBLE_WIDTH_PX","WINDOW_MARGIN_PX","BUBBLE_VERTICAL_OFFSET_PX","ARROW_WIDTH_PX","ARROW_VERTICAL_OFFSET_PX","ARROW_HORIZONTAL_MARGIN_PX","getVerticalPosition","controllerSize","bubbleSize","variant","HelpBubbleVariant","getControllerLeftCenterPx","getControllerRightCenterPx","getBubbleLeftPx","getBubbleRightPx","getBubbleLeftVisible","getBubbleRightIsVisible","getHorizontalPosition","getBubbleAbovePx","getBubbleBelowPx","getBubbleWidth","getBubbleFitsInWindow","getArrowTopxPx","getArrowLeftPx","getArrowRightPx","getBubblePosition","horizontalPosition","verticalPosition","getBubbleStyle","bubblePosition","bubbleWidth","getArrowStyle","bubbleStyle","leftPx","rightPx","minLeftPx","minRightPx","HelpBubble","props","helpBubbleId","children","controllerRef","className","showBubble","noCloseButton","linkText","linkUrl","onLinkClick","onClose","closeAriaLabel","role","testId","bubbleRef","useRef","arrowRef","useSize","setControllerSize","useState","controllerisVisible","useIsVisible","updateControllerSize","_a","useInterval","useLayoutEvent","useEffect","isTooltip","helpBubbleClasses","classNames","styles","arrowClasses","contentClasses","arrowStyle","renderLink","React","AnchorLink","renderCloseButton","Close","AnalyticsId"],"mappings":"ydAOA,MAAMA,GAAkB,IAElBC,EAAmB,GAEnBC,EAA4B,GAE5BC,EAAiB,GAEjBC,GAA2B,EAE3BC,EAA6B,GAStBC,EAAsB,CACjCC,EACAC,EACAC,IAEIA,IAAYC,EAAkB,kBACzBD,EAELF,EAAe,IAAMC,EAAW,OAASN,EACpCQ,EAAkB,cAElBA,EAAkB,cASvBC,EAA6BJ,GAAoCA,EAAe,KAAOA,EAAe,MAAQ,EAO9GK,GAA8BL,GAClC,SAAS,gBAAgB,YAAcA,EAAe,MAAQA,EAAe,MAAQ,EAQjFM,EAAkB,CAACN,EAAyBC,IACXG,EAA0BJ,CAAc,EAEvCC,EAAW,MAAQ,EASrDM,GAAmB,CAACP,EAAyBC,IAC5BK,EAAgBN,EAAgBC,CAAU,EAEzCA,EAAW,MAS7BO,GAAuB,CAACR,EAAyBC,IAChCK,EAAgBN,EAAgBC,CAAU,EAEzCP,EASlBe,GAA0B,CAACT,EAAyBC,IAClCM,GAAiBP,EAAgBC,CAAU,EAE1C,SAAS,gBAAgB,YAAcP,EAS1DgB,GAAwB,CAACV,EAAyBC,IACjDQ,GAAwBT,EAAgBC,CAAU,EAGlDO,GAAqBR,EAAgBC,CAAU,EAI7C,WAHE,OAHA,QAeLU,EAAmB,CAACX,EAAyBC,IACjDD,EAAe,IAAML,EAA4BM,EAAW,OAQxDW,EAAoBZ,GAAoCA,EAAe,OAASL,EAMhFkB,GAAiB,IAAc,SAAS,gBAAgB,YAAcnB,EAAmB,EAMzFoB,GAAwB,IACrB,SAAS,gBAAgB,YAAcrB,GAAkBC,EAAmB,EAQ/EqB,EAAkBf,GAAoCA,EAAe,IAAML,EAA4BE,GAOvGmB,GAAkBhB,GAAoCI,EAA0BJ,CAAc,EAAIJ,EAAiB,EAOnHqB,GAAmBjB,GAAoCK,GAA2BL,CA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AEJ"}
package/Input.js CHANGED
@@ -1,2 +1,2 @@
1
- import t,{useRef as j}from"react";import p from"classnames";import{FormMode as s,FormVariant as J,IconSize as g,AnalyticsId as K}from"./constants.js";import{a as Q}from"./uuid.js";import{Icon as U}from"./components/Icons/Icon.js";import{getColor as R}from"./theme/currys/color.js";import{useBreakpoint as Y,Breakpoint as Z}from"./hooks/useBreakpoint.js";import{E as T}from"./ErrorWrapper.js";import e from"./components/Input/styles.module.scss";var ee=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.search="search",r.tel="tel",r.url="url",r))(ee||{});const re=12,te=(r,o,d)=>{const m=o?"1.5rem":"2rem",u=o?`${d}px`:"0px",l="4px";return`calc(${r*re}px + ${m} + ${u} + ${l})`},ue=t.forwardRef((r,o)=>{const{defaultValue:d,placeholder:m,type:u="text",inputId:l=Q(),name:A,transparent:N=!1,icon:n,iconRight:b,mode:i,variant:I,label:h,error:$,errorText:_,testId:F,disabled:a,readOnly:S,autoComplete:y,afterLabelChildren:C,belowLabelChildren:E,width:v,required:z}=r,B=Y(),c=j(null),x=i===s.ondark,V=i===s.onblueberry,f=i===s.oninvalid||_||$,w=I===J.bigform,D=N&&i!==s.ondark&&!f,H=p(e["input-wrapper"]),L=p(e["input-wrapper__label-wrapper"],{[e["input-wrapper__label-wrapper--on-dark"]]:x,[e["input-wrapper__label-wrapper--disabled"]]:a}),M=p(e["content-wrapper"],{[e["content-wrapper--transparent"]]:D,[e["content-wrapper--on-blueberry"]]:V,[e["content-wrapper--on-dark"]]:x,[e["content-wrapper--invalid"]]:f,[e["content-wrapper--bigform"]]:w,[e["content-wrapper--disabled"]]:a,[e["content-wrapper--with-icon"]]:n}),X=p(e["content-wrapper__input"],{[e["content-wrapper__input--bigform"]]:w,[e["content-wrapper__input--disabled"]]:a}),q=a?R("neutral",500):R("black"),k=B===Z.xs||!w?g.XSmall:g.Small,W=()=>n!==void 0?t.createElement(U,{color:q,size:k,svgIcon:n}):null,G=()=>{if(c&&c.current&&n){const P=b?0:1;c.current.children[P].focus()}},O=v?te(v,!!n,k):void 0;return t.createElement(T,{errorText:_},t.createElement("div",{"data-testid":F,"data-analyticsid":K.Input,className:H},h&&t.createElement("div",{className:L},t.createElement("label",{htmlFor:l},h),C&&t.createElement("div",{className:e["input-wrapper__after-label-children"]},C)),E&&t.createElement("div",null,E),t.createElement("div",{onClick:G,ref:c,className:M,style:{maxWidth:O}},!b&&W(),t.createElement("input",{name:A,type:u,defaultValue:d,id:l,className:X,ref:o,"aria-invalid":!!f,disabled:a,placeholder:m,readOnly:S,autoComplete:y||"off",required:z}),b&&W())))});export{re as A,ue as I,ee as a};
1
+ import t,{useRef as j}from"react";import c from"classnames";import{FormMode as s,FormVariant as J,IconSize as g,AnalyticsId as K,AVERAGE_CHARACTER_WIDTH_PX as Q}from"./constants.js";import{a as U}from"./uuid.js";import{Icon as Y}from"./components/Icons/Icon.js";import{getColor as R}from"./theme/currys/color.js";import{useBreakpoint as Z,Breakpoint as T}from"./hooks/useBreakpoint.js";import{E as ee}from"./ErrorWrapper.js";import e from"./components/Input/styles.module.scss";var re=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.search="search",r.tel="tel",r.url="url",r))(re||{});const te=(r,o,d)=>{const m=o?"1.5rem":"2rem",u=o?`${d}px`:"0px",l="4px";return`calc(${r*Q}px + ${m} + ${u} + ${l})`},ue=t.forwardRef((r,o)=>{const{defaultValue:d,placeholder:m,type:u="text",inputId:l=U(),name:N,transparent:A=!1,icon:n,iconRight:b,mode:i,variant:I,label:h,error:$,errorText:_,testId:F,disabled:a,readOnly:S,autoComplete:y,afterLabelChildren:C,belowLabelChildren:E,width:v,required:z}=r,B=Z(),p=j(null),x=i===s.ondark,V=i===s.onblueberry,f=i===s.oninvalid||_||$,w=I===J.bigform,D=A&&i!==s.ondark&&!f,H=c(e["input-wrapper"]),L=c(e["input-wrapper__label-wrapper"],{[e["input-wrapper__label-wrapper--on-dark"]]:x,[e["input-wrapper__label-wrapper--disabled"]]:a}),M=c(e["content-wrapper"],{[e["content-wrapper--transparent"]]:D,[e["content-wrapper--on-blueberry"]]:V,[e["content-wrapper--on-dark"]]:x,[e["content-wrapper--invalid"]]:f,[e["content-wrapper--bigform"]]:w,[e["content-wrapper--disabled"]]:a,[e["content-wrapper--with-icon"]]:n}),X=c(e["content-wrapper__input"],{[e["content-wrapper__input--bigform"]]:w,[e["content-wrapper__input--disabled"]]:a}),q=a?R("neutral",500):R("black"),k=B===T.xs||!w?g.XSmall:g.Small,W=()=>n!==void 0?t.createElement(Y,{color:q,size:k,svgIcon:n}):null,G=()=>{if(p&&p.current&&n){const P=b?0:1;p.current.children[P].focus()}},O=v?te(v,!!n,k):void 0;return t.createElement(ee,{errorText:_},t.createElement("div",{"data-testid":F,"data-analyticsid":K.Input,className:H},h&&t.createElement("div",{className:L},t.createElement("label",{htmlFor:l},h),C&&t.createElement("div",{className:e["input-wrapper__after-label-children"]},C)),E&&t.createElement("div",null,E),t.createElement("div",{onClick:G,ref:p,className:M,style:{maxWidth:O}},!b&&W(),t.createElement("input",{name:N,type:u,defaultValue:d,id:l,className:X,ref:o,"aria-invalid":!!f,disabled:a,placeholder:m,readOnly:S,autoComplete:y||"off",required:z}),b&&W())))});export{ue as I,re as a};
2
2
  //# sourceMappingURL=Input.js.map
package/Input.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Input.js","sources":["../src/components/Input/Input.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport cn from 'classnames';\n\nimport { FormMode, FormVariant, AnalyticsId } from '../../constants';\nimport { uuid } from '../../utils/uuid';\nimport Icon, { IconSize, SvgIcon } from '../Icons';\nimport { getColor } from '../../theme/currys';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\n\nimport ErrorWrapper from '../ErrorWrapper';\n\nimport styles from './styles.module.scss';\n\nexport interface InputProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'disabled' | 'readOnly' | 'autoComplete' | 'name' | 'placeholder' | 'defaultValue' | 'required'\n > {\n /** HMTL Input type */\n type?: keyof typeof InputTypes;\n /** input id */\n inputId?: string;\n /** Width of input field in characters (approximate) */\n width?: number;\n /** If true, the component will be transparent. */\n transparent?: boolean;\n /** Icon to be displayed next to the input field */\n icon?: SvgIcon;\n /** Places the icon to the right */\n iconRight?: boolean;\n /** Changes the color profile of the input */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the input */\n variant?: keyof typeof FormVariant;\n /** Label of the input */\n label?: string;\n /** Activates Error style for the input */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Component shown after label */\n afterLabelChildren?: React.ReactNode;\n /** Component shown under label */\n belowLabelChildren?: React.ReactNode;\n}\n\nexport enum InputTypes {\n text = 'text',\n number = 'number',\n email = 'email',\n password = 'password',\n search = 'search',\n tel = 'tel',\n url = 'url',\n}\n\nexport const AVERAGE_CHARACTER_WIDTH_PX = 12;\n\nconst getInputMaxWidth = (characters: number, hasIcon: boolean, iconSize: number): string => {\n const paddingWidth = hasIcon ? '1.5rem' : '2rem';\n const iconWidth = hasIcon ? `${iconSize}px` : '0px';\n const borderWidth = '4px';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth} + ${iconWidth} + ${borderWidth})`;\n};\n\nconst Input = React.forwardRef((props: InputProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n defaultValue,\n placeholder,\n type = InputTypes.text,\n inputId = uuid(),\n name,\n transparent = false,\n icon,\n iconRight,\n mode,\n variant,\n label,\n error,\n errorText,\n testId,\n disabled,\n readOnly,\n autoComplete,\n afterLabelChildren,\n belowLabelChildren,\n width,\n required,\n } = props;\n const breakpoint = useBreakpoint();\n const contentWrapperRef = useRef<HTMLDivElement>(null);\n\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const onError = mode === FormMode.oninvalid || errorText || error;\n const bigForm = variant === FormVariant.bigform;\n const isTransparent = transparent && mode !== FormMode.ondark && !onError;\n\n const inputWrapperClass = cn(styles['input-wrapper']);\n\n const labelWrapperClass = cn(styles['input-wrapper__label-wrapper'], {\n [styles['input-wrapper__label-wrapper--on-dark']]: onDark,\n [styles['input-wrapper__label-wrapper--disabled']]: disabled,\n });\n\n const contentWrapperClass = cn(styles['content-wrapper'], {\n [styles['content-wrapper--transparent']]: isTransparent,\n [styles['content-wrapper--on-blueberry']]: onBlueberry,\n [styles['content-wrapper--on-dark']]: onDark,\n [styles['content-wrapper--invalid']]: onError,\n [styles['content-wrapper--bigform']]: bigForm,\n [styles['content-wrapper--disabled']]: disabled,\n [styles['content-wrapper--with-icon']]: icon,\n });\n\n const inputClass = cn(styles['content-wrapper__input'], {\n [styles['content-wrapper__input--bigform']]: bigForm,\n [styles['content-wrapper__input--disabled']]: disabled,\n });\n\n const iconColor = disabled ? getColor('neutral', 500) : getColor('black');\n const iconSize = breakpoint === Breakpoint.xs || !bigForm ? IconSize.XSmall : IconSize.Small;\n\n const renderIcon = () => {\n return icon !== undefined ? <Icon color={iconColor} size={iconSize} svgIcon={icon} /> : null;\n };\n\n const handleClick = (): void => {\n if (contentWrapperRef && contentWrapperRef.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = contentWrapperRef.current.children[selectedChild] as HTMLInputElement;\n input.focus();\n }\n };\n\n const maxWidth = width ? getInputMaxWidth(width, !!icon, iconSize) : undefined;\n\n return (\n <ErrorWrapper errorText={errorText}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass}>\n {label && (\n <div className={labelWrapperClass}>\n <label htmlFor={inputId}>{label}</label>\n {afterLabelChildren && <div className={styles['input-wrapper__after-label-children']}>{afterLabelChildren}</div>}\n </div>\n )}\n {belowLabelChildren && <div>{belowLabelChildren}</div>}\n <div onClick={handleClick} ref={contentWrapperRef} className={contentWrapperClass} style={{ maxWidth }}>\n {!iconRight && renderIcon()}\n <input\n name={name}\n type={type}\n defaultValue={defaultValue}\n id={inputId}\n className={inputClass}\n ref={ref}\n aria-invalid={!!onError}\n disabled={disabled}\n placeholder={placeholder}\n readOnly={readOnly}\n autoComplete={autoComplete || 'off'}\n required={required}\n />\n {iconRight && renderIcon()}\n </div>\n </div>\n </ErrorWrapper>\n );\n});\n\nexport default Input;\n"],"names":["InputTypes","AVERAGE_CHARACTER_WIDTH_PX","getInputMaxWidth","characters","hasIcon","iconSize","paddingWidth","iconWidth","borderWidth","Input","React","props","ref","defaultValue","placeholder","type","inputId","uuid","name","transparent","icon","iconRight","mode","variant","label","error","errorText","testId","disabled","readOnly","autoComplete","afterLabelChildren","belowLabelChildren","width","required","breakpoint","useBreakpoint","contentWrapperRef","useRef","onDark","FormMode","onBlueberry","onError","bigForm","FormVariant","isTransparent","inputWrapperClass","cn","styles","labelWrapperClass","contentWrapperClass","inputClass","iconColor","getColor","Breakpoint","IconSize","renderIcon","Icon","handleClick","selectedChild","maxWidth","ErrorWrapper","AnalyticsId"],"mappings":"6bAgDY,IAAAA,IAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,OAAS,SACTA,EAAA,MAAQ,QACRA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,IAAM,MACNA,EAAA,IAAM,MAPIA,IAAAA,IAAA,CAAA,CAAA,EAUL,MAAMC,GAA6B,GAEpCC,GAAmB,CAACC,EAAoBC,EAAkBC,IAA6B,CACrF,MAAAC,EAAeF,EAAU,SAAW,OACpCG,EAAYH,EAAU,GAAGC,MAAe,MACxCG,EAAc,MAEpB,MAAO,QAAQL,EAAaF,UAAkCK,OAAkBC,OAAeC,IACjG,EAEMC,GAAQC,EAAM,WAAW,CAACC,EAAmBC,IAAqC,CAChF,KAAA,CACJ,aAAAC,EACA,YAAAC,EACA,KAAAC,EAAO,OACP,QAAAC,EAAUC,EAAK,EACf,KAAAC,EACA,YAAAC,EAAc,GACd,KAAAC,EACA,UAAAC,EACA,KAAAC,EACA,QAAAC,EACA,MAAAC,EACA,MAAAC,EACA,UAAA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CACd,CAAA,EAGIC,EAAW3B,EAAQ/B,GAAiB+B,EAAO,CAAC,CAACb,EAAMf,CAAQ,EAAI,OAErE,OACGK,EAAA,cAAAmD,EAAA,CAAa,UAAAnC,CAAA,EACXhB,EAAA,cAAA,MAAA,CAAI,cAAaiB,EAAQ,mBAAkBmC,EAAY,MAAO,UAAWhB,CAAA,EACvEtB,GACEd,EAAA,cAAA,MAAA,CAAI,UAAWuC,CAAA,EACbvC,EAAA,cAAA,QAAA,CAAM,QAASM,CAAU,EAAAQ,CAAM,EAC/BO,GAAuBrB,EAAA,cAAA,MAAA,CAAI,UAAWsC,EAAO,sCAAyC,EAAAjB,CAAmB,CAC5G,EAEDC,mBAAuB,MAAK,KAAAA,CAAmB,EAC/CtB,EAAA,cAAA,MAAA,CAAI,QAASgD,EAAa,IAAKrB,EAAmB,UAAWa,EAAqB,MAAO,CAAE,SAAAU,CAAS,CAAA,EAClG,CAACvC,GAAamC,EAAW,EACzB9C,EAAA,cAAA,QAAA,CACC,KAAAQ,EACA,KAAAH,EACA,aAAAF,EACA,GAAIG,EACJ,UAAWmC,EACX,IAAAvC,EACA,eAAc,CAAC,CAAC8B,EAChB,SAAAd,EACA,YAAAd,EACA,SAAAe,EACA,aAAcC,GAAgB,MAC9B,SAAAI,CACF,CAAA,EACCb,GAAamC,EAChB,CAAA,CACF,CACF,CAEJ,CAAC"}
1
+ {"version":3,"file":"Input.js","sources":["../src/components/Input/Input.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport cn from 'classnames';\n\nimport { FormMode, FormVariant, AnalyticsId, AVERAGE_CHARACTER_WIDTH_PX } from '../../constants';\nimport { uuid } from '../../utils/uuid';\nimport Icon, { IconSize, SvgIcon } from '../Icons';\nimport { getColor } from '../../theme/currys';\nimport { Breakpoint, useBreakpoint } from '../../hooks/useBreakpoint';\n\nimport ErrorWrapper from '../ErrorWrapper';\n\nimport styles from './styles.module.scss';\n\nexport interface InputProps\n extends Pick<\n React.InputHTMLAttributes<HTMLInputElement>,\n 'disabled' | 'readOnly' | 'autoComplete' | 'name' | 'placeholder' | 'defaultValue' | 'required'\n > {\n /** HMTL Input type */\n type?: keyof typeof InputTypes;\n /** input id */\n inputId?: string;\n /** Width of input field in characters (approximate) */\n width?: number;\n /** If true, the component will be transparent. */\n transparent?: boolean;\n /** Icon to be displayed next to the input field */\n icon?: SvgIcon;\n /** Places the icon to the right */\n iconRight?: boolean;\n /** Changes the color profile of the input */\n mode?: keyof typeof FormMode;\n /** Changes the visuals of the input */\n variant?: keyof typeof FormVariant;\n /** Label of the input */\n label?: string;\n /** Activates Error style for the input */\n error?: boolean;\n /** Error text to show above the component */\n errorText?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Component shown after label */\n afterLabelChildren?: React.ReactNode;\n /** Component shown under label */\n belowLabelChildren?: React.ReactNode;\n}\n\nexport enum InputTypes {\n text = 'text',\n number = 'number',\n email = 'email',\n password = 'password',\n search = 'search',\n tel = 'tel',\n url = 'url',\n}\n\nconst getInputMaxWidth = (characters: number, hasIcon: boolean, iconSize: number): string => {\n const paddingWidth = hasIcon ? '1.5rem' : '2rem';\n const iconWidth = hasIcon ? `${iconSize}px` : '0px';\n const borderWidth = '4px';\n\n return `calc(${characters * AVERAGE_CHARACTER_WIDTH_PX}px + ${paddingWidth} + ${iconWidth} + ${borderWidth})`;\n};\n\nconst Input = React.forwardRef((props: InputProps, ref: React.Ref<HTMLInputElement>) => {\n const {\n defaultValue,\n placeholder,\n type = InputTypes.text,\n inputId = uuid(),\n name,\n transparent = false,\n icon,\n iconRight,\n mode,\n variant,\n label,\n error,\n errorText,\n testId,\n disabled,\n readOnly,\n autoComplete,\n afterLabelChildren,\n belowLabelChildren,\n width,\n required,\n } = props;\n const breakpoint = useBreakpoint();\n const contentWrapperRef = useRef<HTMLDivElement>(null);\n\n const onDark = mode === FormMode.ondark;\n const onBlueberry = mode === FormMode.onblueberry;\n const onError = mode === FormMode.oninvalid || errorText || error;\n const bigForm = variant === FormVariant.bigform;\n const isTransparent = transparent && mode !== FormMode.ondark && !onError;\n\n const inputWrapperClass = cn(styles['input-wrapper']);\n\n const labelWrapperClass = cn(styles['input-wrapper__label-wrapper'], {\n [styles['input-wrapper__label-wrapper--on-dark']]: onDark,\n [styles['input-wrapper__label-wrapper--disabled']]: disabled,\n });\n\n const contentWrapperClass = cn(styles['content-wrapper'], {\n [styles['content-wrapper--transparent']]: isTransparent,\n [styles['content-wrapper--on-blueberry']]: onBlueberry,\n [styles['content-wrapper--on-dark']]: onDark,\n [styles['content-wrapper--invalid']]: onError,\n [styles['content-wrapper--bigform']]: bigForm,\n [styles['content-wrapper--disabled']]: disabled,\n [styles['content-wrapper--with-icon']]: icon,\n });\n\n const inputClass = cn(styles['content-wrapper__input'], {\n [styles['content-wrapper__input--bigform']]: bigForm,\n [styles['content-wrapper__input--disabled']]: disabled,\n });\n\n const iconColor = disabled ? getColor('neutral', 500) : getColor('black');\n const iconSize = breakpoint === Breakpoint.xs || !bigForm ? IconSize.XSmall : IconSize.Small;\n\n const renderIcon = () => {\n return icon !== undefined ? <Icon color={iconColor} size={iconSize} svgIcon={icon} /> : null;\n };\n\n const handleClick = (): void => {\n if (contentWrapperRef && contentWrapperRef.current && icon) {\n const selectedChild = iconRight ? 0 : 1;\n const input = contentWrapperRef.current.children[selectedChild] as HTMLInputElement;\n input.focus();\n }\n };\n\n const maxWidth = width ? getInputMaxWidth(width, !!icon, iconSize) : undefined;\n\n return (\n <ErrorWrapper errorText={errorText}>\n <div data-testid={testId} data-analyticsid={AnalyticsId.Input} className={inputWrapperClass}>\n {label && (\n <div className={labelWrapperClass}>\n <label htmlFor={inputId}>{label}</label>\n {afterLabelChildren && <div className={styles['input-wrapper__after-label-children']}>{afterLabelChildren}</div>}\n </div>\n )}\n {belowLabelChildren && <div>{belowLabelChildren}</div>}\n <div onClick={handleClick} ref={contentWrapperRef} className={contentWrapperClass} style={{ maxWidth }}>\n {!iconRight && renderIcon()}\n <input\n name={name}\n type={type}\n defaultValue={defaultValue}\n id={inputId}\n className={inputClass}\n ref={ref}\n aria-invalid={!!onError}\n disabled={disabled}\n placeholder={placeholder}\n readOnly={readOnly}\n autoComplete={autoComplete || 'off'}\n required={required}\n />\n {iconRight && renderIcon()}\n </div>\n </div>\n </ErrorWrapper>\n );\n});\n\nexport default Input;\n"],"names":["InputTypes","getInputMaxWidth","characters","hasIcon","iconSize","paddingWidth","iconWidth","borderWidth","AVERAGE_CHARACTER_WIDTH_PX","Input","React","props","ref","defaultValue","placeholder","type","inputId","uuid","name","transparent","icon","iconRight","mode","variant","label","error","errorText","testId","disabled","readOnly","autoComplete","afterLabelChildren","belowLabelChildren","width","required","breakpoint","useBreakpoint","contentWrapperRef","useRef","onDark","FormMode","onBlueberry","onError","bigForm","FormVariant","isTransparent","inputWrapperClass","cn","styles","labelWrapperClass","contentWrapperClass","inputClass","iconColor","getColor","Breakpoint","IconSize","renderIcon","Icon","handleClick","selectedChild","maxWidth","ErrorWrapper","AnalyticsId"],"mappings":"8dAgDY,IAAAA,IAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,OAAS,SACTA,EAAA,MAAQ,QACRA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,IAAM,MACNA,EAAA,IAAM,MAPIA,IAAAA,IAAA,CAAA,CAAA,EAUZ,MAAMC,GAAmB,CAACC,EAAoBC,EAAkBC,IAA6B,CACrF,MAAAC,EAAeF,EAAU,SAAW,OACpCG,EAAYH,EAAU,GAAGC,MAAe,MACxCG,EAAc,MAEpB,MAAO,QAAQL,EAAaM,SAAkCH,OAAkBC,OAAeC,IACjG,EAEME,GAAQC,EAAM,WAAW,CAACC,EAAmBC,IAAqC,CAChF,KAAA,CACJ,aAAAC,EACA,YAAAC,EACA,KAAAC,EAAO,OACP,QAAAC,EAAUC,EAAK,EACf,KAAAC,EACA,YAAAC,EAAc,GACd,KAAAC,EACA,UAAAC,EACA,KAAAC,EACA,QAAAC,EACA,MAAAC,EACA,MAAAC,EACA,UAAAC,E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d,CAAA,EAGIC,EAAW3B,EAAQhC,GAAiBgC,EAAO,CAAC,CAACb,EAAMhB,CAAQ,EAAI,OAErE,OACGM,EAAA,cAAAmD,GAAA,CAAa,UAAAnC,CAAA,EACXhB,EAAA,cAAA,MAAA,CAAI,cAAaiB,EAAQ,mBAAkBmC,EAAY,MAAO,UAAWhB,CAAA,EACvEtB,GACEd,EAAA,cAAA,MAAA,CAAI,UAAWuC,CAAA,EACbvC,EAAA,cAAA,QAAA,CAAM,QAASM,CAAU,EAAAQ,CAAM,EAC/BO,GAAuBrB,EAAA,cAAA,MAAA,CAAI,UAAWsC,EAAO,sCAAyC,EAAAjB,CAAmB,CAC5G,EAEDC,mBAAuB,MAAK,KAAAA,CAAmB,EAC/CtB,EAAA,cAAA,MAAA,CAAI,QAASgD,EAAa,IAAKrB,EAAmB,UAAWa,EAAqB,MAAO,CAAE,SAAAU,CAAS,CAAA,EAClG,CAACvC,GAAamC,EAAW,EACzB9C,EAAA,cAAA,QAAA,CACC,KAAAQ,EACA,KAAAH,EACA,aAAAF,EACA,GAAIG,EACJ,UAAWmC,EACX,IAAAvC,EACA,eAAc,CAAC,CAAC8B,EAChB,SAAAd,EACA,YAAAd,EACA,SAAAe,EACA,aAAcC,GAAgB,MAC9B,SAAAI,CACF,CAAA,EACCb,GAAamC,EAChB,CAAA,CACF,CACF,CAEJ,CAAC"}
package/Modal.js CHANGED
@@ -1,2 +1,2 @@
1
- import t,{useEffect as $}from"react";import n from"classnames";import{palette as u}from"./theme/palette.js";import{B as k}from"./Button.js";import{Icon as _}from"./components/Icons/Icon.js";import{ZIndex as A,AnalyticsId as F,IconSize as s}from"./constants.js";import a from"./components/Modal/styles.module.scss";import H from"./components/Icons/AlertSignStroke.js";import K from"./components/Icons/AlertSignFill.js";import{useFocusTrap as O}from"./hooks/useFocusTrap.js";import{useIsVisible as x}from"./hooks/useIsVisible.js";import{T as D}from"./Title.js";import{a as M}from"./uuid.js";import{C as V}from"./Close.js";import Z from"./components/Icons/CheckOutline.js";import j from"./components/Portal/index.js";var q=(e=>(e.normal="normal",e.warning="warning",e.error="error",e.success="success",e.image="image",e))(q||{}),G=(e=>(e.large="large",e.medium="medium",e))(G||{});const J={variant:"normal",primaryButtonText:"OK",titleId:M(),className:"",size:"large",zIndex:A.Modal},Q=e=>e==="error"?t.createElement(_,{size:s.Small,svgIcon:K,color:u.cherry500}):e==="warning"?t.createElement(_,{size:s.Small,svgIcon:H,color:u.black}):e==="success"?t.createElement(_,{size:s.Small,svgIcon:Z,color:u.kiwi900}):null,U=(e,r)=>{const c=Q(e);return c?t.createElement("div",{className:a.modal__iconWrapper},c):r?t.createElement("div",{className:a.modal__iconWrapper},t.cloneElement(r,{size:s.Small})):null},X=e=>{var I,w;const[r,c]=t.useState(0),f=t.useRef(null),v=t.useRef(null),i=t.useRef(null),E=t.useRef(null);O(E);const S=x(v),b=t.useRef(null),T=x(b),m=i.current&&i.current.scrollHeight>i.current.clientHeight;function g(l){l.key==="Escape"&&e.onClose&&(l.stopPropagation(),e.onClose())}function y(l){l.target&&d.current===l.target&&e.onClose&&(l.stopPropagation(),e.onClose())}function L(){document.body.style.overflow="hidden"}function W(){document.body.style.removeProperty("overflow")}const o=e.variant==="image",d=t.useRef(null),C=e.secondaryButtonText&&((I=e.secondaryButtonText)==null?void 0:I.length)>0||e.onSuccess,z=e.ariaLabelledBy?void 0:e.ariaLabel,h=e.ariaLabelledBy?e.ariaLabelledBy:e.ariaLabel?void 0:e.titleId;$(()=>{var B;const l=d.current;return(B=f.current)==null||B.focus(),L(),!e.disableCloseEvents&&l&&(l.addEventListener("keydown",g),l.addEventListener("click",y)),()=>{W(),!e.disableCloseEvents&&l&&(l.removeEventListener("keydown",g),l.removeEventListener("click",y))}},[e.disableCloseEvents]);const R=n(e.className,a.modal,a[`modal--${e.variant}`],a[`modal--${e.size}`],m&&!C&&a["modal--no-actions"]),P=n({[a["modal__title--error"]]:e.variant==="error",[a["modal__title--success"]]:e.variant==="success"}),N=t.createElement("div",{"data-testid":"dialog-container"},t.createElement("div",{ref:d,className:a["modal-overlay"],"data-testid":e.testId,"data-analyticsid":F.Modal,style:{zIndex:e.zIndex}},t.createElement("div",{className:a.align},t.createElement("div",{className:R,role:"dialog","aria-label":z,"aria-labelledby":h,ref:E},t.createElement("div",{tabIndex:r,ref:f,onBlur:()=>c(-1)}),t.createElement("div",{className:n(a.modal__shadow,a["modal__shadow--top"],{[a["modal__shadow--show"]]:!S&&m})}),t.createElement("div",{className:n(a.modal__contentWrapper,{[a["modal__contentWrapper--image"]]:o}),ref:i},!e.noCloseButton&&t.createElement("div",{className:a.modal__closeWrapper},t.createElement("div",{className:n(a.modal__closeWrapper__close)},t.createElement(V,{onClick:e.onClose,ariaLabel:e.ariaLabelCloseBtn}))),t.createElement("div",{className:n(a[`modal__contentWrapper__scroll--${e.size}`],{[a["modal__contentWrapper__scroll--image"]]:o})},t.createElement("div",{ref:v}),t.createElement("div",{className:a.modal__contentWrapper__title},U(e.variant,e.icon),t.createElement(D,{id:h,htmlMarkup:"h3",appearance:"title3",className:P},e.title),e.afterTitleChildren&&t.createElement("div",{className:a.modal__afterTitleChildren},e.afterTitleChildren)),o&&t.createElement("div",null,t.createElement("div",{className:a.modal__contentWrapper__imageWrapper},e.children),t.createElement("span",{className:a.modal__contentWrapper__imageDescription},e.description)),!o&&e.children&&t.createElement("div",null,e.children),!o&&!e.children&&t.createElement("p",{className:a.modal__description},e.description),t.createElement("div",{ref:b}))),t.createElement("div",{className:n(a.modal__shadow,a["modal__shadow--bottom"],{[a["modal__shadow--show"]]:!T&&m})}),C&&t.createElement("div",{className:n(a["modal__call-to-action"],a[`modal__call-to-action--${e.size}`])},e.onSuccess&&t.createElement(k,{onClick:e.onSuccess},e.primaryButtonText),e.secondaryButtonText&&((w=e.secondaryButtonText)==null?void 0:w.length)>0&&t.createElement(k,{variant:"borderless",onClick:e.onClose},e.secondaryButtonText))))));if(e.printable){const l="print-modal";return t.createElement(j,{className:l,testId:"print-modal"},t.createElement("style",{media:"print"},`body > *:not(.${l}) {display: none;}`),N)}return N};X.defaultProps=J;export{X as M,q as a,G as b};
1
+ import t,{useEffect as W}from"react";import n from"classnames";import{palette as d}from"./theme/palette.js";import{B as N}from"./Button.js";import{Icon as u}from"./components/Icons/Icon.js";import{ZIndex as z,AnalyticsId as R,IconSize as c}from"./constants.js";import a from"./components/Modal/styles.module.scss";import P from"./components/Icons/AlertSignStroke.js";import $ from"./components/Icons/AlertSignFill.js";import{useFocusTrap as A}from"./hooks/useFocusTrap.js";import{useIsVisible as I}from"./hooks/useIsVisible.js";import{T as F}from"./Title.js";import{a as H}from"./uuid.js";import{C as K}from"./Close.js";import O from"./components/Icons/CheckOutline.js";import D from"./components/Portal/index.js";var M=(e=>(e.normal="normal",e.warning="warning",e.error="error",e.success="success",e.image="image",e))(M||{}),V=(e=>(e.large="large",e.medium="medium",e))(V||{});const Z={variant:"normal",primaryButtonText:"OK",titleId:H(),className:"",size:"large",zIndex:z.Modal},j=e=>e==="error"?t.createElement(u,{size:c.Small,svgIcon:$,color:d.cherry500}):e==="warning"?t.createElement(u,{size:c.Small,svgIcon:P,color:d.black}):e==="success"?t.createElement(u,{size:c.Small,svgIcon:O,color:d.kiwi900}):null,q=(e,r)=>{const o=j(e);return o?t.createElement("div",{className:a.modal__iconWrapper},o):r?t.createElement("div",{className:a.modal__iconWrapper},t.cloneElement(r,{size:c.Small})):null},G=e=>{var C,h;const r=t.useRef(null),o=t.useRef(null),_=t.useRef(null);A(_,!0,!0);const w=I(r),f=t.useRef(null),B=I(f),m=o.current&&o.current.scrollHeight>o.current.clientHeight;function v(l){l.key==="Escape"&&e.onClose&&(l.stopPropagation(),e.onClose())}function E(l){l.target&&s.current===l.target&&e.onClose&&(l.stopPropagation(),e.onClose())}function k(){document.body.style.overflow="hidden"}function L(){document.body.style.removeProperty("overflow")}const i=e.variant==="image",s=t.useRef(null),g=e.secondaryButtonText&&((C=e.secondaryButtonText)==null?void 0:C.length)>0||e.onSuccess,S=e.ariaLabelledBy?void 0:e.ariaLabel,y=e.ariaLabelledBy?e.ariaLabelledBy:e.ariaLabel?void 0:e.titleId;W(()=>{const l=s.current;return k(),!e.disableCloseEvents&&l&&(l.addEventListener("keydown",v),l.addEventListener("click",E)),()=>{L(),!e.disableCloseEvents&&l&&(l.removeEventListener("keydown",v),l.removeEventListener("click",E))}},[e.disableCloseEvents]);const T=n(e.className,a.modal,a[`modal--${e.variant}`],a[`modal--${e.size}`],m&&!g&&a["modal--no-actions"]),x=n({[a["modal__title--error"]]:e.variant==="error",[a["modal__title--success"]]:e.variant==="success"}),b=t.createElement("div",{"data-testid":"dialog-container"},t.createElement("div",{ref:s,className:a["modal-overlay"],"data-testid":e.testId,"data-analyticsid":R.Modal,style:{zIndex:e.zIndex}},t.createElement("div",{className:a.align},t.createElement("div",{className:T,role:"dialog","aria-label":S,"aria-labelledby":y,ref:_},t.createElement("div",{className:n(a.modal__shadow,a["modal__shadow--top"],{[a["modal__shadow--show"]]:!w&&m})}),t.createElement("div",{className:n(a.modal__contentWrapper,{[a["modal__contentWrapper--image"]]:i}),ref:o},!e.noCloseButton&&t.createElement("div",{className:a.modal__closeWrapper},t.createElement("div",{className:n(a.modal__closeWrapper__close)},t.createElement(K,{onClick:e.onClose,ariaLabel:e.ariaLabelCloseBtn}))),t.createElement("div",{className:n(a[`modal__contentWrapper__scroll--${e.size}`],{[a["modal__contentWrapper__scroll--image"]]:i})},t.createElement("div",{ref:r}),t.createElement("div",{className:a.modal__contentWrapper__title},q(e.variant,e.icon),t.createElement(F,{id:y,htmlMarkup:"h3",appearance:"title3",className:x},e.title),e.afterTitleChildren&&t.createElement("div",{className:a.modal__afterTitleChildren},e.afterTitleChildren)),i&&t.createElement("div",null,t.createElement("div",{className:a.modal__contentWrapper__imageWrapper},e.children),t.createElement("span",{className:a.modal__contentWrapper__imageDescription},e.description)),!i&&e.children&&t.createElement("div",null,e.children),!i&&!e.children&&t.createElement("p",{className:a.modal__description},e.description),t.createElement("div",{ref:f}))),t.createElement("div",{className:n(a.modal__shadow,a["modal__shadow--bottom"],{[a["modal__shadow--show"]]:!B&&m})}),g&&t.createElement("div",{className:n(a["modal__call-to-action"],a[`modal__call-to-action--${e.size}`])},e.onSuccess&&t.createElement(N,{onClick:e.onSuccess},e.primaryButtonText),e.secondaryButtonText&&((h=e.secondaryButtonText)==null?void 0:h.length)>0&&t.createElement(N,{variant:"borderless",onClick:e.onClose},e.secondaryButtonText))))));if(e.printable){const l="print-modal";return t.createElement(D,{className:l,testId:"print-modal"},t.createElement("style",{media:"print"},`body > *:not(.${l}) {display: none;}`),b)}return b};G.defaultProps=Z;export{G as M,M as a,V as b};
2
2
  //# sourceMappingURL=Modal.js.map
package/Modal.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Modal.js","sources":["../src/components/Modal/Modal.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport cn from 'classnames';\n\nimport { palette } from '../../theme/palette';\nimport Button from '../Button';\nimport Icon, { IconSize } from '../Icons';\n\nimport styles from './styles.module.scss';\nimport AlertSignStroke from '../Icons/AlertSignStroke';\nimport AlertSignFill from '../Icons/AlertSignFill';\nimport useFocusTrap from '../../hooks/useFocusTrap';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport Title from '../Title/Title';\nimport { uuid } from '../../utils/uuid';\nimport Close from '../Close';\nimport CheckOutline from '../Icons/CheckOutline';\nimport Portal from '../Portal';\nimport { AnalyticsId, ZIndex } from '../../constants';\n\nexport enum ModalVariants {\n normal = 'normal',\n warning = 'warning',\n error = 'error',\n success = 'success',\n image = 'image',\n}\n\nexport enum ModalSize {\n large = 'large',\n medium = 'medium',\n}\n\nexport interface ModalProps {\n /** Title of the modal */\n title: string;\n /** id of the modal title */\n titleId?: string;\n /** Description of the modal. Will not render if the modal has children. */\n description?: string;\n /** Changes the visual representation of the modal */\n variant?: keyof typeof ModalVariants;\n /** Change width of the modal (default: large) */\n size?: keyof typeof ModalSize;\n /** Icon displayed in title */\n icon?: React.ReactElement;\n /** Hides the close button */\n noCloseButton?: boolean;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Primary button text */\n primaryButtonText?: string;\n /** Secondary button text */\n secondaryButtonText?: string;\n /** Sets the aria-label of the modal */\n ariaLabel?: string;\n /** Sets the aria-labelledby of the modal */\n ariaLabelledBy?: string;\n /** Close button aria-label */\n ariaLabelCloseBtn?: string;\n /** Alternative component to modal */\n children?: React.ReactNode;\n /** Component shown after title */\n afterTitleChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Customize the z-index of the modal */\n zIndex?: number;\n /** Function is called when user clicks primary button */\n onSuccess?: () => void;\n /** Function is called when user clicks secondary button, clicks escape or outside the modal */\n onClose?: () => void;\n /** When enabled the component will be rendered in the bottom of document.body */\n printable?: boolean;\n /** If disabled, clicking escape or outside the modal will not close it */\n disableCloseEvents?: boolean;\n}\n\nconst defaultProps = {\n variant: ModalVariants.normal,\n primaryButtonText: 'OK',\n titleId: uuid(),\n className: '',\n size: ModalSize.large,\n zIndex: ZIndex.Modal,\n};\n\nconst getVariantIcon = (variant?: ModalProps['variant']): JSX.Element | null => {\n if (variant === ModalVariants.error) {\n return <Icon size={IconSize.Small} svgIcon={AlertSignFill} color={palette.cherry500} />;\n } else if (variant === ModalVariants.warning) {\n return <Icon size={IconSize.Small} svgIcon={AlertSignStroke} color={palette.black} />;\n } else if (variant === ModalVariants.success) {\n return <Icon size={IconSize.Small} svgIcon={CheckOutline} color={palette.kiwi900} />;\n }\n return null;\n};\n\nconst getIcon = (variant?: ModalProps['variant'], icon?: ModalProps['icon']): JSX.Element | null => {\n const variantIcon = getVariantIcon(variant);\n if (variantIcon) {\n return <div className={styles.modal__iconWrapper}>{variantIcon}</div>;\n }\n if (icon) {\n return (\n <div className={styles.modal__iconWrapper}>\n {React.cloneElement(icon, {\n size: IconSize.Small,\n })}\n </div>\n );\n }\n return null;\n};\n\nconst Modal = (props: ModalProps): JSX.Element => {\n const [tabIndex, setTabIndex] = React.useState(0);\n const initFocus = React.useRef<HTMLDivElement>(null);\n const topContent = React.useRef<HTMLDivElement>(null);\n const modalContentRef = React.useRef<HTMLDivElement>(null);\n const dialogRef = React.useRef<HTMLDivElement>(null);\n useFocusTrap(dialogRef);\n const topContentVisible = useIsVisible(topContent);\n const bottomContent = React.useRef<HTMLDivElement>(null);\n const bottomContentVisible = useIsVisible(bottomContent);\n const contentIsScrollable = modalContentRef.current && modalContentRef.current.scrollHeight > modalContentRef.current.clientHeight;\n\n function handleKeyboardEvent(e: KeyboardEvent): void {\n if (e.key === 'Escape' && props.onClose) {\n e.stopPropagation();\n props.onClose();\n }\n }\n\n function handleClickEvent(event: MouseEvent): void {\n if (event.target && overlayRef.current === event.target && props.onClose) {\n event.stopPropagation();\n props.onClose();\n }\n }\n\n function disableBodyScroll(): void {\n document.body.style.overflow = 'hidden';\n }\n\n function enableBodyScroll(): void {\n document.body.style.removeProperty('overflow');\n }\n\n /* Displays a full window size modal with image */\n const imageView = props.variant === ModalVariants.image;\n\n const overlayRef = React.useRef<HTMLDivElement>(null);\n\n const showActions = (props.secondaryButtonText && props.secondaryButtonText?.length > 0) || props.onSuccess;\n\n // ariaLabelledBy prioriteres over ariaLabel, men dersom ariaLabel brukes trengs ikke ariaLabelledBy\n const ariaLabel = !props.ariaLabelledBy ? props.ariaLabel : undefined;\n const ariaLabelledBy = props.ariaLabelledBy ? props.ariaLabelledBy : !props.ariaLabel ? props.titleId : undefined;\n\n useEffect(() => {\n const overlayElement = overlayRef.current;\n initFocus.current?.focus();\n disableBodyScroll();\n if (!props.disableCloseEvents && overlayElement) {\n overlayElement.addEventListener('keydown', handleKeyboardEvent);\n overlayElement.addEventListener('click', handleClickEvent);\n }\n return (): void => {\n enableBodyScroll();\n if (!props.disableCloseEvents && overlayElement) {\n overlayElement.removeEventListener('keydown', handleKeyboardEvent);\n overlayElement.removeEventListener('click', handleClickEvent);\n }\n };\n }, [props.disableCloseEvents]);\n\n const dialogClasses = cn(\n props.className,\n styles.modal,\n styles[`modal--${props.variant}`],\n styles[`modal--${props.size}`],\n contentIsScrollable && !showActions && styles['modal--no-actions']\n );\n\n const titleClasses = cn({\n [styles['modal__title--error']]: props.variant === ModalVariants.error,\n [styles['modal__title--success']]: props.variant === ModalVariants.success,\n });\n\n const Component = (\n <div data-testid=\"dialog-container\">\n <div\n ref={overlayRef}\n className={styles['modal-overlay']}\n data-testid={props.testId}\n data-analyticsid={AnalyticsId.Modal}\n style={{ zIndex: props.zIndex }}\n >\n <div className={styles.align}>\n <div className={dialogClasses} role=\"dialog\" aria-label={ariaLabel} aria-labelledby={ariaLabelledBy} ref={dialogRef}>\n <div tabIndex={tabIndex} ref={initFocus} onBlur={(): void => setTabIndex(-1)} />\n <div\n className={cn(styles['modal__shadow'], styles['modal__shadow--top'], {\n [styles['modal__shadow--show']]: !topContentVisible && contentIsScrollable,\n })}\n />\n <div\n className={cn(styles.modal__contentWrapper, {\n [styles['modal__contentWrapper--image']]: imageView,\n })}\n ref={modalContentRef}\n >\n {!props.noCloseButton && (\n <div className={styles.modal__closeWrapper}>\n <div className={cn(styles.modal__closeWrapper__close)}>\n <Close onClick={props.onClose} ariaLabel={props.ariaLabelCloseBtn} />\n </div>\n </div>\n )}\n <div\n className={cn(styles[`modal__contentWrapper__scroll--${props.size}`], {\n [styles['modal__contentWrapper__scroll--image']]: imageView,\n })}\n >\n <div ref={topContent} />\n <div className={styles.modal__contentWrapper__title}>\n {getIcon(props.variant, props.icon)}\n <Title id={ariaLabelledBy} htmlMarkup=\"h3\" appearance=\"title3\" className={titleClasses}>\n {props.title}\n </Title>\n {props.afterTitleChildren && <div className={styles['modal__afterTitleChildren']}>{props.afterTitleChildren}</div>}\n </div>\n {imageView && (\n <div>\n <div className={styles['modal__contentWrapper__imageWrapper']}>{props.children}</div>\n <span className={styles['modal__contentWrapper__imageDescription']}>{props.description}</span>\n </div>\n )}\n {!imageView && props.children && <div>{props.children}</div>}\n {!imageView && !props.children && <p className={styles.modal__description}>{props.description}</p>}\n <div ref={bottomContent} />\n </div>\n </div>\n <div\n className={cn(styles['modal__shadow'], styles['modal__shadow--bottom'], {\n [styles['modal__shadow--show']]: !bottomContentVisible && contentIsScrollable,\n })}\n />\n {showActions && (\n <div className={cn(styles['modal__call-to-action'], styles[`modal__call-to-action--${props.size}`])}>\n {props.onSuccess && <Button onClick={props.onSuccess}>{props.primaryButtonText}</Button>}\n {props.secondaryButtonText && props.secondaryButtonText?.length > 0 && (\n <Button variant=\"borderless\" onClick={props.onClose}>\n {props.secondaryButtonText}\n </Button>\n )}\n </div>\n )}\n </div>\n </div>\n </div>\n </div>\n );\n\n if (props.printable) {\n const printModal = 'print-modal';\n return (\n <Portal className={printModal} testId=\"print-modal\">\n <style media=\"print\">{`body > *:not(.${printModal}) {display: none;}`}</style>\n {Component}\n </Portal>\n );\n }\n\n return Component;\n};\n\nModal.defaultProps = defaultProps;\n\nexport default Modal;\n"],"names":["ModalVariants","ModalSize","defaultProps","uuid","ZIndex","getVariantIcon","variant","React","Icon","IconSize","AlertSignFill","palette","AlertSignStroke","CheckOutline","getIcon","icon","variantIcon","styles","Modal","props","tabIndex","setTabIndex","initFocus","topContent","modalContentRef","dialogRef","useFocusTrap","topContentVisible","useIsVisible","bottomContent","bottomContentVisible","contentIsScrollable","handleKeyboardEvent","e","handleClickEvent","event","overlayRef","disableBodyScroll","enableBodyScroll","imageView","showActions","_a","ariaLabel","ariaLabelledBy","useEffect","overlayElement","dialogClasses","cn","titleClasses","Component","AnalyticsId","Close","Title","Button","_b","printModal","Portal"],"mappings":"0sBAmBY,IAAAA,GAAAA,IACVA,EAAA,OAAS,SACTA,EAAA,QAAU,UACVA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,MAAQ,QALEA,IAAAA,GAAA,CAAA,CAAA,EAQAC,GAAAA,IACVA,EAAA,MAAQ,QACRA,EAAA,OAAS,SAFCA,IAAAA,GAAA,CAAA,CAAA,EAkDZ,MAAMC,EAAe,CACnB,QAAS,SACT,kBA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H,CAEJ,CAEO,OAAAA,CACT,EAEA/B,EAAM,aAAehB"}
1
+ {"version":3,"file":"Modal.js","sources":["../src/components/Modal/Modal.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport cn from 'classnames';\n\nimport { palette } from '../../theme/palette';\nimport Button from '../Button';\nimport Icon, { IconSize } from '../Icons';\n\nimport styles from './styles.module.scss';\nimport AlertSignStroke from '../Icons/AlertSignStroke';\nimport AlertSignFill from '../Icons/AlertSignFill';\nimport useFocusTrap from '../../hooks/useFocusTrap';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport Title from '../Title/Title';\nimport { uuid } from '../../utils/uuid';\nimport Close from '../Close';\nimport CheckOutline from '../Icons/CheckOutline';\nimport Portal from '../Portal';\nimport { AnalyticsId, ZIndex } from '../../constants';\n\nexport enum ModalVariants {\n normal = 'normal',\n warning = 'warning',\n error = 'error',\n success = 'success',\n image = 'image',\n}\n\nexport enum ModalSize {\n large = 'large',\n medium = 'medium',\n}\n\nexport interface ModalProps {\n /** Title of the modal */\n title: string;\n /** id of the modal title */\n titleId?: string;\n /** Description of the modal. Will not render if the modal has children. */\n description?: string;\n /** Changes the visual representation of the modal */\n variant?: keyof typeof ModalVariants;\n /** Change width of the modal (default: large) */\n size?: keyof typeof ModalSize;\n /** Icon displayed in title */\n icon?: React.ReactElement;\n /** Hides the close button */\n noCloseButton?: boolean;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Primary button text */\n primaryButtonText?: string;\n /** Secondary button text */\n secondaryButtonText?: string;\n /** Sets the aria-label of the modal */\n ariaLabel?: string;\n /** Sets the aria-labelledby of the modal */\n ariaLabelledBy?: string;\n /** Close button aria-label */\n ariaLabelCloseBtn?: string;\n /** Alternative component to modal */\n children?: React.ReactNode;\n /** Component shown after title */\n afterTitleChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Customize the z-index of the modal */\n zIndex?: number;\n /** Function is called when user clicks primary button */\n onSuccess?: () => void;\n /** Function is called when user clicks secondary button, clicks escape or outside the modal */\n onClose?: () => void;\n /** When enabled the component will be rendered in the bottom of document.body */\n printable?: boolean;\n /** If disabled, clicking escape or outside the modal will not close it */\n disableCloseEvents?: boolean;\n}\n\nconst defaultProps = {\n variant: ModalVariants.normal,\n primaryButtonText: 'OK',\n titleId: uuid(),\n className: '',\n size: ModalSize.large,\n zIndex: ZIndex.Modal,\n};\n\nconst getVariantIcon = (variant?: ModalProps['variant']): JSX.Element | null => {\n if (variant === ModalVariants.error) {\n return <Icon size={IconSize.Small} svgIcon={AlertSignFill} color={palette.cherry500} />;\n } else if (variant === ModalVariants.warning) {\n return <Icon size={IconSize.Small} svgIcon={AlertSignStroke} color={palette.black} />;\n } else if (variant === ModalVariants.success) {\n return <Icon size={IconSize.Small} svgIcon={CheckOutline} color={palette.kiwi900} />;\n }\n return null;\n};\n\nconst getIcon = (variant?: ModalProps['variant'], icon?: ModalProps['icon']): JSX.Element | null => {\n const variantIcon = getVariantIcon(variant);\n if (variantIcon) {\n return <div className={styles.modal__iconWrapper}>{variantIcon}</div>;\n }\n if (icon) {\n return (\n <div className={styles.modal__iconWrapper}>\n {React.cloneElement(icon, {\n size: IconSize.Small,\n })}\n </div>\n );\n }\n return null;\n};\n\nconst Modal = (props: ModalProps): JSX.Element => {\n const topContent = React.useRef<HTMLDivElement>(null);\n const modalContentRef = React.useRef<HTMLDivElement>(null);\n const dialogRef = React.useRef<HTMLDivElement>(null);\n useFocusTrap(dialogRef, true, true);\n const topContentVisible = useIsVisible(topContent);\n const bottomContent = React.useRef<HTMLDivElement>(null);\n const bottomContentVisible = useIsVisible(bottomContent);\n const contentIsScrollable = modalContentRef.current && modalContentRef.current.scrollHeight > modalContentRef.current.clientHeight;\n\n function handleKeyboardEvent(e: KeyboardEvent): void {\n if (e.key === 'Escape' && props.onClose) {\n e.stopPropagation();\n props.onClose();\n }\n }\n\n function handleClickEvent(event: MouseEvent): void {\n if (event.target && overlayRef.current === event.target && props.onClose) {\n event.stopPropagation();\n props.onClose();\n }\n }\n\n function disableBodyScroll(): void {\n document.body.style.overflow = 'hidden';\n }\n\n function enableBodyScroll(): void {\n document.body.style.removeProperty('overflow');\n }\n\n /* Displays a full window size modal with image */\n const imageView = props.variant === ModalVariants.image;\n\n const overlayRef = React.useRef<HTMLDivElement>(null);\n\n const showActions = (props.secondaryButtonText && props.secondaryButtonText?.length > 0) || props.onSuccess;\n\n // ariaLabelledBy prioriteres over ariaLabel, men dersom ariaLabel brukes trengs ikke ariaLabelledBy\n const ariaLabel = !props.ariaLabelledBy ? props.ariaLabel : undefined;\n const ariaLabelledBy = props.ariaLabelledBy ? props.ariaLabelledBy : !props.ariaLabel ? props.titleId : undefined;\n\n useEffect(() => {\n const overlayElement = overlayRef.current;\n disableBodyScroll();\n if (!props.disableCloseEvents && overlayElement) {\n overlayElement.addEventListener('keydown', handleKeyboardEvent);\n overlayElement.addEventListener('click', handleClickEvent);\n }\n return (): void => {\n enableBodyScroll();\n if (!props.disableCloseEvents && overlayElement) {\n overlayElement.removeEventListener('keydown', handleKeyboardEvent);\n overlayElement.removeEventListener('click', handleClickEvent);\n }\n };\n }, [props.disableCloseEvents]);\n\n const dialogClasses = cn(\n props.className,\n styles.modal,\n styles[`modal--${props.variant}`],\n styles[`modal--${props.size}`],\n contentIsScrollable && !showActions && styles['modal--no-actions']\n );\n\n const titleClasses = cn({\n [styles['modal__title--error']]: props.variant === ModalVariants.error,\n [styles['modal__title--success']]: props.variant === ModalVariants.success,\n });\n\n const Component = (\n <div data-testid=\"dialog-container\">\n <div\n ref={overlayRef}\n className={styles['modal-overlay']}\n data-testid={props.testId}\n data-analyticsid={AnalyticsId.Modal}\n style={{ zIndex: props.zIndex }}\n >\n <div className={styles.align}>\n <div className={dialogClasses} role=\"dialog\" aria-label={ariaLabel} aria-labelledby={ariaLabelledBy} ref={dialogRef}>\n <div\n className={cn(styles['modal__shadow'], styles['modal__shadow--top'], {\n [styles['modal__shadow--show']]: !topContentVisible && contentIsScrollable,\n })}\n />\n <div\n className={cn(styles.modal__contentWrapper, {\n [styles['modal__contentWrapper--image']]: imageView,\n })}\n ref={modalContentRef}\n >\n {!props.noCloseButton && (\n <div className={styles.modal__closeWrapper}>\n <div className={cn(styles.modal__closeWrapper__close)}>\n <Close onClick={props.onClose} ariaLabel={props.ariaLabelCloseBtn} />\n </div>\n </div>\n )}\n <div\n className={cn(styles[`modal__contentWrapper__scroll--${props.size}`], {\n [styles['modal__contentWrapper__scroll--image']]: imageView,\n })}\n >\n <div ref={topContent} />\n <div className={styles.modal__contentWrapper__title}>\n {getIcon(props.variant, props.icon)}\n <Title id={ariaLabelledBy} htmlMarkup=\"h3\" appearance=\"title3\" className={titleClasses}>\n {props.title}\n </Title>\n {props.afterTitleChildren && <div className={styles['modal__afterTitleChildren']}>{props.afterTitleChildren}</div>}\n </div>\n {imageView && (\n <div>\n <div className={styles['modal__contentWrapper__imageWrapper']}>{props.children}</div>\n <span className={styles['modal__contentWrapper__imageDescription']}>{props.description}</span>\n </div>\n )}\n {!imageView && props.children && <div>{props.children}</div>}\n {!imageView && !props.children && <p className={styles.modal__description}>{props.description}</p>}\n <div ref={bottomContent} />\n </div>\n </div>\n <div\n className={cn(styles['modal__shadow'], styles['modal__shadow--bottom'], {\n [styles['modal__shadow--show']]: !bottomContentVisible && contentIsScrollable,\n })}\n />\n {showActions && (\n <div className={cn(styles['modal__call-to-action'], styles[`modal__call-to-action--${props.size}`])}>\n {props.onSuccess && <Button onClick={props.onSuccess}>{props.primaryButtonText}</Button>}\n {props.secondaryButtonText && props.secondaryButtonText?.length > 0 && (\n <Button variant=\"borderless\" onClick={props.onClose}>\n {props.secondaryButtonText}\n </Button>\n )}\n </div>\n )}\n </div>\n </div>\n </div>\n </div>\n );\n\n if (props.printable) {\n const printModal = 'print-modal';\n return (\n <Portal className={printModal} testId=\"print-modal\">\n <style media=\"print\">{`body > *:not(.${printModal}) {display: none;}`}</style>\n {Component}\n </Portal>\n );\n }\n\n return Component;\n};\n\nModal.defaultProps = defaultProps;\n\nexport default Modal;\n"],"names":["ModalVariants","ModalSize","defaultProps","uuid","ZIndex","getVariantIcon","variant","React","Icon","IconSize","AlertSignFill","palette","AlertSignStroke","CheckOutline","getIcon","icon","variantIcon","styles","Modal","props","topContent","modalContentRef","dialogRef","useFocusTrap","topContentVisible","useIsVisible","bottomContent","bottomContentVisible","contentIsScrollable","handleKeyboardEvent","e","handleClickEvent","event","overlayRef","disableBodyScroll","enableBodyScroll","imageView","showActions","_a","ariaLabel","ariaLabelledBy","useEffect","overlayElement","dialogClasses","cn","titleClasses","Component","AnalyticsId","Close","Title","Button","_b","printModal","Portal"],"mappings":"0sBAmBY,IAAAA,GAAAA,IACVA,EAAA,OAAS,SACTA,EAAA,QAAU,UACVA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,MAAQ,QALEA,IAAAA,GAAA,CAAA,CAAA,EAQAC,GAAAA,IACVA,EAAA,MAAQ,QACRA,EAAA,OAAS,SAFCA,IAAAA,GAAA,CAAA,CAAA,EAkDZ,MAAMC,EAAe,CACnB,QAAS,SACT,kBAAmB,KACnB,QAASC,EAAK,EACd,UAAW,GACX,KAAM,QACN,OAAQC,EAAO,KACjB,EAEMC,EAAkBC,GAClBA,IAAY,QACNC,EAAA,cAAAC,EAAA,CAAK,KAAMC,EAAS,MAAO,QAASC,EAAe,MAAOC,EAAQ,SAAA,CAAW,EAC5EL,IAAY,UACbC,EAAA,cAAAC,EAAA,CAAK,KAAMC,EAAS,MAAO,QAASG,EAAiB,MAAOD,EAAQ,KAAA,CAAO,EAC1EL,IAAY,UACbC,EAAA,cAAAC,EAAA,CAAK,KAAMC,EAAS,MAAO,QAASI,EAAc,MAAOF,EAAQ,OAAA,CAAS,EAE7E,KAGHG,EAAU,CAACR,EAAiCS,IAAkD,CAC5F,MAAAC,EAAcX,EAAeC,CAAO,EAC1C,OAAIU,EACMT,EAAA,cAAA,MAAA,CAAI,UAAWU,EAAO,kBAAA,EAAqBD,CAAY,EAE7DD,E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,EAAA,cAAA2C,EAAA,CAAO,QAAS/B,EAAM,SAAY,EAAAA,EAAM,iBAAkB,EAC9EA,EAAM,uBAAuBgC,EAAAhC,EAAM,sBAAN,YAAAgC,EAA2B,QAAS,GAC/D5C,EAAA,cAAA2C,EAAA,CAAO,QAAQ,aAAa,QAAS/B,EAAM,OAAA,EACzCA,EAAM,mBACT,CAEJ,CAEJ,CACF,CACF,CACF,EAGF,GAAIA,EAAM,UAAW,CACnB,MAAMiC,EAAa,cACnB,OACG7C,EAAA,cAAA8C,EAAA,CAAO,UAAWD,EAAY,OAAO,aAAA,EACnC7C,EAAA,cAAA,QAAA,CAAM,MAAM,OAAA,EAAS,iBAAiB6C,qBAA+B,EACrEN,CACH,CAEJ,CAEO,OAAAA,CACT,EAEA5B,EAAM,aAAehB"}
package/Panel.js CHANGED
@@ -1,2 +1,2 @@
1
- import t,{useState as se,useEffect as z}from"react";import o from"classnames";import e from"./components/Panel/styles.module.scss";import{T as ie}from"./Title.js";import{B as D}from"./Button.js";import{AnalyticsId as ce,IconSize as x}from"./constants.js";import{Icon as d}from"./components/Icons/Icon.js";import me from"./components/Icons/ChevronDown.js";import pe from"./components/Icons/ChevronUp.js";import ue from"./components/Icons/ArrowRight.js";import de from"./components/Icons/AlertSignFill.js";import{palette as $}from"./theme/palette.js";import fe from"./components/Icons/Pencil.js";import ye from"./components/Icons/Calendar.js";import _e from"./components/Icons/Watch.js";import{useBreakpoint as be,Breakpoint as j}from"./hooks/useBreakpoint.js";import{useUuid as W}from"./hooks/useUuid.js";import{usePrevious as Ee}from"./hooks/usePrevious.js";import{g as ge}from"./accessibility.js";import{B as ve}from"./Badge.js";var he=(a=>(a.normal="normal",a.new="new",a.error="error",a.draft="draft",a))(he||{}),Ce=(a=>(a.fill="fill",a.white="white",a.stroke="stroke",a.line="line",a))(Ce||{}),we=(a=>(a.layout1="layout1",a.layout2="layout2",a.layout3a="layout3a",a.layout3b="layout3b",a.layout3c="layout3c",a))(we||{});const Ne=({status:a,statusMessage:s})=>{const g=()=>a==="error"?{color:$.cherry500,svgIcon:de}:{color:$.black,svgIcon:fe},i=o(e["status-message"],{[e["status-message--new"]]:a==="new"});return(a==="error"||a==="draft")&&s?t.createElement("div",{className:i,"data-testid":"display-status"},t.createElement(d,{...g(),size:x.XSmall})," ",t.createElement("span",null,s)):null},X=({date:a,time:s})=>a||s?t.createElement("div",{className:e["datetime-container"],"data-testid":"datetime"},a&&t.createElement("div",{className:e["datetime-container__icon"]},t.createElement(d,{svgIcon:ye,size:x.XSmall}),t.createElement("span",null,a)),s&&t.createElement("div",{className:e["datetime-container__icon"]},t.createElement(d,{svgIcon:_e,size:x.XSmall}),t.createElement("span",null,s))):null,qe=t.forwardRef(function(s,g){const{children:i,contentA:F,contentB:r,className:H,testId:U,title:v,titleHtmlMarkup:L="h2",url:f,target:O="_self",icon:c,iconRight:B=!1,variant:m="fill",status:p="normal",statusMessage:h,buttonText:A="Se detaljer",buttonTextClose:q="Skjul detaljer",buttonAriaLabelledById:S,buttonAriaLabel:G,layout:n="layout2",containerAsButton:C=!1,date:w,time:N,noTopBorder:J,buttonOnClick:u,buttonHtmlMarkup:K="a",expanded:y=!1,onExpand:_,renderChildrenWhenClosed:Q=!1}=s,[l,T]=se(y),Y=Ee(l),I=W(),b=W(),R=be();z(()=>{y!==l&&T(y)},[y]),z(()=>{_&&l!==!!Y&&_(l)},[l,_]);const E=["layout3a".toString(),"layout3b".toString(),"layout3c".toString()].includes(n),Z=o(e["panel-wrapper"],H),P=o(e.panel,{[e["panel--fill"]]:m==="fill",[e["panel--stroke"]]:m==="stroke",[e["panel--white"]]:m==="white",[e["panel--line"]]:m==="line",[e["panel--no-top-border"]]:m==="line"&&J,[e["panel--selected"]]:l,[e["panel--new"]]:p==="new",[e["panel--draft"]]:p==="draft",[e["panel--error"]]:p==="error",[e["panel--status"]]:p&&p!=="normal",[e["panel--with-icon"]]:c,[e["panel--button"]]:C,[e["panel--clickable"]]:i||f||_||u||C}),V=o({[e.panel__container]:n==="layout2"&&r,[e["panel__container--layout3"]]:E&&r,[e["panel__container--grow"]]:c}),ee=o({[e["panel-content-a"]]:n==="layout2",[e["panel-content-a--layout3a"]]:n==="layout3a",[e["panel-content-a--layout3b"]]:n==="layout3b",[e["panel-content-a--layout3c"]]:n==="layout3c"}),te=o({[e["panel__content-right--layout1"]]:r&&n==="layout1",[e["panel__content-right--layout2"]]:r&&n==="layout2",[e["panel__content-right--layout3"]]:r&&E,[e["panel__content-right--layout3a"]]:r&&n==="layout3a",[e["panel__content-right--layout3b"]]:r&&n==="layout3b",[e["panel__content-right--layout3c"]]:r&&n==="layout3c"}),ae=o(e["panel-content-b"],{[e["panel-content-b--layout1"]]:n==="layout1",[e["panel-content-b--layout3"]]:E}),ne=o(e["panel__details-btn"]),le=()=>{const k=ge({label:G,id:S&&`${b} ${S}`||v&&I&&`${b} ${I}`}),M={onClick:u||(()=>T(!l)),className:C?e.panel__expand:void 0,variant:"borderless",ellipsis:!0,...k};return i?t.createElement(D,{testId:"expand","aria-expanded":l,...M},t.createElement("span",{id:b},l?q:A),t.createElement(d,{svgIcon:l?pe:me})):t.createElement(D,{testId:"url",htmlMarkup:K,href:f,target:O,...M},t.createElement("span",{id:b},A),t.createElement(d,{svgIcon:ue}))},re=o(e["panel__btn-container"],{[e["panel__btn-container--layout3"]]:E,[e["panel__btn-container--padding-top"]]:r}),oe=()=>{if(!i||!Q&&!l)return null;const k=o(e["panel-details"],{[e["panel-details--open"]]:l,[e["panel-details--line"]]:m==="line",[e["panel-details--white"]]:m==="white",[e["panel-details--with-icon"]]:c});return t.createElement("div",{className:k,"data-testid":"panel-details"},t.createElement("div",null,i))};return t.createElement("div",{ref:g,"data-testid":U,className:Z,"data-analyticsid":ce.Panel},t.createElement("div",{className:P},c&&!B&&t.createElement("div",{className:e.panel__icon},c),t.createElement("div",{className:V},t.createElement("div",{className:ee},t.createElement(Ne,{status:p,statusMessage:h}),v&&t.createElement("div",{className:e["panel-content-a__title-container"]},t.createElement(ie,{appearance:"title3",htmlMarkup:L,id:I},v),h&&p==="new"&&t.createElement(ve,{color:"blueberry",testId:"badge-status",className:e.panel__badge},h)),F,R>=j.lg&&t.createElement(X,{date:w,time:N})),t.createElement("div",{className:te},r&&t.createElement("div",{className:ae},r),(i||f||w||N||u)&&t.createElement("div",{className:re},R<j.lg&&t.createElement(X,{date:w,time:N}),(i||f||u)&&t.createElement("div",{className:ne},le())))),c&&B&&t.createElement("div",{className:e["panel__icon--right"]},c)),oe())});export{qe as P,he as a,Ce as b,we as c};
1
+ import t,{useState as se,useEffect as z}from"react";import o from"classnames";import e from"./components/Panel/styles.module.scss";import{T as ie}from"./Title.js";import{B as D}from"./Button.js";import{AnalyticsId as ce,IconSize as x}from"./constants.js";import{Icon as d}from"./components/Icons/Icon.js";import me from"./components/Icons/ChevronDown.js";import pe from"./components/Icons/ChevronUp.js";import ue from"./components/Icons/ArrowRight.js";import de from"./components/Icons/AlertSignFill.js";import{palette as $}from"./theme/palette.js";import fe from"./components/Icons/Pencil.js";import ye from"./components/Icons/Calendar.js";import _e from"./components/Icons/Watch.js";import{useBreakpoint as be,Breakpoint as j}from"./hooks/useBreakpoint.js";import{useUuid as W}from"./hooks/useUuid.js";import{usePrevious as Ee}from"./hooks/usePrevious.js";import{getAriaLabelAttributes as ve}from"./utils/accessibility.js";import{B as ge}from"./Badge.js";var he=(a=>(a.normal="normal",a.new="new",a.error="error",a.draft="draft",a))(he||{}),Ce=(a=>(a.fill="fill",a.white="white",a.stroke="stroke",a.line="line",a))(Ce||{}),we=(a=>(a.layout1="layout1",a.layout2="layout2",a.layout3a="layout3a",a.layout3b="layout3b",a.layout3c="layout3c",a))(we||{});const Ne=({status:a,statusMessage:s})=>{const v=()=>a==="error"?{color:$.cherry500,svgIcon:de}:{color:$.black,svgIcon:fe},i=o(e["status-message"],{[e["status-message--new"]]:a==="new"});return(a==="error"||a==="draft")&&s?t.createElement("div",{className:i,"data-testid":"display-status"},t.createElement(d,{...v(),size:x.XSmall})," ",t.createElement("span",null,s)):null},X=({date:a,time:s})=>a||s?t.createElement("div",{className:e["datetime-container"],"data-testid":"datetime"},a&&t.createElement("div",{className:e["datetime-container__icon"]},t.createElement(d,{svgIcon:ye,size:x.XSmall}),t.createElement("span",null,a)),s&&t.createElement("div",{className:e["datetime-container__icon"]},t.createElement(d,{svgIcon:_e,size:x.XSmall}),t.createElement("span",null,s))):null,qe=t.forwardRef(function(s,v){const{children:i,contentA:F,contentB:r,className:H,testId:U,title:g,titleHtmlMarkup:L="h2",url:f,target:O="_self",icon:c,iconRight:B=!1,variant:m="fill",status:p="normal",statusMessage:h,buttonText:A="Se detaljer",buttonTextClose:q="Skjul detaljer",buttonAriaLabelledById:S,buttonAriaLabel:G,layout:n="layout2",containerAsButton:C=!1,date:w,time:N,noTopBorder:J,buttonOnClick:u,buttonHtmlMarkup:K="a",expanded:y=!1,onExpand:_,renderChildrenWhenClosed:Q=!1}=s,[l,T]=se(y),Y=Ee(l),I=W(),b=W(),R=be();z(()=>{y!==l&&T(y)},[y]),z(()=>{_&&l!==!!Y&&_(l)},[l,_]);const E=["layout3a".toString(),"layout3b".toString(),"layout3c".toString()].includes(n),Z=o(e["panel-wrapper"],H),P=o(e.panel,{[e["panel--fill"]]:m==="fill",[e["panel--stroke"]]:m==="stroke",[e["panel--white"]]:m==="white",[e["panel--line"]]:m==="line",[e["panel--no-top-border"]]:m==="line"&&J,[e["panel--selected"]]:l,[e["panel--new"]]:p==="new",[e["panel--draft"]]:p==="draft",[e["panel--error"]]:p==="error",[e["panel--status"]]:p&&p!=="normal",[e["panel--with-icon"]]:c,[e["panel--button"]]:C,[e["panel--clickable"]]:i||f||_||u||C}),V=o({[e.panel__container]:n==="layout2"&&r,[e["panel__container--layout3"]]:E&&r,[e["panel__container--grow"]]:c}),ee=o({[e["panel-content-a"]]:n==="layout2",[e["panel-content-a--layout3a"]]:n==="layout3a",[e["panel-content-a--layout3b"]]:n==="layout3b",[e["panel-content-a--layout3c"]]:n==="layout3c"}),te=o({[e["panel__content-right--layout1"]]:r&&n==="layout1",[e["panel__content-right--layout2"]]:r&&n==="layout2",[e["panel__content-right--layout3"]]:r&&E,[e["panel__content-right--layout3a"]]:r&&n==="layout3a",[e["panel__content-right--layout3b"]]:r&&n==="layout3b",[e["panel__content-right--layout3c"]]:r&&n==="layout3c"}),ae=o(e["panel-content-b"],{[e["panel-content-b--layout1"]]:n==="layout1",[e["panel-content-b--layout3"]]:E}),ne=o(e["panel__details-btn"]),le=()=>{const k=ve({label:G,id:S&&`${b} ${S}`||g&&I&&`${b} ${I}`}),M={onClick:u||(()=>T(!l)),className:C?e.panel__expand:void 0,variant:"borderless",ellipsis:!0,...k};return i?t.createElement(D,{testId:"expand","aria-expanded":l,...M},t.createElement("span",{id:b},l?q:A),t.createElement(d,{svgIcon:l?pe:me})):t.createElement(D,{testId:"url",htmlMarkup:K,href:f,target:O,...M},t.createElement("span",{id:b},A),t.createElement(d,{svgIcon:ue}))},re=o(e["panel__btn-container"],{[e["panel__btn-container--layout3"]]:E,[e["panel__btn-container--padding-top"]]:r}),oe=()=>{if(!i||!Q&&!l)return null;const k=o(e["panel-details"],{[e["panel-details--open"]]:l,[e["panel-details--line"]]:m==="line",[e["panel-details--white"]]:m==="white",[e["panel-details--with-icon"]]:c});return t.createElement("div",{className:k,"data-testid":"panel-details"},t.createElement("div",null,i))};return t.createElement("div",{ref:v,"data-testid":U,className:Z,"data-analyticsid":ce.Panel},t.createElement("div",{className:P},c&&!B&&t.createElement("div",{className:e.panel__icon},c),t.createElement("div",{className:V},t.createElement("div",{className:ee},t.createElement(Ne,{status:p,statusMessage:h}),g&&t.createElement("div",{className:e["panel-content-a__title-container"]},t.createElement(ie,{appearance:"title3",htmlMarkup:L,id:I},g),h&&p==="new"&&t.createElement(ge,{color:"blueberry",testId:"badge-status",className:e.panel__badge},h)),F,R>=j.lg&&t.createElement(X,{date:w,time:N})),t.createElement("div",{className:te},r&&t.createElement("div",{className:ae},r),(i||f||w||N||u)&&t.createElement("div",{className:re},R<j.lg&&t.createElement(X,{date:w,time:N}),(i||f||u)&&t.createElement("div",{className:ne},le())))),c&&B&&t.createElement("div",{className:e["panel__icon--right"]},c)),oe())});export{qe as P,he as a,Ce as b,we as c};
2
2
  //# sourceMappingURL=Panel.js.map