forked from fcsouza/desafio-loja-pokemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Prince Vasconcelos
committed
Mar 22, 2021
1 parent
6f46b76
commit 82ebfdc
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, {useContext} from 'react' | ||
|
||
import DataContext from 'contexts/data' | ||
import Loading from 'components/Loading' | ||
|
||
import * as H from 'utils/helpers' | ||
import * as S from './styles' | ||
|
||
export default ({ data, loading }) => { | ||
if (loading) return <Loading /> | ||
|
||
if (data.length === 0) return <div>Nenhum resultado encontrado</div> | ||
|
||
const { buyPokemon } = useContext(DataContext) | ||
|
||
const handleBuyButton = name => buyPokemon(name) | ||
|
||
return ( | ||
<S.List> | ||
{data.map(({ name, weight, sprites}) => ( | ||
<S.Item key={name}> | ||
<S.ItemLink to={`/pokemon/${name}`}> | ||
<S.ImageContainer> | ||
{sprites | ||
? <img src={sprites.front_default} alt={`A front image of ${name}`} /> | ||
: <Loading size="2px" />} | ||
</S.ImageContainer> | ||
{/* {sprites && sprites.length > 0 | ||
? <ImageContainer> | ||
{sprites.map(({ front_default, alt}) => <img src={url} alt={alt} />)} | ||
</ImageContainer> | ||
: <Loading size="2px" />} */} | ||
<h3>{name}</h3> | ||
{weight ? <span>R$ {H.priceFormat(weight)}</span> : null} | ||
</S.ItemLink> | ||
<button onClick={() => handleBuyButton(name)}>COMPRAR</button> | ||
</S.Item> | ||
))} | ||
</S.List> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import styled from 'styled-components' | ||
import {Link} from 'react-router-dom' | ||
|
||
export const List = styled.ul` | ||
display: grid; | ||
grid-template-columns: repeat(auto-fill, 200px); | ||
gap: 32px 64px; | ||
justify-content: center; | ||
margin-top: 24px; | ||
` | ||
|
||
export const Item = styled.li` | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
overflow: hidden; | ||
position: relative; | ||
padding: 16px 16px 32px; | ||
&:hover { | ||
background: #f8f9fa; | ||
button { | ||
bottom: 0; | ||
} | ||
} | ||
> button { | ||
position: absolute; | ||
font-weight: 700; | ||
height: 24px; | ||
width: 100%; | ||
color: white; | ||
background: #333; | ||
bottom: -24px; | ||
transition: all .1s; | ||
outline: none; | ||
} | ||
` | ||
|
||
export const ItemLink = styled(Link)` | ||
display: flex; | ||
flex-direction: column; | ||
width: 98px; | ||
text-align: center; | ||
> h3 { | ||
font-weight: 700; | ||
text-transform: capitalize; | ||
} | ||
> span { | ||
font-weight: 700; | ||
opacity: 0.7; | ||
font-size: 14px; | ||
margin-top: 4px; | ||
} | ||
` | ||
|
||
export const ImageContainer = styled.div` | ||
position: relative; | ||
min-height: 98px; | ||
> img { | ||
position: absolute; | ||
width: 98px; | ||
top: 0; | ||
left: 0; | ||
} | ||
` |