@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
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { useThemeAnimation } from '../hooks/use-theme-animation';
|
|
3
|
-
import { useSpacemanTheme } from './SpacemanThemeProvider';
|
|
4
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select';
|
|
5
|
-
export const ThemeSelector = ({ themes = ['light', 'dark', 'system'], colorThemes = ['default'], currentColorTheme, onColorThemeChange, animationType, duration, }) => {
|
|
6
|
-
// Try to use SpacemanTheme context if available (controlled mode)
|
|
7
|
-
let contextTheme = null;
|
|
8
|
-
try {
|
|
9
|
-
contextTheme = useSpacemanTheme();
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
// Context not available, use standalone mode
|
|
13
|
-
}
|
|
14
|
-
// Use context if available, otherwise fall back to standalone hook
|
|
15
|
-
const standaloneHook = useThemeAnimation({
|
|
16
|
-
animationType,
|
|
17
|
-
duration,
|
|
18
|
-
themes,
|
|
19
|
-
colorThemes,
|
|
20
|
-
...(currentColorTheme !== undefined && { colorTheme: currentColorTheme }),
|
|
21
|
-
onColorThemeChange,
|
|
22
|
-
});
|
|
23
|
-
const isControlled = contextTheme !== null;
|
|
24
|
-
const { colorTheme, setColorTheme } = isControlled
|
|
25
|
-
? { colorTheme: contextTheme.colorTheme, setColorTheme: contextTheme.setColorTheme }
|
|
26
|
-
: standaloneHook;
|
|
27
|
-
const handleColorThemeChange = (newColorTheme) => {
|
|
28
|
-
setColorTheme(newColorTheme);
|
|
29
|
-
// Also call the callback if provided
|
|
30
|
-
if (onColorThemeChange) {
|
|
31
|
-
onColorThemeChange(newColorTheme);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
return (_jsx(_Fragment, { children: colorThemes.length > 1 && (_jsx("div", { className: "flex flex-col gap-2", children: _jsxs(Select, { value: colorTheme, onValueChange: (v) => handleColorThemeChange(v), children: [_jsx(SelectTrigger, { className: "capitalize", children: _jsx(SelectValue, { placeholder: "Choose a color theme" }) }), _jsx(SelectContent, { children: colorThemes.map(theme => (_jsx(SelectItem, { className: "capitalize", value: theme, children: theme }, theme))) })] }) })) }));
|
|
35
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
import { motion } from 'motion/react';
|
|
4
|
-
import { clsx } from 'clsx';
|
|
5
|
-
import { useThemeAnimation } from '../hooks/use-theme-animation';
|
|
6
|
-
import { useSpacemanTheme } from './SpacemanThemeProvider';
|
|
7
|
-
const SunIcon = () => (_jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("circle", { cx: "12", cy: "12", r: "5" }), _jsx("path", { d: "M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42" })] }));
|
|
8
|
-
const MoonIcon = () => (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" }) }));
|
|
9
|
-
const MonitorIcon = () => (_jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [_jsx("rect", { width: "20", height: "14", x: "2", y: "3", rx: "2" }), _jsx("line", { x1: "8", x2: "16", y1: "21", y2: "21" }), _jsx("line", { x1: "12", x2: "12", y1: "17", y2: "21" })] }));
|
|
10
|
-
const ThemeOption = ({ icon, value, isActive, isHovered, onClick, onMouseEnter, onMouseLeave, buttonRef, }) => {
|
|
11
|
-
return (_jsxs("button", { ref: isActive ? buttonRef : undefined, className: clsx('relative flex h-9 w-12 cursor-pointer items-center justify-center', 'text-muted-foreground hover:text-foreground', isActive && 'text-foreground font-medium'), role: "radio", "aria-checked": isActive, "aria-label": `Switch to ${value} theme`, onClick: event => onClick(value, event), onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, style: {
|
|
12
|
-
borderRadius: 'var(--radius)',
|
|
13
|
-
}, children: [isHovered && (_jsx(motion.div, { layoutId: "theme-hover", className: "absolute inset-0 bg-muted", style: {
|
|
14
|
-
borderRadius: 'var(--radius)',
|
|
15
|
-
}, transition: {
|
|
16
|
-
type: 'spring',
|
|
17
|
-
bounce: 0,
|
|
18
|
-
stiffness: 100,
|
|
19
|
-
damping: 10,
|
|
20
|
-
duration: 0.3,
|
|
21
|
-
} })), _jsx("div", { className: "relative z-10 flex items-center justify-center", children: _jsx("div", { className: "[&_svg]:size-4", children: icon }) }), isActive && (_jsx("div", { className: "absolute bottom-0 left-1/2 h-0.5 w-6 -translate-x-1/2 rounded-full", style: {
|
|
22
|
-
backgroundColor: 'hsl(var(--primary))',
|
|
23
|
-
} }))] }));
|
|
24
|
-
};
|
|
25
|
-
const THEME_OPTIONS = [
|
|
26
|
-
{
|
|
27
|
-
icon: _jsx(MonitorIcon, {}),
|
|
28
|
-
value: 'system',
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
icon: _jsx(SunIcon, {}),
|
|
32
|
-
value: 'light',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
icon: _jsx(MoonIcon, {}),
|
|
36
|
-
value: 'dark',
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
export const ThemeSwitcher = ({ themes = ['light', 'dark', 'system'], currentTheme, onThemeChange, animationType, duration, className, }) => {
|
|
40
|
-
let contextTheme = null;
|
|
41
|
-
try {
|
|
42
|
-
contextTheme = useSpacemanTheme();
|
|
43
|
-
}
|
|
44
|
-
catch { }
|
|
45
|
-
const standaloneHook = useThemeAnimation({
|
|
46
|
-
animationType,
|
|
47
|
-
duration,
|
|
48
|
-
themes,
|
|
49
|
-
...(currentTheme !== undefined && { theme: currentTheme }),
|
|
50
|
-
onThemeChange,
|
|
51
|
-
});
|
|
52
|
-
const isControlled = contextTheme !== null;
|
|
53
|
-
const { ref, theme, switchTheme } = isControlled
|
|
54
|
-
? { ref: contextTheme.ref, theme: contextTheme.theme, switchTheme: contextTheme.switchTheme }
|
|
55
|
-
: standaloneHook;
|
|
56
|
-
const [isMounted, setIsMounted] = useState(false);
|
|
57
|
-
const [hoveredTheme, setHoveredTheme] = useState(null);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
setIsMounted(true);
|
|
60
|
-
}, []);
|
|
61
|
-
const handleThemeChange = async (newTheme, event) => {
|
|
62
|
-
if (isControlled && contextTheme.switchThemeFromElement && event) {
|
|
63
|
-
await contextTheme.switchThemeFromElement(newTheme, event.currentTarget);
|
|
64
|
-
if (onThemeChange) {
|
|
65
|
-
onThemeChange(newTheme);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
await switchTheme(newTheme);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
const filteredOptions = THEME_OPTIONS.filter(option => themes.includes(option.value));
|
|
73
|
-
return (_jsx("div", { className: clsx('inline-flex h-9 items-center overflow-hidden bg-background shadow-sm border border-border', isMounted ? 'opacity-100' : 'opacity-0', className), style: {
|
|
74
|
-
borderRadius: 'var(--radius)',
|
|
75
|
-
backgroundColor: 'hsl(var(--background))',
|
|
76
|
-
}, role: "radiogroup", onMouseLeave: () => setHoveredTheme(null), children: filteredOptions.map(option => (_jsx(ThemeOption, { icon: option.icon, value: option.value, isActive: theme === option.value, isHovered: hoveredTheme === option.value, onClick: handleThemeChange, onMouseEnter: () => setHoveredTheme(option.value), onMouseLeave: () => { }, buttonRef: theme === option.value ? ref : undefined }, option.value))) }));
|
|
77
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import { Theme, ColorTheme, ThemeAnimationType } from '../types';
|
|
3
|
-
interface ViteThemeContextType {
|
|
4
|
-
ref: React.RefObject<HTMLButtonElement | null>;
|
|
5
|
-
theme: Theme;
|
|
6
|
-
colorTheme: ColorTheme;
|
|
7
|
-
resolvedTheme: 'light' | 'dark';
|
|
8
|
-
systemTheme: 'light' | 'dark';
|
|
9
|
-
setTheme: (theme: Theme) => void;
|
|
10
|
-
setColorTheme: (colorTheme: ColorTheme) => void;
|
|
11
|
-
switchTheme: (theme: Theme) => Promise<void>;
|
|
12
|
-
switchColorTheme: (colorTheme: string) => void;
|
|
13
|
-
toggleTheme: () => Promise<void>;
|
|
14
|
-
toggleLightTheme: () => Promise<void>;
|
|
15
|
-
toggleDarkTheme: () => Promise<void>;
|
|
16
|
-
toggleColorTheme: () => void;
|
|
17
|
-
createColorThemeToggle: (targetColorTheme: string) => () => void;
|
|
18
|
-
isColorThemeActive: (targetColorTheme: string) => boolean;
|
|
19
|
-
switchThemeFromElement: (theme: Theme, element: HTMLButtonElement) => Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
interface ViteThemeProviderProps {
|
|
22
|
-
children: ReactNode;
|
|
23
|
-
themes?: Theme[];
|
|
24
|
-
colorThemes?: ColorTheme[];
|
|
25
|
-
defaultTheme?: Theme;
|
|
26
|
-
defaultColorTheme?: ColorTheme;
|
|
27
|
-
animationType?: ThemeAnimationType;
|
|
28
|
-
duration?: number;
|
|
29
|
-
attribute?: 'class' | 'data-theme';
|
|
30
|
-
disableTransitionOnChange?: boolean;
|
|
31
|
-
storageKey?: string;
|
|
32
|
-
colorStorageKey?: string;
|
|
33
|
-
globalClassName?: string;
|
|
34
|
-
colorThemePrefix?: string;
|
|
35
|
-
}
|
|
36
|
-
export declare const ViteThemeProvider: React.FC<ViteThemeProviderProps>;
|
|
37
|
-
export declare const useViteTheme: () => ViteThemeContextType;
|
|
38
|
-
export {};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useContext, useCallback } from 'react';
|
|
3
|
-
import { useThemeAnimation } from '../hooks/use-theme-animation';
|
|
4
|
-
import { ThemeAnimationType } from '../types';
|
|
5
|
-
const ViteThemeContext = createContext(undefined);
|
|
6
|
-
export const ViteThemeProvider = ({ children, themes = ['light', 'dark', 'system'], colorThemes = ['default'], defaultTheme = 'system', defaultColorTheme = 'default', animationType = ThemeAnimationType.CIRCLE, duration = 750, attribute = 'class', disableTransitionOnChange = false, storageKey = 'vite-theme', colorStorageKey = 'vite-color-theme', globalClassName = 'dark', colorThemePrefix = 'theme-', }) => {
|
|
7
|
-
const themeState = useThemeAnimation({
|
|
8
|
-
themes,
|
|
9
|
-
colorThemes,
|
|
10
|
-
defaultTheme,
|
|
11
|
-
defaultColorTheme,
|
|
12
|
-
animationType,
|
|
13
|
-
duration,
|
|
14
|
-
storageKey,
|
|
15
|
-
colorStorageKey,
|
|
16
|
-
globalClassName: attribute === 'class' ? globalClassName : undefined,
|
|
17
|
-
colorThemePrefix,
|
|
18
|
-
});
|
|
19
|
-
const applyTransitionDisable = useCallback(() => {
|
|
20
|
-
if (!disableTransitionOnChange)
|
|
21
|
-
return () => { };
|
|
22
|
-
const css = document.createElement('style');
|
|
23
|
-
css.textContent = `*,*::before,*::after{-webkit-transition:none!important;-moz-transition:none!important;-o-transition:none!important;-ms-transition:none!important;transition:none!important}`;
|
|
24
|
-
document.head.appendChild(css);
|
|
25
|
-
window.getComputedStyle(document.body);
|
|
26
|
-
return () => {
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
document.head.removeChild(css);
|
|
29
|
-
}, 1);
|
|
30
|
-
};
|
|
31
|
-
}, [disableTransitionOnChange]);
|
|
32
|
-
const wrappedSetTheme = useCallback((theme) => {
|
|
33
|
-
const cleanup = applyTransitionDisable();
|
|
34
|
-
themeState.setTheme(theme);
|
|
35
|
-
cleanup();
|
|
36
|
-
}, [themeState.setTheme, applyTransitionDisable]);
|
|
37
|
-
const wrappedSwitchTheme = useCallback(async (theme) => {
|
|
38
|
-
const cleanup = applyTransitionDisable();
|
|
39
|
-
await themeState.switchTheme(theme);
|
|
40
|
-
cleanup();
|
|
41
|
-
}, [themeState.switchTheme, applyTransitionDisable]);
|
|
42
|
-
const wrappedToggleTheme = useCallback(async () => {
|
|
43
|
-
const cleanup = applyTransitionDisable();
|
|
44
|
-
await themeState.toggleTheme();
|
|
45
|
-
cleanup();
|
|
46
|
-
}, [themeState.toggleTheme, applyTransitionDisable]);
|
|
47
|
-
const wrappedToggleLightTheme = useCallback(async () => {
|
|
48
|
-
const cleanup = applyTransitionDisable();
|
|
49
|
-
await themeState.toggleLightTheme();
|
|
50
|
-
cleanup();
|
|
51
|
-
}, [themeState.toggleLightTheme, applyTransitionDisable]);
|
|
52
|
-
const wrappedToggleDarkTheme = useCallback(async () => {
|
|
53
|
-
const cleanup = applyTransitionDisable();
|
|
54
|
-
await themeState.toggleDarkTheme();
|
|
55
|
-
cleanup();
|
|
56
|
-
}, [themeState.toggleDarkTheme, applyTransitionDisable]);
|
|
57
|
-
const switchThemeFromElement = async (theme, element) => {
|
|
58
|
-
const cleanup = applyTransitionDisable();
|
|
59
|
-
if (themeState.ref.current) {
|
|
60
|
-
const originalRef = themeState.ref.current;
|
|
61
|
-
Object.defineProperty(themeState.ref, 'current', {
|
|
62
|
-
value: element,
|
|
63
|
-
writable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
});
|
|
66
|
-
await themeState.switchTheme(theme);
|
|
67
|
-
Object.defineProperty(themeState.ref, 'current', {
|
|
68
|
-
value: originalRef,
|
|
69
|
-
writable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
Object.defineProperty(themeState.ref, 'current', {
|
|
75
|
-
value: element,
|
|
76
|
-
writable: true,
|
|
77
|
-
configurable: true,
|
|
78
|
-
});
|
|
79
|
-
await themeState.switchTheme(theme);
|
|
80
|
-
}
|
|
81
|
-
cleanup();
|
|
82
|
-
};
|
|
83
|
-
const systemTheme = typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
84
|
-
? 'dark'
|
|
85
|
-
: 'light';
|
|
86
|
-
const contextValue = {
|
|
87
|
-
ref: themeState.ref,
|
|
88
|
-
theme: themeState.theme,
|
|
89
|
-
colorTheme: themeState.colorTheme,
|
|
90
|
-
resolvedTheme: themeState.resolvedTheme,
|
|
91
|
-
systemTheme,
|
|
92
|
-
setTheme: wrappedSetTheme,
|
|
93
|
-
setColorTheme: themeState.setColorTheme,
|
|
94
|
-
switchTheme: wrappedSwitchTheme,
|
|
95
|
-
switchThemeFromElement,
|
|
96
|
-
switchColorTheme: themeState.switchColorTheme,
|
|
97
|
-
toggleTheme: wrappedToggleTheme,
|
|
98
|
-
toggleLightTheme: wrappedToggleLightTheme,
|
|
99
|
-
toggleDarkTheme: wrappedToggleDarkTheme,
|
|
100
|
-
toggleColorTheme: themeState.toggleColorTheme,
|
|
101
|
-
createColorThemeToggle: themeState.createColorThemeToggle,
|
|
102
|
-
isColorThemeActive: themeState.isColorThemeActive,
|
|
103
|
-
};
|
|
104
|
-
return _jsx(ViteThemeContext.Provider, { value: contextValue, children: children });
|
|
105
|
-
};
|
|
106
|
-
export const useViteTheme = () => {
|
|
107
|
-
const context = useContext(ViteThemeContext);
|
|
108
|
-
if (context === undefined) {
|
|
109
|
-
throw new Error('useViteTheme must be used within a ViteThemeProvider');
|
|
110
|
-
}
|
|
111
|
-
return context;
|
|
112
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
3
|
-
declare function Select({ ...props }: React.ComponentProps<typeof SelectPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
|
|
4
|
-
declare function SelectGroup({ ...props }: React.ComponentProps<typeof SelectPrimitive.Group>): import("react/jsx-runtime").JSX.Element;
|
|
5
|
-
declare function SelectValue({ ...props }: React.ComponentProps<typeof SelectPrimitive.Value>): import("react/jsx-runtime").JSX.Element;
|
|
6
|
-
declare function SelectTrigger({ className, size, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
|
7
|
-
size?: 'sm' | 'default';
|
|
8
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
9
|
-
declare function SelectContent({ className, children, position, ...props }: React.ComponentProps<typeof SelectPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
declare function SelectLabel({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.Label>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
declare function SelectItem({ className, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Item>): import("react/jsx-runtime").JSX.Element;
|
|
12
|
-
declare function SelectSeparator({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.Separator>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
declare function SelectScrollUpButton({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>): import("react/jsx-runtime").JSX.Element;
|
|
14
|
-
declare function SelectScrollDownButton({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>): import("react/jsx-runtime").JSX.Element;
|
|
15
|
-
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
function Select({ ...props }) {
|
|
5
|
-
return _jsx(SelectPrimitive.Root, { "data-slot": "select", ...props });
|
|
6
|
-
}
|
|
7
|
-
function SelectGroup({ ...props }) {
|
|
8
|
-
return _jsx(SelectPrimitive.Group, { "data-slot": "select-group", ...props });
|
|
9
|
-
}
|
|
10
|
-
function SelectValue({ ...props }) {
|
|
11
|
-
return _jsx(SelectPrimitive.Value, { "data-slot": "select-value", ...props });
|
|
12
|
-
}
|
|
13
|
-
const ChevronDownIcon = () => (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "m6 9 6 6 6-6" }) }));
|
|
14
|
-
const ChevronUpIcon = () => (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "m18 15-6-6-6 6" }) }));
|
|
15
|
-
const CheckIcon = () => (_jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "M20 6 9 17l-5-5" }) }));
|
|
16
|
-
function SelectTrigger({ className, size = 'default', children, ...props }) {
|
|
17
|
-
return (_jsxs(SelectPrimitive.Trigger, { "data-slot": "select-trigger", "data-size": size, className: clsx("border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { asChild: true, children: _jsx(ChevronDownIcon, {}) })] }));
|
|
18
|
-
}
|
|
19
|
-
function SelectContent({ className, children, position = 'popper', ...props }) {
|
|
20
|
-
return (_jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Content, { "data-slot": "select-content", className: clsx('bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md', position === 'popper' &&
|
|
21
|
-
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1', className), position: position, ...props, children: _jsx(SelectPrimitive.Viewport, { className: clsx('p-1', position === 'popper' &&
|
|
22
|
-
'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'), children: children }) }) }));
|
|
23
|
-
}
|
|
24
|
-
function SelectLabel({ className, ...props }) {
|
|
25
|
-
return (_jsx(SelectPrimitive.Label, { "data-slot": "select-label", className: clsx('py-1.5 pl-8 pr-2 text-sm font-semibold', className), ...props }));
|
|
26
|
-
}
|
|
27
|
-
function SelectItem({ className, children, ...props }) {
|
|
28
|
-
return (_jsxs(SelectPrimitive.Item, { "data-slot": "select-item", className: clsx("focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2", className), ...props, children: [_jsx("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: _jsx(SelectPrimitive.ItemIndicator, { children: _jsx(CheckIcon, {}) }) }), _jsx(SelectPrimitive.ItemText, { children: children })] }));
|
|
29
|
-
}
|
|
30
|
-
function SelectSeparator({ className, ...props }) {
|
|
31
|
-
return (_jsx(SelectPrimitive.Separator, { "data-slot": "select-separator", className: clsx('-mx-1 my-1 h-px bg-muted', className), ...props }));
|
|
32
|
-
}
|
|
33
|
-
function SelectScrollUpButton({ className, ...props }) {
|
|
34
|
-
return (_jsx(SelectPrimitive.ScrollUpButton, { "data-slot": "select-scroll-up-button", className: clsx('flex cursor-default items-center justify-center py-1', className), ...props, children: _jsx(ChevronUpIcon, {}) }));
|
|
35
|
-
}
|
|
36
|
-
function SelectScrollDownButton({ className, ...props }) {
|
|
37
|
-
return (_jsx(SelectPrimitive.ScrollDownButton, { "data-slot": "select-scroll-down-button", className: clsx('flex cursor-default items-center justify-center py-1', className), ...props, children: _jsx(ChevronDownIcon, {}) }));
|
|
38
|
-
}
|
|
39
|
-
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, };
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useState, useCallback } from 'react';
|
|
2
|
-
import { flushSync } from 'react-dom';
|
|
3
|
-
import { ThemeAnimationType, } from '../types';
|
|
4
|
-
import { injectBaseStyles, resolveTheme, getSystemTheme, supportsViewTransitions, prefersReducedMotion, createCircleAnimation, createBlurCircleAnimation, createSlideAnimation, } from '../utils/animations';
|
|
5
|
-
const isBrowser = typeof window !== 'undefined';
|
|
6
|
-
export const useThemeAnimation = (props = {}) => {
|
|
7
|
-
const { duration: propsDuration = 750, easing = 'ease-in-out', animationType = ThemeAnimationType.CIRCLE, blurAmount = 2, styleId = 'spaceman-theme-style', themes = ['light', 'dark', 'system'], colorThemes = ['default'], defaultTheme = 'system', defaultColorTheme = 'default', globalClassName = 'dark', colorThemePrefix = 'theme-', storageKey = 'theme', colorStorageKey = 'color-theme', theme: externalTheme, colorTheme: externalColorTheme, onThemeChange, onColorThemeChange,
|
|
8
|
-
// Slide animation options
|
|
9
|
-
slideDirection = 'left', slideFromX, slideFromY, slideToX = 0, slideToY = 0, } = props;
|
|
10
|
-
const isHighResolution = isBrowser && (window.innerWidth >= 3000 || window.innerHeight >= 2000);
|
|
11
|
-
const duration = isHighResolution ? Math.max(propsDuration * 0.8, 500) : propsDuration;
|
|
12
|
-
const [mounted, setMounted] = useState(false);
|
|
13
|
-
// Inject base styles once on mount
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
injectBaseStyles();
|
|
16
|
-
setMounted(true);
|
|
17
|
-
}, []);
|
|
18
|
-
const [internalTheme, setInternalTheme] = useState(() => {
|
|
19
|
-
if (!isBrowser)
|
|
20
|
-
return defaultTheme;
|
|
21
|
-
const saved = localStorage.getItem(storageKey);
|
|
22
|
-
return saved && themes.indexOf(saved) !== -1 ? saved : defaultTheme;
|
|
23
|
-
});
|
|
24
|
-
const [internalColorTheme, setInternalColorTheme] = useState(() => {
|
|
25
|
-
if (!isBrowser)
|
|
26
|
-
return defaultColorTheme;
|
|
27
|
-
const saved = localStorage.getItem(colorStorageKey);
|
|
28
|
-
return saved && colorThemes.indexOf(saved) !== -1 ? saved : defaultColorTheme;
|
|
29
|
-
});
|
|
30
|
-
const currentTheme = externalTheme ?? internalTheme;
|
|
31
|
-
const currentColorTheme = externalColorTheme ?? internalColorTheme;
|
|
32
|
-
const [, setSystemTheme] = useState(() => getSystemTheme());
|
|
33
|
-
const resolvedTheme = resolveTheme(currentTheme);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
if (!isBrowser)
|
|
36
|
-
return;
|
|
37
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
38
|
-
const handleChange = () => setSystemTheme(getSystemTheme());
|
|
39
|
-
mediaQuery.addEventListener('change', handleChange);
|
|
40
|
-
return () => mediaQuery.removeEventListener('change', handleChange);
|
|
41
|
-
}, []);
|
|
42
|
-
// Apply theme classes to DOM
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (!isBrowser || !mounted)
|
|
45
|
-
return;
|
|
46
|
-
if (resolvedTheme === 'dark') {
|
|
47
|
-
document.documentElement.classList.add(globalClassName);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
document.documentElement.classList.remove(globalClassName);
|
|
51
|
-
}
|
|
52
|
-
colorThemes.forEach(theme => {
|
|
53
|
-
document.documentElement.classList.remove(`${colorThemePrefix}${theme}`);
|
|
54
|
-
});
|
|
55
|
-
document.documentElement.classList.add(`${colorThemePrefix}${currentColorTheme}`);
|
|
56
|
-
}, [resolvedTheme, currentColorTheme, globalClassName, colorThemePrefix, colorThemes, mounted]);
|
|
57
|
-
const ref = useRef(null);
|
|
58
|
-
const setTheme = useCallback((newTheme) => {
|
|
59
|
-
// Always save to localStorage
|
|
60
|
-
if (isBrowser) {
|
|
61
|
-
localStorage.setItem(storageKey, newTheme);
|
|
62
|
-
}
|
|
63
|
-
// Update internal state if no external control
|
|
64
|
-
if (externalTheme === undefined) {
|
|
65
|
-
setInternalTheme(newTheme);
|
|
66
|
-
}
|
|
67
|
-
// Call external callback if provided
|
|
68
|
-
if (onThemeChange) {
|
|
69
|
-
onThemeChange(newTheme);
|
|
70
|
-
}
|
|
71
|
-
}, [onThemeChange, externalTheme, storageKey]);
|
|
72
|
-
const setColorTheme = useCallback((newColorTheme) => {
|
|
73
|
-
// Always save to localStorage
|
|
74
|
-
if (isBrowser) {
|
|
75
|
-
localStorage.setItem(colorStorageKey, newColorTheme);
|
|
76
|
-
}
|
|
77
|
-
// Update internal state if no external control
|
|
78
|
-
if (externalColorTheme === undefined) {
|
|
79
|
-
setInternalColorTheme(newColorTheme);
|
|
80
|
-
}
|
|
81
|
-
// Call external callback if provided
|
|
82
|
-
if (onColorThemeChange) {
|
|
83
|
-
onColorThemeChange(newColorTheme);
|
|
84
|
-
}
|
|
85
|
-
}, [onColorThemeChange, externalColorTheme, colorStorageKey]);
|
|
86
|
-
const switchTheme = useCallback(async (newTheme) => {
|
|
87
|
-
if (!ref.current || !supportsViewTransitions() || prefersReducedMotion()) {
|
|
88
|
-
setTheme(newTheme);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
// Helper function to convert direction to from coordinates
|
|
92
|
-
const getSlideFromCoords = (direction) => {
|
|
93
|
-
switch (direction) {
|
|
94
|
-
case 'left':
|
|
95
|
-
return { a: -100, b: 0 };
|
|
96
|
-
case 'right':
|
|
97
|
-
return { a: 100, b: 0 };
|
|
98
|
-
case 'top':
|
|
99
|
-
return { a: 0, b: -100 };
|
|
100
|
-
case 'bottom':
|
|
101
|
-
return { a: 0, b: 100 };
|
|
102
|
-
case 'top-left':
|
|
103
|
-
return { a: -100, b: -100 };
|
|
104
|
-
case 'top-right':
|
|
105
|
-
return { a: 100, b: -100 };
|
|
106
|
-
case 'bottom-left':
|
|
107
|
-
return { a: -100, b: 100 };
|
|
108
|
-
case 'bottom-right':
|
|
109
|
-
return { a: 100, b: 100 };
|
|
110
|
-
default:
|
|
111
|
-
return { a: -100, b: 0 };
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
let animationConfig;
|
|
115
|
-
if (animationType === ThemeAnimationType.SLIDE) {
|
|
116
|
-
// Use custom coordinates if provided, otherwise use direction
|
|
117
|
-
const fromCoords = slideFromX !== undefined && slideFromY !== undefined
|
|
118
|
-
? { a: slideFromX, b: slideFromY }
|
|
119
|
-
: getSlideFromCoords(slideDirection);
|
|
120
|
-
animationConfig = {
|
|
121
|
-
a: fromCoords.a,
|
|
122
|
-
b: fromCoords.b,
|
|
123
|
-
x: slideToX,
|
|
124
|
-
y: slideToY,
|
|
125
|
-
duration,
|
|
126
|
-
easing,
|
|
127
|
-
animationType,
|
|
128
|
-
blurAmount,
|
|
129
|
-
styleId,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
// For circle and blur circle animations, use button center
|
|
134
|
-
const { top, left, width, height } = ref.current.getBoundingClientRect();
|
|
135
|
-
const x = left + width / 2;
|
|
136
|
-
const y = top + height / 2;
|
|
137
|
-
animationConfig = {
|
|
138
|
-
x,
|
|
139
|
-
y,
|
|
140
|
-
duration,
|
|
141
|
-
easing,
|
|
142
|
-
animationType,
|
|
143
|
-
blurAmount,
|
|
144
|
-
styleId,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
if (animationType === ThemeAnimationType.BLUR_CIRCLE) {
|
|
148
|
-
createBlurCircleAnimation(animationConfig);
|
|
149
|
-
}
|
|
150
|
-
if (animationType === ThemeAnimationType.SLIDE) {
|
|
151
|
-
createSlideAnimation(animationConfig);
|
|
152
|
-
}
|
|
153
|
-
// Start the view transition
|
|
154
|
-
await document.startViewTransition(() => {
|
|
155
|
-
flushSync(() => {
|
|
156
|
-
setTheme(newTheme);
|
|
157
|
-
});
|
|
158
|
-
}).ready;
|
|
159
|
-
if (animationType === ThemeAnimationType.CIRCLE) {
|
|
160
|
-
createCircleAnimation(animationConfig);
|
|
161
|
-
}
|
|
162
|
-
}, [
|
|
163
|
-
setTheme,
|
|
164
|
-
duration,
|
|
165
|
-
easing,
|
|
166
|
-
animationType,
|
|
167
|
-
blurAmount,
|
|
168
|
-
styleId,
|
|
169
|
-
slideDirection,
|
|
170
|
-
slideFromX,
|
|
171
|
-
slideFromY,
|
|
172
|
-
slideToX,
|
|
173
|
-
slideToY,
|
|
174
|
-
]);
|
|
175
|
-
const switchColorTheme = useCallback((newColorTheme) => {
|
|
176
|
-
if (colorThemes.indexOf(newColorTheme) === -1) {
|
|
177
|
-
console.warn(`Color theme "${newColorTheme}" not found in available themes`);
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
setColorTheme(newColorTheme);
|
|
181
|
-
}, [colorThemes, setColorTheme]);
|
|
182
|
-
const toggleTheme = useCallback(async () => {
|
|
183
|
-
const newTheme = resolvedTheme === 'dark' ? 'light' : 'dark';
|
|
184
|
-
await switchTheme(newTheme);
|
|
185
|
-
}, [resolvedTheme, switchTheme]);
|
|
186
|
-
const toggleLightTheme = useCallback(async () => {
|
|
187
|
-
if (resolvedTheme === 'light')
|
|
188
|
-
return;
|
|
189
|
-
await switchTheme('light');
|
|
190
|
-
}, [resolvedTheme, switchTheme]);
|
|
191
|
-
const toggleDarkTheme = useCallback(async () => {
|
|
192
|
-
if (resolvedTheme === 'dark')
|
|
193
|
-
return;
|
|
194
|
-
await switchTheme('dark');
|
|
195
|
-
}, [resolvedTheme, switchTheme]);
|
|
196
|
-
const toggleColorTheme = useCallback(() => {
|
|
197
|
-
const currentIndex = colorThemes.indexOf(currentColorTheme);
|
|
198
|
-
const nextIndex = (currentIndex + 1) % colorThemes.length;
|
|
199
|
-
const nextColorTheme = colorThemes[nextIndex];
|
|
200
|
-
setColorTheme(nextColorTheme);
|
|
201
|
-
}, [currentColorTheme, colorThemes, setColorTheme]);
|
|
202
|
-
const createColorThemeToggle = useCallback((targetColorTheme) => {
|
|
203
|
-
return () => {
|
|
204
|
-
if (colorThemes.indexOf(targetColorTheme) === -1) {
|
|
205
|
-
console.warn(`Color theme "${targetColorTheme}" not found in available themes`);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
setColorTheme(targetColorTheme);
|
|
209
|
-
};
|
|
210
|
-
}, [colorThemes, setColorTheme]);
|
|
211
|
-
const isColorThemeActive = useCallback((targetColorTheme) => {
|
|
212
|
-
return currentColorTheme === targetColorTheme;
|
|
213
|
-
}, [currentColorTheme]);
|
|
214
|
-
return {
|
|
215
|
-
ref,
|
|
216
|
-
theme: currentTheme,
|
|
217
|
-
colorTheme: currentColorTheme,
|
|
218
|
-
resolvedTheme,
|
|
219
|
-
setTheme,
|
|
220
|
-
setColorTheme,
|
|
221
|
-
switchTheme,
|
|
222
|
-
switchColorTheme,
|
|
223
|
-
toggleTheme,
|
|
224
|
-
toggleLightTheme,
|
|
225
|
-
toggleDarkTheme,
|
|
226
|
-
toggleColorTheme,
|
|
227
|
-
createColorThemeToggle,
|
|
228
|
-
isColorThemeActive,
|
|
229
|
-
};
|
|
230
|
-
};
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { useThemeAnimation } from './hooks/use-theme-animation';
|
|
2
|
-
export { ThemeSwitcher } from './components/ThemeSwitcher';
|
|
3
|
-
export { ThemeSelector } from './components/ThemeSelector';
|
|
4
|
-
export { SpacemanThemeProvider, useSpacemanTheme } from './components/SpacemanThemeProvider';
|
|
5
|
-
export { ViteThemeProvider, useViteTheme } from './components/ViteThemeProvider';
|
|
6
|
-
export type { UseThemeAnimationProps, UseThemeAnimationReturn, ThemeSwitcherProps, ThemeSelectorProps, Theme, ColorTheme, SlideDirection, } from './types';
|
|
7
|
-
export { ThemeAnimationType } from './types';
|
|
8
|
-
export { injectBaseStyles, getSystemTheme, resolveTheme, supportsViewTransitions, prefersReducedMotion, } from './utils/animations';
|
package/dist/esm/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { useThemeAnimation } from './hooks/use-theme-animation';
|
|
2
|
-
export { ThemeSwitcher } from './components/ThemeSwitcher';
|
|
3
|
-
export { ThemeSelector } from './components/ThemeSelector';
|
|
4
|
-
export { SpacemanThemeProvider, useSpacemanTheme } from './components/SpacemanThemeProvider';
|
|
5
|
-
export { ViteThemeProvider, useViteTheme } from './components/ViteThemeProvider';
|
|
6
|
-
export { ThemeAnimationType } from './types';
|
|
7
|
-
export { injectBaseStyles, getSystemTheme, resolveTheme, supportsViewTransitions, prefersReducedMotion, } from './utils/animations';
|
package/dist/esm/types/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ThemeAnimationType } from '../types';
|
|
2
|
-
export declare const injectBaseStyles: () => void;
|
|
3
|
-
export declare const createBlurCircleMask: (blur: number) => string;
|
|
4
|
-
export declare const getSystemTheme: () => "light" | "dark";
|
|
5
|
-
export declare const resolveTheme: (theme: string) => "light" | "dark";
|
|
6
|
-
export declare const supportsViewTransitions: () => boolean;
|
|
7
|
-
export declare const prefersReducedMotion: () => boolean;
|
|
8
|
-
export interface AnimationConfig {
|
|
9
|
-
a?: number;
|
|
10
|
-
b?: number;
|
|
11
|
-
x: number;
|
|
12
|
-
y: number;
|
|
13
|
-
duration: number;
|
|
14
|
-
easing: string;
|
|
15
|
-
animationType: ThemeAnimationType;
|
|
16
|
-
blurAmount: number;
|
|
17
|
-
styleId: string;
|
|
18
|
-
}
|
|
19
|
-
export declare const createCircleAnimation: (config: AnimationConfig) => void;
|
|
20
|
-
export declare const createSlideAnimation: (config: AnimationConfig) => void;
|
|
21
|
-
export declare const createBlurCircleAnimation: (config: AnimationConfig) => void;
|