Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/components/icon.tsx
5843 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
declare var DEBUG: boolean; // comes from static webpack; not defined in other contexts.
7
8
import React from "react";
9
10
import { CSS } from "@cocalc/frontend/app-framework";
11
import useOnFrontend from "./use-on-frontend";
12
13
import {
14
AimOutlined,
15
AlignCenterOutlined,
16
AlignLeftOutlined,
17
AlignRightOutlined,
18
ApiOutlined,
19
AppstoreOutlined,
20
AreaChartOutlined,
21
ArrowDownOutlined,
22
ArrowLeftOutlined,
23
ArrowRightOutlined,
24
ArrowUpOutlined,
25
ArrowsAltOutlined,
26
AudioOutlined,
27
BackwardOutlined,
28
BankOutlined,
29
BellFilled,
30
BellOutlined,
31
BoldOutlined,
32
BookOutlined,
33
BorderOutlined,
34
BugOutlined,
35
BulbOutlined,
36
CalculatorOutlined,
37
CalendarOutlined,
38
CameraOutlined,
39
CaretDownFilled,
40
CaretLeftFilled,
41
CaretRightFilled,
42
CaretUpFilled,
43
CheckCircleOutlined,
44
CheckOutlined,
45
CheckSquareOutlined,
46
ClearOutlined,
47
ClockCircleOutlined,
48
CloseCircleFilled,
49
CloseCircleOutlined,
50
CloseCircleTwoTone,
51
CloseOutlined,
52
CloudDownloadOutlined,
53
CloudFilled,
54
CloudServerOutlined,
55
CloudUploadOutlined,
56
ClusterOutlined,
57
CodeOutlined,
58
CoffeeOutlined,
59
ColumnHeightOutlined,
60
ColumnWidthOutlined,
61
CommentOutlined,
62
CompassOutlined,
63
ContainerOutlined,
64
ControlOutlined,
65
CopyOutlined,
66
CreditCardOutlined,
67
DashboardOutlined,
68
DatabaseFilled,
69
DatabaseOutlined,
70
DeleteOutlined,
71
DeliveredProcedureOutlined,
72
DeploymentUnitOutlined,
73
DesktopOutlined,
74
DoubleLeftOutlined,
75
DoubleRightOutlined,
76
DownCircleOutlined,
77
DownOutlined,
78
DownSquareOutlined,
79
DownloadOutlined,
80
EditFilled,
81
EditOutlined,
82
EllipsisOutlined,
83
ExclamationCircleFilled,
84
ExpandOutlined,
85
ExperimentOutlined,
86
ExportOutlined,
87
EyeInvisibleOutlined,
88
EyeOutlined,
89
FacebookFilled,
90
FacebookOutlined,
91
FieldTimeOutlined,
92
FileImageOutlined,
93
FileOutlined,
94
FilePdfOutlined,
95
FileTextOutlined,
96
FileZipOutlined,
97
FireOutlined,
98
FolderOpenOutlined,
99
FolderOutlined,
100
FontSizeOutlined,
101
ForkOutlined,
102
ForwardOutlined,
103
FrownOutlined,
104
FunctionOutlined,
105
FundProjectionScreenOutlined,
106
GatewayOutlined,
107
GiftOutlined,
108
GiftTwoTone,
109
GithubFilled,
110
GithubOutlined,
111
GlobalOutlined,
112
GoogleOutlined,
113
GroupOutlined,
114
HddOutlined,
115
HighlightOutlined,
116
HistoryOutlined,
117
HomeOutlined,
118
HourglassOutlined,
119
Html5Outlined,
120
IdcardOutlined,
121
InfoCircleOutlined,
122
InfoOutlined,
123
InstagramFilled,
124
InstagramOutlined,
125
ItalicOutlined,
126
KeyOutlined,
127
LaptopOutlined,
128
LayoutOutlined,
129
LeftCircleOutlined,
130
LeftOutlined,
131
LeftSquareFilled,
132
LineChartOutlined,
133
LineHeightOutlined,
134
LinkOutlined,
135
LinkedinFilled,
136
LinkedinOutlined,
137
LoadingOutlined,
138
LockFilled,
139
LockOutlined,
140
LoginOutlined,
141
MailOutlined,
142
MedicineBoxOutlined,
143
MehOutlined,
144
MenuOutlined,
145
MergeCellsOutlined,
146
MinusCircleOutlined,
147
MinusOutlined,
148
MinusSquareOutlined,
149
OrderedListOutlined,
150
PauseCircleOutlined,
151
PercentageOutlined,
152
PicCenterOutlined,
153
PieChartOutlined,
154
PlayCircleFilled,
155
PlayCircleOutlined,
156
PlaySquareOutlined,
157
PlusCircleFilled,
158
PlusCircleOutlined,
159
PlusOutlined,
160
PlusSquareOutlined,
161
PoweroffOutlined,
162
PrinterOutlined,
163
ProjectOutlined,
164
QuestionCircleOutlined,
165
RedoOutlined,
166
ReloadOutlined,
167
RetweetOutlined,
168
RightCircleFilled,
169
RightCircleOutlined,
170
RightOutlined,
171
RightSquareFilled,
172
RiseOutlined,
173
RobotOutlined,
174
RocketOutlined,
175
SaveOutlined,
176
ScissorOutlined,
177
SearchOutlined,
178
SelectOutlined,
179
SendOutlined,
180
SettingOutlined,
181
ShareAltOutlined,
182
ShoppingCartOutlined,
183
ShrinkOutlined,
184
SignatureOutlined,
185
SlidersOutlined,
186
SmileOutlined,
187
SolutionOutlined,
188
SoundOutlined,
189
StarFilled,
190
StarOutlined,
191
StepBackwardOutlined,
192
StepForwardOutlined,
193
StopFilled,
194
StopOutlined,
195
StrikethroughOutlined,
196
SwapLeftOutlined,
197
SwapOutlined,
198
SwapRightOutlined,
199
SyncOutlined,
200
TableOutlined,
201
TagFilled,
202
TagOutlined,
203
TagTwoTone,
204
TagsFilled,
205
TagsOutlined,
206
TagsTwoTone,
207
TeamOutlined,
208
ThunderboltOutlined,
209
ToTopOutlined,
210
ToolOutlined,
211
TranslationOutlined,
212
UnderlineOutlined,
213
UndoOutlined,
214
UnlockFilled,
215
UnorderedListOutlined,
216
UpCircleOutlined,
217
UpOutlined,
218
UpSquareOutlined,
219
UploadOutlined,
220
UserAddOutlined,
221
UserDeleteOutlined,
222
UserOutlined,
223
UsergroupAddOutlined,
224
VerticalAlignBottomOutlined,
225
VerticalAlignMiddleOutlined,
226
VerticalLeftOutlined,
227
VerticalRightOutlined,
228
VideoCameraOutlined,
229
WalletOutlined,
230
WarningOutlined,
231
WifiOutlined,
232
XOutlined,
233
YoutubeFilled,
234
YoutubeOutlined,
235
ZoomInOutlined,
236
ZoomOutOutlined,
237
} from "@ant-design/icons";
238
239
// Unfortunately -- "error TS7056: The inferred type of this node exceeds the maximum length the
240
// compiler will serialize. An explicit type annotation is needed."
241
const IconSpec = {
242
"address-card": IdcardOutlined,
243
aim: AimOutlined,
244
"align-left": AlignLeftOutlined,
245
"align-center": AlignCenterOutlined,
246
"align-justify": { IconFont: "align-justify" },
247
"align-right": AlignRightOutlined,
248
"angle-double-left": DoubleLeftOutlined,
249
"angle-double-right": DoubleRightOutlined,
250
"angle-down": DownOutlined,
251
"angle-right": RightOutlined,
252
"arrow-circle-o-left": { IconFont: "arrowcircleoleft" },
253
"arrow-circle-down": DownCircleOutlined,
254
"arrow-circle-up": UpCircleOutlined,
255
"arrow-down": ArrowDownOutlined,
256
"arrow-left": ArrowLeftOutlined,
257
"arrow-right": ArrowRightOutlined,
258
"arrow-up": ArrowUpOutlined,
259
atom: { IconFont: "Atom" },
260
api: ApiOutlined,
261
audio: AudioOutlined,
262
aws: { IconFont: "aws" },
263
backward: BackwardOutlined,
264
"battery-empty": { IconFont: "battery-empty" },
265
"battery-quarter": { IconFont: "battery-quarter" },
266
"battery-half": { IconFont: "battery-half" },
267
"battery-three-quarters": { IconFont: "battery-three-quarters" },
268
"battery-full": { IconFont: "battery-full" },
269
ban: StopOutlined,
270
bank: BankOutlined,
271
bars: { IconFont: "bars" },
272
bell: BellFilled,
273
"bell-o": BellOutlined,
274
blog: { IconFont: "blog" },
275
bold: BoldOutlined,
276
bolt: ThunderboltOutlined,
277
book: BookOutlined,
278
briefcase: { IconFont: "briefcase" },
279
brush: { IconFont: "brush" },
280
bullhorn: { IconFont: "bullhorn" },
281
bug: BugOutlined,
282
calculator: CalculatorOutlined,
283
calendar: CalendarOutlined,
284
"calendar-week": { IconFont: "calendar-week" },
285
"calendar-check": { IconFont: "calendar-check" },
286
"calendar-times": { IconFont: "calendar-times" },
287
camera: CameraOutlined,
288
"caret-down": CaretDownFilled,
289
"caret-left": CaretLeftFilled,
290
"caret-right": CaretRightFilled,
291
"caret-up": CaretUpFilled,
292
"caret-square-left": LeftSquareFilled,
293
"caret-square-right": RightSquareFilled,
294
"cc-discover": { IconFont: "cc-discover" },
295
"cc-mastercard": { IconFont: "cc-mastercard" },
296
"cc-visa": { IconFont: "cc-visa" },
297
"cc-stripe": { IconFont: "cc-stripe" },
298
areaChart: AreaChartOutlined,
299
check: CheckOutlined,
300
"check-circle": CheckCircleOutlined,
301
"check-square": CheckSquareOutlined,
302
"check-square-o": CheckSquareOutlined,
303
"chevron-down": DownOutlined,
304
"chevron-left": LeftOutlined,
305
"chevron-right": RightOutlined,
306
"chevron-circle-right": RightCircleFilled,
307
"chevron-up": UpOutlined,
308
circle: { IconFont: "circle" },
309
"circle-notch": LoadingOutlined,
310
clipboard: { IconFont: "clipboard" },
311
"clipboard-check": { IconFont: "clipboard-check" },
312
clock: ClockCircleOutlined,
313
"close-circle-two-tone": CloseCircleTwoTone,
314
"close-circle-filled": CloseCircleFilled,
315
clone: { IconFont: "clone" },
316
cloud: CloudFilled,
317
"cloud-dev": { IconFont: "cloud-dev" },
318
"cloud-download": CloudDownloadOutlined,
319
"cloud-download-alt": CloudDownloadOutlined,
320
"cloud-upload": CloudUploadOutlined,
321
"cocalc-ring": { IconFont: "cocalc-ring" },
322
code: { IconFont: "code" },
323
"code-outlined": CodeOutlined,
324
CodeOutlined,
325
coffee: CoffeeOutlined,
326
cog: ControlOutlined,
327
cogs: ControlOutlined,
328
colors: { IconFont: "colors" },
329
ColumnHeightOutlined,
330
ColumnWidthOutlined,
331
comment: CommentOutlined,
332
comments: CommentOutlined,
333
compass: CompassOutlined,
334
compress: ShrinkOutlined,
335
container: ContainerOutlined,
336
copy: CopyOutlined,
337
"credit-card": CreditCardOutlined,
338
csv: { IconFont: "csv" },
339
cube: { IconFont: "cube" },
340
cut: ScissorOutlined,
341
dashboard: DashboardOutlined,
342
database: DatabaseOutlined,
343
"database-filled": DatabaseFilled,
344
"deployment-unit": DeploymentUnitOutlined,
345
dedicated: DatabaseOutlined, // icon for "dedicated resources", looks like a server rack
346
desktop: DesktopOutlined,
347
"delivered-procedure-outlined": DeliveredProcedureOutlined,
348
digitalocean: { IconFont: "digitalocean" },
349
discord: { IconFont: "discord" },
350
"disk-drive": { IconFont: "disk-drive" },
351
"disk-round": { IconFont: "disk-round" },
352
"disk-snapshot": { IconFont: "disk-snapshot" },
353
dns: { IconFont: "dns" },
354
docker: { IconFont: "docker" },
355
download: DownloadOutlined,
356
"dot-circle": { IconFont: "dot-circle" },
357
edit: EditOutlined,
358
"edit-filled": EditFilled,
359
eraser: { IconFont: "Eraser-Tool" },
360
ellipsis: EllipsisOutlined,
361
envelope: { IconFont: "envelope" },
362
exchange: { IconFont: "exchange" },
363
"exclamation-circle": ExclamationCircleFilled,
364
"exclamation-triangle": WarningOutlined,
365
expand: ExpandOutlined,
366
"expand-arrows": ArrowsAltOutlined,
367
experiment: ExperimentOutlined,
368
"external-link": { IconFont: "external-link-alt" },
369
eye: EyeOutlined,
370
"eye-slash": EyeInvisibleOutlined,
371
"facebook-filled": FacebookFilled,
372
facebook: FacebookOutlined,
373
file: FileOutlined,
374
"file-archive": FileZipOutlined,
375
"file-alt": FileTextOutlined,
376
"file-code": FileTextOutlined,
377
"file-image": FileImageOutlined,
378
"file-pdf": FilePdfOutlined,
379
"file-zip": FileZipOutlined,
380
files: CopyOutlined,
381
"file-export": ExportOutlined,
382
fire: FireOutlined,
383
firefox: { IconFont: "firefox" },
384
flash: ThunderboltOutlined,
385
"flow-chart": { IconFont: "flow-chart" },
386
folder: FolderOutlined,
387
"folder-open": FolderOpenOutlined,
388
font: { IconFont: "font" },
389
"font-size": FontSizeOutlined,
390
forward: ForwardOutlined,
391
frame: { IconFont: "frame" },
392
frown: FrownOutlined,
393
fx: FunctionOutlined,
394
slides: FundProjectionScreenOutlined,
395
"project-outlined": ProjectOutlined,
396
"gateway-outlined": GatewayOutlined,
397
gavel: { IconFont: "gavel" },
398
gears: ControlOutlined,
399
gear: ControlOutlined,
400
gift: GiftOutlined,
401
gift2: GiftTwoTone,
402
"github-filled": GithubFilled,
403
github: GithubOutlined,
404
git: { IconFont: "git1" },
405
"git-square": { IconFont: "git-square" },
406
global: GlobalOutlined,
407
emacs: { IconFont: "gnuemacs" },
408
google: GoogleOutlined,
409
googlecloud: { IconFont: "googlecloud" },
410
"graduation-cap": { IconFont: "graduation" },
411
graph: { IconFont: "graph" },
412
grass: { IconFont: "grass" },
413
group: { IconFont: "group" },
414
"group-outlined": GroupOutlined,
415
gpu: { IconFont: "gpu" },
416
hand: { IconFont: "hand" },
417
"hand-stop": PoweroffOutlined,
418
header: { IconFont: "header" },
419
heart: { IconFont: "heart" },
420
hdd: HddOutlined,
421
highlighter: HighlightOutlined,
422
history: HistoryOutlined,
423
home: HomeOutlined,
424
"horizontal-split": { IconFont: "horizontal-split" },
425
"hourglass-half": HourglassOutlined,
426
html5: Html5Outlined,
427
image: { IconFont: "image" },
428
icons: { IconFont: "icons" },
429
"info-circle": InfoCircleOutlined,
430
indent: { IconFont: "indent" },
431
info: InfoOutlined,
432
inkscape: { IconFont: "inkscape" },
433
"instagram-filled": InstagramFilled,
434
instagram: InstagramOutlined,
435
ipynb: { IconFont: "ipynb" },
436
italic: ItalicOutlined,
437
"js-square": { IconFont: "js-square" },
438
julia: { IconFont: "julia" },
439
jupyter: { IconFont: "ipynb" },
440
key: KeyOutlined,
441
keyboard: { IconFont: "keyboard" },
442
laptop: LaptopOutlined,
443
layout: LayoutOutlined,
444
"skull-crossbones": { IconFont: "leave_conference" },
445
libreoffice: { IconFont: "libreoffice" },
446
"life-ring": { IconFont: "life-ring" },
447
"life-saver": { IconFont: "life-ring" },
448
lightbulb: BulbOutlined,
449
"line-chart": LineChartOutlined,
450
link: LinkOutlined,
451
"linkedin-filled": LinkedinFilled,
452
linkedin: LinkedinOutlined,
453
linux: { IconFont: "linux" },
454
list: UnorderedListOutlined,
455
"list-ul": UnorderedListOutlined,
456
"list-alt": UnorderedListOutlined,
457
"list-ol": OrderedListOutlined,
458
"lock-open": UnlockFilled,
459
lock: LockFilled,
460
"lock-outlined": LockOutlined,
461
magic: { IconFont: "magic" },
462
mail: MailOutlined,
463
map: { IconFont: "map" },
464
markdown: { IconFont: "markdown" },
465
mask: { IconFont: "mask" },
466
maple: { IconFont: "maple" },
467
mathematica: { IconFont: "mathematica" },
468
matlab: { IconFont: "matlab" },
469
medkit: MedicineBoxOutlined,
470
"menu-outlined": MenuOutlined,
471
meh: MehOutlined,
472
microchip: { IconFont: "microchip" },
473
microsoft: { IconFont: "microsoft" },
474
"minus-circle": MinusCircleOutlined,
475
"minus-square": MinusSquareOutlined,
476
money: CreditCardOutlined,
477
"money-check": { IconFont: "money-check" },
478
mousepointer: { IconFont: "mousepointer" },
479
move: { IconFont: "move" },
480
arrows: { IconFont: "move" }, // fa-arrows is used by the bqplot custom widget
481
network: { IconFont: "network" },
482
"network-server": { IconFont: "network-server" },
483
"network-wired": ClusterOutlined,
484
"node-js": { IconFont: "node-js" },
485
note: { IconFont: "note-text" },
486
nvidia: { IconFont: "nvidia" },
487
octave: { IconFont: "octave" },
488
overview: AppstoreOutlined,
489
outdent: { IconFont: "outdent" },
490
pause: PauseCircleOutlined,
491
"paper-plane": SendOutlined,
492
paste: { IconFont: "paste" },
493
"pic-centered": PicCenterOutlined,
494
pen: { IconFont: "pen" },
495
pencil: EditOutlined,
496
"pencil-alt": EditOutlined,
497
percentage: PercentageOutlined,
498
"pie-chart": PieChartOutlined,
499
play: PlayCircleOutlined,
500
"play-circle": PlayCircleFilled,
501
"play-square": PlaySquareOutlined,
502
plus: PlusOutlined,
503
minus: MinusOutlined,
504
"plus-circle": PlusCircleOutlined,
505
"plus-circle-o": PlusCircleOutlined,
506
"plus-circle-filled": PlusCircleFilled,
507
"plus-one": { IconFont: "plus-one" },
508
"plus-square": PlusSquareOutlined,
509
"plus-square-o": PlusSquareOutlined,
510
PoweroffOutlined,
511
print: PrinterOutlined,
512
python: { IconFont: "python" },
513
pytorch: { IconFont: "pytorch" },
514
qgis: { IconFont: "qgis" },
515
"question-circle": QuestionCircleOutlined,
516
"quote-left": { IconFont: "quote-left" },
517
r: { IconFont: "r" },
518
racket: { IconFont: "racket" },
519
redo: RedoOutlined,
520
refresh: RedoOutlined,
521
reload: ReloadOutlined,
522
remove: CloseOutlined,
523
repeat: RedoOutlined,
524
replace: { IconFont: "find-replace" },
525
reply: { IconFont: "reply" },
526
retweet: RetweetOutlined,
527
robot: RobotOutlined,
528
rocket: RocketOutlined,
529
run: { IconFont: "run" },
530
sagemath: { IconFont: "sagemath" },
531
"sagemath-bold": { IconFont: "sagemath-bold" },
532
"sagemath-file": { IconFont: "sagemath-file" },
533
save: SaveOutlined,
534
scheme: { IconFont: "scheme" },
535
scissors: ScissorOutlined,
536
search: SearchOutlined,
537
"search-minus": ZoomOutOutlined,
538
"search-plus": ZoomInOutlined,
539
"select-outlined": SelectOutlined,
540
settings: SettingOutlined,
541
server: CloudServerOutlined,
542
servers: { IconFont: "servers" },
543
"sign-in": LoginOutlined,
544
"sign-out-alt": LoginOutlined, // Yes, since the logout one breaks darkreader, weirdly! they both look reasonable.
545
sitemap: ClusterOutlined,
546
"share-square": ShareAltOutlined,
547
"shopping-cart": ShoppingCartOutlined,
548
sliders: SlidersOutlined,
549
smile: SmileOutlined,
550
"sort-amount-up": { IconFont: "sort-amount-up" },
551
spinner: { IconFont: "cocalc-ring" },
552
square: BorderOutlined,
553
solution: SolutionOutlined,
554
"square-o": BorderOutlined,
555
"square-root-alt": { IconFont: "square-root-alt" },
556
"star-filled": StarFilled,
557
star: StarOutlined,
558
"step-backward": StepBackwardOutlined,
559
"step-forward": StepForwardOutlined,
560
stop: { IconFont: "stop" }, // the ant-design "stop" looks weird.
561
"stop-filled": StopFilled,
562
stopwatch: FieldTimeOutlined,
563
store: { IconFont: "store" },
564
strikethrough: StrikethroughOutlined,
565
subscript: { IconFont: "subscript" },
566
sun: { IconFont: "sun" },
567
superscript: { IconFont: "superscript" },
568
support: { IconFont: "life-ring" },
569
sync: { IconFont: "sync" },
570
"sync-alt": SyncOutlined,
571
tab: { IconFont: "tab" },
572
table: TableOutlined,
573
"tachometer-alt": DashboardOutlined,
574
tasks: { IconFont: "tasks" },
575
"tag-outlined": TagOutlined,
576
"tags-outlined": TagsOutlined,
577
"tag-filled": TagFilled,
578
"tags-filled": TagsFilled,
579
"tag-two-tone": TagTwoTone,
580
"tags-two-tone": TagsTwoTone,
581
"team-outlined": TeamOutlined,
582
tensorflow: { IconFont: "tensorflow" },
583
terminal: CodeOutlined,
584
tex: { IconFont: "tex" },
585
text: { IconFont: "text" },
586
text1: { IconFont: "text1" },
587
"tex-file": { IconFont: "tex-file" },
588
"text-height": LineHeightOutlined,
589
times: CloseOutlined,
590
"times-circle": CloseCircleOutlined,
591
"times-rectangle": { IconFont: "times-rectangle" },
592
"thumbs-down": { IconFont: "thumbs-down" },
593
"thumbs-up": { IconFont: "thumbs-up" },
594
"toggle-off": { IconFont: "toggle-off" },
595
"toggle-on": { IconFont: "toggle-on" },
596
tool: ToolOutlined,
597
trash: DeleteOutlined,
598
"twitter-filled": XOutlined,
599
twitter: XOutlined,
600
ubuntu: { IconFont: "ubuntu" },
601
underline: UnderlineOutlined,
602
undo: UndoOutlined,
603
ungroup: { IconFont: "ungroup" },
604
"signature-outlined": SignatureOutlined,
605
swap: SwapOutlined,
606
"sync-left": SwapLeftOutlined,
607
"sync-right": SwapRightOutlined,
608
unlink: { IconFont: "unlink" },
609
upload: UploadOutlined,
610
user: UserOutlined,
611
"user-secret": { IconFont: "user-secret" },
612
UserAddOutlined,
613
"user-check": { IconFont: "user-check" },
614
"user-plus": UsergroupAddOutlined,
615
"user-slash": { IconFont: "user-slash" },
616
"user-times": UserDeleteOutlined,
617
users: UsergroupAddOutlined,
618
"vertical-split": { IconFont: "vertical-split" },
619
"vertical-right-outlined": VerticalRightOutlined,
620
"video-camera": VideoCameraOutlined,
621
"vertical-align-middle": VerticalAlignMiddleOutlined,
622
"vertical-align-bottom": VerticalAlignBottomOutlined,
623
"vertical-left-outlined": VerticalLeftOutlined,
624
vim: { IconFont: "vim" },
625
vscode: { IconFont: "vscode" },
626
wallet: WalletOutlined,
627
warning: WarningOutlined,
628
wifi: WifiOutlined,
629
"window-maximize": { IconFont: "window-maximize" },
630
"window-restore": DesktopOutlined, // we only use for x11 and this has big X.
631
wrench: { IconFont: "wrench" },
632
youtube: YoutubeOutlined,
633
"youtube-filled": YoutubeFilled,
634
"left-circle-o": LeftCircleOutlined,
635
"right-circle-o": RightCircleOutlined,
636
"down-circle-o": DownCircleOutlined,
637
"translation-outlined": TranslationOutlined,
638
"clean-outlined": ClearOutlined,
639
"sound-outlined": SoundOutlined,
640
"rise-outlined": RiseOutlined,
641
"up-square-outlined": UpSquareOutlined,
642
"down-square-outlined": DownSquareOutlined,
643
"merge-cells-outlined": MergeCellsOutlined,
644
"fork-outlined": ForkOutlined,
645
"to-top-outlined": ToTopOutlined,
646
"column-width": ColumnWidthOutlined,
647
"column-height": ColumnHeightOutlined,
648
} as const;
649
650
// Icon Fonts coming from https://www.iconfont.cn/?lang=en-us
651
import { createFromIconfontCN } from "@ant-design/icons";
652
export let IconFont: any = undefined;
653
try {
654
if (typeof window != "undefined") {
655
// obviously won't work if window is undefined based on looking at the code...
656
// This loads a bunch of svg elements of the form <svg id="icon-<name>"... into the DOM.
657
// The antd Icon code then duplicates these via the <use> html tag
658
// (https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use)
659
require("./iconfont.cn");
660
// note -- we do NOT pass scriptUrl in, as in the docs! Why? Because
661
// we want everything bundled up into webpack, rather than having to pull
662
// from some random place, which just causes confusion with releases
663
// and caching. Fortunately, just evaluating the js from iconfont, then
664
// running createFromIconfontCN with no arguments does work, as I deduced
665
// by reading the code, then trying this.
666
// https://github.com/ant-design/ant-design-icons/blob/5be2afd296636ab4cfec5d3a2793d6cd41b1789b/packages/icons-vue/src/components/IconFont.tsx
667
668
IconFont = createFromIconfontCN();
669
670
// It would be easy to screw up and put an entry like
671
// "arrow-circle-o-left": { IconFont: "arrowcircleoleft" }
672
// in IconSpec, but forget to actually include "arrowcircleoleft" in
673
// iconfont.cn, or -- just as bad -- make a typo or put the wrong name in.
674
// So we double check that all iconfonts are actually defined here:
675
if (typeof DEBUG != "undefined" && DEBUG) {
676
setTimeout(() => {
677
// only do this during dev to save time.
678
for (const name in IconSpec) {
679
const spec = IconSpec[name];
680
const x = spec?.IconFont;
681
if (x != null) {
682
const id = `icon-${x}`;
683
if (document.getElementById(id) == null) {
684
console.error(
685
`ERROR -- the IconFont ${x} is not in components/iconfont.cn! Fix this or the icon ${name} will be broken.`,
686
);
687
}
688
}
689
}
690
}, 5000);
691
}
692
}
693
} catch (err) {
694
// Might as well have option for a graceful fallback, e.g., when
695
// used from node.js...
696
if (!process.env.COCALC_TEST_MODE) {
697
console.log(`IconFont not available -- ${err}`);
698
}
699
}
700
701
// This used to exceed TypeScript limits, but apparently it is ok now…
702
export type IconName = keyof typeof IconSpec;
703
export const IconName = undefined; // Javascript needs this, though we are only using IconName for the type
704
705
// Typeguard so can tell if a string is name of an icon and also
706
// make typescript happy.
707
export function isIconName(name?: unknown): name is IconName {
708
if (name == null) return false;
709
if (typeof name !== "string") return false;
710
return IconSpec[name] != null;
711
}
712
713
export const iconNames: IconName[] = Object.keys(IconSpec) as any;
714
715
export type IconRotation = "45" | "90" | "135" | "180" | "225" | "270" | "315";
716
717
interface Props {
718
name?: IconName;
719
unicode?: number; // (optional) set a hex 16 bit charcode to render a unicode char, e.g. 0x2620
720
className?: string;
721
size?: "lg" | "2x" | "3x" | "4x" | "5x";
722
rotate?: IconRotation;
723
flip?: "horizontal" | "vertical";
724
spin?: boolean;
725
pulse?: boolean;
726
stack?: "1x" | "2x";
727
inverse?: boolean;
728
style?: CSS;
729
onClick?: (event?: React.MouseEvent) => void; // https://fettblog.eu/typescript-react/events/
730
onMouseOver?: () => void;
731
onMouseOut?: () => void;
732
onMouseEnter?: () => void;
733
onMouseLeave?: () => void;
734
}
735
736
const UNICODE_STYLE = {
737
fontSize: "120%",
738
fontWeight: "bold",
739
lineHeight: "1",
740
verticalAlign: "middle",
741
} as React.CSSProperties;
742
743
const missing: any = {};
744
// Converted from https://github.com/andreypopp/react-fa
745
746
export const Icon: React.FC<Props> = (props: Props) => {
747
// IMPORTANT: This hook is needed for next.js to support server side rendering.
748
// Otherwise, at least with next 13, it crashes when rendering icons.
749
const onFrontend = useOnFrontend();
750
if (!onFrontend) return null;
751
752
if (props.unicode != null) {
753
const style: React.CSSProperties = { ...UNICODE_STYLE, ...props.style };
754
755
// Apply CSS transformations for unicode characters
756
if (props.rotate) {
757
style.display = style.display ?? "inline-block";
758
style.transform = `rotate(${props.rotate}deg)`;
759
}
760
if (props.flip) {
761
style.display = style.display ?? "inline-block";
762
const flipTransform =
763
props.flip === "horizontal" ? "scaleX(-1)" : "scaleY(-1)";
764
style.transform = style.transform
765
? `${style.transform} ${flipTransform}`
766
: flipTransform;
767
}
768
769
return (
770
<span style={style}>
771
{String.fromCharCode(props.unicode!)}
772
</span>
773
);
774
}
775
776
let name: IconName = props.name ?? "square";
777
let C;
778
C = IconSpec[name];
779
if (C == null && name.endsWith("-o")) {
780
// should be impossible because of typescript...
781
// try without -o
782
C = IconSpec[name.slice(0, name.length - 2)];
783
}
784
if (C != null) {
785
if (typeof C.IconFont == "string") {
786
// @ts-ignore
787
if (IconFont == null) {
788
return <span>(IconFonts not available)</span>;
789
}
790
return <IconFont type={"icon-" + C.IconFont} {...props} alt={name} />;
791
}
792
return <C {...props} alt={name} />;
793
}
794
795
// this is when the icon is broken.
796
if (typeof DEBUG != "undefined" && DEBUG) {
797
if (missing[props.name ?? ""] == null) {
798
missing[props.name ?? ""] = true;
799
console.warn(
800
`Icon "${props.name}" is not defined -- fix this in components/icon.tsx.`,
801
);
802
}
803
// make it hopefully clear to devs that this icon is broken
804
return (
805
<span
806
style={{ background: "red", color: "white" }}
807
className="blink"
808
title={`Icon "${props.name}" is not defined -- fix this in components/icon.tsx.`}
809
>
810
{/* @ts-ignore */}
811
<BugOutlined {...props} alt={name} />
812
</span>
813
);
814
} else {
815
// In production, just show a very generic icon so the user
816
// doesn't realize we messed up.
817
// @ts-ignore
818
return <BorderOutlined {...props} alt={name} />;
819
}
820
};
821
822
// TOOD move this to a shared lib, which can import the IconName type
823
export const PAYASYOUGO_ICON: IconName = "compass";
824
825