@react-fabric/core 1.0.0-beta.9 → 1.0.1

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 (592) hide show
  1. package/{src/components/actionLabel/ActionLabel.module.css → css/components/_actionLabel.css} +4 -4
  2. package/{src/overlays/alert/Alert.module.css → css/components/_alert.css} +3 -3
  3. package/css/components/_animations.css +52 -0
  4. package/css/components/_avatar.css +89 -0
  5. package/css/components/_button.css +218 -0
  6. package/css/components/_buttonGroup.css +62 -0
  7. package/css/components/_callout.css +32 -0
  8. package/css/components/_card.css +167 -0
  9. package/css/components/_chip.css +125 -0
  10. package/css/components/_collapsable.css +32 -0
  11. package/{src/overlays/message/Message.module.css → css/components/_divider.css} +11 -10
  12. package/{src/components/dropdown/Dropdown.module.css → css/components/_dropdown.css} +3 -2
  13. package/{src/overlays/flyout/Flyout.module.css → css/components/_flyout.css} +15 -9
  14. package/css/components/_media.css +102 -0
  15. package/{src/components/menu/Menu.module.css → css/components/_menu.css} +21 -20
  16. package/{src/components/meter/Meter.module.css → css/components/_meter.css} +15 -20
  17. package/{src/overlays/modal/Modal.module.css → css/components/_modal.css} +9 -9
  18. package/{src/components/panel/Panel.module.css → css/components/_panel.css} +19 -19
  19. package/{src/components/progress/Progress.module.css → css/components/_progress.css} +7 -10
  20. package/css/components/_sonner.css +431 -0
  21. package/{src/components/tabpanel/TabPanel.module.css → css/components/_tabPanel.css} +125 -85
  22. package/css/components/_titlebar.css +48 -0
  23. package/css/components/index.css +47 -0
  24. package/css/core/_aside.css +176 -0
  25. package/css/core/_content.css +31 -0
  26. package/css/core/_errorboundary.css +55 -0
  27. package/css/core/_responsive.css +45 -0
  28. package/css/core/_typography.css +69 -0
  29. package/css/core/_viewport.css +33 -0
  30. package/{src/hooks/useClientService.tsx → css/core/index.css} +7 -7
  31. package/css/reset/_gradients.css +36 -33
  32. package/css/reset/_reset.css +206 -300
  33. package/css/reset/_text.css +31 -61
  34. package/css/reset/_theme.css +467 -81
  35. package/css/reset/index.css +23 -21
  36. package/css/styles.css +30 -23
  37. package/css/theme/_colors.css +445 -0
  38. package/css/theme/_utilities.css +528 -0
  39. package/css/theme/_variants.css +128 -0
  40. package/css/theme/index.css +55 -0
  41. package/dist/cjs/components/actionLabel/ActionLabel.js +25 -12
  42. package/dist/cjs/{overlays → components}/alert/Alert.js +76 -53
  43. package/dist/cjs/components/animations/Indicator.js +72 -0
  44. package/dist/cjs/components/animations/Loader.js +77 -0
  45. package/dist/cjs/components/animations/LoadingBars.js +37 -0
  46. package/dist/cjs/components/animations/LoadingLine.js +59 -0
  47. package/dist/cjs/components/animations/LoadingSpinner.js +37 -0
  48. package/dist/cjs/components/animations/Skeleton.js +88 -0
  49. package/dist/cjs/components/avatar/Avatar.js +41 -20
  50. package/dist/cjs/components/avatar/AvatarGroup.js +37 -16
  51. package/dist/cjs/components/badge/Badge.js +90 -68
  52. package/dist/cjs/components/button/Button.js +198 -136
  53. package/dist/cjs/components/button/ButtonGroup.js +86 -21
  54. package/dist/cjs/components/button/ConfirmButton.js +55 -41
  55. package/dist/cjs/components/button/ToggleButtonGroup.js +84 -32
  56. package/dist/cjs/components/callout/Callout.js +56 -25
  57. package/dist/cjs/components/card/Card.js +90 -42
  58. package/dist/cjs/components/card/CardCover.js +38 -27
  59. package/dist/cjs/components/card/FlipContent.js +47 -0
  60. package/dist/cjs/components/chip/Chip.js +80 -37
  61. package/dist/cjs/components/collapsable/Collapsable.js +62 -31
  62. package/dist/cjs/components/divider/Divider.js +58 -24
  63. package/dist/cjs/components/dropdown/Dropdown.js +92 -45
  64. package/dist/cjs/components/dropdown/DropdownTool.js +6 -7
  65. package/dist/cjs/components/effect/GlassEffect.js +259 -0
  66. package/dist/cjs/components/effect/MatteEffect.js +127 -0
  67. package/dist/cjs/components/effect/StyleEffect.js +43 -0
  68. package/dist/cjs/components/empty/EmptyContent.js +37 -49
  69. package/dist/cjs/components/flyout/Flyout.js +170 -0
  70. package/dist/cjs/components/hotkey/HotKey.js +42 -0
  71. package/dist/cjs/components/icon/Icon.js +81 -80
  72. package/dist/cjs/components/media/Media.js +154 -77
  73. package/dist/cjs/components/menu/ContextMenu.js +45 -20
  74. package/dist/cjs/components/menu/Menu.js +98 -38
  75. package/dist/cjs/components/menu/MenuItem.js +102 -74
  76. package/dist/cjs/components/meter/Meter.js +35 -12
  77. package/dist/cjs/components/modal/Modal.js +152 -0
  78. package/dist/cjs/components/navigator/Navigator.js +81 -36
  79. package/dist/cjs/components/panel/Panel.js +115 -60
  80. package/dist/cjs/components/panel/PanelGroup.js +42 -16
  81. package/dist/cjs/components/panel/PanelStack.js +47 -16
  82. package/dist/cjs/components/pillbox/Pillbox.js +118 -0
  83. package/dist/cjs/components/progress/ProgressBar.js +30 -14
  84. package/dist/cjs/components/progress/ProgressCircle.js +27 -11
  85. package/dist/cjs/components/tabpanel/Tab.js +53 -37
  86. package/dist/cjs/components/tabpanel/TabPanel.js +74 -28
  87. package/dist/cjs/components/titlebar/Titlebar.js +52 -0
  88. package/dist/cjs/components/tooltip/Tooltip.js +180 -0
  89. package/dist/cjs/context/Global.js +159 -80
  90. package/dist/cjs/context/ModalManager.js +60 -0
  91. package/dist/cjs/context/context.js +43 -0
  92. package/dist/cjs/core/areaToggle/AreaToggle.js +41 -0
  93. package/dist/cjs/core/aside/Aside.js +178 -83
  94. package/dist/cjs/core/boundary/ErrorBoundary.js +37 -34
  95. package/dist/cjs/core/boundary/ErrorIcon.js +32 -19
  96. package/dist/cjs/core/content/Content.js +26 -37
  97. package/dist/cjs/core/headfoot/HeadFoot.js +133 -35
  98. package/dist/cjs/core/layout/Layout.js +28 -0
  99. package/dist/cjs/core/responsive/Responsive.js +62 -26
  100. package/dist/cjs/core/theme/ThemeProvider.js +35 -41
  101. package/dist/cjs/core/viewport/Viewport.js +26 -22
  102. package/dist/cjs/hooks/useClientService.js +39 -18
  103. package/dist/cjs/hooks/useContextMenu.js +103 -0
  104. package/dist/cjs/hooks/useControlledValue.js +13 -7
  105. package/dist/cjs/hooks/useDebounce.js +37 -21
  106. package/dist/cjs/hooks/useEffectDebugger.js +79 -60
  107. package/dist/cjs/hooks/useIsDark.js +34 -26
  108. package/dist/cjs/hooks/useIsRtl.js +13 -3
  109. package/dist/cjs/hooks/useNavigator.js +12 -9
  110. package/dist/cjs/hooks/useNotificationService.js +199 -0
  111. package/dist/cjs/hooks/useOverlayService.js +82 -41
  112. package/dist/cjs/hooks/usePropState.js +41 -0
  113. package/dist/cjs/hooks/usePropToggle.js +32 -26
  114. package/dist/cjs/hooks/useResize.js +47 -38
  115. package/dist/cjs/hooks/useResizeObserver.js +26 -7
  116. package/dist/cjs/hooks/useStorage.js +29 -16
  117. package/dist/cjs/i18n/index.js +25 -23
  118. package/dist/cjs/index.js +142 -94
  119. package/dist/cjs/typography/Abbr.js +43 -20
  120. package/dist/cjs/typography/Anchor.js +39 -0
  121. package/dist/cjs/typography/Copy.js +28 -28
  122. package/dist/cjs/typography/Kbd.js +43 -0
  123. package/dist/cjs/typography/Mark.js +34 -17
  124. package/dist/cjs/typography/Text.js +36 -54
  125. package/dist/cjs/typography/Title.js +17 -40
  126. package/dist/cjs/utils/calculateDimensions.js +38 -23
  127. package/dist/cjs/utils/cloneElement.js +64 -0
  128. package/dist/cjs/{core/section/Section.js → utils/getBadgeProps.js} +25 -21
  129. package/dist/cjs/utils/getColor.js +42 -36
  130. package/dist/cjs/utils/getIconProps.js +63 -0
  131. package/dist/cjs/utils/getTooltipProps.js +66 -0
  132. package/dist/cjs/utils/nodeCheck.js +4 -4
  133. package/dist/esm/components/actionLabel/ActionLabel.js +25 -12
  134. package/dist/esm/{overlays → components}/alert/Alert.js +73 -50
  135. package/dist/esm/components/animations/Indicator.js +72 -0
  136. package/dist/esm/components/animations/Loader.js +77 -0
  137. package/dist/esm/components/animations/LoadingBars.js +37 -0
  138. package/dist/esm/components/animations/LoadingLine.js +59 -0
  139. package/dist/esm/components/animations/LoadingSpinner.js +37 -0
  140. package/dist/esm/components/animations/Skeleton.js +88 -0
  141. package/dist/esm/components/avatar/Avatar.js +42 -21
  142. package/dist/esm/components/avatar/AvatarGroup.js +37 -16
  143. package/dist/esm/components/badge/Badge.js +93 -70
  144. package/dist/esm/components/button/Button.js +199 -137
  145. package/dist/esm/components/button/ButtonGroup.js +87 -22
  146. package/dist/esm/components/button/ConfirmButton.js +58 -44
  147. package/dist/esm/components/button/ToggleButtonGroup.js +86 -34
  148. package/dist/esm/components/callout/Callout.js +56 -25
  149. package/dist/esm/components/card/Card.js +92 -44
  150. package/dist/esm/components/card/CardCover.js +38 -27
  151. package/dist/esm/components/card/FlipContent.js +47 -0
  152. package/dist/esm/components/chip/Chip.js +81 -38
  153. package/dist/esm/components/collapsable/Collapsable.js +63 -32
  154. package/dist/esm/components/divider/Divider.js +59 -25
  155. package/dist/esm/components/dropdown/Dropdown.js +95 -48
  156. package/dist/esm/components/dropdown/DropdownTool.js +6 -7
  157. package/dist/esm/components/effect/GlassEffect.js +259 -0
  158. package/dist/esm/components/effect/MatteEffect.js +127 -0
  159. package/dist/esm/components/effect/StyleEffect.js +43 -0
  160. package/dist/esm/components/empty/EmptyContent.js +38 -50
  161. package/dist/esm/components/flyout/Flyout.js +170 -0
  162. package/dist/esm/components/hotkey/HotKey.js +42 -0
  163. package/dist/esm/components/icon/Icon.js +83 -82
  164. package/dist/esm/components/media/Media.js +156 -79
  165. package/dist/esm/components/menu/ContextMenu.js +46 -21
  166. package/dist/esm/components/menu/Menu.js +101 -41
  167. package/dist/esm/components/menu/MenuItem.js +98 -70
  168. package/dist/esm/components/meter/Meter.js +36 -13
  169. package/dist/esm/components/modal/Modal.js +152 -0
  170. package/dist/esm/components/navigator/Navigator.js +81 -36
  171. package/dist/esm/components/panel/Panel.js +117 -62
  172. package/dist/esm/components/panel/PanelGroup.js +43 -17
  173. package/dist/esm/components/panel/PanelStack.js +48 -17
  174. package/dist/esm/components/pillbox/Pillbox.js +118 -0
  175. package/dist/esm/components/progress/ProgressBar.js +31 -15
  176. package/dist/esm/components/progress/ProgressCircle.js +28 -12
  177. package/dist/esm/components/tabpanel/Tab.js +54 -38
  178. package/dist/esm/components/tabpanel/TabPanel.js +75 -29
  179. package/dist/esm/components/titlebar/Titlebar.js +52 -0
  180. package/dist/esm/components/tooltip/Tooltip.js +180 -0
  181. package/dist/esm/context/Global.js +161 -78
  182. package/dist/esm/context/ModalManager.js +60 -0
  183. package/dist/esm/context/context.js +40 -0
  184. package/dist/esm/core/areaToggle/AreaToggle.js +41 -0
  185. package/dist/esm/core/aside/Aside.js +179 -84
  186. package/dist/esm/core/boundary/ErrorBoundary.js +38 -35
  187. package/dist/esm/core/boundary/ErrorIcon.js +32 -19
  188. package/dist/esm/core/content/Content.js +26 -37
  189. package/dist/esm/core/headfoot/HeadFoot.js +134 -36
  190. package/dist/esm/core/layout/Layout.js +28 -0
  191. package/dist/esm/core/responsive/Responsive.js +62 -26
  192. package/dist/esm/core/theme/ThemeProvider.js +36 -42
  193. package/dist/esm/core/viewport/Viewport.js +26 -22
  194. package/dist/esm/hooks/useClientService.js +39 -18
  195. package/dist/esm/hooks/useContextMenu.js +103 -0
  196. package/dist/esm/hooks/useControlledValue.js +14 -8
  197. package/dist/esm/hooks/useDebounce.js +37 -21
  198. package/dist/esm/hooks/useEffectDebugger.js +81 -62
  199. package/dist/esm/hooks/useIsDark.js +34 -26
  200. package/dist/esm/hooks/useIsRtl.js +13 -3
  201. package/dist/esm/hooks/useNavigator.js +13 -10
  202. package/dist/esm/hooks/useNotificationService.js +199 -0
  203. package/dist/esm/hooks/useOverlayService.js +83 -42
  204. package/dist/esm/hooks/usePropState.js +40 -0
  205. package/dist/esm/hooks/usePropToggle.js +33 -27
  206. package/dist/esm/hooks/useResize.js +48 -39
  207. package/dist/esm/hooks/useResizeObserver.js +27 -8
  208. package/dist/esm/hooks/useStorage.js +30 -17
  209. package/dist/esm/i18n/index.js +23 -21
  210. package/dist/esm/index.js +87 -44
  211. package/dist/esm/typography/Abbr.js +45 -22
  212. package/dist/esm/typography/Anchor.js +39 -0
  213. package/dist/esm/typography/Copy.js +28 -28
  214. package/dist/esm/typography/Kbd.js +43 -0
  215. package/dist/esm/typography/Mark.js +35 -18
  216. package/dist/esm/typography/Text.js +39 -57
  217. package/dist/esm/typography/Title.js +17 -40
  218. package/dist/esm/utils/calculateDimensions.js +38 -23
  219. package/dist/esm/utils/cloneElement.js +64 -0
  220. package/dist/esm/{core/section/Section.js → utils/getBadgeProps.js} +25 -21
  221. package/dist/esm/utils/getColor.js +43 -34
  222. package/dist/esm/utils/getIconProps.js +63 -0
  223. package/dist/esm/utils/getTooltipProps.js +66 -0
  224. package/dist/esm/utils/nodeCheck.js +4 -4
  225. package/dist/types/components/actionLabel/ActionLabel.d.ts +20 -7
  226. package/dist/types/components/alert/Alert.d.ts +74 -0
  227. package/dist/types/components/animations/Indicator.d.ts +57 -0
  228. package/dist/types/components/animations/Loader.d.ts +65 -0
  229. package/dist/types/components/animations/LoadingBars.d.ts +61 -0
  230. package/dist/types/components/animations/LoadingLine.d.ts +43 -0
  231. package/dist/types/components/animations/LoadingSpinner.d.ts +61 -0
  232. package/dist/types/components/animations/Skeleton.d.ts +61 -0
  233. package/dist/types/components/avatar/Avatar.d.ts +70 -19
  234. package/dist/types/components/avatar/AvatarGroup.d.ts +51 -14
  235. package/dist/types/components/badge/Badge.d.ts +64 -14
  236. package/dist/types/components/button/Button.d.ts +72 -55
  237. package/dist/types/components/button/ButtonGroup.d.ts +86 -24
  238. package/dist/types/components/button/ConfirmButton.d.ts +21 -7
  239. package/dist/types/components/button/ToggleButtonGroup.d.ts +88 -44
  240. package/dist/types/components/callout/Callout.d.ts +58 -7
  241. package/dist/types/components/card/Card.d.ts +66 -25
  242. package/dist/types/components/card/CardCover.d.ts +52 -7
  243. package/dist/types/components/card/FlipContent.d.ts +50 -0
  244. package/dist/types/components/chip/Chip.d.ts +72 -20
  245. package/dist/types/components/collapsable/Collapsable.d.ts +55 -15
  246. package/dist/types/components/divider/Divider.d.ts +25 -8
  247. package/dist/types/components/dropdown/Dropdown.d.ts +42 -9
  248. package/dist/types/components/dropdown/DropdownTool.d.ts +22 -4
  249. package/dist/types/components/effect/GlassEffect.d.ts +5 -0
  250. package/dist/types/components/effect/MatteEffect.d.ts +40 -0
  251. package/dist/types/components/effect/StyleEffect.d.ts +27 -0
  252. package/dist/types/components/empty/EmptyContent.d.ts +53 -9
  253. package/dist/types/components/flyout/Flyout.d.ts +60 -0
  254. package/dist/types/components/hotkey/HotKey.d.ts +41 -0
  255. package/dist/types/components/icon/Icon.d.ts +74 -24
  256. package/dist/types/components/media/Media.d.ts +72 -4
  257. package/dist/types/components/menu/ContextMenu.d.ts +22 -5
  258. package/dist/types/components/menu/Menu.d.ts +26 -2
  259. package/dist/types/components/menu/MenuItem.d.ts +19 -4
  260. package/dist/types/components/menu/types.d.ts +23 -14
  261. package/dist/types/components/meter/Meter.d.ts +23 -3
  262. package/dist/types/components/modal/Modal.d.ts +52 -0
  263. package/dist/types/components/navigator/Navigator.d.ts +30 -4
  264. package/dist/types/components/panel/Panel.d.ts +43 -23
  265. package/dist/types/components/panel/PanelGroup.d.ts +22 -3
  266. package/dist/types/components/panel/PanelStack.d.ts +28 -2
  267. package/dist/types/components/pillbox/Pillbox.d.ts +95 -0
  268. package/dist/types/components/progress/ProgressBar.d.ts +19 -4
  269. package/dist/types/components/progress/ProgressCircle.d.ts +18 -4
  270. package/dist/types/components/tabpanel/Tab.d.ts +42 -10
  271. package/dist/types/components/tabpanel/TabPanel.d.ts +47 -7
  272. package/dist/types/components/titlebar/Titlebar.d.ts +54 -0
  273. package/dist/types/components/tooltip/Tooltip.d.ts +76 -0
  274. package/dist/types/context/Global.d.ts +39 -69
  275. package/dist/types/context/ModalManager.d.ts +30 -0
  276. package/dist/types/context/context.d.ts +107 -0
  277. package/dist/types/core/areaToggle/AreaToggle.d.ts +33 -0
  278. package/dist/types/core/aside/Aside.d.ts +75 -20
  279. package/dist/types/core/boundary/ErrorBoundary.d.ts +43 -4
  280. package/dist/types/core/boundary/ErrorIcon.d.ts +38 -1
  281. package/dist/types/core/content/Content.d.ts +38 -6
  282. package/dist/types/core/headfoot/HeadFoot.d.ts +48 -14
  283. package/dist/types/core/layout/Layout.d.ts +38 -0
  284. package/dist/types/core/responsive/Responsive.d.ts +45 -15
  285. package/dist/types/core/theme/ThemeProvider.d.ts +35 -11
  286. package/dist/types/core/viewport/Viewport.d.ts +27 -3
  287. package/dist/types/hooks/useClientService.d.ts +43 -1
  288. package/dist/types/hooks/useContextMenu.d.ts +10 -0
  289. package/dist/types/hooks/useControlledValue.d.ts +28 -4
  290. package/dist/types/hooks/useDebounce.d.ts +38 -2
  291. package/dist/types/hooks/useEffectDebugger.d.ts +73 -4
  292. package/dist/types/hooks/useIsDark.d.ts +6 -0
  293. package/dist/types/hooks/useIsRtl.d.ts +35 -1
  294. package/dist/types/hooks/useNavigator.d.ts +37 -2
  295. package/dist/types/hooks/useNotificationService.d.ts +60 -0
  296. package/dist/types/hooks/useOverlayService.d.ts +28 -8
  297. package/dist/types/hooks/usePropState.d.ts +26 -0
  298. package/dist/types/hooks/usePropToggle.d.ts +41 -7
  299. package/dist/types/hooks/useResize.d.ts +46 -4
  300. package/dist/types/hooks/useResizeObserver.d.ts +45 -3
  301. package/dist/types/hooks/useStorage.d.ts +32 -2
  302. package/dist/types/i18n/index.d.ts +27 -3
  303. package/dist/types/index.d.ts +106 -18
  304. package/dist/types/types/colors.d.ts +29 -0
  305. package/dist/types/types/index.d.ts +216 -76
  306. package/dist/types/typography/Abbr.d.ts +51 -6
  307. package/dist/types/typography/Anchor.d.ts +41 -0
  308. package/dist/types/typography/Copy.d.ts +36 -2
  309. package/dist/types/typography/Kbd.d.ts +40 -0
  310. package/dist/types/typography/Mark.d.ts +44 -7
  311. package/dist/types/typography/Text.d.ts +40 -24
  312. package/dist/types/typography/Title.d.ts +37 -26
  313. package/dist/types/typography/types.d.ts +32 -0
  314. package/dist/types/utils/calculateDimensions.d.ts +50 -6
  315. package/dist/types/utils/cloneElement.d.ts +41 -0
  316. package/dist/types/utils/getBadgeProps.d.ts +16 -0
  317. package/dist/types/utils/getColor.d.ts +43 -4
  318. package/dist/types/utils/getIconProps.d.ts +45 -0
  319. package/dist/types/utils/getTooltipProps.d.ts +47 -0
  320. package/dist/types/utils/index.d.ts +28 -0
  321. package/dist/types/utils/nodeCheck.d.ts +1 -2
  322. package/package.json +29 -21
  323. package/src/components/actionLabel/ActionLabel.tsx +28 -39
  324. package/src/components/alert/Alert.tsx +261 -0
  325. package/src/components/animations/Indicator.tsx +76 -0
  326. package/src/components/animations/Loader.tsx +89 -0
  327. package/src/components/animations/LoadingBars.tsx +70 -0
  328. package/src/components/animations/LoadingLine.tsx +51 -0
  329. package/src/components/animations/LoadingSpinner.tsx +70 -0
  330. package/src/components/animations/Skeleton.tsx +100 -0
  331. package/src/components/avatar/Avatar.tsx +89 -70
  332. package/src/components/avatar/AvatarGroup.tsx +65 -74
  333. package/src/components/badge/Badge.tsx +141 -108
  334. package/src/components/button/Button.tsx +223 -238
  335. package/src/components/button/ButtonGroup.tsx +117 -77
  336. package/src/components/button/ConfirmButton.tsx +60 -90
  337. package/src/components/button/ToggleButtonGroup.tsx +134 -120
  338. package/src/components/callout/Callout.tsx +81 -59
  339. package/src/components/card/Card.tsx +131 -113
  340. package/src/components/card/CardCover.tsx +61 -61
  341. package/src/components/card/FlipContent.tsx +78 -0
  342. package/src/components/chip/Chip.tsx +139 -99
  343. package/src/components/collapsable/Collapsable.tsx +79 -77
  344. package/src/components/divider/Divider.tsx +74 -53
  345. package/src/components/dropdown/Dropdown.tsx +109 -106
  346. package/src/components/dropdown/DropdownTool.tsx +29 -12
  347. package/src/components/effect/GlassEffect.tsx +221 -0
  348. package/src/components/effect/MatteEffect.tsx +99 -0
  349. package/src/components/effect/StyleEffect.tsx +36 -0
  350. package/src/components/empty/EmptyContent.tsx +60 -99
  351. package/src/components/flyout/Flyout.tsx +257 -0
  352. package/src/components/hotkey/HotKey.tsx +57 -0
  353. package/src/components/icon/Icon.tsx +131 -130
  354. package/src/components/media/Media.tsx +184 -154
  355. package/src/components/menu/ContextMenu.tsx +56 -39
  356. package/src/components/menu/Menu.tsx +121 -84
  357. package/src/components/menu/MenuItem.tsx +87 -69
  358. package/src/components/menu/types.ts +23 -28
  359. package/src/components/meter/Meter.tsx +34 -17
  360. package/src/components/modal/Modal.tsx +226 -0
  361. package/src/components/navigator/Navigator.tsx +93 -38
  362. package/src/components/panel/Panel.tsx +123 -131
  363. package/src/components/panel/PanelGroup.tsx +49 -43
  364. package/src/components/panel/PanelStack.tsx +63 -62
  365. package/src/components/pillbox/Pillbox.tsx +208 -0
  366. package/src/components/progress/ProgressBar.tsx +33 -33
  367. package/src/components/progress/ProgressCircle.tsx +29 -37
  368. package/src/components/tabpanel/Tab.tsx +84 -73
  369. package/src/components/tabpanel/TabPanel.tsx +102 -51
  370. package/src/components/titlebar/Titlebar.tsx +115 -0
  371. package/src/components/tooltip/Tooltip.tsx +255 -0
  372. package/src/context/Global.tsx +148 -148
  373. package/src/context/ModalManager.tsx +68 -0
  374. package/src/context/context.ts +111 -0
  375. package/src/core/areaToggle/AreaToggle.tsx +45 -0
  376. package/src/core/aside/Aside.tsx +200 -155
  377. package/src/core/boundary/ErrorBoundary.tsx +50 -68
  378. package/src/core/boundary/ErrorIcon.tsx +34 -32
  379. package/src/core/content/Content.tsx +41 -50
  380. package/src/core/headfoot/HeadFoot.tsx +162 -81
  381. package/src/core/layout/Layout.tsx +54 -0
  382. package/src/core/responsive/Responsive.tsx +91 -98
  383. package/src/core/theme/ThemeProvider.tsx +45 -56
  384. package/src/core/viewport/Viewport.tsx +25 -27
  385. package/src/hooks/useClientService.ts +47 -0
  386. package/src/hooks/useContextMenu.tsx +131 -0
  387. package/src/hooks/useControlledValue.ts +47 -0
  388. package/src/hooks/useDebounce.ts +41 -24
  389. package/src/hooks/useEffectDebugger.ts +105 -94
  390. package/src/hooks/useIsDark.ts +10 -24
  391. package/src/hooks/useIsRtl.ts +32 -20
  392. package/src/hooks/useNavigator.tsx +41 -26
  393. package/src/hooks/useNotificationService.tsx +239 -0
  394. package/src/hooks/useOverlayService.tsx +67 -20
  395. package/src/hooks/usePropState.ts +52 -0
  396. package/src/hooks/usePropToggle.ts +54 -47
  397. package/src/hooks/useResize.ts +69 -45
  398. package/src/hooks/useResizeObserver.ts +59 -34
  399. package/src/hooks/useStorage.ts +40 -48
  400. package/src/i18n/index.ts +24 -25
  401. package/src/index.ts +115 -44
  402. package/src/types/colors.ts +49 -0
  403. package/src/types/global.d.ts +40 -17
  404. package/src/types/index.ts +243 -155
  405. package/src/typography/Abbr.tsx +62 -59
  406. package/src/typography/Anchor.tsx +63 -0
  407. package/src/typography/Copy.tsx +39 -29
  408. package/src/typography/Kbd.tsx +50 -0
  409. package/src/typography/Mark.tsx +56 -51
  410. package/src/typography/Text.tsx +57 -128
  411. package/src/typography/Title.tsx +36 -108
  412. package/src/typography/types.ts +27 -17
  413. package/src/utils/calculateDimensions.ts +50 -40
  414. package/src/utils/cloneElement.ts +61 -0
  415. package/src/{core/content/Content.module.css → utils/getBadgeProps.ts} +20 -15
  416. package/src/utils/getColor.ts +42 -36
  417. package/src/utils/getIconProps.ts +58 -0
  418. package/src/utils/getTooltipProps.ts +59 -0
  419. package/src/utils/index.ts +23 -17
  420. package/src/utils/nodeCheck.ts +4 -8
  421. package/css/flags.rect.css +0 -1607
  422. package/css/flags.wavy.css +0 -1606
  423. package/css/index.js +0 -250
  424. package/css/tailwind/colors.ts +0 -158
  425. package/dist/cjs/components/actionLabel/ActionLabel.module.css +0 -1
  426. package/dist/cjs/components/animations/Animations.js +0 -142
  427. package/dist/cjs/components/animations/Animations.module.css +0 -1
  428. package/dist/cjs/components/avatar/Avatar.module.css +0 -1
  429. package/dist/cjs/components/badge/Badge.module.css +0 -1
  430. package/dist/cjs/components/breadcrumbs/Breadcrumbs.js +0 -71
  431. package/dist/cjs/components/breadcrumbs/Breadcrumbs.module.css +0 -1
  432. package/dist/cjs/components/button/Button.module.css +0 -1
  433. package/dist/cjs/components/card/Card.module.css +0 -1
  434. package/dist/cjs/components/chip/Chip.module.css +0 -1
  435. package/dist/cjs/components/collapsable/Collapsable.module.css +0 -1
  436. package/dist/cjs/components/dropdown/Dropdown.module.css +0 -1
  437. package/dist/cjs/components/icon/Icon.module.css +0 -1
  438. package/dist/cjs/components/media/Media.module.css +0 -1
  439. package/dist/cjs/components/menu/Menu.module.css +0 -1
  440. package/dist/cjs/components/meter/Meter.module.css +0 -1
  441. package/dist/cjs/components/panel/Panel.module.css +0 -1
  442. package/dist/cjs/components/progress/Progress.module.css +0 -1
  443. package/dist/cjs/components/tabpanel/TabPanel.module.css +0 -1
  444. package/dist/cjs/context/NotificationCenter.js +0 -254
  445. package/dist/cjs/core/aside/Aside.module.css +0 -1
  446. package/dist/cjs/core/boundary/ErrorBoundary.module.css +0 -1
  447. package/dist/cjs/core/content/Content.module.css +0 -1
  448. package/dist/cjs/core/headfoot/HeadFoot.module.css +0 -1
  449. package/dist/cjs/core/page/Page.js +0 -66
  450. package/dist/cjs/core/page/Page.module.css +0 -1
  451. package/dist/cjs/core/responsive/Responsive.module.css +0 -1
  452. package/dist/cjs/core/section/Section.module.css +0 -1
  453. package/dist/cjs/core/theme/Theme.module.css +0 -1
  454. package/dist/cjs/core/viewport/Viewport.module.css +0 -1
  455. package/dist/cjs/hotkeys/HotKey.js +0 -47
  456. package/dist/cjs/hotkeys/HotKeyLabel.js +0 -52
  457. package/dist/cjs/hotkeys/HotKeyWrapper.js +0 -98
  458. package/dist/cjs/hotkeys/commons.js +0 -56
  459. package/dist/cjs/overlays/alert/Alert.module.css +0 -1
  460. package/dist/cjs/overlays/flyout/Flyout.js +0 -152
  461. package/dist/cjs/overlays/flyout/Flyout.module.css +0 -1
  462. package/dist/cjs/overlays/message/Message.js +0 -84
  463. package/dist/cjs/overlays/message/Message.module.css +0 -1
  464. package/dist/cjs/overlays/modal/Modal.js +0 -132
  465. package/dist/cjs/overlays/modal/Modal.module.css +0 -1
  466. package/dist/cjs/overlays/toast/Toast.js +0 -166
  467. package/dist/cjs/overlays/toast/Toast.module.css +0 -1
  468. package/dist/cjs/overlays/tooltip/Tooltip.js +0 -133
  469. package/dist/cjs/overlays/tooltip/Tooltip.module.css +0 -1
  470. package/dist/cjs/types/icons.js +0 -200
  471. package/dist/cjs/typography/Link.js +0 -55
  472. package/dist/cjs/typography/Typography.module.css +0 -1
  473. package/dist/cjs/typography/types.js +0 -42
  474. package/dist/esm/components/actionLabel/ActionLabel.module.css +0 -1
  475. package/dist/esm/components/animations/Animations.js +0 -138
  476. package/dist/esm/components/animations/Animations.module.css +0 -1
  477. package/dist/esm/components/avatar/Avatar.module.css +0 -1
  478. package/dist/esm/components/badge/Badge.module.css +0 -1
  479. package/dist/esm/components/breadcrumbs/Breadcrumbs.js +0 -71
  480. package/dist/esm/components/breadcrumbs/Breadcrumbs.module.css +0 -1
  481. package/dist/esm/components/button/Button.module.css +0 -1
  482. package/dist/esm/components/card/Card.module.css +0 -1
  483. package/dist/esm/components/chip/Chip.module.css +0 -1
  484. package/dist/esm/components/collapsable/Collapsable.module.css +0 -1
  485. package/dist/esm/components/dropdown/Dropdown.module.css +0 -1
  486. package/dist/esm/components/icon/Icon.module.css +0 -1
  487. package/dist/esm/components/media/Media.module.css +0 -1
  488. package/dist/esm/components/menu/Menu.module.css +0 -1
  489. package/dist/esm/components/meter/Meter.module.css +0 -1
  490. package/dist/esm/components/panel/Panel.module.css +0 -1
  491. package/dist/esm/components/progress/Progress.module.css +0 -1
  492. package/dist/esm/components/tabpanel/TabPanel.module.css +0 -1
  493. package/dist/esm/context/NotificationCenter.js +0 -254
  494. package/dist/esm/core/aside/Aside.module.css +0 -1
  495. package/dist/esm/core/boundary/ErrorBoundary.module.css +0 -1
  496. package/dist/esm/core/content/Content.module.css +0 -1
  497. package/dist/esm/core/headfoot/HeadFoot.module.css +0 -1
  498. package/dist/esm/core/page/Page.js +0 -66
  499. package/dist/esm/core/page/Page.module.css +0 -1
  500. package/dist/esm/core/responsive/Responsive.module.css +0 -1
  501. package/dist/esm/core/section/Section.module.css +0 -1
  502. package/dist/esm/core/theme/Theme.module.css +0 -1
  503. package/dist/esm/core/viewport/Viewport.module.css +0 -1
  504. package/dist/esm/hotkeys/HotKey.js +0 -47
  505. package/dist/esm/hotkeys/HotKeyLabel.js +0 -52
  506. package/dist/esm/hotkeys/HotKeyWrapper.js +0 -96
  507. package/dist/esm/hotkeys/commons.js +0 -56
  508. package/dist/esm/overlays/alert/Alert.module.css +0 -1
  509. package/dist/esm/overlays/flyout/Flyout.js +0 -152
  510. package/dist/esm/overlays/flyout/Flyout.module.css +0 -1
  511. package/dist/esm/overlays/message/Message.js +0 -84
  512. package/dist/esm/overlays/message/Message.module.css +0 -1
  513. package/dist/esm/overlays/modal/Modal.js +0 -132
  514. package/dist/esm/overlays/modal/Modal.module.css +0 -1
  515. package/dist/esm/overlays/toast/Toast.js +0 -166
  516. package/dist/esm/overlays/toast/Toast.module.css +0 -1
  517. package/dist/esm/overlays/tooltip/Tooltip.js +0 -132
  518. package/dist/esm/overlays/tooltip/Tooltip.module.css +0 -1
  519. package/dist/esm/types/icons.js +0 -202
  520. package/dist/esm/typography/Link.js +0 -55
  521. package/dist/esm/typography/Typography.module.css +0 -1
  522. package/dist/esm/typography/types.js +0 -41
  523. package/dist/types/components/animations/Animations.d.ts +0 -23
  524. package/dist/types/components/breadcrumbs/Breadcrumbs.d.ts +0 -17
  525. package/dist/types/components/index.d.ts +0 -33
  526. package/dist/types/context/NotificationCenter.d.ts +0 -11
  527. package/dist/types/core/index.d.ts +0 -9
  528. package/dist/types/core/page/Page.d.ts +0 -23
  529. package/dist/types/core/section/Section.d.ts +0 -7
  530. package/dist/types/hotkeys/HotKey.d.ts +0 -2
  531. package/dist/types/hotkeys/HotKeyLabel.d.ts +0 -2
  532. package/dist/types/hotkeys/HotKeyWrapper.d.ts +0 -11
  533. package/dist/types/hotkeys/commons.d.ts +0 -28
  534. package/dist/types/overlays/alert/Alert.d.ts +0 -41
  535. package/dist/types/overlays/flyout/Flyout.d.ts +0 -57
  536. package/dist/types/overlays/index.d.ts +0 -6
  537. package/dist/types/overlays/message/Message.d.ts +0 -21
  538. package/dist/types/overlays/modal/Modal.d.ts +0 -53
  539. package/dist/types/overlays/toast/Toast.d.ts +0 -33
  540. package/dist/types/overlays/tooltip/Tooltip.d.ts +0 -18
  541. package/dist/types/types/icons.d.ts +0 -197
  542. package/dist/types/typography/Link.d.ts +0 -25
  543. package/dist/types/typography/index.d.ts +0 -6
  544. package/src/components/animations/Animations.module.css +0 -253
  545. package/src/components/animations/Animations.tsx +0 -196
  546. package/src/components/avatar/Avatar.module.css +0 -90
  547. package/src/components/badge/Badge.module.css +0 -165
  548. package/src/components/breadcrumbs/Breadcrumbs.module.css +0 -189
  549. package/src/components/breadcrumbs/Breadcrumbs.tsx +0 -109
  550. package/src/components/button/Button.module.css +0 -375
  551. package/src/components/card/Card.module.css +0 -152
  552. package/src/components/chip/Chip.module.css +0 -118
  553. package/src/components/collapsable/Collapsable.module.css +0 -30
  554. package/src/components/icon/Icon.module.css +0 -71
  555. package/src/components/index.ts +0 -62
  556. package/src/components/media/Media.module.css +0 -112
  557. package/src/context/NotificationCenter.tsx +0 -223
  558. package/src/core/aside/Aside.module.css +0 -231
  559. package/src/core/boundary/ErrorBoundary.module.css +0 -65
  560. package/src/core/headfoot/HeadFoot.module.css +0 -38
  561. package/src/core/index.ts +0 -32
  562. package/src/core/page/Page.module.css +0 -46
  563. package/src/core/page/Page.tsx +0 -101
  564. package/src/core/responsive/Responsive.module.css +0 -85
  565. package/src/core/section/Section.module.css +0 -28
  566. package/src/core/section/Section.tsx +0 -54
  567. package/src/core/theme/Theme.module.css +0 -30
  568. package/src/core/viewport/Viewport.module.css +0 -32
  569. package/src/hooks/useControlledValue.tsx +0 -43
  570. package/src/hotkeys/HotKey.tsx +0 -39
  571. package/src/hotkeys/HotKeyLabel.tsx +0 -61
  572. package/src/hotkeys/HotKeyWrapper.tsx +0 -137
  573. package/src/hotkeys/commons.ts +0 -74
  574. package/src/overlays/alert/Alert.tsx +0 -252
  575. package/src/overlays/flyout/Flyout.tsx +0 -283
  576. package/src/overlays/index.ts +0 -29
  577. package/src/overlays/message/Message.tsx +0 -107
  578. package/src/overlays/modal/Modal.tsx +0 -244
  579. package/src/overlays/toast/Toast.module.css +0 -37
  580. package/src/overlays/toast/Toast.tsx +0 -216
  581. package/src/overlays/tooltip/Tooltip.module.css +0 -53
  582. package/src/overlays/tooltip/Tooltip.tsx +0 -200
  583. package/src/types/icons.ts +0 -426
  584. package/src/typography/Link.tsx +0 -113
  585. package/src/typography/Typography.module.css +0 -68
  586. package/src/typography/index.ts +0 -29
  587. /package/dist/cjs/i18n/{ar.json.js → ar/core.json.js} +0 -0
  588. /package/dist/cjs/i18n/{en.json.js → en/core.json.js} +0 -0
  589. /package/dist/esm/i18n/{ar.json.js → ar/core.json.js} +0 -0
  590. /package/dist/esm/i18n/{en.json.js → en/core.json.js} +0 -0
  591. /package/src/i18n/{ar.json → ar/core.json} +0 -0
  592. /package/src/i18n/{en.json → en/core.json} +0 -0
