@teo-garcia/react-shared 0.1.9 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/README.md +127 -99
  2. package/dist/components/aspect-ratio/aspect-ratio.d.ts +17 -0
  3. package/dist/components/aspect-ratio/aspect-ratio.d.ts.map +1 -0
  4. package/dist/components/aspect-ratio/aspect-ratio.js +14 -0
  5. package/dist/components/aspect-ratio/index.d.ts +2 -0
  6. package/dist/components/aspect-ratio/index.d.ts.map +1 -0
  7. package/dist/components/aspect-ratio/index.js +1 -0
  8. package/dist/components/debug-json/debug-json.d.ts +14 -0
  9. package/dist/components/debug-json/debug-json.d.ts.map +1 -0
  10. package/dist/components/debug-json/debug-json.js +32 -0
  11. package/dist/components/debug-json/index.d.ts +2 -0
  12. package/dist/components/debug-json/index.d.ts.map +1 -0
  13. package/dist/components/debug-json/index.js +1 -0
  14. package/dist/components/dev-panel/dev-panel.d.ts +30 -0
  15. package/dist/components/dev-panel/dev-panel.d.ts.map +1 -0
  16. package/dist/components/dev-panel/dev-panel.js +155 -0
  17. package/dist/components/dev-panel/index.d.ts +2 -0
  18. package/dist/components/dev-panel/index.d.ts.map +1 -0
  19. package/dist/components/dev-panel/index.js +1 -0
  20. package/dist/components/error-boundary/error-boundary.d.ts +3 -58
  21. package/dist/components/error-boundary/error-boundary.d.ts.map +1 -1
  22. package/dist/components/error-boundary/error-boundary.js +51 -77
  23. package/dist/components/error-boundary/index.d.ts +1 -0
  24. package/dist/components/error-boundary/index.d.ts.map +1 -1
  25. package/dist/components/focus-trap/focus-trap.d.ts +16 -0
  26. package/dist/components/focus-trap/focus-trap.d.ts.map +1 -0
  27. package/dist/components/focus-trap/focus-trap.js +57 -0
  28. package/dist/components/focus-trap/index.d.ts +2 -0
  29. package/dist/components/focus-trap/index.d.ts.map +1 -0
  30. package/dist/components/focus-trap/index.js +1 -0
  31. package/dist/components/index.d.ts +9 -5
  32. package/dist/components/index.d.ts.map +1 -1
  33. package/dist/components/index.js +9 -5
  34. package/dist/components/portal/index.d.ts +2 -0
  35. package/dist/components/portal/index.d.ts.map +1 -0
  36. package/dist/components/portal/index.js +1 -0
  37. package/dist/components/portal/portal.d.ts +14 -0
  38. package/dist/components/portal/portal.d.ts.map +1 -0
  39. package/dist/components/portal/portal.js +21 -0
  40. package/dist/components/separator/index.d.ts +2 -0
  41. package/dist/components/separator/index.d.ts.map +1 -0
  42. package/dist/components/separator/index.js +1 -0
  43. package/dist/components/separator/separator.d.ts +11 -0
  44. package/dist/components/separator/separator.d.ts.map +1 -0
  45. package/dist/components/separator/separator.js +11 -0
  46. package/dist/components/skeleton/index.d.ts +2 -0
  47. package/dist/components/skeleton/index.d.ts.map +1 -0
  48. package/dist/components/skeleton/index.js +1 -0
  49. package/dist/components/skeleton/skeleton.d.ts +3 -0
  50. package/dist/components/skeleton/skeleton.d.ts.map +1 -0
  51. package/dist/components/skeleton/skeleton.js +5 -0
  52. package/dist/components/skip-link/index.d.ts +2 -0
  53. package/dist/components/skip-link/index.d.ts.map +1 -0
  54. package/dist/components/skip-link/index.js +1 -0
  55. package/dist/components/skip-link/skip-link.d.ts +13 -0
  56. package/dist/components/skip-link/skip-link.d.ts.map +1 -0
  57. package/dist/components/skip-link/skip-link.js +26 -0
  58. package/dist/components/visually-hidden/index.d.ts +2 -0
  59. package/dist/components/visually-hidden/index.d.ts.map +1 -0
  60. package/dist/components/visually-hidden/index.js +1 -0
  61. package/dist/components/visually-hidden/visually-hidden.d.ts +3 -0
  62. package/dist/components/visually-hidden/visually-hidden.d.ts.map +1 -0
  63. package/dist/components/visually-hidden/visually-hidden.js +15 -0
  64. package/dist/hooks/index.d.ts +15 -5
  65. package/dist/hooks/index.d.ts.map +1 -1
  66. package/dist/hooks/index.js +15 -4
  67. package/dist/hooks/use-copy-to-clipboard.d.ts +7 -0
  68. package/dist/hooks/use-copy-to-clipboard.d.ts.map +1 -0
  69. package/dist/hooks/use-copy-to-clipboard.js +23 -0
  70. package/dist/hooks/use-debounce.d.ts +2 -0
  71. package/dist/hooks/use-debounce.d.ts.map +1 -0
  72. package/dist/hooks/use-debounce.js +9 -0
  73. package/dist/hooks/use-event-listener.d.ts +4 -0
  74. package/dist/hooks/use-event-listener.d.ts.map +1 -0
  75. package/dist/hooks/use-event-listener.js +13 -0
  76. package/dist/hooks/use-idle.d.ts +7 -0
  77. package/dist/hooks/use-idle.d.ts.map +1 -0
  78. package/dist/hooks/use-idle.js +35 -0
  79. package/dist/hooks/use-intersection-observer.d.ts +15 -0
  80. package/dist/hooks/use-intersection-observer.d.ts.map +1 -0
  81. package/dist/hooks/use-intersection-observer.js +22 -0
  82. package/dist/hooks/use-isomorphic-layout-effect.d.ts +3 -0
  83. package/dist/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
  84. package/dist/hooks/use-isomorphic-layout-effect.js +4 -0
  85. package/dist/hooks/use-latest.d.ts +7 -0
  86. package/dist/hooks/use-latest.d.ts.map +1 -0
  87. package/dist/hooks/use-latest.js +11 -0
  88. package/dist/hooks/use-local-storage.d.ts +2 -0
  89. package/dist/hooks/use-local-storage.d.ts.map +1 -0
  90. package/dist/hooks/use-local-storage.js +37 -0
  91. package/dist/hooks/use-media-query.d.ts +2 -0
  92. package/dist/hooks/use-media-query.d.ts.map +1 -0
  93. package/dist/hooks/use-media-query.js +18 -0
  94. package/dist/hooks/use-network-status.d.ts +10 -0
  95. package/dist/hooks/use-network-status.d.ts.map +1 -0
  96. package/dist/hooks/use-network-status.js +19 -0
  97. package/dist/hooks/use-on-click-outside.d.ts +3 -0
  98. package/dist/hooks/use-on-click-outside.d.ts.map +1 -0
  99. package/dist/hooks/use-on-click-outside.js +17 -0
  100. package/dist/hooks/use-previous.d.ts +2 -0
  101. package/dist/hooks/use-previous.d.ts.map +1 -0
  102. package/dist/hooks/use-previous.js +8 -0
  103. package/dist/hooks/use-render-count.d.ts +7 -0
  104. package/dist/hooks/use-render-count.d.ts.map +1 -0
  105. package/dist/hooks/use-render-count.js +15 -0
  106. package/dist/hooks/use-toggle.d.ts +6 -0
  107. package/dist/hooks/use-toggle.d.ts.map +1 -0
  108. package/dist/hooks/use-toggle.js +12 -0
  109. package/dist/hooks/use-why-did-you-render.d.ts +8 -0
  110. package/dist/hooks/use-why-did-you-render.d.ts.map +1 -0
  111. package/dist/hooks/use-why-did-you-render.js +38 -0
  112. package/dist/index.d.ts +6 -4
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +6 -9
  115. package/dist/test-utils/index.d.ts +14 -0
  116. package/dist/test-utils/index.d.ts.map +1 -0
  117. package/dist/test-utils/index.js +22 -0
  118. package/dist/types.d.ts +17 -36
  119. package/dist/types.d.ts.map +1 -1
  120. package/dist/utils/cn.d.ts +3 -0
  121. package/dist/utils/cn.d.ts.map +1 -0
  122. package/dist/utils/cn.js +5 -0
  123. package/dist/utils/format-date.d.ts +11 -0
  124. package/dist/utils/format-date.d.ts.map +1 -0
  125. package/dist/utils/format-date.js +12 -0
  126. package/dist/utils/format-number.d.ts +11 -0
  127. package/dist/utils/format-number.d.ts.map +1 -0
  128. package/dist/utils/format-number.js +12 -0
  129. package/dist/utils/index.d.ts +4 -5
  130. package/dist/utils/index.d.ts.map +1 -1
  131. package/dist/utils/index.js +4 -5
  132. package/dist/utils/truncate.d.ts +11 -0
  133. package/dist/utils/truncate.d.ts.map +1 -0
  134. package/dist/utils/truncate.js +14 -0
  135. package/package.json +141 -42
  136. package/dist/adapters/environment/index.d.ts +0 -6
  137. package/dist/adapters/environment/index.d.ts.map +0 -1
  138. package/dist/adapters/environment/index.js +0 -5
  139. package/dist/adapters/environment/next.d.ts +0 -17
  140. package/dist/adapters/environment/next.d.ts.map +0 -1
  141. package/dist/adapters/environment/next.js +0 -20
  142. package/dist/adapters/environment/vite.d.ts +0 -17
  143. package/dist/adapters/environment/vite.d.ts.map +0 -1
  144. package/dist/adapters/environment/vite.js +0 -20
  145. package/dist/adapters/index.d.ts +0 -9
  146. package/dist/adapters/index.d.ts.map +0 -1
  147. package/dist/adapters/index.js +0 -8
  148. package/dist/adapters/theme/custom.d.ts +0 -32
  149. package/dist/adapters/theme/custom.d.ts.map +0 -1
  150. package/dist/adapters/theme/custom.js +0 -26
  151. package/dist/adapters/theme/index.d.ts +0 -6
  152. package/dist/adapters/theme/index.d.ts.map +0 -1
  153. package/dist/adapters/theme/index.js +0 -5
  154. package/dist/adapters/theme/next-themes.d.ts +0 -18
  155. package/dist/adapters/theme/next-themes.d.ts.map +0 -1
  156. package/dist/adapters/theme/next-themes.js +0 -23
  157. package/dist/components/theme-switch/index.d.ts +0 -3
  158. package/dist/components/theme-switch/index.d.ts.map +0 -1
  159. package/dist/components/theme-switch/index.js +0 -1
  160. package/dist/components/theme-switch/theme-switch.d.ts +0 -36
  161. package/dist/components/theme-switch/theme-switch.d.ts.map +0 -1
  162. package/dist/components/theme-switch/theme-switch.js +0 -74
  163. package/dist/components/viewport-info/index.d.ts +0 -3
  164. package/dist/components/viewport-info/index.d.ts.map +0 -1
  165. package/dist/components/viewport-info/index.js +0 -1
  166. package/dist/components/viewport-info/viewport-info.d.ts +0 -40
  167. package/dist/components/viewport-info/viewport-info.d.ts.map +0 -1
  168. package/dist/components/viewport-info/viewport-info.js +0 -69
  169. package/dist/hooks/use-healthcheck.d.ts +0 -42
  170. package/dist/hooks/use-healthcheck.d.ts.map +0 -1
  171. package/dist/hooks/use-healthcheck.js +0 -53
  172. package/dist/utils/environment.d.ts +0 -71
  173. package/dist/utils/environment.d.ts.map +0 -1
  174. package/dist/utils/environment.js +0 -86
  175. package/dist/utils/msw.d.ts +0 -54
  176. package/dist/utils/msw.d.ts.map +0 -1
  177. package/dist/utils/msw.js +0 -62
