Skip to content

Commit ab008b2

Browse files
authored
refactor: add styled-components to secretnote (#25)
* refactor: add styled-components to secretnote * refactor: add styled-components to secretnote
1 parent 9749053 commit ab008b2

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

packages/secretnote/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"monaco-editor-webpack-plugin": "^7.1.0",
6969
"smoothie": "^1.36.1",
7070
"sql-formatter": "^15.0.2",
71+
"styled-components": "^6.1.0",
7172
"syntax-parser": "^1.0.18",
7273
"tippy.js": "^6.3.7",
7374
"tiptap-markdown": "^0.8.2",

packages/secretnote/src/components/sh-viewer/index.tsx

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import hljs from 'highlight.js';
22
import { useEffect } from 'react';
3-
3+
import styled from 'styled-components';
44
import 'highlight.js/styles/a11y-dark.css';
55

6+
const CodeWrapper = styled.pre`
7+
background: #2b2b2b;
8+
padding: 12px 0;
9+
border-radius: 8px;
10+
11+
code {
12+
padding: 0 1em !important;
13+
}
14+
`;
15+
616
interface IProps {
717
code: string;
818
className?: string;
@@ -15,11 +25,9 @@ const ShViewer = ({ code }: IProps) => {
1525
}, []);
1626

1727
return (
18-
<pre style={{ background: '#2b2b2b', padding: '12px 0', borderRadius: 8 }}>
19-
<code className="language-bash" style={{ padding: '0 1em' }}>
20-
{code}
21-
</code>
22-
</pre>
28+
<CodeWrapper>
29+
<code className="language-bash">{code}</code>
30+
</CodeWrapper>
2331
);
2432
};
2533

packages/secretnote/src/modules/file/jsonl-preview-contrib.tsx

+24-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
import { singleton } from '@difizen/mana-app';
22
import hljs from 'highlight.js';
33
import { useEffect } from 'react';
4+
import styled from 'styled-components';
45

56
import { FilePreviewContribution } from './protocol';
67
import 'highlight.js/styles/xcode.css'; // 选择主题 https://highlightjs.org/demo
78

9+
const CodeWrapper = styled.pre`
10+
width: 100%;
11+
height: 100%;
12+
overflow: scroll;
13+
margin: 0;
14+
15+
.line-number {
16+
float: left;
17+
text-align: right;
18+
margin-right: 12px;
19+
color: #bfbfbf;
20+
user-select: none;
21+
}
22+
23+
code {
24+
padding: 0 1em !important;
25+
}
26+
`;
27+
828
const JsonlView = (props: { data: string }) => {
929
useEffect(() => {
1030
hljs.highlightAll();
@@ -18,22 +38,10 @@ const JsonlView = (props: { data: string }) => {
1838
.join('');
1939

2040
return (
21-
<pre style={{ width: '100%', height: '100%', overflow: 'scroll', margin: 0 }}>
22-
<span
23-
style={{
24-
float: 'left',
25-
textAlign: 'right',
26-
marginRight: 12,
27-
color: '#bfbfbf',
28-
userSelect: 'none',
29-
}}
30-
>
31-
{lineNumber}
32-
</span>
33-
<code className="language-json" style={{ padding: '0 1em' }}>
34-
{props.data}
35-
</code>
36-
</pre>
41+
<CodeWrapper>
42+
<span className="line-number">{lineNumber}</span>
43+
<code className="language-json">{props.data}</code>
44+
</CodeWrapper>
3745
);
3846
};
3947

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)