diff --git a/webapp/IronCalc/src/components/ColorPicker/ColorMenu.tsx b/webapp/IronCalc/src/components/ColorPicker/ColorMenu.tsx index 2c778ed..8a380b3 100644 --- a/webapp/IronCalc/src/components/ColorPicker/ColorMenu.tsx +++ b/webapp/IronCalc/src/components/ColorPicker/ColorMenu.tsx @@ -1,7 +1,7 @@ import styled from "@emotion/styled"; import { Menu, MenuItem } from "@mui/material"; import { Plus } from "lucide-react"; -import { type JSX, useRef, useState } from "react"; +import { useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { theme } from "../../theme"; import ColorPicker from "./ColorPicker"; @@ -11,10 +11,6 @@ type ColorMenuProps = { anchorEl: React.RefObject; open: boolean; onClose: () => void; - renderMenuItem: ( - color: string, - handleColorSelect: (color: string | null) => void, - ) => JSX.Element; }; const ColorMenu = ({ @@ -22,9 +18,7 @@ const ColorMenu = ({ anchorEl, open, onClose, - renderMenuItem, }: ColorMenuProps) => { - const [color, setColor] = useState(theme.palette.common.black); const recentColors = useRef([]); const [isPickerOpen, setPickerOpen] = useState(false); const { t } = useTranslation(); @@ -107,7 +101,6 @@ const ColorMenu = ({ /> ) : ( - {renderMenuItem(theme.palette.common.black, handleColorSelect)} @@ -116,14 +109,13 @@ const ColorMenu = ({ key={presetColor} $color={presetColor} onClick={(): void => { - setColor(presetColor); handleColorSelect(presetColor); }} /> ))} - {toneArrays.map((tones, index) => ( + {toneArrays.map((tones) => ( {tones.map((presetColor) => ( { - setColor(recentColor); handleColorSelect(recentColor); }} /> diff --git a/webapp/IronCalc/src/components/ColorPicker/ColorPicker.tsx b/webapp/IronCalc/src/components/ColorPicker/ColorPicker.tsx index ef68304..29ac63b 100644 --- a/webapp/IronCalc/src/components/ColorPicker/ColorPicker.tsx +++ b/webapp/IronCalc/src/components/ColorPicker/ColorPicker.tsx @@ -1,38 +1,33 @@ import styled from "@emotion/styled"; import { Menu, MenuItem, Popover, type PopoverOrigin } from "@mui/material"; import { Check, Plus } from "lucide-react"; -import { type JSX, useEffect, useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { HexColorInput, HexColorPicker } from "react-colorful"; import { useTranslation } from "react-i18next"; import { theme } from "../../theme"; // Types type ColorPickerProps = { - color?: string; - onChange: (color: string | null) => void; - onClose?: () => void; + color: string; + onChange: (color: string) => void; + onClose: () => void; anchorEl: React.RefObject; anchorOrigin?: PopoverOrigin; transformOrigin?: PopoverOrigin; open: boolean; - renderMenuItem?: ( - color: string, - handleColorSelect: (color: string | null) => void, - ) => JSX.Element; }; const colorPickerWidth = 240; // Main Component const ColorPicker = ({ - color = theme.palette.common.black, + color, onChange, onClose, anchorEl, anchorOrigin, transformOrigin, open, - renderMenuItem, }: ColorPickerProps) => { const [selectedColor, setSelectedColor] = useState(color); const [isPickerOpen, setPickerOpen] = useState(false); @@ -48,8 +43,8 @@ const ColorPicker = ({ setMenuOpen(open && !isPickerOpen); }, [open, isPickerOpen]); - const handleColorSelect = (color: string | null) => { - if (color && !recentColors.current.includes(color)) { + const handleColorSelect = (color: string) => { + if (!recentColors.current.includes(color)) { const maxRecentColors = 14; recentColors.current = [color, ...recentColors.current].slice( 0, @@ -118,17 +113,6 @@ const ColorPicker = ({ blueTones, ]; - // Default menu item renderer - const defaultRenderMenuItem = ( - color: string, - handleColorSelect: (color: string | null) => void, - ) => ( - handleColorSelect(color)}> - - {t("color_picker.default")} - - ); - // Render color picker or menu return ( <> @@ -191,10 +175,10 @@ const ColorPicker = ({ open={isMenuOpen} onClose={handleClose} > - {(renderMenuItem || defaultRenderMenuItem)( - theme.palette.common.black, - handleColorSelect, - )} + handleColorSelect(color)}> + + {t("color_picker.default")} + @@ -210,7 +194,7 @@ const ColorPicker = ({ ))} - {toneArrays.map((tones, index) => ( + {toneArrays.map((tones) => ( {tones.map((presetColor) => (