Skip to content

Commit

Permalink
website: update example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 23, 2023
1 parent a9a7310 commit 4113ddc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
51 changes: 45 additions & 6 deletions website/src/App.tsx
@@ -1,15 +1,56 @@
import Github from '@uiw/react-shields/esm/github';
import Npm from '@uiw/react-shields/esm/npm';
import { useState } from 'react';
import styled from 'styled-components';
import MarkdownPreview from '@uiw/react-markdown-preview';

const Footer = styled.footer`
const EditorWrapper = styled.div`
padding-bottom: 10px;
margin: 0 auto;
width: 100%;
textarea {
width: 100%;
min-height: 120px;
min-width: 100%;
padding: 5px;
margin-top: 10px;
box-sizing: border-box;
}
.editor-preview {
border: 1px solid var(--color-border-default);
border-radius: 5px;
margin-top: 10px;
min-height: 60px;
padding: 16px;
}
`;

let val = 1;

export const Example = () => {
const [value, setValue] = useState('');
return (
<EditorWrapper>
<button onClick={() => setValue('# Markdown ' + val++)}>set value</button>
<textarea
placeholder="Please enter the Markdown code!"
value={value}
spellCheck="false"
onChange={(e) => setValue(e.target.value)}
/>
<MarkdownPreview className="editor-preview" source={value} />
</EditorWrapper>
);
};

const FooterWrapper = styled.footer`
text-align: center;
padding-top: 30px;
`;

const App = () => {
export const Footer = () => {
return (
<Footer>
<FooterWrapper>
<Github user="uiwjs" repo="react-markdown-preview">
<Github.Social type="forks" href="https://github.com/uiwjs/react-markdown-preview" />
<Github.Social type="stars" href="https://github.com/uiwjs/react-markdown-preview/stargazers" />
Expand All @@ -20,8 +61,6 @@ const App = () => {
packageName="react-markdown-preview"
href="https://www.npmjs.com/package/@uiw/react-markdown-preview"
/>
</Footer>
</FooterWrapper>
);
};

export default App;
7 changes: 5 additions & 2 deletions website/src/index.tsx
@@ -1,7 +1,7 @@
import { createRoot } from 'react-dom/client';
import MarkdownPreviewExample from '@uiw/react-markdown-preview-example';
import data from '@uiw/react-markdown-preview/README.md';
import Example from './App';
import { Footer, Example } from './App';

const container = document.getElementById('root');
const root = createRoot(container!);
Expand All @@ -20,6 +20,9 @@ root.render(
version={`v${VERSION}`}
>
<MarkdownPreviewExample.Github href="https://github.com/uiwjs/react-markdown-preview" />
<Example />
<MarkdownPreviewExample.Example>
<Example />
</MarkdownPreviewExample.Example>
<Footer />
</MarkdownPreviewExample>,
);

0 comments on commit 4113ddc

Please sign in to comment.