Skip to content

Commit c913fbd

Browse files
committed
feat:将navbar和非markdown编辑器隐藏
1 parent 03a84e2 commit c913fbd

File tree

8 files changed

+136
-58
lines changed

8 files changed

+136
-58
lines changed

src/App.css

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,43 @@
66
font-size: 16px;
77
}
88

9-
.text-container {
9+
.nice-text-container {
1010
display: flex;
1111
height: 91vh;
1212
width: 100%;
1313
}
14+
15+
.nice-text-container-immersive {
16+
display: flex;
17+
height: 100vh;
18+
width: 100%;
19+
}
20+
21+
22+
.nice-md-editing-immersive {
23+
padding: 0px;
24+
width: 100%;
25+
}
26+
27+
.nice-md-editing-immersive .CodeMirror-lines {
28+
padding: 20px 10%;
29+
}
30+
1431
/* 编辑器最多会被分成三份width:33.3%,当两份时根据flex-grow:1伸展 */
15-
.text-box {
32+
.nice-md-editing, .nice-style-editing {
1633
width: 33.3%;
1734
flex-grow: 1;
1835
padding: 0 20px 20px 20px;
1936
word-wrap: break-word;
2037
}
2138

22-
#marked-text {
39+
.nice-marked-text {
2340
display: flex;
2441
justify-content: center;
42+
width: 33.3%;
43+
flex-grow: 1;
44+
padding: 0 20px 20px 20px;
45+
word-wrap: break-word;
2546
}
2647

2748
.wx-box {
@@ -45,3 +66,7 @@
4566
background: rgba(0, 0, 0, 0.12);
4667
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
4768
}
69+
70+
.nice-not-md-hide {
71+
display: none;
72+
}

src/App.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import CodeMirror from "@uiw/react-codemirror";
33
import "codemirror/keymap/sublime";
44
import "antd/dist/antd.css";
55
import {observer, inject} from "mobx-react";
6+
import classnames from "classnames";
67

78
import Dialog from "./layout/Dialog";
89
import Navbar from "./layout/Navbar";
@@ -159,20 +160,40 @@ class App extends Component {
159160
};
160161

161162
render() {
162-
const {codeNum, isStyleEditorOpen, previewType} = this.props.navbar;
163+
const {codeNum, isStyleEditorOpen, previewType, isImmersiveEditing} = this.props.navbar;
163164

164165
const parseHtml =
165166
codeNum === 0
166167
? markdownParserWechat.render(this.props.content.content)
167168
: markdownParser.render(this.props.content.content);
168169

170+
const mdEditingClass = classnames({
171+
"nice-md-editing": !isImmersiveEditing,
172+
"nice-md-editing-immersive": isImmersiveEditing,
173+
});
174+
175+
const styleEditingClass = classnames({
176+
"nice-style-editing": true,
177+
"nice-not-md-hide": isImmersiveEditing,
178+
});
179+
180+
const richTextClass = classnames({
181+
"nice-marked-text": true,
182+
"nice-not-md-hide": isImmersiveEditing,
183+
});
184+
185+
const textContainerClass = classnames({
186+
"nice-text-container": !isImmersiveEditing,
187+
"nice-text-container-immersive": isImmersiveEditing,
188+
});
189+
169190
return (
170191
<appContext.Consumer>
171192
{({defaultTitle}) => (
172193
<div className="App">
173194
<Navbar title={defaultTitle} />
174-
<div className="text-container">
175-
<div className="text-box" onMouseOver={(e) => this.setCurrentIndex(1, e)}>
195+
<div className={textContainerClass}>
196+
<div className={mdEditingClass} onMouseOver={(e) => this.setCurrentIndex(1, e)}>
176197
<CodeMirror
177198
value={this.props.content.content}
178199
options={{
@@ -192,7 +213,7 @@ class App extends Component {
192213
ref={this.getInstance}
193214
/>
194215
</div>
195-
<div id="marked-text" className="text-box" onMouseOver={(e) => this.setCurrentIndex(2, e)}>
216+
<div className={richTextClass} onMouseOver={(e) => this.setCurrentIndex(2, e)}>
196217
<div
197218
id={BOX_ID}
198219
className="wx-box"
@@ -215,7 +236,7 @@ class App extends Component {
215236
</div>
216237

217238
{isStyleEditorOpen ? (
218-
<div className="text-box">
239+
<div className={styleEditingClass}>
219240
<StyleEditor />
220241
</div>
221242
) : null}

src/component/FullScreen.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React, {Component} from "react";
22
import {Tooltip, Button} from "antd";
3+
import {observer, inject} from "mobx-react";
34

45
// import fullscreenIcon from "../icon/fullscreen.svg";
56
import {ENTER_DELAY, LEAVE_DELAY} from "../utils/constant";
67
import SvgIcon from "../icon";
78

9+
@inject("navbar")
10+
@observer
811
class FullScreen extends Component {
912
constructor(props) {
1013
super(props);
@@ -15,6 +18,9 @@ class FullScreen extends Component {
1518

1619
// fullScreen or !fullScreen
1720
toggleFullScreen = () => {
21+
const {isImmersiveEditing} = this.props.navbar;
22+
this.props.navbar.setImmersiveEditing(!isImmersiveEditing);
23+
1824
this.setState((prevState) => ({
1925
isFullScreen: !prevState.isFullScreen,
2026
}));

src/layout/Navbar.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.nice-navbar {
2+
height: 64px;
3+
display: flex;
4+
justify-content: space-between;
5+
flex: none;
6+
padding: 20px;
7+
position: relative;
8+
}
9+
10+
.nice-left-nav {
11+
display: flex;
12+
flex: 1;
13+
justify-content: flex-start;
14+
align-items: center;
15+
}
16+
17+
.nice-right-nav {
18+
display: flex;
19+
justify-content: flex-end;
20+
align-items: center;
21+
}
22+
23+
.nice-btn-group-margin {
24+
margin-right: 10px;
25+
}
26+
27+
.nice-btn-group-right {
28+
margin-right: 20px;
29+
}
30+
31+
.nice-icon-bar {
32+
margin-top: 5;
33+
}
34+
35+
.nice-title {
36+
margin-right: 20px;
37+
font-weight: bold;
38+
font-size: 16px;
39+
font-family: Apple Chancery, cursive;
40+
}
41+
42+
.nice-navbar-hide {
43+
display: none;
44+
}

src/layout/Navbar.js

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {Component} from "react";
22
import {observer, inject} from "mobx-react";
33
import {Button} from "antd";
4+
import classnames from "classnames";
45

56
import ThemeSelect from "../component/ThemeSelect";
67
import Format from "../component/Format";
@@ -20,38 +21,45 @@ import FullScreen from "../component/FullScreen";
2021
import About from "../component/About";
2122
import Font from "../component/Font";
2223

24+
import "./Navbar.css";
25+
2326
const ButtonGroup = Button.Group;
2427

2528
// @inject("userInfo")
26-
// @observer
29+
@inject("navbar")
30+
@observer
2731
class Navbar extends Component {
2832
render() {
2933
const {title} = this.props;
34+
const niceNavbarClass = classnames({
35+
"nice-navbar": true,
36+
"nice-navbar-hide": this.props.navbar.isImmersiveEditing,
37+
});
3038
return (
31-
<div style={style.navBar}>
32-
<div style={style.leftNav}>
33-
{title === "" ? null : <section style={style.title}>{title}</section>}
34-
<div style={style.iconBar}>
35-
<ButtonGroup style={style.btnGroupMargin}>
39+
<div className={niceNavbarClass}>
40+
<div className="nice-left-nav">
41+
{title === "" ? null : <section className="nice-title">{title}</section>}
42+
<div className="nice-icon-bar">
43+
<ButtonGroup className="nice-btn-group-margin">
3644
<Del />
3745
<Bold />
3846
<Italic />
3947
<Code />
4048
</ButtonGroup>
41-
<ButtonGroup style={style.btnGroupMargin}>
49+
<ButtonGroup className="nice-btn-group-margin">
4250
<Link />
4351
<Image />
4452
<Form />
4553
</ButtonGroup>
46-
<ButtonGroup style={style.btnGroupMargin}>
54+
<ButtonGroup className="nice-btn-group-margin">
4755
<FullScreen />
4856
<Font />
4957
<Reset />
5058
<About />
5159
</ButtonGroup>
5260
</div>
5361
</div>
54-
<div style={style.rightNav}>
62+
<div className="nice-right-nav">
5563
<Copy />
5664
<ThemeSelect />
5765
<Format />
@@ -64,40 +72,4 @@ class Navbar extends Component {
6472
}
6573
}
6674

67-
const style = {
68-
navBar: {
69-
height: "64px",
70-
display: "flex",
71-
justifyContent: "space-between",
72-
flex: "none",
73-
padding: "20px",
74-
},
75-
leftNav: {
76-
display: "flex",
77-
flex: 1,
78-
justifyContent: "flex-start",
79-
alignItems: "center",
80-
},
81-
rightNav: {
82-
display: "flex",
83-
justifyContent: "flex-end",
84-
alignItems: "center",
85-
},
86-
btnGroupMargin: {
87-
marginRight: "10px",
88-
},
89-
btnGroupRight: {
90-
marginRight: "20px",
91-
},
92-
iconBar: {
93-
marginTop: 5,
94-
},
95-
title: {
96-
marginRight: "20px",
97-
fontWeight: "bold",
98-
fontSize: "16px",
99-
fontFamily: "Apple Chancery, cursive",
100-
},
101-
};
102-
10375
export default Navbar;

src/store/navbar.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
CODE_OPTIONS,
77
IS_PASTE_CHECK_OPEN,
88
IS_PRETTIER_OPEN,
9+
IS_IMMERSIVE_EDITING,
910
PREVIEW_TYPE,
1011
} from "../utils/constant";
1112
import TEMPLATE from "../template/index";
@@ -18,6 +19,8 @@ class Navbar {
1819

1920
@observable isPrettierOpen = true;
2021

22+
@observable isImmersiveEditing = false;
23+
2124
@observable templateNum;
2225

2326
@observable codeNum;
@@ -34,6 +37,11 @@ class Navbar {
3437
this.isPasteCheckOpen = isPasteCheckOpen;
3538
};
3639

40+
@action
41+
setImmersiveEditing = (isImmersiveEditing) => {
42+
this.isImmersiveEditing = isImmersiveEditing;
43+
};
44+
3745
@action
3846
setPrettierOpen = (isPrettierOpen) => {
3947
this.isPrettierOpen = isPrettierOpen;
@@ -94,6 +102,7 @@ store.templateNum = parseInt(window.localStorage.getItem(TEMPLATE_NUM), 10);
94102
store.codeNum = parseInt(window.localStorage.getItem(CODE_NUM), 10);
95103
store.isPasteCheckOpen = window.localStorage.getItem(IS_PASTE_CHECK_OPEN) === "true";
96104
store.isPrettierOpen = window.localStorage.getItem(IS_PRETTIER_OPEN) === "true";
105+
store.isImmersiveEditing = window.localStorage.getItem(IS_IMMERSIVE_EDITING) === "false";
97106
store.previewType = window.localStorage.getItem(PREVIEW_TYPE);
98107

99108
// 初始化代码主题

src/template/content.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default `请使用 **Chrome** 浏览器。
7070
7171
粗体的使用是在需要加粗的文字前后各加两个\`*\`。
7272
73-
而斜体的使用则是在需要斜体的文字前后各加一个\`_\`。
73+
而斜体的使用则是在需要斜体的文字前后各加一个\`*\`。
7474
7575
如果要使用粗体和斜体,那么就是在需要操作的文字前后加三个\`*\`。如下:
7676
@@ -111,8 +111,8 @@ export default `请使用 **Chrome** 浏览器。
111111
| 姓名 | 年龄 | 工作 |
112112
| :----- | :--: | -------: |
113113
| 小可爱 | 18 | 吃可爱多 |
114-
| 小勇敢 | 20 | 爬勇敢树 |
115-
| 小机智 | 22 | 看机智书 |
114+
| 小小勇敢 | 20 | 爬棵勇敢树 |
115+
| 小小小机智 | 22 | 看一本机智书 |
116116
117117
### 3.10 图片
118118
@@ -142,7 +142,7 @@ export default `请使用 **Chrome** 浏览器。
142142
| mdnice | 图片只保存一天 |
143143
| SM.MS | 失败率高可用性很差 |
144144
| 阿里云 | 配置繁琐,费用昂贵 |
145-
| 七牛云 | 需要长期域名替代测试域名 |
145+
| 七牛云 | 配置繁琐,需购买长期域名 |
146146
147147
**建议:一次性排版推荐使用 mdnice,图片需要长期管理推荐使用七牛云**。
148148
@@ -182,7 +182,7 @@ export default `请使用 **Chrome** 浏览器。
182182
183183
Use the \`printf()\` function.
184184
185-
在需要高亮的代码块的前一行及后一行使用三个反引号,同时**第一行反引号后面表面代码块所使用的语言**,如下:
185+
在需要高亮的代码块的前一行及后一行使用三个反引号,同时**第一行反引号后面表示代码块所使用的语言**,如下:
186186
187187
\`\`\`java
188188
// FileName: HelloWorld.java

src/utils/constant.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const PREVIEW_TYPE = "preview_type";
1616
export const VERSION = "version";
1717
export const IS_PASTE_CHECK_OPEN = "is_paste_check_open";
1818
export const IS_PRETTIER_OPEN = "is_prettier_open";
19+
export const IS_IMMERSIVE_EDITING = "is_immersive_editing";
1920
export const ALIOSS_IMAGE_HOSTING = "alioss_image_hosting";
2021
export const QINIUOSS_IMAGE_HOSTING = "qiniuoss_image_hosting";
2122
export const IMAGE_HOSTING_TYPE = "image_hosting_type";

0 commit comments

Comments
 (0)