Skip to content

Commit

Permalink
fix default list color
Browse files Browse the repository at this point in the history
  • Loading branch information
cmintey committed Jan 9, 2025
1 parent f810484 commit a0880e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export const trimToNull = (s: string | null) => {
}
return sTrimed;
};

export const rgbToHex = (r: number, g: number, b: number) => {
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
};
18 changes: 16 additions & 2 deletions src/routes/lists/[id]/manage/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@
import { page } from "$app/stores";
import { getToastStore } from "@skeletonlabs/skeleton";
import ClearableInput from "$lib/components/ClearableInput.svelte";
import { rgbToHex } from "$lib/util";
interface Props {
data: PageData;
}
const { data }: Props = $props();
const defaultColor = "#a940bf"; // this is actually dynamic based on the theme, but easier to hardcode the value
const list = $state(data.list);
let colorValue: string = $state(list.iconColor || defaultColor);
let colorElement: Element | undefined = $state();
let defaultColor: string = $derived.by(() => {
if (colorElement) {
const rgbColor = getComputedStyle(colorElement).backgroundColor;
const rgbValues = rgbColor.match(/\d+/g)?.map(Number.parseFloat);
return rgbValues ? rgbToHex(rgbValues[0], rgbValues[1], rgbValues[2]) : "";
}
return "";
});
let colorValue: string = $state(list.iconColor || (() => defaultColor)());
$effect(() => {
colorValue = defaultColor;
});
$effect(() => {
if ($page.form && !$page.form.success && $page.form.errors === null) {
getToastStore().trigger({
Expand Down Expand Up @@ -100,6 +112,8 @@
</div>
</form>

<div bind:this={colorElement} class="bg-primary-400-500-token hidden"></div>

<svelte:head>
<title>{$t("wishes.manage-list")}</title>
</svelte:head>

0 comments on commit a0880e5

Please sign in to comment.