Skip to content

Commit

Permalink
feat: Modify markdown editor style
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyxh committed Aug 14, 2024
1 parent a909a72 commit 66256ef
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 219 deletions.
96 changes: 96 additions & 0 deletions src/assets/iconfont/md-editor/iconfont.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
@font-face {
font-family: 'iconfont'; /* Project id 4145942 */
/* Color fonts */
src:
url('iconfont.woff2?t=1689582142318') format('woff2'),
url('iconfont.woff?t=1689582142318') format('woff'),
url('iconfont.ttf?t=1689582142318') format('truetype');
}

.iconfont {
font-family: 'iconfont' !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

.icon-dian:before {
content: '\e640';
}

.icon-xuanzeyixuan:before {
content: '\e63c';
}

.icon-danger:before {
content: '\e614';
}

.icon-Success:before {
content: '\e605';
}

.icon-warning:before {
content: '\e600';
}

.icon-info:before {
content: '\e601';
}

.icon-dingwei:before {
content: '\e650';
}

.icon-wenjian:before {
content: '\e652';
}

.icon-shuju:before {
content: '\e653';
}

.icon-biaoqian:before {
content: '\e64a';
}

.icon-biaoqing:before {
content: '\e64b';
}

.icon-jinggao:before {
content: '\e64c';
}

.icon-dianzan:before {
content: '\e64d';
}

.icon-xiangqing:before {
content: '\e64e';
}

.icon-tishi:before {
content: '\e64f';
}

.icon-bangzhu:before {
content: '\e651';
}

.icon-wenjianjia:before {
content: '\e652';
}

.icon-touxiang:before {
content: '\e626';
}

.icon-jiedian:before {
content: '\e649';
}

.icon-cengji:before {
content: '\e67f';
}
Binary file added src/assets/iconfont/md-editor/iconfont.ttf
Binary file not shown.
Binary file added src/assets/iconfont/md-editor/iconfont.woff
Binary file not shown.
Binary file added src/assets/iconfont/md-editor/iconfont.woff2
Binary file not shown.
2 changes: 1 addition & 1 deletion src/components/Dialog/Dialog.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
left: 0;
display: flex;
width: 100%;
height: 30px;
height: 40px;
}

