feat: design my apps along with app layout

This commit is contained in:
Ali BARIN
2021-12-14 00:43:35 +01:00
committed by Ömer Faruk Aydın
parent 3785c705ff
commit 6da8557219
13 changed files with 156 additions and 113 deletions

View File

@@ -1,19 +1,27 @@
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import MuiAppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import IconButton from '@mui/material/IconButton';
import Typography from '@mui/material/Typography';
import MenuIcon from '@mui/icons-material/Menu';
import MenuOpenIcon from '@mui/icons-material/MenuOpen';
import SettingsIcon from '@mui/icons-material/Settings';
import HideOnScroll from 'components/HideOnScroll';
import { FormattedMessage } from 'react-intl';
type AppBarProps = {
onMenuClick: () => void;
drawerOpen: boolean;
onDrawerOpen: () => void;
onDrawerClose: () => void;
};
export default function AppBar({ onMenuClick }: AppBarProps) {
export default function AppBar({ drawerOpen, onDrawerOpen, onDrawerClose }: AppBarProps) {
const theme = useTheme();
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'), { noSsr: true });
return (
<Box sx={{ flexGrow: 1 }}>
<HideOnScroll>
@@ -24,17 +32,17 @@ export default function AppBar({ onMenuClick }: AppBarProps) {
edge="start"
color="inherit"
aria-label="open drawer"
onClick={onMenuClick}
onClick={drawerOpen ? onDrawerClose : onDrawerOpen}
sx={{ mr: 2 }}
>
<MenuIcon />
{drawerOpen && matchSmallScreens ? <MenuOpenIcon /> : <MenuIcon />}
</IconButton>
<Typography
variant="h6"
noWrap
component="div"
sx={{ flexGrow: 1, display: { xs: 'none', sm: 'block' } }}
sx={{ flexGrow: 1 }}
>
<FormattedMessage id="brandText" />
</Typography>

View File

@@ -6,17 +6,13 @@ import CardActionArea from '@mui/material/CardActionArea';
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
import * as URLS from 'config/urls';
import useFormatMessage from 'hooks/useFormatMessage';
import { CardContent, Typography } from './style';
type AppFlowRowProps = {
flow: any;
}
const countTranslation = (value: React.ReactNode) => (<><strong>{value}</strong><br /></>);
function AppFlowRow(props: AppFlowRowProps) {
const formatMessage = useFormatMessage();
const { flow } = props;
return (

View File

@@ -29,7 +29,7 @@ function AppRow(props: AppRowProps) {
return (
<Link to={URLS.APP(name.toLowerCase())}>
<Card sx={{ my: 2 }}>
<Card sx={{ mb: 1 }}>
<CardActionArea>
<CardContent>
<Box>
@@ -43,13 +43,13 @@ function AppRow(props: AppRowProps) {
</Box>
<Box sx={{ px: 2 }}>
<Typography variant="caption" color="textSecondary">
<Typography variant="caption" color="textSecondary" sx={{ display: ['none', 'inline-block'] }}>
{formatMessage('app.connectionCount', { count: countTranslation(connectionCount) })}
</Typography>
</Box>
<Box sx={{ px: 2 }}>
<Typography variant="caption" color="textSecondary">
<Typography variant="caption" color="textSecondary" sx={{ display: ['none', 'inline-block'] }}>
{formatMessage('app.flowCount', { count: countTranslation(0) })}
</Typography>
</Box>

View File

@@ -0,0 +1,30 @@
import * as React from 'react';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import Button from '@mui/material/Button';
import { IconButton } from './style';
export default function ConditionalIconButton(props: any) {
const { Icon, ...buttonProps } = props;
const theme = useTheme();
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'), { noSsr: true });
if (matchSmallScreens) {
return (
<IconButton
color={buttonProps.color}
type={buttonProps.type}
size={buttonProps.size}
component={buttonProps.component}
to={buttonProps.to}
>
<Icon />
</IconButton>
)
}
return (
<Button {...buttonProps} />
);
}

View File

@@ -0,0 +1,13 @@
import { styled } from '@mui/material/styles';
import MuiIconButton, { iconButtonClasses } from '@mui/material/IconButton';
export const IconButton = styled(MuiIconButton)`
&.${iconButtonClasses.colorPrimary} {
background: ${({ theme }) => theme.palette.primary.main};
color: ${({ theme }) => theme.palette.primary.contrastText};
&:hover {
background: ${({ theme }) => theme.palette.primary.dark};
}
}
` as typeof MuiIconButton;

View File

@@ -19,7 +19,7 @@ const iOS = typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigato
export default function Drawer(props: SwipeableDrawerProps) {
const theme = useTheme();
const matchesSmallScreens = useMediaQuery(theme.breakpoints.down('md'));
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'), { noSsr: true });
const formatMessage = useFormatMessage();
return (
@@ -27,13 +27,13 @@ export default function Drawer(props: SwipeableDrawerProps) {
{...props}
disableBackdropTransition={!iOS}
disableDiscovery={iOS}
variant={matchesSmallScreens ? 'temporary' : 'permanent'}
variant={matchSmallScreens ? 'temporary' : 'permanent'}
>
<HideOnScroll unmountOnExit>
<Toolbar />
</HideOnScroll>
<List>
<List sx={{ py: 0, mt: 3 }}>
<ListItemLink
icon={<SwapCallsIcon htmlColor={theme.palette.primary.main} />}
primary={formatMessage('drawer.flows')}

View File

@@ -1,4 +1,7 @@
import { useState, useCallback } from 'react';
import { useState } from 'react';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import Box from '@mui/material/Box';
import AppBar from 'components/AppBar';
import Drawer from 'components/Drawer';
@@ -9,18 +12,22 @@ type LayoutProps = {
}
export default function Layout({ children }: LayoutProps) {
const [isDrawerOpen, setDrawerOpen] = useState(true);
const onMenuClick = useCallback(() => { setDrawerOpen(value => !value) }, []);
const theme = useTheme();
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('lg'), { noSsr: true });
const [isDrawerOpen, setDrawerOpen] = useState(!matchSmallScreens);
const openDrawer = () => setDrawerOpen(true);
const closeDrawer = () => setDrawerOpen(false);
return (
<>
<AppBar onMenuClick={onMenuClick} />
<AppBar drawerOpen={isDrawerOpen} onDrawerOpen={openDrawer} onDrawerClose={closeDrawer} />
<Box sx={{ display: 'flex', }}>
<Drawer
open={isDrawerOpen}
onOpen={onMenuClick}
onClose={onMenuClick}
onOpen={openDrawer}
onClose={closeDrawer}
/>
<Box sx={{ flex: 1 }}>

View File

@@ -1,7 +1,10 @@
import InputLabel from '@mui/material/InputLabel';
import OutlinedInput from '@mui/material/OutlinedInput';
import InputAdornment from '@mui/material/InputAdornment';
import FormControl from '@mui/material/FormControl';
import SearchIcon from '@mui/icons-material/Search';
import useFormatMessage from 'hooks/useFormatMessage';
import { Search, SearchIconWrapper, InputBase } from './style';
type SearchInputProps = {
onChange?: (event: React.ChangeEvent) => void;
@@ -11,16 +14,26 @@ export default function SearchInput({ onChange }: SearchInputProps) {
const formatMessage = useFormatMessage();
return (
<Search>
<SearchIconWrapper>
<SearchIcon />
</SearchIconWrapper>
<FormControl variant="outlined" fullWidth>
<InputLabel
htmlFor="search-input"
>
{formatMessage('searchPlaceholder')}
</InputLabel>
<InputBase
placeholder={formatMessage('searchPlaceholder')}
inputProps={{ 'aria-label': 'search' }}
<OutlinedInput
id="search-input"
type="text"
size="medium"
fullWidth
onChange={onChange}
endAdornment={
<InputAdornment position="end">
<SearchIcon sx={{ color: (theme) => theme.palette.primary.main }} />
</InputAdornment>
}
label={formatMessage('searchPlaceholder')}
/>
</Search>
</FormControl>
);
}

View File

@@ -1,48 +0,0 @@
import { styled, alpha } from '@mui/material/styles';
import MuiInput from '@mui/material/Input';
export const Search = styled('div')(({ theme }) => ({
position: 'relative',
borderRadius: theme.shape.borderRadius,
backgroundColor: alpha(theme.palette.common.white, 0.15),
'&:hover': {
backgroundColor: alpha(theme.palette.common.white, 0.25),
},
marginLeft: 0,
width: '100%',
maxWidth: '100%',
[theme.breakpoints.up('sm')]: {
marginLeft: theme.spacing(1),
width: 'auto',
},
}));
export const SearchIconWrapper = styled('div')(({ theme }) => ({
padding: theme.spacing(0, 2),
height: '100%',
position: 'absolute',
pointerEvents: 'none',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}));
export const InputBase = styled(MuiInput)(({ theme }) => ({
color: 'inherit',
width: '100%',
fontWeight: 400,
maxWidth: '100%',
'& .MuiInput-input': {
padding: theme.spacing(1, 1, 1, 0),
// vertical padding + font size from searchIcon
paddingLeft: `calc(1em + ${theme.spacing(4)})`,
transition: theme.transitions.create('width'),
width: '200',
[theme.breakpoints.up('sm')]: {
width: '12ch',
'&:focus': {
width: '20ch',
},
},
},
}));