@@ -0,0 +1,239 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { isString, shortHash } from "@react-fabric/utilities";
27
+ import { useEffect, useRef } from "react";
28
+ import type { ToastT } from "sonner";
29
+ import { toast, useSonner } from "sonner";
30
+ import type { AlertProps } from "../components/alert/Alert";
31
+ import { Alert } from "../components/alert/Alert";
32
+ import { useGlobals } from "../context/context";
33
+ import { useIsRtl } from "./useIsRtl";
34
+
35
+ type POSITION = "top" | "bottom";
36
+
37
+ const DEFAULT_DURATION = 5000;
38
+
39
+ const TOAST_POSITIONS_LTR = {
40
+ top: "top-right",
41
+ bottom: "bottom-right",
42
+ };
43
+ const TOAST_POSITIONS_RTL = {
44
+ top: "top-left",
45
+ bottom: "bottom-left",
46
+ };
47
+ const MESSAGE_POSITIONS = {
48
+ top: "top-center",
49
+ bottom: "bottom-center",
50
+ };
51
+
52
+ interface Action {
53
+ label: string;
54
+ onClick: () => void;
55
+ }
56
+
57
+ interface ToastProps {
58
+ message: string;
59
+ type?: "info" | "error" | "success" | "warning";
60
+ position?: POSITION;
61
+ icon?: React.ReactElement;
62
+ description?: string;
63
+ actions?: Action[];
64
+ link?: Action;
65
+ duration?: number;
66
+ }
67
+ interface MessageProps {
68
+ message: string;
69
+ type?: "info" | "error" | "success" | "warning";
70
+ position?: POSITION;
71
+ icon?: React.ReactElement;
72
+ link?: Action;
73
+ duration?: number;
74
+ }
75
+
76
+ export function useNotificationService() {
77
+ const isRtl = useIsRtl();
78
+ const { toasts } = useSonner();
79
+ const toastRef = useRef(toasts);
80
+ const { showAlert } = useGlobals();
81
+
82
+ const makeToastOptions = (options: string | ToastProps, promiseId?: string) => {
83
+ const opts = isString(options) ? { message: options } : options;
84
+ const id = promiseId ?? shortHash();
85
+ const duration = opts.duration ?? DEFAULT_DURATION;
86
+ return {
87
+ message: (
88
+ <>
89
+ <div>{opts.message}</div>
90
+ <button data-button data-close-all onClick={c}>
91
+ Close All
92
+ </button>
93
+ </>
94
+ ),
95
+ id,
96
+ position: (isRtl ? TOAST_POSITIONS_RTL : TOAST_POSITIONS_LTR)[opts.position ?? "top"] as ToastT["position"],
97
+ icon: opts.icon,
98
+ toasterId: "toasting",
99
+ closeButton: true,
100
+ action: (opts.actions || opts.link) && (
101
+ <div data-actionbar>
102
+ {opts.actions?.map((act) => (
103
+ <button key={act.label} data-button data-action onClick={() => (act.onClick(), toast.dismiss(id))}>
104
+ {act.label}
105
+ </button>
106
+ ))}
107
+ {opts.link && (
108
+ <button key={opts.link.label} data-link data-action onClick={() => (opts.link?.onClick(), toast.dismiss(id))}>
109
+ {opts.link.label}
110
+ </button>
111
+ )}
112
+ </div>
113
+ ),
114
+ className: duration > 0 ? "progress" : undefined,
115
+ style: {
116
+ "--sonner-duration": duration,
117
+ } as React.CSSProperties,
118
+ description: opts.description,
119
+ duration: duration === 0 ? Infinity : duration,
120
+ };
121
+ };
122
+
123
+ const makeMessageOptions = (options: string | MessageProps) => {
124
+ const opts = isString(options) ? { message: options } : options;
125
+ const id = shortHash();
126
+ const duration = opts.duration ?? DEFAULT_DURATION;
127
+ return {
128
+ message: (
129
+ <>
130
+ <div>{opts.message}</div>
131
+ <button data-button data-close-all onClick={c}>
132
+ Close All
133
+ </button>
134
+ </>
135
+ ),
136
+ id,
137
+ position: MESSAGE_POSITIONS[opts.position ?? "top"] as ToastT["position"],
138
+ icon: opts.icon,
139
+ toasterId: "toasting",
140
+ closeButton: true,
141
+ action: opts.link && (
142
+ <div data-actionbar>
143
+ {opts.link && (
144
+ <button key={opts.link.label} data-link data-action onClick={() => (opts.link?.onClick(), toast.dismiss(id))}>
145
+ {opts.link.label}
146
+ </button>
147
+ )}
148
+ </div>
149
+ ),
150
+ className: duration > 0 ? "progress" : undefined,
151
+ style: {
152
+ "--sonner-duration": duration,
153
+ } as React.CSSProperties,
154
+ duration: duration === 0 ? Infinity : duration,
155
+ };
156
+ };
157
+
158
+ useEffect(() => {
159
+ toastRef.current = toasts;
160
+ }, [toasts]);
161
+
162
+ const c = () => {
163
+ showAlert();
164
+ toastRef.current.forEach((t) => {
165
+ if (t.toasterId === "toasting" && !t.promise) toast.dismiss(t.id);
166
+ });
167
+ };
168
+
169
+ const t = (props: string | ToastProps) => {
170
+ const opts = makeToastOptions(props);
171
+ const tt = !isString(props) && props.type ? toast[props.type] : toast;
172
+ tt(opts.message, opts);
173
+ };
174
+
175
+ const m = (props: string | MessageProps) => {
176
+ const opts = makeMessageOptions(props);
177
+ const tt = !isString(props) && props.type ? toast[props.type] : toast;
178
+ tt(opts.message, opts);
179
+ };
180
+
181
+ const p = (
182
+ promise: Promise<string | ToastProps>,
183
+ props?: {
184
+ loading?: string;
185
+ position?: "top" | "bottom";
186
+ onCancel?: () => void;
187
+ },
188
+ ) => {
189
+ const id = shortHash();
190
+ toast.loading(
191
+ <div className="flex items-center">
192
+ <div className="flex-1">{props?.loading ?? "Loading"}</div>
193
+ {props?.onCancel && (
194
+ <button
195
+ data-button
196
+ data-cancel
197
+ onClick={() => {
198
+ void Promise.resolve(props.onCancel?.()).finally(() => {
199
+ toast.dismiss(id);
200
+ });
201
+ }}
202
+ >
203
+ Cancel
204
+ </button>
205
+ )}
206
+ </div>,
207
+ {
208
+ id,
209
+ toasterId: "toasting",
210
+ position: (isRtl ? TOAST_POSITIONS_RTL : TOAST_POSITIONS_LTR)[props?.position ?? "bottom"] as ToastT["position"],
211
+ },
212
+ );
213
+ void promise
214
+ .then((props) => {
215
+ const opts = makeToastOptions(props, id);
216
+ toast.success(opts.message, opts);
217
+ })
218
+ .catch((props: string | ToastProps) => {
219
+ if (props) {
220
+ const opts = makeToastOptions(props, id);
221
+ toast.error(opts.message, opts);
222
+ }
223
+ });
224
+ };
225
+
226
+ const a = (props: AlertProps) => {
227
+ return new Promise((r) => {
228
+ showAlert(<Alert {...props} onClose={(ret) => (r(ret), showAlert())} />);
229
+ });
230
+ };
231
+
232
+ return {
233
+ alert: a,
234
+ toast: t,
235
+ message: m,
236
+ promise: p,
237
+ closeAll: c,
238
+ };
239
+ }
@@ -21,31 +21,78 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
- import { useState, type FC, type ReactNode } from "react";
24
+ import type { JSX } from "react";
25
+ import { useCallback, useRef, useState } from "react";
26
+ import type { ModalProps } from "../types";
25
27
 
