@navikt/ds-react 5.5.0 → 5.6.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 (342) hide show
  1. package/_docs.json +507 -106
  2. package/cjs/accordion/Accordion.js +1 -0
  3. package/cjs/accordion/AccordionContext.js +1 -1
  4. package/cjs/accordion/AccordionHeader.js +2 -2
  5. package/cjs/accordion/AccordionItem.js +6 -2
  6. package/cjs/date/datepicker/DatePicker.js +30 -34
  7. package/cjs/date/datepicker/DatePickerStandalone.js +23 -26
  8. package/cjs/date/datepicker/parts/Caption.js +28 -0
  9. package/cjs/date/datepicker/{DayButton.js → parts/DayButton.js} +1 -2
  10. package/cjs/date/datepicker/{caption → parts}/DropdownCaption.js +13 -7
  11. package/cjs/date/datepicker/parts/HeadRow.js +36 -0
  12. package/cjs/date/datepicker/parts/Row.js +23 -0
  13. package/cjs/date/datepicker/{TableHead.js → parts/TableHead.js} +4 -3
  14. package/cjs/date/datepicker/parts/WeekNumber.js +35 -0
  15. package/cjs/date/datepicker/parts/WeekRow.js +34 -0
  16. package/cjs/date/hooks/useDatepicker.js +2 -2
  17. package/cjs/date/hooks/useMonthPicker.js +2 -2
  18. package/cjs/date/hooks/useRangeDatepicker.js +3 -3
  19. package/cjs/date/monthpicker/MonthSelector.js +1 -1
  20. package/cjs/date/utils/get-month-weeks.js +46 -0
  21. package/cjs/date/utils/labels.js +40 -1
  22. package/cjs/dropdown/Toggle.js +2 -2
  23. package/cjs/dropdown/index.js +0 -15
  24. package/cjs/form/Select.js +1 -1
  25. package/cjs/form/checkbox/useCheckbox.js +3 -4
  26. package/cjs/form/combobox/Combobox.js +1 -1
  27. package/cjs/form/combobox/Input/Input.js +1 -1
  28. package/cjs/form/search/Search.js +3 -1
  29. package/cjs/index.js +1 -0
  30. package/cjs/layout/bleed/Bleed.js +69 -0
  31. package/cjs/layout/bleed/index.js +5 -0
  32. package/cjs/layout/bleed/package.json +6 -0
  33. package/cjs/layout/box/Box.js +1 -1
  34. package/cjs/layout/responsive/Responsive.js +8 -6
  35. package/cjs/layout/sidemal-test/AvatarPanel.js +18 -0
  36. package/cjs/layout/sidemal-test/Content.js +66 -0
  37. package/cjs/layout/sidemal-test/Filter.js +48 -0
  38. package/cjs/layout/sidemal-test/Header.js +48 -0
  39. package/cjs/layout/sidemal-test/Intro.js +36 -0
  40. package/cjs/layout/sidemal-test/Sidebar.js +49 -0
  41. package/cjs/layout/sidemal-test/content-box/ContentBox.js +65 -0
  42. package/cjs/layout/sidemal-test/content-box/index.js +8 -0
  43. package/cjs/layout/sidemal-test/content-box/package.json +6 -0
  44. package/cjs/layout/stack/Stack.js +2 -2
  45. package/cjs/layout/stack/index.js +3 -1
  46. package/cjs/layout/utilities/css.js +37 -14
  47. package/cjs/loader/Loader.js +2 -2
  48. package/cjs/modal/dialog-polyfill.js +2 -0
  49. package/cjs/popover/Popover.js +3 -2
  50. package/cjs/tabs/TabList.js +6 -7
  51. package/cjs/timeline/Pin.js +20 -20
  52. package/cjs/timeline/Timeline.js +4 -4
  53. package/cjs/timeline/period/ClickablePeriod.js +19 -19
  54. package/cjs/timeline/period/index.js +1 -1
  55. package/cjs/timeline/utils/timeline.js +3 -3
  56. package/cjs/toggle-group/ToggleGroup.js +1 -1
  57. package/cjs/tooltip/Tooltip.js +1 -1
  58. package/cjs/typography/Heading.js +1 -1
  59. package/cjs/util/RandomIcon.js +1 -0
  60. package/cjs/util/Slot.js +88 -0
  61. package/cjs/util/useId.js +2 -4
  62. package/esm/accordion/Accordion.js +1 -0
  63. package/esm/accordion/Accordion.js.map +1 -1
  64. package/esm/accordion/AccordionContext.d.ts +1 -0
  65. package/esm/accordion/AccordionContext.js +1 -1
  66. package/esm/accordion/AccordionContext.js.map +1 -1
  67. package/esm/accordion/AccordionHeader.js +2 -2
  68. package/esm/accordion/AccordionHeader.js.map +1 -1
  69. package/esm/accordion/AccordionItem.js +6 -2
  70. package/esm/accordion/AccordionItem.js.map +1 -1
  71. package/esm/date/datepicker/DatePicker.d.ts +14 -5
  72. package/esm/date/datepicker/DatePicker.js +29 -33
  73. package/esm/date/datepicker/DatePicker.js.map +1 -1
  74. package/esm/date/datepicker/DatePickerStandalone.d.ts +3 -2
  75. package/esm/date/datepicker/DatePickerStandalone.js +22 -25
  76. package/esm/date/datepicker/DatePickerStandalone.js.map +1 -1
  77. package/esm/date/datepicker/{caption → parts}/Caption.d.ts +3 -0
  78. package/esm/date/datepicker/parts/Caption.js +22 -0
  79. package/esm/date/datepicker/parts/Caption.js.map +1 -0
  80. package/esm/date/datepicker/parts/DayButton.d.ts +4 -0
  81. package/esm/date/datepicker/{DayButton.js → parts/DayButton.js} +2 -1
  82. package/esm/date/datepicker/parts/DayButton.js.map +1 -0
  83. package/esm/date/datepicker/{caption → parts}/DropdownCaption.d.ts +3 -0
  84. package/esm/date/datepicker/parts/DropdownCaption.js +44 -0
  85. package/esm/date/datepicker/parts/DropdownCaption.js.map +1 -0
  86. package/esm/date/datepicker/parts/HeadRow.d.ts +11 -0
  87. package/esm/date/datepicker/parts/HeadRow.js +29 -0
  88. package/esm/date/datepicker/parts/HeadRow.js.map +1 -0
  89. package/esm/date/datepicker/parts/Row.d.ts +17 -0
  90. package/esm/date/datepicker/parts/Row.js +19 -0
  91. package/esm/date/datepicker/parts/Row.js.map +1 -0
  92. package/esm/date/datepicker/parts/TableHead.d.ts +6 -0
  93. package/esm/date/datepicker/{TableHead.js → parts/TableHead.js} +5 -2
  94. package/esm/date/datepicker/parts/TableHead.js.map +1 -0
  95. package/esm/date/datepicker/parts/WeekNumber.d.ts +13 -0
  96. package/esm/date/datepicker/parts/WeekNumber.js +31 -0
  97. package/esm/date/datepicker/parts/WeekNumber.js.map +1 -0
  98. package/esm/date/datepicker/parts/WeekRow.d.ts +5 -0
  99. package/esm/date/datepicker/parts/WeekRow.js +30 -0
  100. package/esm/date/datepicker/parts/WeekRow.js.map +1 -0
  101. package/esm/date/hooks/useDatepicker.js +2 -2
  102. package/esm/date/hooks/useDatepicker.js.map +1 -1
  103. package/esm/date/hooks/useMonthPicker.js +2 -2
  104. package/esm/date/hooks/useMonthPicker.js.map +1 -1
  105. package/esm/date/hooks/useRangeDatepicker.js +3 -3
  106. package/esm/date/hooks/useRangeDatepicker.js.map +1 -1
  107. package/esm/date/monthpicker/MonthButton.d.ts +2 -2
  108. package/esm/date/monthpicker/MonthPicker.d.ts +1 -1
  109. package/esm/date/monthpicker/MonthSelector.js +1 -1
  110. package/esm/date/monthpicker/MonthSelector.js.map +1 -1
  111. package/esm/date/utils/get-month-weeks.d.ts +16 -0
  112. package/esm/date/utils/get-month-weeks.js +42 -0
  113. package/esm/date/utils/get-month-weeks.js.map +1 -0
  114. package/esm/date/utils/labels.d.ts +9 -0
  115. package/esm/date/utils/labels.js +36 -0
  116. package/esm/date/utils/labels.js.map +1 -1
  117. package/esm/date/utils/navigation.d.ts +1 -1
  118. package/esm/date/utils/navigation.js.map +1 -1
  119. package/esm/dropdown/Toggle.js +1 -1
  120. package/esm/dropdown/Toggle.js.map +1 -1
  121. package/esm/dropdown/index.d.ts +1 -2
  122. package/esm/dropdown/index.js +0 -1
  123. package/esm/dropdown/index.js.map +1 -1
  124. package/esm/form/Select.js +1 -1
  125. package/esm/form/Select.js.map +1 -1
  126. package/esm/form/checkbox/useCheckbox.d.ts +1 -1
  127. package/esm/form/checkbox/useCheckbox.js +3 -4
  128. package/esm/form/checkbox/useCheckbox.js.map +1 -1
  129. package/esm/form/combobox/Combobox.d.ts +1 -1
  130. package/esm/form/combobox/Combobox.js +1 -1
  131. package/esm/form/combobox/Combobox.js.map +1 -1
  132. package/esm/form/combobox/Input/Input.d.ts +0 -2
  133. package/esm/form/combobox/Input/Input.js +1 -1
  134. package/esm/form/combobox/Input/Input.js.map +1 -1
  135. package/esm/form/search/Search.js +3 -1
  136. package/esm/form/search/Search.js.map +1 -1
  137. package/esm/index.d.ts +1 -0
  138. package/esm/index.js +1 -0
  139. package/esm/index.js.map +1 -1
  140. package/esm/layout/bleed/Bleed.d.ts +47 -0
  141. package/esm/layout/bleed/Bleed.js +41 -0
  142. package/esm/layout/bleed/Bleed.js.map +1 -0
  143. package/esm/layout/bleed/index.d.ts +1 -0
  144. package/esm/layout/bleed/index.js +2 -0
  145. package/esm/layout/bleed/index.js.map +1 -0
  146. package/esm/layout/box/Box.d.ts +1 -2
  147. package/esm/layout/box/Box.js +1 -1
  148. package/esm/layout/box/Box.js.map +1 -1
  149. package/esm/layout/responsive/Responsive.d.ts +8 -4
  150. package/esm/layout/responsive/Responsive.js +8 -6
  151. package/esm/layout/responsive/Responsive.js.map +1 -1
  152. package/esm/layout/sidemal-test/AvatarPanel.d.ts +4 -0
  153. package/esm/layout/sidemal-test/AvatarPanel.js +12 -0
  154. package/esm/layout/sidemal-test/AvatarPanel.js.map +1 -0
  155. package/esm/layout/sidemal-test/Content.d.ts +2 -0
  156. package/esm/layout/sidemal-test/Content.js +60 -0
  157. package/esm/layout/sidemal-test/Content.js.map +1 -0
  158. package/esm/layout/sidemal-test/Filter.d.ts +2 -0
  159. package/esm/layout/sidemal-test/Filter.js +22 -0
  160. package/esm/layout/sidemal-test/Filter.js.map +1 -0
  161. package/esm/layout/sidemal-test/Header.d.ts +2 -0
  162. package/esm/layout/sidemal-test/Header.js +42 -0
  163. package/esm/layout/sidemal-test/Header.js.map +1 -0
  164. package/esm/layout/sidemal-test/Intro.d.ts +2 -0
  165. package/esm/layout/sidemal-test/Intro.js +30 -0
  166. package/esm/layout/sidemal-test/Intro.js.map +1 -0
  167. package/esm/layout/sidemal-test/Sidebar.d.ts +4 -0
  168. package/esm/layout/sidemal-test/Sidebar.js +41 -0
  169. package/esm/layout/sidemal-test/Sidebar.js.map +1 -0
  170. package/esm/layout/sidemal-test/content-box/ContentBox.d.ts +8 -0
  171. package/esm/layout/sidemal-test/content-box/ContentBox.js +37 -0
  172. package/esm/layout/sidemal-test/content-box/ContentBox.js.map +1 -0
  173. package/esm/layout/sidemal-test/content-box/index.d.ts +1 -0
  174. package/esm/layout/sidemal-test/content-box/index.js +2 -0
  175. package/esm/layout/sidemal-test/content-box/index.js.map +1 -0
  176. package/esm/layout/stack/Stack.d.ts +7 -3
  177. package/esm/layout/stack/Stack.js +3 -3
  178. package/esm/layout/stack/Stack.js.map +1 -1
  179. package/esm/layout/stack/index.d.ts +1 -0
  180. package/esm/layout/stack/index.js +1 -0
  181. package/esm/layout/stack/index.js.map +1 -1
  182. package/esm/layout/utilities/css.d.ts +1 -1
  183. package/esm/layout/utilities/css.js +37 -14
  184. package/esm/layout/utilities/css.js.map +1 -1
  185. package/esm/loader/Loader.js +3 -3
  186. package/esm/loader/Loader.js.map +1 -1
  187. package/esm/modal/dialog-polyfill.js +2 -0
  188. package/esm/modal/dialog-polyfill.js.map +1 -1
  189. package/esm/popover/Popover.js +3 -2
  190. package/esm/popover/Popover.js.map +1 -1
  191. package/esm/tabs/TabList.js +6 -7
  192. package/esm/tabs/TabList.js.map +1 -1
  193. package/esm/timeline/Pin.js +21 -21
  194. package/esm/timeline/Pin.js.map +1 -1
  195. package/esm/timeline/Timeline.js +4 -4
  196. package/esm/timeline/Timeline.js.map +1 -1
  197. package/esm/timeline/TimelineRow.js.map +1 -1
  198. package/esm/timeline/hooks/usePeriodContext.d.ts +1 -1
  199. package/esm/timeline/period/ClickablePeriod.js +20 -20
  200. package/esm/timeline/period/ClickablePeriod.js.map +1 -1
  201. package/esm/timeline/period/index.d.ts +2 -2
  202. package/esm/timeline/period/index.js +1 -1
  203. package/esm/timeline/period/index.js.map +1 -1
  204. package/esm/timeline/utils/timeline.js +3 -3
  205. package/esm/timeline/utils/timeline.js.map +1 -1
  206. package/esm/toggle-group/ToggleGroup.js +1 -1
  207. package/esm/toggle-group/ToggleGroup.js.map +1 -1
  208. package/esm/tooltip/Tooltip.js +1 -1
  209. package/esm/tooltip/Tooltip.js.map +1 -1
  210. package/esm/typography/Heading.js +1 -1
  211. package/esm/typography/Heading.js.map +1 -1
  212. package/esm/util/RandomIcon.js +1 -0
  213. package/esm/util/RandomIcon.js.map +1 -1
  214. package/esm/util/Slot.d.ts +6 -0
  215. package/esm/util/Slot.js +60 -0
  216. package/esm/util/Slot.js.map +1 -0
  217. package/esm/util/mergeRefs.d.ts +1 -1
  218. package/esm/util/useId.js +2 -4
  219. package/esm/util/useId.js.map +1 -1
  220. package/package.json +4 -4
  221. package/src/accordion/Accordion.tsx +1 -0
  222. package/src/accordion/AccordionContext.tsx +2 -1
  223. package/src/accordion/AccordionHeader.tsx +2 -2
  224. package/src/accordion/AccordionItem.tsx +7 -5
  225. package/src/accordion/accordion.stories.tsx +21 -34
  226. package/src/alert/alert.stories.tsx +2 -2
  227. package/src/chips/chips.stories.tsx +29 -32
  228. package/src/date/datepicker/DatePicker.tsx +63 -58
  229. package/src/date/datepicker/DatePickerStandalone.tsx +36 -39
  230. package/src/date/datepicker/datepicker.stories.tsx +67 -2
  231. package/src/date/datepicker/datepicker.test.tsx +5 -4
  232. package/src/date/datepicker/{caption → parts}/Caption.tsx +19 -17
  233. package/src/date/datepicker/{DayButton.tsx → parts/DayButton.tsx} +3 -1
  234. package/src/date/datepicker/parts/DropdownCaption.tsx +113 -0
  235. package/src/date/datepicker/parts/HeadRow.tsx +56 -0
  236. package/src/date/datepicker/parts/Row.tsx +47 -0
  237. package/src/date/datepicker/{TableHead.tsx → parts/TableHead.tsx} +6 -2
  238. package/src/date/datepicker/parts/WeekNumber.tsx +79 -0
  239. package/src/date/datepicker/parts/WeekRow.tsx +60 -0
  240. package/src/date/hooks/useDatepicker.tsx +2 -2
  241. package/src/date/hooks/useMonthPicker.tsx +2 -2
  242. package/src/date/hooks/useRangeDatepicker.test.tsx +11 -11
  243. package/src/date/hooks/useRangeDatepicker.tsx +3 -3
  244. package/src/date/monthpicker/MonthButton.tsx +2 -2
  245. package/src/date/monthpicker/MonthPicker.tsx +1 -1
  246. package/src/date/monthpicker/MonthSelector.tsx +3 -3
  247. package/src/date/monthpicker/monthpicker.stories.tsx +1 -1
  248. package/src/date/utils/__tests__/get-initial-year.test.ts +0 -12
  249. package/src/date/utils/__tests__/get-month-weeks.test.ts +113 -0
  250. package/src/date/utils/__tests__/is-match.test.ts +3 -3
  251. package/src/date/utils/__tests__/parse-dates.test.ts +4 -2
  252. package/src/date/utils/get-month-weeks.ts +93 -0
  253. package/src/date/utils/labels.ts +51 -0
  254. package/src/date/utils/navigation.ts +3 -3
  255. package/src/dropdown/Toggle.tsx +1 -1
  256. package/src/dropdown/dropdown.stories.tsx +25 -28
  257. package/src/dropdown/index.ts +1 -2
  258. package/src/expansion-card/expansion-card.stories.tsx +143 -161
  259. package/src/form/ConfirmationPanel.test.tsx +5 -5
  260. package/src/form/Select.tsx +1 -1
  261. package/src/form/checkbox/Checkbox.test.tsx +14 -26
  262. package/src/form/checkbox/checkbox.stories.tsx +66 -71
  263. package/src/form/checkbox/useCheckbox.ts +3 -4
  264. package/src/form/combobox/Combobox.tsx +2 -3
  265. package/src/form/combobox/Input/Input.tsx +1 -3
  266. package/src/form/combobox/combobox.stories.tsx +20 -23
  267. package/src/form/combobox/combobox.test.tsx +22 -20
  268. package/src/form/radio/radio.stories.tsx +39 -44
  269. package/src/form/search/Search.tsx +1 -0
  270. package/src/form/search/search.stories.tsx +22 -26
  271. package/src/form/stories/fieldset.stories.tsx +1 -1
  272. package/src/index.ts +1 -0
  273. package/src/layout/bleed/Bleed.stories.tsx +381 -0
  274. package/src/layout/bleed/Bleed.tsx +130 -0
  275. package/src/layout/bleed/index.ts +1 -0
  276. package/src/layout/box/Box.stories.tsx +251 -256
  277. package/src/layout/box/Box.tsx +2 -1
  278. package/src/layout/responsive/Responsive.tsx +21 -6
  279. package/src/layout/responsive/hide.stories.tsx +35 -0
  280. package/src/layout/responsive/show.stories.tsx +35 -0
  281. package/src/layout/sidemal-test/AvatarPanel.tsx +27 -0
  282. package/src/layout/sidemal-test/Content.tsx +129 -0
  283. package/src/layout/sidemal-test/Filter.tsx +46 -0
  284. package/src/layout/sidemal-test/Header.tsx +96 -0
  285. package/src/layout/sidemal-test/Intro.tsx +91 -0
  286. package/src/layout/sidemal-test/Sidebar.tsx +77 -0
  287. package/src/layout/sidemal-test/content-box/ContentBox.tsx +46 -0
  288. package/src/layout/sidemal-test/content-box/index.ts +1 -0
  289. package/src/layout/sidemal-test/navno-sidemal.stories.mdx +29 -0
  290. package/src/layout/sidemal-test/navno-sidemal.stories.tsx +65 -0
  291. package/src/layout/sidemal-test/styling.css +43 -0
  292. package/src/layout/stack/Stack.tsx +14 -8
  293. package/src/layout/stack/index.ts +1 -0
  294. package/src/layout/stack/stack.stories.tsx +23 -1
  295. package/src/layout/utilities/css.ts +59 -20
  296. package/src/loader/Loader.tsx +2 -3
  297. package/src/modal/dialog-polyfill.ts +2 -0
  298. package/src/pagination/pagination.stories.tsx +35 -42
  299. package/src/popover/Popover.test.tsx +21 -35
  300. package/src/popover/Popover.tsx +2 -2
  301. package/src/popover/popover.stories.tsx +25 -41
  302. package/src/react-css.d.ts +0 -1
  303. package/src/read-more/readmore.stories.tsx +35 -36
  304. package/src/stepper/stepper.stories.tsx +45 -52
  305. package/src/table/stories/table-expandable.stories.tsx +59 -63
  306. package/src/tabs/TabList.tsx +4 -6
  307. package/src/tabs/Tabs.stories.tsx +3 -3
  308. package/src/tag/tag.stories.tsx +4 -4
  309. package/src/timeline/Pin.tsx +44 -39
  310. package/src/timeline/Timeline.tsx +6 -6
  311. package/src/timeline/TimelineRow.tsx +1 -0
  312. package/src/timeline/hooks/usePeriodContext.tsx +1 -1
  313. package/src/timeline/period/ClickablePeriod.tsx +42 -38
  314. package/src/timeline/period/index.tsx +5 -4
  315. package/src/timeline/timeline.stories.tsx +11 -10
  316. package/src/timeline/utils/timeline.ts +3 -3
  317. package/src/toggle-group/ToggleGroup.stories.tsx +25 -29
  318. package/src/toggle-group/ToggleGroup.tsx +0 -1
  319. package/src/tooltip/Tooltip.test.tsx +40 -54
  320. package/src/tooltip/Tooltip.tsx +1 -1
  321. package/src/typography/Heading.tsx +1 -1
  322. package/src/util/RandomIcon.tsx +1 -0
  323. package/src/util/Slot.tsx +69 -0
  324. package/src/util/__tests__/Slot.test.tsx +98 -0
  325. package/src/util/mergeRefs.tsx +1 -1
  326. package/src/util/useId.ts +1 -3
  327. package/cjs/date/datepicker/caption/Caption.js +0 -23
  328. package/cjs/date/datepicker/caption/index.js +0 -10
  329. package/cjs/date/datepicker/caption/package.json +0 -6
  330. package/esm/date/datepicker/DayButton.d.ts +0 -3
  331. package/esm/date/datepicker/DayButton.js.map +0 -1
  332. package/esm/date/datepicker/TableHead.d.ts +0 -3
  333. package/esm/date/datepicker/TableHead.js.map +0 -1
  334. package/esm/date/datepicker/caption/Caption.js +0 -17
  335. package/esm/date/datepicker/caption/Caption.js.map +0 -1
  336. package/esm/date/datepicker/caption/DropdownCaption.js +0 -38
  337. package/esm/date/datepicker/caption/DropdownCaption.js.map +0 -1
  338. package/esm/date/datepicker/caption/index.d.ts +0 -2
  339. package/esm/date/datepicker/caption/index.js +0 -3
  340. package/esm/date/datepicker/caption/index.js.map +0 -1
  341. package/src/date/datepicker/caption/DropdownCaption.tsx +0 -108
  342. package/src/date/datepicker/caption/index.ts +0 -2
