React - Formatting image-box-wrappers to center - javascript

The <div className="image-box-wrapper row justify-content-center"> on my portfolio component isn't laying out the portfolio pictures side by side. I can't seem to find the issue why they won't layout side by side. I think this would be the main piece of CSS that would affect this.
.portfolio-image {
width: 15rem;
margin: 0 auto;
border: 1px solid var(--primary-green);
padding: 0 0.5rem;
justify-content: center;
}
I checked the spelling and made sure the div was closed and still nothing. I'm still getting a column instead of side by side (horizontal). You can see the issue on my portfolio page at the link below. I appreciate help!
https://rinzler8806.github.io/reactPortfolio/
Portfolio Component
import React from "react";
import prw from "../images/prw.png";
import fitnesstracker from "../images/fitnesstracker.png";
import budgettracker from "../images/budgettracker.png";
import pangea from "../images/pangea.png";
//Font Awesome Imports
import { FontAwesomeIcon } from "#fortawesome/react-fontawesome";
import { faSearchPlus } from "#fortawesome/free-solid-svg-icons";
//React POPUPBOX
import { PopupboxManager, PopupboxContainer } from "react-popupbox";
import "react-popupbox/dist/react-popupbox.css";
const Portfolio = () => {
//Prow
const openPopupboxProw = () => {
const content = (
<>
<img className="portfolio-image-popupbox" src={prw} alt="prw"/>
<p> Description of Popular Restaurants of the World
As a traveler, I want to be able to search a location for surrounding restaurants so that I can find a local establishment to fit my needs.
<br></br>
<br></br>
uses Foundation css framework
application utilizes Zomato, and Google API's to retrieve restaurant data
user can search restaurants around the world based on location and food type
user searched cities are saved to local storage and can be accessed via the navbar
when user inputs a location and food type the page will scroll to an embedded map with markers displaying local restaurants that meet search criteria
when user clicks on map marker info about the restaurant will be displayed as well as a get directions link
</p>
<b>GitHub: </b> <a className="hyper-link" onClick={() => window.open("https://github.com/Rinzler8806/Popular-Restaurants-of-the-World-1")}>https://github.com/Rinzler8806/Popular-Restaurants-of-the-World-1</a>
</>
)
PopupboxManager.open({content});
PopupboxManager.update({
content,
config: {
titleBar: {
text: "Popular Restaurants of the World",
},
},
});
}
const popupboxConfigProw = {
titleBar: {
enable: true,
text: "Popular Restaurants of the World"
},
fadeIn: true,
fadeInSpeed: 500
}
//fitnesstracker
const openPopupboxFitnesstracker = () => {
const content = (
<>
<img className="portfolio-image-popupbox" src={fitnesstracker} alt="fitnesstracker"/>
<p>
<br></br>
<br></br>
This app has been created with the intention to be able to view create and track daily workouts. The user will be able to log multiple exercises in a workout on a given day. The user will also be able to track the name, type, weight, sets, reps, and duration of exercise. If the exercise is a cardio exercise, the user will be able to track their distance traveled.
</p>
<b>Demo: </b> <a className="hyper-link" onClick={() => window.open("https://infinite-beach-02354.herokuapp.com/exercise?id=6065391b3f573d0015bbd57e", "_blank")}>https://infinite-beach-02354.herokuapp.com/exercise?id=6065391b3f573d0015bbd57e</a>
<br></br>
<b>GitHub: </b> <a className="hyper-link" onClick={() => window.open("https://github.com/Rinzler8806/fitnessTracker")}>https://github.com/Rinzler8806/fitnessTracker</a>
</>
)
PopupboxManager.open({content});
PopupboxManager.update({
content,
config: {
titleBar: {
text: "Fitness Tracker",
},
},
});
}
const popupboxConfigFitnesstracker = {
titleBar: {
enable: true,
text: "Fitness Tracker"
},
fadeIn: true,
fadeInSpeed: 500
}
//budgettracker
const openPopupboxBudgettracker = () => {
const content = (
<>
<img className="portfolio-image-popupbox" src={budgettracker} alt="budgettracker"/>
<p>
<br></br>
<br></br>
The user will be able to add expenses and deposits to their budget with or without a connection. When entering transactions offline, they should populate the total when brought back online.
<br></br>
Offline Functionality:
Enter deposits offline.
Enter expenses offline.
<br></br>
When brought back online:
Offline entries should be added to tracker.
</p>
<b>Demo: </b> <a className="hyper-link" onClick={() => window.open("https://fathomless-sea-54648.herokuapp.com/", "_blank")}>https://fathomless-sea-54648.herokuapp.com/</a>
<br></br>
<b>GitHub: </b> <a className="hyper-link" onClick={() => window.open("https://github.com/Rinzler8806/BudgetTracker")}>https://github.com/Rinzler8806/BudgetTracker</a>
</>
)
PopupboxManager.open({content});
PopupboxManager.update({
content,
config: {
titleBar: {
text: "Budget Tracker",
},
},
});
}
const popupboxConfigBudgettracker = {
titleBar: {
enable: true,
text: "Budget Tracker"
},
fadeIn: true,
fadeInSpeed: 500
}
//Pangea
const openPopupboxPangea = () => {
const content = (
<>
<img className="portfolio-image-popupbox" src={pangea} alt="Pangea"/>
<p> Pangea
<br></br>
<br></br>
A dynamic messaging application that connects users around the globe. It offers many features and the ability to actively translate your message to a selected language.
<br></br>
Log in as: Batman and use password: password to view demo.
</p>
<b>Demo: </b> <a className="hyper-link" onClick={() => window.open("https://pangeachat.herokuapp.com/", "_blank")}>https://pangeachat.herokuapp.com/</a>
<br></br>
<b>GitHub: </b> <a className="hyper-link" onClick={() => window.open("https://github.com/Rinzler8806/pangea-chat")}>https://github.com/Rinzler8806/pangea-chat</a>
</>
)
PopupboxManager.open({content});
PopupboxManager.update({
content,
config: {
titleBar: {
text: "Pangea",
},
},
});
}
const popupboxConfigPangea = {
titleBar: {
enable: true,
text: "Pangea"
},
fadeIn: true,
fadeInSpeed: 500
}
return (
<div id="Portfolio" className="portfolio-wrapper">
<div className="container">
<h1 className="text-uppercase text-center py-5">Portfolio</h1>
<div Classname="image-box-wrapper row justify-content-center">
<div Classname="portfolio-image-box" onClick={openPopupboxProw}>
<img className="portfolio-image" src={prw} alt="prw" />
<div className="overflow"></div>
<FontAwesomeIcon className="portfolio-icon" icon={faSearchPlus} />
</div>
{/* - */}
<div Classname="portfolio-image-box" onClick={openPopupboxFitnesstracker}>
<img className="portfolio-image" src={fitnesstracker} alt="fitnesstracker" />
<div className="overflow"></div>
<FontAwesomeIcon className="portfolio-icon" icon={faSearchPlus} />
</div>
{/* - */}
<div Classname="portfolio-image-box" onClick={openPopupboxBudgettracker}>
<img className="portfolio-image" src={budgettracker} alt="budgettracker" />
<div className="overflow"></div>
<FontAwesomeIcon className="portfolio-icon" icon={faSearchPlus} />
</div>
{/* - */}
<div Classname="portfolio-image-box" onClick={openPopupboxPangea}>
<img className="portfolio-image" src={pangea} alt="pangea" />
<div className="overflow"></div>
<FontAwesomeIcon className="portfolio-icon" icon={faSearchPlus} />
</div>
</div>
</div>
<PopupboxContainer {...popupboxConfigProw} />
<PopupboxContainer {...popupboxConfigFitnesstracker} />
<PopupboxContainer {...popupboxConfigBudgettracker} />
<PopupboxContainer {...popupboxConfigPangea} />
</div>
)
}
export default Portfolio;
CSS
.portfolio-wrapper {
background: var(--primary-light-grey);
padding: 3rem 0;
}
.portfolio-wrapper h1 {
color: var(--primary-green);
}
.portfolio-image {
width: 15rem;
border: 1px solid var(--primary-green);
padding: 0 0.5rem;
justify-content: center;
}
.portfolio-image-box {
position: relative;
margin: 1rem;
}
.popupbox-wrapper {
margin-top: 7rem;
}
/*OVERFLOW BOX*/
.overflow {
position: absolute;
opacity: 0;
background: var(--primary-black);
width: 15rem;
height: 8rem;
top: 0;
border: 1px solid var(--primary-purple);
cursor: pointer;
}
.portfolio-image-box:hover .overflow {
opacity: 60%;
transition: 0.3s ease-in-out;
}
.portfolio-icon {
position: absolute;
opacity: 0;
margin-left: -8rem;
margin-top: 3.6rem;
color: var(--primary-purple);
font-size: 1.5rem;
}
.portfolio-image-box:hover .portfolio-icon {
opacity: 70%;
transition: 0.3s ease-in-out;
cursor: pointer;
}
/*POPUPBOX*/
.portfolio-image-popupbox {
width: 45rem;
padding: 0 0.5rem;
}
.hyper-link {
cursor: pointer;
color: var(--primary-blue);
}
.hyper-link:hover {
color: var(--primary-purple);
}
/*MEDIA*/
#media(max-width: 768px) {
.portfolio-image-popupbox {
width: 100%;
}
}
#media(max-height: 570px) {
.popupbox-wrapper {
height: 100%;
}
.portfolio-image-popupbox {
width: 50%;
}
}
#media(max-height: 570px) {
.popupbox-content {
height: 100%;
}
.portfolio-image-popupbox {
width: 100%;
}
}
#media(max-height: 280px) {
.popupbox-wrapper {
height: 90%;
}
.portfolio-image-popupbox {
width: 30%;
}
}