26
- type OverlayComponent = FC<{
27
- onClose: (args?: AnyObject) => void;
28
- [key: string]: AnyObject;
29
- }>;
28
+ type OverlayProps<P, T> = Partial<ModalProps<P, T>>;
30
29
 
31
- export const useOverlayService = (
32
- ModalOrFlyout: OverlayComponent,
30
+ /**
31
+ * Hook to manage overlay components like modals or flyouts.
32
+ * It provides a way to open an overlay with specified properties and handle its closure.
33
+ * This hook returns the current overlay component and a function to open it with props.
34
+ * It is useful for scenarios where you need to display overlays dynamically,
35
+ * such as modals, flyouts, or any other overlay components in a React application.
36
+ * The `openOverlay` function returns a promise that resolves with the result
37
+ * of the overlay when it is closed, allowing you to handle the result in a controlled manner.
38
+ *
39
+ * @example
40
+ * ```jsx
41
+ * const [Overlay, openOverlay] = useOverlayService(MyModalComponent);
42
+ * // To open the overlay:
43
+ * const handleOpen = async () => {
44
+ * const result = await openOverlay({ title: "My Modal", content: "Hello World" });
45
+ * console.log(result); // Handle the result from the overlay
46
+ * };
47
+ * <button onClick={handleOpen}>Open Modal</button>
48
+ * <Overlay />
49
+ * ```
50
+ */
51
+ export function useOverlayService<P extends AnyObject = AnyObject, T extends AnyObject = AnyObject>(
52
+ OverlayComponent: React.FunctionComponent<ModalProps<P, T>>,
33
53
  ): [
34
- Overlay: ReactNode | null,
35
- openOverlay: (props?: KeyValue) => Promise<AnyObject>,
36
- ] => {
37
- const [Overlay, setOverlay] = useState<ReactNode | null>(null);
54
+ renderOverlay: (props?: OverlayProps<P, T>) => JSX.Element | null,
55
+ openOverlay: (props?: OverlayProps<P, T>) => Promise<T | null>,
56
+ closeOverlay: ((args: T | null) => void) | null,
57
+ ] {
58
+ const [isOpen, setIsOpen] = useState(false);
59
+ const [modalProps, setModalProps] = useState<OverlayProps<P, T>>({} as OverlayProps<P, T>);
60
+ const existingOpenPromiseRef = useRef<(args: T | null, onClose?: (args: T | null) => void) => void>(null);
38
61
 
39
- const openOverlay = async ({ onClose, ...props }: KeyValue = {}) => {
40
- return await new Promise((resolve) => {
41
- const handleClose = (args: AnyObject) => {
42
- setOverlay(null);
62
+ // Open modal and optionally pass dynamic props down to it
63
+ const openOverlay = useCallback(async (props: OverlayProps<P, T> = {}) => {
64
+ setModalProps(props);
65
+ setIsOpen(true);
66
+ return await new Promise<T | null>((resolve) => {
67
+ existingOpenPromiseRef.current = (args: T | null) => {
43
68
  resolve(args);
44
- onClose?.(args);
69
+ props?.onClose?.(args);
70
+ setIsOpen(false);
71
+ setModalProps({});
72
+ existingOpenPromiseRef.current = null;
45
73
  };
46
- setOverlay(<ModalOrFlyout {...props} onClose={handleClose} />);
47
74
  });
48
- };
75
+ }, []);
76
+
77
+ const closeOverlay = useCallback((args: T | null) => {
78
+ existingOpenPromiseRef.current?.(args);
79
+ }, []);
80
+
81
+ // A wrapper component that handles the Portal attachment safely
82
+ const renderOverlay = useCallback(
83
+ (props: OverlayProps<P, T> = {}) => {
84
+ if (!isOpen) return null;
85
+ return (
86
+ // @ts-expect-error ignore
87
+ <OverlayComponent
88
+ {...props}
89
+ {...modalProps}
90
+ onClose={(args) => existingOpenPromiseRef.current?.(args, props.onClose)}
91
+ />
92
+ );
93
+ },
94
+ [OverlayComponent, isOpen, modalProps],
95
+ );
49
96
 
50
- return [Overlay, openOverlay];
51
- };
97
+ return [renderOverlay, openOverlay, closeOverlay];
98
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { isEqual } from "@react-fabric/utilities";
27
+ import { useRef, useState } from "react";
28
+
29
+ export function usePropState<T>(value: T, callback?: (value: T) => void) {
30
+ const currentRef = useRef(value);
31
+ const [state, setState] = useState(() => value);
32
+
33
+ if (!isEqual(currentRef.current, value)) {
34
+ currentRef.current = value;
35
+ setState(value);
36
+ callback?.(value);
37
+ }
38
+
39
+ return [state, setState] as [T, React.Dispatch<React.SetStateAction<T>>];
40
+ }
41
+
42
+ export function usePropWatcher<T>(value: T, ...args: unknown[]) {
43
+ const currentRef = useRef(args);
44
+ const [state, setState] = useState(() => value);
45
+
46
+ if (!isEqual(currentRef.current, args)) {
47
+ currentRef.current = args;
48
+ setState(value);
49
+ }
50
+
51
+ return [state, setState] as [T, React.Dispatch<React.SetStateAction<T>>];
52
+ }
@@ -1,61 +1,68 @@
1
- /*
1
+ /**
2
2
  * React Fabric
3
- * @version: 1.0.0
4
- *
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
5
6
  *
6
- * The MIT License (MIT)
7
- * Copyright (c) 2024 Adarsh Pastakia
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
8
13
  *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
- * subject to the following conditions:
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
14
16
  *
15
- * The above copyright notice and this permission notice shall be included in all copies or substantial
16
- * portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
22
24
  */
23
25
 
24
- import { useCallback, useRef, useState, type RefObject } from "react";
25
- import { useLayoutEffectDebugger } from "./useEffectDebugger";
26
+ import { useCallback } from "react";
27
+ import { usePropState } from "./usePropState";
26
28
 
27
29
  /**
28
- * hook to control boolean props
29
- * @param isOn (is prop true)
30
- * @param callback (optional callback)
31
- * @param key (optional key to pass to callback)
32
- * @returns
30
+ * This hook is used to manage a toggle state based on a prop value.
31
+ * It allows you to toggle the state and also provides a reference to the current state.
32
+ * It is useful for scenarios where you want to control a toggle state from a parent component while also allowing local toggling.
33
+ *
34
+ * @param isOn - The initial state of the toggle.
35
+ * @param onToggle - A callback function that is called when the toggle state changes.
36
+ * @param key - A unique key to identify the toggle state.
37
+ * @returns A tuple containing the current toggle state, a function to toggle the state, and a reference to the current state.
38
+ *
39
+ * @example
40
+ * ```jsx
41
+ * const [isToggled, toggle, toggleRef] = usePropToggle(false, (newState) => {
42
+ * console.log("Toggle state changed to:", newState);
43
+ * });
44
+ * toggle(); // This will toggle the state and call the onToggle callback
45
+ * ```
33
46
  */
34
- export const usePropToggle = (
47
+ export function usePropToggle(
35
48
  isOn = false,
36
- onToggle?: (is: boolean, key?: string) => unknown,
37
- key?: string,
38
- ): [boolean, () => void, RefObject<boolean>] => {
39
- const toggleRef = useRef(isOn);
40
- const [toggleOn, setToggleOn] = useState(isOn);
49
+ onToggle?: (is: boolean, key?: string | number) => unknown,
50
+ key?: string | number,
51
+ ): [boolean, (toggle?: boolean) => void] {
52
+ const [toggleOn, setToggleOn] = usePropState(isOn);
41
53
 
42
- /** ***************** update toggle state on change *******************/
43
- useLayoutEffectDebugger(
44
- () => {
45
- toggleRef.current = isOn;
46
- setToggleOn(isOn);
54
+ /** ***************** toggle handler *******************/
55
+ const doToggle = useCallback(
56
+ (toggle?: boolean) => {
57
+ setToggleOn((toggleOn) => {
58
+ if (onToggle?.(toggle ?? !toggleOn, key) !== false) {
59
+ return toggle ?? !toggleOn;
60
+ }
61
+ return toggleOn;
62
+ });
47
63
  },
48
- [isOn],
49
- "usePropToggle",
64
+ [setToggleOn, onToggle, key],
50
65
  );
51
66
 
52
- /** ***************** toggle handler *******************/
53
- const doToggle = useCallback(() => {
54
- if (onToggle?.(!toggleOn, key) !== false) {
55
- toggleRef.current = !toggleOn;
56
- setToggleOn(!toggleOn);
57
- }
58
- }, [toggleOn, onToggle, key]);
59
-
60
- return [toggleOn, doToggle, toggleRef];
61
- };
67
+ return [toggleOn, doToggle];
68
+ }
@@ -1,27 +1,29 @@
1
- /*
1
+ /**
2
2
  * React Fabric
3
- * @version: 1.0.0
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
4
6
  *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
5
13
  *
6
- * The MIT License (MIT)
7
- * Copyright (c) 2024 Adarsh Pastakia
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
8
16
  *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
- * subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all copies or substantial
16
- * portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
22
24
  */
23
25
 
24
- import { useCallback, useRef, type RefObject } from "react";
26
+ import { useCallback, useRef, useState } from "react";
25
27
  import { useIsRtl } from "./useIsRtl";
26
28
 
27
29
  interface Options {
@@ -43,48 +45,70 @@ interface Options {
43
45
  onEnd?: () => void;
44
46
  }
45
47
 
46
- export const useResize = <T extends HTMLElement = HTMLDivElement>(
48
+ /**
49
+ * Custom hook to handle resizing of an element.
50
+ * It provides a ref to the element and a mouse down event handler to initiate resizing.
51
+ * The resizing is done by tracking mouse movements and calculating the difference in x and y coordinates.
52
+ * It supports both horizontal and vertical resizing, and can be configured to reverse the direction based on RTL (Right-to-Left) layout.
53
+ *
54
+ * @param onResize - Callback function to handle the resize difference.
55
+ * @param options - Options for the resizing behavior.
56
+ * @returns An object containing the ref to the element, a boolean indicating if resizing is in progress, and a mouse down event handler.
57
+ *
58
+ * @example
59
+ * ```jsx
60
+ * const { ref, onMouseDown } = useResize((diff) => {
61
+ * console.log("Resize difference:", diff);
62
+ * }, { isReverse: true, isVertical: false });
63
+ * <div ref={ref} onMouseDown={onMouseDown}>Resize Me</div>
64
+ * ```
65
+ */
66
+ export function useResize<T extends HTMLElement = HTMLDivElement>(
47
67
  onResize: (diff: { x: number; y: number }) => void,
48
68
  { isReverse = false, isVertical = false, onStart, onEnd }: Options,
49
- ): { ref: RefObject<T>; onMouseDown: React.MouseEventHandler } => {
50
- const refEl = useRef<T>(null);
69
+ ): { ref: React.RefObject<T | null>; isResizing: boolean; onMouseDown: React.MouseEventHandler } {
70
+ const elRef = useRef<T>(null);
51
71
  const isRtl = useIsRtl();
72
+ const [isResizing, setIsResizing] = useState(false);
52
73
 
53
- const onResizing = useCallback(
54
- (evt: MouseEvent) => {
55
- if (refEl.current != null) {
56
- /** ***************** check if reverse enabled of RTL *******************/
57
- const reversed = ((isRtl ? 1 : 0) ^ (isReverse ? 1 : 0)) === 1;
58
- const box = refEl.current?.getBoundingClientRect();
59
- const x =
60
- (evt.clientX - (reversed ? box.left : box.right)) *
61
- (reversed ? -1 : 1);
62
- const y = evt.clientY - box.bottom;
63
- onResize({ x, y });
64
- }
65
- },
66
- [onResize, isRtl, isReverse],
67
- );
74
+ const onResizingRef = useRef((evt: MouseEvent) => {
75
+ if (elRef.current != null) {
76
+ /** ***************** check if reverse enabled of RTL *******************/
77
+ const reversed = ((isRtl ? 1 : 0) ^ (isReverse ? 1 : 0)) === 1;
78
+ const box = elRef.current?.getBoundingClientRect();
79
+ const diffX = isReverse ? box.left : box.right;
80
+ const diffY = isReverse ? box.top : box.bottom;
81
+ const x = (evt.clientX - diffX) * (reversed ? -1 : 1);
82
+ const y = (evt.clientY - diffY) * (isReverse ? -1 : 1);
83
+ onResize({ x, y });
84
+ }
85
+ });
68
86
 
69
87
  /** ***************** dettach handlers on mouseup *******************/
70
- const onResizeEnd = useCallback(() => {
88
+ const onResizeEndRef = useRef(() => {
71
89
  document.body.style.cursor = "unset";
72
- document.removeEventListener("mousemove", onResizing);
73
- document.removeEventListener("mouseup", onResizeEnd);
90
+ document.body.style.userSelect = "unset";
91
+ document.removeEventListener("mousemove", onResizingRef.current);
92
+ document.removeEventListener("mouseup", onResizeEndRef.current);
93
+ setIsResizing(false);
74
94
  onEnd?.();
75
- }, [onEnd, onResizing]);
95
+ });
76
96
 
77
97
  /** ***************** attach handlers on mousedown *******************/
78
98
  const onResizeStart = useCallback(
79
99
  (e: React.MouseEvent) => {
100
+ if (e.button !== 0) return;
80
101
  e.preventDefault();
102
+ e.stopPropagation();
103
+ document.body.style.userSelect = "none";
81
104
  document.body.style.cursor = isVertical ? "row-resize" : "col-resize";
82
- document.addEventListener("mousemove", onResizing);
83
- document.addEventListener("mouseup", onResizeEnd);
105
+ document.addEventListener("mousemove", onResizingRef.current);
106
+ document.addEventListener("mouseup", onResizeEndRef.current);
107
+ setIsResizing(true);
84
108
  onStart?.();
85
109
  },
86
- [onResizing, onResizeEnd, onStart],
110
+ [isVertical, onStart],
87
111
  );
88
112
 
89
- return { ref: refEl, onMouseDown: onResizeStart };
90
- };
113
+ return { ref: elRef, isResizing, onMouseDown: onResizeStart };
114
+ }