Skip to content

Commit

Permalink
code-editor added (#340)
Browse files Browse the repository at this point in the history
* code-editor added

* changes added

* Updated README.md

* Update README.md badge

* Rename screenshot.png to screenshot.webp

* Update README.md ss
  • Loading branch information
maradadivyasree020 authored Jun 19, 2024
1 parent 59af971 commit 59b02b2
Show file tree
Hide file tree
Showing 19 changed files with 435 additions and 1 deletion.
70 changes: 70 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<h1 align='center'><b>💥 Code Editor 💥</b></h1>

<!-- -------------------------------------------------------------------------------------------------------------- -->

<h3 align='center'>Tech Stack Used 🎮</h3>
<!-- enlist all the technologies used to create this project from them (Remove comment using 'ctrl+z' or 'command+z') -->

<div align='center'>

![HTML5](https://img.shields.io/badge/html5-%23E34F26.svg?style=for-the-badge&logo=html5&logoColor=white)
![CSS3](https://img.shields.io/badge/css3-%231572B6.svg?style=for-the-badge&logo=css3&logoColor=white)
![JavaScript](https://img.shields.io/badge/javascript-%23323330.svg?style=for-the-badge&logo=javascript&logoColor=%23F7DF1E)
![React](https://img.shields.io/badge/react-%2320232a.svg?style=for-the-badge&logo=react&logoColor=%2361DAFB)
</div>


![Line](https://github.com/Avdhesh-Varshney/WebMasterLog/assets/114330097/4b78510f-a941-45f8-a9d5-80ed0705e847)

<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: Description 📃

<div>
<!-- <p>Add Description of the project</p> -->
<p>This project is a code editor built with React.js. It allows users to write, edit, and execute code snippets in programming languages linke HTML,CSS,JS.</p>
</div></p>
</div>


<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: How to run it? 🕹️

<!-- Add steps how to run this project -->
To run this project locally, follow these steps:

1. Fork the repository.

2. Clone the repository to your local computer:
git clone https://github.com/your-username/CodeEditor.git

3. Open the project folder in your preferred code editor, now you can view website in live.



<!-- -------------------------------------------------------------------------------------------------------------- -->

## :zap: Screenshots 📸
<!-- add the screenshot of the project (Mandatory) -->

<img src='./screenshot.webp'>


![Line](https://github.com/Avdhesh-Varshney/WebMasterLog/assets/114330097/4b78510f-a941-45f8-a9d5-80ed0705e847)

<!-- -------------------------------------------------------------------------------------------------------------- -->

<h4 align='center'>Developed By <b><i>Marada Divya Sree</i></b> 👦</h4>
<p align='center'>
<a href='https://www.linkedin.com/in/marada-divya-sree-72b164255/'>
<img src='https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white' />
</a>
<a href='https://github.com/maradadivyasree020'>
<img src='https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white' />
</a>
</p>

<h4 align='center'>Happy Coding 🧑‍💻</h4>

<h3 align="center">Show some &nbsp;❤️&nbsp; by &nbsp;🌟&nbsp; this repository!</h3>
45 changes: 45 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "code-editor",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.19",
"@mui/material": "^5.14.20",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"codemirror": "^5.65.16",
"react": "^18.2.0",
"react-codemirror2": "^7.3.0",
"react-dom": "^18.2.0",
"react-icons": "^4.12.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"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"
]
}
}
43 changes: 43 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/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>React App</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>
Binary file not shown.
22 changes: 22 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.icon{
font-size: 15px;
}

.ic{
display: flex;
justify-content: space-between;
align-items: flex-start;
}

.CodeMirror{
height: 340;
color:#fff;
}

.CodeMirror-gutters{
background: #1d1e22;
}

.CodeMirror-scroll{
background: #1d1e22;
}
17 changes: 17 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

import DataProvider from './context/DataProvider';
import './App.css';
import Home from './Components/Home';

function App() {
return (
<>
<DataProvider>
{/* children */}
<Home />
</DataProvider>
</>
);
}

export default App;
8 changes: 8 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
22 changes: 22 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/src/Components/Code.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Editor from "./Editor";
import{Box,styled} from '@mui/material';

import { useContext } from "react";
import { DataContext } from "../context/DataProvider";

const Container = styled(Box)`
display:flex;
background-color:#060606;
height:50vh`

const Code = () =>{
const{html,setHtml,css,setCss,js,setJs} = useContext(DataContext)
return(
<Container>
<Editor heading ="HTML" icon="/" color="#FF3C41" value={html} onChange={setHtml}/>
<Editor heading ="CSS" icon="*" color="#0EBEFF" value={css} onChange={setCss}/>
<Editor heading ="JavaScript" icon="{}" color="#FCD000" value={js} onChange={setJs}/>
</Container>
)
}
export default Code;
67 changes: 67 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/src/Components/Editor.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Box,styled } from '@mui/material';
import CloseFullscreenIcon from '@mui/icons-material/CloseFullscreen';

import {Controlled as ControlledEditor} from 'react-codemirror2'
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
import 'codemirror/mode/xml/xml';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/css/css';
import '../App.css';
import { useState } from 'react';

const Heading = styled(Box)`
background:#1d1e22;
display:flex;
padding:9x 12px;`
const Header = styled(Box)`
display:flex;
background:#060606;
color:#AAAEBC;
justify-content:space-between;
font-weight:700`
const Container=styled(Box)`
flex-grow:1;
flex-basic:0;
display:flex;
flex-direction:column;
padding: 0 8px 8px;`

const Editor = (props) =>{

const [open,setOpen]=useState(true)

const handleChange = (editor, data, value) => {
props.onChange(value);
}

return(
<Container style={open ? null: {flexGrow:0}}>
<Header>
<Heading>
<Box component="span" style={{background:props.color,
height:20,
width:24,
display:'flex',
placeContent:'center',
borderRadius:5,
marginRight:2,
paddingBottom:2
}}>{props.icon}</Box>
{props.heading}
</Heading>
<CloseFullscreenIcon fontSize='small'
style={{alignSelf:'center'}}
onClick={() => setOpen(prevState => !prevState)}/>
</Header>
<ControlledEditor className='controlled-editor'
value={props.value}
onBeforeChange={handleChange}
options={{
theme:'material',
lineNumbers:true
}}/>
</Container>
)
}
export default Editor;
24 changes: 24 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/src/Components/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {AppBar,Toolbar,styled} from '@mui/material';
import { FaPen } from "react-icons/fa";
import '../App.css';

const Container=styled(AppBar)`
background:#060606;
height:9vh;
font-size:10px;
font-weight:5px;
font-family:cursive`

const Header = () =>{
return(
<>
<Container position='static'>
<Toolbar className='ic'>
<h1>CodeEditor</h1>
<FaPen className='icon'/>
</Toolbar>
</Container>
</>
)
}
export default Header;
14 changes: 14 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/src/Components/Home.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Header from "./Header"
import Code from "./Code"
import Result from "./Result"

const Home = () =>{
return(
<>
<Header/>
<Code />
<Result />
</>
)
}
export default Home;
29 changes: 29 additions & 0 deletions React-JS-Projects/Advanced/Code-Editor/src/Components/Result.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useContext,useEffect,useState } from 'react'
import { DataContext } from '../context/DataProvider'
import {Box,styled} from '@mui/material'

const Container=styled(Box)`
height:41vh`

const Result = () =>{
const [src,setSrc]=useState('')
const {html,css,js} = useContext(DataContext)
const srcCode=`
<html>
<body>${html}</body>
<style>${css}</style>
<script>${js}</script>
</html>`
useEffect(()=>{
const timeout = setTimeout(() => {
setSrc(srcCode);
},1000)
return () => clearTimeout(timeout)
},[html,css,js,srcCode])
return(
<Container>
<iframe srcDoc={src} title='Output' sandbox='allow-modals allow-forms allow-popups allow-scripts allow-same-origin' frameBorder={0} width="100%" height="100%"/>
</Container>
)
}
export default Result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createContext, useState } from "react";

export const DataContext = createContext()

const DataProvider = ({children}) =>{
const [html,setHtml]=useState('');
const [css,setCss]=useState('')
const [js,setJs]=useState('')
return(
<DataContext.Provider value={{
html,setHtml,
css,setCss,
js,setJs
}}>
{children}
</DataContext.Provider>
)
}

export default DataProvider;
Loading

0 comments on commit 59b02b2

Please sign in to comment.