react-simplikit 0.0.51 → 0.0.53

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 (280) hide show
  1. package/README.md +34 -24
  2. package/dist/components/ImpressionArea/ImpressionArea.cjs +57 -0
  3. package/{esm/components/ImpressionArea/index.d.ts → dist/components/ImpressionArea/ImpressionArea.d.cts} +9 -8
  4. package/dist/components/ImpressionArea/ImpressionArea.d.mts +48 -0
  5. package/dist/components/ImpressionArea/ImpressionArea.mjs +57 -0
  6. package/dist/components/ImpressionArea/index.d.cts +2 -46
  7. package/dist/components/ImpressionArea/index.d.mts +3 -0
  8. package/dist/components/Separated/Separated.cjs +38 -0
  9. package/{esm/components/Separated/index.d.ts → dist/components/Separated/Separated.d.cts} +7 -7
  10. package/dist/components/Separated/Separated.d.mts +38 -0
  11. package/dist/components/Separated/Separated.mjs +38 -0
  12. package/dist/components/Separated/index.d.cts +2 -37
  13. package/dist/components/Separated/index.d.mts +3 -0
  14. package/dist/components/SwitchCase/SwitchCase.cjs +40 -0
  15. package/{esm/components/SwitchCase/index.d.ts → dist/components/SwitchCase/SwitchCase.d.cts} +7 -8
  16. package/dist/components/SwitchCase/SwitchCase.d.mts +45 -0
  17. package/dist/components/SwitchCase/SwitchCase.mjs +40 -0
  18. package/dist/components/SwitchCase/index.d.cts +2 -45
  19. package/dist/components/SwitchCase/index.d.mts +3 -0
  20. package/dist/hooks/useAsyncEffect/index.d.cts +2 -24
  21. package/dist/hooks/useAsyncEffect/index.d.mts +3 -0
  22. package/dist/hooks/useAsyncEffect/useAsyncEffect.cjs +39 -0
  23. package/{esm/hooks/useAsyncEffect/index.d.ts → dist/hooks/useAsyncEffect/useAsyncEffect.d.cts} +4 -3
  24. package/dist/hooks/useAsyncEffect/useAsyncEffect.d.mts +26 -0
  25. package/dist/hooks/useAsyncEffect/useAsyncEffect.mjs +39 -0
  26. package/dist/hooks/useBooleanState/useBooleanState.cjs +36 -0
  27. package/dist/hooks/useBooleanState/{index.d.cts → useBooleanState.d.cts} +4 -2
  28. package/{esm/hooks/useBooleanState/index.d.ts → dist/hooks/useBooleanState/useBooleanState.d.mts} +4 -2
  29. package/dist/hooks/useBooleanState/useBooleanState.mjs +36 -0
  30. package/dist/hooks/useCallbackOncePerRender/index.d.cts +2 -39
  31. package/dist/hooks/useCallbackOncePerRender/index.d.mts +3 -0
  32. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs +52 -0
  33. package/{esm/hooks/useCallbackOncePerRender/index.d.ts → dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.cts} +4 -3
  34. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.mts +41 -0
  35. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs +52 -0
  36. package/dist/hooks/useConditionalEffect/index.d.cts +2 -42
  37. package/dist/hooks/useConditionalEffect/index.d.mts +3 -0
  38. package/dist/hooks/useConditionalEffect/useConditionalEffect.cjs +57 -0
  39. package/{esm/hooks/useConditionalEffect/index.d.ts → dist/hooks/useConditionalEffect/useConditionalEffect.d.cts} +4 -3
  40. package/dist/hooks/useConditionalEffect/useConditionalEffect.d.mts +44 -0
  41. package/dist/hooks/useConditionalEffect/useConditionalEffect.mjs +57 -0
  42. package/dist/hooks/useControlledState/index.d.cts +2 -50
  43. package/dist/hooks/useControlledState/index.d.mts +3 -0
  44. package/dist/hooks/useControlledState/useControlledState.cjs +60 -0
  45. package/{esm/hooks/useControlledState/index.d.ts → dist/hooks/useControlledState/useControlledState.d.cts} +11 -10
  46. package/dist/hooks/useControlledState/useControlledState.d.mts +52 -0
  47. package/dist/hooks/useControlledState/useControlledState.mjs +60 -0
  48. package/dist/hooks/useCounter/useCounter.cjs +75 -0
  49. package/{esm/hooks/useCounter/index.d.ts → dist/hooks/useCounter/useCounter.d.cts} +12 -10
  50. package/dist/hooks/useCounter/{index.d.cts → useCounter.d.mts} +12 -10
  51. package/dist/hooks/useCounter/useCounter.mjs +75 -0
  52. package/dist/hooks/useDebounce/debounce.cjs +49 -0
  53. package/dist/hooks/useDebounce/debounce.d.cts +8 -0
  54. package/dist/hooks/useDebounce/debounce.d.mts +8 -0
  55. package/dist/hooks/useDebounce/debounce.mjs +49 -0
  56. package/dist/hooks/useDebounce/useDebounce.cjs +66 -0
  57. package/{esm/hooks/useDebounce/index.d.ts → dist/hooks/useDebounce/useDebounce.d.cts} +6 -8
  58. package/dist/hooks/useDebounce/{index.d.cts → useDebounce.d.mts} +6 -8
  59. package/dist/hooks/useDebounce/useDebounce.mjs +66 -0
  60. package/dist/hooks/useDebouncedCallback/useDebouncedCallback.cjs +62 -0
  61. package/{esm/hooks/useDebouncedCallback/index.d.ts → dist/hooks/useDebouncedCallback/useDebouncedCallback.d.cts} +9 -7
  62. package/dist/hooks/useDebouncedCallback/{index.d.cts → useDebouncedCallback.d.mts} +9 -7
  63. package/dist/hooks/useDebouncedCallback/useDebouncedCallback.mjs +62 -0
  64. package/dist/hooks/useDoubleClick/index.d.cts +2 -45
  65. package/dist/hooks/useDoubleClick/index.d.mts +3 -0
  66. package/dist/hooks/useDoubleClick/useDoubleClick.cjs +64 -0
  67. package/{esm/hooks/useDoubleClick/index.d.ts → dist/hooks/useDoubleClick/useDoubleClick.d.cts} +8 -7
  68. package/dist/hooks/useDoubleClick/useDoubleClick.d.mts +47 -0
  69. package/dist/hooks/useDoubleClick/useDoubleClick.mjs +64 -0
  70. package/dist/hooks/useGeolocation/useGeolocation.cjs +210 -0
  71. package/{esm/hooks/useGeolocation/index.d.ts → dist/hooks/useGeolocation/useGeolocation.d.cts} +26 -24
  72. package/dist/hooks/useGeolocation/{index.d.cts → useGeolocation.d.mts} +26 -24
  73. package/dist/hooks/useGeolocation/useGeolocation.mjs +209 -0
  74. package/dist/hooks/useImpressionRef/useImpressionRef.cjs +67 -0
  75. package/{esm/hooks/useImpressionRef/index.d.ts → dist/hooks/useImpressionRef/useImpressionRef.d.cts} +10 -8
  76. package/dist/hooks/useImpressionRef/{index.d.cts → useImpressionRef.d.mts} +10 -8
  77. package/dist/hooks/useImpressionRef/useImpressionRef.mjs +67 -0
  78. package/dist/hooks/useInputState/index.d.cts +2 -22
  79. package/dist/hooks/useInputState/index.d.mts +3 -0
  80. package/dist/hooks/useInputState/useInputState.cjs +32 -0
  81. package/{esm/hooks/useInputState/index.d.ts → dist/hooks/useInputState/useInputState.d.cts} +4 -3
  82. package/dist/hooks/useInputState/useInputState.d.mts +24 -0
  83. package/dist/hooks/useInputState/useInputState.mjs +32 -0
  84. package/dist/hooks/useIntersectionObserver/useIntersectionObserver.cjs +58 -0
  85. package/dist/hooks/useIntersectionObserver/{index.d.cts → useIntersectionObserver.d.cts} +4 -2
  86. package/{esm/hooks/useIntersectionObserver/index.d.ts → dist/hooks/useIntersectionObserver/useIntersectionObserver.d.mts} +4 -2
  87. package/dist/hooks/useIntersectionObserver/useIntersectionObserver.mjs +58 -0
  88. package/dist/hooks/useInterval/useInterval.cjs +65 -0
  89. package/dist/hooks/useInterval/{index.d.cts → useInterval.d.cts} +7 -5
  90. package/{esm/hooks/useInterval/index.d.ts → dist/hooks/useInterval/useInterval.d.mts} +7 -5
  91. package/dist/hooks/useInterval/useInterval.mjs +65 -0
  92. package/dist/hooks/useIsClient/useIsClient.cjs +49 -0
  93. package/dist/hooks/useIsClient/{index.d.cts → useIsClient.d.cts} +4 -2
  94. package/{esm/hooks/useIsClient/index.d.ts → dist/hooks/useIsClient/useIsClient.d.mts} +4 -2
  95. package/dist/hooks/useIsClient/useIsClient.mjs +49 -0
  96. package/dist/hooks/useIsomorphicLayoutEffect/index.d.cts +2 -24
  97. package/dist/hooks/useIsomorphicLayoutEffect/index.d.mts +3 -0
  98. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs +25 -0
  99. package/{esm/hooks/useIsomorphicLayoutEffect/index.d.ts → dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.cts} +4 -3
  100. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.mts +26 -0
  101. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +25 -0
  102. package/dist/hooks/useList/useList.cjs +94 -0
  103. package/{esm/hooks/useList/index.d.ts → dist/hooks/useList/useList.d.cts} +10 -8
  104. package/dist/hooks/useList/{index.d.cts → useList.d.mts} +10 -8
  105. package/dist/hooks/useList/useList.mjs +94 -0
  106. package/dist/hooks/useLoading/useLoading.cjs +61 -0
  107. package/dist/hooks/useLoading/{index.d.cts → useLoading.d.cts} +4 -2
  108. package/{esm/hooks/useLoading/index.d.ts → dist/hooks/useLoading/useLoading.d.mts} +4 -2
  109. package/dist/hooks/useLoading/useLoading.mjs +61 -0
  110. package/dist/hooks/useLongPress/index.d.cts +2 -73
  111. package/dist/hooks/useLongPress/index.d.mts +3 -0
  112. package/dist/hooks/useLongPress/useLongPress.cjs +133 -0
  113. package/{esm/hooks/useLongPress/index.d.ts → dist/hooks/useLongPress/useLongPress.d.cts} +18 -17
  114. package/dist/hooks/useLongPress/useLongPress.d.mts +75 -0
  115. package/dist/hooks/useLongPress/useLongPress.mjs +133 -0
  116. package/dist/hooks/useMap/useMap.cjs +64 -0
  117. package/dist/hooks/useMap/{index.d.cts → useMap.d.cts} +12 -10
  118. package/{esm/hooks/useMap/index.d.ts → dist/hooks/useMap/useMap.d.mts} +12 -10
  119. package/dist/hooks/useMap/useMap.mjs +64 -0
  120. package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.cjs +51 -0
  121. package/dist/hooks/useOutsideClickEffect/{index.d.cts → useOutsideClickEffect.d.cts} +4 -2
  122. package/{esm/hooks/useOutsideClickEffect/index.d.ts → dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.mts} +4 -2
  123. package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.mjs +51 -0
  124. package/dist/hooks/usePreservedCallback/usePreservedCallback.cjs +41 -0
  125. package/dist/hooks/usePreservedCallback/{index.d.cts → usePreservedCallback.d.cts} +4 -2
  126. package/{esm/hooks/usePreservedCallback/index.d.ts → dist/hooks/usePreservedCallback/usePreservedCallback.d.mts} +4 -2
  127. package/dist/hooks/usePreservedCallback/usePreservedCallback.mjs +41 -0
  128. package/dist/hooks/usePreservedReference/usePreservedReference.cjs +55 -0
  129. package/dist/hooks/usePreservedReference/{index.d.cts → usePreservedReference.d.cts} +4 -2
  130. package/{esm/hooks/usePreservedReference/index.d.ts → dist/hooks/usePreservedReference/usePreservedReference.d.mts} +4 -2
  131. package/dist/hooks/usePreservedReference/usePreservedReference.mjs +55 -0
  132. package/dist/hooks/usePrevious/usePrevious.cjs +39 -0
  133. package/{esm/hooks/usePrevious/index.d.ts → dist/hooks/usePrevious/usePrevious.d.cts} +4 -2
  134. package/dist/hooks/usePrevious/{index.d.cts → usePrevious.d.mts} +4 -2
  135. package/dist/hooks/usePrevious/usePrevious.mjs +39 -0
  136. package/dist/hooks/useRefEffect/index.d.cts +2 -30
  137. package/dist/hooks/useRefEffect/index.d.mts +3 -0
  138. package/dist/hooks/useRefEffect/useRefEffect.cjs +42 -0
  139. package/{esm/hooks/useRefEffect/index.d.ts → dist/hooks/useRefEffect/useRefEffect.d.cts} +4 -3
  140. package/dist/hooks/useRefEffect/useRefEffect.d.mts +32 -0
  141. package/dist/hooks/useRefEffect/useRefEffect.mjs +42 -0
  142. package/dist/hooks/useSet/useSet.cjs +79 -0
  143. package/dist/hooks/useSet/{index.d.cts → useSet.d.cts} +9 -7
  144. package/{esm/hooks/useSet/index.d.ts → dist/hooks/useSet/useSet.d.mts} +9 -7
  145. package/dist/hooks/useSet/useSet.mjs +79 -0
  146. package/dist/hooks/useStorageState/index.d.cts +2 -60
  147. package/dist/hooks/useStorageState/index.d.mts +3 -0
  148. package/dist/hooks/useStorageState/storage.cjs +85 -0
  149. package/dist/hooks/useStorageState/storage.d.cts +10 -0
  150. package/dist/hooks/useStorageState/storage.d.mts +10 -0
  151. package/dist/hooks/useStorageState/storage.mjs +80 -0
  152. package/dist/hooks/useStorageState/useStorageState.cjs +81 -0
  153. package/{esm/hooks/useStorageState/index.d.ts → dist/hooks/useStorageState/useStorageState.d.cts} +10 -15
  154. package/dist/hooks/useStorageState/useStorageState.d.mts +56 -0
  155. package/dist/hooks/useStorageState/useStorageState.mjs +81 -0
  156. package/dist/hooks/useThrottle/throttle.cjs +19 -0
  157. package/dist/hooks/useThrottle/throttle.d.cts +19 -0
  158. package/dist/hooks/useThrottle/throttle.d.mts +19 -0
  159. package/dist/hooks/useThrottle/throttle.mjs +19 -0
  160. package/dist/hooks/useThrottle/useThrottle.cjs +49 -0
  161. package/dist/hooks/useThrottle/{index.d.cts → useThrottle.d.cts} +6 -19
  162. package/{esm/hooks/useThrottle/index.d.ts → dist/hooks/useThrottle/useThrottle.d.mts} +6 -19
  163. package/dist/hooks/useThrottle/useThrottle.mjs +49 -0
  164. package/dist/hooks/useThrottledCallback/useThrottledCallback.cjs +65 -0
  165. package/{esm/hooks/useThrottledCallback/index.d.ts → dist/hooks/useThrottledCallback/useThrottledCallback.d.cts} +8 -6
  166. package/dist/hooks/useThrottledCallback/{index.d.cts → useThrottledCallback.d.mts} +8 -6
  167. package/dist/hooks/useThrottledCallback/useThrottledCallback.mjs +65 -0
  168. package/dist/hooks/useTimeout/useTimeout.cjs +40 -0
  169. package/dist/hooks/useTimeout/{index.d.cts → useTimeout.d.cts} +4 -2
  170. package/{esm/hooks/useTimeout/index.d.ts → dist/hooks/useTimeout/useTimeout.d.mts} +4 -2
  171. package/dist/hooks/useTimeout/useTimeout.mjs +40 -0
  172. package/dist/hooks/useToggle/useToggle.cjs +34 -0
  173. package/dist/hooks/useToggle/{index.d.cts → useToggle.d.cts} +4 -4
  174. package/{esm/hooks/useToggle/index.d.ts → dist/hooks/useToggle/useToggle.d.mts} +4 -4
  175. package/dist/hooks/useToggle/useToggle.mjs +34 -0
  176. package/dist/hooks/useVisibilityEvent/useVisibilityEvent.cjs +42 -0
  177. package/{esm/hooks/useVisibilityEvent/index.d.ts → dist/hooks/useVisibilityEvent/useVisibilityEvent.d.cts} +5 -3
  178. package/dist/hooks/useVisibilityEvent/{index.d.cts → useVisibilityEvent.d.mts} +5 -3
  179. package/dist/hooks/useVisibilityEvent/useVisibilityEvent.mjs +42 -0
  180. package/dist/index.cjs +77 -1397
  181. package/dist/index.d.cts +56 -40
  182. package/dist/index.d.mts +56 -0
  183. package/dist/index.mjs +40 -0
  184. package/dist/utils/buildContext/buildContext.cjs +50 -0
  185. package/{esm/utils/buildContext/index.d.ts → dist/utils/buildContext/buildContext.d.cts} +7 -7
  186. package/dist/utils/buildContext/buildContext.d.mts +38 -0
  187. package/dist/utils/buildContext/buildContext.mjs +50 -0
  188. package/dist/utils/buildContext/index.d.cts +2 -37
  189. package/dist/utils/buildContext/index.d.mts +3 -0
  190. package/dist/utils/mergeProps/index.d.cts +2 -25
  191. package/dist/utils/mergeProps/index.d.mts +3 -0
  192. package/dist/utils/mergeProps/mergeProps.cjs +53 -0
  193. package/{esm/utils/mergeProps/index.d.ts → dist/utils/mergeProps/mergeProps.d.cts} +7 -8
  194. package/dist/utils/mergeProps/mergeProps.d.mts +25 -0
  195. package/dist/utils/mergeProps/mergeProps.mjs +53 -0
  196. package/dist/utils/mergeRefs/index.d.cts +2 -38
  197. package/dist/utils/mergeRefs/index.d.mts +3 -0
  198. package/dist/utils/mergeRefs/mergeRefs.cjs +50 -0
  199. package/{esm/utils/mergeRefs/index.d.ts → dist/utils/mergeRefs/mergeRefs.d.cts} +4 -3
  200. package/dist/utils/mergeRefs/mergeRefs.d.mts +40 -0
  201. package/dist/utils/mergeRefs/mergeRefs.mjs +50 -0
  202. package/package.json +9 -11
  203. package/dist/components/ImpressionArea/index.cjs +0 -295
  204. package/dist/components/Separated/index.cjs +0 -41
  205. package/dist/components/SwitchCase/index.cjs +0 -36
  206. package/dist/hooks/useAsyncEffect/index.cjs +0 -49
  207. package/dist/hooks/useBooleanState/index.cjs +0 -46
  208. package/dist/hooks/useCallbackOncePerRender/index.cjs +0 -63
  209. package/dist/hooks/useConditionalEffect/index.cjs +0 -51
  210. package/dist/hooks/useControlledState/index.cjs +0 -57
  211. package/dist/hooks/useCounter/index.cjs +0 -70
  212. package/dist/hooks/useDebounce/index.cjs +0 -130
  213. package/dist/hooks/useDebouncedCallback/index.cjs +0 -148
  214. package/dist/hooks/useDoubleClick/index.cjs +0 -79
  215. package/dist/hooks/useGeolocation/index.cjs +0 -154
  216. package/dist/hooks/useImpressionRef/index.cjs +0 -258
  217. package/dist/hooks/useInputState/index.cjs +0 -46
  218. package/dist/hooks/useIntersectionObserver/index.cjs +0 -95
  219. package/dist/hooks/useInterval/index.cjs +0 -84
  220. package/dist/hooks/useIsClient/index.cjs +0 -40
  221. package/dist/hooks/useIsomorphicLayoutEffect/index.cjs +0 -35
  222. package/dist/hooks/useList/index.cjs +0 -104
  223. package/dist/hooks/useLoading/index.cjs +0 -65
  224. package/dist/hooks/useLongPress/index.cjs +0 -127
  225. package/dist/hooks/useMap/index.cjs +0 -78
  226. package/dist/hooks/useOutsideClickEffect/index.cjs +0 -74
  227. package/dist/hooks/usePreservedCallback/index.cjs +0 -45
  228. package/dist/hooks/usePreservedReference/index.cjs +0 -45
  229. package/dist/hooks/usePrevious/index.cjs +0 -48
  230. package/dist/hooks/useRefEffect/index.cjs +0 -72
  231. package/dist/hooks/useSet/index.cjs +0 -105
  232. package/dist/hooks/useStorageState/index.cjs +0 -196
  233. package/dist/hooks/useThrottle/index.cjs +0 -151
  234. package/dist/hooks/useThrottledCallback/index.cjs +0 -172
  235. package/dist/hooks/useTimeout/index.cjs +0 -57
  236. package/dist/hooks/useToggle/index.cjs +0 -37
  237. package/dist/hooks/useVisibilityEvent/index.cjs +0 -47
  238. package/dist/utils/buildContext/index.cjs +0 -56
  239. package/dist/utils/mergeProps/index.cjs +0 -71
  240. package/dist/utils/mergeRefs/index.cjs +0 -46
  241. package/esm/components/ImpressionArea/index.js +0 -269
  242. package/esm/components/Separated/index.js +0 -15
  243. package/esm/components/SwitchCase/index.js +0 -10
  244. package/esm/hooks/useAsyncEffect/index.js +0 -23
  245. package/esm/hooks/useBooleanState/index.js +0 -20
  246. package/esm/hooks/useCallbackOncePerRender/index.js +0 -37
  247. package/esm/hooks/useConditionalEffect/index.js +0 -25
  248. package/esm/hooks/useControlledState/index.js +0 -31
  249. package/esm/hooks/useCounter/index.js +0 -44
  250. package/esm/hooks/useDebounce/index.js +0 -104
  251. package/esm/hooks/useDebouncedCallback/index.js +0 -122
  252. package/esm/hooks/useDoubleClick/index.js +0 -53
  253. package/esm/hooks/useGeolocation/index.js +0 -128
  254. package/esm/hooks/useImpressionRef/index.js +0 -232
  255. package/esm/hooks/useInputState/index.js +0 -20
  256. package/esm/hooks/useIntersectionObserver/index.js +0 -69
  257. package/esm/hooks/useInterval/index.js +0 -58
  258. package/esm/hooks/useIsClient/index.js +0 -14
  259. package/esm/hooks/useIsomorphicLayoutEffect/index.js +0 -9
  260. package/esm/hooks/useList/index.js +0 -78
  261. package/esm/hooks/useLoading/index.js +0 -39
  262. package/esm/hooks/useLongPress/index.js +0 -101
  263. package/esm/hooks/useMap/index.js +0 -52
  264. package/esm/hooks/useOutsideClickEffect/index.js +0 -48
  265. package/esm/hooks/usePreservedCallback/index.js +0 -19
  266. package/esm/hooks/usePreservedReference/index.js +0 -19
  267. package/esm/hooks/usePrevious/index.js +0 -22
  268. package/esm/hooks/useRefEffect/index.js +0 -46
  269. package/esm/hooks/useSet/index.js +0 -79
  270. package/esm/hooks/useStorageState/index.js +0 -170
  271. package/esm/hooks/useThrottle/index.js +0 -125
  272. package/esm/hooks/useThrottledCallback/index.js +0 -146
  273. package/esm/hooks/useTimeout/index.js +0 -31
  274. package/esm/hooks/useToggle/index.js +0 -11
  275. package/esm/hooks/useVisibilityEvent/index.js +0 -21
  276. package/esm/index.d.ts +0 -40
  277. package/esm/index.js +0 -1335
  278. package/esm/utils/buildContext/index.js +0 -30
  279. package/esm/utils/mergeProps/index.js +0 -45
  280. package/esm/utils/mergeRefs/index.js +0 -20
