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

Add dark mode #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions src/app.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "omnibox-js/omnibox.css";
@import "./omnibox.css";

@tailwind base;
@tailwind components;
Expand Down Expand Up @@ -45,6 +46,7 @@ h2,
font-size: 20px;
font-weight: 500;
color: var(--primary-text-color);
@apply dark:text-[#f8fafc];
}
.text {
font-family: "Fira Sans", sans-serif;
Expand All @@ -70,19 +72,23 @@ h2,
}
.crate-list-item:hover {
background-color: #f5f3f1;
@apply dark:bg-darkHoverColor;
}
.crate-list-item .crate-attr {
margin: 0 8px;
font-size: 16px;
@apply dark:text-darkTextPrimary;
}
.crate-list-item .crate-desc {
color: #565656;
padding: 10px 0;
font-size: 16px;
@apply dark:text-[#8d8d8d];
}
.crate-list-item .crate-extra {
color: #565656;
font-size: 15px;
@apply dark:text-[#8d8d8d];
}
.btn-remove {
color: #dd4814;
Expand Down Expand Up @@ -172,9 +178,11 @@ input:checked + .slider:before {
}
.btn-primary {
background-color: #f9bb2daa;
@apply dark:bg-[#f9bb2d];
}
.btn-primary:hover {
background-color: #f9bb2d;
@apply dark:bg-[#f9bb2daa];
}
.btn-secondary {
background-color: #121212bb;
Expand Down Expand Up @@ -267,4 +275,5 @@ h3 {

.selected {
background-color: var(--primary-color);
@apply dark:!text-black
}
3 changes: 3 additions & 0 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
/* Primary theme text color */
--primary-text-color: #121212;
}
.dark {
background-color: #121213;
}
</style>
%sveltekit.head%
</head>
Expand Down
171 changes: 171 additions & 0 deletions src/omnibox.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
.omn-container {
box-sizing: border-box;
display: flex;
z-index: 3;
position: relative;
background: #fff;
border: 1px solid #dfe1e5;
box-shadow: none;
margin: 0 auto;
width: 100%;
align-items: center;
border-radius: 14px;
padding: 4px 10px;
font-size: 15px;

& + .omn-dropdown {
@apply dark:bg-black dark:text-darkTextPrimary;
& .omn-dim {
@apply dark:text-[#8d8d8d];
}
& .omn-dropdown-item:hover {
@apply dark:bg-darkHoverColor;
}
& .omn-selected{
@apply dark:bg-[#333333bf];
}
& img {
@apply dark:invert;
}
& div:last-child {
& > div {
@apply dark:bg-darkBgPrimary;
}
& button {
@apply hover:dark:bg-[#c8541ac7];
}
}
}
}
@media (min-width: 768px) {
.omn-container {
border-radius: 24px;
padding: 6px 12px;
font-size: 16px;
}
}
.omn-search-icon,
.omn-clear {
height: 22px;
line-height: 22px;
width: 22px;
margin-right: 5px;
}
.omn-clear {
display: none;
cursor: pointer;
margin-right: 10px;
}
.omn-input {
width: 100%;
border: transparent;
padding: 5px;
overflow-x: hidden;
}

.omn-hint {
display: flex;
color: #2559c9;
white-space: nowrap;
text-wrap: nowrap;
}

.omn-hint-gapline {
width: 1px;
height: 15px;
background: #9cb5eb;
margin: 0 5px;
align-self: center;
}

.omn-filled {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
box-shadow: 0 1px 6px rgba(32, 33, 36, 0.28);
border-color: transparent;
}

.omn-input:focus {
outline: none;
}

.omn-dropdown {
position: absolute;
z-index: 999;
margin-top: -1px;
width: 100%;
display: flex;
flex-direction: column;
margin: 0;
padding: 0;
overflow: hidden;
background: #fff;
border-radius: 0 0 24px 24px;
box-shadow: 0 4px 6px rgba(32, 33, 36, 0.28);
border: 0;
}

.omn-gapline {
border-top: 1px solid #e8eaed;
margin: 0 20px 0 14px;
padding-bottom: 4px;
}

.omn-dropdown-item {
padding: 0.6rem 1rem;
display: flex;
font-size: 16px;
}

.omn-dropdown-item a {
font-weight: normal;
text-decoration: none;
color: inherit;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}

.omn-dropdown-item a:visited {
color: inherit;
}

.omn-dropdown-item:hover {
cursor: pointer;
}

.omn-dropdown-item img {
width: 18px;
height: 18px;
padding: 2px;
vertical-align: middle;
}

.omn-dropdown-indicator {
display: none;
position: absolute;
box-sizing: border-box;
left: 0;
top: 0;
height: 100%;
border: 2px #3168cb solid;
border-radius: 0 10px 10px 0;
}

.omn-selected .omn-dropdown-indicator {
display: block;
}

.omn-selected,
.omn-dropdown-item:hover {
background-color: #f2f2f2;
}

.omn-match {
font-weight: 600;
}

.omn-dim {
font-weight: 300;
color: #474747;
}
72 changes: 62 additions & 10 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import { onMount } from "svelte";
import { storage, Statistics, CrateDocManager } from "querylib";
import "../app.css";
import { themeStore } from "../store/index";

let isDarkMode = false;
let hiddenMenu = true;
const menus = [
{
Expand All @@ -23,6 +25,23 @@
},
];

function handleChangeThemeMode() {
if (isDarkMode) {
document.documentElement.classList.add("dark");
localStorage.setItem("QUERY_RS_THEME", "dark");
themeStore.update(() => "dark");
} else {
document.documentElement.classList.remove("dark");
localStorage.setItem("QUERY_RS_THEME", "light");
themeStore.update(() => "light");
}
}

function changeThemeMethod() {
isDarkMode = !isDarkMode;
handleChangeThemeMode();
}

onMount(async () => {
let firstVisit = await storage.getItem("first-visit");
if (firstVisit === null) {
Expand All @@ -48,25 +67,53 @@
await storage.setItem("first-visit", "false");
}
});

onMount(() => {
if (
localStorage.QUERY_RS_THEME === "dark" ||
(!("QUERY_RS_THEME" in localStorage) &&
window.matchMedia("(prefers-color-scheme: dark)").matches)
) {
isDarkMode = true;
} else {
isDarkMode = false;
}
handleChangeThemeMode();
});
</script>

<div class="flex-layout" style="flex-direction: column;">
<div class="flex-layout dark:bg-darkBgPrimary dark:text-darkTextPrimary" style="flex-direction: column;">
<div class="max-w-[1160px] w-full flex flex-col">
<ul
class="hidden list-none flex-row overflow-auto md:flex self-end py-5 text-base md:text-xl"
class="hidden list-none flex-row overflow-auto md:flex self-end py-5 text-base md:text-xl items-center"
>
{#each menus as menu}
<li class="px-5 rounded-md hover:bg-[#f9bc2d46]">
<a href={menu.path}>{menu.name}</a>
<li
class="px-5 rounded-md hover:bg-[#f9bc2d46] dark:hover:bg-darkHoverColor"
>
<a
class="dark:text-darkTextPrimary dark:visited:text-darkTextPrimary"
href={menu.path}>{menu.name}</a
>
</li>
{/each}
<button
class="w-10 h-10 dark:hover:bg-darkHoverColor rounded-lg hover:bg-[#f9bc2d46]"
on:click={changeThemeMethod}
>
{#if isDarkMode}
<img src="/assets/light.svg" alt="light mode" />
{:else}
<img src="/assets/dark.svg" alt="dark mode" />
{/if}
</button>
</ul>
<div>
<div class="flex flex-row justify-between items-center md:hidden">
<img
src="/assets/logo.svg"
alt="logo"
class="w-24 mx-6 transition-opacity ease-in-out delay-300 duration-1000"
class="w-24 mx-6 transition-opacity ease-in-out delay-300 duration-1000 dark:invert"
class:opacity-0={hiddenMenu}
class:opacity-100={!hiddenMenu}
/>
Expand Down Expand Up @@ -103,21 +150,26 @@
</button>
</div>
<div
class="box-border px-4 py-12 md:px-12 md:py-24 bg-[white] relative rounded-[10px] mb-[50px] min-h-[calc(100vh_-_180px)]"
class="dark:bg-[#18181b] box-border px-4 py-12 md:px-12 md:py-24 bg-[white] relative rounded-[10px] mb-[50px] min-h-[calc(100vh_-_180px)]"
>
<a href="/" class="no-underline hover:no-underline">
<img
src="/assets/logo.svg"
alt="logo"
class="block mx-auto w-60 md:w-80 mt-8 mb-12"
class="block mx-auto w-60 md:w-80 mt-8 mb-12 dark:invert"
/>
</a>
<slot />
</div>
</div>
<footer class="pb-6 text-center px-4">
<footer class="pb-6 text-center px-4 dark:text-darkTextPrimary">
© 2024 Query.rs, built by
<a href="https://github.com/folyd" target="_blank">Folyd</a>
with ❤️❤️, see <a href="/about">about</a> page to learn more.
<a
href="https://github.com/folyd"
target="_blank"
class="dark:text-darkTextPrimary">Folyd</a
>
with ❤️❤️, see <a href="/about" class="dark:text-darkTextPrimary">about</a> page
to learn more.
</footer>
</div>
Loading