@@ -1,13 +1,16 @@
1
- import { act, cleanup, fireEvent } from "@testing-library/react";
1
+ import { act, fireEvent, screen } from "@testing-library/react";
2
2
  import React from "react";
3
- import { focusVisible, simulatePointerDown } from "../../tests/utils";
3
+ import {
4
+ focusVisible,
5
+ simulatePointerDown,
6
+ renderWithStyles as render,
7
+ } from "../../tests/utils";
4
8
  import userEvent from "@testing-library/user-event";
5
9
  import Tooltip from "./Tooltip";
6
- import { renderWithStyles as render } from "../../tests/utils";
7
10
 
8
11
  describe("Tooltip", () => {
9
12
  test("controlled open", () => {
10
- const { getByRole } = render(
13
+ render(
11
14
  <Tooltip content="Hello World" open>
12
15
  <button id="testChild" type="submit">
13
16
  Hello World
@@ -15,12 +18,11 @@ describe("Tooltip", () => {
15
18
  </Tooltip>
16
19
  );
17
20
 
18
- expect(getByRole("tooltip")).toBeVisible();
19
- cleanup();
21
+ expect(screen.getByRole("tooltip")).toBeVisible();
20
22
  });
21
23
 
22
24
  test("default open", () => {
23
- const { getByRole } = render(
25
+ render(
24
26
  <Tooltip content="Hello World" defaultOpen>
25
27
  <button id="testChild" type="submit">
26
28
  Hello World
@@ -28,12 +30,11 @@ describe("Tooltip", () => {
28
30
  </Tooltip>
29
31
  );
30
32
 
31
- expect(getByRole("tooltip")).toBeVisible();
32
- cleanup();
33
+ expect(screen.getByRole("tooltip")).toBeVisible();
33
34
  });
34
35
 
35
36
  test("Focus", async () => {
36
- const { getByRole } = render(
37
+ render(
37
38
  <Tooltip content="Hello World">
38
39
  <button id="testChild" type="submit">
39
40
  Hello World
@@ -42,14 +43,12 @@ describe("Tooltip", () => {
42
43
  );
43
44
  simulatePointerDown();
44
45
 
45
- focusVisible(getByRole("button"));
46
- expect(getByRole("tooltip")).toBeVisible();
47
-
48
- cleanup();
46
+ focusVisible(screen.getByRole("button"));
47
+ expect(screen.getByRole("tooltip")).toBeVisible();
49
48
  });
50
49
 
51
50
  test("Escape", async () => {
52
- const { queryByRole, getByRole } = render(
51
+ render(
53
52
  <Tooltip content="Hello World">
54
53
  <button id="testChild" type="submit">
55
54
  Hello World
@@ -58,21 +57,17 @@ describe("Tooltip", () => {
58
57
  );
59
58
  simulatePointerDown();
60
59
 
61
- focusVisible(getByRole("button"));
62
- expect(getByRole("tooltip")).toBeVisible();
63
-
64
- act(() => {
65
- fireEvent.keyDown(document, { key: "Escape" });
66
- });
67
- expect(queryByRole("tooltip")).toBeNull();
60
+ focusVisible(screen.getByRole("button"));
61
+ expect(screen.getByRole("tooltip")).toBeVisible();
68
62
 
69
- cleanup();
63
+ fireEvent.keyDown(document, { key: "Escape" });
64
+ expect(screen.queryByRole("tooltip")).toBeNull();
70
65
  });
71
66
 
72
67
  it("delay", async () => {
73
68
  const user = userEvent.setup();
74
69
 
75
- const { queryByRole, getByRole } = render(
70
+ render(
76
71
  <Tooltip content="Hello World" delay={300}>
77
72
  <button id="testChild" type="submit">
78
73
  Hello World
@@ -81,18 +76,17 @@ describe("Tooltip", () => {
81
76
  );
82
77
 
83
78
  await act(async () => {
84
- await user.hover(getByRole("button"));
79
+ await user.hover(screen.getByRole("button"));
85
80
  await new Promise((r) => setTimeout(r, 250));
86
- expect(queryByRole("tooltip")).toBeNull();
81
+ expect(screen.queryByRole("tooltip")).toBeNull();
87
82
  await new Promise((r) => setTimeout(r, 600));
88
83
  });
89
84
 
90
- expect(getByRole("tooltip")).toBeVisible();
91
- cleanup();
85
+ expect(screen.getByRole("tooltip")).toBeVisible();
92
86
  });
93
87
 
94
88
  it("outsideClick", async () => {
95
- const { queryByRole, getByRole } = render(
89
+ render(
96
90
  <div>
97
91
  <Tooltip content="Hello World">
98
92
  <button id="testChild" type="submit">
@@ -103,21 +97,19 @@ describe("Tooltip", () => {
103
97
  </div>
104
98
  );
105
99
 
106
- simulatePointerDown(getByRole("button"));
107
- focusVisible(getByRole("button"));
100
+ simulatePointerDown(screen.getByRole("button"));
101
+ focusVisible(screen.getByRole("button"));
108
102
 
109
103
  await act(async () => {
110
- expect(getByRole("tooltip")).toBeVisible();
111
- getByRole("link").focus();
104
+ expect(screen.getByRole("tooltip")).toBeVisible();
105
+ screen.getByRole("link").focus();
112
106
  });
113
107
 
114
- expect(queryByRole("tooltip")).toBeNull();
115
-
116
- cleanup();
108
+ expect(screen.queryByRole("tooltip")).toBeNull();
117
109
  });
118
110
 
119
111
  it("keep open on tooltip-click", async () => {
120
- const { getByRole } = render(
112
+ render(
121
113
  <div>
122
114
  <Tooltip content="Hello World">
123
115
  <button id="testChild" type="submit">
@@ -127,21 +119,17 @@ describe("Tooltip", () => {
127
119
  </div>
128
120
  );
129
121
 
130
- simulatePointerDown(getByRole("button"));
131
- focusVisible(getByRole("button"));
122
+ simulatePointerDown(screen.getByRole("button"));
123
+ focusVisible(screen.getByRole("button"));
132
124
 
133
- await act(async () => {
134
- expect(getByRole("tooltip")).toBeVisible();
135
- fireEvent.click(getByRole("tooltip"));
136
- });
125
+ expect(screen.getByRole("tooltip")).toBeVisible();
126
+ fireEvent.click(screen.getByRole("tooltip"));
137
127
 
138
- expect(getByRole("tooltip")).toBeVisible();
139
-
140
- cleanup();
128
+ expect(screen.getByRole("tooltip")).toBeVisible();
141
129
  });
142
130
 
143
131
  it("close on focus-loss", async () => {
144
- const { getByRole, queryByRole } = render(
132
+ render(
145
133
  <div>
146
134
  <Tooltip content="Hello World">
147
135
  <button id="testChild" type="submit">
@@ -152,16 +140,14 @@ describe("Tooltip", () => {
152
140
  </div>
153
141
  );
154
142
 
155
- simulatePointerDown(getByRole("button"));
156
- focusVisible(getByRole("button"));
143
+ simulatePointerDown(screen.getByRole("button"));
144
+ focusVisible(screen.getByRole("button"));
157
145
 
158
146
  await act(async () => {
159
- expect(getByRole("tooltip")).toBeVisible();
160
- getByRole("link").focus();
147
+ expect(screen.getByRole("tooltip")).toBeVisible();
148
+ screen.getByRole("link").focus();
161
149
  });
162
150
 
163
- expect(queryByRole("tooltip")).toBeNull();
164
-
165
- cleanup();
151
+ expect(screen.queryByRole("tooltip")).toBeNull();
166
152
  });
167
153
  });
@@ -125,7 +125,7 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
125
125
  } = useFloating({
126
126
  placement: _placement,
127
127
  open: userOpen ?? open,
128
- onOpenChange: setOpen,
128
+ onOpenChange: (_open) => setOpen(_open),
129
129
  middleware: [
130
130
  offset(_offset ? _offset : _arrow ? 10 : 2),
131
131
  shift(),
@@ -52,7 +52,7 @@ export const Heading: OverridableComponent<HeadingProps, HTMLHeadingElement> =
52
52
  },
53
53
  ref
54
54
  ) => {
55
- let HeadingTag = as ?? (`h${level}` as React.ElementType);
55
+ const HeadingTag = as ?? (`h${level}` as React.ElementType);
56
56
 
57
57
  return (
58
58
  <HeadingTag
@@ -1,6 +1,7 @@
1
1
  import * as AllIcons from "@navikt/aksel-icons";
2
2
  import React from "react";
3
3
 
4
+ // eslint-disable-next-line import/namespace
4
5
  const icons = Object.keys(AllIcons).map((key) => AllIcons[key]);
5
6
 
6
7
  export const RandomIcon = () => {
@@ -0,0 +1,69 @@
1
+ // https://github.com/radix-ui/primitives/blob/main/packages/react/slot/src/Slot.tsx
2
+ import * as React from "react";
3
+ import mergeRefs from "./mergeRefs";
4
+
5
+ interface SlotProps extends React.HTMLAttributes<HTMLElement> {
6
+ children?: React.ReactNode;
7
+ }
8
+
9
+ export const Slot = React.forwardRef<HTMLElement, SlotProps>(
10
+ (props, forwardedRef) => {
11
+ const { children, ...slotProps } = props;
12
+
13
+ if (React.isValidElement(children)) {
14
+ return React.cloneElement<any>(children, {
15
+ ...mergeProps(slotProps, children.props),
16
+ ref: forwardedRef
17
+ ? mergeRefs([forwardedRef, (children as any).ref])
18
+ : (children as any).ref,
19
+ });
20
+ }
21
+
22
+ if (React.Children.count(children) > 1) {
23
+ console.error(
24
+ "Aksel: Components using 'asChild' expects to recieve a single React element child."
25
+ );
26
+ return React.Children.only(null);
27
+ }
28
+
29
+ return null;
30
+ }
31
+ );
32
+
33
+ function mergeProps(
34
+ slotProps: Record<string, any>,
35
+ childProps: Record<string, any>
36
+ ) {
37
+ // all child props should override
38
+ const overrideProps = { ...childProps };
39
+
40
+ for (const propName in childProps) {
41
+ const slotPropValue = slotProps[propName];
42
+ const childPropValue = childProps[propName];
43
+
44
+ const isHandler = /^on[A-Z]/.test(propName);
45
+ if (isHandler) {
46
+ // if the handler exists on both, we compose them
47
+ if (slotPropValue && childPropValue) {
48
+ overrideProps[propName] = (...args: unknown[]) => {
49
+ childPropValue(...args);
50
+ slotPropValue(...args);
51
+ };
52
+ }
53
+ // but if it exists only on the slot, we use only this one
54
+ else if (slotPropValue) {
55
+ overrideProps[propName] = slotPropValue;
56
+ }
57
+ }
58
+ // if it's `style`, we merge them
59
+ else if (propName === "style") {
60
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
61
+ } else if (propName === "className") {
62
+ overrideProps[propName] = [slotPropValue, childPropValue]
63
+ .filter(Boolean)
64
+ .join(" ");
65
+ }
66
+ }
67
+
68
+ return { ...slotProps, ...overrideProps };
69
+ }
@@ -0,0 +1,98 @@
1
+ import { render, screen, fireEvent } from "@testing-library/react";
2
+ import React from "react";
3
+ import { Button } from "../../button";
4
+ import { Slot } from "../Slot";
5
+
6
+ describe("Slot", () => {
7
+ describe("should handle forwarning events", () => {
8
+ test("Should call onClick when event is on Slot", async () => {
9
+ const handleClick = jest.fn();
10
+ render(
11
+ <Slot onClick={handleClick}>
12
+ <Button>Button</Button>
13
+ </Slot>
14
+ );
15
+ fireEvent.click(screen.getByRole("button"));
16
+ expect(handleClick).toHaveBeenCalledTimes(1);
17
+ });
18
+
19
+ test("Should call onClick when event is on Child", async () => {
20
+ const handleClick = jest.fn();
21
+ render(
22
+ <Slot>
23
+ <Button onClick={handleClick}>Button</Button>
24
+ </Slot>
25
+ );
26
+ fireEvent.click(screen.getByRole("button"));
27
+ expect(handleClick).toHaveBeenCalledTimes(1);
28
+ });
29
+
30
+ test("Should call onClick when event is on Child and Slot", async () => {
31
+ const handleClickSlot = jest.fn();
32
+ const handleClick = jest.fn();
33
+ render(
34
+ <Slot onClick={handleClickSlot}>
35
+ <Button onClick={handleClick}>Button</Button>
36
+ </Slot>
37
+ );
38
+ fireEvent.click(screen.getByRole("button"));
39
+ expect(handleClickSlot).toHaveBeenCalledTimes(1);
40
+ expect(handleClick).toHaveBeenCalledTimes(1);
41
+ });
42
+
43
+ test("Should call onClick when event is on Child and undefined on Slot", async () => {
44
+ const handleClick = jest.fn();
45
+ render(
46
+ <Slot onClick={undefined}>
47
+ <Button onClick={handleClick}>Button</Button>
48
+ </Slot>
49
+ );
50
+ fireEvent.click(screen.getByRole("button"));
51
+ expect(handleClick).toHaveBeenCalledTimes(1);
52
+ });
53
+
54
+ test("Should call onClick when event is on Slot and undefined on Child", async () => {
55
+ const handleClick = jest.fn();
56
+ render(
57
+ <Slot onClick={handleClick}>
58
+ <Button onClick={undefined}>Button</Button>
59
+ </Slot>
60
+ );
61
+ fireEvent.click(screen.getByRole("button"));
62
+ expect(handleClick).toHaveBeenCalledTimes(1);
63
+ });
64
+ });
65
+
66
+ describe("should handle className", () => {
67
+ test("Should merge className correctly when Child and Slot has className", async () => {
68
+ render(
69
+ <Slot className="class1">
70
+ <button className="class2 class2--inline">Button</button>
71
+ </Slot>
72
+ );
73
+ expect(screen.getByRole("button").className).toEqual(
74
+ "class1 class2 class2--inline"
75
+ );
76
+ });
77
+
78
+ test("Should merge className correctly when Child has className and Slot has undefined className", async () => {
79
+ render(
80
+ <Slot className={undefined}>
81
+ <button className="class2 class2--inline">Button</button>
82
+ </Slot>
83
+ );
84
+ expect(screen.getByRole("button").className).toEqual(
85
+ "class2 class2--inline"
86
+ );
87
+ });
88
+
89
+ test("Should merge className correctly when Slot has className and Child has undefined className", async () => {
90
+ render(
91
+ <Slot className="class1">
92
+ <button className={undefined}>Button</button>
93
+ </Slot>
94
+ );
95
+ expect(screen.getByRole("button").className).toEqual("class1");
96
+ });
97
+ });
98
+ });
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  // https://github.com/gregberge/react-merge-refs
3
- export default function mergeRefs<T = any>(
3
+ export default function mergeRefs<T>(
4
4
  refs: Array<React.MutableRefObject<T> | React.LegacyRef<T>>
5
5
  ): React.RefCallback<T> {
6
6
  return (value) => {
package/src/util/useId.ts CHANGED
@@ -18,10 +18,8 @@ function useGlobalId(idOverride?: string): string | undefined {
18
18
  return id;
19
19
  }
20
20
 
21
- // eslint-disable-next-line no-useless-concat -- Workaround for https://github.com/webpack/webpack/issues/14814
22
21
  const maybeReactUseId: undefined | (() => string) = (React as any)[
23
- // eslint-disable-next-line no-useless-concat
24
- "useId" + ""
22
+ "useId" + "" // Workaround for https://github.com/webpack/webpack/issues/14814
25
23
  ];
26
24
  /**
27
25
  *
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DatePickerCaption = void 0;
7
- const aksel_icons_1 = require("@navikt/aksel-icons");
8
- const react_1 = __importDefault(require("react"));
9
- const react_day_picker_1 = require("react-day-picker");
10
- const __1 = require("../../..");
11
- const DatePickerCaption = ({ displayMonth, id }) => {
12
- const { goToMonth, nextMonth, previousMonth } = (0, react_day_picker_1.useNavigation)();
13
- const { labels: { labelPrevious, labelNext }, formatters: { formatCaption }, locale, } = (0, react_day_picker_1.useDayPicker)();
14
- const previousLabel = labelPrevious(previousMonth, { locale });
15
- const nextLabel = labelNext(nextMonth, { locale });
16
- return (react_1.default.createElement("div", { className: "navds-date__caption" },
17
- react_1.default.createElement(__1.Label, { as: "span", "aria-live": "polite", "aria-atomic": "true", id: id, className: "navds-date__caption-label" }, formatCaption(displayMonth, { locale })),
18
- react_1.default.createElement("div", { className: "navds-date__caption__month-wrapper" },
19
- react_1.default.createElement(__1.Button, { "aria-label": previousLabel, variant: "tertiary", disabled: !previousMonth, onClick: () => previousMonth && goToMonth(previousMonth), icon: react_1.default.createElement(aksel_icons_1.ArrowLeftIcon, { title: "velg forrige m\u00E5ned" }), className: "navds-date__caption-button", type: "button" }),
20
- react_1.default.createElement(__1.Button, { "aria-label": nextLabel, icon: react_1.default.createElement(aksel_icons_1.ArrowRightIcon, { title: "velg neste m\u00E5ned" }), onClick: () => nextMonth && goToMonth(nextMonth), disabled: !nextMonth, variant: "tertiary", className: "navds-date__caption-button", type: "button" }))));
21
- };
22
- exports.DatePickerCaption = DatePickerCaption;
23
- exports.default = exports.DatePickerCaption;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DropdownCaption = exports.Caption = void 0;
7
- var Caption_1 = require("./Caption");
8
- Object.defineProperty(exports, "Caption", { enumerable: true, get: function () { return __importDefault(Caption_1).default; } });
9
- var DropdownCaption_1 = require("./DropdownCaption");
10
- Object.defineProperty(exports, "DropdownCaption", { enumerable: true, get: function () { return __importDefault(DropdownCaption_1).default; } });
@@ -1,6 +0,0 @@
1
- {
2
- "sideEffects": false,
3
- "main": "./index.js",
4
- "module": "../../../../esm/date/datepicker/caption/index.js",
5
- "types": "../../../../esm/date/datepicker/caption/index.d.ts"
6
- }
@@ -1,3 +0,0 @@
1
- import React from "react";
2
- import { DayProps } from "react-day-picker";
3
- export declare const DayButton: (props: DayProps) => React.JSX.Element;
@@ -1 +0,0 @@
1
- {"version":3,"file":"DayButton.js","sourceRoot":"","sources":["../../../src/date/datepicker/DayButton.tsx"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,MAAM,EAAY,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAe,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;IAClD,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IAC1E,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAAC;IAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAE1D,IAAI,SAAS,CAAC,QAAQ,EAAE;QACtB,OAAO,yCAAK,CAAC;KACd;IACD,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;QACvB,OAAO,6CAAS,SAAS,CAAC,QAAQ,EAAI,CAAC;KACxC;IAED,OAAO,CACL,oBAAC,MAAM,kBACL,IAAI,EAAC,KAAK,EACV,GAAG,EAAE,SAAS,IACV,SAAS,CAAC,WAAW,kBACb,QAAQ,iBACP,SAAS,CAAC,eAAe,CAAC,OAAO,IAC9C,CACH,CAAC;AACJ,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- /// <reference types="react" />
2
- /** Render the table head. */
3
- export declare function TableHead(): JSX.Element;
@@ -1 +0,0 @@
1
- {"version":3,"file":"TableHead.js","sourceRoot":"","sources":["../../../src/date/datepicker/TableHead.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEzD,6BAA6B;AAC7B,MAAM,UAAU,SAAS;;IACvB,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,YAAY,EAAE,CAAC;IAC1D,MAAM,gBAAgB,GAAG,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,mCAAI,OAAO,CAAC;IACxD,OAAO,CACL,+BAAO,KAAK,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,CAAC,IAAI;QACnD,oBAAC,gBAAgB,OAAG,CACd,CACT,CAAC;AACJ,CAAC"}
@@ -1,17 +0,0 @@
1
- import { ArrowLeftIcon, ArrowRightIcon } from "@navikt/aksel-icons";
2
- import React from "react";
3
- import { useDayPicker, useNavigation } from "react-day-picker";
4
- import { Button, Label } from "../../..";
5
- export const DatePickerCaption = ({ displayMonth, id }) => {
6
- const { goToMonth, nextMonth, previousMonth } = useNavigation();
7
- const { labels: { labelPrevious, labelNext }, formatters: { formatCaption }, locale, } = useDayPicker();
8
- const previousLabel = labelPrevious(previousMonth, { locale });
9
- const nextLabel = labelNext(nextMonth, { locale });
10
- return (React.createElement("div", { className: "navds-date__caption" },
11
- React.createElement(Label, { as: "span", "aria-live": "polite", "aria-atomic": "true", id: id, className: "navds-date__caption-label" }, formatCaption(displayMonth, { locale })),
12
- React.createElement("div", { className: "navds-date__caption__month-wrapper" },
13
- React.createElement(Button, { "aria-label": previousLabel, variant: "tertiary", disabled: !previousMonth, onClick: () => previousMonth && goToMonth(previousMonth), icon: React.createElement(ArrowLeftIcon, { title: "velg forrige m\u00E5ned" }), className: "navds-date__caption-button", type: "button" }),
14
- React.createElement(Button, { "aria-label": nextLabel, icon: React.createElement(ArrowRightIcon, { title: "velg neste m\u00E5ned" }), onClick: () => nextMonth && goToMonth(nextMonth), disabled: !nextMonth, variant: "tertiary", className: "navds-date__caption-button", type: "button" }))));
15
- };
16
- export default DatePickerCaption;
17
- //# sourceMappingURL=Caption.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Caption.js","sourceRoot":"","sources":["../../../../src/date/datepicker/caption/Caption.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAgB,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,YAAY,EAAE,EAAE,EAAgB,EAAE,EAAE;IACtE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,aAAa,EAAE,CAAC;IAChE,MAAM,EACJ,MAAM,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,EACpC,UAAU,EAAE,EAAE,aAAa,EAAE,EAC7B,MAAM,GACP,GAAG,YAAY,EAAE,CAAC;IAEnB,MAAM,aAAa,GAAG,aAAa,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAEnD,OAAO,CACL,6BAAK,SAAS,EAAC,qBAAqB;QAClC,oBAAC,KAAK,IACJ,EAAE,EAAC,MAAM,eACC,QAAQ,iBACN,MAAM,EAClB,EAAE,EAAE,EAAE,EACN,SAAS,EAAC,2BAA2B,IAEpC,aAAa,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,CAClC;QAER,6BAAK,SAAS,EAAC,oCAAoC;YACjD,oBAAC,MAAM,kBACO,aAAa,EACzB,OAAO,EAAC,UAAU,EAClB,QAAQ,EAAE,CAAC,aAAa,EACxB,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,IAAI,SAAS,CAAC,aAAa,CAAC,EACxD,IAAI,EAAE,oBAAC,aAAa,IAAC,KAAK,EAAC,yBAAoB,GAAG,EAClD,SAAS,EAAC,4BAA4B,EACtC,IAAI,EAAC,QAAQ,GACb;YACF,oBAAC,MAAM,kBACO,SAAS,EACrB,IAAI,EAAE,oBAAC,cAAc,IAAC,KAAK,EAAC,uBAAkB,GAAG,EACjD,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,IAAI,SAAS,CAAC,SAAS,CAAC,EAChD,QAAQ,EAAE,CAAC,SAAS,EACpB,OAAO,EAAC,UAAU,EAClB,SAAS,EAAC,4BAA4B,EACtC,IAAI,EAAC,QAAQ,GACb,CACE,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -1,38 +0,0 @@
1
- import { ArrowLeftIcon, ArrowRightIcon } from "@navikt/aksel-icons";
2
- import setMonth from "date-fns/setMonth";
3
- import setYear from "date-fns/setYear";
4
- import startOfMonth from "date-fns/startOfMonth";
5
- import React from "react";
6
- import { useDayPicker, useNavigation } from "react-day-picker";
7
- import { Button, Select } from "../../..";
8
- import { getMonths, getYears } from "../../utils/get-dates";
9
- import { labelMonthDropdown, labelYearDropdown } from "../../utils/labels";
10
- import { max, min } from "date-fns";
11
- export const DropdownCaption = ({ displayMonth, id }) => {
12
- const { goToMonth, nextMonth, previousMonth } = useNavigation();
13
- const { fromDate, toDate, formatters: { formatYearCaption, formatMonthCaption, formatCaption }, labels: { labelPrevious, labelNext }, locale, } = useDayPicker();
14
- if (!fromDate || !toDate) {
15
- console.warn("Using dropdownCaption required fromDate and toDate");
16
- return null;
17
- }
18
- const handleYearChange = (e) => {
19
- const newMonth = setYear(startOfMonth(displayMonth), Number(e.target.value));
20
- goToMonth(startOfMonth(min([max([newMonth, fromDate]), toDate])));
21
- };
22
- const handleMonthChange = (e) => goToMonth(setMonth(startOfMonth(displayMonth), Number(e.target.value)));
23
- const years = getYears(fromDate, toDate, displayMonth.getFullYear());
24
- const months = getMonths(fromDate, toDate, displayMonth);
25
- const previousLabel = labelPrevious(previousMonth, { locale });
26
- const nextLabel = labelNext(nextMonth, { locale });
27
- const yearDropdownLabel = labelYearDropdown(locale);
28
- const MonthDropdownLabel = labelMonthDropdown(locale);
29
- return (React.createElement("div", { className: "navds-date__caption-dropdown" },
30
- React.createElement("span", { "aria-live": "polite", "aria-atomic": "true", id: id, className: "navds-sr-only" }, formatCaption(displayMonth, { locale })),
31
- React.createElement(Button, { "aria-label": previousLabel, variant: "tertiary", disabled: !previousMonth, onClick: () => previousMonth && goToMonth(previousMonth), icon: React.createElement(ArrowLeftIcon, { title: "velg forrige m\u00E5ned" }), className: "navds-date__caption-button", type: "button" }),
32
- React.createElement("div", { className: "navds-date__caption__month-wrapper" },
33
- React.createElement(Select, { label: MonthDropdownLabel, hideLabel: true, className: "navds-date__caption__month", value: displayMonth.getMonth(), onChange: handleMonthChange }, months.map((m) => (React.createElement("option", { key: m.getMonth(), value: m.getMonth() }, formatMonthCaption(m, { locale }))))),
34
- React.createElement(Select, { label: yearDropdownLabel, hideLabel: true, value: displayMonth.getFullYear(), onChange: handleYearChange, className: "navds-date__caption__year" }, years.map((year) => (React.createElement("option", { key: year.getFullYear(), value: year.getFullYear() }, formatYearCaption(year, { locale })))))),
35
- React.createElement(Button, { "aria-label": nextLabel, icon: React.createElement(ArrowRightIcon, { title: "velg neste m\u00E5ned" }), onClick: () => nextMonth && goToMonth(nextMonth), disabled: !nextMonth, variant: "tertiary", className: "navds-date__caption-button", type: "button" })));
36
- };
37
- export default DropdownCaption;
38
- //# sourceMappingURL=DropdownCaption.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DropdownCaption.js","sourceRoot":"","sources":["../../../../src/date/datepicker/caption/DropdownCaption.tsx"],"names":[],"mappings":"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"}
@@ -1,2 +0,0 @@
1
- export { default as Caption } from "./Caption";
2
- export { default as DropdownCaption } from "./DropdownCaption";
@@ -1,3 +0,0 @@
1
- export { default as Caption } from "./Caption";
2
- export { default as DropdownCaption } from "./DropdownCaption";
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/date/datepicker/caption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC"}