forked from dnnsoftware/Dnn.Platform
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.jsx
More file actions
134 lines (117 loc) · 3.19 KB
/
Copy pathindex.jsx
File metadata and controls
134 lines (117 loc) · 3.19 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React, { Component } from "react";
import PropTypes from "prop-types";
import {
AddIcon,
EditIcon,
CardViewIcon,
ListViewIcon,
PreviewIcon,
SettingsIcon,
PageIcon,
TrafficIcon,
TemplateIcon,
TrashIcon,
UserIcon,
ArrowDownIcon,
ArrowRightIcon,
ArrowUpIcon,
LockClosedIcon,
CheckMarkIcon,
CrossOutIcon,
CheckboxUncheckedIcon,
CheckboxIcon
} from "../SvgIcons";
import "./style.less";
export default class IconButton extends Component {
constructor(props) {
super(props);
}
getIcon() {
const {props} = this;
if (props.customIcon) {
return props.customIcon;
}
switch (props.type.toLowerCase()) {
case "add":
return AddIcon;
case "edit":
return EditIcon;
case "card":
return CardViewIcon;
case "list":
return ListViewIcon;
case "preview":
return PreviewIcon;
case "settings":
return SettingsIcon;
case "page":
return PageIcon;
case "traffic":
return TrafficIcon;
case "template":
return TemplateIcon;
case "trash":
return TrashIcon;
case "user":
return UserIcon;
case "arrow-down":
return ArrowDownIcon;
case "arrow-right":
return ArrowRightIcon;
case "arrow-up":
return ArrowUpIcon;
case "lock-closed":
return LockClosedIcon;
case "checked":
return CheckMarkIcon;
case "denied":
return CrossOutIcon;
case "unchecked":
return CheckboxUncheckedIcon;
case "checkbox":
return CheckboxIcon;
default:
return null;
}
}
getClassName() {
const {props} = this;
let name = "icon-button";
if (props.className) {
name += " " + props.className;
}
return name;
}
getStyle() {
const {props} = this;
let style = {};
if (props.width && props.width > 0) {
style["width"] = props.width + "px";
}
if (props.height && props.height > 0) {
style["height"] = props.height + "px";
}
return style;
}
onClick(event) {
const {props} = this;
event.preventDefault();
props.onClick(event);
}
render() {
const {props} = this;
const Icon = this.getIcon();
if (typeof props.onClick === "function") {
return <a href="#" className={this.getClassName()} style={this.getStyle()} onClick={this.onClick.bind(this)} aria-label={props.type}><Icon /></a>;
} else {
return <span className="icon-flat" style={this.getStyle()}><Icon /></span>;
}
}
}
IconButton.propTypes = {
type: PropTypes.string,
onClick: PropTypes.func,
width: PropTypes.number,
height: PropTypes.number,
customIcon: PropTypes.string
};