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

View File

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

View File

@@ -29,7 +29,7 @@ function AppRow(props: AppRowProps) {
return ( return (
<Link to={URLS.APP(name.toLowerCase())}> <Link to={URLS.APP(name.toLowerCase())}>
<Card sx={{ my: 2 }}> <Card sx={{ mb: 1 }}>
<CardActionArea> <CardActionArea>
<CardContent> <CardContent>
<Box> <Box>
@@ -43,13 +43,13 @@ function AppRow(props: AppRowProps) {
</Box> </Box>
<Box sx={{ px: 2 }}> <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) })} {formatMessage('app.connectionCount', { count: countTranslation(connectionCount) })}
</Typography> </Typography>
</Box> </Box>
<Box sx={{ px: 2 }}> <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) })} {formatMessage('app.flowCount', { count: countTranslation(0) })}
</Typography> </Typography>
</Box> </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) { export default function Drawer(props: SwipeableDrawerProps) {
const theme = useTheme(); const theme = useTheme();
const matchesSmallScreens = useMediaQuery(theme.breakpoints.down('md')); const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'), { noSsr: true });
const formatMessage = useFormatMessage(); const formatMessage = useFormatMessage();
return ( return (
@@ -27,13 +27,13 @@ export default function Drawer(props: SwipeableDrawerProps) {
{...props} {...props}
disableBackdropTransition={!iOS} disableBackdropTransition={!iOS}
disableDiscovery={iOS} disableDiscovery={iOS}
variant={matchesSmallScreens ? 'temporary' : 'permanent'} variant={matchSmallScreens ? 'temporary' : 'permanent'}
> >
<HideOnScroll unmountOnExit> <HideOnScroll unmountOnExit>
<Toolbar /> <Toolbar />
</HideOnScroll> </HideOnScroll>
<List> <List sx={{ py: 0, mt: 3 }}>
<ListItemLink <ListItemLink
icon={<SwapCallsIcon htmlColor={theme.palette.primary.main} />} icon={<SwapCallsIcon htmlColor={theme.palette.primary.main} />}
primary={formatMessage('drawer.flows')} 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 Box from '@mui/material/Box';
import AppBar from 'components/AppBar'; import AppBar from 'components/AppBar';
import Drawer from 'components/Drawer'; import Drawer from 'components/Drawer';
@@ -9,18 +12,22 @@ type LayoutProps = {
} }
export default function Layout({ children }: LayoutProps) { export default function Layout({ children }: LayoutProps) {
const [isDrawerOpen, setDrawerOpen] = useState(true); const theme = useTheme();
const onMenuClick = useCallback(() => { setDrawerOpen(value => !value) }, []); const matchSmallScreens = useMediaQuery(theme.breakpoints.down('lg'), { noSsr: true });
const [isDrawerOpen, setDrawerOpen] = useState(!matchSmallScreens);
const openDrawer = () => setDrawerOpen(true);
const closeDrawer = () => setDrawerOpen(false);
return ( return (
<> <>
<AppBar onMenuClick={onMenuClick} /> <AppBar drawerOpen={isDrawerOpen} onDrawerOpen={openDrawer} onDrawerClose={closeDrawer} />
<Box sx={{ display: 'flex', }}> <Box sx={{ display: 'flex', }}>
<Drawer <Drawer
open={isDrawerOpen} open={isDrawerOpen}
onOpen={onMenuClick} onOpen={openDrawer}
onClose={onMenuClick} onClose={closeDrawer}
/> />
<Box sx={{ flex: 1 }}> <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 SearchIcon from '@mui/icons-material/Search';
import useFormatMessage from 'hooks/useFormatMessage'; import useFormatMessage from 'hooks/useFormatMessage';
import { Search, SearchIconWrapper, InputBase } from './style';
type SearchInputProps = { type SearchInputProps = {
onChange?: (event: React.ChangeEvent) => void; onChange?: (event: React.ChangeEvent) => void;
@@ -11,16 +14,26 @@ export default function SearchInput({ onChange }: SearchInputProps) {
const formatMessage = useFormatMessage(); const formatMessage = useFormatMessage();
return ( return (
<Search> <FormControl variant="outlined" fullWidth>
<SearchIconWrapper> <InputLabel
<SearchIcon /> htmlFor="search-input"
</SearchIconWrapper> >
{formatMessage('searchPlaceholder')}
</InputLabel>
<InputBase <OutlinedInput
placeholder={formatMessage('searchPlaceholder')} id="search-input"
inputProps={{ 'aria-label': 'search' }} type="text"
size="medium"
fullWidth
onChange={onChange} 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',
},
},
},
}));

View File

@@ -1,6 +1,6 @@
{ {
"brandText": "Automatisch", "brandText": "Automatisch",
"searchPlaceholder": "Search...", "searchPlaceholder": "Search",
"welcomeText": "Here comes the dashboard homepage.", "welcomeText": "Here comes the dashboard homepage.",
"drawer.dashboard": "Dashboard", "drawer.dashboard": "Dashboard",
"drawer.flows": "Flows", "drawer.flows": "Flows",
@@ -12,7 +12,7 @@
"app.settings": "Settings", "app.settings": "Settings",
"app.connections": "Connections", "app.connections": "Connections",
"app.flows": "Flows", "app.flows": "Flows",
"apps.title": "Apps", "apps.title": "My Apps",
"apps.addConnection": "Add connection", "apps.addConnection": "Add connection",
"apps.addNewAppConnection": "Add a new app connection", "apps.addNewAppConnection": "Add a new app connection",
"apps.searchApp": "Search for app", "apps.searchApp": "Search for app",

View File

@@ -3,8 +3,9 @@ import { Link, Routes, Route, useNavigate } from 'react-router-dom';
import { useQuery } from '@apollo/client'; import { useQuery } from '@apollo/client';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
import Button from '@mui/material/Button'; import AddIcon from '@mui/icons-material/Add';
import ConditionalIconButton from 'components/ConditionalIconButton';
import Container from 'components/Container'; import Container from 'components/Container';
import AddNewAppConnection from 'components/AddNewAppConnection'; import AddNewAppConnection from 'components/AddNewAppConnection';
import PageTitle from 'components/PageTitle'; import PageTitle from 'components/PageTitle';
@@ -32,28 +33,28 @@ export default function Applications() {
return ( return (
<Box sx={{ py: 3 }}> <Box sx={{ py: 3 }}>
<Container> <Container>
<Grid container sx={{ mb: 3 }} spacing={1}> <Grid container sx={{ mb: [2, 5] }} columnSpacing={1.5} rowSpacing={3}>
<Grid item xs={12} sm> <Grid container item xs sm alignItems="center" order={{ xs: 0 }}>
<PageTitle>{formatMessage('apps.title')}</PageTitle> <PageTitle>{formatMessage('apps.title')}</PageTitle>
</Grid> </Grid>
<Grid container item xs={12} sm="auto" justifyContent="flex-end" spacing={2}> <Grid item xs={12} sm="auto" order={{ xs: 2, sm: 1 }}>
<Grid item xs={12} sm="auto"> <SearchInput onChange={onSearchChange} />
<SearchInput onChange={onSearchChange} /> </Grid>
</Grid>
<Grid item xs={12} sm="auto"> <Grid container item xs="auto" sm="auto" alignItems="center" order={{ xs: 1, sm: 2 }}>
<Button <ConditionalIconButton
type="submit" type="submit"
variant="contained" variant="contained"
color="primary" color="primary"
component={Link} size="large"
to={URLS.NEW_APP_CONNECTION} component={Link}
fullWidth to={URLS.NEW_APP_CONNECTION}
> fullWidth
{formatMessage('apps.addConnection')} Icon={<AddIcon />}
</Button> >
</Grid> {formatMessage('apps.addConnection')}
</ConditionalIconButton>
</Grid> </Grid>
</Grid> </Grid>

View File

@@ -1,5 +1,5 @@
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import Container from '@mui/material/Container'; import Container from 'components/Container';
export default function Flows() { export default function Flows() {
return ( return (

View File

@@ -1,4 +1,5 @@
import { createTheme } from '@mui/material/styles'; import { createTheme, alpha } from '@mui/material/styles';
import { cardActionAreaClasses } from '@mui/material/CardActionArea';
const referenceTheme = createTheme({ const referenceTheme = createTheme({
palette: { palette: {
@@ -164,11 +165,44 @@ const extendedTheme = createTheme({
} }
}, },
components: { components: {
MuiAppBar: {
styleOverrides: {
root: {
background: referenceTheme.palette.primary.dark,
zIndex: referenceTheme.zIndex.drawer + 1,
}
},
defaultProps: {
elevation: 2,
},
},
MuiButton: { MuiButton: {
styleOverrides: { styleOverrides: {
root: { root: {
padding: '12px 16px',
textTransform: 'none', textTransform: 'none',
},
sizeLarge: {
padding: '14px 22px',
},
sizeMedium: {
padding: '10px 16px',
},
sizeSmall: {
padding: '6px 10px',
}
}
},
MuiCardActionArea: {
styleOverrides: {
root: {
borderRadius: referenceTheme.shape.borderRadius,
[`& .${cardActionAreaClasses.focusHighlight}`]: {
background: 'unset',
border: `1px solid ${alpha(referenceTheme.palette.primary.light, 1)}`,
},
[`&:hover .${cardActionAreaClasses.focusHighlight}`]: {
opacity: 1,
}
} }
} }
}, },
@@ -187,17 +221,6 @@ const extendedTheme = createTheme({
}, },
}, },
}, },
MuiAppBar: {
styleOverrides: {
root: {
background: referenceTheme.palette.primary.dark,
zIndex: referenceTheme.zIndex.drawer + 1,
}
},
defaultProps: {
elevation: 2,
},
},
MuiToolbar: { MuiToolbar: {
styleOverrides: { styleOverrides: {
root: { root: {