-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0585f7
commit a6f2f34
Showing
22 changed files
with
368 additions
and
174 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
1 change: 1 addition & 0 deletions
1
packages/curve-common/src/features/switch-advanced-mode/index.ts
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 @@ | ||
export * from './AdvancedModeSwitcher' |
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
32 changes: 0 additions & 32 deletions
32
packages/curve-common/src/features/switch-theme/ThemeSwitcher.tsx
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
packages/curve-common/src/features/switch-theme/ThemeSwitcherButton.tsx
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,30 @@ | ||
import { FunctionComponent } from 'react' | ||
import type { Theme } from '@mui/system' | ||
import { type ThemeSwitcherProps } from './types' | ||
import { Button } from 'curve-ui-kit/src/shared/ui/Button' | ||
import { Box } from 'curve-ui-kit/src/shared/ui/Box' | ||
import { t } from '@lingui/macro' | ||
import { useThemeToggle } from './useThemeToggle' | ||
|
||
export const ThemeSwitcherButton: FunctionComponent<ThemeSwitcherProps> = ({ theme, onChange }) => { | ||
const [ component, onClick ] = useThemeToggle({ theme, onChange }) | ||
const Icon = ( | ||
<Box sx={{ minWidth: 38 }}> | ||
{component} | ||
</Box> | ||
) | ||
return ( | ||
<Button | ||
onClick={onClick} | ||
endIcon={Icon} | ||
variant="ghost" | ||
color="secondary" | ||
sx={{ | ||
fill: (t: Theme) => t.palette.text.secondary, | ||
'&:hover': {fill: (t: Theme) => t.palette.primary.contrastText}, | ||
}} | ||
> | ||
{t`Mode`} | ||
</Button> | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/curve-common/src/features/switch-theme/ThemeSwitcherIconButton.tsx
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,14 @@ | ||
import type { FunctionComponent } from 'react' | ||
import type { Theme } from '@mui/system' | ||
import IconButton from '@mui/material/IconButton' | ||
import { ThemeSwitcherProps } from './types' | ||
import { useThemeToggle } from './useThemeToggle' | ||
|
||
export const ThemeSwitcherIconButton: FunctionComponent<ThemeSwitcherProps> = ({ theme, onChange }) => { | ||
const [ component, onClick ] = useThemeToggle({ theme, onChange }) | ||
return ( | ||
<IconButton onClick={onClick} sx={{minWidth: 38, fill: (t: Theme) => t.palette.primary.main}}> | ||
{component} | ||
</IconButton> | ||
) | ||
} |
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,3 @@ | ||
export * from './types' | ||
export * from './ThemeSwitcherButton' | ||
export * from './ThemeSwitcherIconButton' |
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,14 @@ | ||
import { ChadImg, RCMoon, RCSun } from 'ui' | ||
import Image from 'next/image' | ||
import type { ThemeKey } from 'curve-ui-kit/src/shared/lib' | ||
|
||
export const themes = [ | ||
{ type: 'light', Component: <RCSun aria-label="Light theme" /> }, | ||
{ type: 'dark', Component: <RCMoon aria-label="Dark theme" /> }, | ||
{ type: 'chad', Component: <Image width={24} src={ChadImg} alt="Fun theme" /> }, | ||
] as const | ||
|
||
export type ThemeSwitcherProps = { | ||
theme: ThemeKey | ||
onChange(themeType: ThemeKey): void | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/curve-common/src/features/switch-theme/useThemeToggle.tsx
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,12 @@ | ||
import { themes, ThemeSwitcherProps } from './types' | ||
import { useCallback } from 'react' | ||
|
||
export function useThemeToggle({theme, onChange}: ThemeSwitcherProps) { | ||
const i = themes.findIndex((t) => t.type === theme) | ||
const themeIndex = i === -1 ? 0 : i | ||
const onClick = useCallback(() => { | ||
const nextIndex = (themeIndex + 1) % themes.length | ||
onChange(themes[nextIndex].type) | ||
}, [themeIndex, onChange]) | ||
return [ themes[themeIndex]!.Component, onClick ] as const | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/curve-common/src/widgets/Header/DesktopHeader.tsx
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,37 @@ | ||
import { AppBar, Toolbar } from '@mui/material' | ||
import Box from '@mui/material/Box' | ||
import { ConnectWalletIndicator } from '../../features/connect-wallet' | ||
import { LanguageSwitcher } from '../../features/switch-language' | ||
import { ChainSwitcher } from '../../features/switch-chain' | ||
import { AppButtonLinks } from './AppButtonLinks' | ||
import { HeaderLogo } from './HeaderLogo' | ||
import { HeaderStats } from './HeaderStats' | ||
import { PageTabs } from './PageTabs' | ||
import { Theme } from '@mui/system' | ||
import { ThemeSwitcherIconButton } from '../../features/switch-theme' | ||
import { AdvancedModeSwitcher } from '../../features/switch-advanced-mode' | ||
import { BaseHeaderProps, toolbarColors } from './types' | ||
|
||
export const DesktopHeader = <TChainId extends number>({ currentApp, chains, languages, wallet, pages, appStats, themes: [theme, setTheme], sections, advancedMode: [isAdvancedMode, setAdvancedMode] }: BaseHeaderProps<TChainId>) => ( | ||
<AppBar color="transparent" position="relative"> | ||
<Toolbar sx={{ backgroundColor: (t: Theme) => toolbarColors[t.palette.mode][0] }}> | ||
<HeaderLogo appName={currentApp} /> | ||
<AppButtonLinks currentApp="lend" /> | ||
|
||
<Box sx={{ flexGrow: 1 }} /> | ||
|
||
<Box display="flex" marginLeft={2} justifyContent="flex-end" gap={3}> | ||
<AdvancedModeSwitcher advancedMode={isAdvancedMode} onChange={setAdvancedMode} /> | ||
<LanguageSwitcher {...languages} /> | ||
<ThemeSwitcherIconButton theme={theme} onChange={setTheme} /> | ||
<ChainSwitcher {...chains} /> | ||
<ConnectWalletIndicator {...wallet} /> | ||
</Box> | ||
</Toolbar> | ||
<Toolbar sx={{ backgroundColor: (t: Theme) => toolbarColors[t.palette.mode][1] }}> | ||
<PageTabs pages={pages} /> | ||
<Box flexGrow={1} /> | ||
<HeaderStats appStats={appStats} /> | ||
</Toolbar> | ||
</AppBar> | ||
); |
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,82 +1,6 @@ | ||
import { AppBar, Toolbar } from '@mui/material' | ||
import Box from '@mui/material/Box' | ||
import type { AppName, AppNavSections, AppPage } from 'ui/src/AppNav/types' | ||
import { ConnectWalletIndicator, ConnectWalletIndicatorProps } from '../../features/connect-wallet' | ||
import { LanguageSwitcher, LanguageSwitcherProps } from '../../features/switch-language' | ||
import { ChainSwitcher, ChainSwitcherProps } from '../../features/switch-chain' | ||
import { AppButtonLinks } from './AppButtonLinks' | ||
import { Dispatch } from 'react' | ||
import { ThemeKey } from 'curve-ui-kit/src/shared/lib' | ||
import { HeaderLogo } from './HeaderLogo' | ||
import { HeaderStats } from './HeaderStats' | ||
import { PageTabs } from './PageTabs' | ||
import { Theme } from '@mui/system' | ||
import { ThemeSwitcher } from '../../features/switch-theme/ThemeSwitcher' | ||
import { AdvancedModeSwitcher } from '../../features/switch-advanced-mode/AdvancedModeSwitcher' | ||
import { HeaderProps } from './types' | ||
import { DesktopHeader } from './DesktopHeader' | ||
import { MobileHeader } from './MobileHeader' | ||
|
||
interface HeaderProps<TChainId> { | ||
currentApp: AppName | ||
languages: LanguageSwitcherProps | ||
chains: ChainSwitcherProps<TChainId> | ||
wallet: ConnectWalletIndicatorProps | ||
pages: AppPage[] | ||
themes: [ThemeKey, Dispatch<ThemeKey>] | ||
appStats: {label: string, value: string}[] | ||
sections: AppNavSections | ||
advancedMode: [boolean, Dispatch<boolean>] | ||
isMdUp: boolean | ||
} | ||
|
||
const APP_NAMES = { | ||
main: "Curve", | ||
lend: "Llamalend", | ||
crvusd: "crvUSD", | ||
} as const | ||
|
||
// TODO: Color should be in theme | ||
const toolbarColors = { | ||
light: ['#eeeceb', '#f4f3f0'], | ||
dark: ['#1f1f1f', '#2f2f2f'], // todo | ||
} as const | ||
|
||
|
||
export const Header = <TChainId extends number>({ currentApp, chains, languages, wallet, pages, appStats, themes: [theme, setTheme], sections, advancedMode: [isAdvancedMode, setAdvancedMode], isMdUp }: HeaderProps<TChainId>) => { | ||
return ( | ||
<AppBar color="transparent" position={"relative"}> | ||
<Toolbar sx={{ backgroundColor: (t: Theme) => toolbarColors[t.palette.mode][0] }}> | ||
{/*{*/} | ||
{/* !isMdUp && (*/} | ||
{/* <IconButton*/} | ||
{/* onClick={onOpenSidebar}*/} | ||
{/* sx={{*/} | ||
{/* display: {*/} | ||
{/* xs: 'inline-flex',*/} | ||
{/* lg: 'none',*/} | ||
{/* },*/} | ||
{/* }}*/} | ||
{/* data-testid={createTestId('dashboard-menu-trigger')}*/} | ||
{/* >*/} | ||
{/* <MenuIcon fontSize="small" />*/} | ||
{/* </IconButton>*/} | ||
{/*}*/} | ||
<HeaderLogo appName={APP_NAMES[currentApp]} /> | ||
{isMdUp && <AppButtonLinks currentApp="lend" />} | ||
|
||
<Box sx={{ flexGrow: 1 }} /> | ||
|
||
<Box display="flex" marginLeft={2} justifyContent="flex-end" gap={3}> | ||
<AdvancedModeSwitcher advancedMode={isAdvancedMode} onChange={setAdvancedMode} /> | ||
<LanguageSwitcher {...languages} /> | ||
<ThemeSwitcher theme={theme} onChange={setTheme} /> | ||
<ChainSwitcher {...chains} /> | ||
<ConnectWalletIndicator {...wallet} /> | ||
</Box> | ||
</Toolbar> | ||
<Toolbar sx={{ backgroundColor: (t: Theme) => toolbarColors[t.palette.mode][1] }}> | ||
<PageTabs pages={pages} /> | ||
<Box flexGrow={1} /> | ||
<HeaderStats appStats={appStats} /> | ||
</Toolbar> | ||
</AppBar> | ||
); | ||
}; | ||
export const Header = <TChainId extends number>({ isMdUp, ...props }: HeaderProps<TChainId>) => isMdUp ? | ||
<DesktopHeader {...props} /> : <MobileHeader {...props} />; |
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.