This commit is contained in:
Viktor Rådberg
2023-07-02 10:14:41 +02:00
parent b78321586f
commit 17dbef5f3d
6 changed files with 97 additions and 32 deletions

View File

@@ -1,9 +1,16 @@
import './App.css'; import './App.css';
import Counters from './Components/Counters'; import Counters from './Components/Counters/Counters';
import styled from 'styled-components';
const MainWrapper = styled.div`
`;
function App() { function App() {
return ( return (
<MainWrapper>
<Counters/> <Counters/>
</MainWrapper>
); );
} }

View File

@@ -1,25 +0,0 @@
import * as S from "./Componets.style";
const Counters = () => {
return (
<S.CountersWrapper>
<S.CountersGrid>
<S.GridItem>
hej1
</S.GridItem>
<S.GridItem>
hej2
</S.GridItem>
<S.GridItem>
hej3
</S.GridItem>
<S.GridItem>
hej4
</S.GridItem>
</S.CountersGrid>
</S.CountersWrapper>
);
}
export default Counters;

View File

@@ -3,7 +3,7 @@ import styled from "styled-components";
export const CountersWrapper = styled.div` export const CountersWrapper = styled.div`
width: 100vw; width: 100vw;
height: 100vh; height: 100vh;
background-color: black; background-color: #4f4f4f;
`; `;
export const CountersGrid = styled.div` export const CountersGrid = styled.div`
@@ -11,16 +11,16 @@ export const CountersGrid = styled.div`
flex-wrap: wrap; flex-wrap: wrap;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background-color: red;
border-radius: 10px; border-radius: 10px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
`; `;
export const GridItem = styled.div` export const GridItemContainer = styled.div`
display: flex; display: flex;
width: 50%; width: 50%;
height: 50vh; height: 50vh;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background-color: antiquewhite;
border-radius: 10px;
`; `;

View File

@@ -0,0 +1,26 @@
import * as S from "./Counters.style";
import LifeCounter from "../LifeCounter/LifeCounter";
const Counters = () => {
return (
<S.CountersWrapper>
<S.CountersGrid>
<S.GridItemContainer>
<LifeCounter backgroundColor="grey"/>
</S.GridItemContainer>
<S.GridItemContainer>
<LifeCounter backgroundColor="pink"/>
</S.GridItemContainer>
<S.GridItemContainer>
<LifeCounter backgroundColor="white"/>
</S.GridItemContainer>
<S.GridItemContainer>
<LifeCounter backgroundColor="lightblue"/>
</S.GridItemContainer>
</S.CountersGrid>
</S.CountersWrapper>
);
}
export default Counters;

View File

@@ -0,0 +1,37 @@
import styled from "styled-components";
//LifeCounterWrapper with a background color variable:
export const LifeCounterWrapper = styled.div<{ backgroundColor?: string }>`
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
background-color: ${props => props.backgroundColor || "antiquewhite"};
border-radius: 10px;
`;
export const LifeCounterButton = styled.button`
width: 100%;
height: 100%;
font-size: 5rem;
font-weight: bold;
background-color: transparent;
border: none;
outline: none;
cursor: pointer;
`;
export const LifeCounterText = styled.p`
font-size: 5rem;
font-weight: bold;
text-align: center;
margin: 0;
padding: 0;
`;

View File

@@ -0,0 +1,20 @@
import { useState } from "react";
import * as S from "./LifeCounter.style";
type LifeCounterProps = {
backgroundColor: string;
}
const LifeCounter = ({backgroundColor}: LifeCounterProps) => {
const [life, setLife] = useState(40);
return (
<S.LifeCounterWrapper backgroundColor={backgroundColor}>
<S.LifeCounterButton onClick={() => setLife(life - 1)}>-</S.LifeCounterButton>
<S.LifeCounterText>{life}</S.LifeCounterText>
<S.LifeCounterButton onClick={() => setLife(life + 1)}>+</S.LifeCounterButton>
</S.LifeCounterWrapper>
);
}
export default LifeCounter;