forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsx
61 lines (57 loc) · 1.56 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
import React, { Component } from 'react';
import classNames from 'classnames';
import { oneOf, bool, string } from 'prop-types';
import purple from '@material-ui/core/colors/purple';
import { withStyles } from '@material-ui/core/styles';
import Label from '../Label';
import labels from '../../utils/labels';
@withStyles(theme => ({
pending: {
backgroundColor: `${purple[400]} !important`,
color: `${theme.palette.getContrastText(purple[400])} !important`,
},
}))
/**
* A label color-coded based on known statuses from GraphQL responses.
*/
export default class StatusLabel extends Component {
static defaultProps = {
mini: true,
className: null,
variant: null,
};
static propTypes = {
/**
* A GraphQL status/state string.
*/
state: string.isRequired,
/**
* Render the label using dense styling.
*/
mini: bool,
/** The CSS class name of the wrapper element */
className: string,
/**
* The label color. Only use this if you are looking to override
* the color that's already derived from the state prop.
* */
variant: oneOf(['default', 'info', 'success', 'error', 'warning']),
};
render() {
const { classes, variant, state, mini, className, ...props } = this.props;
return (
<Label
mini={mini}
status={variant || labels[state] || 'default'}
className={classNames(
{
[classes.pending]: state === 'PENDING',
},
className
)}
{...props}>
{state || 'UNKNOWN'}
</Label>
);
}
}