@teo-garcia/react-shared 0.1.8 → 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.
- package/README.md +76 -168
- package/dist/components/error-boundary/error-boundary.d.ts.map +1 -1
- package/dist/components/error-boundary/error-boundary.js +1 -1
- package/dist/components/index.d.ts +0 -5
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +0 -5
- package/dist/hooks/index.d.ts +6 -5
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +6 -4
- package/dist/hooks/use-debounce.d.ts +2 -0
- package/dist/hooks/use-debounce.d.ts.map +1 -0
- package/dist/hooks/use-debounce.js +9 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts +3 -0
- package/dist/hooks/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/dist/hooks/use-isomorphic-layout-effect.js +4 -0
- package/dist/hooks/use-local-storage.d.ts +2 -0
- package/dist/hooks/use-local-storage.d.ts.map +1 -0
- package/dist/hooks/use-local-storage.js +37 -0
- package/dist/hooks/use-media-query.d.ts +2 -0
- package/dist/hooks/use-media-query.d.ts.map +1 -0
- package/dist/hooks/use-media-query.js +18 -0
- package/dist/hooks/use-on-click-outside.d.ts +3 -0
- package/dist/hooks/use-on-click-outside.d.ts.map +1 -0
- package/dist/hooks/use-on-click-outside.js +17 -0
- package/dist/hooks/use-previous.d.ts +2 -0
- package/dist/hooks/use-previous.d.ts.map +1 -0
- package/dist/hooks/use-previous.js +8 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -9
- package/dist/test-utils/index.d.ts +14 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/index.js +22 -0
- package/dist/types.d.ts +0 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/cn.d.ts +3 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/cn.js +5 -0
- package/dist/utils/index.d.ts +1 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -5
- package/package.json +62 -45
- package/dist/adapters/environment/index.d.ts +0 -6
- package/dist/adapters/environment/index.d.ts.map +0 -1
- package/dist/adapters/environment/index.js +0 -5
- package/dist/adapters/environment/next.d.ts +0 -17
- package/dist/adapters/environment/next.d.ts.map +0 -1
- package/dist/adapters/environment/next.js +0 -20
- package/dist/adapters/environment/vite.d.ts +0 -17
- package/dist/adapters/environment/vite.d.ts.map +0 -1
- package/dist/adapters/environment/vite.js +0 -20
- package/dist/adapters/index.d.ts +0 -9
- package/dist/adapters/index.d.ts.map +0 -1
- package/dist/adapters/index.js +0 -8
- package/dist/adapters/theme/custom.d.ts +0 -32
- package/dist/adapters/theme/custom.d.ts.map +0 -1
- package/dist/adapters/theme/custom.js +0 -26
- package/dist/adapters/theme/index.d.ts +0 -6
- package/dist/adapters/theme/index.d.ts.map +0 -1
- package/dist/adapters/theme/index.js +0 -5
- package/dist/adapters/theme/next-themes.d.ts +0 -18
- package/dist/adapters/theme/next-themes.d.ts.map +0 -1
- package/dist/adapters/theme/next-themes.js +0 -23
- package/dist/components/theme-switch/index.d.ts +0 -3
- package/dist/components/theme-switch/index.d.ts.map +0 -1
- package/dist/components/theme-switch/index.js +0 -1
- package/dist/components/theme-switch/theme-switch.d.ts +0 -36
- package/dist/components/theme-switch/theme-switch.d.ts.map +0 -1
- package/dist/components/theme-switch/theme-switch.js +0 -74
- package/dist/components/viewport-info/index.d.ts +0 -3
- package/dist/components/viewport-info/index.d.ts.map +0 -1
- package/dist/components/viewport-info/index.js +0 -1
- package/dist/components/viewport-info/viewport-info.d.ts +0 -40
- package/dist/components/viewport-info/viewport-info.d.ts.map +0 -1
- package/dist/components/viewport-info/viewport-info.js +0 -69
- package/dist/hooks/use-healthcheck.d.ts +0 -42
- package/dist/hooks/use-healthcheck.d.ts.map +0 -1
- package/dist/hooks/use-healthcheck.js +0 -53
- package/dist/utils/environment.d.ts +0 -71
- package/dist/utils/environment.d.ts.map +0 -1
- package/dist/utils/environment.js +0 -86
- package/dist/utils/msw.d.ts +0 -54
- package/dist/utils/msw.d.ts.map +0 -1
- package/dist/utils/msw.js +0 -62
package/dist/types.d.ts
CHANGED
|
@@ -1,40 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Theme mode type - represents the three possible theme states
|
|
3
|
-
*/
|
|
4
|
-
export type ThemeMode = 'light' | 'dark' | 'system';
|
|
5
|
-
/**
|
|
6
|
-
* ThemeAdapter interface - allows components to work with different theme providers
|
|
7
|
-
* Implementations should map their specific theme library to this interface
|
|
8
|
-
*/
|
|
9
|
-
export interface ThemeAdapter {
|
|
10
|
-
/** Current theme mode */
|
|
11
|
-
theme: ThemeMode;
|
|
12
|
-
/** Function to update the theme */
|
|
13
|
-
setTheme: (theme: ThemeMode) => void;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* EnvironmentAdapter interface - abstracts environment detection across frameworks
|
|
17
|
-
* Different frameworks (Next.js vs Vite) use different environment variable systems
|
|
18
|
-
*/
|
|
19
|
-
export interface EnvironmentAdapter {
|
|
20
|
-
/** Check if running in development mode */
|
|
21
|
-
isDevelopment: () => boolean;
|
|
22
|
-
/** Check if running in production mode */
|
|
23
|
-
isProduction?: () => boolean;
|
|
24
|
-
/** Check if running on server */
|
|
25
|
-
isServer?: () => boolean;
|
|
26
|
-
/** Check if running on client */
|
|
27
|
-
isClient?: () => boolean;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* ErrorBoundary fallback render function type
|
|
31
|
-
*/
|
|
32
1
|
export interface ErrorBoundaryProps {
|
|
33
|
-
/** The React children to wrap */
|
|
34
2
|
children: React.ReactNode;
|
|
35
|
-
/** Optional fallback UI to render on error */
|
|
36
3
|
fallback?: React.ReactNode | ((error: Error) => React.ReactNode);
|
|
37
|
-
/** Optional callback when an error is caught */
|
|
38
4
|
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
39
5
|
}
|
|
40
6
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,KAAK,CAAC,SAAS,CAAC,CAAA;IAChE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAA;CAC7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/utils/cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAA;AAG5C,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAElD"}
|
package/dist/utils/cn.js
ADDED
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teo-garcia/react-shared",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Shared React
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared React hooks, utilities, and test helpers for the teo-garcia template portfolio",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -14,14 +14,6 @@
|
|
|
14
14
|
"import": "./dist/components/index.js",
|
|
15
15
|
"types": "./dist/components/index.d.ts"
|
|
16
16
|
},
|
|
17
|
-
"./components/theme-switch": {
|
|
18
|
-
"import": "./dist/components/theme-switch/index.js",
|
|
19
|
-
"types": "./dist/components/theme-switch/index.d.ts"
|
|
20
|
-
},
|
|
21
|
-
"./components/viewport-info": {
|
|
22
|
-
"import": "./dist/components/viewport-info/index.js",
|
|
23
|
-
"types": "./dist/components/viewport-info/index.d.ts"
|
|
24
|
-
},
|
|
25
17
|
"./components/error-boundary": {
|
|
26
18
|
"import": "./dist/components/error-boundary/index.js",
|
|
27
19
|
"types": "./dist/components/error-boundary/index.d.ts"
|
|
@@ -30,33 +22,41 @@
|
|
|
30
22
|
"import": "./dist/hooks/index.js",
|
|
31
23
|
"types": "./dist/hooks/index.d.ts"
|
|
32
24
|
},
|
|
33
|
-
"./hooks/use-
|
|
34
|
-
"import": "./dist/hooks/use-
|
|
35
|
-
"types": "./dist/hooks/use-
|
|
25
|
+
"./hooks/use-debounce": {
|
|
26
|
+
"import": "./dist/hooks/use-debounce.js",
|
|
27
|
+
"types": "./dist/hooks/use-debounce.d.ts"
|
|
36
28
|
},
|
|
37
|
-
"./
|
|
38
|
-
"import": "./dist/
|
|
39
|
-
"types": "./dist/
|
|
29
|
+
"./hooks/use-isomorphic-layout-effect": {
|
|
30
|
+
"import": "./dist/hooks/use-isomorphic-layout-effect.js",
|
|
31
|
+
"types": "./dist/hooks/use-isomorphic-layout-effect.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./hooks/use-local-storage": {
|
|
34
|
+
"import": "./dist/hooks/use-local-storage.js",
|
|
35
|
+
"types": "./dist/hooks/use-local-storage.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./hooks/use-media-query": {
|
|
38
|
+
"import": "./dist/hooks/use-media-query.js",
|
|
39
|
+
"types": "./dist/hooks/use-media-query.d.ts"
|
|
40
40
|
},
|
|
41
|
-
"./
|
|
42
|
-
"import": "./dist/
|
|
43
|
-
"types": "./dist/
|
|
41
|
+
"./hooks/use-on-click-outside": {
|
|
42
|
+
"import": "./dist/hooks/use-on-click-outside.js",
|
|
43
|
+
"types": "./dist/hooks/use-on-click-outside.d.ts"
|
|
44
44
|
},
|
|
45
|
-
"./
|
|
46
|
-
"import": "./dist/
|
|
47
|
-
"types": "./dist/
|
|
45
|
+
"./hooks/use-previous": {
|
|
46
|
+
"import": "./dist/hooks/use-previous.js",
|
|
47
|
+
"types": "./dist/hooks/use-previous.d.ts"
|
|
48
48
|
},
|
|
49
|
-
"./
|
|
50
|
-
"import": "./dist/
|
|
51
|
-
"types": "./dist/
|
|
49
|
+
"./utils": {
|
|
50
|
+
"import": "./dist/utils/index.js",
|
|
51
|
+
"types": "./dist/utils/index.d.ts"
|
|
52
52
|
},
|
|
53
|
-
"./
|
|
54
|
-
"import": "./dist/
|
|
55
|
-
"types": "./dist/
|
|
53
|
+
"./utils/cn": {
|
|
54
|
+
"import": "./dist/utils/cn.js",
|
|
55
|
+
"types": "./dist/utils/cn.d.ts"
|
|
56
56
|
},
|
|
57
|
-
"./
|
|
58
|
-
"import": "./dist/
|
|
59
|
-
"types": "./dist/
|
|
57
|
+
"./test-utils": {
|
|
58
|
+
"import": "./dist/test-utils/index.js",
|
|
59
|
+
"types": "./dist/test-utils/index.d.ts"
|
|
60
60
|
},
|
|
61
61
|
"./types": {
|
|
62
62
|
"import": "./dist/types.js",
|
|
@@ -70,13 +70,10 @@
|
|
|
70
70
|
],
|
|
71
71
|
"keywords": [
|
|
72
72
|
"react",
|
|
73
|
-
"components",
|
|
74
73
|
"hooks",
|
|
75
74
|
"utilities",
|
|
76
|
-
"
|
|
77
|
-
"typescript"
|
|
78
|
-
"nextjs",
|
|
79
|
-
"react-router"
|
|
75
|
+
"testing",
|
|
76
|
+
"typescript"
|
|
80
77
|
],
|
|
81
78
|
"author": "teo-garcia",
|
|
82
79
|
"license": "MIT",
|
|
@@ -84,33 +81,53 @@
|
|
|
84
81
|
"type": "git",
|
|
85
82
|
"url": "git+https://github.com/teo-garcia/react-shared.git"
|
|
86
83
|
},
|
|
84
|
+
"prettier": "@teo-garcia/prettier-config-shared",
|
|
85
|
+
"packageManager": "pnpm@10.2.0",
|
|
87
86
|
"engines": {
|
|
88
|
-
"node": ">=
|
|
87
|
+
"node": ">=24"
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"clsx": "^2.1.1",
|
|
91
|
+
"tailwind-merge": "^3.0.0"
|
|
89
92
|
},
|
|
90
93
|
"peerDependencies": {
|
|
91
|
-
"lucide-react": "^0.400.0",
|
|
92
94
|
"react": "^19.0.0",
|
|
93
|
-
"react-dom": "^19.0.0"
|
|
95
|
+
"react-dom": "^19.0.0",
|
|
96
|
+
"@tanstack/react-query": "^5.0.0",
|
|
97
|
+
"@testing-library/react": "^16.0.0"
|
|
94
98
|
},
|
|
95
99
|
"peerDependenciesMeta": {
|
|
96
|
-
"
|
|
97
|
-
"optional":
|
|
100
|
+
"@tanstack/react-query": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
103
|
+
"@testing-library/react": {
|
|
104
|
+
"optional": true
|
|
98
105
|
}
|
|
99
106
|
},
|
|
100
107
|
"devDependencies": {
|
|
108
|
+
"@teo-garcia/prettier-config-shared": "^0.2.9",
|
|
101
109
|
"@tanstack/react-query": "^5.0.0",
|
|
110
|
+
"@testing-library/jest-dom": "^6.0.0",
|
|
111
|
+
"@testing-library/react": "^16.0.0",
|
|
102
112
|
"@types/node": "^24.0.0",
|
|
103
113
|
"@types/react": "^19.0.0",
|
|
104
114
|
"@types/react-dom": "^19.0.0",
|
|
105
|
-
"
|
|
106
|
-
"
|
|
115
|
+
"@vitejs/plugin-react": "^5.0.4",
|
|
116
|
+
"happy-dom": "^16.0.0",
|
|
107
117
|
"prettier": "^3.0.0",
|
|
108
|
-
"
|
|
118
|
+
"react": "^19.0.0",
|
|
119
|
+
"react-dom": "^19.0.0",
|
|
120
|
+
"typescript": "^5.0.0",
|
|
121
|
+
"vite-tsconfig-paths": "^6.0.0",
|
|
122
|
+
"vitest": "^4.0.0"
|
|
109
123
|
},
|
|
110
124
|
"scripts": {
|
|
111
|
-
"build": "tsc",
|
|
125
|
+
"build": "rm -rf dist && tsc",
|
|
126
|
+
"check": "pnpm format:check && pnpm build && pnpm test",
|
|
127
|
+
"coverage": "vitest run --coverage",
|
|
112
128
|
"format": "prettier --write .",
|
|
113
129
|
"format:check": "prettier --check .",
|
|
130
|
+
"test": "vitest run",
|
|
114
131
|
"prepublishOnly": "pnpm build"
|
|
115
132
|
}
|
|
116
133
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/environment/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -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
|
-
};
|
package/dist/adapters/index.d.ts
DELETED
|
@@ -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"}
|
package/dist/adapters/index.js
DELETED
|
@@ -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 +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,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 +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
|
-
};
|