Skip to content

Commit 1aec579

Browse files
committed
smooth theme transition
1 parent a69975e commit 1aec579

3 files changed

Lines changed: 112 additions & 19 deletions

File tree

src/css/custom.css

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -370,21 +370,67 @@ html[data-theme="dark"] .menu__link--active::after {
370370
}
371371

372372
/* ======= SECTION 9 :Smooth theme transitions ========== */
373-
html,
374-
body {
375-
transition:
376-
background-color 150ms ease,
377-
color 150ms ease;
378-
}
379373

374+
/* Global smooth theme transitions for all color-related properties */
375+
html,
376+
body,
380377
.navbar,
378+
.navbar__inner,
379+
.navbar__brand,
380+
.navbar__link,
381+
.navbar__item,
381382
.footer,
383+
.footer__link,
382384
.sidebar,
383-
.main-wrapper {
385+
.sidebar__link,
386+
.main-wrapper,
387+
.theme-doc-sidebar-container,
388+
.theme-doc-toc-desktop,
389+
.theme-doc-sidebar-item,
390+
.article-card,
391+
.blog-card,
392+
.card,
393+
.menu__link,
394+
.menu__caret,
395+
.pagination,
396+
.pagination__item,
397+
.breadcrumbs,
398+
[class*="breadcrumb"],
399+
[class*="button"],
400+
[class*="btn"],
401+
.badge,
402+
.pill,
403+
.tag,
404+
.button-group,
405+
.admonition,
406+
.alert,
407+
.docusaurus-highlight-code-line,
408+
pre,
409+
code,
410+
input,
411+
textarea,
412+
select,
413+
[role="button"] {
414+
transition:
415+
background-color 300ms ease-in-out,
416+
color 300ms ease-in-out,
417+
border-color 300ms ease-in-out,
418+
box-shadow 300ms ease-in-out,
419+
fill 300ms ease-in-out,
420+
stroke 300ms ease-in-out,
421+
opacity 300ms ease-in-out !important;
422+
}
423+
424+
/* SVG and icon transitions */
425+
svg,
426+
i,
427+
[class*="icon"] {
384428
transition:
385-
background-color 150ms ease,
386-
color 150ms ease,
387-
border-color 150ms ease;
429+
fill 300ms ease-in-out,
430+
stroke 300ms ease-in-out,
431+
color 300ms ease-in-out,
432+
filter 300ms ease-in-out,
433+
opacity 300ms ease-in-out !important;
388434
}
389435

390436
/* Navbar icon styling */
@@ -395,6 +441,7 @@ body {
395441
margin-right: 4px;
396442
min-width: 18px;
397443
min-height: 18px;
444+
transition: all 250ms cubic-bezier(0.4, 0, 0.2, 1);
398445
}
399446

400447
/* Navbar social icon styles */
@@ -406,8 +453,45 @@ body {
406453
border-radius: 6px;
407454
color: var(--ifm-navbar-link-color);
408455
transition:
409-
color 0.2s ease,
410-
background-color 0.2s ease;
456+
color 250ms cubic-bezier(0.4, 0, 0.2, 1),
457+
background-color 250ms cubic-bezier(0.4, 0, 0.2, 1),
458+
filter 250ms cubic-bezier(0.4, 0, 0.2, 1);
459+
}
460+
461+
/* Form elements smooth transitions */
462+
input,
463+
textarea,
464+
select,
465+
button,
466+
[role="button"] {
467+
transition:
468+
background-color 250ms cubic-bezier(0.4, 0, 0.2, 1),
469+
color 250ms cubic-bezier(0.4, 0, 0.2, 1),
470+
border-color 250ms cubic-bezier(0.4, 0, 0.2, 1),
471+
box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1);
472+
}
473+
474+
/* Code block transitions */
475+
code,
476+
pre,
477+
.code-block,
478+
.highlight,
479+
[class*="hljs"] {
480+
transition:
481+
background-color 250ms cubic-bezier(0.4, 0, 0.2, 1),
482+
color 250ms cubic-bezier(0.4, 0, 0.2, 1),
483+
border-color 250ms cubic-bezier(0.4, 0, 0.2, 1);
484+
}
485+
486+
/* Icon transitions */
487+
svg,
488+
i,
489+
[class*="icon"] {
490+
transition:
491+
fill 250ms cubic-bezier(0.4, 0, 0.2, 1),
492+
stroke 250ms cubic-bezier(0.4, 0, 0.2, 1),
493+
color 250ms cubic-bezier(0.4, 0, 0.2, 1),
494+
filter 250ms cubic-bezier(0.4, 0, 0.2, 1);
411495
}
412496

