|
1 |
| -import React, { FunctionComponent } from 'react'; |
| 1 | +import React, { FunctionComponent, useState } from 'react'; |
2 | 2 | import Pokemon from '../models/pokemon';
|
3 | 3 | import './pokemon-card.css';
|
4 |
| -type Props = { |
5 |
| - pokemon: Pokemon |
| 4 | +import formatDate from '../helpers/formatDate'; |
| 5 | +import formatType from '../helpers/formatType'; |
| 6 | +type Props = {//methodes pour les props |
| 7 | + pokemon: Pokemon, |
| 8 | + borderColor ? : string //couleur des bordures par défaut |
6 | 9 | };
|
7 | 10 |
|
8 |
| -const PokemonCard: FunctionComponent<Props> = ({ pokemon }) => { |
| 11 | +const PokemonCard: FunctionComponent<Props> = ({ pokemon, borderColor = 'red' }) => { //methode pour les props |
| 12 | + const [color, setColor] = useState <string>(); |
| 13 | + |
| 14 | + const showBorder = () => { |
| 15 | + setColor(borderColor); |
| 16 | + } |
| 17 | + const hideBorder = ()=>{ |
| 18 | + setColor("#f5f5f5"); |
| 19 | + } |
9 | 20 |
|
10 | 21 | return (
|
11 |
| - <div className="col s6 m4"> |
12 |
| - <div className="card horizontal"> |
| 22 | + <div className="col s6 m4" onMouseEnter={showBorder} onMouseLeave={hideBorder}> |
| 23 | + <div className="card horizontal" style={{borderColor : color}}> |
13 | 24 | <div className="card-image">
|
14 | 25 | <img src={pokemon.picture} alt={pokemon.name} />
|
15 | 26 | </div>
|
16 | 27 | <div className="card-stacked">
|
17 | 28 | <div className="card-content">
|
| 29 | + |
18 | 30 | <p>{pokemon.name}</p>
|
19 |
| - <p><small>{pokemon.created.toString()}</small></p> |
| 31 | + <p><small>{formatDate(pokemon.created)}</small></p> |
| 32 | + |
| 33 | + {pokemon.types.map(type=>( |
| 34 | + <span key={type} className={formatType(type)}> {type}</span> |
| 35 | + ))} |
| 36 | + |
20 | 37 | </div>
|
21 | 38 | </div>
|
22 | 39 | </div>
|
|
0 commit comments