Wrote color values component.

This commit is contained in:
Jay
2025-08-09 16:16:33 -04:00
parent 105e66b30b
commit ae02e49ce2
4 changed files with 229 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import { createContext, useContext, useReducer } from "react";
import type { ReactNode } from "react";
import * as colorlib from "colorlib";
import { colorReducer, createColorActions } from "@hooks/color";
import type { ColorActions } from "@hooks/color";
interface SelectedColorContextType {
selectedColor: colorlib.Color;
selectedColorActions: ColorActions;
}
export const SelectedColorContext = createContext<
SelectedColorContextType | undefined
>(undefined);
export const SelectedColorProvider = ({
children,
}: {
children: ReactNode;
}) => {
const initialState = {
color: colorlib.Color.from_hex("00C9FA"),
};
const [colorState, colorDispatch] = useReducer(colorReducer, initialState);
const colorActions = createColorActions(colorDispatch);
const value = {
selectedColor: colorState.color,
selectedColorActions: colorActions,
};
return (
<SelectedColorContext.Provider value={value}>
{children}
</SelectedColorContext.Provider>
);
};