413497
.navbar-social-icon:hover {
@@ -2039,4 +2123,4 @@ html[data-theme="light"] {
20392123
html[data-theme="dark"] {
20402124
scrollbar-width: thin !important;
20412125
scrollbar-color: #334155 transparent !important;
2042-
}
2126+
}

src/styles/globals.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@
118118
* {
119119
@apply border-border outline-ring/50;
120120
}
121+
121122
body {
122123
@apply bg-background text-foreground;
124+
transition: background-color 300ms ease-in-out, color 300ms ease-in-out !important;
123125
}
124-
}
126+
}

src/theme/ColorModeToggle/index.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ export default function ColorModeToggle(): JSX.Element {
88
// Safe setColorMode that works with DOM
99
const setColorMode = (mode: "light" | "dark") => {
1010
if (!ExecutionEnvironment.canUseDOM) return;
11+
// Set DOM attribute immediately for instant visual feedback
1112
document.documentElement.setAttribute("data-theme", mode);
12-
// Also trigger Docusaurus's internal theme change if available
13+
// Also store in localStorage
14+
localStorage.setItem("theme", mode);
15+
// Trigger Docusaurus's internal theme change if available
1316
try {
1417
const {
1518
setColorMode: docusaurusSetColorMode,
@@ -39,7 +42,7 @@ export default function ColorModeToggle(): JSX.Element {
3942
display: "flex",
4043
alignItems: "center",
4144
justifyContent: "center",
42-
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
45+
transition: "all 200ms ease-out",
4346
transform: "scale(1)",
4447
}}
4548
onMouseEnter={(e) => {
@@ -51,7 +54,7 @@ export default function ColorModeToggle(): JSX.Element {
5154
>
5255
<div
5356
style={{
54-
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
57+
transition: "all 300ms ease-in-out",
5558
opacity: 1,
5659
transform: "rotate(0deg)",
5760
}}
@@ -63,8 +66,10 @@ export default function ColorModeToggle(): JSX.Element {
6366
viewBox="0 0 24 24"
6467
fill="currentColor"
6568
style={{
66-
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
69+
transition: "all 300ms ease-in-out",
6770
filter: "drop-shadow(0 0 4px rgba(255, 193, 7, 0.3))",
71+
opacity: 1,
72+
transform: "rotate(0deg) scale(1)",
6873
}}
6974
>
7075
<path d="M12 2.25a.75.75 0 01.75.75v2.25a.75.75 0 01-1.5 0V3a.75.75 0 01.75-.75zM7.5 12a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM18.894 6.166a.75.75 0 00-1.06-1.06l-1.591 1.59a.75.75 0 101.06 1.061l1.591-1.59zM21.75 12a.75.75 0 01-.75.75h-2.25a.75.75 0 010-1.5H21a.75.75 0 01.75.75zM17.834 18.894a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 10-1.061 1.06l1.59 1.591zM12 18a.75.75 0 01.75.75V21a.75.75 0 01-1.5 0v-2.25A.75.75 0 0112 18zM7.758 17.303a.75.75 0 00-1.061-1.06l-1.591 1.59a.75.75 0 001.06 1.061l1.591-1.59zM6 12a.75.75 0 01-.75.75H3a.75.75 0 010-1.5h2.25A.75.75 0 016 12zM6.697 7.757a.75.75 0 001.06-1.06l-1.59-1.591a.75.75 0 00-1.061 1.06l1.59 1.591z" />
@@ -76,8 +81,10 @@ export default function ColorModeToggle(): JSX.Element {
7681
viewBox="0 0 24 24"
7782
fill="currentColor"
7883
style={{
79-
transition: "all 0.3s cubic-bezier(0.4, 0, 0.2, 1)",
84+
transition: "all 300ms ease-in-out",
8085
filter: "drop-shadow(0 0 4px rgba(99, 102, 241, 0.3))",
86+
opacity: 1,
87+
transform: "rotate(0deg) scale(1)",
8188
}}
8289
>
8390
<path d="M9.528 1.718a.75.75 0 01.162.819A8.97 8.97 0 009 6a9 9 0 009 9 8.97 8.97 0 003.463-.69.75.75 0 01.981.98 10.503 10.503 0 01-9.694 6.46c-5.799 0-10.5-4.701-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 01.818.162z" />

0 commit comments

Comments
 (0)