-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
icon-long.jsx
218 lines (194 loc) · 4.55 KB
/
icon-long.jsx
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
* This file is part of the @iconify/icon-finder package.
*
* (c) Vjacheslav Trushkin <cyberalien@gmail.com>
*
* For the full copyright and license information, please view the license.txt or license.gpl.txt
* files that were distributed with this source code.
*
* Licensed under Apache 2.0 or GPL 2.0 at your option.
* If derivative product is not compatible with one of licenses, you can pick one of licenses.
*
* @license Apache 2.0
* @license GPL 2.0
*/
'use strict';
import React, { Component } from 'react';
import Iconify from '@iconify/iconify';
import filters from '../../../core/data/icon-filters';
import ListIcon from '../../parts/icon-list';
import Icon from '../../parts/icon-decoration';
import Filter from '../../parts/filter';
const phrases = require('../../../data/phrases');
const lang = phrases.icons;
class LongIcon extends Component {
render() {
let props = this.props,
name = props.name,
loaded = Iconify.iconExists(name),
deleteButton = null;
// Delete button
if (props.view.type === 'custom' && props.view.canDelete) {
deleteButton = (
<a
href="#"
key="delete"
onClick={this._onDeleteClick.bind(this)}
className="plugin-icon-item-delete"
title={lang.delete}
>
<Icon name="trash" />
</a>
);
}
if (!loaded) {
return (
<ListIcon
loading={true}
selected={props.selected}
title={props.title}
onClick={this._onClick.bind(this)}
size={lang.loading}
>
{deleteButton}
</ListIcon>
);
}
let icon = props.icon,
iconData = Iconify.getIcon(name);
// Generate link and tooltip
let link = props.config.links.icon
.replace('{prefix}', icon.prefix)
.replace('{name}', icon.name);
let tooltip = [
lang.name.replace('{prefix}', icon.prefix).replace('{name}', icon.name),
lang.size
.replace('{width}', iconData.width)
.replace('{height}', iconData.height),
lang.palette.replace(
'{palette}',
iconData.body.indexOf('currentColor') === -1
? lang.colors
: lang.colorless
),
];
tooltip = tooltip.join('\n');
// Text
let size = lang.sizeList
.replace('{width}', iconData.width)
.replace('{height}', iconData.height);
// Filters/tags
let filtersList = [];
if (props.view.type === 'search') {
// Add collection
let block = props.view.blocks.collections;
if (block.filters[icon.prefix] !== void 0) {
filtersList.push(
<Filter
key={icon.prefix}
title={block.filters[icon.prefix]}
index={Object.keys(block.filters).indexOf(icon.prefix)}
onClick={this._onFilterClick.bind(this, 'collections', icon.prefix)}
/>
);
}
}
filters.forEach(filter => {
let key = filter.icon;
if (icon[key] === void 0 || icon[key] === null) {
return;
}
let routeValue = props.view.route.params[filter.route];
(typeof icon[key] === 'string' ? [icon[key]] : icon[key]).forEach(
value => {
if (value === routeValue) {
return;
}
let block = props.view.blocks[filter.key];
filtersList.push(
<Filter
key={filter.key + '-' + value}
title={value}
index={block.index + Object.keys(block.filters).indexOf(value)}
onClick={this._onFilterClick.bind(this, filter.key, value)}
/>
);
}
);
});
// Delete button
if (props.view.type === 'custom' && props.view.canDelete) {
filtersList.push(deleteButton);
}
// Generate SVG
let svg = Iconify.getSVG(name, {
'data-width': '1em',
'data-height': '1em',
'data-inline': false,
});
return (
<ListIcon
selected={props.selected}
title={props.title}
href={link}
tooltip={tooltip}
onClick={this._onClick.bind(this)}
onDrag={this._onDrag.bind(this)}
svg={svg}
size={size}
>
{filtersList}
</ListIcon>
);
}
/**
* Icon dragged
*
* @param {object} props
* @private
*/
_onDrag(props) {
this.props.container.dropIconifyIcon(
{
isSample: false,
iconName: this.props.name,
},
props
);
}
/**
* Icon clicked
*
* @param event
* @private
*/
_onClick(event) {
event.preventDefault();
if (this.props.onClick) {
this.props.onClick(this.props.icon);
}
}
/**
* Filter clicked
*
* @param {string} name
* @param {string} value
* @param event
* @private
*/
_onFilterClick(name, value, event) {
event.preventDefault();
this.props.view.action(name, value);
}
/**
* Delete icon
*
* @param event
* @private
*/
_onDeleteClick(event) {
event.preventDefault();
this.props.view.action('delete', this.props.icon);
}
}
export default LongIcon;