-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add different layout presentations
- Loading branch information
Showing
14 changed files
with
270 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,42 @@ | ||
import { FC, PropsWithChildren } from 'react'; | ||
import { QueryClientProvider, QueryClientProviderProps } from 'react-query'; | ||
import { MemoryRouter, Route, Routes } from 'react-router-dom'; | ||
import { WidgetConfig } from '.'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { AppProps, AppProvider } from './AppProvider'; | ||
import { AppContainer } from './components/AppContainer'; | ||
import { Header } from './components/Header'; | ||
import { queryClient } from './config/queryClient'; | ||
import { MainPage } from './pages/MainPage'; | ||
import { SelectTokenPage } from './pages/SelectTokenPage'; | ||
import { SelectWalletPage } from './pages/SelectWalletPage'; | ||
import { SettingsPage } from './pages/SettingsPage'; | ||
import { SwapPage } from './pages/SwapPage'; | ||
import { SwapRoutesPage } from './pages/SwapRoutesPage'; | ||
import { SwapFormProvider } from './providers/SwapFormProvider'; | ||
import { ThemeProvider } from './providers/ThemeProvider'; | ||
import { WalletProvider } from './providers/WalletProvider'; | ||
import { WidgetProvider } from './providers/WidgetProvider'; | ||
import { routes } from './utils/routes'; | ||
|
||
interface AppProps { | ||
config: WidgetConfig; | ||
} | ||
|
||
const QueryProvider = QueryClientProvider as FC< | ||
PropsWithChildren<QueryClientProviderProps> | ||
>; | ||
|
||
export const App: React.FC<AppProps> = ({ config }) => { | ||
return ( | ||
<WidgetProvider config={config}> | ||
<ThemeProvider> | ||
<QueryProvider client={queryClient}> | ||
<MemoryRouter> | ||
<WalletProvider> | ||
<SwapFormProvider> | ||
<AppContainer | ||
sx={config.containerStyle} | ||
style={config.baselineStyle} | ||
> | ||
<Header /> | ||
<Routes> | ||
<Route path={routes.home} element={<MainPage />} /> | ||
<Route | ||
path={routes.selectWallet} | ||
element={<SelectWalletPage />} | ||
/> | ||
<Route path={routes.settings} element={<SettingsPage />} /> | ||
<Route | ||
path={routes.fromToken} | ||
element={<SelectTokenPage formType="from" />} | ||
/> | ||
<Route | ||
path={routes.toToken} | ||
element={<SelectTokenPage formType="to" />} | ||
/> | ||
<Route | ||
path={routes.swapRoutes} | ||
element={<SwapRoutesPage />} | ||
/> | ||
<Route path={routes.swap} element={<SwapPage />} /> | ||
</Routes> | ||
</AppContainer> | ||
</SwapFormProvider> | ||
</WalletProvider> | ||
</MemoryRouter> | ||
</QueryProvider> | ||
</ThemeProvider> | ||
</WidgetProvider> | ||
<AppProvider config={config}> | ||
<AppDefault /> | ||
</AppProvider> | ||
); | ||
}; | ||
|
||
export const AppDefault = () => { | ||
return ( | ||
<AppContainer> | ||
<Header /> | ||
<Routes> | ||
<Route path={routes.home} element={<MainPage />} /> | ||
<Route path={routes.selectWallet} element={<SelectWalletPage />} /> | ||
<Route path={routes.settings} element={<SettingsPage />} /> | ||
<Route | ||
path={routes.fromToken} | ||
element={<SelectTokenPage formType="from" />} | ||
/> | ||
<Route | ||
path={routes.toToken} | ||
element={<SelectTokenPage formType="to" />} | ||
/> | ||
<Route path={routes.swapRoutes} element={<SwapRoutesPage />} /> | ||
<Route path={routes.swap} element={<SwapPage />} /> | ||
</Routes> | ||
</AppContainer> | ||
); | ||
}; |
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,59 @@ | ||
import { Button, Typography } from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
|
||
export const DrawerButton = styled(Button, { | ||
shouldForwardProp: (prop) => prop !== 'open', | ||
})<{ open?: boolean }>(({ theme, open }) => ({ | ||
background: | ||
theme.palette.mode === 'light' | ||
? theme.palette.common.black | ||
: theme.palette.common.white, | ||
color: | ||
theme.palette.mode === 'light' | ||
? theme.palette.common.white | ||
: theme.palette.common.black, | ||
alignItems: 'center', | ||
borderRadius: `${theme.shape.borderRadius}px 0 0 ${theme.shape.borderRadius}px`, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
height: 148, | ||
justifyContent: 'center', | ||
minWidth: 40, | ||
padding: theme.spacing(1, 0, 1, 0), | ||
position: 'absolute', | ||
right: 0, | ||
top: 'calc(50% - 74px)', | ||
transform: `translate3d(calc(${open ? '392px' : '0px'} * -1), 0, 0)`, | ||
transition: theme.transitions.create(['transform'], { | ||
duration: theme.transitions.duration.enteringScreen, | ||
easing: theme.transitions.easing.easeOut, | ||
}), | ||
zIndex: 1500, | ||
'&:hover': { | ||
background: | ||
theme.palette.mode === 'light' | ||
? theme.palette.common.black | ||
: theme.palette.common.white, | ||
}, | ||
})); | ||
|
||
export const DrawerButtonTypography = styled(Typography)(({ theme }) => ({ | ||
borderRadius: `0 ${theme.shape.borderRadius}px ${theme.shape.borderRadius}px 0`, | ||
background: | ||
theme.palette.mode === 'light' | ||
? theme.palette.common.black | ||
: theme.palette.common.white, | ||
color: | ||
theme.palette.mode === 'light' | ||
? theme.palette.common.white | ||
: theme.palette.common.black, | ||
cursor: 'pointer', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
fontSize: '18px', | ||
padding: theme.spacing(1), | ||
position: 'relative', | ||
textTransform: 'none', | ||
transform: 'rotateZ(180deg)', | ||
writingMode: 'vertical-rl', | ||
})); |
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,92 @@ | ||
import { | ||
KeyboardArrowLeft as KeyboardArrowLeftIcon, | ||
KeyboardArrowRight as KeyboardArrowRightIcon, | ||
} from '@mui/icons-material'; | ||
import { Drawer, DrawerProps } from '@mui/material'; | ||
import { | ||
forwardRef, | ||
RefObject, | ||
useCallback, | ||
useImperativeHandle, | ||
useRef, | ||
useState, | ||
} from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { AppDefault } from './App'; | ||
import { DrawerButton, DrawerButtonTypography } from './AppDrawer.style'; | ||
import { AppProvider } from './AppProvider'; | ||
import { WidgetConfig } from './types'; | ||
|
||
export type AppDrawerProps = DrawerProps & { | ||
elementRef?: RefObject<HTMLDivElement>; | ||
config: WidgetConfig; | ||
}; | ||
|
||
export interface AppDrawerBase { | ||
isOpen(): void; | ||
toggleDrawer(): void; | ||
openDrawer(): void; | ||
closeDrawer(): void; | ||
} | ||
|
||
export const AppDrawer = forwardRef<AppDrawerBase, AppDrawerProps>( | ||
({ elementRef, open, config }, ref) => { | ||
const { t } = useTranslation(); | ||
const openRef = useRef(open); | ||
const [drawerOpen, setDrawerOpen] = useState(open); | ||
|
||
const toggleDrawer = useCallback(() => { | ||
setDrawerOpen((open) => !open); | ||
}, []); | ||
|
||
const openDrawer = useCallback(() => { | ||
setDrawerOpen(true); | ||
}, []); | ||
|
||
const closeDrawer = useCallback(() => { | ||
setDrawerOpen(false); | ||
}, []); | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
isOpen: () => openRef.current, | ||
toggleDrawer, | ||
openDrawer, | ||
closeDrawer, | ||
}), | ||
[closeDrawer, openDrawer, toggleDrawer], | ||
); | ||
|
||
return ( | ||
<AppProvider config={config}> | ||
<DrawerButton | ||
variant="contained" | ||
onClick={toggleDrawer} | ||
open={drawerOpen} | ||
disableElevation | ||
> | ||
{drawerOpen ? <KeyboardArrowRightIcon /> : <KeyboardArrowLeftIcon />} | ||
<DrawerButtonTypography> | ||
{drawerOpen ? t('button.hide') : t('button.lifiSwap')} | ||
</DrawerButtonTypography> | ||
</DrawerButton> | ||
<Drawer | ||
ref={elementRef} | ||
anchor="right" | ||
open={drawerOpen} | ||
onClose={closeDrawer} | ||
BackdropProps={{ | ||
sx: { | ||
backgroundColor: 'rgb(0 0 0 / 48%)', | ||
backdropFilter: 'blur(3px)', | ||
}, | ||
}} | ||
keepMounted | ||
> | ||
<AppDefault /> | ||
</Drawer> | ||
</AppProvider> | ||
); | ||
}, | ||
); |
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,36 @@ | ||
import { FC, PropsWithChildren } from 'react'; | ||
import { QueryClientProvider, QueryClientProviderProps } from 'react-query'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { WidgetConfig } from '.'; | ||
import { queryClient } from './config/queryClient'; | ||
import { SwapFormProvider } from './providers/SwapFormProvider'; | ||
import { ThemeProvider } from './providers/ThemeProvider'; | ||
import { WalletProvider } from './providers/WalletProvider'; | ||
import { WidgetProvider } from './providers/WidgetProvider'; | ||
|
||
export interface AppProps { | ||
config: WidgetConfig; | ||
} | ||
|
||
const QueryProvider = QueryClientProvider as FC< | ||
PropsWithChildren<QueryClientProviderProps> | ||
>; | ||
|
||
export const AppProvider: React.FC<PropsWithChildren<AppProps>> = ({ | ||
children, | ||
config, | ||
}) => { | ||
return ( | ||
<WidgetProvider config={config}> | ||
<ThemeProvider> | ||
<QueryProvider client={queryClient}> | ||
<MemoryRouter> | ||
<WalletProvider> | ||
<SwapFormProvider>{children}</SwapFormProvider> | ||
</WalletProvider> | ||
</MemoryRouter> | ||
</QueryProvider> | ||
</ThemeProvider> | ||
</WidgetProvider> | ||
); | ||
}; |
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.