Добавлено поле поиска в шапке (#43)
* Добавлено поле поиска в шапке * Исправлены недочеты после ревью * Rebase * Исправлен баг после rebase
This commit is contained in:
@ -1,17 +1,10 @@
|
|||||||
import {AppBar, createStyles, Fab, IconButton, makeStyles, Theme, Toolbar} from '@material-ui/core';
|
import {AppBar, createStyles, Fab, IconButton, makeStyles, Theme, Toolbar} from '@material-ui/core';
|
||||||
import React, {memo} from 'react';
|
import React, {memo} from 'react';
|
||||||
import Slide from '@material-ui/core/Slide';
|
|
||||||
import MoreIcon from '@material-ui/icons/MoreVert';
|
import MoreIcon from '@material-ui/icons/MoreVert';
|
||||||
import AddIcon from '@material-ui/icons/Add';
|
import AddIcon from '@material-ui/icons/Add';
|
||||||
import MoveToInboxIcon from '@material-ui/icons/MoveToInbox';
|
import MoveToInboxIcon from '@material-ui/icons/MoveToInbox';
|
||||||
import CalendarTodayIcon from '@material-ui/icons/CalendarToday';
|
import CalendarTodayIcon from '@material-ui/icons/CalendarToday';
|
||||||
import ListAltIcon from '@material-ui/icons/ListAlt';
|
import ListAltIcon from '@material-ui/icons/ListAlt';
|
||||||
import {NavLink} from 'react-router-dom';
|
|
||||||
import {ROUTES} from '_consts/common';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
trigger: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) =>
|
const useStyles = makeStyles((theme: Theme) =>
|
||||||
createStyles({
|
createStyles({
|
||||||
@ -36,12 +29,16 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
trigger: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
const BothMenu: React.FC<Props> = ({trigger}) => {
|
const BothMenu: React.FC<Props> = ({trigger}) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slide appear={false} direction="up" in={!trigger}>
|
|
||||||
<AppBar
|
<AppBar
|
||||||
|
position="fixed"
|
||||||
color="primary"
|
color="primary"
|
||||||
className={classes.appBar}
|
className={classes.appBar}
|
||||||
>
|
>
|
||||||
@ -51,17 +48,13 @@ const BothMenu: React.FC<Props> = ({trigger}) => {
|
|||||||
edge="start"
|
edge="start"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
>
|
>
|
||||||
<NavLink to={ROUTES.CHAOS_BOX}>
|
|
||||||
<MoveToInboxIcon />
|
<MoveToInboxIcon />
|
||||||
</NavLink>
|
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
edge="end"
|
edge="end"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
>
|
>
|
||||||
<NavLink to={ROUTES.PROJECTS}>
|
|
||||||
<ListAltIcon />
|
<ListAltIcon />
|
||||||
</NavLink>
|
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Fab
|
<Fab
|
||||||
color="secondary"
|
color="secondary"
|
||||||
@ -75,9 +68,7 @@ const BothMenu: React.FC<Props> = ({trigger}) => {
|
|||||||
edge="start"
|
edge="start"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
>
|
>
|
||||||
<NavLink to={ROUTES.CALENDAR}>
|
|
||||||
<CalendarTodayIcon />
|
<CalendarTodayIcon />
|
||||||
</NavLink>
|
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
edge="end"
|
edge="end"
|
||||||
@ -87,7 +78,6 @@ const BothMenu: React.FC<Props> = ({trigger}) => {
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
</Slide>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,21 @@
|
|||||||
import React, {memo} from 'react';
|
import React, {memo, useState} from 'react';
|
||||||
import {useHistory} from 'react-router-dom';
|
import {useHistory} from 'react-router-dom';
|
||||||
import {createStyles, makeStyles} from '@material-ui/core/styles';
|
import {createStyles, makeStyles, Theme} from '@material-ui/core/styles';
|
||||||
import AppBar from '@material-ui/core/AppBar';
|
import AppBar from '@material-ui/core/AppBar';
|
||||||
import Toolbar from '@material-ui/core/Toolbar';
|
import Toolbar from '@material-ui/core/Toolbar';
|
||||||
import Slide from '@material-ui/core/Slide';
|
import Slide from '@material-ui/core/Slide';
|
||||||
import Typography from '@material-ui/core/Typography';
|
import Typography from '@material-ui/core/Typography';
|
||||||
import IconButton from '@material-ui/core/IconButton';
|
import IconButton from '@material-ui/core/IconButton';
|
||||||
|
import TextField from '@material-ui/core/TextField';
|
||||||
import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos';
|
import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos';
|
||||||
import SearchIcon from '@material-ui/icons/Search';
|
import SearchIcon from '@material-ui/icons/Search';
|
||||||
|
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
|
||||||
import {Avatar} from '@material-ui/core';
|
import {Avatar} from '@material-ui/core';
|
||||||
import {PageType} from '_enums/common';
|
import {PageType} from '_enums/common';
|
||||||
import {PAGE_TITLE} from '_consts/common';
|
import {PAGE_TITLE} from '_consts/common';
|
||||||
import {usePageType} from '_hooks/usePageType';
|
import {usePageType} from '_hooks/usePageType';
|
||||||
import {buildPath} from '_utils/buildPath';
|
import {buildPath} from '_utils/buildPath';
|
||||||
|
import {LABELS} from '../../consts';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
trigger: boolean;
|
trigger: boolean;
|
||||||
@ -20,17 +23,21 @@ type Props = {
|
|||||||
|
|
||||||
const NO_NAME_AVATAR = 'https://d.newsweek.com/en/full/425257/02-10-putin-economy.jpg';
|
const NO_NAME_AVATAR = 'https://d.newsweek.com/en/full/425257/02-10-putin-economy.jpg';
|
||||||
|
|
||||||
const useStyles = makeStyles(() =>
|
const useStyles = makeStyles((theme: Theme) =>
|
||||||
createStyles({
|
createStyles({
|
||||||
title: {
|
title: {
|
||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
},
|
},
|
||||||
|
searchInput: {
|
||||||
|
backgroundColor: theme.palette.background.default,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const TopMenu: React.FC<Props> = ({trigger}) => {
|
const TopMenu: React.FC<Props> = ({trigger}) => {
|
||||||
|
const [isShowSearch, setShowSearch] = useState(false);
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const pageType = usePageType();
|
const pageType = usePageType();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@ -39,18 +46,42 @@ const TopMenu: React.FC<Props> = ({trigger}) => {
|
|||||||
history.push(buildPath({pageType: PageType.Main}));
|
history.push(buildPath({pageType: PageType.Main}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleToggleSearch = () => {
|
||||||
|
setShowSearch(!isShowSearch);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClickAway = () => {
|
||||||
|
setShowSearch(false);
|
||||||
|
};
|
||||||
|
|
||||||
const title = PAGE_TITLE[pageType];
|
const title = PAGE_TITLE[pageType];
|
||||||
return (
|
return (
|
||||||
<Slide appear={false} direction="down" in={!trigger}>
|
<Slide appear={false} direction="down" in={!trigger}>
|
||||||
<AppBar position="sticky">
|
<AppBar position="sticky">
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
{pageType === PageType.Main && (
|
{pageType === PageType.Main && (
|
||||||
|
<>
|
||||||
|
{isShowSearch ? (
|
||||||
|
<ClickAwayListener onClickAway={handleClickAway}>
|
||||||
|
<TextField
|
||||||
|
label={LABELS.SEACRH}
|
||||||
|
id="outlined-size-small"
|
||||||
|
defaultValue=""
|
||||||
|
variant="outlined"
|
||||||
|
size="small"
|
||||||
|
className={classes.searchInput}
|
||||||
|
/>
|
||||||
|
</ClickAwayListener>
|
||||||
|
) : (
|
||||||
<IconButton
|
<IconButton
|
||||||
edge="start"
|
edge="start"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
>
|
>
|
||||||
<SearchIcon />
|
<SearchIcon onClick={handleToggleSearch} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{pageType !== PageType.Main && (
|
{pageType !== PageType.Main && (
|
||||||
<IconButton
|
<IconButton
|
||||||
@ -61,14 +92,12 @@ const TopMenu: React.FC<Props> = ({trigger}) => {
|
|||||||
<ArrowBackIosIcon />
|
<ArrowBackIosIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Typography
|
<Typography
|
||||||
variant="h6"
|
variant="h6"
|
||||||
className={classes.title}
|
className={classes.title}
|
||||||
>
|
>
|
||||||
{title}
|
{isShowSearch ? '' : title}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Avatar src={NO_NAME_AVATAR} />
|
<Avatar src={NO_NAME_AVATAR} />
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
|
|||||||
3
src/app/consts.ts
Normal file
3
src/app/consts.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export const LABELS = {
|
||||||
|
SEACRH: 'Поиск',
|
||||||
|
} as const;
|
||||||
Reference in New Issue
Block a user