package/README.md CHANGED
@@ -27,7 +27,7 @@ We are repositioning react-simplikit to focus exclusively on **platform-independ
27
27
  Hooks that don't depend on specific platform APIs will continue to be actively maintained:
28
28
 
29
29
  - State management hooks like `useToggle`, `useBooleanState`, `useCounter`
30
- - Lifecycle hooks like `usePrevious`, `useMount`
30
+ - Lifecycle hooks like `usePrevious`
31
31
  - Utility hooks like `useDebounce`, `useThrottle`
32
32
  - **Backward compatibility (BC) is preserved** for these existing pure logic hooks
33
33
 
@@ -69,37 +69,46 @@ pnpm add react-simplikit
69
69
  ## Quick Start
70
70
 
71
71
  ```tsx
72
- import { useState, useEffect } from 'react';
72
+ import { useState } from 'react';
73
73
  import { useDebounce } from 'react-simplikit';
74
74
 
75
75
  function SearchInput() {
76
76
  const [query, setQuery] = useState('');
77
- const debouncedQuery = useDebounce(query, 300);
78
77
 
79
- useEffect(() => {
80
- if (debouncedQuery) {
81
- searchAPI(debouncedQuery);
82
- }
83
- }, [debouncedQuery]);
84
-
85
- return <input value={query} onChange={e => setQuery(e.target.value)} />;
78
+ const debouncedSearch = useDebounce((value: string) => {
79
+ // Actual API call
80
+ searchAPI(value);
81
+ }, 300);
82
+
83
+ return (
84
+ <input
85
+ value={query}
86
+ onChange={e => {
87
+ setQuery(e.target.value);
88
+ debouncedSearch(e.target.value);
89
+ }}
90
+ placeholder="Enter search term"
91
+ />
92
+ );
86
93
  }
87
94
  ```
