Basics-1

How React Works Behind the Scenes

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./style.css">
    <title>React Test</title>
</head>
<body>
    <div id="root"> Not Rendered </div>


    <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script>
    <script src="./App.js"></script>
</body>
</html>
//App.js
// Code goes here.
// https://gumroad.com/l/dank-mono
// https://github.com/tonsky/FiraCode



const Pet = (props) => {
    return React.createElement("div", {}, [
        React.createElement("h1", {}, props.name),
        React.createElement("h2", {}, props.animal),
        React.createElement("h3", {}, props.breed)
    ])
}



// This is react component, think of it like class
const App = () => {
    return React.createElement(
    "div",
    {}, 
    [
        React.createElement("h1", {}, 'Adopt Me!!'),
        React.createElement(Pet, {name: "Luna", animal:"Dog", breed: "Havanese"}), // in react by default data only flow from parent to child components.
        React.createElement(Pet, {name: "Pepper", animal:"Bird", breed: "Cocka"}),
        React.createElement(Pet, {name: "Sudo", animal:"Dog", breed: "Tail"}),
    ]
    )
}

// Rendering component to browser, kind of making connection between custom html element and react componenet
ReactDOM.render(React.createElement(App), document.getElementById('root'))


/* style.css */
* {
  box-sizing: border-box;
  color: #333;
}

body {
  background-color: #ad343e;
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.search,
.details,
.search-params {
  background-color: #c4b2bc;
  width: 95%;
  margin: 0 auto;
  padding: 15px;
  border-radius: 5px;
}

.pet {
  width: 100%;
  height: 100px;
  display: block;
  overflow: hidden;
  margin: 15px 0;
}

.pet img {
  width: 100px;
  min-height: 100px;
}

.info {
  float: left;
  height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

.image-container {
  clip-path: circle(50% at 50% 50%);
  width: 100px;
  height: 100px;
  float: left;
  margin-right: 20px;
}

.pet h1 {
  white-space: nowrap;
  font-weight: normal;
  font-size: 30px;
  width: 100%;
  overflow: hidden;
  margin: 0;
}

.pet h2 {
  white-space: nowrap;
  font-weight: normal;
  font-size: 20px;
  margin: 0;
}

header a {
  color: #f2af29;
  font-size: 50px;
  text-decoration: none;
  font-weight: bold;
  display: block;
}

header {
  display: flex;
  align-content: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 20px;
}

.details p {
  line-height: 2;
}

.details h1,
.details h2 {
  text-align: center;
}

.carousel {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 400px;
}

.carousel > img {
  max-width: 45%;
  max-height: 400px;
}

.carousel-smaller {
  width: 50%;
}

.carousel-smaller > img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: inline-block;
  margin: 15px;
  cursor: pointer;
  border: 2px solid #333;
}

.carousel-smaller > img.active {
  border-color: #ad343e;
  opacity: 0.6;
}

.search-params label {
  display: block;
  width: 60px;
}

.search-params input,
.search-params select {
  margin-bottom: 30px;
  font-size: 18px;
  height: 30px;
  width: 325px;
}

.search-params button,
#modal button,
.details button {
  background-color: #ad343e;
  padding: 5px 25px;
  color: white;
  font-size: 18px;
  border: #333 1px solid;
  border-radius: 5px;
  display: block;
  margin: 0 auto;
  cursor: pointer;
}

.search-params button:hover {
  background-color: #c36b72;
}

.search-params button:active {
  background-color: #5f1d22;
}

.search-params button:focus {
  border: 1px solid cornflowerblue;
}

#modal {
  background-color: rgba(0, 0, 0, 0.9);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
}

#modal:empty {
  display: none;
}

#modal > div {
  background-color: white;
  max-width: 500px;
  padding: 15px;
  border-radius: 5px;
  text-align: center;
}

#modal .buttons button {
  display: inline-block;
  margin-right: 15px;
}

Next