react-simplikit 0.0.2 → 0.0.3

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 (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -0
  3. package/dist/components/ImpressionArea/index.d.ts +48 -0
  4. package/dist/components/ImpressionArea/index.js +276 -0
  5. package/dist/components/Separated/index.d.ts +38 -0
  6. package/dist/components/Separated/index.js +40 -0
  7. package/dist/components/SwitchCase/index.d.ts +46 -0
  8. package/dist/components/SwitchCase/index.js +35 -0
  9. package/dist/hooks/useAsyncEffect/index.d.ts +25 -0
  10. package/dist/hooks/useAsyncEffect/index.js +43 -0
  11. package/dist/hooks/useBooleanState/index.d.ts +19 -0
  12. package/dist/hooks/useBooleanState/index.js +45 -0
  13. package/dist/hooks/useCallbackOnce/index.d.ts +41 -0
  14. package/dist/hooks/useCallbackOnce/index.js +59 -0
  15. package/dist/hooks/useDebounce/index.d.ts +47 -0
  16. package/dist/hooks/useDebounce/index.js +123 -0
  17. package/dist/hooks/useImpressionRef/index.d.ts +38 -0
  18. package/dist/hooks/useImpressionRef/index.js +237 -0
  19. package/dist/hooks/useInputState/index.d.ts +27 -0
  20. package/dist/hooks/useInputState/index.js +45 -0
  21. package/dist/hooks/useIntersectionObserver/index.d.ts +33 -0
  22. package/dist/hooks/useIntersectionObserver/index.js +91 -0
  23. package/dist/hooks/useInterval/index.d.ts +37 -0
  24. package/dist/hooks/useInterval/index.js +64 -0
  25. package/dist/hooks/useLoading/index.d.ts +37 -0
  26. package/dist/hooks/useLoading/index.js +61 -0
  27. package/dist/hooks/useOutsideClickEffect/index.d.ts +27 -0
  28. package/dist/hooks/useOutsideClickEffect/index.js +70 -0
  29. package/dist/hooks/usePreservedCallback/index.d.ts +30 -0
  30. package/dist/hooks/usePreservedCallback/index.js +41 -0
  31. package/dist/hooks/usePreservedReference/index.d.ts +42 -0
  32. package/dist/hooks/usePreservedReference/index.js +44 -0
  33. package/dist/hooks/usePrevious/index.d.ts +21 -0
  34. package/dist/hooks/usePrevious/index.js +47 -0
  35. package/dist/hooks/useRefEffect/index.d.ts +31 -0
  36. package/dist/hooks/useRefEffect/index.js +68 -0
  37. package/dist/hooks/useStorageState/index.d.ts +50 -0
  38. package/dist/hooks/useStorageState/index.js +168 -0
  39. package/dist/hooks/useThrottle/index.d.ts +47 -0
  40. package/dist/hooks/useThrottle/index.js +147 -0
  41. package/dist/hooks/useTimeout/index.d.ts +30 -0
  42. package/dist/hooks/useTimeout/index.js +53 -0
  43. package/dist/hooks/useToggle/index.d.ts +30 -0
  44. package/dist/hooks/useToggle/index.js +36 -0
  45. package/dist/hooks/useVisibilityEvent/index.d.ts +27 -0
  46. package/dist/hooks/useVisibilityEvent/index.js +46 -0
  47. package/dist/index.d.ts +26 -0
  48. package/dist/index.js +761 -0
  49. package/dist/utils/buildContext/index.d.ts +38 -0
  50. package/dist/utils/buildContext/index.js +55 -0
  51. package/dist/utils/mergeRefs/index.d.ts +37 -0
  52. package/dist/utils/mergeRefs/index.js +45 -0
  53. package/esm/components/ImpressionArea/index.d.mts +48 -0
  54. package/esm/components/ImpressionArea/index.mjs +249 -0
  55. package/esm/components/Separated/index.d.mts +38 -0
  56. package/esm/components/Separated/index.mjs +13 -0
  57. package/esm/components/SwitchCase/index.d.mts +46 -0
  58. package/esm/components/SwitchCase/index.mjs +8 -0
  59. package/esm/hooks/useAsyncEffect/index.d.mts +25 -0
  60. package/esm/hooks/useAsyncEffect/index.mjs +16 -0
  61. package/esm/hooks/useBooleanState/index.d.mts +19 -0
  62. package/esm/hooks/useBooleanState/index.mjs +18 -0
  63. package/esm/hooks/useCallbackOnce/index.d.mts +41 -0
  64. package/esm/hooks/useCallbackOnce/index.mjs +32 -0
  65. package/esm/hooks/useDebounce/index.d.mts +47 -0
  66. package/esm/hooks/useDebounce/index.mjs +96 -0
  67. package/esm/hooks/useImpressionRef/index.d.mts +38 -0
  68. package/esm/hooks/useImpressionRef/index.mjs +210 -0
  69. package/esm/hooks/useInputState/index.d.mts +27 -0
  70. package/esm/hooks/useInputState/index.mjs +18 -0
  71. package/esm/hooks/useIntersectionObserver/index.d.mts +33 -0
  72. package/esm/hooks/useIntersectionObserver/index.mjs +64 -0
  73. package/esm/hooks/useInterval/index.d.mts +37 -0
  74. package/esm/hooks/useInterval/index.mjs +37 -0
  75. package/esm/hooks/useLoading/index.d.mts +37 -0
  76. package/esm/hooks/useLoading/index.mjs +34 -0
  77. package/esm/hooks/useOutsideClickEffect/index.d.mts +27 -0
  78. package/esm/hooks/useOutsideClickEffect/index.mjs +43 -0
  79. package/esm/hooks/usePreservedCallback/index.d.mts +30 -0
  80. package/esm/hooks/usePreservedCallback/index.mjs +14 -0
  81. package/esm/hooks/usePreservedReference/index.d.mts +42 -0
  82. package/esm/hooks/usePreservedReference/index.mjs +17 -0
  83. package/esm/hooks/usePrevious/index.d.mts +21 -0
  84. package/esm/hooks/usePrevious/index.mjs +20 -0
  85. package/esm/hooks/useRefEffect/index.d.mts +31 -0
  86. package/esm/hooks/useRefEffect/index.mjs +41 -0
  87. package/esm/hooks/useStorageState/index.d.mts +50 -0
  88. package/esm/hooks/useStorageState/index.mjs +141 -0
  89. package/esm/hooks/useThrottle/index.d.mts +47 -0
  90. package/esm/hooks/useThrottle/index.mjs +120 -0
  91. package/esm/hooks/useTimeout/index.d.mts +30 -0
  92. package/esm/hooks/useTimeout/index.mjs +26 -0
  93. package/esm/hooks/useToggle/index.d.mts +30 -0
  94. package/esm/hooks/useToggle/index.mjs +9 -0
  95. package/esm/hooks/useVisibilityEvent/index.d.mts +27 -0
  96. package/esm/hooks/useVisibilityEvent/index.mjs +19 -0
  97. package/esm/index.d.mts +26 -0
  98. package/esm/index.mjs +711 -0
  99. package/esm/utils/buildContext/index.d.mts +38 -0
  100. package/esm/utils/buildContext/index.mjs +28 -0
  101. package/esm/utils/mergeRefs/index.d.mts +37 -0
  102. package/esm/utils/mergeRefs/index.mjs +18 -0
  103. package/package.json +79 -7
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Viva Republica, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ ![react-simplikit](./src/public/images/og.png)
2
+
3
+ # react-simplikit · [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/toss/slash/blob/main/LICENSE)
4
+
5
+ English | [Korean](./README-ko_kr.md)
6
+
7
+ `react-simplikit` is a lightweight yet powerful library that provides various utilities for use in React environments.
8
+
9
+ - `react-simplikit` is dependency-free, making it extremely lightweight.
10
+ - `react-simplikit` guarantees reliability with 100% test coverage.
11
+ - `react-simplikit` offers JSDoc comments, detailed documentation, and examples to ensure any developer can easily use it.
12
+
13
+ ## Example
14
+
15
+ ```tsx
16
+ import { useBooleanState } from 'react-simplikit';
17
+
18
+ function Component() {
19
+ const [open, openBottomSheet, closeBottomSheet, toggleBottomSheet] = useBooleanState(false);
20
+
21
+ return (
22
+ <div>
23
+ <p>Bottom Sheet State: {open ? 'Open' : 'Closed'}</p>
24
+ <button onClick={openBottomSheet}>Open</button>
25
+ <button onClick={closeBottomSheet}>Close</button>
26
+ <button onClick={toggleBottomSheet}>Toggle</button>
27
+ </div>
28
+ );
29
+ }
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ Contributions are welcome from everyone in the community. Please check the contribution guide linked below.
35
+
36
+ [CONTRIBUTING](./src/docs/en/contributing.md)
37
+
38
+ ## License
39
+
40
+ MIT © Viva Republica, Inc. For more details, see [LICENSE](./LICENSE)
@@ -0,0 +1,48 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React__default, { ElementType, Ref } from 'react';
3
+ import { UseImpressionRefOptions } from '../../hooks/useImpressionRef/index.js';
4
+
5
+ type Props<Tag extends ElementType> = React__default.ComponentPropsWithoutRef<Tag> & UseImpressionRefOptions & {
6
+ as?: Tag;
7
+ ref?: Ref<HTMLElement>;
8
+ children?: React__default.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
+ * @param {Object} props - The props for the component.
18
+ * @param {ElementType} [props.as='div'] - The HTML tag to render. Defaults to `div`.
19
+ * @param {string} [props.rootMargin] - Margin to adjust the detection area.
20
+ * @param {number} [props.areaThreshold] - Minimum ratio of the element that must be visible (0 to 1).
21
+ * @param {number} [props.timeThreshold] - Minimum time the element must be visible (in milliseconds).
22
+ * @param {() => void} [props.onImpressionStart] - Callback function executed when the element enters the view.
23
+ * @param {() => void} [props.onImpressionEnd] - Callback function executed when the element exits the view.
24
+ * @param {Ref<HTMLElement>} [props.ref] - Reference to the element.
25
+ * @param {React.ReactNode} [props.children] - Child elements to be rendered inside the component.
26
+ * @param {string} [props.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
+ * import { ImpressionArea } from 'react-simplikit';
32
+ *
33
+ * function App() {
34
+ * return (
35
+ * <ImpressionArea
36
+ * onImpressionStart={() => console.log('Element entered view')}
37
+ * onImpressionEnd={() => console.log('Element exited view')}
38
+ * timeThreshold={1000}
39
+ * areaThreshold={0.5}
40
+ * >
41
+ * <div>Track my visibility!</div>
42
+ * </ImpressionArea>
43
+ * );
44
+ * }
45
+ */
46
+ declare function ImpressionArea<T extends ElementType = 'div'>({ as, rootMargin, areaThreshold, timeThreshold, onImpressionStart, onImpressionEnd, ref, ...props }: Props<T>): react_jsx_runtime.JSX.Element;
47
+
48
+ export { ImpressionArea };
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/components/ImpressionArea/index.ts
21
+ var ImpressionArea_exports = {};
22
+ __export(ImpressionArea_exports, {
23
+ ImpressionArea: () => ImpressionArea
24
+ });
25
+ module.exports = __toCommonJS(ImpressionArea_exports);
26
+
27
+ // src/hooks/useImpressionRef/useImpressionRef.ts
28
+ var import_react6 = require("react");
29
+
30
+ // src/hooks/useIntersectionObserver/useIntersectionObserver.ts
31
+ var import_react3 = require("react");
32
+
33
+ // src/hooks/usePreservedCallback/usePreservedCallback.ts
34
+ var import_react = require("react");
35
+ function usePreservedCallback(callback) {
36
+ const callbackRef = (0, import_react.useRef)(callback);
37
+ (0, import_react.useEffect)(() => {
38
+ callbackRef.current = callback;
39
+ }, [callback]);
40
+ return (0, import_react.useCallback)((...args) => {
41
+ return callbackRef.current(...args);
42
+ }, []);
43
+ }
44
+
45
+ // src/hooks/useRefEffect/useRefEffect.ts
46
+ var import_react2 = require("react");
47
+ function useRefEffect(callback, deps) {
48
+ const preservedCallback = usePreservedCallback(callback);
49
+ const cleanupCallbackRef = (0, import_react2.useRef)(() => {
50
+ });
51
+ const effect = (0, import_react2.useCallback)(
52
+ (element) => {
53
+ cleanupCallbackRef.current();
54
+ cleanupCallbackRef.current = () => {
55
+ };
56
+ if (element == null) {
57
+ return;
58
+ }
59
+ const cleanup = preservedCallback(element);
60
+ if (typeof cleanup === "function") {
61
+ cleanupCallbackRef.current = cleanup;
62
+ }
63
+ },
64
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
+ [preservedCallback, ...deps]
66
+ );
67
+ return effect;
68
+ }
69
+
70
+ // src/hooks/useIntersectionObserver/useIntersectionObserver.ts
71
+ function useIntersectionObserver(callback, options) {
72
+ const preservedCallback = usePreservedCallback(callback);
73
+ const observer = (0, import_react3.useMemo)(() => {
74
+ if (typeof IntersectionObserver === "undefined") {
75
+ return;
76
+ }
77
+ return new IntersectionObserver(([entry]) => {
78
+ preservedCallback(entry);
79
+ }, options);
80
+ }, [preservedCallback, options]);
81
+ return useRefEffect(
82
+ (element) => {
83
+ observer?.observe(element);
84
+ return () => {
85
+ observer?.unobserve(element);
86
+ };
87
+ },
88
+ [preservedCallback, options]
89
+ );
90
+ }
91
+
92
+ // src/hooks/useVisibilityEvent/useVisibilityEvent.ts
93
+ var import_react4 = require("react");
94
+ function useVisibilityEvent(callback, options = {}) {
95
+ const handleVisibilityChange = (0, import_react4.useCallback)(() => {
96
+ callback(document.visibilityState);
97
+ }, [callback]);
98
+ (0, import_react4.useEffect)(() => {
99
+ if (options?.immediate ?? false) {
100
+ handleVisibilityChange();
101
+ }
102
+ document.addEventListener("visibilitychange", handleVisibilityChange);
103
+ return () => {
104
+ document.removeEventListener("visibilitychange", handleVisibilityChange);
105
+ };
106
+ }, [handleVisibilityChange, options?.immediate]);
107
+ }
108
+
109
+ // src/hooks/useImpressionRef/useDebouncedCallback.ts
110
+ var import_react5 = require("react");
111
+
112
+ // src/hooks/useDebounce/debounce.ts
113
+ function debounce(func, debounceMs, { edges = ["leading", "trailing"] } = {}) {
114
+ let pendingThis = void 0;
115
+ let pendingArgs = null;
116
+ const leading = edges != null && edges.includes("leading");
117
+ const trailing = edges == null || edges.includes("trailing");
118
+ const invoke = () => {
119
+ if (pendingArgs !== null) {
120
+ func.apply(pendingThis, pendingArgs);
121
+ pendingThis = void 0;
122
+ pendingArgs = null;
123
+ }
124
+ };
125
+ const onTimerEnd = () => {
126
+ if (trailing) {
127
+ invoke();
128
+ }
129
+ cancel();
130
+ };
131
+ let timeoutId = null;
132
+ const schedule = () => {
133
+ if (timeoutId != null) {
134
+ clearTimeout(timeoutId);
135
+ }
136
+ timeoutId = setTimeout(() => {
137
+ timeoutId = null;
138
+ onTimerEnd();
139
+ }, debounceMs);
140
+ };
141
+ const cancelTimer = () => {
142
+ if (timeoutId !== null) {
143
+ clearTimeout(timeoutId);
144
+ timeoutId = null;
145
+ }
146
+ };
147
+ const cancel = () => {
148
+ cancelTimer();
149
+ pendingThis = void 0;
150
+ pendingArgs = null;
151
+ };
152
+ const debounced = function(...args) {
153
+ pendingThis = this;
154
+ pendingArgs = args;
155
+ const isFirstCall = timeoutId == null;
156
+ schedule();
157
+ if (leading && isFirstCall) {
158
+ invoke();
159
+ }
160
+ };
161
+ debounced.cancel = cancel;
162
+ return debounced;
163
+ }
164
+
165
+ // src/hooks/useImpressionRef/useDebouncedCallback.ts
166
+ function useDebouncedCallback({
167
+ onChange,
168
+ timeThreshold
169
+ }) {
170
+ const handleChange = usePreservedCallback(onChange);
171
+ const ref = (0, import_react5.useRef)({ value: false, clearPreviousDebounce: () => {
172
+ } });
173
+ (0, import_react5.useEffect)(() => {
174
+ const current = ref.current;
175
+ return () => {
176
+ current.clearPreviousDebounce();
177
+ };
178
+ }, []);
179
+ return (0, import_react5.useCallback)(
180
+ (nextValue) => {
181
+ if (nextValue === ref.current.value) {
182
+ return;
183
+ }
184
+ const debounced = debounce(() => {
185
+ handleChange(nextValue);
186
+ ref.current.value = nextValue;
187
+ }, timeThreshold);
188
+ ref.current.clearPreviousDebounce();
189
+ debounced();
190
+ ref.current.clearPreviousDebounce = debounced.cancel;
191
+ },
192
+ [handleChange, timeThreshold]
193
+ );
194
+ }
195
+
196
+ // src/hooks/useImpressionRef/useImpressionRef.ts
197
+ function useImpressionRef({
198
+ onImpressionStart = () => {
199
+ },
200
+ onImpressionEnd = () => {
201
+ },
202
+ rootMargin,
203
+ areaThreshold = 0,
204
+ timeThreshold = 0
205
+ }) {
206
+ const impressionStartHandler = usePreservedCallback(onImpressionStart);
207
+ const impressionEndHandler = usePreservedCallback(onImpressionEnd);
208
+ const isIntersectingRef = (0, import_react6.useRef)(false);
209
+ const impressionEventHandler = useDebouncedCallback({
210
+ timeThreshold,
211
+ onChange: (impressed) => {
212
+ (impressed ? impressionStartHandler : impressionEndHandler)();
213
+ }
214
+ });
215
+ useVisibilityEvent((documentVisible) => {
216
+ if (!isIntersectingRef.current) {
217
+ return;
218
+ }
219
+ impressionEventHandler(documentVisible === "visible");
220
+ });
221
+ return useIntersectionObserver(
222
+ (entry) => {
223
+ if (document.visibilityState === "hidden") {
224
+ return;
225
+ }
226
+ const currentRatio = entry.intersectionRatio;
227
+ const isIntersecting = areaThreshold === 0 ? entry.isIntersecting : currentRatio >= areaThreshold;
228
+ isIntersectingRef.current = isIntersecting;
229
+ impressionEventHandler(isIntersecting);
230
+ },
231
+ { rootMargin, threshold: areaThreshold }
232
+ );
233
+ }
234
+
235
+ // src/utils/mergeRefs/mergeRefs.ts
236
+ function mergeRefs(...refs) {
237
+ return (value) => {
238
+ for (const ref of refs) {
239
+ if (ref == null) {
240
+ continue;
241
+ }
242
+ if (typeof ref === "function") {
243
+ ref(value);
244
+ continue;
245
+ }
246
+ ref.current = value;
247
+ }
248
+ };
249
+ }
250
+
251
+ // src/components/ImpressionArea/ImpressionArea.tsx
252
+ var import_jsx_runtime = require("react/jsx-runtime");
253
+ function ImpressionArea({
254
+ as,
255
+ rootMargin,
256
+ areaThreshold,
257
+ timeThreshold,
258
+ onImpressionStart,
259
+ onImpressionEnd,
260
+ ref,
261
+ ...props
262
+ }) {
263
+ const Component = as ?? "div";
264
+ const impressionRef = useImpressionRef({
265
+ onImpressionStart,
266
+ onImpressionEnd,
267
+ areaThreshold,
268
+ timeThreshold,
269
+ rootMargin
270
+ });
271
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ref: mergeRefs(ref, impressionRef), ...props });
272
+ }
273
+ // Annotate the CommonJS export names for ESM import in node:
274
+ 0 && (module.exports = {
275
+ ImpressionArea
276
+ });
@@ -0,0 +1,38 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ type Props = {
5
+ with: 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} with - 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 with={<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, with: separator }: Props): react_jsx_runtime.JSX.Element;
37
+
38
+ export { Separated };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/components/Separated/index.ts
21
+ var Separated_exports = {};
22
+ __export(Separated_exports, {
23
+ Separated: () => Separated
24
+ });
25
+ module.exports = __toCommonJS(Separated_exports);
26
+
27
+ // src/components/Separated/Separated.tsx
28
+ var import_react = require("react");
29
+ var import_jsx_runtime = require("react/jsx-runtime");
30
+ function Separated({ children, with: separator }) {
31
+ const childrenArray = import_react.Children.toArray(children).filter(import_react.isValidElement);
32
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
33
+ child,
34
+ i + 1 !== length ? separator : null
35
+ ] }, i)) });
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ Separated
40
+ });
@@ -0,0 +1,46 @@
1
+ import { ReactElement } from 'react';
2
+
3
+ type StringifiedValue<T> = T extends boolean ? 'true' | 'false' : T extends number ? `${T}` : T extends string ? T : never;
4
+ type Props<Case> = {
5
+ value: Case;
6
+ caseBy: Partial<{
7
+ [P in StringifiedValue<Case>]: () => ReactElement | null;
8
+ }>;
9
+ defaultComponent?: () => ReactElement | null;
10
+ };
11
+ /**
12
+ * @description
13
+ * `SwitchCase` is a component that allows you to declaratively render components based on a given value,
14
+ * similar to a `switch-case` statement. It is useful when you need to conditionally render different
15
+ * components depending on a specific state.
16
+ *
17
+ * @param {string | number} value - The value to compare against.
18
+ * The component associated with the matching key in `caseBy` will be rendered.
19
+ * @param {Record<string | number, () => JSX.Element>} caseBy - An object that maps values to
20
+ * components to render. The keys represent possible values, and the values are functions returning
21
+ * the corresponding components.
22
+ * @param {() => JSX.Element} defaultComponent - The component to render if `value` does not match
23
+ * any key in `caseBy`.
24
+ *
25
+ * @returns {JSX.Element} A React component that conditionally renders based on cases.
26
+ *
27
+ * @example
28
+ * function App() {
29
+ * return (
30
+ * <SwitchCase
31
+ * value={status}
32
+ * // Renders TypeA, TypeB, or TypeC based on the status value.
33
+ * caseBy={{
34
+ * a: () => <TypeA />,
35
+ * b: () => <TypeB />,
36
+ * c: () => <TypeC />,
37
+ * }}
38
+ * // Renders Default when the status value does not match any case.
39
+ * defaultComponent={() => <Default />}
40
+ * />
41
+ * );
42
+ * }
43
+ */
44
+ declare function SwitchCase<Case>({ value, caseBy, defaultComponent }: Props<Case>): ReactElement | null;
45
+
46
+ export { SwitchCase };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/components/SwitchCase/index.ts
21
+ var SwitchCase_exports = {};
22
+ __export(SwitchCase_exports, {
23
+ SwitchCase: () => SwitchCase
24
+ });
25
+ module.exports = __toCommonJS(SwitchCase_exports);
26
+
27
+ // src/components/SwitchCase/SwitchCase.tsx
28
+ function SwitchCase({ value, caseBy, defaultComponent = () => null }) {
29
+ const stringifiedValue = String(value);
30
+ return (caseBy[stringifiedValue] ?? defaultComponent)();
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ SwitchCase
35
+ });
@@ -0,0 +1,25 @@
1
+ import { DependencyList } from 'react';
2
+
3
+ /**
4
+ * @description
5
+ * `useAsyncEffect` is a custom hook for handling asynchronous side effects in React components.
6
+ * It follows the same cleanup pattern as `useEffect` while ensuring async operations are handled safely.
7
+ *
8
+ * @param {() => Promise<void | (() => void)>} effect - An asynchronous function executed in the `useEffect` pattern.
9
+ * This function can optionally return a cleanup function.
10
+ * @param {DependencyList} [deps] - A dependency array.
11
+ * The effect will re-run whenever any value in this array changes. If omitted, it runs only once when the component mounts.
12
+ *
13
+ * @example
14
+ * useAsyncEffect(async () => {
15
+ * const data = await fetchData();
16
+ * setData(data);
17
+ *
18
+ * return () => {
19
+ * console.log('Cleanup on unmount or dependency change');
20
+ * };
21
+ * }, [dependency]);
22
+ */
23
+ declare function useAsyncEffect(effect: () => Promise<void | (() => void)>, deps?: DependencyList): void;
24
+
25
+ export { useAsyncEffect };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/hooks/useAsyncEffect/index.ts
21
+ var useAsyncEffect_exports = {};
22
+ __export(useAsyncEffect_exports, {
23
+ useAsyncEffect: () => useAsyncEffect
24
+ });
25
+ module.exports = __toCommonJS(useAsyncEffect_exports);
26
+
27
+ // src/hooks/useAsyncEffect/useAsyncEffect.ts
28
+ var import_react = require("react");
29
+ function useAsyncEffect(effect, deps) {
30
+ (0, import_react.useEffect)(() => {
31
+ let cleanup;
32
+ effect().then((result) => {
33
+ cleanup = result;
34
+ });
35
+ return () => {
36
+ cleanup?.();
37
+ };
38
+ }, deps);
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ useAsyncEffect
43
+ });
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @description
3
+ * `useBooleanState` is a React hook that simplifies managing a boolean state.
4
+ * It provides functions to set the state to `true`, set it to `false`, and toggle its value.
5
+ *
6
+ * @param {boolean} [defaultValue=false] - The initial value of the state. Defaults to `false`.
7
+ *
8
+ * @returns {readonly [boolean, () => void, () => void, () => void]} A tuple containing:
9
+ * - `boolean` - The current state value.
10
+ * - `() => void` - A function to set the state to `true`.
11
+ * - `() => void` - A function to set the state to `false`.
12
+ * - `() => void` - A function to toggle the state.
13
+ *
14
+ * @example
15
+ * const [open, openBottomSheet, closeBottomSheet, toggleBottomSheet] = useBooleanState(false);
16
+ */
17
+ declare const useBooleanState: (defaultValue?: boolean) => readonly [boolean, () => void, () => void, () => void];
18
+
19
+ export { useBooleanState };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/hooks/useBooleanState/index.ts
21
+ var useBooleanState_exports = {};
22
+ __export(useBooleanState_exports, {
23
+ useBooleanState: () => useBooleanState
24
+ });
25
+ module.exports = __toCommonJS(useBooleanState_exports);
26
+
27
+ // src/hooks/useBooleanState/useBooleanState.ts
28
+ var import_react = require("react");
29
+ var useBooleanState = (defaultValue = false) => {
30
+ const [bool, setBool] = (0, import_react.useState)(defaultValue);
31
+ const setTrue = (0, import_react.useCallback)(() => {
32
+ setBool(true);
33
+ }, []);
34
+ const setFalse = (0, import_react.useCallback)(() => {
35
+ setBool(false);
36
+ }, []);
37
+ const toggle = (0, import_react.useCallback)(() => {
38
+ setBool((b) => !b);
39
+ }, []);
40
+ return [bool, setTrue, setFalse, toggle];
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ useBooleanState
45
+ });