Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

feat: support for multiple themes

daniel31x13c3981c7fff2c
diff --git a/components/IconPicker.tsx b/components/IconPicker.tsx
index 82643a8c..1f2fd0b8 100644
--- a/components/IconPicker.tsx
+++ b/components/IconPicker.tsx
@@ -48,15 +48,12 @@ const IconPicker = ({
icon={iconName}
size={60}
weight={(weight || "regular") as IconWeight}
- color={color || "#0ea5e9"}
+ color={color}
/>
) : !iconName && hideDefaultIcon ? (
<p className="p-1">{t("set_custom_icon")}</p>
) : (
- <i
- className="bi-folder-fill text-6xl"
- style={{ color: color || "#0ea5e9" }}
- ></i>
+ <i className="bi-folder-fill text-6xl" style={{ color: color }}></i>
)}
</div>
{iconPicker && (
diff --git a/components/LinkDetails.tsx b/components/LinkDetails.tsx
index 0a98cf9b..f83fbb0c 100644
--- a/components/LinkDetails.tsx
+++ b/components/LinkDetails.tsx
@@ -29,6 +29,7 @@ import unescapeString from "@/lib/client/unescapeString";
import IconPopover from "./IconPopover";
import TextInput from "./TextInput";
import usePermissions from "@/hooks/usePermissions";
+import oklchVariableToHex from "@/lib/client/oklchVariableToHex";
type Props = {
className?: string;
@@ -279,7 +280,7 @@ export default function LinkDetails({
</div>
{iconPopover && (
<IconPopover
- color={link.color || "#006796"}
+ color={link.color || oklchVariableToHex("--p")}
setColor={(color: string) => setLink({ ...link, color })}
weight={(link.iconWeight || "regular") as IconWeight}
setWeight={(iconWeight: string) =>
diff --git a/components/LinkViews/LinkComponents/LinkIcon.tsx b/components/LinkViews/LinkComponents/LinkIcon.tsx
index 327e7af3..4def762a 100644
--- a/components/LinkViews/LinkComponents/LinkIcon.tsx
+++ b/components/LinkViews/LinkComponents/LinkIcon.tsx
@@ -5,6 +5,7 @@ import React, { useState } from "react";
import Icon from "@/components/Icon";
import { IconWeight } from "@phosphor-icons/react";
import clsx from "clsx";
+import oklchVariableToHex from "@/lib/client/oklchVariableToHex";
export default function LinkIcon({
link,
@@ -19,7 +20,7 @@ export default function LinkIcon({
}) {
let iconClasses: string = clsx(
"rounded flex item-center justify-center shadow select-none z-10 w-12 h-12",
- !hideBackground && "rounded-md bg-white backdrop-blur-lg bg-opacity-50 p-1",
+ !hideBackground && "rounded-md backdrop-blur-xl bg-opacity-50 p-1",
className
);
@@ -36,7 +37,7 @@ export default function LinkIcon({
icon={link.icon}
size={30}
weight={(link.iconWeight || "regular") as IconWeight}
- color={link.color || "#006796"}
+ color={link.color || oklchVariableToHex("--p")}
className="m-auto"
/>
</div>
@@ -92,7 +93,12 @@ const LinkPlaceholderIcon = ({
icon: string;
}) => {
return (
- <div className={clsx(iconClasses, "aspect-square text-4xl text-[#006796]")}>
+ <div
+ className={clsx(
+ iconClasses,
+ "aspect-square text-4xl text-[oklch(var(--p))]"
+ )}
+ >
<i className={`${icon} m-auto`}></i>
</div>
);
diff --git a/components/ModalContent/EditCollectionModal.tsx b/components/ModalContent/EditCollectionModal.tsx
index e76456a9..a1cb97c4 100644
--- a/components/ModalContent/EditCollectionModal.tsx
+++ b/components/ModalContent/EditCollectionModal.tsx
@@ -7,6 +7,7 @@ import { useUpdateCollection } from "@/hooks/store/collections";
import toast from "react-hot-toast";
import IconPicker from "../IconPicker";
import { IconWeight } from "@phosphor-icons/react";
+import oklchVariableToHex from "@/lib/client/oklchVariableToHex";
type Props = {
onClose: Function;
@@ -74,7 +75,7 @@ export default function EditCollectionModal({
reset={() =>
setCollection({
...collection,
- color: "#0ea5e9",
+ color: oklchVariableToHex("--p"),
icon: "",
iconWeight: "",
})
diff --git a/components/ModalContent/NewCollectionModal.tsx b/components/ModalContent/NewCollectionModal.tsx
index b407c508..5f6ae776 100644
--- a/components/ModalContent/NewCollectionModal.tsx
+++ b/components/ModalContent/NewCollectionModal.tsx
@@ -8,6 +8,7 @@ import { useCreateCollection } from "@/hooks/store/collections";
import toast from "react-hot-toast";
import IconPicker from "../IconPicker";
import { IconWeight } from "@phosphor-icons/react";
+import oklchVariableToHex from "@/lib/client/oklchVariableToHex";
type Props = {
onClose: Function;
@@ -16,18 +17,19 @@ type Props = {
export default function NewCollectionModal({ onClose, parent }: Props) {
const { t } = useTranslation();
+
const initial = {
parentId: parent?.id,
name: "",
description: "",
- color: "#0ea5e9",
+ color: oklchVariableToHex("--p"), // Use resolved color
} as Partial<Collection>;
const [collection, setCollection] = useState<Partial<Collection>>(initial);
useEffect(() => {
setCollection(initial);
- }, []);
+ }, [parent]);
const [submitLoader, setSubmitLoader] = useState(false);
@@ -75,7 +77,7 @@ export default function NewCollectionModal({ onClose, parent }: Props) {
<div className="flex flex-col gap-3">
<div className="flex gap-3 items-end">
<IconPicker
- color={collection.color || "#0ea5e9"}
+ color={collection.color || oklchVariableToHex("--p")}
setColor={(color: string) =>
setCollection({ ...collection, color })
}
@@ -90,7 +92,7 @@ export default function NewCollectionModal({ onClose, parent }: Props) {
reset={() =>
setCollection({
...collection,
- color: "#0ea5e9",
+ color: oklchVariableToHex("--p"),
icon: "",
iconWeight: "",
})
diff --git a/lib/client/oklchVariableToHex.ts b/lib/client/oklchVariableToHex.ts
new file mode 100644
index 00000000..63537cbe
--- /dev/null
+++ b/lib/client/oklchVariableToHex.ts
@@ -0,0 +1,15 @@
+import Color from "colorjs.io";
+
+const oklchVariableToHex = (variable: string): string => {
+ const rootStyle = getComputedStyle(document.documentElement);
+ const rawColor = rootStyle.getPropertyValue(variable).trim();
+ const oklchColor = `oklch(${rawColor})`;
+ const hexColor = new Color(oklchColor)
+ .toGamut({ space: "srgb" })
+ .to("srgb")
+ .toString({ format: "hex" });
+ console.log(hexColor);
+ return hexColor;
+};
+
+export default oklchVariableToHex;
diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.ts
index 5b0b1501..b75aeaf4 100644
--- a/lib/shared/schemaValidation.ts
+++ b/lib/shared/schemaValidation.ts
@@ -126,7 +126,7 @@ export const UpdateLinkSchema = z.object({
description: z.string().trim().max(2048).nullish(),
icon: z.string().trim().max(50).nullish(),
iconWeight: z.string().trim().max(50).nullish(),
- color: z.string().trim().max(10).nullish(),
+ color: z.string().trim().max(50).nullish(),
collection: z.object({
id: z.number(),
ownerId: z.number(),
@@ -179,7 +179,7 @@ export const UploadFileSchema = z.object({
export const PostCollectionSchema = z.object({
name: z.string().trim().max(2048),
description: z.string().trim().max(2048).optional(),
- color: z.string().trim().max(10).optional(),
+ color: z.string().trim().max(50).optional(),
icon: z.string().trim().max(50).optional(),
iconWeight: z.string().trim().max(50).optional(),
parentId: z.number().optional(),
@@ -191,7 +191,7 @@ export const UpdateCollectionSchema = z.object({
id: z.number(),
name: z.string().trim().max(2048),
description: z.string().trim().max(2048).optional(),
- color: z.string().trim().max(10).optional(),
+ color: z.string().trim().max(50).optional(),
isPublic: z.boolean().optional(),
icon: z.string().trim().max(50).nullish(),
iconWeight: z.string().trim().max(50).nullish(),
diff --git a/package.json b/package.json
index 70e73992..92d8090f 100644
--- a/package.json
+++ b/package.json
@@ -43,6 +43,7 @@
"bootstrap-icons": "^1.11.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
+ "colorjs.io": "^0.5.2",
"colorthief": "^2.4.0",
"concurrently": "^8.2.2",
"crypto-js": "^4.2.0",
diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsx
index 10abc7c1..1875683e 100644
--- a/pages/settings/preference.tsx
+++ b/pages/settings/preference.tsx
@@ -12,7 +12,7 @@ import TagSelection from "@/components/InputSelect/TagSelection";
export default function Appearance() {
const { t } = useTranslation();
- const { updateSettings } = useLocalSettingsStore();
+ const { settings, updateSettings } = useLocalSettingsStore();
const [submitLoader, setSubmitLoader] = useState(false);
const { data: account } = useUser();
const updateUser = useUpdateUser();
@@ -121,29 +121,60 @@ export default function Appearance() {
<div className="flex flex-col gap-5">
<div>
- <p className="mb-3">{t("select_theme")}</p>
<div className="flex gap-3 w-full">
- <div
- className={`w-full text-center outline-solid outline-neutral-content outline dark:outline-neutral-700 h-36 duration-100 rounded-md flex items-center justify-center cursor-pointer select-none bg-black ${
- localStorage.getItem("theme") === "dark"
- ? "dark:outline-primary text-primary"
- : "text-white"
- }`}
- onClick={() => updateSettings({ theme: "dark" })}
- >
- <i className="bi-moon-fill text-6xl"></i>
- <p className="ml-2 text-2xl">{t("dark")}</p>
- </div>
- <div
- className={`w-full text-center outline-solid outline-neutral-content outline dark:outline-neutral-700 h-36 duration-100 rounded-md flex items-center justify-center cursor-pointer select-none bg-white ${
- localStorage.getItem("theme") === "light"
- ? "outline-primary text-primary"
- : "text-black"
- }`}
- onClick={() => updateSettings({ theme: "light" })}
- >
- <i className="bi-sun-fill text-6xl"></i>
- <p className="ml-2 text-2xl">{t("light")}</p>
+ {[
+ {
+ theme: "dark",
+ icon: "bi-moon-fill",
+ bgColor: "bg-black",
+ textColor: "text-white",
+ activeColor: "text-primary",
+ },
+ {
+ theme: "light",
+ icon: "bi-sun-fill",
+ bgColor: "bg-white",
+ textColor: "text-black",
+ activeColor: "text-primary",
+ },
+ ].map(({ theme, icon, bgColor, textColor, activeColor }) => (
+ <div
+ key={theme}
+ className={`w-full text-center outline-solid outline-neutral-content outline h-20 duration-100 rounded-xl flex items-center justify-center cursor-pointer select-none ${bgColor} ${
+ localStorage.getItem("theme") === theme
+ ? `outline-primary ${activeColor}`
+ : textColor
+ }`}
+ onClick={() => updateSettings({ theme })}
+ >
+ <i className={`${icon} text-3xl`}></i>
+ <p className="ml-2 text-2xl">{t(theme)}</p>
+ </div>
+ ))}
+ </div>
+
+ <div className="mt-3">
+ <div className="flex gap-3 w-3/4 mx-auto">
+ {[
+ "--default",
+ "--red",
+ "--rose",
+ "--yellow",
+ "--green",
+ "--orange",
+ "--zinc",
+ ].map((color) => (
+ <div
+ key={color}
+ className="relative rounded-full w-full aspect-square cursor-pointer"
+ style={{ backgroundColor: `oklch(var(${color}))` }}
+ onClick={() => updateSettings({ color })}
+ >
+ {settings.color === color && (
+ <i className="bi-check2 text-xl text-base-100 absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"></i>
+ )}
+ </div>
+ ))}
</div>
</div>
</div>
diff --git a/store/localSettings.ts b/store/localSettings.ts
index 57254d02..6ce76ea4 100644
--- a/store/localSettings.ts
+++ b/store/localSettings.ts
@@ -4,6 +4,7 @@ import { create } from "zustand";
type LocalSettings = {
theme: string;
viewMode: string;
+ color: string;
show: {
link: boolean;
name: boolean;
@@ -28,6 +29,7 @@ const useLocalSettingsStore = create<LocalSettingsStore>((set) => ({
settings: {
theme: "",
viewMode: "",
+ color: "",
show: {
link: true,
name: true,
@@ -42,7 +44,7 @@ const useLocalSettingsStore = create<LocalSettingsStore>((set) => ({
sortBy: Sort.DateNewestFirst,
},
updateSettings: (newSettings) => {
- const { theme, viewMode, sortBy, show, columns } = newSettings;
+ const { theme, viewMode, color, sortBy, show, columns } = newSettings;
if (theme !== undefined && theme !== localStorage.getItem("theme")) {
localStorage.setItem("theme", theme);
@@ -56,6 +58,11 @@ const useLocalSettingsStore = create<LocalSettingsStore>((set) => ({
localStorage.setItem("viewMode", viewMode);
}
+ if (color !== undefined) {
+ localStorage.setItem("color", color);
+ document.documentElement.style.setProperty("--p", `var(${color})`);
+ }
+
if (sortBy !== undefined) {
localStorage.setItem("sortBy", sortBy.toString());
}
@@ -83,6 +90,9 @@ const useLocalSettingsStore = create<LocalSettingsStore>((set) => ({
const theme = localStorage.getItem("theme") || "dark";
localStorage.setItem("theme", theme);
+ const color = localStorage.getItem("color") || "--default";
+ localStorage.setItem("color", color);
+
const viewMode = localStorage.getItem("viewMode") || "card";
localStorage.setItem("viewMode", viewMode);
@@ -108,6 +118,7 @@ const useLocalSettingsStore = create<LocalSettingsStore>((set) => ({
settings: {
theme,
viewMode,
+ color,
show,
columns,
sortBy: useLocalSettingsStore.getState().settings.sortBy,
@@ -115,6 +126,7 @@ const useLocalSettingsStore = create<LocalSettingsStore>((set) => ({
});
document.querySelector("html")?.setAttribute("data-theme", theme);
+ document.documentElement.style.setProperty("--p", `var(${color})`);
},
}));
diff --git a/styles/globals.css b/styles/globals.css
index de596a4e..5b72f0dc 100644
--- a/styles/globals.css
+++ b/styles/globals.css
@@ -3,23 +3,34 @@
@tailwind utilities;
:root {
- --my-color: #fff;
--selection-color: #fff;
--selection-bg-color: #fff;
}
[data-theme="dark"] {
- --my-color: #000;
color-scheme: dark;
--selection-color: #000000;
--selection-bg-color: #ffffff;
+ --default: 82.76% 0.101277 230.317893;
+ --red: 69.73% 0.168 22.43;
+ --rose: 75% 0.2 340;
+ --yellow: 90% 0.1 90;
+ --green: 70% 0.15 140;
+ --orange: 80% 0.18 60;
+ --zinc: 88.45% 0.05 220;
}
[data-theme="light"] {
- --my-color: #ffabc8;
color-scheme: light;
--selection-color: #ffffff;
--selection-bg-color: #000000;
+ --default: 50% 0.1193 242.75;
+ --red: 49.7% 0.2026 22.43;
+ --rose: 55% 0.25 340;
+ --yellow: 69.58% 0.2 90;
+ --green: 60% 0.2 140;
+ --orange: 70% 0.22 60;
+ --zinc: 50% 0.07 220;
}
::selection {
@@ -196,14 +207,6 @@
}
}
-.primary-btn-gradient {
- box-shadow: inset 0px -9px 10px oklch(var(--p));
-}
-
-.primary-btn-gradient:hover {
- box-shadow: inset 0px -20px 40px #00436c;
-}
-
.line-break * {
overflow-y: hidden;
}
diff --git a/yarn.lock b/yarn.lock
index 8e380558..70595678 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2667,6 +2667,11 @@ color-support@^1.1.2:
resolved "https://registry.yarnpkg.com/color-support/-/color-support-1.1.3.tgz#93834379a1cc9a0c61f82f52f0d04322251bd5a2"
integrity sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==
+colorjs.io@^0.5.2:
+ version "0.5.2"
+ resolved "https://registry.yarnpkg.com/colorjs.io/-/colorjs.io-0.5.2.tgz#63b20139b007591ebc3359932bef84628eb3fcef"
+ integrity sha512-twmVoizEW7ylZSN32OgKdXRmo1qg+wT5/6C3xu5b9QsWzSFAhHLn2xd8ro0diCsKfCj1RdaTP/nrcW+vAoQPIw==
+
colorthief@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/colorthief/-/colorthief-2.4.0.tgz#74e6edd142695655bd5f52c7f8116b125ea2b2bd"