import React, { useState, useRef } from 'react'; import ReactDOM from 'react-dom'; import { makeStyles, TextField, Button } from '@material-ui/core'; import { Benzin, Header, Window, Markdown, ContentSection, } from './lib'; import icon from './assets/icon.svg'; interface RenderPropTypes { index: number; style: React.CSSProperties; } const useStyles = makeStyles(theme => ({ window: { padding: theme.spacing(4), }, promoButton: { display: 'flex', justifyContent: 'center', marginTop: theme.spacing(4), }, })); const Icon = logo; const headerContents = { home: null, spacevim: null, 'material-ui': null, custom: null, 'live preview': null, }; const pageMap: Record = { home: 'https://raw.githubusercontent.com/eug-vs/react-benzin/develop/README.md', spacevim: 'https://raw.githubusercontent.com/spacevim/spacevim/master/README.md', 'material-ui': 'https://raw.githubusercontent.com/mui-org/material-ui/master/README.md', }; const CustomPage: React.FC = () => { const [url, setUrl] = useState(''); const inputEl = useRef(null); const handleParseUrl = (): void => { setUrl(inputEl.current?.value || ''); }; return ( <>

This should be a link to a valid markdown file. Response should give the file contents. If you copy README file from GitHub, make sure you provide link to raw view.

); }; interface LivePropTypes { setLivePreviewData: (livePreviewData: string) => void; } const LivePreviewPage: React.FC = ({ setLivePreviewData }) => { const inputEl = useRef(null); const handleRender = (): void => { setLivePreviewData(inputEl.current?.value || ''); }; return ( <>

Start typing and see your text rendered on the left window! We recommend starting with # Header.

); }; const App: React.FC = () => { const classes = useStyles(); const [page, setPage] = useState('home'); const [livePreviewData, setLivePreviewData] = useState(''); const handleGoLivePreview = (): void => { setPage('live preview'); }; const url = pageMap[page]; const fileName = url?.slice(url.lastIndexOf('/') + 1); const info = [ `## Markdown\n [Markdown file](${url}) *(...${fileName})* that you can see on the left was parsed and rendered by **BENZIN**! :rocket:`, 'Switch between tabs on the header to explore other markdown templates. :recycle: ', 'Currently **only core features** of markdown function.', 'Templates on the left are being loaded from the [GitHub](https://github.com), though this pane is generated from plaintext. :pen:', '## How do I use this feature?', '```', 'import Markdown from \'react-benzin\';', 'const data = \'# Header\\nHello, *world!*\';', 'ReactDOM.render(, document.getElementById(\'root\'));', '```', ].join('\n'); return (
{ (page === 'custom') ? : (page === 'live preview') ? : }
{ (page === 'live preview') ? : ( <>

) }
); }; ReactDOM.render(, document.getElementById('root'));