-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [Footer/header] new color scheme toggle and cleaner footer desi…
…gn (#433) Closes DG-86, DG-85 ## What changed? Why? Doesn't move it to footer but cleans up the color scheme toggle + footer design currently <img width="1195" alt="image" src="https://github.com/dgattey/dg/assets/982182/3cff217f-4687-4d90-86f0-7dbd018270f6"> <img width="272" alt="image" src="https://github.com/dgattey/dg/assets/982182/3ba65db9-fad1-4e55-8d1b-413dfb3714e3">
- Loading branch information
Showing
11 changed files
with
138 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { ButtonProps, TooltipProps } from '@mui/material'; | ||
import { Button, Tooltip } from '@mui/material'; | ||
|
||
/** | ||
* Handles weird layout problems with buttons and tooltips by wrapping it in a div | ||
*/ | ||
export function ButtonWithTooltip({ | ||
tooltipProps, | ||
buttonProps, | ||
children, | ||
}: { | ||
tooltipProps: Partial<Omit<TooltipProps, 'children'>> & Pick<TooltipProps, 'title'>; | ||
buttonProps: Partial<Omit<ButtonProps, 'children'>>; | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<Tooltip {...tooltipProps}> | ||
<div> | ||
<Button {...buttonProps}>{children}</Button> | ||
</div> | ||
</Tooltip> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { Moon, Sun, Monitor } from 'lucide-react'; | ||
import type { Theme } from '@mui/material'; | ||
import { useColorScheme } from '../theme/useColorScheme'; | ||
import type { ColorSchemeMode } from '../theme/useColorScheme'; | ||
import { ButtonWithTooltip } from './ButtonWithTooltip'; | ||
|
||
type Mode = ColorSchemeMode | 'system'; | ||
|
||
type ColorSchemeButtonProps = { | ||
/** | ||
* The color scheme mode to switch to on click | ||
*/ | ||
mode: Mode; | ||
}; | ||
|
||
const ICON_SIZE = 13; | ||
const DELAY_MS = 200; | ||
|
||
const ICONS: Record<Mode, JSX.Element> = { | ||
light: <Sun size={ICON_SIZE} />, | ||
dark: <Moon size={ICON_SIZE} />, | ||
system: <Monitor size={ICON_SIZE} />, | ||
} as const; | ||
|
||
function getColor(mode: Mode, theme: Theme) { | ||
switch (mode) { | ||
case 'light': | ||
return theme.vars.palette.warning.main; | ||
case 'dark': | ||
return theme.vars.palette.secondary.light; | ||
case 'system': | ||
return theme.vars.palette.primary.dark; | ||
} | ||
} | ||
|
||
/** | ||
* Creates an icon that is clickable to update to a preferred color scheme | ||
* if we have one that's set already. Otherwise, renders a disabled icon. | ||
*/ | ||
export function ColorSchemeButton({ mode }: ColorSchemeButtonProps) { | ||
const { updatePreferredMode } = useColorScheme(); | ||
const tooltip = (() => { | ||
switch (mode) { | ||
case 'light': | ||
return 'Use light color mode'; | ||
case 'dark': | ||
return 'Use dark color mode'; | ||
case 'system': | ||
return `Use system color mode`; | ||
} | ||
})(); | ||
|
||
return ( | ||
<ButtonWithTooltip | ||
buttonProps={{ | ||
size: 'small', | ||
'aria-label': tooltip, | ||
onClick: () => { | ||
updatePreferredMode(mode === 'system' ? null : mode); | ||
}, | ||
sx: (theme) => ({ | ||
paddingY: 0.75, | ||
paddingX: 0.25, | ||
'& svg': { | ||
transition: theme.transitions.create('transform'), | ||
transformOrigin: 'center', | ||
}, | ||
'&:hover svg': { | ||
color: getColor(mode, theme), | ||
transform: mode === 'system' ? undefined : 'rotate(45deg)', | ||
}, | ||
}), | ||
}} | ||
tooltipProps={{ | ||
enterDelay: DELAY_MS, | ||
enterNextDelay: DELAY_MS, | ||
enterTouchDelay: DELAY_MS, | ||
title: tooltip, | ||
}} | ||
> | ||
{ICONS[mode]} | ||
</ButtonWithTooltip> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,18 @@ | ||
import { Stack, Switch, switchClasses } from '@mui/material'; | ||
import { useColorScheme } from '../theme/useColorScheme'; | ||
import { ColorSchemeIcon } from './ColorSchemeIcon'; | ||
|
||
const HEIGHT_PX = 24; | ||
const WIDTH_PX = 48; | ||
const PADDING = 0.5; | ||
const PADDING_PX = PADDING * 8; | ||
const TRACK_SIZE_PX = HEIGHT_PX - 2 * PADDING_PX; | ||
import { ButtonGroup, Stack } from '@mui/material'; | ||
import { ColorSchemeButton } from './ColorSchemeButton'; | ||
|
||
/** | ||
* Provides the ability to toggle the page's color scheme between | ||
* system, light, and dark. Prerendered, `mode` is `light`. | ||
*/ | ||
export function ColorSchemeToggle() { | ||
const { colorScheme, updatePreferredMode } = useColorScheme(); | ||
const setInvertedScheme = () => { | ||
updatePreferredMode(colorScheme.mode === 'dark' ? 'light' : 'dark'); | ||
}; | ||
|
||
return ( | ||
<Stack sx={{ flexDirection: 'row', alignItems: 'center' }}> | ||
<ColorSchemeIcon mode="light" /> | ||
<Switch | ||
aria-hidden | ||
aria-label="Change color scheme mode" | ||
checked={colorScheme.isInitialized ? colorScheme.mode === 'dark' : false} | ||
onChange={setInvertedScheme} | ||
sx={(theme) => ({ | ||
// Overrides our "animations off" for color scheme changes since we do always want the switch to animate | ||
'& *': { | ||
transition: `${theme.transitions.create('all', { | ||
duration: theme.transitions.duration.complex, | ||
})} !important`, | ||
}, | ||
height: HEIGHT_PX, | ||
width: WIDTH_PX, | ||
margin: 0, | ||
padding: 0, | ||
|
||
[`&& .${switchClasses.switchBase}`]: { | ||
cursor: colorScheme.isInitialized ? 'pointer' : 'not-allowed', | ||
margin: PADDING, | ||
padding: 0, | ||
|
||
[`&.${switchClasses.checked}`]: { | ||
transform: `translateX(${WIDTH_PX - TRACK_SIZE_PX - 2 * PADDING_PX}px)`, | ||
[`&& + .${switchClasses.track}`]: { | ||
opacity: 1, | ||
backgroundColor: colorScheme.isCustomized | ||
? theme.vars.palette.active.main | ||
: theme.vars.palette.card.border, | ||
}, | ||
}, | ||
}, | ||
[`&& .${switchClasses.input}`]: { | ||
width: WIDTH_PX * 2 + TRACK_SIZE_PX, | ||
height: HEIGHT_PX, | ||
left: -WIDTH_PX - TRACK_SIZE_PX / 2, | ||
top: -PADDING_PX, | ||
}, | ||
[`& .${switchClasses.thumb}`]: { | ||
backgroundColor: theme.vars.palette.common.white, | ||
width: TRACK_SIZE_PX, | ||
height: TRACK_SIZE_PX, | ||
}, | ||
[`&&& .${switchClasses.track}`]: { | ||
opacity: 1, | ||
backgroundColor: colorScheme.isCustomized | ||
? theme.vars.palette.active.main | ||
: theme.vars.palette.card.border, | ||
borderRadius: HEIGHT_PX / 2, | ||
transition: theme.transitions.create('background-color'), | ||
}, | ||
})} | ||
tabIndex={-1} | ||
/> | ||
<ColorSchemeIcon mode="dark" /> | ||
<ButtonGroup aria-label="outlined primary button group" size="small" variant="outlined"> | ||
<ColorSchemeButton mode="light" /> | ||
<ColorSchemeButton mode="dark" /> | ||
<ColorSchemeButton mode="system" /> | ||
</ButtonGroup> | ||
</Stack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
dffa092
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
dg – ./
dg-dgattey.vercel.app
dg.vercel.app
dylangattey.com
dg-git-main-dgattey.vercel.app