Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add react demo for cherry-markdown #821

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples/cherry-markdown-react-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
8 changes: 8 additions & 0 deletions examples/cherry-markdown-react-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 介绍
这是cherry-markdown的react示例

# 开始
```
npm install
npm start
```
35 changes: 35 additions & 0 deletions examples/cherry-markdown-react-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "cherry-markdown-react-demo",
"version": "0.1.0",
"private": true,
"dependencies": {
"cherry-markdown": "^0.8.44",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file not shown.
1 change: 1 addition & 0 deletions examples/cherry-markdown-react-demo/public/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions examples/cherry-markdown-react-demo/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Cherry React Demo</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions examples/cherry-markdown-react-demo/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
178 changes: 178 additions & 0 deletions examples/cherry-markdown-react-demo/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
:root {
--width: 1400px;
--color: #e26862;
}

header {
height: 60px;
border-bottom: 1px solid var(--color);
display: flex;
justify-content: center;
}

h2 {
margin-top: 8px;
margin-bottom: 8px;
}

h3 {
margin-top: 6px;
margin-bottom: 6px;
}

.header-wrapper {
height: 100%;
width: var(--width);
display: flex;
justify-content: start;
align-items: center;
}

.header-logo {
height: 60%;
width: auto;
object-fit: contain;
}

.header-repo-a {
height: 100%;
display: flex;
align-items: center;
margin-left: auto;
}

.header-text {
font-size: 20px;
text-decoration: none;
color: inherit;
padding: 10px;

margin-left: 15px;
border-radius: 5px;
}

.header-text:hover {
background-color: var(--color);
color: white;
}

.header-text:nth-child(2) {
background-color: var(--color);
color: white;
}

main {
display: flex;
align-items: center;
flex-direction: column;
width: 100%;
}

.main-wrapper {
width: var(--width)
}

.title-wrapper {
width: 100%;
}

.title {
display: flex;
justify-content: start;
}

.menu {
border: 1px solid gray;
padding: 8px;
border-radius: 5px;
margin-bottom: 10px;
}


#markdown-container {
width: 100%;
height: 800px !important;
}

.custom-select-container {
display: inline-block;
min-width: 250px;
text-align: center;
position: relative;
z-index: 100;
margin-left: 5px;
}

.custom-select {
padding: 5px;
border-bottom: 1px solid var(--color);
}

.custom-option-wrapper {
position: absolute;
width: 100%;
margin: 0;
padding: 0;
text-align: center;
background: white;
border: 1px solid var(--color);
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}

.custom-option {
list-style-type: none;
margin: 6px 10px;
border-bottom: 1px solid gainsboro;
cursor: pointer;
line-height: 30px;
border-radius: 5px;
}

.custom-option:hover {
/* background-color: gray; */
color: #ffffff;
background-color: var(--color);
}


.code-input {
width: 99%;
max-width: 99%;
padding: 5px;
font-size: 20px;
}


.demo-desc {
font-size: 17px;
white-space: pre-wrap;
}


.run-btn {
background-color: white;
font-size: 20px;
color: white;
border: 1px solid var(--color);
background-color: var(--color);
border-radius: 5px;
margin-left: 5px;
cursor: pointer;
}

.run-btn:disabled {
background-color: gainsboro;
border: 1px solid gainsboro;
cursor: default;
}

.run-btn:disabled:hover {
background-color: gainsboro;
border: 1px solid gainsboro;
}

.run-btn:hover {
background-color: red;
border: 1px solid red;
}
40 changes: 40 additions & 0 deletions examples/cherry-markdown-react-demo/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useEffect, useState, useRef } from 'react';
import './App.css';
import Header from './components/Header'
import 'cherry-markdown/dist/cherry-markdown.css';
import Cherry from 'cherry-markdown';
import Title from './components/Title';
import Menu from "./components/Menu";

function App() {
const editorRef = useRef(null);
const [editor, setEditor] = useState(null);
useEffect(() => {
if (editor == null) {
// 初始化编辑器
const config = {
el: editorRef.current,
value: '',
callback: {
afterChange: (md, html) => console.log('change'),
},
};
setEditor(new Cherry(config));
}
}, []);
return (
<>
<Header />
<main>
<div className='main-wrapper'>
<Title />
<Menu cherryObj={editor} />
{/* 该div作为编辑器的最外层容器 */}
<div ref={editorRef} id="markdown-container" />
</div>
</main>
</>
);
}

export default App;
16 changes: 16 additions & 0 deletions examples/cherry-markdown-react-demo/src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default () => {
return (
<header>
<div className="header-wrapper">
<img src="logo--color.png" className="header-logo" />
<a href="#" className="header-text">Demo</a>
<a href="https://github.com/Tencent/cherry-markdown/wiki/%E5%88%9D%E8%AF%86cherry-markdown-%E7%BC%96%E8%BE%91%E5%99%A8" target="_blank" className="header-text">介绍</a>
<a href="https://tencent.github.io/cherry-markdown/examples/api.html" target="_blank" className="header-text">API文档</a>
<a href="https://tencent.github.io/cherry-markdown/examples/preview_only.html" target="_blank" className="header-text">Markdown语法</a>
<a href="https://github.com/Tencent/cherry-markdown" target="_black" className="header-repo-a">
<img src="github.svg" className="header-logo" />
</a>
</div>
</header>
)
}
Loading
Loading