Skip to content

Commit

Permalink
add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
mor10 committed Oct 20, 2020
1 parent a757a8f commit 65bcad3
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 9 deletions.
78 changes: 78 additions & 0 deletions 01_01/Photo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Fragment from React Photo Gallery component.
* By Sandra Gonzales @neptunian
* @link https://github.com/neptunian/react-photo-gallery
* The MIT License (MIT)
* Copyright (c) 2015-2018 Sandra Gonzales
*/

import React from "react";
import PropTypes from "prop-types";

const imgWithClick = { cursor: "pointer" };

const Photo = ({
index,
onClick,
photo,
margin,
direction,
top,
left,
key,
}) => {
const imgStyle = { margin: margin, display: "block" };
if (direction === "column") {
imgStyle.position = "absolute";
imgStyle.left = left;
imgStyle.top = top;
}

const handleClick = (event) => {
onClick(event, { photo, index });
};

return (
<img
key={key}
style={onClick ? { ...imgStyle, ...imgWithClick } : imgStyle}
{...photo}
onClick={onClick ? handleClick : null}
/>
);
};

export const photoPropType = PropTypes.shape({
key: PropTypes.string,
src: PropTypes.string.isRequired,
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
alt: PropTypes.string,
title: PropTypes.string,
srcSet: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
sizes: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
});

Photo.propTypes = {
index: PropTypes.number.isRequired,
onClick: PropTypes.func,
photo: photoPropType.isRequired,
margin: PropTypes.number,
top: (props) => {
if (props.direction === "column" && typeof props.top !== "number") {
return new Error(
"top is a required number when direction is set to `column`"
);
}
},
left: (props) => {
if (props.direction === "column" && typeof props.left !== "number") {
return new Error(
"left is a required number when direction is set to `column`"
);
}
},
direction: PropTypes.string,
};

export default Photo;
10 changes: 10 additions & 0 deletions 01_04/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Console demo</title>
<script src="script.js" defer></script>
</head>
<body></body>
</html>
56 changes: 56 additions & 0 deletions 01_04/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Create a Backpack object, populate some HTML to display its properties.
*/

// Single line comment

/* Multi-line comment
See! this line is also commented out! */

const updateBackpack = (update) => {
let main = document.querySelector("main"); // main is an element
main.innerHTML = markup(backpack);
console.info(update);
};

const backpack = {
name: "Everyday Backpack",
volume: 30,
color: "grey",
pocketNum: 15,
strapLength: {
left: 26,
right: 26,
},
lidOpen: false,
toggleLid: function (lidStatus) {
this.lidOpen = lidStatus;
updateBackpack(`Lid status changed.`);
},
newStrapLength: function (lengthLeft, lengthRight) {
this.strapLength.left = lengthLeft;
this.strapLength.right = lengthRight;
updateBackpack(`Strap lengths updated.`);
},
};

const markup = (backpack) => {
return `
<div>
<h3>${backpack.name}</h3>
<ul>
<li>Volume: ${backpack.volume}</li>
<li>Color: ${backpack.color}</li>
<li>Number of pockets: ${backpack.pocketNum}</li>
<li>Strap lengths: L: ${backpack.strapLength.left}, R: ${
backpack.strapLength.right
} </li>
<li>Top lid: ${backpack.lidOpen ? "Open" : "Closed"}</li>
</ul>
</div>
`;
};

const main = document.createElement("main");
main.innerHTML = markup(backpack);
document.body.appendChild(main);
23 changes: 14 additions & 9 deletions 01_05/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
* Create a Backpack object, populate some HTML to display its properties.
*/

// Single line comment

/* Multi-line comment
See! this line is also commented out! */

const updateBackpack = (update) => {
let main = document.querySelector("main");

This comment has been minimized.

Copy link
@sahakash-dev

sahakash-dev Nov 10, 2023

//noyhing

let main = document.querySelector("main"); // main is an element
main.innerHTML = markup(backpack);
console.info(update);
};
Expand Down Expand Up @@ -32,16 +37,16 @@ const backpack = {
const markup = (backpack) => {
return `
<div>
<h3>${backpack.name}</h3>
<ul>
<li>Volume: ${backpack.volume}</li>
<li>Color: ${backpack.color}</li>
<li>Number of pockets: ${backpack.pocketNum}</li>
<li>Strap lengths: L: ${backpack.strapLength.left}, R: ${
<h3>${backpack.name}</h3>
<ul>
<li>Volume: ${backpack.volume}</li>
<li>Color: ${backpack.color}</li>
<li>Number of pockets: ${backpack.pocketNum}</li>
<li>Strap lengths: L: ${backpack.strapLength.left}, R: ${
backpack.strapLength.right
} </li>
<li>Top lid: ${backpack.lidOpen ? "Open" : "Closed"}</li>
</ul>
<li>Top lid: ${backpack.lidOpen ? "Open" : "Closed"}</li>
</ul>
</div>
`;
};
Expand Down

0 comments on commit 65bcad3

Please sign in to comment.