Skip to content

Commit 722603f

Browse files
authored
Merge pull request #1626 from hrx01-dev/smooth-theme-transition
smooth theme transition
2 parents 79359f5 + 136a1a3 commit 722603f

3 files changed

Lines changed: 111 additions & 87 deletions

File tree

src/css/custom.css

Lines changed: 96 additions & 81 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 {
@@ -1970,75 +2054,6 @@ main>div:not(.m-0) {
19702054
margin-top: 1.5rem;
19712055
margin-bottom: 1.5rem;
19722056
}
1973-
1974-
.blog-carousel-section {
1975-
padding: 1.5rem 0 !important;
1976-
margin: 1.5rem 0 !important;
1977-
}
1978-
1979-
/* Reduce section padding on mobile */
1980-
section,
1981-
[role="region"] {
1982-
padding: 1.5rem 0;
1983-
margin: 1.5rem 0;
1984-
}
1985-
}
1986-
1987-
/* Typography spacing for consistency */
1988-
h1:not(:first-child),
1989-
h2:not(:first-child),
1990-
h3:not(:first-child) {
1991-
margin-top: 2rem;
1992-
margin-bottom: 1rem;
1993-
}
1994-
1995-
h1:first-child,
1996-
h2:first-child,
1997-
h3:first-child {
1998-
margin-top: 0;
1999-
margin-bottom: 1rem;
2000-
}
2001-
2002-
/* --- CUSTOM MODERN SCROLLBAR --- */
2003-
2004-
::-webkit-scrollbar {
2005-
width: 6px !important;
2006-
height: 6px !important;
2007-
}
2008-
2009-
::-webkit-scrollbar-track {
2010-
background: transparent !important;
2011-
}
2012-
2013-
/* --- LIGHT THEME --- */
2014-
html[data-theme="light"] ::-webkit-scrollbar-thumb {
2015-
background-color: rgba(203, 213, 225, 1) !important;
2016-
border-radius: 10px !important;
2017-
}
2018-
2019-
html[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
2020-
background-color: rgba(148, 163, 184, 1) !important;
2021-
}
2022-
2023-
/* --- DARK THEME --- */
2024-
html[data-theme="dark"] ::-webkit-scrollbar-thumb {
2025-
background-color: rgba(51, 65, 85, 0.8) !important;
2026-
border-radius: 10px !important;
2027-
}
2028-
2029-
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
2030-
background-color: #06b6d4 !important;
2031-
}
2032-
2033-
/* --- FIREFOX CORRECTIONS --- */
2034-
html[data-theme="light"] {
2035-
scrollbar-width: thin !important;
2036-
scrollbar-color: #cbd5e1 transparent !important;
2037-
}
2038-
2039-
html[data-theme="dark"] {
2040-
scrollbar-width: thin !important;
2041-
scrollbar-color: #334155 transparent !important;
20422057
}
20432058

20442059
/* =====================================================

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)