@lumx/react 3.0.7 → 3.1.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 (517) hide show
  1. package/{CONTRIBUTING.md → dist/CONTRIBUTING.md} +0 -0
  2. package/{LICENSE.md → dist/LICENSE.md} +0 -0
  3. package/dist/README.md +38 -0
  4. package/{_internal → dist/_internal}/ClickAwayProvider.js +0 -0
  5. package/{_internal → dist/_internal}/ClickAwayProvider.js.map +0 -0
  6. package/{_internal → dist/_internal}/types.d.ts +1 -1
  7. package/{index.d.ts → dist/index.d.ts} +67 -8
  8. package/{index.js → dist/index.js} +766 -613
  9. package/dist/index.js.map +1 -0
  10. package/dist/package.json +117 -0
  11. package/dist/src/components/alert-dialog/AlertDialog.stories.tsx +196 -0
  12. package/dist/src/components/alert-dialog/AlertDialog.test.tsx +43 -0
  13. package/dist/src/components/alert-dialog/AlertDialog.tsx +185 -0
  14. package/dist/src/components/alert-dialog/__snapshots__/AlertDialog.test.tsx.snap +551 -0
  15. package/dist/src/components/alert-dialog/index.ts +1 -0
  16. package/dist/src/components/autocomplete/Autocomplete.stories.tsx +70 -0
  17. package/dist/src/components/autocomplete/Autocomplete.test.tsx +181 -0
  18. package/dist/src/components/autocomplete/Autocomplete.tsx +292 -0
  19. package/dist/src/components/autocomplete/AutocompleteMultiple.stories.tsx +170 -0
  20. package/dist/src/components/autocomplete/AutocompleteMultiple.test.tsx +94 -0
  21. package/dist/src/components/autocomplete/AutocompleteMultiple.tsx +156 -0
  22. package/dist/src/components/autocomplete/__mockData__/index.ts +34 -0
  23. package/dist/src/components/autocomplete/__snapshots__/Autocomplete.test.tsx.snap +213 -0
  24. package/dist/src/components/autocomplete/__snapshots__/AutocompleteMultiple.test.tsx.snap +88 -0
  25. package/dist/src/components/autocomplete/index.ts +2 -0
  26. package/dist/src/components/avatar/Avatar.stories.tsx +92 -0
  27. package/dist/src/components/avatar/Avatar.test.tsx +39 -0
  28. package/dist/src/components/avatar/Avatar.tsx +112 -0
  29. package/dist/src/components/avatar/__snapshots__/Avatar.test.tsx.snap +681 -0
  30. package/dist/src/components/avatar/index.ts +1 -0
  31. package/dist/src/components/badge/Badge.stories.tsx +45 -0
  32. package/dist/src/components/badge/Badge.test.tsx +91 -0
  33. package/dist/src/components/badge/Badge.tsx +55 -0
  34. package/dist/src/components/badge/__snapshots__/Badge.test.tsx.snap +11 -0
  35. package/dist/src/components/badge/index.ts +1 -0
  36. package/dist/src/components/button/Button.stories.tsx +156 -0
  37. package/dist/src/components/button/Button.test.tsx +152 -0
  38. package/dist/src/components/button/Button.tsx +81 -0
  39. package/dist/src/components/button/ButtonGroup.test.tsx +66 -0
  40. package/dist/src/components/button/ButtonGroup.tsx +46 -0
  41. package/dist/src/components/button/ButtonRoot.test.tsx +203 -0
  42. package/dist/src/components/button/ButtonRoot.tsx +190 -0
  43. package/dist/src/components/button/IconButton.test.tsx +103 -0
  44. package/dist/src/components/button/IconButton.tsx +80 -0
  45. package/dist/src/components/button/__snapshots__/Button.test.tsx.snap +96 -0
  46. package/dist/src/components/button/__snapshots__/ButtonGroup.test.tsx.snap +22 -0
  47. package/dist/src/components/button/__snapshots__/ButtonRoot.test.tsx.snap +160 -0
  48. package/dist/src/components/button/__snapshots__/IconButton.test.tsx.snap +83 -0
  49. package/dist/src/components/button/index.ts +4 -0
  50. package/dist/src/components/checkbox/Checkbox.stories.tsx +37 -0
  51. package/dist/src/components/checkbox/Checkbox.test.tsx +114 -0
  52. package/dist/src/components/checkbox/Checkbox.tsx +145 -0
  53. package/dist/src/components/checkbox/__snapshots__/Checkbox.test.tsx.snap +141 -0
  54. package/dist/src/components/checkbox/index.ts +1 -0
  55. package/dist/src/components/chip/Chip.stories.tsx +21 -0
  56. package/dist/src/components/chip/Chip.test.tsx +199 -0
  57. package/dist/src/components/chip/Chip.tsx +154 -0
  58. package/dist/src/components/chip/ChipGroup.test.tsx +29 -0
  59. package/dist/src/components/chip/ChipGroup.tsx +62 -0
  60. package/dist/src/components/chip/__snapshots__/Chip.test.tsx.snap +12 -0
  61. package/dist/src/components/chip/__snapshots__/ChipGroup.test.tsx.snap +29 -0
  62. package/dist/src/components/chip/index.ts +2 -0
  63. package/dist/src/components/comment-block/CommentBlock.stories.tsx +30 -0
  64. package/dist/src/components/comment-block/CommentBlock.test.tsx +28 -0
  65. package/dist/src/components/comment-block/CommentBlock.tsx +174 -0
  66. package/dist/src/components/comment-block/__snapshots__/CommentBlock.test.tsx.snap +92 -0
  67. package/dist/src/components/comment-block/index.ts +1 -0
  68. package/dist/src/components/date-picker/DatePicker.test.tsx +41 -0
  69. package/dist/src/components/date-picker/DatePicker.tsx +56 -0
  70. package/dist/src/components/date-picker/DatePickerControlled.test.tsx +44 -0
  71. package/dist/src/components/date-picker/DatePickerControlled.tsx +128 -0
  72. package/dist/src/components/date-picker/DatePickerField.stories.tsx +93 -0
  73. package/dist/src/components/date-picker/DatePickerField.test.tsx +47 -0
  74. package/dist/src/components/date-picker/DatePickerField.tsx +141 -0
  75. package/dist/src/components/date-picker/__snapshots__/DatePicker.test.tsx.snap +22 -0
  76. package/dist/src/components/date-picker/__snapshots__/DatePickerControlled.test.tsx.snap +597 -0
  77. package/dist/src/components/date-picker/__snapshots__/DatePickerField.test.tsx.snap +43 -0
  78. package/dist/src/components/date-picker/constants.ts +11 -0
  79. package/dist/src/components/date-picker/index.ts +4 -0
  80. package/dist/src/components/date-picker/types.ts +28 -0
  81. package/dist/src/components/dialog/Dialog.stories.tsx +426 -0
  82. package/dist/src/components/dialog/Dialog.test.tsx +93 -0
  83. package/dist/src/components/dialog/Dialog.tsx +263 -0
  84. package/dist/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +960 -0
  85. package/dist/src/components/dialog/index.ts +1 -0
  86. package/dist/src/components/divider/Divider.test.tsx +93 -0
  87. package/dist/src/components/divider/Divider.tsx +51 -0
  88. package/dist/src/components/divider/__snapshots__/Divider.test.tsx.snap +9 -0
  89. package/dist/src/components/divider/index.ts +1 -0
  90. package/dist/src/components/drag-handle/DragHandle.tsx +50 -0
  91. package/dist/src/components/drag-handle/index.ts +1 -0
  92. package/dist/src/components/dropdown/Dropdown.stories.tsx +216 -0
  93. package/dist/src/components/dropdown/Dropdown.test.tsx +97 -0
  94. package/dist/src/components/dropdown/Dropdown.tsx +184 -0
  95. package/dist/src/components/dropdown/__snapshots__/Dropdown.test.tsx.snap +35 -0
  96. package/dist/src/components/dropdown/index.ts +1 -0
  97. package/dist/src/components/expansion-panel/ExpansionPanel.test.tsx +116 -0
  98. package/dist/src/components/expansion-panel/ExpansionPanel.tsx +170 -0
  99. package/dist/src/components/expansion-panel/index.ts +1 -0
  100. package/dist/src/components/flag/Flag.stories.tsx +23 -0
  101. package/dist/src/components/flag/Flag.test.tsx +86 -0
  102. package/dist/src/components/flag/Flag.tsx +47 -0
  103. package/dist/src/components/flag/__snapshots__/Flag.test.tsx.snap +133 -0
  104. package/dist/src/components/flag/index.ts +1 -0
  105. package/dist/src/components/flex-box/FlexBox.stories.tsx +245 -0
  106. package/dist/src/components/flex-box/FlexBox.test.tsx +65 -0
  107. package/dist/src/components/flex-box/FlexBox.tsx +98 -0
  108. package/dist/src/components/flex-box/__snapshots__/FlexBox.test.tsx.snap +492 -0
  109. package/dist/src/components/flex-box/index.ts +1 -0
  110. package/dist/src/components/generic-block/GenericBlock.stories.jsx +128 -0
  111. package/dist/src/components/generic-block/GenericBlock.test.tsx +152 -0
  112. package/dist/src/components/generic-block/GenericBlock.tsx +222 -0
  113. package/dist/src/components/generic-block/constants.ts +9 -0
  114. package/dist/src/components/generic-block/index.ts +2 -0
  115. package/dist/src/components/grid/Grid.tsx +73 -0
  116. package/dist/src/components/grid/GridItem.tsx +54 -0
  117. package/dist/src/components/grid/index.ts +2 -0
  118. package/dist/src/components/grid-column/GridColumn.stories.jsx +56 -0
  119. package/dist/src/components/grid-column/GridColumn.test.jsx +58 -0
  120. package/dist/src/components/grid-column/GridColumn.tsx +90 -0
  121. package/dist/src/components/grid-column/index.ts +1 -0
  122. package/dist/src/components/heading/Heading.stories.tsx +108 -0
  123. package/dist/src/components/heading/Heading.test.tsx +82 -0
  124. package/dist/src/components/heading/Heading.tsx +63 -0
  125. package/dist/src/components/heading/HeadingLevelProvider.tsx +30 -0
  126. package/dist/src/components/heading/constants.ts +16 -0
  127. package/dist/src/components/heading/context.tsx +13 -0
  128. package/dist/src/components/heading/index.ts +3 -0
  129. package/dist/src/components/heading/useHeadingLevel.tsx +8 -0
  130. package/dist/src/components/icon/Icon.stories.tsx +76 -0
  131. package/dist/src/components/icon/Icon.test.tsx +102 -0
  132. package/dist/src/components/icon/Icon.tsx +121 -0
  133. package/dist/src/components/icon/__snapshots__/Icon.test.tsx.snap +49 -0
  134. package/dist/src/components/icon/index.ts +1 -0
  135. package/dist/src/components/image-block/ImageBlock.stories.tsx +52 -0
  136. package/dist/src/components/image-block/ImageBlock.test.tsx +28 -0
  137. package/dist/src/components/image-block/ImageBlock.tsx +151 -0
  138. package/dist/src/components/image-block/__snapshots__/ImageBlock.test.tsx.snap +64 -0
  139. package/dist/src/components/image-block/index.ts +1 -0
  140. package/dist/src/components/index.ts +176 -0
  141. package/dist/src/components/inline-list/InlineList.stories.tsx +40 -0
  142. package/dist/src/components/inline-list/InlineList.test.tsx +41 -0
  143. package/dist/src/components/inline-list/InlineList.tsx +82 -0
  144. package/dist/src/components/inline-list/index.ts +1 -0
  145. package/dist/src/components/input-helper/InputHelper.stories.tsx +29 -0
  146. package/dist/src/components/input-helper/InputHelper.test.tsx +107 -0
  147. package/dist/src/components/input-helper/InputHelper.tsx +61 -0
  148. package/dist/src/components/input-helper/__snapshots__/InputHelper.test.tsx.snap +9 -0
  149. package/dist/src/components/input-helper/constants.ts +11 -0
  150. package/dist/src/components/input-helper/index.ts +1 -0
  151. package/dist/src/components/input-label/InputLabel.stories.tsx +15 -0
  152. package/dist/src/components/input-label/InputLabel.test.tsx +86 -0
  153. package/dist/src/components/input-label/InputLabel.tsx +59 -0
  154. package/dist/src/components/input-label/__snapshots__/InputLabel.test.tsx.snap +10 -0
  155. package/dist/src/components/input-label/index.ts +1 -0
  156. package/dist/src/components/lightbox/Lightbox.stories.tsx +83 -0
  157. package/dist/src/components/lightbox/Lightbox.test.tsx +30 -0
  158. package/dist/src/components/lightbox/Lightbox.tsx +153 -0
  159. package/dist/src/components/lightbox/__snapshots__/Lightbox.test.tsx.snap +194 -0
  160. package/dist/src/components/lightbox/index.ts +1 -0
  161. package/dist/src/components/link/Link.stories.tsx +141 -0
  162. package/dist/src/components/link/Link.test.tsx +60 -0
  163. package/dist/src/components/link/Link.tsx +156 -0
  164. package/dist/src/components/link/__snapshots__/Link.test.tsx.snap +29 -0
  165. package/dist/src/components/link/index.ts +1 -0
  166. package/dist/src/components/link-preview/LinkPreview.stories.tsx +88 -0
  167. package/dist/src/components/link-preview/LinkPreview.test.tsx +102 -0
  168. package/dist/src/components/link-preview/LinkPreview.tsx +158 -0
  169. package/dist/src/components/link-preview/index.ts +1 -0
  170. package/dist/src/components/list/List.stories.tsx +141 -0
  171. package/dist/src/components/list/List.test.tsx +29 -0
  172. package/dist/src/components/list/List.tsx +94 -0
  173. package/dist/src/components/list/ListDivider.stories.tsx +7 -0
  174. package/dist/src/components/list/ListDivider.test.tsx +29 -0
  175. package/dist/src/components/list/ListDivider.tsx +42 -0
  176. package/dist/src/components/list/ListItem.stories.tsx +62 -0
  177. package/{src/components/progress/Progress.test.tsx → dist/src/components/list/ListItem.test.tsx} +8 -7
  178. package/dist/src/components/list/ListItem.tsx +154 -0
  179. package/dist/src/components/list/ListSubheader.stories.tsx +8 -0
  180. package/dist/src/components/list/ListSubheader.test.tsx +29 -0
  181. package/dist/src/components/list/ListSubheader.tsx +43 -0
  182. package/dist/src/components/list/__snapshots__/List.test.tsx.snap +360 -0
  183. package/dist/src/components/list/__snapshots__/ListDivider.test.tsx.snap +7 -0
  184. package/dist/src/components/list/__snapshots__/ListItem.test.tsx.snap +160 -0
  185. package/dist/src/components/list/__snapshots__/ListSubheader.test.tsx.snap +9 -0
  186. package/dist/src/components/list/index.ts +4 -0
  187. package/dist/src/components/list/useInteractiveList.tsx +202 -0
  188. package/dist/src/components/message/Message.stories.tsx +27 -0
  189. package/dist/src/components/message/Message.test.tsx +76 -0
  190. package/dist/src/components/message/Message.tsx +74 -0
  191. package/dist/src/components/message/__snapshots__/Message.test.tsx.snap +15 -0
  192. package/dist/src/components/message/index.ts +1 -0
  193. package/dist/src/components/mosaic/Mosaic.stories.tsx +85 -0
  194. package/dist/src/components/mosaic/Mosaic.test.tsx +120 -0
  195. package/dist/src/components/mosaic/Mosaic.tsx +95 -0
  196. package/dist/src/components/mosaic/__snapshots__/Mosaic.test.tsx.snap +357 -0
  197. package/dist/src/components/mosaic/index.ts +1 -0
  198. package/dist/src/components/notification/Notification.test.tsx +108 -0
  199. package/dist/src/components/notification/Notification.tsx +130 -0
  200. package/dist/src/components/notification/Notifications.stories.tsx +77 -0
  201. package/dist/src/components/notification/__snapshots__/Notification.test.tsx.snap +34 -0
  202. package/dist/src/components/notification/constants.ts +28 -0
  203. package/dist/src/components/notification/index.ts +1 -0
  204. package/dist/src/components/popover/Popover.stories.tsx +386 -0
  205. package/dist/src/components/popover/Popover.test.tsx +30 -0
  206. package/dist/src/components/popover/Popover.tsx +382 -0
  207. package/dist/src/components/popover/__snapshots__/Popover.test.tsx.snap +343 -0
  208. package/dist/src/components/popover/index.ts +1 -0
  209. package/dist/src/components/popover-dialog/PopoverDialog.stories.tsx +75 -0
  210. package/dist/src/components/popover-dialog/PopoverDialog.test.tsx +65 -0
  211. package/dist/src/components/popover-dialog/PopoverDialog.tsx +65 -0
  212. package/dist/src/components/popover-dialog/index.tsx +1 -0
  213. package/dist/src/components/post-block/PostBlock.test.tsx +28 -0
  214. package/dist/src/components/post-block/PostBlock.tsx +123 -0
  215. package/dist/src/components/post-block/__snapshots__/PostBlock.test.tsx.snap +139 -0
  216. package/dist/src/components/post-block/index.ts +1 -0
  217. package/dist/src/components/progress/Progress.tsx +68 -0
  218. package/dist/src/components/progress/ProgressCircular.stories.tsx +18 -0
  219. package/dist/src/components/progress/ProgressCircular.test.tsx +49 -0
  220. package/dist/src/components/progress/ProgressCircular.tsx +68 -0
  221. package/dist/src/components/progress/ProgressLinear.stories.tsx +8 -0
  222. package/dist/src/components/progress/ProgressLinear.test.tsx +37 -0
  223. package/dist/src/components/progress/ProgressLinear.tsx +52 -0
  224. package/dist/src/components/progress/index.ts +3 -0
  225. package/dist/src/components/progress-tracker/ProgressTracker.stories.tsx +145 -0
  226. package/dist/src/components/progress-tracker/ProgressTracker.test.tsx +57 -0
  227. package/dist/src/components/progress-tracker/ProgressTracker.tsx +89 -0
  228. package/dist/src/components/progress-tracker/ProgressTrackerProvider.test.tsx +42 -0
  229. package/dist/src/components/progress-tracker/ProgressTrackerProvider.tsx +66 -0
  230. package/dist/src/components/progress-tracker/ProgressTrackerStep.test.tsx +128 -0
  231. package/dist/src/components/progress-tracker/ProgressTrackerStep.tsx +159 -0
  232. package/dist/src/components/progress-tracker/ProgressTrackerStepPanel.test.tsx +73 -0
  233. package/dist/src/components/progress-tracker/ProgressTrackerStepPanel.tsx +67 -0
  234. package/dist/src/components/progress-tracker/__snapshots__/ProgressTracker.test.tsx.snap +41 -0
  235. package/dist/src/components/progress-tracker/__snapshots__/ProgressTrackerStep.test.tsx.snap +141 -0
  236. package/dist/src/components/progress-tracker/__snapshots__/ProgressTrackerStepPanel.test.tsx.snap +25 -0
  237. package/dist/src/components/progress-tracker/index.ts +4 -0
  238. package/dist/src/components/radio-button/RadioButton.stories.tsx +28 -0
  239. package/dist/src/components/radio-button/RadioButton.test.tsx +123 -0
  240. package/dist/src/components/radio-button/RadioButton.tsx +141 -0
  241. package/dist/src/components/radio-button/RadioGroup.stories.tsx +42 -0
  242. package/dist/src/components/radio-button/RadioGroup.test.tsx +77 -0
  243. package/dist/src/components/radio-button/RadioGroup.tsx +52 -0
  244. package/dist/src/components/radio-button/__snapshots__/RadioButton.test.tsx.snap +113 -0
  245. package/dist/src/components/radio-button/__snapshots__/RadioGroup.test.tsx.snap +26 -0
  246. package/dist/src/components/radio-button/index.ts +2 -0
  247. package/dist/src/components/select/Select.stories.tsx +399 -0
  248. package/dist/src/components/select/Select.test.tsx +359 -0
  249. package/dist/src/components/select/Select.tsx +193 -0
  250. package/dist/src/components/select/SelectMultiple.stories.tsx +227 -0
  251. package/dist/src/components/select/SelectMultiple.test.tsx +405 -0
  252. package/dist/src/components/select/SelectMultiple.tsx +198 -0
  253. package/dist/src/components/select/WithSelectContext.tsx +143 -0
  254. package/dist/src/components/select/__snapshots__/Select.test.tsx.snap +43 -0
  255. package/dist/src/components/select/__snapshots__/SelectMultiple.test.tsx.snap +87 -0
  256. package/dist/src/components/select/constants.ts +53 -0
  257. package/dist/src/components/select/index.ts +2 -0
  258. package/dist/src/components/side-navigation/SideNavigation.stories.tsx +191 -0
  259. package/dist/src/components/side-navigation/SideNavigation.test.tsx +52 -0
  260. package/dist/src/components/side-navigation/SideNavigation.tsx +54 -0
  261. package/dist/src/components/side-navigation/SideNavigationItem.test.tsx +175 -0
  262. package/dist/src/components/side-navigation/SideNavigationItem.tsx +162 -0
  263. package/dist/src/components/side-navigation/__snapshots__/SideNavigation.test.tsx.snap +7 -0
  264. package/dist/src/components/side-navigation/__snapshots__/SideNavigationItem.test.tsx.snap +30 -0
  265. package/dist/src/components/side-navigation/index.ts +2 -0
  266. package/dist/src/components/skeleton/SkeletonCircle.stories.tsx +25 -0
  267. package/dist/src/components/skeleton/SkeletonCircle.test.tsx +28 -0
  268. package/dist/src/components/skeleton/SkeletonCircle.tsx +52 -0
  269. package/dist/src/components/skeleton/SkeletonRectangle.stories.tsx +107 -0
  270. package/dist/src/components/skeleton/SkeletonRectangle.test.tsx +28 -0
  271. package/dist/src/components/skeleton/SkeletonRectangle.tsx +78 -0
  272. package/dist/src/components/skeleton/SkeletonTypography.stories.tsx +26 -0
  273. package/dist/src/components/skeleton/SkeletonTypography.test.tsx +28 -0
  274. package/dist/src/components/skeleton/SkeletonTypography.tsx +57 -0
  275. package/dist/src/components/skeleton/__snapshots__/SkeletonCircle.test.tsx.snap +54 -0
  276. package/dist/src/components/skeleton/__snapshots__/SkeletonRectangle.test.tsx.snap +177 -0
  277. package/dist/src/components/skeleton/__snapshots__/SkeletonTypography.test.tsx.snap +174 -0
  278. package/dist/src/components/skeleton/index.ts +3 -0
  279. package/dist/src/components/slider/Slider.stories.tsx +29 -0
  280. package/dist/src/components/slider/Slider.test.tsx +31 -0
  281. package/dist/src/components/slider/Slider.tsx +299 -0
  282. package/dist/src/components/slider/__snapshots__/Slider.test.tsx.snap +122 -0
  283. package/dist/src/components/slider/index.ts +2 -0
  284. package/dist/src/components/slideshow/Slides.tsx +124 -0
  285. package/dist/src/components/slideshow/Slideshow.stories.tsx +212 -0
  286. package/dist/src/components/slideshow/Slideshow.test.tsx +39 -0
  287. package/dist/src/components/slideshow/Slideshow.tsx +170 -0
  288. package/dist/src/components/slideshow/SlideshowControls.stories.tsx +112 -0
  289. package/dist/src/components/slideshow/SlideshowControls.tsx +241 -0
  290. package/dist/src/components/slideshow/SlideshowItem.tsx +52 -0
  291. package/dist/src/components/slideshow/SlideshowItemGroup.tsx +64 -0
  292. package/dist/src/components/slideshow/__snapshots__/Slideshow.test.tsx.snap +157 -0
  293. package/dist/src/components/slideshow/constants.ts +24 -0
  294. package/dist/src/components/slideshow/index.ts +4 -0
  295. package/dist/src/components/slideshow/useKeyNavigate.ts +28 -0
  296. package/dist/src/components/slideshow/usePaginationVisibleRange.ts +37 -0
  297. package/dist/src/components/slideshow/useSlideFocusManagement.tsx +92 -0
  298. package/dist/src/components/slideshow/useSwipeNavigate.ts +18 -0
  299. package/dist/src/components/switch/Switch.stories.tsx +36 -0
  300. package/dist/src/components/switch/Switch.test.tsx +189 -0
  301. package/dist/src/components/switch/Switch.tsx +141 -0
  302. package/dist/src/components/switch/__snapshots__/Switch.test.tsx.snap +179 -0
  303. package/dist/src/components/switch/index.ts +1 -0
  304. package/dist/src/components/table/Table.test.tsx +28 -0
  305. package/dist/src/components/table/Table.tsx +59 -0
  306. package/dist/src/components/table/TableBody.test.tsx +22 -0
  307. package/dist/src/components/table/TableBody.tsx +44 -0
  308. package/dist/src/components/table/TableCell.test.tsx +23 -0
  309. package/dist/src/components/table/TableCell.tsx +125 -0
  310. package/dist/src/components/table/TableHeader.test.tsx +22 -0
  311. package/dist/src/components/table/TableHeader.tsx +50 -0
  312. package/dist/src/components/table/TableRow.test.tsx +22 -0
  313. package/dist/src/components/table/TableRow.tsx +68 -0
  314. package/dist/src/components/table/__snapshots__/Table.test.tsx.snap +263 -0
  315. package/dist/src/components/table/index.ts +5 -0
  316. package/dist/src/components/tabs/Tab.test.tsx +116 -0
  317. package/dist/src/components/tabs/Tab.tsx +120 -0
  318. package/dist/src/components/tabs/TabList.test.tsx +80 -0
  319. package/dist/src/components/tabs/TabList.tsx +82 -0
  320. package/dist/src/components/tabs/TabPanel.test.tsx +74 -0
  321. package/dist/src/components/tabs/TabPanel.tsx +65 -0
  322. package/dist/src/components/tabs/TabProvider.test.tsx +42 -0
  323. package/dist/src/components/tabs/TabProvider.tsx +59 -0
  324. package/dist/src/components/tabs/Tabs.stories.tsx +134 -0
  325. package/dist/src/components/tabs/__snapshots__/Tab.test.tsx.snap +62 -0
  326. package/dist/src/components/tabs/__snapshots__/TabList.test.tsx.snap +22 -0
  327. package/dist/src/components/tabs/__snapshots__/TabPanel.test.tsx.snap +25 -0
  328. package/dist/src/components/tabs/index.ts +4 -0
  329. package/dist/src/components/tabs/state.ts +116 -0
  330. package/dist/src/components/tabs/test.mocks.ts +33 -0
  331. package/dist/src/components/text/Text.stories.jsx +75 -0
  332. package/dist/src/components/text/Text.test.tsx +108 -0
  333. package/dist/src/components/text/Text.tsx +121 -0
  334. package/dist/src/components/text/index.ts +1 -0
  335. package/dist/src/components/text-field/TextField.stories.tsx +169 -0
  336. package/dist/src/components/text-field/TextField.test.tsx +171 -0
  337. package/dist/src/components/text-field/TextField.tsx +432 -0
  338. package/dist/src/components/text-field/__snapshots__/TextField.test.tsx.snap +42 -0
  339. package/dist/src/components/text-field/index.ts +1 -0
  340. package/dist/src/components/thumbnail/Thumbnail.stories.tsx +510 -0
  341. package/dist/src/components/thumbnail/Thumbnail.test.tsx +46 -0
  342. package/dist/src/components/thumbnail/Thumbnail.tsx +222 -0
  343. package/dist/src/components/thumbnail/__snapshots__/Thumbnail.test.tsx.snap +130 -0
  344. package/dist/src/components/thumbnail/index.ts +3 -0
  345. package/dist/src/components/thumbnail/types.ts +39 -0
  346. package/dist/src/components/thumbnail/useFocusPointStyle.test.ts +92 -0
  347. package/dist/src/components/thumbnail/useFocusPointStyle.tsx +111 -0
  348. package/dist/src/components/thumbnail/useImageLoad.ts +40 -0
  349. package/dist/src/components/toolbar/Toolbar.tsx +67 -0
  350. package/dist/src/components/toolbar/index.ts +1 -0
  351. package/dist/src/components/tooltip/Tooltip.stories.tsx +172 -0
  352. package/dist/src/components/tooltip/Tooltip.test.tsx +105 -0
  353. package/dist/src/components/tooltip/Tooltip.tsx +122 -0
  354. package/dist/src/components/tooltip/__snapshots__/Tooltip.test.tsx.snap +233 -0
  355. package/dist/src/components/tooltip/index.ts +1 -0
  356. package/dist/src/components/tooltip/useInjectTooltipRef.tsx +44 -0
  357. package/dist/src/components/tooltip/useTooltipOpen.tsx +113 -0
  358. package/dist/src/components/uploader/Uploader.test.tsx +87 -0
  359. package/dist/src/components/uploader/Uploader.tsx +105 -0
  360. package/dist/src/components/uploader/__snapshots__/Uploader.test.tsx.snap +14 -0
  361. package/dist/src/components/uploader/index.ts +1 -0
  362. package/dist/src/components/user-block/UserBlock.stories.tsx +76 -0
  363. package/dist/src/components/user-block/UserBlock.test.tsx +38 -0
  364. package/dist/src/components/user-block/UserBlock.tsx +179 -0
  365. package/dist/src/components/user-block/__snapshots__/UserBlock.test.tsx.snap +362 -0
  366. package/dist/src/components/user-block/index.ts +1 -0
  367. package/dist/src/constants.ts +17 -0
  368. package/dist/src/hooks/useBooleanState.tsx +13 -0
  369. package/dist/src/hooks/useCallbackOnEscape.ts +34 -0
  370. package/dist/src/hooks/useChipGroupNavigation.tsx +75 -0
  371. package/dist/src/hooks/useClickAway.tsx +47 -0
  372. package/dist/src/hooks/useDisableBodyScroll.ts +28 -0
  373. package/dist/src/hooks/useEventCallback.tsx +17 -0
  374. package/dist/src/hooks/useFocus.tsx +21 -0
  375. package/dist/src/hooks/useFocusTrap.ts +85 -0
  376. package/dist/src/hooks/useFocusWithin.ts +33 -0
  377. package/dist/src/hooks/useInfiniteScroll.tsx +60 -0
  378. package/dist/src/hooks/useIntersectionObserver.tsx +43 -0
  379. package/dist/src/hooks/useInterval.tsx +31 -0
  380. package/dist/src/hooks/useKeyboardListNavigation.tsx +204 -0
  381. package/dist/src/hooks/useListenFocus.tsx +26 -0
  382. package/dist/src/hooks/useOnResize.ts +41 -0
  383. package/dist/src/hooks/useRovingTabIndex.tsx +90 -0
  384. package/dist/src/hooks/useSlideshowControls.ts +243 -0
  385. package/dist/src/hooks/useStopPropagation.ts +21 -0
  386. package/dist/src/hooks/useTransitionVisibility.ts +54 -0
  387. package/dist/src/index.ts +58 -0
  388. package/dist/src/stories/chromaticForceScreenSize.tsx +7 -0
  389. package/dist/src/stories/generated/Autocomplete/Demos.stories.tsx +7 -0
  390. package/dist/src/stories/generated/Avatar/Demos.stories.tsx +7 -0
  391. package/dist/src/stories/generated/Badge/Demos.stories.tsx +9 -0
  392. package/dist/src/stories/generated/Button/Demos.stories.tsx +11 -0
  393. package/dist/src/stories/generated/Checkbox/Demos.stories.tsx +6 -0
  394. package/dist/src/stories/generated/Chip/Demos.stories.tsx +11 -0
  395. package/dist/src/stories/generated/CommentBlock/Demos.stories.tsx +8 -0
  396. package/dist/src/stories/generated/DatePicker/Demos.stories.tsx +8 -0
  397. package/dist/src/stories/generated/Dialog/Demos.stories.tsx +10 -0
  398. package/dist/src/stories/generated/Divider/Demos.stories.tsx +6 -0
  399. package/dist/src/stories/generated/Dropdown/Demos.stories.tsx +8 -0
  400. package/dist/src/stories/generated/ExpansionPanel/Demos.stories.tsx +9 -0
  401. package/dist/src/stories/generated/Flag/Demos.stories.tsx +6 -0
  402. package/dist/src/stories/generated/GenericBlock/Demos.stories.tsx +8 -0
  403. package/dist/src/stories/generated/Heading/Demos.stories.tsx +6 -0
  404. package/dist/src/stories/generated/Icon/Demos.stories.tsx +8 -0
  405. package/dist/src/stories/generated/ImageBlock/Demos.stories.tsx +9 -0
  406. package/dist/src/stories/generated/Lightbox/Demos.stories.tsx +6 -0
  407. package/dist/src/stories/generated/Link/Demos.stories.tsx +8 -0
  408. package/dist/src/stories/generated/LinkPreview/Demos.stories.tsx +7 -0
  409. package/dist/src/stories/generated/List/Demos.stories.tsx +11 -0
  410. package/dist/src/stories/generated/Message/Demos.stories.tsx +10 -0
  411. package/dist/src/stories/generated/Mosaic/Demos.stories.tsx +9 -0
  412. package/dist/src/stories/generated/Notification/Demos.stories.tsx +6 -0
  413. package/dist/src/stories/generated/Popover/Demos.stories.tsx +11 -0
  414. package/dist/src/stories/generated/PopoverDialog/Demos.stories.tsx +6 -0
  415. package/dist/src/stories/generated/PostBlock/Demos.stories.tsx +6 -0
  416. package/dist/src/stories/generated/Progress/Demos.stories.tsx +7 -0
  417. package/dist/src/stories/generated/ProgressTracker/Demos.stories.tsx +9 -0
  418. package/dist/src/stories/generated/RadioButton/Demos.stories.tsx +6 -0
  419. package/dist/src/stories/generated/Select/Demos.stories.tsx +14 -0
  420. package/dist/src/stories/generated/SideNavigation/Demos.stories.tsx +10 -0
  421. package/dist/src/stories/generated/Skeleton/Demos.stories.tsx +9 -0
  422. package/dist/src/stories/generated/Slider/Demos.stories.tsx +9 -0
  423. package/dist/src/stories/generated/Slideshow/Demos.stories.tsx +8 -0
  424. package/dist/src/stories/generated/Switch/Demos.stories.tsx +6 -0
  425. package/dist/src/stories/generated/Table/Demos.stories.tsx +6 -0
  426. package/dist/src/stories/generated/Tabs/Demos.stories.tsx +8 -0
  427. package/dist/src/stories/generated/TextField/Demos.stories.tsx +19 -0
  428. package/dist/src/stories/generated/Thumbnail/Demos.stories.tsx +12 -0
  429. package/dist/src/stories/generated/Toolbar/Demos.stories.tsx +10 -0
  430. package/dist/src/stories/generated/Tooltip/Demos.stories.tsx +8 -0
  431. package/dist/src/stories/generated/Uploader/Demos.stories.tsx +8 -0
  432. package/dist/src/stories/generated/UserBlock/Demos.stories.tsx +10 -0
  433. package/dist/src/stories/knobs/buttonKnob.ts +9 -0
  434. package/dist/src/stories/knobs/emphasisKnob.ts +8 -0
  435. package/dist/src/stories/knobs/enumKnob.ts +14 -0
  436. package/dist/src/stories/knobs/focusKnob.ts +3 -0
  437. package/dist/src/stories/knobs/image.ts +69 -0
  438. package/dist/src/stories/knobs/lorem.ts +59 -0
  439. package/dist/src/stories/knobs/sizeKnob.ts +5 -0
  440. package/dist/src/stories/knobs/thumbnailsKnob.ts +9 -0
  441. package/dist/src/stories/utils/CustomLink.tsx +7 -0
  442. package/dist/src/stories/withResizableBox.tsx +18 -0
  443. package/dist/src/testing/utils/commonTestsSuite.ts +71 -0
  444. package/dist/src/testing/utils/commonTestsSuiteRTL.ts +55 -0
  445. package/dist/src/testing/utils/index.ts +4 -0
  446. package/dist/src/testing/utils/itShouldRenderStories.tsx +103 -0
  447. package/dist/src/testing/utils/queries.ts +19 -0
  448. package/dist/src/untypped-modules.d.ts +7 -0
  449. package/dist/src/utils/ClickAwayProvider/ClickAwayProvider.stories.jsx +58 -0
  450. package/dist/src/utils/ClickAwayProvider/ClickAwayProvider.tsx +65 -0
  451. package/dist/src/utils/ClickAwayProvider/index.ts +1 -0
  452. package/dist/src/utils/MaterialThemeSwitcher/MaterialThemeSwitcher.tsx +54 -0
  453. package/dist/src/utils/MaterialThemeSwitcher/index.ts +1 -0
  454. package/dist/src/utils/browserDoesNotSupportHover.test.js +24 -0
  455. package/dist/src/utils/browserDoesNotSupportHover.ts +2 -0
  456. package/dist/src/utils/clamp.ts +17 -0
  457. package/dist/src/utils/className.ts +44 -0
  458. package/dist/src/utils/event.ts +1 -0
  459. package/dist/src/utils/flattenChildren.test.tsx +58 -0
  460. package/dist/src/utils/flattenChildren.ts +27 -0
  461. package/dist/src/utils/focus/constants.ts +5 -0
  462. package/dist/src/utils/focus/getFirstAndLastFocusable.test.ts +134 -0
  463. package/dist/src/utils/focus/getFirstAndLastFocusable.ts +21 -0
  464. package/dist/src/utils/focus/getFocusableElements.test.ts +151 -0
  465. package/dist/src/utils/focus/getFocusableElements.ts +7 -0
  466. package/dist/src/utils/index.ts +5 -0
  467. package/dist/src/utils/isInternetExplorer.ts +15 -0
  468. package/dist/src/utils/makeListenerTowerContext.ts +32 -0
  469. package/dist/src/utils/mergeRefs.ts +22 -0
  470. package/dist/src/utils/partitionMulti.ts +28 -0
  471. package/dist/src/utils/renderLink.tsx +17 -0
  472. package/dist/src/utils/type.ts +113 -0
  473. package/dist/src/utils/userHasReducedMotion.ts +7 -0
  474. package/dist/src/utils/utils.test.ts +48 -0
  475. package/{utils → dist/utils}/index.d.ts +0 -0
  476. package/{utils → dist/utils}/index.js +0 -0
  477. package/{utils → dist/utils}/index.js.map +0 -0
  478. package/jest/__mocks__/@storybook/addon-actions.js +3 -0
  479. package/jest/__mocks__/@storybook/addon-knobs.js +6 -0
  480. package/jest/__mocks__/emptyFileMockTransformer.js +8 -0
  481. package/jest/__mocks__/emptyModuleMock.js +1 -0
  482. package/jest/configure.js +6 -0
  483. package/jest/index.js +36 -0
  484. package/jest/transform.js +6 -0
  485. package/package.json +3 -5
  486. package/rollup.config.js +98 -0
  487. package/src/components/badge/Badge.tsx +2 -2
  488. package/src/components/button/ButtonRoot.tsx +2 -2
  489. package/src/components/chip/Chip.tsx +2 -2
  490. package/src/components/grid-column/GridColumn.stories.jsx +56 -0
  491. package/src/components/grid-column/GridColumn.test.jsx +58 -0
  492. package/src/components/grid-column/GridColumn.tsx +90 -0
  493. package/src/components/grid-column/index.ts +1 -0
  494. package/src/components/icon/Icon.tsx +2 -2
  495. package/src/components/link/Link.tsx +2 -2
  496. package/src/components/progress/Progress.tsx +6 -25
  497. package/src/components/progress/ProgressCircular.stories.tsx +18 -0
  498. package/src/components/progress/ProgressCircular.test.tsx +49 -0
  499. package/src/components/progress/ProgressCircular.tsx +68 -0
  500. package/src/components/progress/ProgressLinear.stories.tsx +8 -0
  501. package/src/components/progress/ProgressLinear.test.tsx +37 -0
  502. package/src/components/progress/ProgressLinear.tsx +52 -0
  503. package/src/components/progress/index.ts +2 -0
  504. package/src/index.ts +1 -0
  505. package/storybook/build +4 -0
  506. package/storybook/generate-demo-stories.js +59 -0
  507. package/storybook/main.js +67 -0
  508. package/storybook/package.json +13 -0
  509. package/storybook/preview.js +11 -0
  510. package/storybook/start +4 -0
  511. package/storybook/story-block/StoryBlock.tsx +49 -0
  512. package/storybook/story-block/decorator.jsx +7 -0
  513. package/storybook/story-block/index.scss +27 -0
  514. package/storybook/yarn.lock +13192 -0
  515. package/tsconfig.json +3 -0
  516. package/index.js.map +0 -1
  517. package/src/components/progress/__snapshots__/Progress.test.tsx.snap +0 -48
