@teo-garcia/react-shared 0.1.9 → 1.0.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 (84) hide show
  1. package/README.md +8 -11
  2. package/dist/components/error-boundary/error-boundary.d.ts.map +1 -1
  3. package/dist/components/error-boundary/error-boundary.js +1 -1
  4. package/dist/components/index.d.ts +0 -5
  5. package/dist/components/index.d.ts.map +1 -1
  6. package/dist/components/index.js +0 -5
  7. package/dist/hooks/index.d.ts +6 -5
  8. package/dist/hooks/index.d.ts.map +1 -1
  9. package/dist/hooks/index.js +6 -4
  10. package/dist/hooks/use-debounce.d.ts +2 -0
  11. package/dist/hooks/use-debounce.d.ts.map +1 -0
  12. package/dist/hooks/use-debounce.js +9 -0
  13. package/dist/hooks/use-isomorphic-layout-effect.d.ts +3 -0
  14. package/dist/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
  15. package/dist/hooks/use-isomorphic-layout-effect.js +4 -0
  16. package/dist/hooks/use-local-storage.d.ts +2 -0
  17. package/dist/hooks/use-local-storage.d.ts.map +1 -0
  18. package/dist/hooks/use-local-storage.js +37 -0
  19. package/dist/hooks/use-media-query.d.ts +2 -0
  20. package/dist/hooks/use-media-query.d.ts.map +1 -0
  21. package/dist/hooks/use-media-query.js +18 -0
  22. package/dist/hooks/use-on-click-outside.d.ts +3 -0
  23. package/dist/hooks/use-on-click-outside.d.ts.map +1 -0
  24. package/dist/hooks/use-on-click-outside.js +17 -0
  25. package/dist/hooks/use-previous.d.ts +2 -0
  26. package/dist/hooks/use-previous.d.ts.map +1 -0
  27. package/dist/hooks/use-previous.js +8 -0
  28. package/dist/index.d.ts +6 -4
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +6 -9
  31. package/dist/test-utils/index.d.ts +14 -0
  32. package/dist/test-utils/index.d.ts.map +1 -0
  33. package/dist/test-utils/index.js +22 -0
  34. package/dist/types.d.ts +0 -34
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/utils/cn.d.ts +3 -0
  37. package/dist/utils/cn.d.ts.map +1 -0
  38. package/dist/utils/cn.js +5 -0
  39. package/dist/utils/index.d.ts +1 -5
  40. package/dist/utils/index.d.ts.map +1 -1
  41. package/dist/utils/index.js +1 -5
  42. package/package.json +60 -45
  43. package/dist/adapters/environment/index.d.ts +0 -6
  44. package/dist/adapters/environment/index.d.ts.map +0 -1
  45. package/dist/adapters/environment/index.js +0 -5
  46. package/dist/adapters/environment/next.d.ts +0 -17
  47. package/dist/adapters/environment/next.d.ts.map +0 -1
  48. package/dist/adapters/environment/next.js +0 -20
  49. package/dist/adapters/environment/vite.d.ts +0 -17
  50. package/dist/adapters/environment/vite.d.ts.map +0 -1
  51. package/dist/adapters/environment/vite.js +0 -20
  52. package/dist/adapters/index.d.ts +0 -9
  53. package/dist/adapters/index.d.ts.map +0 -1
  54. package/dist/adapters/index.js +0 -8
  55. package/dist/adapters/theme/custom.d.ts +0 -32
  56. package/dist/adapters/theme/custom.d.ts.map +0 -1
  57. package/dist/adapters/theme/custom.js +0 -26
  58. package/dist/adapters/theme/index.d.ts +0 -6
  59. package/dist/adapters/theme/index.d.ts.map +0 -1
  60. package/dist/adapters/theme/index.js +0 -5
  61. package/dist/adapters/theme/next-themes.d.ts +0 -18
  62. package/dist/adapters/theme/next-themes.d.ts.map +0 -1
  63. package/dist/adapters/theme/next-themes.js +0 -23
  64. package/dist/components/theme-switch/index.d.ts +0 -3
  65. package/dist/components/theme-switch/index.d.ts.map +0 -1
  66. package/dist/components/theme-switch/index.js +0 -1
  67. package/dist/components/theme-switch/theme-switch.d.ts +0 -36
  68. package/dist/components/theme-switch/theme-switch.d.ts.map +0 -1
  69. package/dist/components/theme-switch/theme-switch.js +0 -74
  70. package/dist/components/viewport-info/index.d.ts +0 -3
  71. package/dist/components/viewport-info/index.d.ts.map +0 -1
  72. package/dist/components/viewport-info/index.js +0 -1
  73. package/dist/components/viewport-info/viewport-info.d.ts +0 -40
  74. package/dist/components/viewport-info/viewport-info.d.ts.map +0 -1
  75. package/dist/components/viewport-info/viewport-info.js +0 -69
  76. package/dist/hooks/use-healthcheck.d.ts +0 -42
  77. package/dist/hooks/use-healthcheck.d.ts.map +0 -1
  78. package/dist/hooks/use-healthcheck.js +0 -53
  79. package/dist/utils/environment.d.ts +0 -71
  80. package/dist/utils/environment.d.ts.map +0 -1
  81. package/dist/utils/environment.js +0 -86
  82. package/dist/utils/msw.d.ts +0 -54
  83. package/dist/utils/msw.d.ts.map +0 -1
  84. package/dist/utils/msw.js +0 -62
