-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathActionButton.js
107 lines (95 loc) · 2.55 KB
/
ActionButton.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
import React, { forwardRef } from 'react'
import { styled } from '@mui/material/styles'
import { Button, Typography } from '@mui/material'
import PropTypes from 'prop-types'
const PREFIX = 'RSFActionButton'
const defaultClasses = {
label: `${PREFIX}-label`,
caption: `${PREFIX}-caption`,
button: `${PREFIX}-button`,
value: `${PREFIX}-value`,
}
const StyledButton = styled(Button)(({ theme }) => ({
/**
* Styles passed through to the [`Button`](https://mui.com/api/button/#css) element's
* `label` CSS rule.
*/
[`& .${defaultClasses.label}`]: {
justifyContent: 'space-between',
alignItems: 'baseline',
textTransform: 'none',
},
/**
* Styles applied to the label container.
*/
[`& .${defaultClasses.caption}`]: {
textTransform: 'none',
fontWeight: 'bold',
},
/**
* Styles passed through to the [`Button`](https://mui.com/api/button/#css) element's
* `contained` CSS rule.
*/
[`& .${defaultClasses.button}`]: {
boxShadow: 'none',
backgroundColor: theme.palette.grey[200],
},
/**
* Styles applied to the values container.
*/
[`& .${defaultClasses.value}`]: {
color: theme.palette.text.primary,
whiteSpace: 'nowrap',
textOverflow: 'ellipses',
marginLeft: '10px',
},
}))
export {}
/**
* This button class displays a label and value.
*
* Example:
*
* ```js
* <ActionButton label="Sort" value="Lowest Price" onClick={openSortMenu} />
* ```
*/
const ActionButton = forwardRef(({ label, value, classes: c = {}, ...props }, ref) => {
const classes = { ...defaultClasses, ...c }
const { caption, value: valueClasses, button, label: labelClasses, ...otherClasses } = classes
return (
<StyledButton
ref={ref}
variant="contained"
color="primary"
classes={{
contained: button,
label: labelClasses,
...otherClasses,
}}
{...props}
>
<Typography variant="button" className={caption}>
{label}
</Typography>
<Typography variant="caption" className={valueClasses}>
{value}
</Typography>
</StyledButton>
)
})
ActionButton.propTypes = {
/**
* Override or extend the styles applied to the component. See [CSS API](#css) below for more details.
*/
classes: PropTypes.object,
/**
* The label to display on the left side of the button.
*/
label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
/**
* The value to display on the right side of the button.
*/
value: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
}
export default ActionButton