@@ -1,26 +0,0 @@
1
- /**
2
- * Factory function to create a theme adapter from a custom theme hook
3
- * Use this when you have a custom theme provider implementation
4
- *
5
- * @param themeHookResult - The result from your custom useTheme hook
6
- * @returns ThemeAdapter compatible interface
7
- *
8
- * @example
9
- * ```tsx
10
- * import { createCustomThemeAdapter } from '@teo-garcia/react-shared/adapters/theme'
11
- * import { ThemeSwitch } from '@teo-garcia/react-shared/components'
12
- * import { useTheme } from '~/components/theme-provider' // Your custom hook
13
- *
14
- * function App() {
15
- * const customTheme = useTheme()
16
- * const themeAdapter = createCustomThemeAdapter(customTheme)
17
- * return <ThemeSwitch themeAdapter={themeAdapter} />
18
- * }
19
- * ```
20
- */
21
- export const createCustomThemeAdapter = (themeHookResult) => {
22
- return {
23
- theme: themeHookResult.theme,
24
- setTheme: themeHookResult.setTheme,
25
- };
26
- };
@@ -1,6 +0,0 @@
1
- /**
2
- * Theme adapters - bridge between different theme libraries and our components
3
- */
4
- export { createCustomThemeAdapter } from './custom.js';
5
- export { useNextThemesAdapter } from './next-themes.js';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/theme/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Theme adapters - bridge between different theme libraries and our components
3
- */
4
- export { createCustomThemeAdapter } from './custom.js';
5
- export { useNextThemesAdapter } from './next-themes.js';
@@ -1,18 +0,0 @@
1
- import type { ThemeAdapter } from '../../types';
2
- /**
3
- * Adapter for next-themes library
4
- * Maps the next-themes useTheme hook to our standard ThemeAdapter interface
5
- *
6
- * @example
7
- * ```tsx
8
- * import { useNextThemesAdapter } from '@teo-garcia/react-shared/adapters/theme'
9
- * import { ThemeSwitch } from '@teo-garcia/react-shared/components'
10
- *
11
- * function App() {
12
- * const themeAdapter = useNextThemesAdapter()
13
- * return <ThemeSwitch themeAdapter={themeAdapter} />
14
- * }
15
- * ```
16
- */
17
- export declare const useNextThemesAdapter: () => ThemeAdapter;
18
- //# sourceMappingURL=next-themes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"next-themes.d.ts","sourceRoot":"","sources":["../../../src/adapters/theme/next-themes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,aAAa,CAAA;AAE1D;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,QAAO,YAOvC,CAAA"}
@@ -1,23 +0,0 @@
1
- import { useTheme } from 'next-themes';
2
- /**
3
- * Adapter for next-themes library
4
- * Maps the next-themes useTheme hook to our standard ThemeAdapter interface
5
- *
6
- * @example
7
- * ```tsx
8
- * import { useNextThemesAdapter } from '@teo-garcia/react-shared/adapters/theme'
9
- * import { ThemeSwitch } from '@teo-garcia/react-shared/components'
10
- *
11
- * function App() {
12
- * const themeAdapter = useNextThemesAdapter()
13
- * return <ThemeSwitch themeAdapter={themeAdapter} />
14
- * }
15
- * ```
16
- */
17
- export const useNextThemesAdapter = () => {
18
- const { theme, setTheme } = useTheme();
19
- return {
20
- theme: (theme ?? 'system'),
21
- setTheme: (newTheme) => setTheme(newTheme),
22
- };
23
- };
@@ -1,3 +0,0 @@
1
- export { ThemeSwitch } from './theme-switch.js';
2
- export type { ThemeSwitchProps } from './theme-switch.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/theme-switch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
@@ -1 +0,0 @@
1
- export { ThemeSwitch } from './theme-switch.js';
@@ -1,36 +0,0 @@
1
- import type { ThemeAdapter } from '../../types';
2
- export interface ThemeSwitchProps {
3
- /** Theme adapter that connects to your theme provider */
4
- themeAdapter: ThemeAdapter;
5
- }
6
- /**
7
- * ThemeSwitch component - A button that cycles through light, dark, and system themes
8
- *
9
- * This component uses the adapter pattern to work with any theme provider.
10
- * It cycles through themes in the order: light → dark → system → light
11
- *
12
- * @example Next.js with next-themes
13
- * ```tsx
14
- * import { ThemeSwitch } from '@teo-garcia/react-shared/components'
15
- * import { useNextThemesAdapter } from '@teo-garcia/react-shared/adapters/theme'
16
- *
17
- * function App() {
18
- * const themeAdapter = useNextThemesAdapter()
19
- * return <ThemeSwitch themeAdapter={themeAdapter} />
20
- * }
21
- * ```
22
- *
23
- * @example React Router with custom theme provider
24
- * ```tsx
25
- * import { ThemeSwitch } from '@teo-garcia/react-shared/components'
26
- * import { createCustomThemeAdapter } from '@teo-garcia/react-shared/adapters/theme'
27
- * import { useTheme } from '~/components/theme-provider'
28
- *
29
- * function App() {
30
- * const themeAdapter = createCustomThemeAdapter(useTheme())
31
- * return <ThemeSwitch themeAdapter={themeAdapter} />
32
- * }
33
- * ```
34
- */
35
- export declare const ThemeSwitch: ({ themeAdapter }: ThemeSwitchProps) => import("react/jsx-runtime").JSX.Element;
36
- //# sourceMappingURL=theme-switch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"theme-switch.d.ts","sourceRoot":"","sources":["../../../src/components/theme-switch/theme-switch.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,aAAa,CAAA;AAE1D,MAAM,WAAW,gBAAgB;IAC/B,yDAAyD;IACzD,YAAY,EAAE,YAAY,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,WAAW,GAAI,kBAAkB,gBAAgB,4CAuD7D,CAAA"}
@@ -1,74 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { Laptop, Moon, Sun } from 'lucide-react';
4
- /**
5
- * ThemeSwitch component - A button that cycles through light, dark, and system themes
6
- *
7
- * This component uses the adapter pattern to work with any theme provider.
8
- * It cycles through themes in the order: light → dark → system → light
9
- *
10
- * @example Next.js with next-themes
11
- * ```tsx
12
- * import { ThemeSwitch } from '@teo-garcia/react-shared/components'
13
- * import { useNextThemesAdapter } from '@teo-garcia/react-shared/adapters/theme'
14
- *
15
- * function App() {
16
- * const themeAdapter = useNextThemesAdapter()
17
- * return <ThemeSwitch themeAdapter={themeAdapter} />
18
- * }
19
- * ```
20
- *
21
- * @example React Router with custom theme provider
22
- * ```tsx
23
- * import { ThemeSwitch } from '@teo-garcia/react-shared/components'
24
- * import { createCustomThemeAdapter } from '@teo-garcia/react-shared/adapters/theme'
25
- * import { useTheme } from '~/components/theme-provider'
26
- *
27
- * function App() {
28
- * const themeAdapter = createCustomThemeAdapter(useTheme())
29
- * return <ThemeSwitch themeAdapter={themeAdapter} />
30
- * }
31
- * ```
32
- */
33
- export const ThemeSwitch = ({ themeAdapter }) => {
34
- const { theme, setTheme } = themeAdapter;
35
- // Ensure we have a valid theme, default to 'system' if undefined
36
- const activeTheme = (theme ?? 'system');
37
- /**
38
- * Cycles to the next theme in the sequence
39
- * light → dark → system → light
40
- */
41
- const getNextTheme = () => {
42
- switch (activeTheme) {
43
- case 'light': {
44
- return 'dark';
45
- }
46
- case 'dark': {
47
- return 'system';
48
- }
49
- default: {
50
- return 'light';
51
- }
52
- }
53
- };
54
- /**
55
- * Returns the appropriate icon for the current theme
56
- */
57
- const getCurrentIcon = () => {
58
- switch (activeTheme) {
59
- case 'light': {
60
- return _jsx(Sun, { className: "size-5" });
61
- }
62
- case 'dark': {
63
- return _jsx(Moon, { className: "size-5" });
64
- }
65
- default: {
66
- return _jsx(Laptop, { className: "size-5" });
67
- }
68
- }
69
- };
70
- const handleClick = () => {
71
- setTheme(getNextTheme());
72
- };
73
- return (_jsx("button", { onClick: handleClick, "aria-label": `Theme switcher, current mode: ${activeTheme}`, className: "fixed right-4 top-4 rounded-lg border p-2 md:right-8 md:top-8 transition-colors duration-200 hover:bg-accent hover:text-accent-foreground", title: `Current theme: ${activeTheme}. Click to switch to ${getNextTheme()}`, children: getCurrentIcon() }));
74
- };
@@ -1,3 +0,0 @@
1
- export { ViewportInfo } from './viewport-info.js';
2
- export type { ViewportInfoProps } from './viewport-info.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/viewport-info/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA"}
@@ -1 +0,0 @@
1
- export { ViewportInfo } from './viewport-info.js';
@@ -1,40 +0,0 @@
1
- import type { EnvironmentAdapter } from '../../types';
2
- export interface ViewportInfoProps {
3
- /** Environment adapter to detect if running in development mode */
4
- environmentAdapter: EnvironmentAdapter;
5
- }
6
- /**
7
- * ViewportInfo component - Displays current viewport dimensions and Tailwind breakpoint
8
- *
9
- * This component is useful during development to see the current viewport size and
10
- * which Tailwind breakpoint is active. It automatically hides in production.
11
- *
12
- * Features:
13
- * - Shows viewport width and height in pixels
14
- * - Displays active Tailwind CSS breakpoint (default, sm, md, lg, xl, 2xl)
15
- * - Auto-updates on window resize
16
- * - Only renders in development mode
17
- * - Fixed position in bottom-right corner
18
- *
19
- * @example Next.js
20
- * ```tsx
21
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
22
- * import { nextEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
23
- *
24
- * function App() {
25
- * return <ViewportInfo environmentAdapter={nextEnvironmentAdapter} />
26
- * }
27
- * ```
28
- *
29
- * @example React Router / Vite
30
- * ```tsx
31
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
32
- * import { viteEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
33
- *
34
- * function App() {
35
- * return <ViewportInfo environmentAdapter={viteEnvironmentAdapter} />
36
- * }
37
- * ```
38
- */
39
- export declare const ViewportInfo: ({ environmentAdapter }: ViewportInfoProps) => import("react/jsx-runtime").JSX.Element | null;
40
- //# sourceMappingURL=viewport-info.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"viewport-info.d.ts","sourceRoot":"","sources":["../../../src/components/viewport-info/viewport-info.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,kBAAkB,EAAE,kBAAkB,CAAA;CACvC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,YAAY,GAAI,wBAAwB,iBAAiB,mDAmDrE,CAAA"}
@@ -1,69 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { RulerIcon } from 'lucide-react';
4
- import { useEffect, useState } from 'react';
5
- /**
6
- * ViewportInfo component - Displays current viewport dimensions and Tailwind breakpoint
7
- *
8
- * This component is useful during development to see the current viewport size and
9
- * which Tailwind breakpoint is active. It automatically hides in production.
10
- *
11
- * Features:
12
- * - Shows viewport width and height in pixels
13
- * - Displays active Tailwind CSS breakpoint (default, sm, md, lg, xl, 2xl)
14
- * - Auto-updates on window resize
15
- * - Only renders in development mode
16
- * - Fixed position in bottom-right corner
17
- *
18
- * @example Next.js
19
- * ```tsx
20
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
21
- * import { nextEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
22
- *
23
- * function App() {
24
- * return <ViewportInfo environmentAdapter={nextEnvironmentAdapter} />
25
- * }
26
- * ```
27
- *
28
- * @example React Router / Vite
29
- * ```tsx
30
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
31
- * import { viteEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
32
- *
33
- * function App() {
34
- * return <ViewportInfo environmentAdapter={viteEnvironmentAdapter} />
35
- * }
36
- * ```
37
- */
38
- export const ViewportInfo = ({ environmentAdapter }) => {
39
- // State to track viewport dimensions
40
- const [{ width: viewportWidth, height: viewportHeight }, setViewportSize] = useState(() => ({
41
- width: 0,
42
- height: 0,
43
- }));
44
- useEffect(() => {
45
- // Guard against SSR - window is not available on the server
46
- if (globalThis.window == undefined) {
47
- return;
48
- }
49
- // Handler to update viewport dimensions
50
- const handleResize = () => {
51
- setViewportSize({
52
- width: window.innerWidth,
53
- height: window.innerHeight,
54
- });
55
- };
56
- // Set initial dimensions
57
- handleResize();
58
- // Listen for resize events
59
- window.addEventListener('resize', handleResize);
60
- // Cleanup listener on unmount
61
- return () => {
62
- window.removeEventListener('resize', handleResize);
63
- };
64
- }, []);
65
- // Only show in development mode
66
- if (!environmentAdapter.isDevelopment())
67
- return null;
68
- return (_jsxs("aside", { className: "fixed bottom-0 right-0 flex items-center gap-x-1 rounded-l-lg px-4 py-2 bg-primary text-primary-foreground font-semibold", children: [_jsx(RulerIcon, { className: "size-5" }), _jsxs("p", { className: "text-lg flex gap-x-2", children: [viewportWidth, "px - ", viewportHeight, "px -", _jsx("span", { className: "inline sm:hidden font-semibold", children: "default" }), _jsx("span", { className: "hidden sm:inline md:hidden font-semibold", children: "sm" }), _jsx("span", { className: "hidden md:inline lg:hidden font-semibold", children: "md" }), _jsx("span", { className: "hidden lg:inline xl:hidden font-semibold", children: "lg " }), _jsx("span", { className: "hidden xl:inline 2xl:hidden font-semibold", children: "xl" }), _jsx("span", { className: "hidden 2xl:inline font-semibold", children: "2xl" })] })] }));
69
- };
@@ -1,42 +0,0 @@
1
- export interface UseHealthcheckOptions {
2
- /** The healthcheck endpoint URL (default: http://localhost:3000/api/healthcheck) */
3
- url?: string;
4
- /** Enable/disable the query (default: true) */
5
- enabled?: boolean;
6
- }
7
- /**
8
- * useHealthcheck hook - Fetches health status from an API endpoint
9
- *
10
- * This hook uses React Query to fetch and cache the health status of your API.
11
- * It's useful for monitoring if your backend is available and responding.
12
- *
13
- * @param options - Configuration options
14
- * @returns React Query result with health status data
15
- *
16
- * @example Basic usage
17
- * ```tsx
18
- * import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
19
- *
20
- * function HealthStatus() {
21
- * const { data, isLoading, error } = useHealthcheck()
22
- *
23
- * if (isLoading) return <div>Checking health...</div>
24
- * if (error) return <div>Health check failed</div>
25
- * return <div>Status: {data?.status}</div>
26
- * }
27
- * ```
28
- *
29
- * @example Custom URL
30
- * ```tsx
31
- * import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
32
- *
33
- * function HealthStatus() {
34
- * const { data } = useHealthcheck({
35
- * url: 'http://localhost:8080/health'
36
- * })
37
- * return <div>{data?.status}</div>
38
- * }
39
- * ```
40
- */
41
- export declare const useHealthcheck: (options?: UseHealthcheckOptions) => import("@tanstack/react-query").UseQueryResult<any, Error>;
42
- //# sourceMappingURL=use-healthcheck.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-healthcheck.d.ts","sourceRoot":"","sources":["../../src/hooks/use-healthcheck.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,qBAAqB;IACpC,oFAAoF;IACpF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,+CAA+C;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,GAAI,UAAS,qBAA0B,+DAkBjE,CAAA"}
@@ -1,53 +0,0 @@
1
- import { useQuery } from '@tanstack/react-query';
2
- /**
3
- * useHealthcheck hook - Fetches health status from an API endpoint
4
- *
5
- * This hook uses React Query to fetch and cache the health status of your API.
6
- * It's useful for monitoring if your backend is available and responding.
7
- *
8
- * @param options - Configuration options
9
- * @returns React Query result with health status data
10
- *
11
- * @example Basic usage
12
- * ```tsx
13
- * import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
14
- *
15
- * function HealthStatus() {
16
- * const { data, isLoading, error } = useHealthcheck()
17
- *
18
- * if (isLoading) return <div>Checking health...</div>
19
- * if (error) return <div>Health check failed</div>
20
- * return <div>Status: {data?.status}</div>
21
- * }
22
- * ```
23
- *
24
- * @example Custom URL
25
- * ```tsx
26
- * import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
27
- *
28
- * function HealthStatus() {
29
- * const { data } = useHealthcheck({
30
- * url: 'http://localhost:8080/health'
31
- * })
32
- * return <div>{data?.status}</div>
33
- * }
34
- * ```
35
- */
36
- export const useHealthcheck = (options = {}) => {
37
- const { url = 'http://localhost:3000/api/healthcheck', enabled = true } = options;
38
- return useQuery({
39
- queryKey: ['healthcheck', url],
40
- queryFn: async () => {
41
- const response = await fetch(url);
42
- if (!response.ok) {
43
- throw new Error(`Health check failed: ${response.statusText}`);
44
- }
45
- return await response.json();
46
- },
47
- enabled,
48
- // Refetch every 30 seconds to keep health status fresh
49
- refetchInterval: 30000,
50
- // Retry failed requests
51
- retry: 3,
52
- });
53
- };
@@ -1,71 +0,0 @@
1
- /**
2
- * Environment detection utilities
3
- *
4
- * These utilities help detect the runtime environment (development, production, server, client).
5
- * They work across different frameworks by checking both process.env and import.meta.env.
6
- */
7
- /**
8
- * Check if running in development mode
9
- * Works with both Next.js (process.env) and Vite (import.meta.env)
10
- *
11
- * @returns true if in development mode
12
- *
13
- * @example
14
- * ```tsx
15
- * import { isDevelopment } from '@teo-garcia/react-shared/utils'
16
- *
17
- * if (isDevelopment()) {
18
- * console.log('Running in dev mode')
19
- * }
20
- * ```
21
- */
22
- export declare const isDevelopment: () => boolean;
23
- /**
24
- * Check if running in production mode
25
- * Works with both Next.js (process.env) and Vite (import.meta.env)
26
- *
27
- * @returns true if in production mode
28
- *
29
- * @example
30
- * ```tsx
31
- * import { isProduction } from '@teo-garcia/react-shared/utils'
32
- *
33
- * if (isProduction()) {
34
- * // Enable analytics
35
- * }
36
- * ```
37
- */
38
- export declare const isProduction: () => boolean;
39
- /**
40
- * Check if code is running on the server (SSR)
41
- * Works by detecting the absence of window object
42
- *
43
- * @returns true if running on server
44
- *
45
- * @example
46
- * ```tsx
47
- * import { isServer } from '@teo-garcia/react-shared/utils'
48
- *
49
- * if (isServer()) {
50
- * // Server-only code
51
- * }
52
- * ```
53
- */
54
- export declare const isServer: () => boolean;
55
- /**
56
- * Check if code is running on the client (browser)
57
- * Works by detecting the presence of window object
58
- *
59
- * @returns true if running on client
60
- *
61
- * @example
62
- * ```tsx
63
- * import { isClient } from '@teo-garcia/react-shared/utils'
64
- *
65
- * if (isClient()) {
66
- * // Client-only code like localStorage access
67
- * }
68
- * ```
69
- */
70
- export declare const isClient: () => boolean;
71
- //# sourceMappingURL=environment.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,QAAO,OAYhC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,QAAO,OAE/B,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,QAAO,OAE3B,CAAA"}
@@ -1,86 +0,0 @@
1
- /**
2
- * Environment detection utilities
3
- *
4
- * These utilities help detect the runtime environment (development, production, server, client).
5
- * They work across different frameworks by checking both process.env and import.meta.env.
6
- */
7
- /**
8
- * Check if running in development mode
9
- * Works with both Next.js (process.env) and Vite (import.meta.env)
10
- *
11
- * @returns true if in development mode
12
- *
13
- * @example
14
- * ```tsx
15
- * import { isDevelopment } from '@teo-garcia/react-shared/utils'
16
- *
17
- * if (isDevelopment()) {
18
- * console.log('Running in dev mode')
19
- * }
20
- * ```
21
- */
22
- export const isDevelopment = () => {
23
- // Check process.env first (Next.js, Node.js)
24
- if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development') {
25
- return true;
26
- }
27
- // Check import.meta.env (Vite, modern bundlers)
28
- if (typeof import.meta !== 'undefined' && import.meta.env?.DEV === true) {
29
- return true;
30
- }
31
- return false;
32
- };
33
- /**
34
- * Check if running in production mode
35
- * Works with both Next.js (process.env) and Vite (import.meta.env)
36
- *
37
- * @returns true if in production mode
38
- *
39
- * @example
40
- * ```tsx
41
- * import { isProduction } from '@teo-garcia/react-shared/utils'
42
- *
43
- * if (isProduction()) {
44
- * // Enable analytics
45
- * }
46
- * ```
47
- */
48
- export const isProduction = () => {
49
- return !isDevelopment();
50
- };
51
- /**
52
- * Check if code is running on the server (SSR)
53
- * Works by detecting the absence of window object
54
- *
55
- * @returns true if running on server
56
- *
57
- * @example
58
- * ```tsx
59
- * import { isServer } from '@teo-garcia/react-shared/utils'
60
- *
61
- * if (isServer()) {
62
- * // Server-only code
63
- * }
64
- * ```
65
- */
66
- export const isServer = () => {
67
- return typeof window === 'undefined';
68
- };
69
- /**
70
- * Check if code is running on the client (browser)
71
- * Works by detecting the presence of window object
72
- *
73
- * @returns true if running on client
74
- *
75
- * @example
76
- * ```tsx
77
- * import { isClient } from '@teo-garcia/react-shared/utils'
78
- *
79
- * if (isClient()) {
80
- * // Client-only code like localStorage access
81
- * }
82
- * ```
83
- */
84
- export const isClient = () => {
85
- return !isServer();
86
- };
@@ -1,54 +0,0 @@
1
- /**
2
- * Mock Service Worker (MSW) setup utilities
3
- *
4
- * These utilities help set up MSW for API mocking in development and testing.
5
- * They provide consistent factories for creating MSW workers across projects.
6
- */
7
- import type { RequestHandler } from 'msw';
8
- /**
9
- * Creates and starts a browser MSW worker
10
- * Use this in client-side applications (Next.js, React Router, etc.)
11
- *
12
- * @param handlers - Array of request handlers to use
13
- * @param options - MSW worker options
14
- * @returns Promise that resolves when worker is started
15
- *
16
- * @example
17
- * ```tsx
18
- * import { setupMSWBrowser } from '@teo-garcia/react-shared/utils'
19
- * import { handlers } from './handlers'
20
- *
21
- * // In your app initialization
22
- * if (isDevelopment()) {
23
- * await setupMSWBrowser(handlers)
24
- * }
25
- * ```
26
- */
27
- export declare const setupMSWBrowser: (handlers: RequestHandler[], options?: {
28
- onUnhandledRequest?: "bypass" | "warn" | "error";
29
- }) => Promise<import("msw/browser").SetupWorker>;
30
- /**
31
- * Creates and starts a Node.js MSW server
32
- * Use this in server-side applications and tests
33
- *
34
- * @param handlers - Array of request handlers to use
35
- * @param options - MSW server options
36
- * @returns Promise that resolves to the server instance
37
- *
38
- * @example
39
- * ```tsx
40
- * import { setupMSWServer } from '@teo-garcia/react-shared/utils'
41
- * import { handlers } from './handlers'
42
- *
43
- * // In your test setup
44
- * const server = await setupMSWServer(handlers)
45
- *
46
- * beforeAll(() => server.listen())
47
- * afterEach(() => server.resetHandlers())
48
- * afterAll(() => server.close())
49
- * ```
50
- */
51
- export declare const setupMSWServer: (handlers: RequestHandler[], options?: {
52
- onUnhandledRequest?: "bypass" | "warn" | "error";
53
- }) => Promise<import("msw/node").SetupServerApi>;
54
- //# sourceMappingURL=msw.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msw.d.ts","sourceRoot":"","sources":["../../src/utils/msw.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAEzC;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,cAAc,EAAE,EAC1B,UAAU;IAAE,kBAAkB,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,+CAU/D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,cAAc,EAAE,EAC1B,UAAU;IAAE,kBAAkB,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAA;CAAE,+CAU/D,CAAA"}