forked from storefront-foundation/react-storefront
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolbarButton.js
57 lines (49 loc) · 1.43 KB
/
ToolbarButton.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
import React, { forwardRef } from 'react'
import { makeStyles } from '@material-ui/core/styles'
import { IconButton } from '@material-ui/core'
import PropTypes from 'prop-types'
export const styles = theme => ({
/**
* Styles applied to the content wrapper element inside the button
*/
wrap: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
...theme.typography.caption,
},
})
const useStyles = makeStyles(styles, { name: 'RSFToolbarButton' })
/**
* A toolbar button with optional label. Use these in your AppBar. All additional
* props are spread to the underlying material-ui IconButton.
*/
const ToolbarButton = forwardRef(({ icon, label, classes = {}, children, ...others }, ref) => {
let { wrap, ...buttonClasses } = classes
classes = useStyles({ classes: { wrap } })
return (
<IconButton ref={ref} classes={buttonClasses} {...others}>
<div className={classes.wrap}>
{icon}
<div>{label}</div>
</div>
{children}
</IconButton>
)
})
ToolbarButton.propTypes = {
/**
* Override or extend the styles applied to the component. See [CSS API](#css) below for more details.
*/
classes: PropTypes.object,
/**
* The icon to use for the button.
*/
icon: PropTypes.element,
/**
* The label text for the button.
*/
label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
}
export default ToolbarButton