forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseIcon.js
More file actions
95 lines (83 loc) · 2.06 KB
/
Copy pathBaseIcon.js
File metadata and controls
95 lines (83 loc) · 2.06 KB
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
import React from 'react'
import ReactDOM from 'react-dom'
import _ from 'underscore'
var BaseIcon = React.createClass({
propTypes: {
name: React.PropTypes.string.isRequired,
content: React.PropTypes.string.isRequired,
viewBox: React.PropTypes.string.isRequired,
title: React.PropTypes.string,
desc: React.PropTypes.string,
width: React.PropTypes.string,
height: React.PropTypes.string
},
componentWillMount () {
this.titleId = _.uniqueId('iconTitle_');
this.descId = _.uniqueId('iconDesc_');
},
componentDidMount () {
ReactDOM.findDOMNode(this).setAttribute('focusable', 'false')
},
getDefaultProps () {
return {
width: '1em',
height: '1em'
}
},
getRole () {
if (this.props.title) {
return 'img'
} else {
return 'presentation'
}
},
renderTitle () {
const { title } = this.props
return (title) ? (
<title id={this.titleId}>{title}</title>
) : null
},
renderDesc () {
const { desc } = this.props
return (desc) ? (
<desc id={this.descId}>{desc}</desc>
) : null
},
getLabelledBy () {
const ids = []
if (this.props.title) {
ids.push(this.titleId)
}
if (this.props.desc) {
ids.push(this.descId)
}
return (ids.length > 0) ? ids.join(' ') : null
},
render () {
const {
title,
width,
height,
viewBox,
className
} = this.props
const style = {
fill: 'currentColor'
}
return (
<svg
style={style}
width={width}
height={height}
viewBox={viewBox}
aria-hidden={title ? null : 'true'}
aria-labelledby={this.getLabelledBy()}
role={this.getRole()}>
{this.renderTitle()}
{this.renderDesc()}
<g role="presentation" dangerouslySetInnerHTML={{__html: this.props.content}} />
</svg>
)
}
});
export default BaseIcon