.header .bar {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const Dialog = forwardRef<IDialogExpose, Readonly<IDialogProps>>(function Dialog

return (
<>
<div aria-hidden style={{ width: '100%', height: 30 }}></div>
<div aria-hidden style={{ width: '100%', height: 40 }}></div>
<header className={styles.header}>
<div
className={styles.bar}
Expand Down
18 changes: 12 additions & 6 deletions src/filehandle/components/FileSideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,18 @@ function Menu({
}
>
{item.type === FileType.DIRECTORY ? (
<Icon
className={classNames(styles.directoryIcon, {
[styles.expand]: expands.includes(item.id)
})}
icon="material-symbols:keyboard-arrow-right"
/>
<>
<Icon
className={classNames(styles.directoryIcon, {
[styles.expand]: expands.includes(item.id)
})}
icon="material-symbols:keyboard-arrow-right"
/>
<Icon
className={classNames(styles.directoryIcon)}
icon="material-symbols-light:folder"
/>
</>
) : null}

<span>{item.name}</span>
Expand Down
5 changes: 3 additions & 2 deletions src/filehandle/components/styles/FileSideMenu.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
user-select: none;

span {
margin-left: 8px;
margin-left: 18px;
}

.directoryIcon + span {
margin-left: 0;
margin-left: 3px;
}

> .list {
Expand All @@ -63,6 +63,7 @@
}

.list .item .row {
padding-block: 2px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Expand Down
28 changes: 18 additions & 10 deletions src/filehandle/md_editor/component/MDContent.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { HTMLAttributes } from 'react';
import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';

import { addGlobalListener, confirm, error } from '@/utils';
Expand All @@ -11,7 +12,7 @@ import type { IMDEditorExpose } from './MDEditor';
import MDEditor from './MDEditor';
import styles from './styles/MDContent.module.less';

interface IMDContentProps {
interface IMDContentProps extends HTMLAttributes<HTMLDivElement> {
handle: DH | FH;
update(): void;
}
Expand All @@ -22,7 +23,7 @@ export interface IMDContentExpose {

export const MDContent = forwardRef<IMDContentExpose, IMDContentProps>(
function MDContent(props, ref) {
const { handle, update } = props;
const { handle, update, ...rest } = props;

const [changed, setChanged] = useState(false);
const [currentHandle, setCurrentHandle] = useState<FH | null>(null);
Expand Down Expand Up @@ -127,7 +128,7 @@ export const MDContent = forwardRef<IMDContentExpose, IMDContentProps>(
};

return (
<div className={styles.content}>
<div className={styles.content} {...rest}>
{isDirectoryHandle(handle) ? (
<FileSideMenu
handle={handle}
Expand All @@ -140,13 +141,20 @@ export const MDContent = forwardRef<IMDContentExpose, IMDContentProps>(
) : null}

<div className={styles.mdEditor}>
<MDEditor
ref={editorRef}
currentHandle={currentHandle}
changed={changed}
onChanged={handleSetChanged}
onSave={handleSave}
/>
<div className={styles.editStatus}>
{currentHandle?.name}
{changed ? <span className={styles.changed}> - 已编辑</span> : null}
</div>

<div className={styles.editorWrapper}>
<MDEditor
ref={editorRef}
currentHandle={currentHandle}
changed={changed}
onChanged={handleSetChanged}
onSave={handleSave}
/>
</div>
</div>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion src/filehandle/md_editor/component/MDHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,12 @@ const MDHandle: React.FC<IMDHandle> = (props) => {
onMinimize={handleMinimize}
onClose={onClose}
>
<MDContent ref={mdContentRef} handle={handle} update={update} />
<MDContent
style={{ borderTop: '1px solid var(--border-color-primary)' }}
ref={mdContentRef}
handle={handle}
update={update}
/>
</Dialog>
);
};
Expand Down
29 changes: 28 additions & 1 deletion src/filehandle/md_editor/component/styles/MDContent.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,35 @@
}

.mdEditor {
position: relative;
padding: 0 50px 30px;
flex: 1;
height: 100%;
padding: 30px;
overflow-y: auto;
background-color: rgb(199, 229, 252);
}

.editStatus {
position: sticky;
top: 0;
height: 45px;
background-color: rgb(199, 229, 252);
text-align: center;
line-height: 45px;
font-weight: 700;
z-index: var(--z-normal);
}

.changed {
color: var(--color-info);
}

.editorWrapper {
margin: 4px auto;
max-width: 1140px;
padding: 30px;
background-color: #fff;
min-height: 100%;
border-radius: var(--border-radius-base);
box-shadow: 0 0 1px 4px #495060;
}
54 changes: 51 additions & 3 deletions src/filehandle/md_editor/component/styles/MDEditor.module.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import url('@/assets/iconfont/md-editor/iconfont.css');

.editorContainer {
:global(.milkdown) {
height: 100%;
Expand Down Expand Up @@ -47,17 +49,21 @@
h5,
h6 {
margin-bottom: 1em;
width: max-content;
font-weight: 600;
}

h1 {
width: 100%;
font-size: 38px;
line-height: 1.21;
text-align: center;
}

h2 {
font-size: 30px;
line-height: 1.266;
border-bottom: 3px solid #fe5f58;
}

h3 {
Expand Down Expand Up @@ -102,6 +108,25 @@
}
}

h1::before {
margin-right: 3px;
font-family: 'iconfont';
content: '\e626';
vertical-align: middle;
}

h2::before {
margin-right: 3px;
content: '#';
color: #fe5f58;
}

h3::before {
margin-right: 8px;
font-family: 'iconfont';
content: '\e67f';
}

strong {
font-weight: 600;
}
Expand Down Expand Up @@ -188,7 +213,7 @@
}

ul {
list-style: initial;
list-style: none;
}

// li[data-checked='false']::before {
Expand All @@ -199,6 +224,26 @@
// content: 'done';
// }

li {
position: relative;
}

li::before {
position: absolute;
top: 8px;
left: -20px;
display: inline-block;
content: '';
width: 8px;
height: 8px;
text-align: center;
vertical-align: middle;
color: #000;
background-color: #fff;
border: 2px solid #fe5f58;
border-radius: 50%;
}

pre {
position: relative;
z-index: var(--z-ignore);
Expand Down Expand Up @@ -238,9 +283,12 @@
}

img {
margin: 0 auto;
display: block;
max-width: 598px;
text-align: center;
max-width: 720px;
height: auto;
box-shadow: 0 0 5px 0px rgba(0, 0, 0, 0.18);
object-fit: cover;
}

a {
Expand Down
Loading

0 comments on commit 66256ef

Please sign in to comment.