@space-man/react-theme-animation 1.0.2 → 1.0.3
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 +46 -46
- package/dist/cjs/components/ThemeSelector.js +3 -3
- package/dist/cjs/components/ThemeSwitcher.js +4 -4
- package/dist/cjs/components/ui/select.d.ts +3 -3
- package/dist/cjs/components/ui/select.js +9 -9
- package/dist/esm/components/ThemeSelector.js +3 -3
- package/dist/esm/components/ThemeSwitcher.js +4 -4
- package/dist/esm/components/ui/select.d.ts +3 -3
- package/dist/esm/components/ui/select.js +11 -11
- package/package.json +14 -5
package/README.md
CHANGED
|
@@ -43,16 +43,16 @@ Perfect for custom theme toggle buttons and complete control over animated theme
|
|
|
43
43
|
### Basic Theme Toggle
|
|
44
44
|
|
|
45
45
|
```tsx
|
|
46
|
-
import { useThemeAnimation } from '@space-man/react-theme-animation'
|
|
46
|
+
import { useThemeAnimation } from '@space-man/react-theme-animation'
|
|
47
47
|
|
|
48
48
|
function ThemeToggle() {
|
|
49
|
-
const { theme, toggleTheme, ref } = useThemeAnimation()
|
|
49
|
+
const { theme, toggleTheme, ref } = useThemeAnimation()
|
|
50
50
|
|
|
51
51
|
return (
|
|
52
52
|
<button ref={ref} onClick={toggleTheme} className="theme-toggle-btn">
|
|
53
53
|
{theme === 'light' ? '🌙' : '🌞'} {theme}
|
|
54
54
|
</button>
|
|
55
|
-
)
|
|
55
|
+
)
|
|
56
56
|
}
|
|
57
57
|
```
|
|
58
58
|
|
|
@@ -69,7 +69,7 @@ import {
|
|
|
69
69
|
SpacemanThemeProvider,
|
|
70
70
|
ThemeSwitcher,
|
|
71
71
|
ThemeSelector,
|
|
72
|
-
} from '@space-man/react-theme-animation'
|
|
72
|
+
} from '@space-man/react-theme-animation'
|
|
73
73
|
|
|
74
74
|
function App() {
|
|
75
75
|
return (
|
|
@@ -88,7 +88,7 @@ function App() {
|
|
|
88
88
|
</main>
|
|
89
89
|
</div>
|
|
90
90
|
</SpacemanThemeProvider>
|
|
91
|
-
)
|
|
91
|
+
)
|
|
92
92
|
}
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -135,7 +135,7 @@ Hook to access theme state from SpacemanThemeProvider context.
|
|
|
135
135
|
|
|
136
136
|
```tsx
|
|
137
137
|
const { theme, colorTheme, switchTheme, setColorTheme, switchThemeFromElement, ref } =
|
|
138
|
-
useSpacemanTheme()
|
|
138
|
+
useSpacemanTheme()
|
|
139
139
|
```
|
|
140
140
|
|
|
141
141
|
#### Returns
|
|
@@ -161,7 +161,7 @@ const { theme, colorTheme, switchTheme, setColorTheme, toggleTheme, ref } = useT
|
|
|
161
161
|
duration: 800,
|
|
162
162
|
onThemeChange: theme => console.log('Theme changed:', theme),
|
|
163
163
|
onColorThemeChange: colorTheme => console.log('Color changed:', colorTheme),
|
|
164
|
-
})
|
|
164
|
+
})
|
|
165
165
|
```
|
|
166
166
|
|
|
167
167
|
#### Options
|
|
@@ -258,59 +258,59 @@ enum ThemeAnimationType {
|
|
|
258
258
|
### Types
|
|
259
259
|
|
|
260
260
|
```tsx
|
|
261
|
-
type Theme = 'light' | 'dark' | 'system'
|
|
262
|
-
type ColorTheme = string
|
|
261
|
+
type Theme = 'light' | 'dark' | 'system'
|
|
262
|
+
type ColorTheme = string // e.g., 'default', 'blue', 'green', etc.
|
|
263
263
|
|
|
264
264
|
interface SpacemanThemeProviderProps {
|
|
265
|
-
children: React.ReactNode
|
|
266
|
-
defaultTheme?: Theme
|
|
267
|
-
defaultColorTheme?: ColorTheme
|
|
268
|
-
themes?: Theme[]
|
|
269
|
-
colorThemes?: ColorTheme[]
|
|
270
|
-
animationType?: ThemeAnimationType
|
|
271
|
-
duration?: number
|
|
272
|
-
blurAmount?: number
|
|
273
|
-
onThemeChange?: (theme: Theme) => void
|
|
274
|
-
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
265
|
+
children: React.ReactNode
|
|
266
|
+
defaultTheme?: Theme
|
|
267
|
+
defaultColorTheme?: ColorTheme
|
|
268
|
+
themes?: Theme[]
|
|
269
|
+
colorThemes?: ColorTheme[]
|
|
270
|
+
animationType?: ThemeAnimationType
|
|
271
|
+
duration?: number
|
|
272
|
+
blurAmount?: number
|
|
273
|
+
onThemeChange?: (theme: Theme) => void
|
|
274
|
+
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
interface UseThemeAnimationProps {
|
|
278
|
-
themes?: Theme[]
|
|
279
|
-
colorThemes?: ColorTheme[]
|
|
280
|
-
theme?: Theme
|
|
281
|
-
colorTheme?: ColorTheme
|
|
282
|
-
animationType?: ThemeAnimationType
|
|
283
|
-
duration?: number
|
|
284
|
-
blurAmount?: number
|
|
285
|
-
onThemeChange?: (theme: Theme) => void
|
|
286
|
-
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
278
|
+
themes?: Theme[]
|
|
279
|
+
colorThemes?: ColorTheme[]
|
|
280
|
+
theme?: Theme
|
|
281
|
+
colorTheme?: ColorTheme
|
|
282
|
+
animationType?: ThemeAnimationType
|
|
283
|
+
duration?: number
|
|
284
|
+
blurAmount?: number
|
|
285
|
+
onThemeChange?: (theme: Theme) => void
|
|
286
|
+
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
interface UseThemeAnimationReturn {
|
|
290
|
-
theme: Theme
|
|
291
|
-
colorTheme: ColorTheme
|
|
292
|
-
switchTheme: (theme: Theme) => Promise<void
|
|
293
|
-
setColorTheme: (colorTheme: ColorTheme) => void
|
|
294
|
-
toggleTheme: () => Promise<void
|
|
295
|
-
ref: RefObject<HTMLElement
|
|
290
|
+
theme: Theme
|
|
291
|
+
colorTheme: ColorTheme
|
|
292
|
+
switchTheme: (theme: Theme) => Promise<void>
|
|
293
|
+
setColorTheme: (colorTheme: ColorTheme) => void
|
|
294
|
+
toggleTheme: () => Promise<void>
|
|
295
|
+
ref: RefObject<HTMLElement>
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
interface ThemeSwitcherProps {
|
|
299
|
-
themes?: Theme[]
|
|
300
|
-
currentTheme?: Theme
|
|
301
|
-
onThemeChange?: (theme: Theme) => void
|
|
302
|
-
animationType?: ThemeAnimationType
|
|
303
|
-
duration?: number
|
|
304
|
-
className?: string
|
|
299
|
+
themes?: Theme[]
|
|
300
|
+
currentTheme?: Theme
|
|
301
|
+
onThemeChange?: (theme: Theme) => void
|
|
302
|
+
animationType?: ThemeAnimationType
|
|
303
|
+
duration?: number
|
|
304
|
+
className?: string
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
interface ThemeSelectorProps {
|
|
308
|
-
themes?: Theme[]
|
|
309
|
-
colorThemes?: ColorTheme[]
|
|
310
|
-
currentColorTheme?: ColorTheme
|
|
311
|
-
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
312
|
-
animationType?: ThemeAnimationType
|
|
313
|
-
duration?: number
|
|
308
|
+
themes?: Theme[]
|
|
309
|
+
colorThemes?: ColorTheme[]
|
|
310
|
+
currentColorTheme?: ColorTheme
|
|
311
|
+
onColorThemeChange?: (colorTheme: ColorTheme) => void
|
|
312
|
+
animationType?: ThemeAnimationType
|
|
313
|
+
duration?: number
|
|
314
314
|
}
|
|
315
315
|
```
|
|
316
316
|
|
|
@@ -24,9 +24,9 @@ const ThemeSelector = ({ themes = ['light', 'dark', 'system'], colorThemes = ['d
|
|
|
24
24
|
onColorThemeChange,
|
|
25
25
|
});
|
|
26
26
|
const isControlled = contextTheme !== null;
|
|
27
|
-
const { colorTheme, setColorTheme } = isControlled
|
|
28
|
-
{ colorTheme: contextTheme.colorTheme, setColorTheme: contextTheme.setColorTheme }
|
|
29
|
-
standaloneHook;
|
|
27
|
+
const { colorTheme, setColorTheme } = isControlled
|
|
28
|
+
? { colorTheme: contextTheme.colorTheme, setColorTheme: contextTheme.setColorTheme }
|
|
29
|
+
: standaloneHook;
|
|
30
30
|
const handleColorThemeChange = (newColorTheme) => {
|
|
31
31
|
setColorTheme(newColorTheme);
|
|
32
32
|
// Also call the callback if provided
|
|
@@ -11,7 +11,7 @@ const SunIcon = () => ((0, jsx_runtime_1.jsxs)("svg", { width: "16", height: "16
|
|
|
11
11
|
const MoonIcon = () => ((0, jsx_runtime_1.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: (0, jsx_runtime_1.jsx)("path", { d: "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" }) }));
|
|
12
12
|
const MonitorIcon = () => ((0, jsx_runtime_1.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [(0, jsx_runtime_1.jsx)("rect", { width: "20", height: "14", x: "2", y: "3", rx: "2" }), (0, jsx_runtime_1.jsx)("line", { x1: "8", x2: "16", y1: "21", y2: "21" }), (0, jsx_runtime_1.jsx)("line", { x1: "12", x2: "12", y1: "17", y2: "21" })] }));
|
|
13
13
|
const ThemeOption = ({ icon, value, isActive, isHovered, onClick, onMouseEnter, onMouseLeave, buttonRef, }) => {
|
|
14
|
-
return ((0, jsx_runtime_1.jsxs)("button", { ref: isActive ? buttonRef : undefined, className: (0, clsx_1.clsx)('relative flex h-9 w-12 cursor-pointer items-center justify-center transition-all duration-200 ease-in-out', 'text-muted-foreground hover:text-foreground', isActive && 'text-foreground font-medium'), role: "radio", "aria-checked": isActive, "aria-label": `Switch to ${value} theme`, onClick:
|
|
14
|
+
return ((0, jsx_runtime_1.jsxs)("button", { ref: isActive ? buttonRef : undefined, className: (0, clsx_1.clsx)('relative flex h-9 w-12 cursor-pointer items-center justify-center transition-all duration-200 ease-in-out', '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: {
|
|
15
15
|
borderRadius: 'var(--radius)',
|
|
16
16
|
}, children: [isHovered && ((0, jsx_runtime_1.jsx)(react_2.motion.div, { layoutId: "theme-hover-bg", className: "absolute inset-0 bg-muted backdrop-blur-sm", style: {
|
|
17
17
|
borderRadius: 'var(--radius)',
|
|
@@ -67,9 +67,9 @@ const ThemeSwitcher = ({ themes = ['light', 'dark', 'system'], currentTheme, onT
|
|
|
67
67
|
onThemeChange,
|
|
68
68
|
});
|
|
69
69
|
const isControlled = contextTheme !== null;
|
|
70
|
-
const { ref, theme, switchTheme } = isControlled
|
|
71
|
-
{ ref: contextTheme.ref, theme: contextTheme.theme, switchTheme: contextTheme.switchTheme }
|
|
72
|
-
standaloneHook;
|
|
70
|
+
const { ref, theme, switchTheme } = isControlled
|
|
71
|
+
? { ref: contextTheme.ref, theme: contextTheme.theme, switchTheme: contextTheme.switchTheme }
|
|
72
|
+
: standaloneHook;
|
|
73
73
|
const [isMounted, setIsMounted] = (0, react_1.useState)(false);
|
|
74
74
|
(0, react_1.useEffect)(() => {
|
|
75
75
|
setIsMounted(true);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as SelectPrimitive from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
3
3
|
declare function Select({ ...props }: React.ComponentProps<typeof SelectPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
declare function SelectGroup({ ...props }: React.ComponentProps<typeof SelectPrimitive.Group>): import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
declare function SelectValue({ ...props }: React.ComponentProps<typeof SelectPrimitive.Value>): import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
declare function SelectTrigger({ className, size, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
|
7
|
-
size?:
|
|
7
|
+
size?: 'sm' | 'default';
|
|
8
8
|
}): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
declare function SelectContent({ className, children, position, ...props }: React.ComponentProps<typeof SelectPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
declare function SelectLabel({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.Label>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -58,26 +58,26 @@ function SelectValue({ ...props }) {
|
|
|
58
58
|
const ChevronDownIcon = () => ((0, jsx_runtime_1.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: (0, jsx_runtime_1.jsx)("path", { d: "m6 9 6 6 6-6" }) }));
|
|
59
59
|
const ChevronUpIcon = () => ((0, jsx_runtime_1.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: (0, jsx_runtime_1.jsx)("path", { d: "m18 15-6-6-6 6" }) }));
|
|
60
60
|
const CheckIcon = () => ((0, jsx_runtime_1.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: (0, jsx_runtime_1.jsx)("path", { d: "M20 6 9 17l-5-5" }) }));
|
|
61
|
-
function SelectTrigger({ className, size =
|
|
61
|
+
function SelectTrigger({ className, size = 'default', children, ...props }) {
|
|
62
62
|
return ((0, jsx_runtime_1.jsxs)(SelectPrimitive.Trigger, { "data-slot": "select-trigger", "data-size": size, className: (0, clsx_1.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, (0, jsx_runtime_1.jsx)(SelectPrimitive.Icon, { asChild: true, children: (0, jsx_runtime_1.jsx)(ChevronDownIcon, {}) })] }));
|
|
63
63
|
}
|
|
64
|
-
function SelectContent({ className, children, position =
|
|
65
|
-
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.Portal, { children: (0, jsx_runtime_1.jsx)(SelectPrimitive.Content, { "data-slot": "select-content", className: (0, clsx_1.clsx)(
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
function SelectContent({ className, children, position = 'popper', ...props }) {
|
|
65
|
+
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.Portal, { children: (0, jsx_runtime_1.jsx)(SelectPrimitive.Content, { "data-slot": "select-content", className: (0, clsx_1.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' &&
|
|
66
|
+
'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: (0, jsx_runtime_1.jsx)(SelectPrimitive.Viewport, { className: (0, clsx_1.clsx)('p-1', position === 'popper' &&
|
|
67
|
+
'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'), children: children }) }) }));
|
|
68
68
|
}
|
|
69
69
|
function SelectLabel({ className, ...props }) {
|
|
70
|
-
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.Label, { "data-slot": "select-label", className: (0, clsx_1.clsx)(
|
|
70
|
+
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.Label, { "data-slot": "select-label", className: (0, clsx_1.clsx)('py-1.5 pl-8 pr-2 text-sm font-semibold', className), ...props }));
|
|
71
71
|
}
|
|
72
72
|
function SelectItem({ className, children, ...props }) {
|
|
73
73
|
return ((0, jsx_runtime_1.jsxs)(SelectPrimitive.Item, { "data-slot": "select-item", className: (0, clsx_1.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: [(0, jsx_runtime_1.jsx)("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: (0, jsx_runtime_1.jsx)(SelectPrimitive.ItemIndicator, { children: (0, jsx_runtime_1.jsx)(CheckIcon, {}) }) }), (0, jsx_runtime_1.jsx)(SelectPrimitive.ItemText, { children: children })] }));
|
|
74
74
|
}
|
|
75
75
|
function SelectSeparator({ className, ...props }) {
|
|
76
|
-
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.Separator, { "data-slot": "select-separator", className: (0, clsx_1.clsx)(
|
|
76
|
+
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.Separator, { "data-slot": "select-separator", className: (0, clsx_1.clsx)('-mx-1 my-1 h-px bg-muted', className), ...props }));
|
|
77
77
|
}
|
|
78
78
|
function SelectScrollUpButton({ className, ...props }) {
|
|
79
|
-
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.ScrollUpButton, { "data-slot": "select-scroll-up-button", className: (0, clsx_1.clsx)(
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.ScrollUpButton, { "data-slot": "select-scroll-up-button", className: (0, clsx_1.clsx)('flex cursor-default items-center justify-center py-1', className), ...props, children: (0, jsx_runtime_1.jsx)(ChevronUpIcon, {}) }));
|
|
80
80
|
}
|
|
81
81
|
function SelectScrollDownButton({ className, ...props }) {
|
|
82
|
-
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.ScrollDownButton, { "data-slot": "select-scroll-down-button", className: (0, clsx_1.clsx)(
|
|
82
|
+
return ((0, jsx_runtime_1.jsx)(SelectPrimitive.ScrollDownButton, { "data-slot": "select-scroll-down-button", className: (0, clsx_1.clsx)('flex cursor-default items-center justify-center py-1', className), ...props, children: (0, jsx_runtime_1.jsx)(ChevronDownIcon, {}) }));
|
|
83
83
|
}
|
|
@@ -21,9 +21,9 @@ export const ThemeSelector = ({ themes = ['light', 'dark', 'system'], colorTheme
|
|
|
21
21
|
onColorThemeChange,
|
|
22
22
|
});
|
|
23
23
|
const isControlled = contextTheme !== null;
|
|
24
|
-
const { colorTheme, setColorTheme } = isControlled
|
|
25
|
-
{ colorTheme: contextTheme.colorTheme, setColorTheme: contextTheme.setColorTheme }
|
|
26
|
-
standaloneHook;
|
|
24
|
+
const { colorTheme, setColorTheme } = isControlled
|
|
25
|
+
? { colorTheme: contextTheme.colorTheme, setColorTheme: contextTheme.setColorTheme }
|
|
26
|
+
: standaloneHook;
|
|
27
27
|
const handleColorThemeChange = (newColorTheme) => {
|
|
28
28
|
setColorTheme(newColorTheme);
|
|
29
29
|
// Also call the callback if provided
|
|
@@ -8,7 +8,7 @@ const SunIcon = () => (_jsxs("svg", { width: "16", height: "16", viewBox: "0 0 2
|
|
|
8
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
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
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 transition-all duration-200 ease-in-out', 'text-muted-foreground hover:text-foreground', isActive && 'text-foreground font-medium'), role: "radio", "aria-checked": isActive, "aria-label": `Switch to ${value} theme`, onClick:
|
|
11
|
+
return (_jsxs("button", { ref: isActive ? buttonRef : undefined, className: clsx('relative flex h-9 w-12 cursor-pointer items-center justify-center transition-all duration-200 ease-in-out', '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
12
|
borderRadius: 'var(--radius)',
|
|
13
13
|
}, children: [isHovered && (_jsx(motion.div, { layoutId: "theme-hover-bg", className: "absolute inset-0 bg-muted backdrop-blur-sm", style: {
|
|
14
14
|
borderRadius: 'var(--radius)',
|
|
@@ -64,9 +64,9 @@ export const ThemeSwitcher = ({ themes = ['light', 'dark', 'system'], currentThe
|
|
|
64
64
|
onThemeChange,
|
|
65
65
|
});
|
|
66
66
|
const isControlled = contextTheme !== null;
|
|
67
|
-
const { ref, theme, switchTheme } = isControlled
|
|
68
|
-
{ ref: contextTheme.ref, theme: contextTheme.theme, switchTheme: contextTheme.switchTheme }
|
|
69
|
-
standaloneHook;
|
|
67
|
+
const { ref, theme, switchTheme } = isControlled
|
|
68
|
+
? { ref: contextTheme.ref, theme: contextTheme.theme, switchTheme: contextTheme.switchTheme }
|
|
69
|
+
: standaloneHook;
|
|
70
70
|
const [isMounted, setIsMounted] = useState(false);
|
|
71
71
|
useEffect(() => {
|
|
72
72
|
setIsMounted(true);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import * as SelectPrimitive from
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
3
3
|
declare function Select({ ...props }: React.ComponentProps<typeof SelectPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
declare function SelectGroup({ ...props }: React.ComponentProps<typeof SelectPrimitive.Group>): import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
declare function SelectValue({ ...props }: React.ComponentProps<typeof SelectPrimitive.Value>): import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
declare function SelectTrigger({ className, size, children, ...props }: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
|
7
|
-
size?:
|
|
7
|
+
size?: 'sm' | 'default';
|
|
8
8
|
}): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
declare function SelectContent({ className, children, position, ...props }: React.ComponentProps<typeof SelectPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
|
|
10
10
|
declare function SelectLabel({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.Label>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import * as SelectPrimitive from
|
|
3
|
-
import { clsx } from
|
|
2
|
+
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
4
|
function Select({ ...props }) {
|
|
5
5
|
return _jsx(SelectPrimitive.Root, { "data-slot": "select", ...props });
|
|
6
6
|
}
|
|
@@ -13,27 +13,27 @@ function SelectValue({ ...props }) {
|
|
|
13
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
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
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 =
|
|
16
|
+
function SelectTrigger({ className, size = 'default', children, ...props }) {
|
|
17
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
18
|
}
|
|
19
|
-
function SelectContent({ className, children, position =
|
|
20
|
-
return (_jsx(SelectPrimitive.Portal, { children: _jsx(SelectPrimitive.Content, { "data-slot": "select-content", className: clsx(
|
|
21
|
-
|
|
22
|
-
|
|
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
23
|
}
|
|
24
24
|
function SelectLabel({ className, ...props }) {
|
|
25
|
-
return (_jsx(SelectPrimitive.Label, { "data-slot": "select-label", className: clsx(
|
|
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
26
|
}
|
|
27
27
|
function SelectItem({ className, children, ...props }) {
|
|
28
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
29
|
}
|
|
30
30
|
function SelectSeparator({ className, ...props }) {
|
|
31
|
-
return (_jsx(SelectPrimitive.Separator, { "data-slot": "select-separator", className: clsx(
|
|
31
|
+
return (_jsx(SelectPrimitive.Separator, { "data-slot": "select-separator", className: clsx('-mx-1 my-1 h-px bg-muted', className), ...props }));
|
|
32
32
|
}
|
|
33
33
|
function SelectScrollUpButton({ className, ...props }) {
|
|
34
|
-
return (_jsx(SelectPrimitive.ScrollUpButton, { "data-slot": "select-scroll-up-button", className: clsx(
|
|
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
35
|
}
|
|
36
36
|
function SelectScrollDownButton({ className, ...props }) {
|
|
37
|
-
return (_jsx(SelectPrimitive.ScrollDownButton, { "data-slot": "select-scroll-down-button", className: clsx(
|
|
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
38
|
}
|
|
39
39
|
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, };
|
package/package.json
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@space-man/react-theme-animation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "React theme switching with smooth view transition animations and multi-theme support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
|
-
"reactjs",
|
|
8
|
-
"hooks",
|
|
9
7
|
"theme",
|
|
8
|
+
"dark mode",
|
|
9
|
+
"light mode",
|
|
10
|
+
"theme switching",
|
|
11
|
+
"view transitions",
|
|
12
|
+
"hooks",
|
|
10
13
|
"animation",
|
|
11
14
|
"switch",
|
|
12
15
|
"typescript",
|
|
13
|
-
"nextjs",
|
|
14
16
|
"dark",
|
|
15
17
|
"light",
|
|
16
18
|
"view-transition",
|
|
19
|
+
"view-transition-api",
|
|
20
|
+
"tailwind",
|
|
17
21
|
"tailwindcss",
|
|
18
|
-
"shadcn"
|
|
22
|
+
"shadcn",
|
|
23
|
+
"reactjs",
|
|
24
|
+
"nextjs",
|
|
25
|
+
"vite"
|
|
19
26
|
],
|
|
20
27
|
"publishConfig": {
|
|
21
28
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -50,6 +57,8 @@
|
|
|
50
57
|
"lint": "eslint \"**/*.{js,jsx,ts,tsx}\"",
|
|
51
58
|
"lint:fix": "eslint --fix . --ext .{js,jsx,ts,tsx}",
|
|
52
59
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
60
|
+
"prettier:check": "prettier --check . --config ./.prettierrc",
|
|
61
|
+
"prettier:fix": "prettier --write . --config ./.prettierrc",
|
|
53
62
|
"changeset": "changeset add --type patch",
|
|
54
63
|
"changeset:patch": "changeset add --type patch",
|
|
55
64
|
"changeset:feature": "changeset add --type minor",
|