-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathAppBar.js
130 lines (123 loc) · 3.59 KB
/
AppBar.js
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
import React, { cloneElement } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import classNames from 'classnames';
import MuiAppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import { withStyles } from '@material-ui/core/styles';
import MenuIcon from '@material-ui/icons/Menu';
import withWidth from '@material-ui/core/withWidth';
import compose from 'recompose/compose';
import { toggleSidebar as toggleSidebarAction } from 'ra-core';
import LoadingIndicator from './LoadingIndicator';
import UserMenu from './UserMenu';
import Headroom from './Headroom';
const styles = theme => ({
toolbar: {
paddingRight: 24,
},
menuButton: {
marginLeft: '0.5em',
marginRight: '0.5em',
},
menuButtonIconClosed: {
transition: theme.transitions.create(['transform'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
transform: 'rotate(0deg)',
},
menuButtonIconOpen: {
transition: theme.transitions.create(['transform'], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
transform: 'rotate(180deg)',
},
title: {
flex: 1,
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden',
},
});
const AppBar = ({
children,
classes,
className,
logout,
open,
title,
toggleSidebar,
userMenu,
width,
...rest
}) => (
<Headroom>
<MuiAppBar
className={className}
color="secondary"
position="static"
{...rest}
>
<Toolbar
disableGutters
variant={width === 'xs' ? 'regular' : 'dense'}
className={classes.toolbar}
>
<IconButton
color="inherit"
aria-label="open drawer"
onClick={toggleSidebar}
className={classNames(classes.menuButton)}
>
<MenuIcon
classes={{
root: open
? classes.menuButtonIconOpen
: classes.menuButtonIconClosed,
}}
/>
</IconButton>
<Typography
variant="title"
color="inherit"
className={classes.title}
id="react-admin-title"
/>
<LoadingIndicator />
{cloneElement(userMenu, { logout })}
</Toolbar>
</MuiAppBar>
</Headroom>
);
AppBar.propTypes = {
children: PropTypes.node,
classes: PropTypes.object,
className: PropTypes.string,
logout: PropTypes.element,
open: PropTypes.bool,
title: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
.isRequired,
toggleSidebar: PropTypes.func.isRequired,
userMenu: PropTypes.node,
width: PropTypes.string,
};
AppBar.defaultProps = {
userMenu: <UserMenu />,
};
const enhance = compose(
connect(
state => ({
locale: state.i18n.locale, // force redraw on locale change
}),
{
toggleSidebar: toggleSidebarAction,
}
),
withStyles(styles),
withWidth()
);
export default enhance(AppBar);