From 43a3c7100ffd7b989376cac192e4b9b76af2cd7d Mon Sep 17 00:00:00 2001 From: Fechin Date: Sat, 21 Jun 2025 10:07:49 +0800 Subject: [PATCH] feat: improve mobile responsiveness and dark mode UX Mobile improvements: - Fix content overflow issues on mobile devices - Optimize code blocks and tables for small screens - Add proper word-wrapping and container constraints Dark mode enhancements: - Replace icons with modern sun/moon designs - Implement smooth icon switching with CSS transitions - Simplify toggle logic for better performance Resolves mobile layout issues and enhances theme switching experience --- source/assets/icon/dark.svg | 5 ++- source/assets/icon/light.svg | 5 ++- themes/coo/layout/_partial/header.ejs | 7 +++- themes/coo/layout/_partial/index/logo.ejs | 2 +- themes/coo/source/css/components/code.css | 17 ++++++++++ .../source/css/components/layout_table.css | 9 ++++++ themes/coo/source/css/style.tailwindcss | 32 +++++++++++++++++++ themes/coo/source/js/main.js | 9 ------ 8 files changed, 69 insertions(+), 17 deletions(-) diff --git a/source/assets/icon/dark.svg b/source/assets/icon/dark.svg index cefa443..8b6bba7 100644 --- a/source/assets/icon/dark.svg +++ b/source/assets/icon/dark.svg @@ -1,4 +1,3 @@ - - + + diff --git a/source/assets/icon/light.svg b/source/assets/icon/light.svg index 1624d0b..25b4369 100644 --- a/source/assets/icon/light.svg +++ b/source/assets/icon/light.svg @@ -1,4 +1,3 @@ - - + + diff --git a/themes/coo/layout/_partial/header.ejs b/themes/coo/layout/_partial/header.ejs index 7368ee4..d40089f 100644 --- a/themes/coo/layout/_partial/header.ejs +++ b/themes/coo/layout/_partial/header.ejs @@ -45,9 +45,14 @@ "> + + "> <%- icon("light") %> + + "> + <%- icon("dark") %> + diff --git a/themes/coo/layout/_partial/index/logo.ejs b/themes/coo/layout/_partial/index/logo.ejs index a35d72d..c5409e2 100644 --- a/themes/coo/layout/_partial/index/logo.ejs +++ b/themes/coo/layout/_partial/index/logo.ejs @@ -25,7 +25,7 @@ if (logoTheme === 'dark') { %> <% if (icon) { %> -
+
<%- icon("logo") %>
diff --git a/themes/coo/source/css/components/code.css b/themes/coo/source/css/components/code.css index 58266f8..1bbaaa5 100644 --- a/themes/coo/source/css/components/code.css +++ b/themes/coo/source/css/components/code.css @@ -5,6 +5,8 @@ code { pre { line-height: 1.5; + word-wrap: break-word; + white-space: pre-wrap; @apply overflow-hidden overflow-x-auto bg-white p-4; } @@ -34,6 +36,21 @@ pre > code.wrap { @apply whitespace-pre-wrap break-words !important; } +@media (width <= 768px) { + pre { + @apply text-sm; + + max-width: 100%; + overflow-x: auto; + } + + pre > code { + white-space: pre-wrap; + word-wrap: break-word; + overflow-wrap: break-word; + } +} + .mdLayout .line-highlight { transform: translate3d(0, 2px, 0); background: linear-gradient(to right, rgb(20 175 131 / 5%) 25%, transparent); diff --git a/themes/coo/source/css/components/layout_table.css b/themes/coo/source/css/components/layout_table.css index 1219cbe..85d59e7 100644 --- a/themes/coo/source/css/components/layout_table.css +++ b/themes/coo/source/css/components/layout_table.css @@ -1,5 +1,7 @@ .mdLayout table { width: 100%; + table-layout: fixed; + word-wrap: break-word; } .mdLayout .section > table:last-child::after { @@ -41,6 +43,13 @@ white-space: nowrap; } +@media (width <= 768px) { + .mdLayout table td:first-child { + white-space: normal; + word-wrap: break-word; + } +} + .mdLayout table td:first-child > code { @apply text-indigo-600; } diff --git a/themes/coo/source/css/style.tailwindcss b/themes/coo/source/css/style.tailwindcss index b859bbc..cb43626 100644 --- a/themes/coo/source/css/style.tailwindcss +++ b/themes/coo/source/css/style.tailwindcss @@ -39,6 +39,14 @@ html.scrollbar { @apply mx-auto p-3; } +@media (max-width: 768px) { + .max-container { + @apply px-4; + max-width: 100%; + overflow-x: hidden; + } +} + .header-button { @apply inline-flex items-center bg-slate-200 text-slate-600 transition duration-200 rounded-full border-0 p-3 ml-1 font-medium; @apply hover:bg-slate-300 hover:text-slate-700 hover:shadow-lg; @@ -86,6 +94,30 @@ html.scrollbar { @apply flex flex-col space-y-14; } +@media (max-width: 768px) { + .mdLayout { + overflow-x: hidden; + word-wrap: break-word; + } +} + +/* Dark mode toggle icons */ +.icon-light { + display: block; +} + +.icon-dark { + display: none; +} + +.dark .icon-light { + display: none; +} + +.dark .icon-dark { + display: block; +} + .mdLayout h3 a.h-anchor, .mdLayout h4 a.h-anchor, .mdLayout h5 a.h-anchor { @apply hidden; } diff --git a/themes/coo/source/js/main.js b/themes/coo/source/js/main.js index 24d69e3..46c63ee 100644 --- a/themes/coo/source/js/main.js +++ b/themes/coo/source/js/main.js @@ -504,18 +504,9 @@ window.addEventListener('load', () => { fetchGitHubStars(); // Dark mode functionality - const isDarkMode = document.documentElement.classList.contains('dark'); - if (!isDarkMode) { - const icon = document.querySelector('#darkMode > i').classList; - icon.toggle('icon-light'); - icon.toggle('icon-dark'); - } document.querySelector('#darkMode').addEventListener('click', () => { const html = document.documentElement.classList; html.toggle('dark'); - const icon = document.querySelector('#darkMode > i').classList; - icon.toggle('icon-light'); - icon.toggle('icon-dark'); const isDarkMode = html.contains('dark'); localStorage.theme = isDarkMode ? 'dark' : ''; });