88
95
 
96
+ The debounced function exposes `.cancel()`, and pending calls are cancelled automatically when the component unmounts.
97
+
89
98
  ## What's Included
90
99
 
91
100
  ### Hooks
92
101
 
93
- | Hook | Description |
94
- | ------------------------- | --------------------------------------------------- |
95
- | `useBooleanState` | Manage boolean state with handlers |
96
- | `useDebounce` | Debounce a value |
97
- | `useDebouncedCallback` | Debounce a callback function |
98
- | `useInterval` | Set up intervals declaratively |
99
- | `useIntersectionObserver` | Observe element visibility |
100
- | `usePreservedCallback` | Stable callback reference |
101
- | `usePreservedReference` | Stable object reference |
102
- | ... | [See all hooks](https://react-simplikit.slash.page) |
102
+ | Hook | Description |
103
+ | ------------------------- | ----------------------------------------------------- |
104
+ | `useBooleanState` | Manage boolean state with handlers |
105
+ | `useDebounce` | Debounce a callback function |
106
+ | `useDebouncedCallback` | Debounce an `onChange` callback via an options object |
107
+ | `useInterval` | Set up intervals declaratively |
108
+ | `useIntersectionObserver` | Observe element visibility |
109
+ | `usePreservedCallback` | Stable callback reference |
110
+ | `usePreservedReference` | Stable object reference |
111
+ | ... | [See all hooks](https://react-simplikit.slash.page) |
103
112
 
104
113
  ### Components
105
114
 
@@ -111,10 +120,11 @@ function SearchInput() {
111
120
 
112
121
  ### Utilities
113
122
 
114
- | Utility | Description |
115
- | -------- | ----------------- |
116
- | `assert` | Runtime assertion |
117
- | `noop` | Empty function |
123
+ | Utility | Description |
124
+ | -------------- | --------------------------------------------------- |
125
+ | `buildContext` | Define React Context with less boilerplate |
126
+ | `mergeProps` | Merge props, composing `className`, `style`, events |
127
+ | `mergeRefs` | Combine multiple refs into a single ref |
118
128
 
119
129
  ## Documentation
120
130
 
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ const require_useImpressionRef = require("../../hooks/useImpressionRef/useImpressionRef.cjs");
3
+ const require_mergeRefs = require("../../utils/mergeRefs/mergeRefs.cjs");
4
+ let react = require("react");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ //#region src/components/ImpressionArea/ImpressionArea.tsx
7
+ /**
8
+ * @description
9
+ * `ImpressionArea` is a component that measures the time a specific DOM element is visible on the screen
10
+ * and executes callbacks when the element enters or exits the viewport. This component uses the `useImpressionRef`
11
+ * hook to track the element's visibility.
12
+ *
13
+ * @template {ElementType} T - The HTML tag to render. Defaults to `div`.
14
+ * @param {T} [as='div'] - The HTML tag to render. Defaults to `div`.
15
+ * @param {string} [rootMargin] - Margin to adjust the detection area.
16
+ * @param {number} [areaThreshold] - Minimum ratio of the element that must be visible (0 to 1).
17
+ * @param {number} [timeThreshold] - Minimum time the element must be visible (in milliseconds).
18
+ * @param {() => void} [onImpressionStart] - Callback function executed when the element enters the view.
19
+ * @param {() => void} [onImpressionEnd] - Callback function executed when the element exits the view.
20
+ * @param {Ref<Element<T>>} [ref] - Reference to the element.
21
+ * @param {React.ReactNode} [children] - Child elements to be rendered inside the component.
22
+ * @param {string} [className] - Additional class names for styling.
23
+ *
24
+ * @returns {JSX.Element} A React component that tracks the visibility of its child elements.
25
+ *
26
+ * @example
27
+ * function App() {
28
+ * return (
29
+ * <ImpressionArea
30
+ * onImpressionStart={() => console.log('Element entered view')}
31
+ * onImpressionEnd={() => console.log('Element exited view')}
32
+ * timeThreshold={1000}
33
+ * areaThreshold={0.5}
34
+ * >
35
+ * <div>Track me!</div>
36
+ * </ImpressionArea>
37
+ * );
38
+ * }
39
+ */
40
+ const ImpressionArea = (0, react.forwardRef)(ImpressionAreaImpl);
41
+ function ImpressionAreaImpl({ as, rootMargin, areaThreshold, timeThreshold, onImpressionStart, onImpressionEnd, ...props }, ref) {
42
+ const Component = as ?? "div";
43
+ const impressionRef = require_useImpressionRef.useImpressionRef({
44
+ onImpressionStart,
45
+ onImpressionEnd,
46
+ areaThreshold,
47
+ timeThreshold,
48
+ rootMargin
49
+ });
50
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Component, {
51
+ ref: require_mergeRefs.mergeRefs(ref, impressionRef),
52
+ ...props
53
+ });
54
+ }
55
+ Object.assign(ImpressionArea, { displayName: "ImpressionArea" });
56
+ //#endregion
57
+ exports.ImpressionArea = ImpressionArea;
@@ -1,11 +1,12 @@
1
- import { ElementType, ReactNode, Ref } from 'react';
2
- import { UseImpressionRefOptions } from '../../hooks/useImpressionRef/index.js';
3
1
 
2
+ import { UseImpressionRefOptions } from "../../hooks/useImpressionRef/useImpressionRef.cjs";
3
+ import { ElementType, ReactNode, Ref } from "react";
4
+ //#region src/components/ImpressionArea/ImpressionArea.d.ts
4
5
  type Element<T extends ElementType, IntrinsicElementsOf = T extends keyof React.JSX.IntrinsicElements ? React.JSX.IntrinsicElements[T] : HTMLElement> = IntrinsicElementsOf extends React.ClassAttributes<infer E extends HTMLElement> ? E : HTMLElement;
5
6
  type Props<Tag extends ElementType> = React.ComponentPropsWithoutRef<Tag> & UseImpressionRefOptions & {
6
- as?: Tag;
7
- children?: ReactNode;
8
- className?: string;
7
+ as?: Tag;
8
+ children?: ReactNode;
9
+ className?: string;
9
10
  };
10
11
  /**
11
12
  * @description
@@ -41,7 +42,7 @@ type Props<Tag extends ElementType> = React.ComponentPropsWithoutRef<Tag> & UseI
41
42
  * }
42
43
  */
43
44
  declare const ImpressionArea: <T extends ElementType = "div">(props: Props<T> & {
44
- ref?: Ref<Element<T>>;
45
+ ref?: Ref<Element<T>>;
45
46
  }) => React.ReactElement;
46
-
47
- export { ImpressionArea };
47
+ //#endregion
48
+ export { ImpressionArea };
@@ -0,0 +1,48 @@
1
+
2
+ import { UseImpressionRefOptions } from "../../hooks/useImpressionRef/useImpressionRef.mjs";
3
+ import { ElementType, ReactNode, Ref } from "react";
4
+ //#region src/components/ImpressionArea/ImpressionArea.d.ts
5
+ type Element<T extends ElementType, IntrinsicElementsOf = T extends keyof React.JSX.IntrinsicElements ? React.JSX.IntrinsicElements[T] : HTMLElement> = IntrinsicElementsOf extends React.ClassAttributes<infer E extends HTMLElement> ? E : HTMLElement;
6
+ type Props<Tag extends ElementType> = React.ComponentPropsWithoutRef<Tag> & UseImpressionRefOptions & {
7
+ as?: Tag;
8
+ children?: ReactNode;
9
+ className?: string;
10
+ };
11
+ /**
12
+ * @description
13
+ * `ImpressionArea` is a component that measures the time a specific DOM element is visible on the screen
14
+ * and executes callbacks when the element enters or exits the viewport. This component uses the `useImpressionRef`
15
+ * hook to track the element's visibility.
16
+ *
17
+ * @template {ElementType} T - The HTML tag to render. Defaults to `div`.
18
+ * @param {T} [as='div'] - The HTML tag to render. Defaults to `div`.
19
+ * @param {string} [rootMargin] - Margin to adjust the detection area.
20
+ * @param {number} [areaThreshold] - Minimum ratio of the element that must be visible (0 to 1).
21
+ * @param {number} [timeThreshold] - Minimum time the element must be visible (in milliseconds).
22
+ * @param {() => void} [onImpressionStart] - Callback function executed when the element enters the view.
23
+ * @param {() => void} [onImpressionEnd] - Callback function executed when the element exits the view.
24
+ * @param {Ref<Element<T>>} [ref] - Reference to the element.
25
+ * @param {React.ReactNode} [children] - Child elements to be rendered inside the component.
26
+ * @param {string} [className] - Additional class names for styling.
27
+ *
28
+ * @returns {JSX.Element} A React component that tracks the visibility of its child elements.
29
+ *
30
+ * @example
31
+ * function App() {
32
+ * return (
33
+ * <ImpressionArea
34
+ * onImpressionStart={() => console.log('Element entered view')}
35
+ * onImpressionEnd={() => console.log('Element exited view')}
36
+ * timeThreshold={1000}
37
+ * areaThreshold={0.5}
38
+ * >
39
+ * <div>Track me!</div>
40
+ * </ImpressionArea>
41
+ * );
42
+ * }
43
+ */
44
+ declare const ImpressionArea: <T extends ElementType = "div">(props: Props<T> & {
45
+ ref?: Ref<Element<T>>;
46
+ }) => React.ReactElement;
47
+ //#endregion
48
+ export { ImpressionArea };
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import { useImpressionRef } from "../../hooks/useImpressionRef/useImpressionRef.mjs";
3
+ import { mergeRefs } from "../../utils/mergeRefs/mergeRefs.mjs";
4
+ import { forwardRef } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ //#region src/components/ImpressionArea/ImpressionArea.tsx
7
+ /**
8
+ * @description
9
+ * `ImpressionArea` is a component that measures the time a specific DOM element is visible on the screen
10
+ * and executes callbacks when the element enters or exits the viewport. This component uses the `useImpressionRef`
11
+ * hook to track the element's visibility.
12
+ *
13
+ * @template {ElementType} T - The HTML tag to render. Defaults to `div`.
14
+ * @param {T} [as='div'] - The HTML tag to render. Defaults to `div`.
15
+ * @param {string} [rootMargin] - Margin to adjust the detection area.
16
+ * @param {number} [areaThreshold] - Minimum ratio of the element that must be visible (0 to 1).
17
+ * @param {number} [timeThreshold] - Minimum time the element must be visible (in milliseconds).
18
+ * @param {() => void} [onImpressionStart] - Callback function executed when the element enters the view.
19
+ * @param {() => void} [onImpressionEnd] - Callback function executed when the element exits the view.
20
+ * @param {Ref<Element<T>>} [ref] - Reference to the element.
21
+ * @param {React.ReactNode} [children] - Child elements to be rendered inside the component.
22
+ * @param {string} [className] - Additional class names for styling.
23
+ *
24
+ * @returns {JSX.Element} A React component that tracks the visibility of its child elements.
25
+ *
26
+ * @example
27
+ * function App() {
28
+ * return (
29
+ * <ImpressionArea
30
+ * onImpressionStart={() => console.log('Element entered view')}
31
+ * onImpressionEnd={() => console.log('Element exited view')}
32
+ * timeThreshold={1000}
33
+ * areaThreshold={0.5}
34
+ * >
35
+ * <div>Track me!</div>
36
+ * </ImpressionArea>
37
+ * );
38
+ * }
39
+ */
40
+ const ImpressionArea = forwardRef(ImpressionAreaImpl);
41
+ function ImpressionAreaImpl({ as, rootMargin, areaThreshold, timeThreshold, onImpressionStart, onImpressionEnd, ...props }, ref) {
42
+ const Component = as ?? "div";
43
+ const impressionRef = useImpressionRef({
44
+ onImpressionStart,
45
+ onImpressionEnd,
46
+ areaThreshold,
47
+ timeThreshold,
48
+ rootMargin
49
+ });
50
+ return /* @__PURE__ */ jsx(Component, {
51
+ ref: mergeRefs(ref, impressionRef),
52
+ ...props
53
+ });
54
+ }
55
+ Object.assign(ImpressionArea, { displayName: "ImpressionArea" });
56
+ //#endregion
57
+ export { ImpressionArea };
@@ -1,47 +1,3 @@
1
- import { ElementType, ReactNode, Ref } from 'react';
2
- import { UseImpressionRefOptions } from '../../hooks/useImpressionRef/index.cjs';
3
1
 
4
- type Element<T extends ElementType, IntrinsicElementsOf = T extends keyof React.JSX.IntrinsicElements ? React.JSX.IntrinsicElements[T] : HTMLElement> = IntrinsicElementsOf extends React.ClassAttributes<infer E extends HTMLElement> ? E : HTMLElement;
5
- type Props<Tag extends ElementType> = React.ComponentPropsWithoutRef<Tag> & UseImpressionRefOptions & {
6
- as?: Tag;
7
- children?: ReactNode;
8
- className?: string;
9
- };
10
- /**
11
- * @description
12
- * `ImpressionArea` is a component that measures the time a specific DOM element is visible on the screen
13
- * and executes callbacks when the element enters or exits the viewport. This component uses the `useImpressionRef`
14
- * hook to track the element's visibility.
15
- *
16
- * @template {ElementType} T - The HTML tag to render. Defaults to `div`.
17
- * @param {T} [as='div'] - The HTML tag to render. Defaults to `div`.
18
- * @param {string} [rootMargin] - Margin to adjust the detection area.
19
- * @param {number} [areaThreshold] - Minimum ratio of the element that must be visible (0 to 1).
20
- * @param {number} [timeThreshold] - Minimum time the element must be visible (in milliseconds).
21
- * @param {() => void} [onImpressionStart] - Callback function executed when the element enters the view.
22
- * @param {() => void} [onImpressionEnd] - Callback function executed when the element exits the view.
23
- * @param {Ref<Element<T>>} [ref] - Reference to the element.
24
- * @param {React.ReactNode} [children] - Child elements to be rendered inside the component.
25
- * @param {string} [className] - Additional class names for styling.
26
- *
27
- * @returns {JSX.Element} A React component that tracks the visibility of its child elements.
28
- *
29
- * @example
30
- * function App() {
31
- * return (
32
- * <ImpressionArea
33
- * onImpressionStart={() => console.log('Element entered view')}
34
- * onImpressionEnd={() => console.log('Element exited view')}
35
- * timeThreshold={1000}
36
- * areaThreshold={0.5}
37
- * >
38
- * <div>Track me!</div>
39
- * </ImpressionArea>
40
- * );
41
- * }
42
- */
43
- declare const ImpressionArea: <T extends ElementType = "div">(props: Props<T> & {
44
- ref?: Ref<Element<T>>;
45
- }) => React.ReactElement;
46
-
47
- export { ImpressionArea };
2
+ import { ImpressionArea } from "./ImpressionArea.cjs";
3
+ export { ImpressionArea };
@@ -0,0 +1,3 @@
1
+
2
+ import { ImpressionArea } from "./ImpressionArea.mjs";
3
+ export { ImpressionArea };
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ let react = require("react");
3
+ let react_jsx_runtime = require("react/jsx-runtime");
4
+ //#region src/components/Separated/Separated.tsx
5
+ /**
6
+ * @description
7
+ * `Separated` is a component that inserts a specified component between each child element.
8
+ * It is useful for adding separators, spacing, or other repeating elements in lists.
9
+ *
10
+ * @param {React.ReactNode} children - The child elements to render.
11
+ * Only valid React elements (`React.isValidElement`) will be rendered.
12
+ * @param {React.ReactNode} by - The component to insert between child elements.
13
+ *
14
+ * @returns {JSX.Element} A React component that separates children with a specified separator.
15
+ *
16
+ * @example
17
+ * function App() {
18
+ * return (
19
+ * <Separated by={<Border type="padding24" />}>
20
+ * {['hello', 'react', 'world'].map(item => (
21
+ * <div key={item}>{item}</div>
22
+ * ))}
23
+ * </Separated>
24
+ * );
25
+ * // Expected output:
26
+ * // <div>hello</div>
27
+ * // <Border type="padding24" />
28
+ * // <div>react</div>
29
+ * // <Border type="padding24" />
30
+ * // <div>world</div>
31
+ * }
32
+ */
33
+ function Separated({ children, by: separator }) {
34
+ const childrenArray = react.Children.toArray(children).filter(react.isValidElement);
35
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.Fragment, { children: [child, i + 1 !== length && separator] }, child.key)) });
36
+ }
37
+ //#endregion
38
+ exports.Separated = Separated;
@@ -1,9 +1,9 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
1
 
