-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
CardActions.js
73 lines (65 loc) · 1.69 KB
/
CardActions.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
import React, {Component} from 'react';
import PropTypes from 'prop-types';
function getStyles() {
return {
root: {
padding: 8,
position: 'relative',
},
action: {
marginRight: 8,
},
};
}
class CardActions extends Component {
static propTypes = {
/**
* If true, a click on this card component expands the card.
*/
actAsExpander: PropTypes.bool,
/**
* Can be used to render elements inside the Card Action.
*/
children: PropTypes.node,
/**
* If true, this card component is expandable.
*/
expandable: PropTypes.bool,
/**
* If true, this card component will include a button to expand the card.
*/
showExpandableButton: PropTypes.bool,
/**
* Override the inline-styles of the root element.
*/
style: PropTypes.object,
};
static contextTypes = {
muiTheme: PropTypes.object.isRequired,
};
render() {
const {
actAsExpander, // eslint-disable-line no-unused-vars
children,
expandable, // eslint-disable-line no-unused-vars
showExpandableButton, // eslint-disable-line no-unused-vars
style,
...other
} = this.props;
const {prepareStyles} = this.context.muiTheme;
const styles = getStyles(this.props, this.context);
const styledChildren = React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
return React.cloneElement(child, {
style: Object.assign({}, styles.action, child.props.style),
});
}
});
return (
<div {...other} style={prepareStyles(Object.assign(styles.root, style))}>
{styledChildren}
</div>
);
}
}
export default CardActions;