import React, { useState } from 'react';
import styled from 'styled-components';
import CandyDetails from './CandyDetails';
const candies = [
{ name: 'Snickers', funFact: 'Snickers is named after a horse!', img: 'path_to_snickers_image.jpg' },
{ name: 'Kit Kat', funFact: 'Kit Kat is known as "Kitto Katsu" in Japan, which means "surely win".', img: 'path_to_kitkat_image.jpg' },
// ... Add more candies with fun facts and image paths
];
const AppContainer = styled.div`
background-color: black;
color: white;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-image: url('path_to_spooky_background.jpg'); // Replace with your spooky background
background-size: cover;
`;
const CandyList = styled.ul`
list-style-type: none;
padding: 0;
`;
const CandyItem = styled.li`
margin: 5px 0;
cursor: pointer;
`;
function App() {
const [selectedCandy, setSelectedCandy] = useState(null);
const handleCandyClick = (candy) => {
setSelectedCandy(candy);
};
return (
<AppContainer>
<h1>Halloween Candy Counter</h1>
<CandyList>
{candies.map(candy => (
<CandyItem key={candy.name} onClick={() => handleCandyClick(candy)}>
{candy.name}
</CandyItem>
))}
</CandyList>
{selectedCandy && <CandyDetails candy={selectedCandy} onClose={() => setSelectedCandy(null)} />}
</AppContainer>
);
}
export default App;
import React from 'react';
import styled from 'styled-components';
const DetailsContainer = styled.div`
border: 2px solid white;
padding: 20px;
margin-top: 20px;
width: 300px;
position: relative;
`;
const CloseButton = styled.button`
position: absolute;
top: 5px;
right: 5px;
background: red;
border: none;
border-radius: 50%;
width: 20px;
height: 20px;
color: white;
font-weight: bold;
cursor: pointer;
`;
const CandyImage = styled.img`
width: 100%;
margin-bottom: 10px;
`;
function CandyDetails({ candy, onClose }) {
return (
<DetailsContainer>
<CloseButton onClick={onClose}>X</CloseButton>
<CandyImage src={candy.img} alt={candy.name} />
<h2>{candy.name}</h2>
<p>{candy.funFact}</p>
</DetailsContainer>
);
}
export default CandyDetails;
bashCopy code
npm start
javascriptCopy code
const [count, setCount] = useState(0);