forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolicyCell.js
More file actions
69 lines (60 loc) · 1.84 KB
/
Copy pathPolicyCell.js
File metadata and controls
69 lines (60 loc) · 1.84 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
import $ from 'jquery'
import React from 'react'
import ReactDOM from 'react-dom'
import RadioInput from 'instructure-ui/lib/components/RadioInput'
import RadioInputGroup from 'instructure-ui/lib/components/RadioInputGroup'
import ScreenReaderContent from 'instructure-ui/lib/components/ScreenReaderContent'
const PropTypes = React.PropTypes
export default class PolicyCell extends React.Component {
static renderAt (elt, props) {
ReactDOM.render(<PolicyCell {...props} />, elt)
}
constructor () {
super()
this.handleValueChanged = this.handleValueChanged.bind(this)
}
static propTypes = {
selection: PropTypes.string,
category: PropTypes.string,
channelId: PropTypes.string,
buttonData: PropTypes.array,
onValueChanged: PropTypes.func,
}
handleValueChanged (newValue) {
if (this.props.onValueChanged) {
this.props.onValueChanged(this.props.category, this.props.channelId, newValue)
}
}
renderIcon (iconName, title) {
return <span>
<i aria-hidden="true" className={iconName} />
<ScreenReaderContent>{title}</ScreenReaderContent>
</span>
}
renderRadioInput(iconName, title, value) {
return <RadioInput
key={value}
label={this.renderIcon(iconName, title)}
value={value}
id={`cat_${this.props.category}_ch_${this.props.channelId}_${value}`}
/>
}
renderRadioInputs() {
const buttonData = this.props.buttonData
return buttonData.map((button) => {
return this.renderRadioInput(button.icon, button.title, button.code)
})
}
render () {
return <RadioInputGroup
name={Math.floor(1 + Math.random() * 0x10000).toString()}
description=""
variant="toggle"
size="small"
defaultValue={this.props.selection}
onChange={this.handleValueChanged}
>
{this.renderRadioInputs()}
</RadioInputGroup>
}
}