├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── presentation └── react-codepen-clone.gif ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── components ├── App.js └── Editor.js ├── hooks └── useLocalStorage.js ├── index.css └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | # 🔲 CodePen Clone With React 4 | 5 |

6 | 7 |

8 |
9 | 10 | ### Installation 11 | 12 | - Clone the repo to your local machine `git clone https://github.com/zumrudu-anka/react-codepen-clone.git` 13 | - Go to the project folder 14 | - Run `npm install` to install packages 15 | 16 | ## Available Scripts 17 | 18 | In the project directory, you can run: 19 | 20 | ### `npm start` 21 | 22 | Runs the app in the development mode.
23 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 24 | 25 | The page will reload if you make edits.
26 | You will also see any lint errors in the console. 27 | 28 | ### `npm test` 29 | 30 | Launches the test runner in the interactive watch mode.
31 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 32 | 33 | ### `npm run build` 34 | 35 | Builds the app for production to the `build` folder.
36 | It correctly bundles React in production mode and optimizes the build for the best performance. 37 | 38 | The build is minified and the filenames include the hashes.
39 | Your app is ready to be deployed! 40 | 41 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 42 | 43 | ### `npm run eject` 44 | 45 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 46 | 47 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 48 | 49 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 50 | 51 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 52 | 53 | ## Learn More 54 | 55 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 56 | 57 | To learn React, check out the [React documentation](https://reactjs.org/). 58 | 59 | ### Code Splitting 60 | 61 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 62 | 63 | ### Analyzing the Bundle Size 64 | 65 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 66 | 67 | ### Making a Progressive Web App 68 | 69 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 70 | 71 | ### Advanced Configuration 72 | 73 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 74 | 75 | ### Deployment 76 | 77 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 78 | 79 | ### `npm run build` fails to minify 80 | 81 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 82 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-codepen-clone", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": "https://zumrudu-anka.github.io/react-codepen-clone/", 6 | "dependencies": { 7 | "@fortawesome/fontawesome-svg-core": "^1.2.30", 8 | "@fortawesome/free-solid-svg-icons": "^5.14.0", 9 | "@fortawesome/react-fontawesome": "^0.1.11", 10 | "@testing-library/jest-dom": "^4.2.4", 11 | "@testing-library/react": "^9.5.0", 12 | "@testing-library/user-event": "^7.2.1", 13 | "codemirror": "^5.57.0", 14 | "gh-pages": "^3.1.0", 15 | "react": "^16.13.1", 16 | "react-codemirror2": "^7.2.1", 17 | "react-dom": "^16.13.1", 18 | "react-scripts": "3.4.3" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "predeploy": "npm run build", 25 | "deploy": "gh-pages -b master -d build", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": "react-app" 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /presentation/react-codepen-clone.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zumrudu-anka/react-codepen-clone/e12b0f73db785ca4a40279d5e63d9806239e8fbf/presentation/react-codepen-clone.gif -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zumrudu-anka/react-codepen-clone/e12b0f73db785ca4a40279d5e63d9806239e8fbf/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zumrudu-anka/react-codepen-clone/e12b0f73db785ca4a40279d5e63d9806239e8fbf/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zumrudu-anka/react-codepen-clone/e12b0f73db785ca4a40279d5e63d9806239e8fbf/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/components/App.js: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | import Editor from "./Editor"; 3 | import useLocalStorage from "../hooks/useLocalStorage"; 4 | 5 | function App() { 6 | 7 | const [html, setHtml] = useLocalStorage("html", ""); 8 | const [css, setCss] = useLocalStorage("css", ""); 9 | const [js, setJs] = useLocalStorage("js", ""); 10 | const [srcDoc, setSrcDoc] = useState(""); 11 | 12 | useEffect(() => { 13 | const timeout = setTimeout(() =>{ 14 | setSrcDoc(` 15 | 16 | ${html} 17 | 18 | 19 | 20 | `); 21 | }, 250); 22 | 23 | return () => clearTimeout(timeout); 24 | }, [html, css, js]); 25 | 26 | return ( 27 | <> 28 |
29 | 35 | 41 | 47 |
48 |
49 | 57 |
58 | 59 | ); 60 | } 61 | 62 | export default App; 63 | -------------------------------------------------------------------------------- /src/components/Editor.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import "codemirror/lib/codemirror.css"; 3 | import "codemirror/theme/material.css"; 4 | import "codemirror/mode/xml/xml"; 5 | import "codemirror/mode/javascript/javascript"; 6 | import "codemirror/mode/css/css"; 7 | import { Controlled as ControlledEditor } from "react-codemirror2"; 8 | import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; 9 | import { faCompressAlt, faExpandAlt } from "@fortawesome/free-solid-svg-icons"; 10 | 11 | export default function Editor(props) { 12 | const { 13 | language, 14 | displayName, 15 | value, 16 | onChange 17 | } = props; 18 | 19 | const [open, setOpen] = useState(true); 20 | 21 | function handleChange(editor, data, value){ 22 | onChange(value); 23 | } 24 | 25 | return ( 26 |
27 |
28 | {displayName} 29 | 36 |
37 | 49 |
50 | ) 51 | } 52 | -------------------------------------------------------------------------------- /src/hooks/useLocalStorage.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react' 2 | 3 | const PREFIX = "codepen-clone"; 4 | 5 | export default function useLocalStorage(key, initialValue) { 6 | const prefixedKey = PREFIX + key; 7 | 8 | const [value, setValue] = useState(() => { 9 | const jsonValue = localStorage.getItem(prefixedKey); 10 | 11 | if(jsonValue != null) return JSON.parse(jsonValue); 12 | 13 | if(typeof initialValue === "function"){ 14 | return initialValue() 15 | } 16 | else{ 17 | return initialValue; 18 | } 19 | }); 20 | 21 | useEffect(() =>{ 22 | localStorage.setItem(prefixedKey, JSON.stringify(value)); 23 | }, [prefixedKey, value]); 24 | 25 | return [value, setValue]; 26 | } -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body{ 2 | margin: 0; 3 | } 4 | 5 | .top-pane{ 6 | background-color: hsl(225, 6%, 25%); 7 | } 8 | 9 | .pane{ 10 | height: 50vh; 11 | display: flex; 12 | } 13 | 14 | .editor-container{ 15 | flex-grow: 1; 16 | flex-basis: 0; 17 | display: flex; 18 | flex-direction: column; 19 | padding: .5rem; 20 | background-color: hsl(225, 6%, 25%); 21 | } 22 | 23 | .editor-container.collapsed .CodeMirror-scroll{ 24 | position: absolute; 25 | overflow: hidden !important; 26 | } 27 | 28 | .expand-collapse-button{ 29 | margin-left: .5rem; 30 | background: none; 31 | border: none; 32 | color: white; 33 | cursor: pointer; 34 | } 35 | 36 | .editor-container.collapsed{ 37 | flex-grow: 0; 38 | } 39 | 40 | .editor-title{ 41 | display: flex; 42 | justify-content: space-between; 43 | background-color: hsl(225, 6%, 13%); 44 | color: white; 45 | padding: .5rem .5rem .5rem 1rem; 46 | border-top-right-radius: .5rem; 47 | border-top-left-radius: .5rem; 48 | } 49 | 50 | .CodeMirror{ 51 | height: 100% !important; 52 | } 53 | 54 | .code-mirror-wrapper{ 55 | flex-grow: 1; 56 | border-bottom-right-radius: .5rem; 57 | border-bottom-left-radius: .5rem; 58 | overflow: hidden; 59 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './components/App'; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById('root') 11 | ); 12 | --------------------------------------------------------------------------------