Skip to content

Commit

Permalink
avoid nested ternary and use props for default iconColor state
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmac committed Jan 18, 2024
1 parent 17ee058 commit 2b31174
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/invertible-theme/src/Buttons/DarkModeIconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ export const DarkModeIconButton: React.FC<DarkModeIconButtonProps> = ({
toggleMode,
...props
}) => {
const [iconColor, setIconColor] = useState<iconColor>('inherit')
const [iconColorIsSet, setIconColorIsSet] = useState(false)
const darkModeIconColor = defaultDarkModeColor ?? 'inherit'
const lightModeIconColor = defaultLightModeColor ?? 'inherit'
const [iconColor, setIconColor] = useState<iconColor>(darkMode ? defaultDarkModeColor : defaultLightModeColor)
const [iconColorIsSet, setIconColorIsSet] = useState(false)

const handleHover = () => {
setIconColor(darkMode ? (iconColorIsSet ? darkModeIconColor : 'info') : iconColorIsSet ? lightModeIconColor : 'warning')
setIconColor(() => {
if (darkMode) {
return iconColorIsSet ? darkModeIconColor : 'info'
} else {
return iconColorIsSet ? lightModeIconColor : 'warning'
}
})
setIconColorIsSet(!iconColorIsSet)
}

Expand Down

0 comments on commit 2b31174

Please sign in to comment.