@@ -0,0 +1,85 @@
1
+ import { useEffect } from 'react';
2
+
3
+ import { DOCUMENT } from '@lumx/react/constants';
4
+ import { getFirstAndLastFocusable } from '@lumx/react/utils/focus/getFirstAndLastFocusable';
5
+ import { Falsy } from '@lumx/react/utils/type';
6
+ import { Listener, makeListenerTowerContext } from '@lumx/react/utils/makeListenerTowerContext';
7
+
8
+ const FOCUS_TRAPS = makeListenerTowerContext();
9
+
10
+ /**
11
+ * Trap 'Tab' focus switch inside the `focusZoneElement`.
12
+ *
13
+ * If multiple focus trap are activated, only the last one is maintained and when a focus trap closes, the previous one
14
+ * gets activated again.
15
+ *
16
+ * @param focusZoneElement The element in which to trap the focus.
17
+ * @param focusElement The element to focus when the focus trap is activated (otherwise the first focusable element
18
+ * will be focused).
19
+ */
20
+ export function useFocusTrap(focusZoneElement: HTMLElement | Falsy, focusElement?: HTMLElement | null): void {
21
+ useEffect(() => {
22
+ // Body element can be undefined in SSR context.
23
+ const rootElement = DOCUMENT?.body;
24
+
25
+ if (!rootElement || !focusZoneElement) {
26
+ return undefined;
27
+ }
28
+
29
+ // Trap 'Tab' key down focus switch into the focus zone.
30
+ const trapTabFocusInFocusZone = (evt: KeyboardEvent) => {
31
+ const { key } = evt;
32
+ if (key !== 'Tab') {
33
+ return;
34
+ }
35
+ const focusable = getFirstAndLastFocusable(focusZoneElement);
36
+
37
+ // Prevent focus switch if no focusable available.
38
+ if (!focusable.first) {
39
+ evt.preventDefault();
40
+ return;
41
+ }
42
+
43
+ if (
44
+ // No previous focus
45
+ !document.activeElement ||
46
+ // Previous focus is at the end of the focus zone.
47
+ (!evt.shiftKey && document.activeElement === focusable.last) ||
48
+ // Previous focus is outside the focus zone
49
+ !focusZoneElement.contains(document.activeElement)
50
+ ) {
51
+ focusable.first.focus();
52
+ evt.preventDefault();
53
+ return;
54
+ }
55
+
56
+ if (
57
+ // Focus order reversed
58
+ evt.shiftKey &&
59
+ // Previous focus is at the start of the focus zone.
60
+ document.activeElement === focusable.first
61
+ ) {
62
+ focusable.last.focus();
63
+ evt.preventDefault();
64
+ }
65
+ };
66
+
67
+ const focusTrap: Listener = {
68
+ enable: () => rootElement.addEventListener('keydown', trapTabFocusInFocusZone),
69
+ disable: () => rootElement.removeEventListener('keydown', trapTabFocusInFocusZone),
70
+ };
71
+
72
+ // SETUP:
73
+ if (focusElement && focusZoneElement.contains(focusElement)) {
74
+ // Focus the given element.
75
+ focusElement.focus();
76
+ } else {
77
+ // Focus the first focusable element in the zone.
78
+ getFirstAndLastFocusable(focusZoneElement).first?.focus();
79
+ }
80
+ FOCUS_TRAPS.register(focusTrap);
81
+
82
+ // TEARDOWN:
83
+ return () => FOCUS_TRAPS.unregister(focusTrap);
84
+ }, [focusElement, focusZoneElement]);
85
+ }
@@ -0,0 +1,33 @@
1
+ import { useEffect } from 'react';
2
+
3
+ export interface UseFocusWithinOptions {
4
+ /** element to add the focus within to */
5
+ element: HTMLElement | null;
6
+ /** callback to be executed on focus in */
7
+ onFocusIn: (ev: FocusEvent) => void;
8
+ /** callback to be executed on focus out */
9
+ onFocusOut: (ev: FocusEvent) => void;
10
+ }
11
+
12
+ /**
13
+ * Hook that allows to control when there is a focus event within a given element, meaning
14
+ * that any element within the given target will trigger the focus in and focus out events.
15
+ * @param options - UseFocusWithinOptions
16
+ */
17
+ export const useFocusWithin = ({ element, onFocusIn, onFocusOut }: UseFocusWithinOptions) => {
18
+ useEffect(() => {
19
+ if (element) {
20
+ element.addEventListener('focusin', onFocusIn);
21
+
22
+ element.addEventListener('focusout', onFocusOut);
23
+ }
24
+
25
+ return () => {
26
+ if (element) {
27
+ element.removeEventListener('focusin', onFocusIn);
28
+
29
+ element.removeEventListener('focusout', onFocusOut);
30
+ }
31
+ };
32
+ }, [onFocusIn, element, onFocusOut]);
33
+ };
@@ -0,0 +1,60 @@
1
+ import React, { useEffect } from 'react';
2
+
3
+ type useInfiniteScrollType = (
4
+ ref: React.RefObject<HTMLElement>,
5
+ callback?: EventCallback,
6
+ callbackOnMount?: boolean,
7
+ ) => void;
8
+ type EventCallback = (evt?: Event) => void;
9
+
10
+ // The error margin in px we want to have for triggering infinite scroll
11
+ const SCROLL_TRIGGER_MARGIN = 5;
12
+
13
+ /**
14
+ * Listen to clicks away from a given element and callback the passed in function.
15
+ *
16
+ * @param ref A reference to the element on which you want to listen scroll event.
17
+ * @param [callback] A callback function to call when the bottom of the reference element is reached.
18
+ * @param [callbackOnMount] A callback function to call when the component is mounted.
19
+ */
20
+ export const useInfiniteScroll: useInfiniteScrollType = (
21
+ ref,
22
+ callback,
23
+ callbackOnMount = false,
24
+ scrollTriggerMargin = SCROLL_TRIGGER_MARGIN,
25
+ ) => {
26
+ useEffect(() => {
27
+ const { current } = ref;
28
+ if (!callback || !current) {
29
+ return undefined;
30
+ }
31
+
32
+ const isAtBottom = () =>
33
+ Boolean(
34
+ current && current.scrollHeight - (current.scrollTop + current.clientHeight) <= scrollTriggerMargin,
35
+ );
36
+
37
+ const onScroll = (e?: Event): void => {
38
+ if (isAtBottom()) {
39
+ callback(e);
40
+ }
41
+ };
42
+
43
+ if (isAtBottom()) {
44
+ onScroll();
45
+ }
46
+
47
+ current.addEventListener('scroll', onScroll);
48
+ current.addEventListener('resize', onScroll);
49
+ return () => {
50
+ current.removeEventListener('scroll', onScroll);
51
+ current.removeEventListener('resize', onScroll);
52
+ };
53
+ }, [ref, callback, scrollTriggerMargin]);
54
+
55
+ useEffect(() => {
56
+ if (callback && callbackOnMount) {
57
+ callback();
58
+ }
59
+ }, [callback, callbackOnMount]);
60
+ };
@@ -0,0 +1,43 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ export type Intersections<T> = Map<T, IntersectionObserverEntry>;
4
+
5
+ /**
6
+ * Convenient hook to create interaction observers.
7
+ *
8
+ * @param elements Elements to observe.
9
+ * @param options IntersectionObserver options.
10
+ * @return Map of intersections.
11
+ */
12
+ export function useIntersectionObserver<T extends Element>(
13
+ elements: Array<T | null | undefined>,
14
+ options?: IntersectionObserverInit,
15
+ ): Intersections<T> {
16
+ const [intersections, setIntersections] = useState<Intersections<T>>(() => new Map());
17
+
18
+ useEffect(
19
+ () => {
20
+ if (elements.length < 1 || !elements.some(Boolean)) {
21
+ return undefined;
22
+ }
23
+
24
+ const observer = new IntersectionObserver((entries) => {
25
+ for (const entry of entries) {
26
+ intersections.set(entry.target as T, entry);
27
+ }
28
+ setIntersections(new Map(intersections));
29
+ }, options);
30
+
31
+ for (const element of elements) {
32
+ if (element) {
33
+ observer.observe(element);
34
+ }
35
+ }
36
+ return () => observer.disconnect();
37
+ },
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ [...elements],
40
+ );
41
+
42
+ return intersections;
43
+ }
@@ -0,0 +1,31 @@
1
+ import { useEffect, useRef } from 'react';
2
+
3
+ import isFunction from 'lodash/isFunction';
4
+ import { Callback } from '@lumx/react/utils/type';
5
+
6
+ /**
7
+ * Making setInterval Declarative with React Hooks.
8
+ * Credits: https://overreacted.io/making-setinterval-declarative-with-react-hooks/
9
+ *
10
+ * @param callback Function called by setInterval.
11
+ * @param delay Delay for setInterval.
12
+ */
13
+ export function useInterval(callback: Callback, delay: number | null): void {
14
+ const savedCallback = useRef<Callback>();
15
+
16
+ useEffect(() => {
17
+ savedCallback.current = callback;
18
+ });
19
+
20
+ useEffect(() => {
21
+ if (delay === null) return undefined;
22
+
23
+ function tick() {
24
+ if (isFunction(savedCallback.current)) {
25
+ savedCallback.current();
26
+ }
27
+ }
28
+ const id = setInterval(tick, delay);
29
+ return () => clearInterval(id);
30
+ }, [delay]);
31
+ }
@@ -0,0 +1,204 @@
1
+ import { RefObject, SetStateAction, useEffect, useState } from 'react';
2
+
3
+ import get from 'lodash/get';
4
+
5
+ type Listener = (evt: KeyboardEvent) => void;
6
+
7
+ interface UseKeyboardListNavigationType {
8
+ /** the current active index */
9
+ activeItemIndex: number;
10
+ /** callback to be used when a key is pressed. usually used with the native prop `onKeyDown` */
11
+ onKeyboardNavigation: Listener;
12
+ /** Resets the active index to the initial state */
13
+ resetActiveIndex(): void;
14
+ /** Sets the active index to a given value */
15
+ setActiveItemIndex(value: SetStateAction<number>): void;
16
+ }
17
+
18
+ export type useKeyboardListNavigationType = <I>(
19
+ items: I[],
20
+ ref: RefObject<HTMLElement>,
21
+ onListItemSelected: (itemSelected: I) => void,
22
+ onListItemNavigated?: (itemSelected: I) => void,
23
+ onEnterPressed?: (itemSelected: string) => void,
24
+ onBackspacePressed?: Listener,
25
+ keepFocusAfterSelection?: boolean,
26
+ initialIndex?: number,
27
+ preventTabOnEnteredValue?: boolean,
28
+ ) => UseKeyboardListNavigationType;
29
+
30
+ const INITIAL_INDEX = -1;
31
+
32
+ /**
33
+ * This custom hook provides the necessary set of functions and values to properly navigate
34
+ * a list using the keyboard.
35
+ *
36
+ * @param items the list of items that will be navigated using the keyboard.
37
+ * @param ref A reference to the element that is controlling the navigation.
38
+ * @param onListItemSelected callback to be executed when the ENTER key is pressed on an item.
39
+ * @param onListItemNavigated callback to be executed when the Arrow keys are pressed.
40
+ * @param onEnterPressed callback to be executed when the ENTER key is pressed.
41
+ * @param onBackspacePressed callback to be executed when the BACKSPACE key is pressed.
42
+ * @param keepFocusAfterSelection determines whether after selecting an item, the focus should be maintained on the current target or not.
43
+ * @param initialIndex where should the navigation start from. it defaults to `-1`, so the first item navigated is the item on position `0`.
44
+ * @param preventTabOnEnteredValue determines whether upon TAB, if there is a value entered, the event is prevented or not.
45
+ * @return useKeyboardListNavigation helpers.
46
+ */
47
+ export const useKeyboardListNavigation: useKeyboardListNavigationType = (
48
+ items,
49
+ ref,
50
+ onListItemSelected,
51
+ onListItemNavigated,
52
+ onEnterPressed,
53
+ onBackspacePressed,
54
+ keepFocusAfterSelection = false,
55
+ initialIndex = INITIAL_INDEX,
56
+ preventTabOnEnteredValue = true,
57
+ ) => {
58
+ const [activeItemIndex, setActiveItemIndex] = useState(initialIndex);
59
+
60
+ /**
61
+ * This function calculates the next index in the list to be highlighted
62
+ * @param key - key code pressed
63
+ * @return next active index
64
+ */
65
+ const calculateActiveIndex = (key: string): number => {
66
+ switch (key) {
67
+ case 'ArrowDown':
68
+ return activeItemIndex + 1 < items.length ? activeItemIndex + 1 : 0;
69
+ case 'ArrowUp':
70
+ return activeItemIndex - 1 >= 0 ? activeItemIndex - 1 : items.length - 1;
71
+ default:
72
+ return initialIndex;
73
+ }
74
+ };
75
+
76
+ /**
77
+ * Resets the active index to the initial state
78
+ */
79
+ const resetActiveIndex = () => {
80
+ setActiveItemIndex(initialIndex);
81
+ };
82
+
83
+ /**
84
+ * Prevents the default event and stops the propagation of said event
85
+ * @param evt - key pressed event
86
+ */
87
+ const preventDefaultAndStopPropagation: Listener = (evt) => {
88
+ evt.preventDefault();
89
+ evt.stopPropagation();
90
+ };
91
+
92
+ /**
93
+ * Handles navigation with the arrows using the keyboard
94
+ * @param evt - key pressed event
95
+ */
96
+ const onArrowPressed: Listener = (evt) => {
97
+ const { key } = evt;
98
+ const nextActiveIndex = calculateActiveIndex(key);
99
+ setActiveItemIndex(nextActiveIndex);
100
+ preventDefaultAndStopPropagation(evt);
101
+ if (onListItemNavigated) {
102
+ const selectedItem = items[nextActiveIndex];
103
+ onListItemNavigated(selectedItem);
104
+ }
105
+ };
106
+
107
+ /**
108
+ * Handles the event when the backspace key is pressed
109
+ * @param evt - key pressed event
110
+ */
111
+ const onBackspaceKeyPressed: Listener = (evt) => {
112
+ if (onBackspacePressed) {
113
+ onBackspacePressed(evt);
114
+ }
115
+ };
116
+
117
+ /**
118
+ * Handles when the ENTER key is pressed
119
+ * @param evt - key pressed event
120
+ */
121
+ const onEnterKeyPressed: Listener = (evt) => {
122
+ if (!onListItemSelected) {
123
+ return;
124
+ }
125
+
126
+ preventDefaultAndStopPropagation(evt);
127
+
128
+ if (!keepFocusAfterSelection) {
129
+ (evt.currentTarget as HTMLElement).blur();
130
+ }
131
+
132
+ const selectedItem = items[activeItemIndex];
133
+
134
+ if (selectedItem) {
135
+ onListItemSelected(selectedItem);
136
+ resetActiveIndex();
137
+ } else if (activeItemIndex === initialIndex && onEnterPressed) {
138
+ const value = get(evt, 'target.value');
139
+ onEnterPressed(value);
140
+ resetActiveIndex();
141
+ }
142
+ };
143
+
144
+ /**
145
+ * Handles when the TAB key is pressed
146
+ * @param evt - key pressed event
147
+ */
148
+ const onTabKeyPressed: Listener = (evt) => {
149
+ const value = get(evt, 'target.value');
150
+
151
+ if (preventTabOnEnteredValue && value && value.length > 0) {
152
+ preventDefaultAndStopPropagation(evt);
153
+ }
154
+ };
155
+
156
+ /**
157
+ * In order to make it easier in the future to add new events depending on the key
158
+ * a map was created to add these handlers. In the future, if there is another event
159
+ * that we need to manage depending on a specific key, we just need to add the key code
160
+ * here, and as a value, the handler for said key.
161
+ */
162
+ const eventsForKeyPressed: Record<string, Listener> = {
163
+ ArrowDown: onArrowPressed,
164
+ Tab: onTabKeyPressed,
165
+ ArrowUp: onArrowPressed,
166
+ Enter: onEnterKeyPressed,
167
+ Backspace: onBackspaceKeyPressed,
168
+ };
169
+
170
+ /**
171
+ * Calculates the next active item index depending on the key pressed.
172
+ * If the key pressed was ENTER, the function executes the callback `onListItemSelected`
173
+ * and resets the active index, since an item was selected.
174
+ * @param evt - key pressed or key down event
175
+ */
176
+ const onKeyboardNavigation: Listener = (evt) => {
177
+ const { key } = evt;
178
+ const handler = eventsForKeyPressed[key];
179
+
180
+ if (handler) {
181
+ handler(evt);
182
+ }
183
+ };
184
+
185
+ useEffect(() => {
186
+ const { current: currentElement } = ref;
187
+ if (!currentElement) {
188
+ return undefined;
189
+ }
190
+ currentElement.addEventListener('focus', resetActiveIndex);
191
+ currentElement.addEventListener('keydown', onKeyboardNavigation);
192
+ return () => {
193
+ currentElement.removeEventListener('focus', resetActiveIndex);
194
+ currentElement.removeEventListener('keydown', onKeyboardNavigation);
195
+ };
196
+ });
197
+
198
+ return {
199
+ activeItemIndex,
200
+ onKeyboardNavigation,
201
+ resetActiveIndex,
202
+ setActiveItemIndex,
203
+ };
204
+ };
@@ -0,0 +1,26 @@
1
+ import { RefObject, useEffect, useState } from 'react';
2
+
3
+ /**
4
+ * Listen on element focus to store the focus status.
5
+ */
6
+ export function useListenFocus(ref: RefObject<HTMLElement>) {
7
+ const [isFocus, setFocus] = useState(false);
8
+
9
+ useEffect(() => {
10
+ const { current: element } = ref;
11
+ if (!element) {
12
+ return undefined;
13
+ }
14
+
15
+ const onFocus = () => setFocus(true);
16
+ const onBlur = () => setFocus(false);
17
+ element.addEventListener('focus', onFocus);
18
+ element.addEventListener('blur', onBlur);
19
+ return () => {
20
+ element.removeEventListener('focus', onFocus);
21
+ element.removeEventListener('blur', onBlur);
22
+ };
23
+ }, [ref, setFocus]);
24
+
25
+ return isFocus;
26
+ }
@@ -0,0 +1,41 @@
1
+ import { Callback, Falsy } from '@lumx/react/utils/type';
2
+ import { MutableRefObject, RefObject, useEffect, useRef } from 'react';
3
+ import { WINDOW } from '@lumx/react/constants';
4
+ import { ResizeObserver as Polyfill } from '@juggle/resize-observer';
5
+
6
+ const ResizeObserver: typeof Polyfill = (WINDOW as any)?.ResizeObserver || Polyfill;
7
+
8
+ export function useOnResize(element: HTMLElement | Falsy, update: RefObject<Callback>): void {
9
+ const observerRef = useRef(null) as MutableRefObject<Polyfill | null>;
10
+ const previousSize = useRef<{ width: number; height: number }>();
11
+
12
+ useEffect(() => {
13
+ if (!element || !update) {
14
+ return undefined;
15
+ }
16
+
17
+ previousSize.current = undefined;
18
+ const observer =
19
+ observerRef.current ||
20
+ new ResizeObserver(([entry]) => {
21
+ const updateFunction = update.current;
22
+ if (!updateFunction) {
23
+ return;
24
+ }
25
+
26
+ const { width, height } = entry.contentRect;
27
+ if (previousSize.current?.width === width && previousSize.current?.height === height) {
28
+ return;
29
+ }
30
+
31
+ window.requestAnimationFrame(() => updateFunction());
32
+ previousSize.current = entry.contentRect;
33
+ });
34
+ if (!observerRef.current) observerRef.current = observer;
35
+
36
+ observer.observe(element);
37
+ return () => {
38
+ observer.unobserve(element);
39
+ };
40
+ }, [element, update]);
41
+ }
@@ -0,0 +1,90 @@
1
+ import { RefObject, useEffect } from 'react';
2
+
3
+ interface UseRovingTabIndexOptions {
4
+ parentRef: RefObject<HTMLElement>;
5
+ elementSelector: string;
6
+ keepTabIndex?: boolean;
7
+ /** Action to trigger when an element is focused using roving tab index */
8
+ onElementFocus?: (element: HTMLElement) => void;
9
+ /** List of values to be used as extra dependencies of the useEffect */
10
+ extraDependencies?: any[];
11
+ }
12
+
13
+ export const useRovingTabIndex = ({
14
+ parentRef,
15
+ elementSelector,
16
+ keepTabIndex,
17
+ onElementFocus,
18
+ extraDependencies = [],
19
+ }: UseRovingTabIndexOptions): void => {
20
+ useEffect(
21
+ () => {
22
+ const parent = parentRef?.current;
23
+ if (!parent) {
24
+ return undefined;
25
+ }
26
+
27
+ const elements = parent.querySelectorAll(elementSelector) as NodeListOf<HTMLElement>;
28
+ const initialFocusableElement = parent?.querySelector(`${elementSelector}[tabindex="0"]`);
29
+
30
+ const handleKeyDown = (index: number) => (evt: KeyboardEvent) => {
31
+ let newTabFocus = index;
32
+ if (!(evt.key === 'ArrowRight' || evt.key === 'ArrowLeft')) {
33
+ return;
34
+ }
35
+
36
+ if (evt.key === 'ArrowRight') {
37
+ // Move right
38
+ newTabFocus += 1;
39
+ // If we're at the end, go to the start
40
+ if (newTabFocus >= elements.length) {
41
+ newTabFocus = 0;
42
+ }
43
+ } else if (evt.key === 'ArrowLeft') {
44
+ // Move left
45
+ newTabFocus -= 1;
46
+ if (newTabFocus < 0) {
47
+ // If we're at the start, move to the end
48
+ newTabFocus = elements.length - 1;
49
+ }
50
+ }
51
+ const newElement = elements[newTabFocus];
52
+ newElement?.focus();
53
+
54
+ // When an element is focused using roving tab index, trigger the onElementFocus callback
55
+ if (newElement && onElementFocus) {
56
+ onElementFocus(newElement);
57
+ }
58
+
59
+ if (keepTabIndex) {
60
+ (evt.currentTarget as HTMLElement).setAttribute('tabindex', '-1');
61
+ newElement?.setAttribute('tabindex', '0');
62
+ }
63
+ };
64
+
65
+ if (elements?.length > 0) {
66
+ elements.forEach((el, key) => {
67
+ // if no element has tabindex set to 0, set the first element as focusable
68
+ if (!initialFocusableElement && key === 0) {
69
+ el.setAttribute('tabindex', '0');
70
+ // set all other to -1
71
+ } else if (initialFocusableElement !== el) {
72
+ el.setAttribute('tabindex', '-1');
73
+ }
74
+ // add event listener
75
+ el.addEventListener('keydown', handleKeyDown(key) as EventListener);
76
+ });
77
+ }
78
+
79
+ // Cleanup listeners
80
+ return () => {
81
+ if (elements?.length > 0) {
82
+ elements.forEach((el, key) => {
83
+ el.removeEventListener('keydown', handleKeyDown(key) as EventListener);
84
+ });
85
+ }
86
+ };
87
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
88
+ [parentRef, ...extraDependencies],
89
+ );
90
+ };