Skip to content

Commit

Permalink
feat: refactor modal
Browse files Browse the repository at this point in the history
  • Loading branch information
jimcase committed Aug 28, 2023
1 parent 6bdc9f5 commit 5c8be9d
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 130 deletions.
33 changes: 16 additions & 17 deletions ui/summit-2023/src/common/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@ import componentsOverride from './overrides';
import { createBreakpoints } from '@mui/system';

declare module '@mui/material/styles' {
interface BreakpointOverrides {
xxl: true;
}
interface BreakpointOverrides {
xxl: true;
}
}
const breakpoints = createBreakpoints({ values: { xs: 0, sm: 600, md: 960, lg: 1280, xl: 1920, xxl: 2160 } });

const theme = createTheme({
palette: {
primary: {
main: '#03021F',
},
secondary: {
main: '#F5F9FF',
},
error: {
main: '#C20024',
},
},
breakpoints,
}
);
palette: {
primary: {
main: '#03021F',
},
secondary: {
main: '#F5F9FF',
},
error: {
main: '#C20024',
},
},
breakpoints,
});

theme.components = componentsOverride(theme);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { Avatar, List, ListItem, ListItemAvatar, Typography } from '@mui/material';
import { useCardano } from '@cardano-foundation/cardano-connect-with-wallet';
import './ConnectWalletList.scss';
import { walletIcon } from '../../utils/utils';

type ConnectWalletModalProps = {
description: string;
onConnectWallet: () => void;
onConnectError: () => void;
};

// TODO: move to .env file
// TODO: handle mobile support. Flint
const SUPPORTED_WALLETS = ['flint', 'nami', 'eternl', 'typhon', 'yoroi', 'nufi'];

const ConnectWalletList = (props: ConnectWalletModalProps) => {
const { description, onConnectWallet, onConnectError } = props;
const { installedExtensions, connect } = useCardano();

const availableWallets = installedExtensions.filter((installedWallet) => SUPPORTED_WALLETS.includes(installedWallet));

return (
<>
<Typography
className="connect-wallet-modal-description"
gutterBottom
style={{ wordWrap: 'break-word' }}
>
{description}
</Typography>
<List>
{availableWallets.map((walletName, index) => (
<ListItem
key={index}
className="walletItem"
onClick={() => connect(walletName, onConnectWallet, onConnectError)}
>
<ListItemAvatar>
<Avatar
src={walletIcon(walletName)}
style={{ width: '24px', height: '24px' }}
/>
</ListItemAvatar>
<Typography className="walletLabel">
Connect <span className="walletName">{walletName}</span> wallet
</Typography>
</ListItem>
))}
</List>
</>
);
};

export default ConnectWalletList;

This file was deleted.

7 changes: 2 additions & 5 deletions ui/summit-2023/src/components/Hero/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const Hero: React.FC = () => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));

const containerStyles = isMobile
? { padding: '100px 40px', display: 'flex', height: '80vh', alignItems: 'center' }
: { padding: '10px 20px', width: '90%', margin: '0 auto', display: 'flex', height: '80vh', alignItems: 'center' };

const handleOpenModal = () => {
setModalOpen(true);
};
Expand All @@ -28,7 +24,8 @@ const Hero: React.FC = () => {
display: 'flex',
flexDirection: { xs: 'column', sm: 'row' },
height: { xs: 'auto', sm: '400px' },
marginLeft: isMobile ? '0px' : '50px',
marginLeft: isMobile ? '0px' : '150px',
marginTop: isMobile ? '0px' : '50px',
}}
>
<Box
Expand Down
25 changes: 14 additions & 11 deletions ui/summit-2023/src/components/common/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline';
import DoNotDisturbAltIcon from '@mui/icons-material/DoNotDisturbAlt';
import './Header.scss';
import { i18n } from '../../../i18n';
import ConnectWalletModal from '../../ConnectWalletModal/ConnectWalletModal';
import { useCardano } from '@cardano-foundation/cardano-connect-with-wallet';
import { addressSlice, walletIcon } from '../../../utils/utils';
import Modal from '../Modal/Modal';
import ConnectWalletList from '../../ConnectWalletList/ConnectWalletList';

const Header: React.FC = () => {
const [drawerOpen, setDrawerOpen] = useState(false);
Expand Down Expand Up @@ -233,17 +234,19 @@ const Header: React.FC = () => {
{drawerItems}
</Drawer>

<ConnectWalletModal
openStatus={openAuthDialog}
<Modal
id='connect-wallet-modal'
isOpen={openAuthDialog}
name='connect-wallet-modal'
title='Connect wallet'
onClose={handleCloseAuthDialog}
onConnectError={onConnectWalletError}
name="connect-wallet-list"
id="connect-wallet-list"
title="Connect wallet"
description="In order to vote, first you will need to connect your wallet."
onConnectWallet={onConnectWallet}
/>

>
<ConnectWalletList
description='In order to vote, first you will need to connect your wallet.'
onConnectWallet={onConnectWallet}
onConnectError={onConnectWalletError}
/>
</Modal>
<Snackbar
className={`header-toast ${toastIsError ? 'header-toast-error' : ''}`}
open={toastOpen}
Expand Down
27 changes: 27 additions & 0 deletions ui/summit-2023/src/components/common/Modal/Modal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@import './src/common/styles/colors';

.closeButton.MuiButtonBase-root {
background-color: var(--color-ultra-light-blue);
}

.closeButton.MuiButtonBase-root:hover {
background-color: var(--color-ultra-light-blue);
opacity: 0.9;
}

.modal-title {
color: var(--color-ultra-dark-blue);
font-size: 28px !important;
font-style: normal;
font-weight: 600 !important;
line-height: normal;
float: left;
}

.modal-description {
color: var(--color-medium-grey);
font-size: 16px !important;
font-style: normal;
font-weight: 400 !important;
line-height: 22px;
}
59 changes: 59 additions & 0 deletions ui/summit-2023/src/components/common/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import Dialog from '@mui/material/Dialog';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import { IconButton, Typography } from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';
import Paper from '@mui/material/Paper';
import './Modal.scss';

const StyledPaper = (props: any) => {
return (
<Paper
{...props}
style={{ borderRadius: '16px' }}
/>
);
};

type ModalProps = {
name: string;
id: string;
isOpen: boolean;
title: string;
width?: string;
onClose: () => void;
children: React.ReactNode;
};

const Modal = (props: ModalProps) => {
const { name, id, isOpen, title, width, onClose } = props;

return (
<Dialog
open={isOpen}
onClose={onClose}
aria-labelledby={name}
maxWidth='sm'
PaperComponent={StyledPaper}
>
<DialogTitle
id={id}
style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}
>
<Typography className='modal-title'>{title}</Typography>
<IconButton
className='closeButton'
edge='end'
color='inherit'
onClick={onClose}
>
<CloseIcon />
</IconButton>
</DialogTitle>
<DialogContent style={{ width: width || '400px' }}>{props.children}</DialogContent>
</Dialog>
);
};

export default Modal;
2 changes: 1 addition & 1 deletion ui/summit-2023/src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useMediaQuery, useTheme } from '@mui/material';
const Home = () => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
const isLarger = useMediaQuery('(min-width:1921px)');
const isLarger = useMediaQuery(theme.breakpoints.up('xxl'));

return (
<>
Expand Down

0 comments on commit 5c8be9d

Please sign in to comment.