2
+ import { ReactNode } from "react";
3
+ //#region src/components/Separated/Separated.d.ts
4
4
  type Props = {
5
- by: ReactNode;
6
- children: ReactNode;
5
+ by: ReactNode;
6
+ children: ReactNode;
7
7
  };
8
8
  /**
9
9
  * @description
@@ -33,6 +33,6 @@ type Props = {
33
33
  * // <div>world</div>
34
34
  * }
35
35
  */
36
- declare function Separated({ children, by: separator }: Props): react_jsx_runtime.JSX.Element;
37
-
38
- export { Separated };
36
+ declare function Separated({ children, by: separator }: Props): import("react/jsx-runtime").JSX.Element;
37
+ //#endregion
38
+ export { Separated };
@@ -0,0 +1,38 @@
1
+
2
+ import { ReactNode } from "react";
3
+ //#region src/components/Separated/Separated.d.ts
4
+ type Props = {
5
+ by: ReactNode;
6
+ children: ReactNode;
7
+ };
8
+ /**
9
+ * @description
10
+ * `Separated` is a component that inserts a specified component between each child element.
11
+ * It is useful for adding separators, spacing, or other repeating elements in lists.
12
+ *
13
+ * @param {React.ReactNode} children - The child elements to render.
14
+ * Only valid React elements (`React.isValidElement`) will be rendered.
15
+ * @param {React.ReactNode} by - The component to insert between child elements.
16
+ *
17
+ * @returns {JSX.Element} A React component that separates children with a specified separator.
18
+ *
19
+ * @example
20
+ * function App() {
21
+ * return (
22
+ * <Separated by={<Border type="padding24" />}>
23
+ * {['hello', 'react', 'world'].map(item => (
24
+ * <div key={item}>{item}</div>
25
+ * ))}
26
+ * </Separated>
27
+ * );
28
+ * // Expected output:
29
+ * // <div>hello</div>
30
+ * // <Border type="padding24" />
31
+ * // <div>react</div>
32
+ * // <Border type="padding24" />
33
+ * // <div>world</div>
34
+ * }
35
+ */
36
+ declare function Separated({ children, by: separator }: Props): import("react/jsx-runtime").JSX.Element;
37
+ //#endregion
38
+ export { Separated };
@@ -0,0 +1,38 @@
1
+ "use client";
2
+ import { Children, Fragment, isValidElement } from "react";
3
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
4
+ //#region src/components/Separated/Separated.tsx
5
+ /**
6
+ * @description
7
+ * `Separated` is a component that inserts a specified component between each child element.
8
+ * It is useful for adding separators, spacing, or other repeating elements in lists.
9
+ *
10
+ * @param {React.ReactNode} children - The child elements to render.
11
+ * Only valid React elements (`React.isValidElement`) will be rendered.
12
+ * @param {React.ReactNode} by - The component to insert between child elements.
13
+ *
14
+ * @returns {JSX.Element} A React component that separates children with a specified separator.
15
+ *
16
+ * @example
17
+ * function App() {
18
+ * return (
19
+ * <Separated by={<Border type="padding24" />}>
20
+ * {['hello', 'react', 'world'].map(item => (
21
+ * <div key={item}>{item}</div>
22
+ * ))}
23
+ * </Separated>
24
+ * );
25
+ * // Expected output:
26
+ * // <div>hello</div>
27
+ * // <Border type="padding24" />
28
+ * // <div>react</div>
29
+ * // <Border type="padding24" />
30
+ * // <div>world</div>
31
+ * }
32
+ */
33
+ function Separated({ children, by: separator }) {
34
+ const childrenArray = Children.toArray(children).filter(isValidElement);
35
+ return /* @__PURE__ */ jsx(Fragment$1, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ jsxs(Fragment, { children: [child, i + 1 !== length && separator] }, child.key)) });
36
+ }
37
+ //#endregion
38
+ export { Separated };
@@ -1,38 +1,3 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
1
 
