mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-10-26 21:19:04 +08:00
feat(ui): add theme-aware gradient colors to magic card
- Integrate next-themes for dynamic color switching - Add light/dark theme specific gradient colors - Implement state management for theme-based color updates - Use pink gradient for dark theme and blue gradient for light theme - Improve visual consistency across different theme modes
This commit is contained in:
@@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
import { motion, useMotionTemplate, useMotionValue } from "motion/react"
|
import { motion, useMotionTemplate, useMotionValue } from "motion/react"
|
||||||
import type React from "react"
|
import type React from "react"
|
||||||
import { useCallback, useEffect, useRef } from "react"
|
import { useCallback, useEffect, useRef, useState } from "react"
|
||||||
|
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
import { useTheme } from "next-themes"
|
||||||
|
|
||||||
interface MagicCardProps {
|
interface MagicCardProps {
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
@@ -29,6 +30,7 @@ export function MagicCard({
|
|||||||
const mouseX = useMotionValue(-gradientSize)
|
const mouseX = useMotionValue(-gradientSize)
|
||||||
const mouseY = useMotionValue(-gradientSize)
|
const mouseY = useMotionValue(-gradientSize)
|
||||||
|
|
||||||
|
|
||||||
const handleMouseMove = useCallback(
|
const handleMouseMove = useCallback(
|
||||||
(e: MouseEvent) => {
|
(e: MouseEvent) => {
|
||||||
if (cardRef.current) {
|
if (cardRef.current) {
|
||||||
@@ -76,6 +78,21 @@ export function MagicCard({
|
|||||||
mouseY.set(-gradientSize)
|
mouseY.set(-gradientSize)
|
||||||
}, [gradientSize, mouseX, mouseY])
|
}, [gradientSize, mouseX, mouseY])
|
||||||
|
|
||||||
|
const { theme } = useTheme() // "light" | "dark"
|
||||||
|
|
||||||
|
const [fromColor, setFromColor] = useState(gradientFrom)
|
||||||
|
const [toColor, setToColor] = useState(gradientTo)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (theme === "dark") {
|
||||||
|
setFromColor("#ffb3c1") // fallback for dark
|
||||||
|
setToColor("#ff75a0")
|
||||||
|
} else {
|
||||||
|
setFromColor("#1e9df1") // fallback for light
|
||||||
|
setToColor("#8ed0f9")
|
||||||
|
}
|
||||||
|
}, [theme])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={cardRef} className={cn("group relative rounded-[inherit]", className)}>
|
<div ref={cardRef} className={cn("group relative rounded-[inherit]", className)}>
|
||||||
<motion.div
|
<motion.div
|
||||||
@@ -83,8 +100,8 @@ export function MagicCard({
|
|||||||
style={{
|
style={{
|
||||||
background: useMotionTemplate`
|
background: useMotionTemplate`
|
||||||
radial-gradient(${gradientSize}px circle at ${mouseX}px ${mouseY}px,
|
radial-gradient(${gradientSize}px circle at ${mouseX}px ${mouseY}px,
|
||||||
${gradientFrom},
|
${fromColor},
|
||||||
${gradientTo},
|
${toColor},
|
||||||
var(--border) 100%
|
var(--border) 100%
|
||||||
)
|
)
|
||||||
`,
|
`,
|
||||||
|
|||||||
Reference in New Issue
Block a user