Skip to content

Commit

Permalink
fix: logs color in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lideming committed Nov 27, 2023
1 parent f0c42f7 commit c4a11c1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
34 changes: 32 additions & 2 deletions neetbox/frontend/src/components/dashboard/project/logs.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
[theme-mode="dark"] .log-tag {
background-color: #333;
.log-item {
margin-bottom: 5px;
font-family: "Courier New", Courier, monospace;
font-size: 13px;

.log-tag {
display: inline-block;
--log-tag-bg-hs: 0, 0%;
--log-tag-bg-l: 80%;
background-color: hsl(var(--log-tag-bg-hs), var(--log-tag-bg-l));
padding: 0 3px;
border-radius: 5px;
}
.log-prefix-info {
--log-tag-bg-hs: 222, 80%;
}
.log-prefix-ok {
--log-tag-bg-hs: 128, 80%;
}
.log-prefix-warning {
--log-tag-bg-hs: 55, 80%;
}
.log-prefix-debug {
--log-tag-bg-hs: 277, 80%;
}
.log-prefix-error {
--log-tag-bg-hs: 0, 80%;
}
}

[theme-mode="dark"] .log-item .log-tag {
--log-tag-bg-l: 30%;
}
35 changes: 3 additions & 32 deletions neetbox/frontend/src/components/dashboard/project/logs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
import { styled } from "styled-components";
import { LogData, useProjectLogs } from "../../../services/projects";
import "./logs.css";

Expand Down Expand Up @@ -51,34 +50,6 @@ const LogItems = ({ logs }: { logs: LogData[] }) => {
return logs.map((x) => <LogItem key={x._id} data={x} />);
};

const LogItemContainer = styled.div`
margin-bottom: 5px;
font-family: "Courier New", Courier, monospace;
font-size: 13px;
.log-tag {
display: inline-block;
background-color: #ddd;
padding: 0 3px;
border-radius: 5px;
}
.log-prefix-info {
background-color: #bbcffc;
}
.log-prefix-ok {
background-color: #a2ffae;
}
.log-prefix-warning {
background-color: #ede483;
}
.log-prefix-debug {
background-color: #c483ed;
}
.log-prefix-error {
background-color: #ffa2a2;
}
`;

function getColorFromWhom(whom: string) {
const hue =
50 +
Expand All @@ -87,14 +58,14 @@ function getColorFromWhom(whom: string) {
.reduce((prev, char) => ((prev * 11) % 360) + char.charCodeAt(0), 0) *
233) %
200);
return `hsl(${hue}, 70%, 80%)`;
return `hsl(${hue}, 70%, var(--log-tag-bg-l))`;
}

const LogItem = React.memo(({ data }: { data: LogData }) => {
let { prefix } = data;
if (!prefix) prefix = "log";
return (
<LogItemContainer>
<div className="log-item">
<span className="log-tag log-datetime">{data.datetime}</span>{" "}
<span className={`log-tag log-prefix log-prefix-${prefix}`}>
{prefix}
Expand All @@ -106,6 +77,6 @@ const LogItem = React.memo(({ data }: { data: LogData }) => {
{data.whom}
</span>{" "}
{data.msg}
</LogItemContainer>
</div>
);
});

0 comments on commit c4a11c1

Please sign in to comment.