]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/components/icon_button.js
1 import React
from 'react';
2 import Motion
from 'react-motion/lib/Motion';
3 import spring
from 'react-motion/lib/spring';
4 import PropTypes
from 'prop-types';
6 export default class IconButton
extends React
.PureComponent
{
9 className: PropTypes
.string
,
10 title: PropTypes
.string
.isRequired
,
11 icon: PropTypes
.string
.isRequired
,
12 onClick: PropTypes
.func
,
13 size: PropTypes
.number
,
14 active: PropTypes
.bool
,
15 pressed: PropTypes
.bool
,
16 style: PropTypes
.object
,
17 activeStyle: PropTypes
.object
,
18 disabled: PropTypes
.bool
,
19 inverted: PropTypes
.bool
,
20 animate: PropTypes
.bool
,
21 overlay: PropTypes
.bool
,
22 tabIndex: PropTypes
.string
,
25 static defaultProps
= {
34 handleClick
= (e
) => {
37 if (!this.props
.disabled
) {
38 this.props
.onClick(e
);
44 fontSize: `${this.props.size}px`,
45 width: `${this.props.size * 1.28571429}px`,
46 height: `${this.props.size * 1.28571429}px`,
47 lineHeight: `${this.props.size}px`,
49 ...(this.props
.active
? this.props
.activeStyle : {}),
52 const classes
= ['icon-button'];
54 if (this.props
.active
) {
55 classes
.push('active');
58 if (this.props
.disabled
) {
59 classes
.push('disabled');
62 if (this.props
.inverted
) {
63 classes
.push('inverted');
66 if (this.props
.overlay
) {
67 classes
.push('overlayed');
70 if (this.props
.className
) {
71 classes
.push(this.props
.className
);
75 <Motion defaultStyle
={{ rotate: this.props
.active
? -360 : 0 }} style
={{ rotate: this.props
.animate
? spring(this.props
.active
? -360 : 0, { stiffness: 120, damping: 7 }) : 0 }}>
78 aria
-label
={this.props
.title
}
79 aria
-pressed
={this.props
.pressed
}
80 title
={this.props
.title
}
81 className
={classes
.join(' ')}
82 onClick
={this.handleClick
}
84 tabIndex
={this.props
.tabIndex
}
86 <i style
={{ transform: `rotate(${rotate}deg)` }} className
={`fa fa-fw fa-${this.props.icon}`} aria
-hidden
='true' />
This page took 0.169112 seconds and 4 git commands to generate.