4
- type Props = {
5
- by: ReactNode;
6
- children: ReactNode;
7
- };
8
- /**
9
- * @description
10
- * `Separated` is a component that inserts a specified component between each child element.
11
- * It is useful for adding separators, spacing, or other repeating elements in lists.
12
- *
13
- * @param {React.ReactNode} children - The child elements to render.
14
- * Only valid React elements (`React.isValidElement`) will be rendered.
15
- * @param {React.ReactNode} by - The component to insert between child elements.
16
- *
17
- * @returns {JSX.Element} A React component that separates children with a specified separator.
18
- *
19
- * @example
20
- * function App() {
21
- * return (
22
- * <Separated by={<Border type="padding24" />}>
23
- * {['hello', 'react', 'world'].map(item => (
24
- * <div key={item}>{item}</div>
25
- * ))}
26
- * </Separated>
27
- * );
28
- * // Expected output:
29
- * // <div>hello</div>
30
- * // <Border type="padding24" />
31
- * // <div>react</div>
32
- * // <Border type="padding24" />
33
- * // <div>world</div>
34
- * }
35
- */
36
- declare function Separated({ children, by: separator }: Props): react_jsx_runtime.JSX.Element;
37
-
38
- export { Separated };
2
+ import { Separated } from "./Separated.cjs";
3
+ export { Separated };
@@ -0,0 +1,3 @@
1
+
2
+ import { Separated } from "./Separated.mjs";
3
+ export { Separated };
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ //#region src/components/SwitchCase/SwitchCase.tsx
3
+ /**
4
+ * @description
5
+ * `SwitchCase` is a component that allows you to declaratively render components based on a given value,
6
+ * similar to a `switch-case` statement. It is useful when you need to conditionally render different
7
+ * components depending on a specific state.
8
+ *
9
+ * @param {Case} value - The value to compare against.
10
+ * The component associated with the matching key in `caseBy` will be rendered.
11
+ * @param {Partial<{ [P in StringifiedValue<Case>]: () => ReactElement | null }>} caseBy - An object that maps values to
12
+ * components to render. The keys represent possible values, and the values are functions returning
13
+ * the corresponding components.
14
+ * @param {() => ReactElement | null} [defaultComponent] - The component to render if `value` does not match
15
+ * any key in `caseBy`.
16
+ *
17
+ * @returns {ReactElement | null} A React component that conditionally renders based on cases.
18
+ *
19
+ * @example
20
+ * function App() {
21
+ * return (
22
+ * <SwitchCase
23
+ * value={status}
24
+ * // Renders TypeA, TypeB, or TypeC based on the status value.
25
+ * caseBy={{
26
+ * a: () => <TypeA />,
27
+ * b: () => <TypeB />,
28
+ * c: () => <TypeC />,
29
+ * }}
30
+ * // Renders Default when the status value does not match any case.
31
+ * defaultComponent={() => <Default />}
32
+ * />
33
+ * );
34
+ * }
35
+ */
36
+ function SwitchCase({ value, caseBy, defaultComponent = () => null }) {
37
+ return (caseBy[String(value)] ?? defaultComponent)();
38
+ }
39
+ //#endregion
40
+ exports.SwitchCase = SwitchCase;
@@ -1,12 +1,11 @@
1
- import { ReactElement } from 'react';
2
1
 