@@ -1,17 +0,0 @@
1
- import type { EnvironmentAdapter } from '../../types';
2
- /**
3
- * Environment adapter for Next.js applications
4
- * Uses process.env.NODE_ENV for environment detection
5
- *
6
- * @example
7
- * ```tsx
8
- * import { nextEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
9
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
10
- *
11
- * function App() {
12
- * return <ViewportInfo environmentAdapter={nextEnvironmentAdapter} />
13
- * }
14
- * ```
15
- */
16
- export declare const nextEnvironmentAdapter: EnvironmentAdapter;
17
- //# sourceMappingURL=next.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"next.d.ts","sourceRoot":"","sources":["../../../src/adapters/environment/next.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,EAAE,kBAKpC,CAAA"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Environment adapter for Next.js applications
3
- * Uses process.env.NODE_ENV for environment detection
4
- *
5
- * @example
6
- * ```tsx
7
- * import { nextEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
8
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
9
- *
10
- * function App() {
11
- * return <ViewportInfo environmentAdapter={nextEnvironmentAdapter} />
12
- * }
13
- * ```
14
- */
15
- export const nextEnvironmentAdapter = {
16
- isDevelopment: () => process.env.NODE_ENV === 'development',
17
- isProduction: () => process.env.NODE_ENV === 'production',
18
- isServer: () => typeof window === 'undefined',
19
- isClient: () => typeof window !== 'undefined',
20
- };
@@ -1,17 +0,0 @@
1
- import type { EnvironmentAdapter } from '../../types';
2
- /**
3
- * Environment adapter for Vite-based applications (React Router, vanilla Vite)
4
- * Uses import.meta.env for environment detection
5
- *
6
- * @example
7
- * ```tsx
8
- * import { viteEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
9
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
10
- *
11
- * function App() {
12
- * return <ViewportInfo environmentAdapter={viteEnvironmentAdapter} />
13
- * }
14
- * ```
15
- */
16
- export declare const viteEnvironmentAdapter: EnvironmentAdapter;
17
- //# sourceMappingURL=vite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../src/adapters/environment/vite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,EAAE,kBAKpC,CAAA"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Environment adapter for Vite-based applications (React Router, vanilla Vite)
3
- * Uses import.meta.env for environment detection
4
- *
5
- * @example
6
- * ```tsx
7
- * import { viteEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
8
- * import { ViewportInfo } from '@teo-garcia/react-shared/components'
9
- *
10
- * function App() {
11
- * return <ViewportInfo environmentAdapter={viteEnvironmentAdapter} />
12
- * }
13
- * ```
14
- */
15
- export const viteEnvironmentAdapter = {
16
- isDevelopment: () => import.meta.env.DEV === true,
17
- isProduction: () => import.meta.env.PROD === true,
18
- isServer: () => import.meta.env.SSR === true,
19
- isClient: () => import.meta.env.SSR !== true,
20
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * Adapters - bridge between different frameworks and our shared components
3
- *
4
- * Adapters allow our components to work with different theme libraries,
5
- * environment detection systems, and other framework-specific APIs
6
- */
7
- export * from './environment/index.js';
8
- export * from './theme/index.js';
9
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA"}
@@ -1,8 +0,0 @@
1
- /**
2
- * Adapters - bridge between different frameworks and our shared components
3
- *
4
- * Adapters allow our components to work with different theme libraries,
5
- * environment detection systems, and other framework-specific APIs
6
- */
7
- export * from './environment/index.js';
8
- export * from './theme/index.js';
@@ -1,32 +0,0 @@
1
- import type { ThemeAdapter, ThemeMode } from '../../types';
2
- /**
3
- * Custom theme provider result interface
4
- * This matches the common pattern of custom theme providers
5
- */
6
- interface CustomThemeHook {
7
- theme: ThemeMode;
8
- setTheme: (theme: ThemeMode) => void;
9
- }
10
- /**
11
- * Factory function to create a theme adapter from a custom theme hook
12
- * Use this when you have a custom theme provider implementation
13
- *
14
- * @param themeHookResult - The result from your custom useTheme hook
15
- * @returns ThemeAdapter compatible interface
16
- *
17
- * @example
18
- * ```tsx
19
- * import { createCustomThemeAdapter } from '@teo-garcia/react-shared/adapters/theme'
20
- * import { ThemeSwitch } from '@teo-garcia/react-shared/components'
21
- * import { useTheme } from '~/components/theme-provider' // Your custom hook
22
- *
23
- * function App() {
24
- * const customTheme = useTheme()
25
- * const themeAdapter = createCustomThemeAdapter(customTheme)
26
- * return <ThemeSwitch themeAdapter={themeAdapter} />
27
- * }
28
- * ```
29
- */
30
- export declare const createCustomThemeAdapter: (themeHookResult: CustomThemeHook) => ThemeAdapter;
31
- export {};
32
- //# sourceMappingURL=custom.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../../src/adapters/theme/custom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE1D;;;GAGG;AACH,UAAU,eAAe;IACvB,KAAK,EAAE,SAAS,CAAA;IAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAA;CACrC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,wBAAwB,GAAI,iBAAiB,eAAe,KAAG,YAK3E,CAAA"}
@@ -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
- };