Skip to content

Commit

Permalink
create Gallery component
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince Vasconcelos committed Mar 22, 2021
1 parent 6f46b76 commit 82ebfdc
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/components/Gallery/index.js
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>
)
}
70 changes: 70 additions & 0 deletions src/components/Gallery/styles.js
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;
}
`

0 comments on commit 82ebfdc

Please sign in to comment.