2
+ import { ReactElement } from "react";
3
+ //#region src/components/SwitchCase/SwitchCase.d.ts
3
4
  type StringifiedValue<T> = (T extends boolean ? 'true' | 'false' : never) | (T extends number ? `${T}` : never) | (T extends string ? T : never);
4
5
  type Props<Case> = {
5
- value: Case;
6
- caseBy: Partial<{
7
- [P in StringifiedValue<Case>]: () => ReactElement | null;
8
- }>;
9
- defaultComponent?: () => ReactElement | null;
6
+ value: Case;
7
+ caseBy: Partial<{ [P in StringifiedValue<Case>]: () => ReactElement | null; }>;
8
+ defaultComponent?: () => ReactElement | null;
10
9
  };
11
10
  /**
12
11
  * @description
@@ -42,5 +41,5 @@ type Props<Case> = {
42
41
  * }
43
42
  */
44
43
  declare function SwitchCase<Case>({ value, caseBy, defaultComponent }: Props<Case>): ReactElement | null;
45
-
46
- export { SwitchCase };
44
+ //#endregion
45
+ export { SwitchCase };
@@ -0,0 +1,45 @@
1
+
2
+ import { ReactElement } from "react";
3
+ //#region src/components/SwitchCase/SwitchCase.d.ts
4
+ type StringifiedValue<T> = (T extends boolean ? 'true' | 'false' : never) | (T extends number ? `${T}` : never) | (T extends string ? T : never);
5
+ type Props<Case> = {
6
+ value: Case;
7
+ caseBy: Partial<{ [P in StringifiedValue<Case>]: () => ReactElement | null; }>;
8
+ defaultComponent?: () => ReactElement | null;
9
+ };
10
+ /**
11
+ * @description
12
+ * `SwitchCase` is a component that allows you to declaratively render components based on a given value,
13
+ * similar to a `switch-case` statement. It is useful when you need to conditionally render different
14
+ * components depending on a specific state.
15
+ *
16
+ * @param {Case} value - The value to compare against.
17
+ * The component associated with the matching key in `caseBy` will be rendered.
18
+ * @param {Partial<{ [P in StringifiedValue<Case>]: () => ReactElement | null }>} caseBy - An object that maps values to
19
+ * components to render. The keys represent possible values, and the values are functions returning
20
+ * the corresponding components.
21
+ * @param {() => ReactElement | null} [defaultComponent] - The component to render if `value` does not match
22
+ * any key in `caseBy`.
23
+ *
24
+ * @returns {ReactElement | null} A React component that conditionally renders based on cases.
25
+ *
26
+ * @example
27
+ * function App() {
28
+ * return (
29
+ * <SwitchCase
30
+ * value={status}
31
+ * // Renders TypeA, TypeB, or TypeC based on the status value.
32
+ * caseBy={{
33
+ * a: () => <TypeA />,
34
+ * b: () => <TypeB />,
35
+ * c: () => <TypeC />,
36
+ * }}
37
+ * // Renders Default when the status value does not match any case.
38
+ * defaultComponent={() => <Default />}
39
+ * />
40
+ * );
41
+ * }
42
+ */
43
+ declare function SwitchCase<Case>({ value, caseBy, defaultComponent }: Props<Case>): ReactElement | null;
44
+ //#endregion
45
+ export { SwitchCase };