Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change scrollbar css according to theme #39

Merged
merged 2 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="dark" lang="en">
<html class="dark" data-color-scheme="dark" lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
Expand Down
33 changes: 29 additions & 4 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
@tailwind components;
@tailwind utilities;

[data-color-scheme="dark"] {
color-scheme: dark;
}

[data-color-scheme="light"] {
color-scheme: light;
}

html {
@apply h-full;
}
Expand Down Expand Up @@ -40,17 +48,34 @@ td {
@screen md {
* {
scrollbar-width: thin;
scrollbar-color: theme(colors.slate.500);
}
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
::-webkit-scrollbar-thumb {
border: 1px solid theme(colors.slate.400);
border-radius: 4px;
}

[data-color-scheme="light"] * {
scrollbar-color: theme(colors.slate.300);
}
[data-color-scheme="light"] ::-webkit-scrollbar-track {
background: theme(colors.slate.300);
}
[data-color-scheme="light"] ::-webkit-scrollbar-thumb {
background-color: theme(colors.slate.400);
border: 1px solid theme(colors.slate.400);
}

[data-color-scheme="dark"] * {
scrollbar-color: theme(colors.slate.500);
}
[data-color-scheme="dark"] ::-webkit-scrollbar-track {
background: theme(colors.slate.800);
}
::-webkit-scrollbar-thumb {
[data-color-scheme="dark"] ::-webkit-scrollbar-thumb {
background-color: theme(colors.slate.700);
border-radius: 4px;
border: 1px solid theme(colors.slate.600);
}
}
12 changes: 9 additions & 3 deletions src/utils/hooks/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ export const useTheme = () => {

useEffect(() => {
localStorage.setItem('theme', theme)
if (theme == 'dark') {
document.documentElement.classList.add('dark')
if (theme == "dark") {
document.documentElement.classList.add("dark")
document.documentElement.classList.remove('light');
} else {
document.documentElement.classList.remove('dark')
document.documentElement.classList.add("light")
document.documentElement.classList.remove('dark');
}
document.documentElement.setAttribute(
"data-color-scheme",
theme
);
}, [theme])

return [theme, setTheme] as const
Expand Down