@space-man/react-theme-animation 2.0.0 → 2.3.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 +90 -464
- package/dist/core/index.cjs +74 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/{esm/types/index.d.ts → core/index.d.cts} +30 -12
- package/dist/{cjs/types → core}/index.d.ts +30 -12
- package/dist/core/index.js +66 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.cjs +1756 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1706 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +1742 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +224 -0
- package/dist/react/index.d.ts +224 -0
- package/dist/react/index.js +1697 -0
- package/dist/react/index.js.map +1 -0
- package/dist/tanstack/index.cjs +34 -0
- package/dist/tanstack/index.cjs.map +1 -0
- package/dist/tanstack/index.d.cts +20 -0
- package/dist/tanstack/index.d.ts +20 -0
- package/dist/tanstack/index.js +27 -0
- package/dist/tanstack/index.js.map +1 -0
- package/package.json +66 -37
- package/dist/cjs/components/SpacemanThemeProvider.d.ts +0 -57
- package/dist/cjs/components/SpacemanThemeProvider.js +0 -113
- package/dist/cjs/components/ThemeSelector.d.ts +0 -3
- package/dist/cjs/components/ThemeSelector.js +0 -39
- package/dist/cjs/components/ThemeSwitcher.d.ts +0 -3
- package/dist/cjs/components/ThemeSwitcher.js +0 -81
- package/dist/cjs/components/ViteThemeProvider.d.ts +0 -38
- package/dist/cjs/components/ViteThemeProvider.js +0 -117
- package/dist/cjs/components/ui/select.d.ts +0 -15
- package/dist/cjs/components/ui/select.js +0 -83
- package/dist/cjs/hooks/use-theme-animation.d.ts +0 -2
- package/dist/cjs/hooks/use-theme-animation.js +0 -234
- package/dist/cjs/index.d.ts +0 -8
- package/dist/cjs/index.js +0 -23
- package/dist/cjs/types/index.js +0 -9
- package/dist/cjs/utils/animations.d.ts +0 -21
- package/dist/cjs/utils/animations.js +0 -189
- package/dist/esm/components/SpacemanThemeProvider.d.ts +0 -57
- package/dist/esm/components/SpacemanThemeProvider.js +0 -108
- package/dist/esm/components/ThemeSelector.d.ts +0 -3
- package/dist/esm/components/ThemeSelector.js +0 -35
- package/dist/esm/components/ThemeSwitcher.d.ts +0 -3
- package/dist/esm/components/ThemeSwitcher.js +0 -77
- package/dist/esm/components/ViteThemeProvider.d.ts +0 -38
- package/dist/esm/components/ViteThemeProvider.js +0 -112
- package/dist/esm/components/ui/select.d.ts +0 -15
- package/dist/esm/components/ui/select.js +0 -39
- package/dist/esm/hooks/use-theme-animation.d.ts +0 -2
- package/dist/esm/hooks/use-theme-animation.js +0 -230
- package/dist/esm/index.d.ts +0 -8
- package/dist/esm/index.js +0 -7
- package/dist/esm/types/index.js +0 -6
- package/dist/esm/utils/animations.d.ts +0 -21
- package/dist/esm/utils/animations.js +0 -177
package/README.md
CHANGED
|
@@ -1,85 +1,18 @@
|
|
|
1
1
|
# @space-man/react-theme-animation
|
|
2
2
|
|
|
3
|
-
https://github.com/user-attachments/assets/2819cf70-c474-478e-b821-6b26457c8d4a
|
|
4
|
-
|
|
5
3
|
React theme switching with smooth view transition animations, multi-theme support, and synchronized state management.
|
|
6
4
|
|
|
7
|
-
## Spaceman React Theme Animation
|
|
8
|
-
|
|
9
|
-
Version 2 introduces new features for enhanced color theme management and improved Vite integration.
|
|
5
|
+
## Spaceman React Theme Animation v2 release
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
- Vite theme provider now supports theme toggling and persistence
|
|
13
|
-
- Functions to manage and check active themes
|
|
14
|
-
- Functions to toggle light and dark themes directly
|
|
7
|
+
Version 2 moves the library into a workspace-friendly monorepo, keeps the published package name stable, and standardizes the public API around flat root imports.
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
import { useThemeAnimation } from '@space-man/react-theme-animation'
|
|
9
|
+
Highlights in this release:
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<>
|
|
27
|
-
<button onClick={createColorThemeToggle('supabase')} className="theme-toggle-btn">
|
|
28
|
-
Supabase Theme {isColorThemeActive('supabase') ? '✅' : '❌'}
|
|
29
|
-
</button>
|
|
30
|
-
<button ref={ref} onClick={toggleDarkTheme} className="theme-toggle-btn">
|
|
31
|
-
Dark Theme
|
|
32
|
-
</button>
|
|
33
|
-
<button ref={ref} onClick={toggleLightTheme} className="theme-toggle-btn">
|
|
34
|
-
Light Theme
|
|
35
|
-
</button>
|
|
36
|
-
</>
|
|
37
|
-
)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Vite Theme Provider Example
|
|
41
|
-
function App() {
|
|
42
|
-
return (
|
|
43
|
-
<ViteThemeProvider
|
|
44
|
-
themes={['light', 'dark', 'system']}
|
|
45
|
-
colorThemes={['default', 'supabase']}
|
|
46
|
-
defaultTheme="system"
|
|
47
|
-
defaultColorTheme="default"
|
|
48
|
-
>
|
|
49
|
-
<ThemeToggle />
|
|
50
|
-
</ViteThemeProvider>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function ThemeToggle() {
|
|
55
|
-
const { createColorThemeToggle, isColorThemeActive } = useViteTheme()
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<button onClick={createColorThemeToggle('supabase')} className="theme-toggle-btn">
|
|
59
|
-
Supabase Theme {isColorThemeActive('supabase') ? '✅' : '❌'}
|
|
60
|
-
</button>
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## Live Demo
|
|
66
|
-
|
|
67
|
-
[Live Demo Link](https://spaceman-rta-vite.netlify.app/)
|
|
68
|
-
|
|
69
|
-
## Features
|
|
70
|
-
|
|
71
|
-
- **Smooth Animations**: Beautiful view transition animations for theme switching with customizable origins
|
|
72
|
-
- **Multi-Theme Support**: Support for light, dark, and system themes
|
|
73
|
-
- **Color Themes**: Additional color theme variants (brand colors, etc.)
|
|
74
|
-
- **Powerful Hook**: `useThemeAnimation` hook with full control
|
|
75
|
-
- **Ready Components**: `ThemeSwitcher` and `ThemeSelector` components
|
|
76
|
-
- **Provider Pattern**: Centralized theme state management with `SpacemanThemeProvider`
|
|
77
|
-
- **State Synchronization**: Prevents state drift between multiple components
|
|
78
|
-
- **Responsive**: Works on all screen sizes including high-resolution displays
|
|
79
|
-
- **Performance**: Optimized animations with reduced motion support
|
|
80
|
-
- **TypeScript**: Full TypeScript support with comprehensive types
|
|
81
|
-
- **Customizable**: Extensive configuration options
|
|
82
|
-
- **Backward Compatible**: Works with existing implementations
|
|
11
|
+
- root-first public API via `@space-man/react-theme-animation`
|
|
12
|
+
- framework-specific providers for Next.js, TanStack Start, and Vite
|
|
13
|
+
- TanStack SSR helpers exposed from the root package
|
|
14
|
+
- workspace examples for Next.js, TanStack Start, and TanStack Start SSR
|
|
15
|
+
- build and packaging updates for ESM, CJS, and declaration output
|
|
83
16
|
|
|
84
17
|
## Installation
|
|
85
18
|
|
|
@@ -87,435 +20,128 @@ function ThemeToggle() {
|
|
|
87
20
|
npm install @space-man/react-theme-animation
|
|
88
21
|
```
|
|
89
22
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
1. **Hook-Only Usage**: Direct hook usage for custom implementations
|
|
95
|
-
2. **Provider Pattern**: Centralized state management (recommended)
|
|
96
|
-
3. **ViteThemeProvider**: Specialized provider for Vite React SPAs
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add @space-man/react-theme-animation
|
|
25
|
+
```
|
|
97
26
|
|
|
98
|
-
|
|
27
|
+
```bash
|
|
28
|
+
yarn add @space-man/react-theme-animation
|
|
29
|
+
```
|
|
99
30
|
|
|
100
|
-
|
|
31
|
+
## Imports
|
|
101
32
|
|
|
102
|
-
|
|
33
|
+
Import everything from the package root:
|
|
103
34
|
|
|
104
|
-
|
|
35
|
+
```tsx
|
|
36
|
+
import {
|
|
37
|
+
NextThemeProvider,
|
|
38
|
+
TanStackThemeProvider,
|
|
39
|
+
ViteThemeProvider,
|
|
40
|
+
ThemeSwitcher,
|
|
41
|
+
ThemeSelector,
|
|
42
|
+
useThemeAnimation,
|
|
43
|
+
} from '@space-man/react-theme-animation'
|
|
44
|
+
```
|
|
105
45
|
|
|
106
|
-
|
|
46
|
+
Compatibility subpath exports still exist for migration safety, but the package root is the documented public API.
|
|
107
47
|
|
|
108
|
-
|
|
48
|
+
For Next.js App Router, import providers/hooks from the package root inside client components. A
|
|
49
|
+
typical setup is a local `app/providers.tsx` file with `'use client'`, rendered by the server
|
|
50
|
+
`app/layout.tsx`.
|
|
109
51
|
|
|
110
|
-
|
|
52
|
+
## Tailwind Setup For Prebuilt Components
|
|
111
53
|
|
|
112
|
-
|
|
113
|
-
import { useThemeAnimation } from '@space-man/react-theme-animation'
|
|
54
|
+
`ThemeSwitcher`, `ThemeSelector`, and the bundled select primitives use Tailwind utility classes. The package does not ship a compiled stylesheet for those components, so the consuming app must include the installed package in Tailwind's source scan.
|
|
114
55
|
|
|
115
|
-
|
|
116
|
-
const { theme, toggleTheme, ref } = useThemeAnimation()
|
|
56
|
+
For Tailwind v4, add an `@source` directive next to your Tailwind import:
|
|
117
57
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
</button>
|
|
122
|
-
)
|
|
123
|
-
}
|
|
58
|
+
```css
|
|
59
|
+
@import 'tailwindcss';
|
|
60
|
+
@source '../node_modules/@space-man/react-theme-animation/dist';
|
|
124
61
|
```
|
|
125
62
|
|
|
126
|
-
|
|
63
|
+
Adjust the relative path to match your app structure.
|
|
64
|
+
|
|
65
|
+
## Provider Selection
|
|
127
66
|
|
|
128
|
-
|
|
67
|
+
Choose the right provider for your framework:
|
|
129
68
|
|
|
130
|
-
|
|
69
|
+
| Provider | Best For | Key Features |
|
|
70
|
+
| --------------------- | ------------------------------ | ------------------------------------------------- |
|
|
71
|
+
| SpacemanThemeProvider | General React apps | Universal provider with synchronized theme state |
|
|
72
|
+
| NextThemeProvider | Next.js, Remix, SSR frameworks | Pre-hydration script, CSP support, animations |
|
|
73
|
+
| TanStackThemeProvider | TanStack Start apps | Cookie SSR, pre-hydration script, system CSS mode |
|
|
74
|
+
| ViteThemeProvider | Vite React SPAs | Lightweight, transition control, no SSR overhead |
|
|
131
75
|
|
|
132
|
-
|
|
76
|
+
## Quick Start
|
|
133
77
|
|
|
134
78
|
```tsx
|
|
135
79
|
import {
|
|
136
80
|
SpacemanThemeProvider,
|
|
137
|
-
|
|
138
|
-
ThemeSelector,
|
|
81
|
+
useSpacemanTheme,
|
|
139
82
|
} from '@space-man/react-theme-animation'
|
|
140
83
|
|
|
141
84
|
function App() {
|
|
142
85
|
return (
|
|
143
|
-
<SpacemanThemeProvider>
|
|
144
|
-
<
|
|
145
|
-
<header>
|
|
146
|
-
<ThemeSwitcher />
|
|
147
|
-
</header>
|
|
148
|
-
|
|
149
|
-
<aside>
|
|
150
|
-
<ThemeSelector colorThemes={['default', 'supabase', 'mono']} />
|
|
151
|
-
</aside>
|
|
152
|
-
|
|
153
|
-
<main>
|
|
154
|
-
<YourAppContent />
|
|
155
|
-
</main>
|
|
156
|
-
</div>
|
|
157
|
-
</SpacemanThemeProvider>
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
---
|
|
163
|
-
|
|
164
|
-
## 3. ViteThemeProvider (Vite React SPAs)
|
|
165
|
-
|
|
166
|
-
Specialized theme provider optimized for Vite React single-page applications. Provides essential theme management without animation features.
|
|
167
|
-
|
|
168
|
-
### Basic Vite Setup
|
|
169
|
-
|
|
170
|
-
```tsx
|
|
171
|
-
import { ViteThemeProvider, useViteTheme } from '@space-man/react-theme-animation'
|
|
172
|
-
|
|
173
|
-
function App() {
|
|
174
|
-
return (
|
|
175
|
-
<ViteThemeProvider defaultTheme="system" storageKey="my-app-theme" attribute="class">
|
|
176
|
-
<div className="app">
|
|
177
|
-
<header>
|
|
178
|
-
<ThemeToggle />
|
|
179
|
-
</header>
|
|
180
|
-
<main>
|
|
181
|
-
<ThemeSection />
|
|
182
|
-
</main>
|
|
183
|
-
</div>
|
|
184
|
-
</ViteThemeProvider>
|
|
185
|
-
)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function ThemeSection() {
|
|
189
|
-
return (
|
|
190
|
-
<SpacemanThemeProvider>
|
|
191
|
-
<div className="app">
|
|
192
|
-
<header>
|
|
193
|
-
<ThemeSwitcher />
|
|
194
|
-
</header>
|
|
195
|
-
|
|
196
|
-
<aside>
|
|
197
|
-
<ThemeSelector colorThemes={['default', 'supabase', 'mono']} />
|
|
198
|
-
</aside>
|
|
199
|
-
|
|
200
|
-
<main>
|
|
201
|
-
<YourAppContent />
|
|
202
|
-
</main>
|
|
203
|
-
</div>
|
|
86
|
+
<SpacemanThemeProvider defaultTheme="system" defaultColorTheme="default">
|
|
87
|
+
<YourApp />
|
|
204
88
|
</SpacemanThemeProvider>
|
|
205
89
|
)
|
|
206
90
|
}
|
|
207
91
|
|
|
208
92
|
function ThemeToggle() {
|
|
209
|
-
const { theme,
|
|
93
|
+
const { theme, toggleTheme, ref } = useSpacemanTheme()
|
|
210
94
|
|
|
211
95
|
return (
|
|
212
|
-
<button onClick={() =>
|
|
213
|
-
{
|
|
96
|
+
<button ref={ref} onClick={() => toggleTheme()}>
|
|
97
|
+
{theme === 'light' ? 'Dark' : 'Light'}
|
|
214
98
|
</button>
|
|
215
99
|
)
|
|
216
100
|
}
|
|
217
101
|
```
|
|
218
102
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
| Prop | Type | Default | Description |
|
|
222
|
-
| --------------------------- | ------------------------------- | -------------- | ------------------------------------------- |
|
|
223
|
-
| `children` | `ReactNode` | - | React children |
|
|
224
|
-
| `attribute` | `'class' \| 'data-theme'` | `'class'` | How to apply theme to DOM |
|
|
225
|
-
| `defaultTheme` | `'light' \| 'dark' \| 'system'` | `'system'` | Default theme |
|
|
226
|
-
| `enableSystem` | `boolean` | `true` | Enable system theme detection |
|
|
227
|
-
| `disableTransitionOnChange` | `boolean` | `false` | Disable CSS transitions during theme change |
|
|
228
|
-
| `storageKey` | `string` | `'vite-theme'` | localStorage key for persistence |
|
|
229
|
-
|
|
230
|
-
---
|
|
231
|
-
|
|
232
|
-
## Defining Application color theme as CSS Variables
|
|
233
|
-
|
|
234
|
-
The library uses CSS custom properties for theming. Define these in your **MAIN** CSS file. _Note_: do not define the other theme variables in a separate CSS file and import it, as the `:root` variables for light mode will override the light mode variables for the other themes. Keep everything in the same file.
|
|
235
|
-
|
|
236
|
-
```css
|
|
237
|
-
/* Base theme variables */
|
|
238
|
-
:root {
|
|
239
|
-
--background: 0 0% 100%;
|
|
240
|
-
--foreground: 222.2 84% 4.9%;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/* Dark theme */
|
|
244
|
-
.dark {
|
|
245
|
-
--background: 222.2 84% 4.9%;
|
|
246
|
-
--foreground: 210 40% 98%;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/* Add other theme variants from design system or tweakcn */
|
|
250
|
-
|
|
251
|
-
.theme-supabase {
|
|
252
|
-
--background: oklch(0.9911 0 0);
|
|
253
|
-
--foreground: oklch(0.2046 0 0);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
.theme-supabase.dark {
|
|
257
|
-
--background: oklch(0.1822 0 0);
|
|
258
|
-
--foreground: oklch(0.9288 0.0126 255.5078);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
.theme-mono {
|
|
262
|
-
--background: oklch(1 0 0);
|
|
263
|
-
--foreground: oklch(0.1448 0 0);
|
|
264
|
-
}
|
|
103
|
+
## Documentation
|
|
265
104
|
|
|
266
|
-
|
|
267
|
-
--background: oklch(0.1448 0 0);
|
|
268
|
-
--foreground: oklch(1 0 0);
|
|
269
|
-
}
|
|
270
|
-
```
|
|
105
|
+
Repository documentation, framework guides, migration notes, and examples are linked from the GitHub docs hub:
|
|
271
106
|
|
|
272
|
-
|
|
107
|
+
- https://github.com/tonyedgal/spaceman-react-theme-animation#documentation
|
|
273
108
|
|
|
274
109
|
## API Reference
|
|
275
110
|
|
|
276
|
-
###
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
Hook to access theme state from SpacemanThemeProvider context.
|
|
312
|
-
|
|
313
|
-
```tsx
|
|
314
|
-
const { theme, colorTheme, switchTheme, setColorTheme, switchThemeFromElement, ref } =
|
|
315
|
-
useSpacemanTheme()
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
#### Returns
|
|
319
|
-
|
|
320
|
-
| Property | Type | Description |
|
|
321
|
-
| ------------------------ | ------------------------------------------------------- | ------------------------------------------------- |
|
|
322
|
-
| `theme` | `Theme` | Current theme |
|
|
323
|
-
| `colorTheme` | `ColorTheme` | Current color theme |
|
|
324
|
-
| `switchTheme` | `(theme: Theme) => Promise<void>` | Switch to specific theme |
|
|
325
|
-
| `setColorTheme` | `(colorTheme: ColorTheme) => void` | Set color theme |
|
|
326
|
-
| `switchThemeFromElement` | `(theme: Theme, element: HTMLElement) => Promise<void>` | Switch theme with animation from specific element |
|
|
327
|
-
| `ref` | `RefObject<HTMLElement>` | Ref for animation origin |
|
|
328
|
-
|
|
329
|
-
### useThemeAnimation
|
|
330
|
-
|
|
331
|
-
Standalone hook for theme management and animations.
|
|
332
|
-
|
|
333
|
-
```tsx
|
|
334
|
-
const { theme, colorTheme, switchTheme, setColorTheme, toggleTheme, ref } = useThemeAnimation({
|
|
335
|
-
themes: ['light', 'dark', 'system'],
|
|
336
|
-
colorThemes: ['default', 'blue', 'green', 'purple'],
|
|
337
|
-
animationType: ThemeAnimationType.SLIDE,
|
|
338
|
-
duration: 800,
|
|
339
|
-
onThemeChange: theme => console.log('Theme changed:', theme),
|
|
340
|
-
onColorThemeChange: colorTheme => console.log('Color changed:', colorTheme),
|
|
341
|
-
})
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
#### Options
|
|
345
|
-
|
|
346
|
-
| Property | Type | Default | Description |
|
|
347
|
-
| -------------------- | ---------------------------------- | ----------------------------- | --------------------------------------------------- |
|
|
348
|
-
| `themes` | `Theme[]` | `['light', 'dark', 'system']` | Available themes |
|
|
349
|
-
| `colorThemes` | `ColorTheme[]` | `['default']` | Available color themes |
|
|
350
|
-
| `theme` | `Theme` | `'system'` | Initial theme |
|
|
351
|
-
| `colorTheme` | `ColorTheme` | `'default'` | Initial color theme |
|
|
352
|
-
| `animationType` | `ThemeAnimationType` | `ThemeAnimationType.CIRCLE` | Animation type. Options: CIRCLE, BLUR_CIRCLE, SLIDE |
|
|
353
|
-
| `duration` | `number` | `500` | Animation duration in ms |
|
|
354
|
-
| `blurAmount` | `number` | `2` | Blur amount for blur-circle animation |
|
|
355
|
-
| `onThemeChange` | `(theme: Theme) => void` | - | Theme change callback |
|
|
356
|
-
| `onColorThemeChange` | `(colorTheme: ColorTheme) => void` | - | Color theme change callback |
|
|
357
|
-
| `slideDirection` | `SlideDirection` | `left` | Animation slide direction |
|
|
358
|
-
|
|
359
|
-
#### Return
|
|
360
|
-
|
|
361
|
-
| Property | Type | Description |
|
|
362
|
-
| --------------- | ---------------------------------- | ------------------------- |
|
|
363
|
-
| `theme` | `Theme` | Current theme |
|
|
364
|
-
| `colorTheme` | `ColorTheme` | Current color theme |
|
|
365
|
-
| `switchTheme` | `(theme: Theme) => Promise<void>` | Switch to specific theme |
|
|
366
|
-
| `setColorTheme` | `(colorTheme: ColorTheme) => void` | Set color theme |
|
|
367
|
-
| `toggleTheme` | `() => Promise<void>` | Toggle between light/dark |
|
|
368
|
-
| `ref` | `RefObject<HTMLElement>` | Ref for animation origin |
|
|
369
|
-
|
|
370
|
-
### ThemeSwitcher
|
|
371
|
-
|
|
372
|
-
Pre-built theme switcher component with animated buttons.
|
|
373
|
-
|
|
374
|
-
```tsx
|
|
375
|
-
<ThemeSwitcher
|
|
376
|
-
themes={['light', 'dark', 'system']}
|
|
377
|
-
currentTheme="light"
|
|
378
|
-
onThemeChange={theme => console.log(theme)}
|
|
379
|
-
animationType={ThemeAnimationType.CIRCLE}
|
|
380
|
-
duration={600}
|
|
381
|
-
className="custom-class"
|
|
382
|
-
/>
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
#### ThemeSwitcher Props
|
|
386
|
-
|
|
387
|
-
| Property | Type | Default | Description |
|
|
388
|
-
| --------------- | ------------------------ | ----------------------------- | ----------------------------------- |
|
|
389
|
-
| `themes` | `Theme[]` | `['light', 'dark', 'system']` | Available themes |
|
|
390
|
-
| `currentTheme` | `Theme` | - | Controlled current theme (optional) |
|
|
391
|
-
| `onThemeChange` | `(theme: Theme) => void` | - | Theme change callback (optional) |
|
|
392
|
-
| `animationType` | `ThemeAnimationType` | `ThemeAnimationType.CIRCLE` | Animation type |
|
|
393
|
-
| `duration` | `number` | `500` | Animation duration in ms |
|
|
394
|
-
| `className` | `string` | - | Additional CSS classes |
|
|
395
|
-
|
|
396
|
-
> **Note**: When used with `SpacemanThemeProvider`, `currentTheme` and `onThemeChange` are automatically handled by the context.
|
|
397
|
-
|
|
398
|
-
### ThemeSelector
|
|
399
|
-
|
|
400
|
-
Dropdown selector for color themes.
|
|
401
|
-
|
|
402
|
-
```tsx
|
|
403
|
-
<ThemeSelector
|
|
404
|
-
colorThemes={['default', 'blue', 'green', 'purple']}
|
|
405
|
-
currentColorTheme="blue"
|
|
406
|
-
onColorThemeChange={colorTheme => console.log(colorTheme)}
|
|
407
|
-
animationType={ThemeAnimationType.BLUR_CIRCLE}
|
|
408
|
-
duration={400}
|
|
409
|
-
/>
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
#### ThemeSelector Props
|
|
413
|
-
|
|
414
|
-
| Property | Type | Default | Description |
|
|
415
|
-
| -------------------- | ---------------------------------- | ----------------------------- | ----------------------------------------- |
|
|
416
|
-
| `themes` | `Theme[]` | `['light', 'dark', 'system']` | Available themes (for standalone hook) |
|
|
417
|
-
| `colorThemes` | `ColorTheme[]` | `['default']` | Available color themes |
|
|
418
|
-
| `currentColorTheme` | `ColorTheme` | - | Controlled current color theme (optional) |
|
|
419
|
-
| `onColorThemeChange` | `(colorTheme: ColorTheme) => void` | - | Color theme change callback (optional) |
|
|
420
|
-
| `animationType` | `ThemeAnimationType` | `ThemeAnimationType.CIRCLE` | Animation type |
|
|
421
|
-
| `duration` | `number` | `500` | Animation duration in ms |
|
|
422
|
-
|
|
423
|
-
> **Note**: When used with `SpacemanThemeProvider`, `currentColorTheme` and `onColorThemeChange` are automatically handled by the context.
|
|
424
|
-
|
|
425
|
-
### ThemeAnimationType
|
|
426
|
-
|
|
427
|
-
Animation types for theme transitions.
|
|
428
|
-
|
|
429
|
-
```tsx
|
|
430
|
-
enum ThemeAnimationType {
|
|
431
|
-
CIRCLE = 'circle',
|
|
432
|
-
BLUR_CIRCLE = 'blur-circle',
|
|
433
|
-
}
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
### Types
|
|
437
|
-
|
|
438
|
-
```tsx
|
|
439
|
-
type Theme = 'light' | 'dark' | 'system'
|
|
440
|
-
type ColorTheme = string // e.g., 'default', 'blue', 'green', etc.
|
|
441
|
-
|
|
442
|
-
interface SpacemanThemeProviderProps {
|
|
443
|
-
children: React.ReactNode
|
|
444
|
-
defaultTheme?: Theme
|
|
445
|
-
defaultColorTheme?: ColorTheme
|
|
446
|
-
themes?: Theme[]
|
|
447
|
-
colorThemes?: ColorTheme[]
|
|
448
|
-
animationType?: ThemeAnimationType
|
|
449
|
-
duration?: number
|
|
450
|
-
blurAmount?: number
|
|
451
|
-
onThemeChange?: (theme: Theme) => void
|
|
452
|
-
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
interface UseThemeAnimationProps {
|
|
456
|
-
themes?: Theme[]
|
|
457
|
-
colorThemes?: ColorTheme[]
|
|
458
|
-
theme?: Theme
|
|
459
|
-
colorTheme?: ColorTheme
|
|
460
|
-
animationType?: ThemeAnimationType
|
|
461
|
-
duration?: number
|
|
462
|
-
blurAmount?: number
|
|
463
|
-
onThemeChange?: (theme: Theme) => void
|
|
464
|
-
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
interface UseThemeAnimationReturn {
|
|
468
|
-
theme: Theme
|
|
469
|
-
colorTheme: ColorTheme
|
|
470
|
-
switchTheme: (theme: Theme) => Promise<void>
|
|
471
|
-
setColorTheme: (colorTheme: ColorTheme) => void
|
|
472
|
-
toggleTheme: () => Promise<void>
|
|
473
|
-
ref: RefObject<HTMLElement>
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
interface ThemeSwitcherProps {
|
|
477
|
-
themes?: Theme[]
|
|
478
|
-
currentTheme?: Theme
|
|
479
|
-
onThemeChange?: (theme: Theme) => void
|
|
480
|
-
animationType?: ThemeAnimationType
|
|
481
|
-
duration?: number
|
|
482
|
-
className?: string
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
interface ThemeSelectorProps {
|
|
486
|
-
themes?: Theme[]
|
|
487
|
-
colorThemes?: ColorTheme[]
|
|
488
|
-
currentColorTheme?: ColorTheme
|
|
489
|
-
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
490
|
-
animationType?: ThemeAnimationType
|
|
491
|
-
duration?: number
|
|
492
|
-
}
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
---
|
|
496
|
-
|
|
497
|
-
---
|
|
498
|
-
|
|
499
|
-
## Browser Support
|
|
500
|
-
|
|
501
|
-
- **View Transitions API**: Chrome 111+, Edge 111+
|
|
502
|
-
- **Fallback**: All modern browsers with CSS transitions
|
|
503
|
-
- **Reduced Motion**: Respects `prefers-reduced-motion` setting
|
|
504
|
-
- **Framework Support**: React 16.8+ (hooks required)
|
|
505
|
-
|
|
506
|
-
---
|
|
507
|
-
|
|
508
|
-
## Performance
|
|
509
|
-
|
|
510
|
-
- Animations use the View Transitions API when available
|
|
511
|
-
- Optimized for 60fps animations
|
|
512
|
-
- Respects `prefers-reduced-motion` setting
|
|
513
|
-
|
|
514
|
-
---
|
|
515
|
-
|
|
516
|
-
## Contributing
|
|
517
|
-
|
|
518
|
-
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
|
|
111
|
+
### Shared Hook Return (All Providers)
|
|
112
|
+
|
|
113
|
+
All providers expose the same core hook interface:
|
|
114
|
+
|
|
115
|
+
| Property | Type | Description |
|
|
116
|
+
| ---------------------- | ------------------------------------------------------- | ---------------------------------- |
|
|
117
|
+
| theme | Theme | Current theme |
|
|
118
|
+
| colorTheme | ColorTheme | Current color theme |
|
|
119
|
+
| resolvedTheme | 'light' \| 'dark' | Resolved theme (system → actual) |
|
|
120
|
+
| systemTheme | 'light' \| 'dark' | OS theme preference |
|
|
121
|
+
| ref | RefObject<HTMLElement> | Ref for animation origin |
|
|
122
|
+
| setTheme | (theme: Theme) => void | Set theme instantly |
|
|
123
|
+
| setColorTheme | (colorTheme: ColorTheme) => void | Set color theme |
|
|
124
|
+
| switchTheme | (theme: Theme, animationOff?: boolean) => Promise<void> | Switch with animation |
|
|
125
|
+
| switchColorTheme | (colorTheme: string) => void | Switch color theme with animation |
|
|
126
|
+
| toggleTheme | (animationOff?: boolean) => Promise<void> | Toggle light/dark |
|
|
127
|
+
| toggleLightTheme | (animationOff?: boolean) => Promise<void> | Toggle to light |
|
|
128
|
+
| toggleDarkTheme | (animationOff?: boolean) => Promise<void> | Toggle to dark |
|
|
129
|
+
| toggleColorTheme | () => void | Toggle between color themes |
|
|
130
|
+
| createColorThemeToggle | (colorTheme: string) => () => void | Create color theme toggle |
|
|
131
|
+
| isColorThemeActive | (colorTheme: string) => boolean | Check if color theme active |
|
|
132
|
+
| switchThemeFromElement | (theme: Theme, element: HTMLElement) => Promise<void> | Switch with animation from element |
|
|
133
|
+
|
|
134
|
+
### Root Exports
|
|
135
|
+
|
|
136
|
+
The root package exports:
|
|
137
|
+
|
|
138
|
+
- providers and framework hooks
|
|
139
|
+
- prebuilt `ThemeSwitcher` and `ThemeSelector`
|
|
140
|
+
- `useThemeAnimation`
|
|
141
|
+
- shared types and animation utilities
|
|
142
|
+
- TanStack server helpers such as `buildServerThemeData`, `STORAGE_KEY`, and `COLOR_STORAGE_KEY`
|
|
143
|
+
|
|
144
|
+
See the repository docs hub for provider-specific setup guides and examples.
|
|
519
145
|
|
|
520
146
|
## License
|
|
521
147
|
|