mirror of
https://github.com/coaidev/coai.git
synced 2025-05-19 21:10:18 +09:00
chore: remove non-essential theme switching animations
This commit is contained in:
parent
6ff57f1231
commit
34dfa05c9b
@ -107,7 +107,6 @@ export const useTheme = () => {
|
|||||||
|
|
||||||
export function ModeToggle() {
|
export function ModeToggle() {
|
||||||
const { theme, toggleTheme } = useTheme();
|
const { theme, toggleTheme } = useTheme();
|
||||||
const [isAnimating, setIsAnimating] = useState(false);
|
|
||||||
const [currentIconIndex, setCurrentIconIndex] = useState(0);
|
const [currentIconIndex, setCurrentIconIndex] = useState(0);
|
||||||
|
|
||||||
const icons = [
|
const icons = [
|
||||||
@ -120,24 +119,24 @@ export function ModeToggle() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const savedTheme = getTheme();
|
const savedTheme = getTheme();
|
||||||
const index = icons.findIndex(icon => icon.key === savedTheme);
|
const index = icons.findIndex(icon => icon.key === savedTheme);
|
||||||
|
setCurrentIconIndex(index >= 0 ? index : 0);
|
||||||
setCurrentIconIndex(index);
|
|
||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
if (isAnimating) return; // 防止重复点击
|
|
||||||
setIsAnimating(true);
|
|
||||||
|
|
||||||
|
|
||||||
toggleTheme?.();
|
toggleTheme?.();
|
||||||
|
|
||||||
setTimeout(() => {
|
const currentTheme = getTheme();
|
||||||
|
let nextTheme: Theme;
|
||||||
|
if (currentTheme === "dark") {
|
||||||
|
nextTheme = "light";
|
||||||
|
} else if (currentTheme === "light") {
|
||||||
|
nextTheme = "system";
|
||||||
|
} else {
|
||||||
|
nextTheme = "dark";
|
||||||
|
}
|
||||||
|
const nextIndex = icons.findIndex(icon => icon.key === nextTheme);
|
||||||
|
setCurrentIconIndex(nextIndex >= 0 ? nextIndex : 0);
|
||||||
|
|
||||||
const nextIconIndex = (currentIconIndex + 1) % icons.length;
|
|
||||||
|
|
||||||
setCurrentIconIndex(nextIconIndex);
|
|
||||||
setIsAnimating(false);
|
|
||||||
}, 500);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -145,24 +144,8 @@ export function ModeToggle() {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
style={{
|
|
||||||
transition: "background-color 0.5s ease",
|
|
||||||
position: "relative",
|
|
||||||
overflow: "hidden",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: "absolute",
|
|
||||||
transform: isAnimating ? "scale(0)" : "scale(1)",
|
|
||||||
transition: "transform 0.5s ease, opacity 0.5s ease",
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{icons[currentIconIndex]}
|
{icons[currentIconIndex]}
|
||||||
</div>
|
|
||||||
|
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ModeToggle;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user