@teo-garcia/react-shared 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +259 -0
  3. package/dist/adapters/environment/index.d.ts +6 -0
  4. package/dist/adapters/environment/index.d.ts.map +1 -0
  5. package/dist/adapters/environment/index.js +5 -0
  6. package/dist/adapters/environment/next.d.ts +17 -0
  7. package/dist/adapters/environment/next.d.ts.map +1 -0
  8. package/dist/adapters/environment/next.js +20 -0
  9. package/dist/adapters/environment/vite.d.ts +17 -0
  10. package/dist/adapters/environment/vite.d.ts.map +1 -0
  11. package/dist/adapters/environment/vite.js +20 -0
  12. package/dist/adapters/index.d.ts +9 -0
  13. package/dist/adapters/index.d.ts.map +1 -0
  14. package/dist/adapters/index.js +8 -0
  15. package/dist/adapters/theme/custom.d.ts +32 -0
  16. package/dist/adapters/theme/custom.d.ts.map +1 -0
  17. package/dist/adapters/theme/custom.js +26 -0
  18. package/dist/adapters/theme/index.d.ts +6 -0
  19. package/dist/adapters/theme/index.d.ts.map +1 -0
  20. package/dist/adapters/theme/index.js +5 -0
  21. package/dist/adapters/theme/next-themes.d.ts +18 -0
  22. package/dist/adapters/theme/next-themes.d.ts.map +1 -0
  23. package/dist/adapters/theme/next-themes.js +23 -0
  24. package/dist/components/error-boundary/error-boundary.d.ts +71 -0
  25. package/dist/components/error-boundary/error-boundary.d.ts.map +1 -0
  26. package/dist/components/error-boundary/error-boundary.js +100 -0
  27. package/dist/components/error-boundary/index.d.ts +2 -0
  28. package/dist/components/error-boundary/index.d.ts.map +1 -0
  29. package/dist/components/error-boundary/index.js +1 -0
  30. package/dist/components/index.d.ts +7 -0
  31. package/dist/components/index.d.ts.map +1 -0
  32. package/dist/components/index.js +6 -0
  33. package/dist/components/theme-switch/index.d.ts +3 -0
  34. package/dist/components/theme-switch/index.d.ts.map +1 -0
  35. package/dist/components/theme-switch/index.js +1 -0
  36. package/dist/components/theme-switch/theme-switch.d.ts +36 -0
  37. package/dist/components/theme-switch/theme-switch.d.ts.map +1 -0
  38. package/dist/components/theme-switch/theme-switch.js +74 -0
  39. package/dist/components/viewport-info/index.d.ts +3 -0
  40. package/dist/components/viewport-info/index.d.ts.map +1 -0
  41. package/dist/components/viewport-info/index.js +1 -0
  42. package/dist/components/viewport-info/viewport-info.d.ts +40 -0
  43. package/dist/components/viewport-info/viewport-info.d.ts.map +1 -0
  44. package/dist/components/viewport-info/viewport-info.js +69 -0
  45. package/dist/hooks/index.d.ts +6 -0
  46. package/dist/hooks/index.d.ts.map +1 -0
  47. package/dist/hooks/index.js +4 -0
  48. package/dist/hooks/use-healthcheck.d.ts +42 -0
  49. package/dist/hooks/use-healthcheck.d.ts.map +1 -0
  50. package/dist/hooks/use-healthcheck.js +53 -0
  51. package/dist/index.d.ts +16 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +20 -0
  54. package/dist/types.d.ts +40 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +1 -0
  57. package/dist/utils/environment.d.ts +71 -0
  58. package/dist/utils/environment.d.ts.map +1 -0
  59. package/dist/utils/environment.js +86 -0
  60. package/dist/utils/index.d.ts +6 -0
  61. package/dist/utils/index.d.ts.map +1 -0
  62. package/dist/utils/index.js +5 -0
  63. package/dist/utils/msw.d.ts +54 -0
  64. package/dist/utils/msw.d.ts.map +1 -0
  65. package/dist/utils/msw.js +62 -0
  66. package/package.json +112 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 teo-garcia
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,259 @@
1
+ # @teo-garcia/react-shared
2
+
3
+ Shared React components, hooks, utilities, and adapters for fullstack web templates.
4
+
5
+ This package provides framework-agnostic React utilities that work across Next.js, React Router, and other React-based frameworks using the adapter pattern.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add @teo-garcia/react-shared
11
+ ```
12
+
13
+ ### Peer Dependencies
14
+
15
+ This package requires the following peer dependencies:
16
+
17
+ ```bash
18
+ pnpm add react react-dom lucide-react
19
+ ```
20
+
21
+ For hooks functionality, you'll also need:
22
+
23
+ ```bash
24
+ pnpm add @tanstack/react-query
25
+ ```
26
+
27
+ For MSW utilities:
28
+
29
+ ```bash
30
+ pnpm add -D msw
31
+ ```
32
+
33
+ ## Features
34
+
35
+ - 🎨 **Components**: Ready-to-use UI components (ThemeSwitch, ViewportInfo, ErrorBoundary)
36
+ - 🪝 **Hooks**: Reusable React hooks (useHealthcheck)
37
+ - 🛠️ **Utilities**: Pure helper functions (environment detection, MSW setup)
38
+ - 🔌 **Adapters**: Framework bridges for theme providers and environment detection
39
+ - 📦 **Framework Agnostic**: Works with Next.js, React Router, and other React frameworks
40
+ - 🎯 **TypeScript**: Full type safety with TypeScript definitions
41
+ - 🌲 **Tree-shakeable**: Import only what you need
42
+
43
+ ## Usage
44
+
45
+ ### Components
46
+
47
+ #### ThemeSwitch
48
+
49
+ A button that cycles through light, dark, and system themes.
50
+
51
+ **Next.js (with next-themes):**
52
+
53
+ ```tsx
54
+ import { ThemeSwitch } from '@teo-garcia/react-shared/components'
55
+ import { useNextThemesAdapter } from '@teo-garcia/react-shared/adapters/theme'
56
+
57
+ export function App() {
58
+ const themeAdapter = useNextThemesAdapter()
59
+ return <ThemeSwitch themeAdapter={themeAdapter} />
60
+ }
61
+ ```
62
+
63
+ **React Router (with custom provider):**
64
+
65
+ ```tsx
66
+ import { ThemeSwitch } from '@teo-garcia/react-shared/components'
67
+ import { createCustomThemeAdapter } from '@teo-garcia/react-shared/adapters/theme'
68
+ import { useTheme } from '~/components/theme-provider'
69
+
70
+ export function App() {
71
+ const themeAdapter = createCustomThemeAdapter(useTheme())
72
+ return <ThemeSwitch themeAdapter={themeAdapter} />
73
+ }
74
+ ```
75
+
76
+ #### ViewportInfo
77
+
78
+ Displays current viewport dimensions and Tailwind breakpoint (dev mode only).
79
+
80
+ ```tsx
81
+ import { ViewportInfo } from '@teo-garcia/react-shared/components'
82
+ import { nextEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
83
+
84
+ export function App() {
85
+ return <ViewportInfo environmentAdapter={nextEnvironmentAdapter} />
86
+ }
87
+ ```
88
+
89
+ **For Vite/React Router:**
90
+
91
+ ```tsx
92
+ import { ViewportInfo } from '@teo-garcia/react-shared/components'
93
+ import { viteEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
94
+
95
+ export function App() {
96
+ return <ViewportInfo environmentAdapter={viteEnvironmentAdapter} />
97
+ }
98
+ ```
99
+
100
+ #### ErrorBoundary
101
+
102
+ Catches JavaScript errors in child components.
103
+
104
+ ```tsx
105
+ import { ErrorBoundary } from '@teo-garcia/react-shared/components'
106
+
107
+ export function App() {
108
+ return (
109
+ <ErrorBoundary
110
+ fallback={(error) => (
111
+ <div>
112
+ <h1>Something went wrong</h1>
113
+ <p>{error.message}</p>
114
+ </div>
115
+ )}
116
+ onError={(error, errorInfo) => {
117
+ console.error('Error caught:', error, errorInfo)
118
+ }}
119
+ >
120
+ <YourApp />
121
+ </ErrorBoundary>
122
+ )
123
+ }
124
+ ```
125
+
126
+ ### Hooks
127
+
128
+ #### useHealthcheck
129
+
130
+ Fetches health status from an API endpoint using React Query.
131
+
132
+ ```tsx
133
+ import { useHealthcheck } from '@teo-garcia/react-shared/hooks'
134
+
135
+ export function HealthStatus() {
136
+ const { data, isLoading, error } = useHealthcheck({
137
+ url: 'http://localhost:3000/api/healthcheck',
138
+ })
139
+
140
+ if (isLoading) return <div>Checking...</div>
141
+ if (error) return <div>Health check failed</div>
142
+ return <div>Status: {data?.status}</div>
143
+ }
144
+ ```
145
+
146
+ ### Utilities
147
+
148
+ #### Environment Detection
149
+
150
+ ```tsx
151
+ import { isDevelopment, isProduction, isServer, isClient } from '@teo-garcia/react-shared/utils'
152
+
153
+ if (isDevelopment()) {
154
+ console.log('Running in dev mode')
155
+ }
156
+
157
+ if (isClient()) {
158
+ // Access browser APIs
159
+ localStorage.setItem('key', 'value')
160
+ }
161
+ ```
162
+
163
+ #### MSW Setup
164
+
165
+ ```tsx
166
+ import { setupMSWBrowser } from '@teo-garcia/react-shared/utils'
167
+ import { handlers } from './mocks/handlers'
168
+
169
+ // In your app initialization
170
+ if (isDevelopment()) {
171
+ await setupMSWBrowser(handlers)
172
+ }
173
+ ```
174
+
175
+ ### Adapters
176
+
177
+ Adapters bridge the gap between different framework-specific implementations and our components.
178
+
179
+ #### Theme Adapters
180
+
181
+ **Next.js (next-themes):**
182
+
183
+ ```tsx
184
+ import { useNextThemesAdapter } from '@teo-garcia/react-shared/adapters/theme'
185
+
186
+ const themeAdapter = useNextThemesAdapter()
187
+ ```
188
+
189
+ **Custom Theme Provider:**
190
+
191
+ ```tsx
192
+ import { createCustomThemeAdapter } from '@teo-garcia/react-shared/adapters/theme'
193
+ import { useTheme } from '~/your-theme-provider'
194
+
195
+ const themeAdapter = createCustomThemeAdapter(useTheme())
196
+ ```
197
+
198
+ #### Environment Adapters
199
+
200
+ **Next.js:**
201
+
202
+ ```tsx
203
+ import { nextEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
204
+ ;<ViewportInfo environmentAdapter={nextEnvironmentAdapter} />
205
+ ```
206
+
207
+ **Vite/React Router:**
208
+
209
+ ```tsx
210
+ import { viteEnvironmentAdapter } from '@teo-garcia/react-shared/adapters/environment'
211
+ ;<ViewportInfo environmentAdapter={viteEnvironmentAdapter} />
212
+ ```
213
+
214
+ ## API Reference
215
+
216
+ ### Components
217
+
218
+ - `ThemeSwitch` - Theme switcher button
219
+ - `ViewportInfo` - Viewport dimensions display (dev only)
220
+ - `ErrorBoundary` - Error boundary component
221
+
222
+ ### Hooks
223
+
224
+ - `useHealthcheck` - API health check hook
225
+
226
+ ### Utilities
227
+
228
+ - `isDevelopment()` - Check if in development mode
229
+ - `isProduction()` - Check if in production mode
230
+ - `isServer()` - Check if running on server
231
+ - `isClient()` - Check if running on client
232
+ - `setupMSWBrowser()` - Setup MSW for browser
233
+ - `setupMSWServer()` - Setup MSW for Node.js/tests
234
+
235
+ ### Adapters
236
+
237
+ **Theme:**
238
+
239
+ - `useNextThemesAdapter()` - Adapter for next-themes
240
+ - `createCustomThemeAdapter()` - Create adapter for custom theme provider
241
+
242
+ **Environment:**
243
+
244
+ - `nextEnvironmentAdapter` - Environment detection for Next.js
245
+ - `viteEnvironmentAdapter` - Environment detection for Vite
246
+
247
+ ## Requirements
248
+
249
+ - **Tailwind CSS**: Components use Tailwind CSS classes
250
+ - **React 18+**: Uses modern React features
251
+ - **TypeScript**: Full type definitions included
252
+
253
+ ## License
254
+
255
+ MIT
256
+
257
+ ## Author
258
+
259
+ teo-garcia
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Environment adapters - abstract environment detection across different frameworks
3
+ */
4
+ export { nextEnvironmentAdapter } from './next';
5
+ export { viteEnvironmentAdapter } from './vite';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/environment/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Environment adapters - abstract environment detection across different frameworks
3
+ */
4
+ export { nextEnvironmentAdapter } from './next';
5
+ export { viteEnvironmentAdapter } from './vite';
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,20 @@
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
+ };
@@ -0,0 +1,17 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,20 @@
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
+ };
@@ -0,0 +1,9 @@
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';
8
+ export * from './theme';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,SAAS,CAAA"}
@@ -0,0 +1,8 @@
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';
8
+ export * from './theme';
@@ -0,0 +1,32 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,26 @@
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
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Theme adapters - bridge between different theme libraries and our components
3
+ */
4
+ export { createCustomThemeAdapter } from './custom';
5
+ export { useNextThemesAdapter } from './next-themes';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/theme/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Theme adapters - bridge between different theme libraries and our components
3
+ */
4
+ export { createCustomThemeAdapter } from './custom';
5
+ export { useNextThemesAdapter } from './next-themes';
@@ -0,0 +1,18 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,23 @@
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
+ };
@@ -0,0 +1,71 @@
1
+ import { Component, type ReactNode } from 'react';
2
+ import type { ErrorBoundaryProps } from '../../types';
3
+ interface ErrorBoundaryState {
4
+ hasError: boolean;
5
+ error: Error | null;
6
+ }
7
+ /**
8
+ * ErrorBoundary component - Catches JavaScript errors in child components
9
+ *
10
+ * This component wraps your application (or part of it) to catch runtime errors
11
+ * and display a fallback UI instead of crashing the entire app.
12
+ *
13
+ * Features:
14
+ * - Catches errors in child component tree
15
+ * - Displays custom fallback UI
16
+ * - Optional error callback for logging
17
+ * - Follows React error boundary best practices
18
+ *
19
+ * @example Basic usage
20
+ * ```tsx
21
+ * import { ErrorBoundary } from '@teo-garcia/react-shared/components'
22
+ *
23
+ * function App() {
24
+ * return (
25
+ * <ErrorBoundary fallback={<div>Something went wrong</div>}>
26
+ * <YourApp />
27
+ * </ErrorBoundary>
28
+ * )
29
+ * }
30
+ * ```
31
+ *
32
+ * @example With dynamic fallback
33
+ * ```tsx
34
+ * import { ErrorBoundary } from '@teo-garcia/react-shared/components'
35
+ *
36
+ * function App() {
37
+ * return (
38
+ * <ErrorBoundary
39
+ * fallback={(error) => (
40
+ * <div>
41
+ * <h1>Error: {error.message}</h1>
42
+ * <button onClick={() => window.location.reload()}>Reload</button>
43
+ * </div>
44
+ * )}
45
+ * onError={(error, errorInfo) => {
46
+ * console.error('Error caught:', error, errorInfo)
47
+ * // Send to error tracking service
48
+ * }}
49
+ * >
50
+ * <YourApp />
51
+ * </ErrorBoundary>
52
+ * )
53
+ * }
54
+ * ```
55
+ */
56
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
57
+ constructor(props: ErrorBoundaryProps);
58
+ /**
59
+ * Static method called when an error is thrown in a child component
60
+ * Updates state to trigger fallback UI rendering
61
+ */
62
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
63
+ /**
64
+ * Called after an error is caught
65
+ * Used for side effects like logging
66
+ */
67
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
68
+ render(): ReactNode;
69
+ }
70
+ export {};
71
+ //# sourceMappingURL=error-boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../../../src/components/error-boundary/error-boundary.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,qBAAa,aAAc,SAAQ,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;gBACtE,KAAK,EAAE,kBAAkB;IAKrC;;;OAGG;IACH,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAIjE;;;OAGG;IACH,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,GAAG,IAAI;IAOjE,MAAM,IAAI,SAAS;CAwCpB"}