you seems to have missed the implementations of your image-box-wrapper, row
and justify-content-center classes.
That is why no styling is being applied to the container.
Adding a simple display: flex in chrome dev tools solved the issue.

Related

How to render SVG images inside a div

I'm new to react and i hope someone can help me with this. I've searched everywhere for a solution to my problem with no luck.
Basically i want to render an array of SVG images inside a div as a backgroundImage: url().
I've managed to render my array with math.random but i want the SVG images to render in same order as in the array.
This is my code so far:
import './ListView.css';
import Green from '../Assets/ListCard/Green.svg';
import Brown from '../Assets/ListCard/Brown.svg';
import Orange from '../Assets/ListCard/Orange.svg';
import Mail from '../Assets/Icons/Mail.svg'
import Phone from '../Assets/Icons/Phone.svg'
function ListView({ userData}) {
const cardImages = [Green, Brown, Orange]; /// Array
const renderList = cardImages.map(function(image) { /// Tried to map through the array with -
return image; /// no luck
})
/// This Math.radom method works, but not the solution i want
const randomItem = cardImages[Math.floor(Math.random()*cardImages.length)];
return ( /// Below inside the div is where i want to render the images.
<div className="list-card" style={{backgroundImage: `url(${renderList})`}}>
<div className="list-card-wrapper">
<div className="list-user-image"><img src={userData.picture.medium} alt=""/></div>
<div className="list-user-info">
<div className="list-user-name">{userData.name.first} {userData.name.last}</div>
<div className="list-user-location">{userData.location.city}</div>
</div>
<div className="list-user-contact">
<img height={19} src={Mail} alt="svg"/>
<img height={19} src={Phone} alt="svg"/>
</div>
</div>
</div>
)
}
export default ListView```
you will need import image and bind it like below:
import logo from './logo.svg';
function App() {
return (
<div className="App">
<img src={logo} className="App-logo" alt="logo" />
</div>
);
}
export default App;
This is what you might be looking for:
import "./styles.css";
export default function App() {
const items = [
{ name: "first" },
{ name: "second" },
{ name: "third" },
{ name: "fourth" },
{ name: "fifth" },
{ name: "sixth" }
];
const colorArray = ["green", "brown", "orange"];
return (
<div className="App">
{items.map((item, index) => {
const classColorIndex = index % 3;
return (
<div
className={`list-card ${colorArray[classColorIndex]}`}
key={index}
>
<p>{item.name}</p>
</div>
);
})}
</div>
);
}
The main concept behind this is, that you have to focus on the index of the item and check if it the first, second, or third item (I am considering it 3 because you have 3 colors in the array). Now, according to index number, you need to add a class to that div, and using CSS, you could provide background to each div according to that array.
In this sample, I have used plain background color, but I have commented how you could use svg as well. on APP.css, and here is the css
.App {
font-family: sans-serif;
text-align: center;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.list-card {
width: 50px;
height: 50px;
display: flex;
justify-content: center;
flex-basis: 50%;
}
.list-card.green {
background: green;
/* background:url('../../Green.svg'); */
}
.list-card.brown {
background: brown;
}
.list-card.orange {
background: orange;
}
and here is the sandbox link:
https://codesandbox.io/s/stack-overflos-sample-z0yxyk?file=/src/App.js
On this example, you can see background is assigned, exactly to the array.

How to change div background on click in React js?

I am fetching a list of questions from the Question.js file to Home.js
How can I change the answer border color when the user clicks on that.
I want to make green if the user clicks on the right answer and red if the user clicks on the wrong answer.
If the user clicks on the wrong answer then it should show the right answer by making the background green and the rest all should become the red border.
See output:
Home.js file:
import React from 'react'
import Questions from './Questions'
const Home = () => {
function action(){
}
return (
<>
<div className="main">
{
Questions.map((item)=>(
<div className="box">
<div className="title">
<h2 className="qno">{item.numb}</h2>
<h2> {item.question}</h2>
</div>
<div className="options">
<span onClick={()=>action()} >{item.options.q1}</span>
<span>{item.options.q2}</span>
<span>{item.options.q3}</span>
<span>{item.options.q4}</span>
</div>
</div>
))
}
</div>
</>
)
}
export default Home;
Questions.js file:
let Questions = [
{
numb: 1,
question: "What does HTML stand for?",
answer: "Hyper Text Markup Language",
options: {
q1: "Hyper Text Preprocessor",
q2: "Hyper Text Markup Language",
q3: "Hyper Text Multiple Language",
q4: "Hyper Tool Multi Language",
},
},
{
numb: 2,
question: "Who is Ankit Yadav?",
answer: "Engineer",
options: {
q1: "Engineer",
q2: "Doctor",
q3: "CEO",
q4: "Scientist",
},
},
];
export default Questions;
style.css file:
/* styling */
.main{
width: 70vw;
height: 100%;
box-shadow: 0 0 14px 0;
margin: 30px auto;
border-radius: 5px;
}
.box{
padding: 10px;
border-bottom: 2px solid #4c4c4c;
}
.title .qno{
font-size: 1.7rem;
font-weight: 800;
font-family: 'Courier New', Courier, monospace;
background-color: #4c4c4c;
padding: 5px;
border-radius: 70px;
color: #fff;
}
.title h2{
font-size: 1.7rem;
font-weight: 500;
margin-left: 10px;
}
.box .title{
display: flex;
}
.options{
display: flex;
flex-direction: column;
justify-content: space-between;
margin: 20px 25px;
}
You can achieve it using inline styles and a few util functions
const Home = () => {
const [answerStatus, setAnswerStatus] = useState(() => {
return Questions.map((item) => {
return {
numb: item.numb,
answered: false,
givenAnswer: ""
};
});
});
const action = (questionNumber, answer) => {
setAnswerStatus((prevState) => {
return prevState.map((item) =>
item.numb === questionNumber
? { ...item, answered: true, givenAnswer: answer }
: item
);
});
};
const isAnswerCorrect = (questionNumber) => {
const status = answerStatus.find((item) => item.numb === questionNumber);
const question = Questions.find((item) => item.numb === questionNumber);
return status.answered && question.answer === status.givenAnswer;
};
const questionAnswered = (questionNumber) => {
const status = answerStatus.find((item) => item.numb === questionNumber);
return status.answered;
};
const getGivenAnswer = (questionNumber) => {
return answerStatus.find((item) => item.numb === questionNumber)
?.givenAnswer;
};
return (
<>
<div className="main">
{Questions.map((item) => (
<div className="box">
<div className="title">
<h2 className="qno">{item.numb}</h2>
<h2> {item.question}</h2>
</div>
<div className="options">
{Object.entries(item.options).map(([optionId, optionDesc]) => {
return (
<span
onClick={() => action(item.numb, optionDesc)}
style={{
backgroundColor: questionAnswered(item.numb)
? isAnswerCorrect(item.numb) &&
getGivenAnswer(item.numb) === optionDesc
? "lightgreen"
: isAnswerCorrect(item.numb)
? "lightblue"
: item.answer !== optionDesc
? "tomato"
: "lightgreen"
: "lightblue",
padding: "5px",
borderRadius: "3px",
margin: "3px",
cursor: "pointer"
}}
>
{optionDesc}
{questionAnswered(item.numb) &&
getGivenAnswer(item.numb) === optionDesc &&
" (given answer)"}
</span>
);
})}
</div>
</div>
))}
</div>
</>
);
};
export default Home;
Code sandbox => https://codesandbox.io/s/quirky-hill-cwoc5?file=/src/App.js
I would recommend to create separate component called Question to avoid working with arrays of data and put state login inside. But if this is not possible I would do it this way:
Home.js
import React from 'react'
import Questions from './Questions'
const Home = () => {
// Add this two state values
const { highlightedRightIds, setHighlightedRightIds } = useState([]);
const { highlightedWrongIds, setHighlightedWrongIds } = useState([]);
// Handle click here
const handleClick = (questionId, isRight) => {
setHighlightedWrongIds([...highlightedWrongIds, questionId]);
if (isRight) {
setHighlightedRightIds([...highlightedRightIds, questionId]);
}
}
return (
<>
<div className="main">
{
Questions.map((item)=>(
<div className="box">
<div className="title">
<h2 className="qno">{item.numb}</h2>
<h2> {item.question}</h2>
</div>
<div className="options">
{
// use map to render a list of options
item.options.map(option => {
const isRight = option === item.answer;
const highlight = isRight
? highlightedRightIds.includes(item.numb)
: highlightedWrongIds.includes(item.numb);
const highlightClass = isRight
? "rightAnswer"
: "wrongAnswer";
return <span
onClick={() => handleClick(item.numb, isRight)}
className={highlight ? highlightClass : ""}
>
{option}
</span>;
})
}
</div>
</div>
))
}
</div>
</>
)
}
export default Home;
style.css (add new classes)
// ... other styles
.rightAnswer{
background-color: green;
}
.wrongAnswer{
border-color: red;
}

ReactJS onclick add or remove class to another element

I am struggling to convert my normal jQuery code in to React JS (I'm new to React).
I have the following code:
$(".add").click(function () {
$("nav").addClass("show");
});
$(".remove").click(function () {
$("nav").removeClass("show");
});
$(".toggle").click(function () {
$("nav").toggleClass("show");
});
nav {
width: 250px;
height: 150px;
background: #eee;
padding: 15px;
margin-top: 15px;
}
nav.show {
background: red;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<button class="add">Add</button>
<button class="remove">Remove</button>
<button class="toggle">Toggle</button>
<nav>Navigation menu</nav>
Tried references seems that only add/remove class for the same element:
https://stackoverflow.com/a/42630743/6191987
How to add or remove a className on event in ReactJS?
So, how can I convert or create the same jQuery methods to ReactJS?
Use the state that keeps the track of whether to show the nav or not.
Use a class name in the react code that corresponds to the state.
React uses "className" instead of "class" since "class" is already a reserved word in javascript.
You could check this sandbox link for implementation
function App() {
const [show, setShow] = React.useState();
return (
<div className="App">
<button className="add" onClick={() => setShow(true)}>
Add
</button>
<button className="remove" onClick={() => setShow(false)}>
Remove
</button>
<button className="toggle" onClick={() => setShow(!show)}>
Toggle
</button>
<nav className={show ? "show" : ""}>Navigation menu</nav>
</div>
);
}
You could combine the use useRef for nav and manipulate the ref (accessing nav's DOM) with event handlers for each button
import React from "react";
import "./styles.css";
export default function App() {
const navRef = React.useRef(null);
const onAddClick = (e) => {
navRef.current.classList.add("show");
};
const onRemoveClick = (e) => {
navRef.current.classList.remove("show");
};
const onToggleClick = (e) => {
navRef.current.classList.toggle("show");
};
return (
<div className="App">
<button onClick={onAddClick}>Add</button>
<button onClick={onRemoveClick}>Remove</button>
<button onClick={onToggleClick}>Toggle</button>
<nav ref={navRef}>Navigation menu</nav>
</div>
);
}
.App {
font-family: sans-serif;
}
nav {
width: 250px;
height: 150px;
background: #eee;
padding: 15px;
margin-top: 15px;
}
nav.show {
background: red;
color: white;
}
Codesanbox link for demo
Reference:
Refs and the DOM
useRef doc
Element.classList doc

React.js Popup modal for shopping cart

I am currently working on a shopping cart and I am trying to figure out how to have the modal appear once I click on the shopping cart icon. I have looked at the documentation for the semantic-ui for modals but it is vague as to how to get the modal to appear when clicking on something. I am using the semantic-ui class="ui modal" for the modal.
I was thinking of putting an onClick on the icon but was still confused as to how to go from there. Currently, I have the icon in another component and the shopping cart in another separate component. I want the items to appear inside of the pop-up modal which should be the shopping cart.
import React from 'react'
import { Icon } from 'semantic-ui-react';
const ShoppingCartIcon = () => {
return(
<Icon.Group size='big' className="shopping_cart_icon">
<Icon link name='shopping cart'/>
<Icon corner='top right'/>
</Icon.Group>
)
}
export default ShoppingCartIcon;
import React from 'react'
import Shirt from './Shirt';
class ShoppingCart extends React.Component {
render() {
const listShirts = this.props.shirts.map(shirt => {
return <Shirt key={shirt.id} {...shirt}/>
})
return(
<div className="ui modal">
<div className="content">
{listShirts}
</div>
</div>
)
}
}
export default ShoppingCart;
Currently, I do not have the functionality for adding items to the cart working yet. I just want to focus on getting the modal to show up once I click on the shopping cart icon
as far as I see, you are not using neither redux nor context api. you are passing props with props drilling.
so this is how you should organize your code step by step.
we render cartIcon component in the header.js. here is a classic header
Header.js
import CartDropdown from "../cart-dropdown/cart-dropdown.component";
class Header extends React.Component {
constructor(props) {
super(props);
state = { hidden: true, cartItems:[]};
}
toggleHidden() {
this.setState(() => ({ hidden: !this.state.hidden }));
}
render() {
return (
<div className="header">
<Link className="logo-container" to="/">
<Logo className="logo" />
</Link>
<div className="options">
<Link className="option" to="/shop">
SHOP
</Link>
<Link to="/contact" className="option">
CONTACT
</Link>
{/* <Link></Link> */}
<CartIcon />
</div>
{hidden ? null : (
<CartDropdown
toggle={this.toggleHidden}
cartItems={this.state.cartItems}
></CartDropdown>
)}
</div>
);
}
}
you said you have not set the addItem functionality yet. as you add items to the cartItems array you will display them in the cart.
now we need to set up the cartDropdown component.
const CartDropdown = ({ cartItems, toggleHidden }) => (
<div className="cart-dropdown">
<div className="cart-items">
{cartItems.length ? (
cartItems.map(item => <CartItem key={item.id} item={item} />)
) : (
<span className="empty-message"> Your cart is empty </span>
)}
</div>
<CustomButton
onClick={() => {
toggleHidden();
}}
>
GO TO CHECKOUT
</CustomButton>
</div>
);
here we need to add css for cartDropdown. I do not how you are dealing with your css. prop-types or scss but here is the css code so you can apply to your project.
css for cartDropdown component
.cart-dropdown {
position: absolute;
width: 240px;
height: 340px;
display: flex;
flex-direction: column;
padding: 20px;
border: 1px solid black;
background-color: white;
top: 80px;
right: 0;
z-index: 5;
.cart-items {
height: 240px;
display: flex;
flex-direction: column;
overflow: scroll;
}
.empty-message {
font-size: 18px;
margin: 50px auto;
}
button {
margin-top: auto;
}
}

ReactJS ES6 building a TODO small project blocker in rendering elements

I'm making a small TODO list project and I hit the wall. I created a form that is responsible for adding new tasks on the list. It consists of two inputs - one for the task name and the other one for the description. There's also an image submit input.
The problem is that only the first item is appended. Another entries just replace the current one. I was trying to somehow gather all of these into one array and map but was unsuccessful. Perhaps it's a couple of lines of code to make this work properly and I'm missing something. Please take a look:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import addStaticButton from './images/addStaticBtn.png';
import addButton from './images/addTaskBtn.png';
var todoContainer = document.getElementById('todo');
class AddTaskElement extends Component {
render() {
const styling = {
addTaskContainer: {
border: "2px solid #000",
width: "350px",
cursor: 'pointer',
boxSizing: 'border-box'
},
leftArea: {
position: 'relative',
float: 'left',
marginRight: '20px',
padding: '12px'
},
addStaticBtn: {
width: '50px',
height: '50px'
}
}
return (
<div style={styling.addTaskContainer} onClick={this.props.isAddTaskClicked} className="addTaskContainer">
<div style={styling.leftArea} className="leftArea">
<img style={styling.addStaticBtn} id="addStaticBtn" alt="addStaticBtn" src={addStaticButton}/>
</div>
<div className="rightArea">
<h1 id="addTaskText">ADD TASK</h1>
</div>
</div>
);
}
}
class TaskInfo extends Component {
constructor(props) {
super(props);
}
render() {
const styling = {
taskInfoContainer: {
border: "2px solid #000",
boxSizing: 'border-box',
width: '350px'
},
taskNameContainer: {
padding: '10px',
},
taskDescriptionContainer: {
padding: '10px'
},
label: {
width: '100px',
display: 'inline-block'
},
taskName: {
width: '220px'
},
taskDescription: {
width: '220px',
height: '75px'
},
addTaskBtn: {
width: '50px',
height: '50px'
},
addTaskBtnContainer: {
textAlign: 'center'
}
}
return(
<div style={styling.taskInfoContainer} className={this.props.taskElementItemClass}>
<form onSubmit={this.props.formSubmit}>
<div className="taskNameContainer" style={styling.taskNameContainer}>
<label style={styling.label}>Name: </label>
<input id="taskName" style={styling.taskName} name="name" type="text" />
</div>
<div style={styling.taskDescriptionContainer} className="taskDescriptionContainer">
<label style={styling.label}>Description: </label>
<textarea id="taskDescription" style={styling.taskDescription} ></textarea>
</div>
<div style={styling.addTaskBtnContainer}>
<input style={styling.addTaskBtn} type="image" src={addButton} alt="Add Task" />
</div>
</form>
</div>
);
}
}
class TaskItem extends Component {
render() {
return(
<div>
{/*{this.props.children}*/}
<p>{this.props.taskItemName}</p>
<p>{this.props.taskItemDescription}</p>
</div>
);
}
}
class TaskList extends Component {
static defaultProps = {
numberOfTasks: 0
}
render() {
const styling = {
taskListContainer: {
width: '350px',
border: '2px solid #000',
boxSizing: 'border-box',
textAlign: 'center'
}
};
return(
<div>
<div className="taskListContainer" style={styling.taskListContainer}>
<p>Task List ({this.props.numberOfTasks})</p>
<TaskItem taskItemName={this.props.taskItemName} taskItemDescription={this.props.taskItemDescription} />
</div>
</div>
);
}
}
class Printer extends Component {
constructor(props) {
super(props);
this.state = {
taskElementItemState: 'hidden',
taskName: '',
taskDescription: ''
}
this.handleAddTaskClick = this.handleAddTaskClick.bind(this);
this.handleTaskAdd = this.handleTaskAdd.bind(this);
}
handleTaskAdd(e) {
e.preventDefault();
this.setState({
taskName: document.getElementById('taskName').value,
taskDescription: document.getElementById('taskDescription').value
});
}
handleAddTaskClick() {
this.setState({
taskElementItemState: this.state.taskElementItemState === 'hidden' ? 'visible' : 'hidden'
});
}
render() {
return(
<div>
<AddTaskElement isAddTaskClicked={this.handleAddTaskClick}/>
<TaskInfo formSubmit={this.handleTaskAdd} taskElementItemClass={this.state.taskElementItemState}/>
<TaskList taskItemName={this.state.taskName} taskItemDescription={this.state.taskDescription} />
</div>
);
}
}
ReactDOM.render(<Printer/>, todoContainer);

Categories

Resources