-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making ThemeSwitcher it's own component and styling
- Loading branch information
1 parent
12d49dc
commit c029457
Showing
4 changed files
with
49 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { selectAnatomy } from '@chakra-ui/anatomy' | ||
import { createMultiStyleConfigHelpers } from '@chakra-ui/react' | ||
|
||
const { definePartsStyle, defineMultiStyleConfig } = | ||
createMultiStyleConfigHelpers(selectAnatomy.keys) | ||
|
||
const variants = { | ||
themeSelect: definePartsStyle({ | ||
field: { | ||
background: '#545859', | ||
color: 'white', | ||
'& > option': { | ||
background: '#545859', | ||
color: 'white', | ||
}, | ||
fontFamily: 'var(--font-fondamento)', | ||
}, | ||
icon: { | ||
color: 'white', | ||
}, | ||
|
||
}), | ||
} | ||
|
||
export const selectTheme = defineMultiStyleConfig({ variants }) |
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 |
---|---|---|
@@ -1,58 +1,18 @@ | ||
import { ChakraProvider } from '@chakra-ui/react'; | ||
import { corporateTheme } from 'chakra/theme/corporate/theme'; | ||
import fantasyTheme from 'chakra/theme/fantasy/theme'; | ||
import { useEngageTracker } from 'components/Contexts'; | ||
import React, { FC, useState, createContext } from 'react'; | ||
import * as GTag from 'lib/GTag'; | ||
import React from 'react' | ||
import { Select, Text, Show } from '@chakra-ui/react'; | ||
import { useThemeContext } from 'components/Contexts/ThemeContext/ThemeContext'; | ||
|
||
interface ThemeSwitcherProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export const ThemeSwitcher = createContext<ThemeSwitcherType>({} as ThemeSwitcherType); | ||
|
||
export interface ThemeSwitcherType { | ||
changeTheme: (themeChoice: string) => void; | ||
currentTheme: string; | ||
} | ||
|
||
export const useThemeSwitcher = () => React.useContext(ThemeSwitcher); | ||
|
||
export const ThemeSwitcherProvider: FC<ThemeSwitcherProps> = ({ children }) => { | ||
const tracker = useEngageTracker(); | ||
|
||
const themes = { | ||
"corporate": corporateTheme, | ||
"fantasy": fantasyTheme | ||
}; | ||
export default function () { | ||
|
||
const [themeName, setThemeName] = useState<string>("corporate"); | ||
|
||
const changeTheme = async (themeChoice: string) => { | ||
await tracker.TrackEvent('THEME_CHANGE', { theme: themeChoice }); | ||
GTag.event('theme_change', 'Theme', themeChoice); | ||
|
||
setThemeName(themeChoice); | ||
} | ||
|
||
const currentTheme = () => { | ||
return themeName; | ||
} | ||
|
||
const theme = themes[themeName as keyof typeof themes]; | ||
const themeContext = useThemeContext(); | ||
|
||
return ( | ||
<ThemeSwitcher.Provider | ||
value={{ | ||
changeTheme: (themeChoice: string) => { | ||
changeTheme(themeChoice); | ||
}, | ||
currentTheme: currentTheme() | ||
}} | ||
> | ||
<ChakraProvider theme={theme}> | ||
{children} | ||
</ChakraProvider> | ||
</ThemeSwitcher.Provider> | ||
); | ||
}; | ||
<> | ||
<Select variant={'themeSelect'} mt={2} size={{base: 'sm', lg: "md"}} onChange={(event) => themeContext.changeTheme(event.target.selectedOptions[0].value)}> | ||
<option selected hidden disabled value="">Theme</option> | ||
<option value='corporate'>Corporate</option> | ||
<option value='fantasy'>👑 Fantasy</option> | ||
</Select> | ||
</> | ||
) | ||
} |