-
Notifications
You must be signed in to change notification settings - Fork 8
/
Clickable.js
67 lines (59 loc) · 1.58 KB
/
Clickable.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
/**
* Clickable Cell Component
*/
import {Component} from './Component';
import {h} from 'maquette';
/**
* About Replacements
* ------------------
* This component has a single
* regular replacement:
* * `contents`
*/
/**
* About Named Children
* --------------------
* `content` (single) - The cell that can go inside the clickable
* component
*/
class Clickable extends Component {
constructor(props, ...args){
super(props, ...args);
// Bind context to methods
this.makeContent = this.makeContent.bind(this);
this.getStyle = this.getStyle.bind(this);
this._getEvent = this._getEvent.bind(this);
}
render(){
return(
h('div', {
id: this.props.id,
"data-cell-id": this.props.id,
"data-cell-type": "Clickable",
onclick: this._getEvent('onclick'),
style: this.getStyle()
}, [
h('div', {}, [this.makeContent()])
]
)
);
}
getStyle(){
if(this.props.extraData.bold){
return "cursor:pointer;*cursor:hand;font-weight:bold;display:inline-block;";
} else {
return "display:inline-block;";
}
}
makeContent(){
if(this.usesReplacements){
return this.getReplacementElementFor('contents');
} else {
return this.renderChildNamed('content');
}
}
_getEvent(eventName) {
return this.props.extraData.events[eventName];
}
}
export {Clickable, Clickable as default};