diff --git a/src/components/ColorInput/ColorInput.tsx b/src/components/ColorInput/ColorInput.tsx index f1e06db..17f13a1 100644 --- a/src/components/ColorInput/ColorInput.tsx +++ b/src/components/ColorInput/ColorInput.tsx @@ -1,8 +1,8 @@ import React from "react"; -import { useRecoilState } from "recoil"; -import TinyColor from "tinycolor2"; +import { useRecoilState, useRecoilValue } from "recoil"; import { iconColorAtom } from "../../state/atoms"; +import { isDarkThemeSelector } from "../../state/selectors"; import useThrottled from "../../hooks/useThrottled"; import "./ColorInput.css"; @@ -10,17 +10,19 @@ type ColorInputProps = {}; const ColorInput: React.FC = () => { const [color, setColor] = useRecoilState(iconColorAtom); - const isDark = TinyColor(color).isDark(); - + const isDark = useRecoilValue(isDarkThemeSelector); + const handleColorChange = (event: React.ChangeEvent) => { const { target: { value: color }, } = event; if (color[0] === "#") setColor(color); }; - - const throttledColorChange = useThrottled(handleColorChange, 100, [handleColorChange]) - + + const throttledColorChange = useThrottled(handleColorChange, 100, [ + handleColorChange, + ]); + return (
= () => { onChange={throttledColorChange} value={color} /> - {color} + {color}
); }; diff --git a/src/components/IconGrid/IconGrid.tsx b/src/components/IconGrid/IconGrid.tsx index 6c8ebbc..4a5a4aa 100644 --- a/src/components/IconGrid/IconGrid.tsx +++ b/src/components/IconGrid/IconGrid.tsx @@ -2,27 +2,26 @@ import React, { useRef, useEffect } from "react"; import { useRecoilValue } from "recoil"; import { motion, useAnimation } from "framer-motion"; import { useWindowSize } from "react-use"; -import TinyColor from "tinycolor2"; import { IconContext, Warning } from "phosphor-react"; import { - styleQueryAtom, + iconStyleAtom, iconSizeAtom, iconColorAtom, searchQueryAtom, } from "../../state/atoms"; -import { filteredQueryResultsSelector } from "../../state/selectors"; +import { filteredQueryResultsSelector, isDarkThemeSelector } from "../../state/selectors"; import GridItem from "./IconGridItem"; import "./IconGrid.css"; type IconGridProps = {}; -const IconGridAnimated: React.FC = () => { - const weight = useRecoilValue(styleQueryAtom); +const IconGrid: React.FC = () => { + const weight = useRecoilValue(iconStyleAtom); const size = useRecoilValue(iconSizeAtom); const color = useRecoilValue(iconColorAtom); const query = useRecoilValue(searchQueryAtom); - const isDark = TinyColor(color).isLight(); + const isDark = useRecoilValue(isDarkThemeSelector); const { width } = useWindowSize(); const spans = Math.floor(Math.min(width - 32, 1120) / 168); @@ -77,4 +76,4 @@ const IconGridAnimated: React.FC = () => { ); }; -export default IconGridAnimated; +export default IconGrid; diff --git a/src/components/IconGrid/InfoPanel.tsx b/src/components/IconGrid/InfoPanel.tsx index 185c9d0..b411952 100644 --- a/src/components/IconGrid/InfoPanel.tsx +++ b/src/components/IconGrid/InfoPanel.tsx @@ -5,7 +5,7 @@ import { saveAs } from "file-saver"; import { Icon, Copy, X, CheckCircle, ArchiveDiskDot } from "phosphor-react"; import { - styleQueryAtom, + iconStyleAtom, iconSizeAtom, iconColorAtom, iconPreviewOpenAtom, @@ -37,7 +37,7 @@ interface InfoPanelProps { const InfoPanel: React.FC = (props) => { const { index, spans, isDark, name, Icon } = props; - const weight = useRecoilValue(styleQueryAtom); + const weight = useRecoilValue(iconStyleAtom); const size = useRecoilValue(iconSizeAtom); const color = useRecoilValue(iconColorAtom); const setOpen = useSetRecoilState(iconPreviewOpenAtom); diff --git a/src/components/StyleInput/StyleInput.tsx b/src/components/StyleInput/StyleInput.tsx index 27f3b06..160a3f7 100644 --- a/src/components/StyleInput/StyleInput.tsx +++ b/src/components/StyleInput/StyleInput.tsx @@ -3,7 +3,7 @@ import { useRecoilState } from "recoil"; import Select from "react-dropdown-select"; import { PencilLine } from "phosphor-react"; -import { styleQueryAtom } from "../../state/atoms"; +import { iconStyleAtom } from "../../state/atoms"; import { IconStyle } from "../../lib"; import "./StyleInput.css"; @@ -43,7 +43,7 @@ const options = [ type StyleInputProps = {}; const StyleInput: React.FC = () => { - const [style, setStyle] = useRecoilState(styleQueryAtom); + const [style, setStyle] = useRecoilState(iconStyleAtom); void style; // const handleStyleChange = (event: React.ChangeEvent) => { diff --git a/src/state/atoms.ts b/src/state/atoms.ts index e9110bd..00c83ff 100644 --- a/src/state/atoms.ts +++ b/src/state/atoms.ts @@ -6,7 +6,7 @@ export const searchQueryAtom = atom({ default: "", }); -export const styleQueryAtom = atom({ +export const iconStyleAtom = atom({ key: "styleQueryAtom", default: IconStyle.REGULAR, }); diff --git a/src/state/selectors.ts b/src/state/selectors.ts index 46c59a3..f67046c 100644 --- a/src/state/selectors.ts +++ b/src/state/selectors.ts @@ -1,6 +1,7 @@ import { selector, selectorFamily } from "recoil"; +import TinyColor from "tinycolor2"; -import { searchQueryAtom, styleQueryAtom } from "./atoms"; +import { searchQueryAtom, iconStyleAtom, iconColorAtom } from "./atoms"; import { IconEntry, IconCategory } from "../lib"; import { icons } from "../lib/icons"; @@ -16,7 +17,7 @@ export const filteredQueryResultsSelector = selector>({ key: "filteredQueryResultsSelector", get: async ({ get }) => { const query = get(searchQueryAtom).trim().toLowerCase(); - const style = get(styleQueryAtom); + const style = get(iconStyleAtom); if (!query && !style) return icons; @@ -62,3 +63,8 @@ export const singleCategoryQueryResultsSelector = selectorFamily< ); }, }); + +export const isDarkThemeSelector = selector({ + key: "isDarkThemeSelector", + get: ({ get }) => TinyColor(get(iconColorAtom)).isLight(), +});