frontend client for gemstone. decentralised workplace app

feat: better palette hook

serenity 9471a1fa fb7d3566

Changed files
+21
src
providers
+21
src/providers/ThemeProvider.tsx
···
+
import { useFacet } from "@/lib/facet";
+
import type { Facet } from "@/lib/facet/src/facet";
+
import type { FacetPalette } from "@/lib/facet/src/palette";
import type { Enumify } from "@/lib/utils/types";
import type { Dispatch, ReactNode, SetStateAction } from "react";
import { createContext, useContext, useState } from "react";
···
interface ThemeContextValue {
colorMode: ColorMode;
setColorMode: Dispatch<SetStateAction<ColorMode>>;
+
currentPalette: FacetPalette;
}
const ThemeContext = createContext<ThemeContextValue | null>(null);
···
return setColorMode;
};
+
export const useCurrentPalette = () => {
+
const { currentPalette } = useThemeProvider();
+
return currentPalette;
+
};
+
export const ThemeProvider = ({ children }: { children: ReactNode }) => {
const [colorMode, setColorMode] = useState<ColorMode>(ColorMode.DARK);
+
const facet = useFacet();
+
const currentPalette =
+
colorMode === "dark"
+
? facet.variants.obsidian
+
: // TODO: temporary. will remove the null coalesce when pearl is defined.
+
(facet.variants.pearl ?? facet.variants.obsidian);
+
+
// TODO: remove nullability with obsidian and pearl palettes.
+
// instead, these are provided as defaults and if we add more themes
+
// in the future, they can just be tacked on.
+
if (!currentPalette) throw new Error("Don't use light mode for now.");
const value: ThemeContextValue = {
colorMode,
setColorMode,
+
currentPalette,
};
return <ThemeContext value={value}>{children}</ThemeContext>;
};