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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import * as _ from 'lodash';
import { action, IReactionDisposer, observable, reaction, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { DocumentType } from '../../documents/DocumentTypes';
import '../global/globalCssVariables.scss';
import { IconBar } from './IconBar';
import './IconButton.scss';
import './SearchBox.scss';
interface iconButtonProps {
type: string;
}
@observer
export class IconButton extends React.Component<iconButtonProps> {
@observable private _isSelected: boolean = IconBar.Instance.getIcons().indexOf(this.props.type) !== -1;
@observable private _hover = false;
private _resetReaction?: IReactionDisposer;
private _selectAllReaction?: IReactionDisposer;
static Instance: IconButton;
constructor(props: iconButtonProps) {
super(props);
IconButton.Instance = this;
}
componentDidMount = () => {
this._resetReaction = reaction(
() => IconBar.Instance._resetClicked,
action(() => {
if (IconBar.Instance._resetClicked) {
this._isSelected = false;
IconBar.Instance._reset++;
if (IconBar.Instance._reset === 9) {
IconBar.Instance._reset = 0;
IconBar.Instance._resetClicked = false;
}
}
})
);
this._selectAllReaction = reaction(
() => IconBar.Instance._selectAllClicked,
action(() => {
if (IconBar.Instance._selectAllClicked) {
this._isSelected = true;
IconBar.Instance._select++;
if (IconBar.Instance._select === 9) {
IconBar.Instance._select = 0;
IconBar.Instance._selectAllClicked = false;
}
}
})
);
};
@action.bound
getIcon() {
switch (this.props.type) {
case DocumentType.NONE: return 'ban';
case DocumentType.AUDIO: return 'music';
case DocumentType.COL: return 'object-group';
case DocumentType.IMG: return 'image';
case DocumentType.LINK: return 'link';
case DocumentType.PDF: return 'file-pdf';
case DocumentType.RTF: return 'sticky-note';
case DocumentType.VID: return 'video';
case DocumentType.WEB: return 'globe-asia';
case DocumentType.MAP: return 'map-marker-alt';
default: return 'caret-down';
} // prettier-ignore
}
@action.bound
onClick = () => {
const newList: string[] = IconBar.Instance.getIcons();
if (!this._isSelected) {
this._isSelected = true;
newList.push(this.props.type);
} else {
this._isSelected = false;
_.pull(newList, this.props.type);
}
IconBar.Instance.updateIcon(newList);
};
selected = {
opacity: 1,
backgroundColor: '#121721',
//backgroundColor: "rgb(128, 128, 128)"
};
notSelected = {
opacity: 0.2,
backgroundColor: '#121721',
};
hoverStyle = {
opacity: 1,
backgroundColor: 'rgb(128, 128, 128)',
//backgroundColor: "rgb(178, 206, 248)" //$medium-blue
};
render() {
return (
<div className="type-outer" id={this.props.type + '-filter'} onMouseEnter={() => (this._hover = true)} onMouseLeave={() => (this._hover = false)} onClick={this.onClick}>
<div className="type-icon" id={this.props.type + '-icon'} style={this._hover ? this.hoverStyle : this._isSelected ? this.selected : this.notSelected}>
<FontAwesomeIcon className="fontawesome-icon" icon={this.getIcon()} />
</div>
{/* <div className="filter-description">{this.props.type}</div> */}
</div>
);
}
}
|