forked from wso2/carbon-apimgt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
137 lines (129 loc) · 4.19 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import React from 'react';
import { IconButton, Toolbar, AppBar } from '@material-ui/core';
import { withStyles } from '@material-ui/core/styles';
import MenuIcon from '@material-ui/icons/Menu';
import SearchIcon from '@material-ui/icons/SearchOutlined';
import Hidden from '@material-ui/core/Hidden';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import VerticalDivider from 'AppComponents/Shared/VerticalDivider';
import Avatar from './avatar/Avatar';
import HeaderSearch from './headersearch/HeaderSearch';
import GlobalNavBar from './navbar/GlobalNavBar';
const styles = theme => ({
appBar: {
// zIndex: theme.zIndex.modal + 1,
position: 'relative',
background: theme.palette.background.appBar,
},
typoRoot: {
marginLeft: theme.spacing.unit * 3,
marginRight: theme.spacing.unit * 3,
textTransform: 'capitalize',
},
brandLink: {
color: theme.palette.primary.contrastText,
},
toolbar: {
minHeight: 56,
[`${theme.breakpoints.up('xs')} and (orientation: landscape)`]: {
minHeight: 48,
},
[theme.breakpoints.up('sm')]: {
minHeight: 64,
},
},
menuIcon: {
color: theme.palette.getContrastText(theme.palette.background.appBar),
fontSize: 35,
},
});
/**
* Construct the Global AppBar header section
* @class Header
* @extends {React.Component}
*/
class Header extends React.Component {
/**
*Creates an instance of Header.
* @param {Object} props @inheritdoc
* @memberof Header
*/
constructor(props) {
super(props);
this.state = {
openNavBar: false,
smScreen: false,
};
this.toggleGlobalNavBar = this.toggleGlobalNavBar.bind(this);
this.toggleSmSearch = this.toggleSmSearch.bind(this);
}
/**
* Toggle the Global LHS Navbar visibility
*
* @memberof Header
*/
toggleGlobalNavBar() {
this.setState({ openNavBar: !this.state.openNavBar });
}
/**
* Show search input in sm breakpoint or lower resolution
*/
toggleSmSearch() {
this.setState({ smScreen: !this.state.smScreen });
}
/**
*
* @inheritdoc
* @returns {React.ComponentClass} @inheritdoc
* @memberof Header
*/
render() {
const { openNavBar, smScreen } = this.state;
const { classes, avatar, theme } = this.props;
return (
<React.Fragment>
<AppBar className={classes.appBar} position='fixed'>
<Toolbar className={classes.toolbar}>
<IconButton onClick={this.toggleGlobalNavBar}>
<MenuIcon className={classes.menuIcon} />
</IconButton>
<Link to='/'>
<img src={theme.custom.logo} alt={theme.custom.title} />
</Link>
<VerticalDivider height={32} />
<Hidden smDown>
<HeaderSearch />
</Hidden>
<Hidden mdUp>
<IconButton onClick={this.toggleSmSearch} color='inherit'>
<SearchIcon className={classes.menuIcon} />
</IconButton>
{smScreen && <HeaderSearch toggleSmSearch={this.toggleSmSearch} smSearch={smScreen} />}
</Hidden>
{avatar}
</Toolbar>
</AppBar>
<GlobalNavBar toggleGlobalNavBar={this.toggleGlobalNavBar} open={openNavBar} />
</React.Fragment>
);
}
}
Header.defaultProps = {
avatar: <Avatar />,
};
Header.propTypes = {
classes: PropTypes.shape({
appBar: PropTypes.string,
menuIcon: PropTypes.string,
toolbar: PropTypes.string,
}).isRequired,
avatar: PropTypes.element,
theme: PropTypes.shape({
custom: PropTypes.shape({
logo: PropTypes.string,
title: PropTypes.string,
}),
}).isRequired,
};
export default withStyles(styles, { withTheme: true })(Header);