-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIcon.jsx
53 lines (51 loc) · 1.67 KB
/
Icon.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
/**
* Copyright 2018-2021 Sourcepole AG
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import ConfigUtils from '../utils/ConfigUtils';
import LocaleUtils from '../utils/LocaleUtils';
import './style/Icon.css';
export default class Icon extends React.Component {
static propTypes = {
className: PropTypes.string,
icon: PropTypes.string,
onClick: PropTypes.func,
size: PropTypes.string,
title: PropTypes.string,
titlemsgid: PropTypes.string
}
static defaultProps = {
className: "",
title: ""
}
render() {
const classes = classnames({
icon: true,
["icon-" + this.props.icon]: true,
["icon_" + this.props.size]: !!this.props.size,
[this.props.className]: !!this.props.className,
icon_clickable: !!this.props.onClick
});
let title = this.props.title;
if (this.props.titlemsgid) {
title = LocaleUtils.tr(this.props.titlemsgid);
}
if (this.props.icon.startsWith(":/")) {
const assetsPath = ConfigUtils.getAssetsPath();
const src = assetsPath + this.props.icon.substr(1);
return (
<img alt={title} className={classes} onClick={this.props.onClick} src={src} title={title} />
);
} else {
return (
<span className={classes} onClick={this.props.onClick} title={title} />
);
}
}
}