From acd956d3e3585c811f2b86688bef6ee7be8c539b Mon Sep 17 00:00:00 2001 From: alexTexis Date: Fri, 12 Jan 2024 16:11:47 -0600 Subject: [PATCH] feat(suggestions): update colors on click button apply --- src/components/color-inputs/suggestions-button.tsx | 12 +----------- src/components/suggestions/suggestions.tsx | 14 ++++++++++---- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/components/color-inputs/suggestions-button.tsx b/src/components/color-inputs/suggestions-button.tsx index e9f7152..17c9f24 100644 --- a/src/components/color-inputs/suggestions-button.tsx +++ b/src/components/color-inputs/suggestions-button.tsx @@ -1,27 +1,17 @@ "use client"; -import { useSetAtom } from "jotai"; import * as Dialog from "@radix-ui/react-dialog"; import { css } from "@root/styled-system/css"; import { Button } from "@/components/primitives/button"; import { Suggestions } from "@/components/suggestions"; import { LightFill, CloseFill } from "@/components/icons"; -import { background, foreground } from "@/store"; import { useToggle } from "@/hooks/use-toggle"; import classes from "./suggestions-button.styled"; export function SuggestionsButton() { const { isEnabled: open, onOpen, onClose, setOpen } = useToggle(); - const setFg = useSetAtom(foreground); - const setBg = useSetAtom(background); - - function onClickApply(bg: string, fg: string) { - setFg(fg); - setBg(bg); - onClose(); - } return ( @@ -51,7 +41,7 @@ export function SuggestionsButton() {
- +
diff --git a/src/components/suggestions/suggestions.tsx b/src/components/suggestions/suggestions.tsx index cc8160b..4766a14 100644 --- a/src/components/suggestions/suggestions.tsx +++ b/src/components/suggestions/suggestions.tsx @@ -1,7 +1,7 @@ "use client"; import { useRef } from "react"; -import { useAtomValue } from "jotai"; +import { useAtomValue, useAtom } from "jotai"; import { background, foreground, pickingColor, contrastRelation } from "@/store"; import { createContrastSuggestions } from "@/lib/contrast-suggestions"; @@ -15,8 +15,8 @@ interface SuggestionProps extends Pick { type Suggestions = ReturnType; export function Suggestions({ onApply, className }: SuggestionProps) { - const fg = useAtomValue(foreground); - const bg = useAtomValue(background); + const [fg, setFg] = useAtom(foreground); + const [bg, setBg] = useAtom(background); const isPickingColor = useAtomValue(pickingColor); const score = useAtomValue(contrastRelation); const prevSuggestions = useRef([]); @@ -29,6 +29,12 @@ export function Suggestions({ onApply, className }: SuggestionProps) { if (!isPickingColor) prevSuggestions.current = suggestions; + function handleOnApply(bg: string, fg: string) { + setFg(fg); + setBg(bg); + onApply?.(bg, fg); + } + return (
{isEmpty ? ( @@ -36,7 +42,7 @@ export function Suggestions({ onApply, className }: SuggestionProps) { ) : ( <> {suggestions.map((item) => ( - + ))} )}