-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogEntries.js
40 lines (33 loc) · 997 Bytes
/
LogEntries.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
import React from "react";
import "./LogEntries.css";
import { view } from "@risingstack/react-easy-state";
import { VscInfo, VscWarning, VscError } from "react-icons/vsc";
export const ArrayLogger = function () {
const entries = [];
this.log = message => entries.push({ level: "info", message: message });
this.warn = message => entries.push({ level: "warning", message: message });
this.error = message => entries.push({ level: "error", message: message });
this.getEntries = () => entries.slice(0);
};
const LEVEL_ICONS = {
error: () => <VscError />,
warning: () => <VscWarning />,
info: () => <VscInfo />
};
export const LogEntry = ({ entry }) => {
const { level, message } = entry;
return (
<div className={`LogEntry LogEntry-${level}`}>
{LEVEL_ICONS[level]()} {message}
</div>
);
};
export const LogEntries = view(({ entries }) => {
return (
<>
{entries.map((e, i) => (
<LogEntry entry={e} key={i} />
))}
</>
);
});