Skip to content

Commit

Permalink
Added Image Component.
Browse files Browse the repository at this point in the history
  • Loading branch information
Azenris committed Nov 5, 2023
1 parent 7fdbaab commit 79873fc
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 25 deletions.
29 changes: 29 additions & 0 deletions src/components/Image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

export type ImageProps = {
key?: string;
className?: string;
src: string;
alt: string;
width: number;
height: number;
loading?: 'eager' | 'lazy' | undefined;
title?: string;
};

export function Image({ key, className, src, alt, width, height, loading, title }: ImageProps) {

const fullSource : string = `${import.meta.env.BASE_URL}${src}`;

return (
<img
key={key}
className={className}
src={fullSource}
alt={alt}
width={width}
height={height}
loading={loading}
title={title}
/>
);
}
3 changes: 2 additions & 1 deletion src/components/ItemCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ElementNames } from "../data/elements";
import { get_item } from "../data/items";
import { get_move } from "../data/moves";
import { Image } from "./Image";

export type ItemCardProps = {
itemID: number;
Expand Down Expand Up @@ -32,7 +33,7 @@ export function ItemCard({ itemID, clicked }: ItemCardProps) {
)}
</div>
<div className="item-card-image-block">
<img
<Image
className="item-card-image"
src={item.img}
alt={item.name}
Expand Down
3 changes: 2 additions & 1 deletion src/components/MoveCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { itemDB } from "../data/items";
import { get_move } from "../data/moves";
import { Image } from "./Image";

export type MoveCardProps = {
moveID: number;
Expand Down Expand Up @@ -30,7 +31,7 @@ export function MoveCard({ moveID, clicked }: MoveCardProps) {
)}
</div>
<div className="move-card-image-block">
<img
<Image
className="move-card-image"
src={move.img}
alt={move.name}
Expand Down
17 changes: 9 additions & 8 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NavLink, useLocation } from "react-router-dom";
import { Image } from "./Image";

type MenuItem = {
path: string;
Expand All @@ -10,37 +11,37 @@ const menuItems: MenuItem[] = [
{
path: "/",
name: "Home",
icon: `${import.meta.env.BASE_URL}/imgs/pokeball-0.png`
icon: "/imgs/pokeball-0.png"
},
{
path: "/pokemon",
name: "POKéMON",
icon: `${import.meta.env.BASE_URL}/imgs/pokeball-0.png`
icon: "/imgs/pokeball-0.png"
},
{
path: "/collection",
name: "Collection",
icon: `${import.meta.env.BASE_URL}/imgs/pokeball-0.png`
icon: "/imgs/pokeball-0.png"
},
{
path: "/item",
name: "Items",
icon: `${import.meta.env.BASE_URL}/imgs/pokeball-0.png`
icon: "/imgs/pokeball-0.png"
},
{
path: "/tm",
name: "HMs / TMs",
icon: `${import.meta.env.BASE_URL}/imgs/pokeball-0.png`
icon: "/imgs/pokeball-0.png"
},
{
path: "/move",
name: "Moves",
icon: `${import.meta.env.BASE_URL}/imgs/pokeball-0.png`
icon: "/imgs/pokeball-0.png"
},
{
path: "/about",
name: "About",
icon: `${import.meta.env.BASE_URL}/imgs/pokeball-0.png`
icon: "/imgs/pokeball-0.png"
}
];

Expand All @@ -54,7 +55,7 @@ export function Navbar() {
return (
<li key={menu.path} className={location == menu.path ? "active" : ""}>
<NavLink to={menu.path}>
<img src={menu.icon} alt={menu.name}></img>
<Image src={menu.icon} alt={menu.name} width={12} height={12} />
{' '}
{menu.name}
</NavLink>
Expand Down
9 changes: 5 additions & 4 deletions src/components/PokemonCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PokemonElements } from "./PokemonElement";
import { PokemonGameVersionNames, PokemonAvailableGameVersionNames, get_pokemon } from "../data/pokemon";
import { Image } from "./Image";

export type PokemonSelectionProps = {
pokemonID: number;
Expand All @@ -26,22 +27,22 @@ export function PokemonCard({ pokemonID, active, forceInPokeball, clicked }: Pok
<div>
{pokemon.available.map((game) => {
return (
<img
<Image
key={game}

Check failure on line 31 in src/components/PokemonCard.tsx

View workflow job for this annotation

GitHub Actions / Build

Type 'import("/home/runner/work/webdev-pokemon/webdev-pokemon/src/data/pokemon").PokemonGameVersion' is not assignable to type 'string'.
className="poke-card-ball"
src={`/imgs/pokeball-${game}.png`}
alt={PokemonGameVersionNames[game]}
title={PokemonAvailableGameVersionNames[game]}
width="24"
height="24"
width={24}
height={24}
loading="lazy"
/>
);
})}
</div>
<div className={`poke-card-name ${activeClass}`}>{pokemon.name}</div>
<div className={`poke-card-image-block ${activeClass} ${forceInPokeball ? "pokeball" : ""}`}>
<img className={`poke-card-image ${activeClass}`} src={pokemon.imgGBC} alt={pokemon.name} width={pokemon.imgW} height={pokemon.imgH} />
<Image className={`poke-card-image ${activeClass}`} src={pokemon.imgGBC} alt={pokemon.name} width={pokemon.imgW} height={pokemon.imgH} />
</div>
<PokemonElements types={pokemon.types} />
<div className={`poke-card-id ${activeClass}`}>#{pokemon.id}</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/itemdex/ItemdexPicture.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Item } from "../../data/items";
import { Image } from "../Image";

export type ItemdexPictureProps = {
item: Item;
Expand All @@ -15,7 +16,7 @@ export function ItemdexPicture({ item }: ItemdexPictureProps) {
<td>
<div className="item-image-header">
<div className="item-image-block-big">
<img className="item-image-big" src={item.img} alt={item.name} width={item.imgW * 3} height={item.imgH * 3} />
<Image className="item-image-big" src={item.img} alt={item.name} width={item.imgW * 3} height={item.imgH * 3} />
</div>
</div>
</td>
Expand Down
3 changes: 2 additions & 1 deletion src/components/movedex/movedexPicture.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Move } from "../../data/moves";
import { Image } from "../Image";

export type MovedexPictureProps = {
move: Move;
Expand All @@ -15,7 +16,7 @@ export function MovedexPicture({ move }: MovedexPictureProps) {
<td>
<div className="move-image-header">
<div className="move-image-block-big">
<img className="move-image-big" src={move.img} alt={move.name} width={move.imgW * 3} height={move.imgH * 3} />
<Image className="move-image-big" src={move.img} alt={move.name} width={move.imgW * 3} height={move.imgH * 3} />
</div>
</div>
</td>
Expand Down
11 changes: 6 additions & 5 deletions src/components/pokedex/PokedexEvolutions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Link } from "react-router-dom";
import { EvolveTo, Pokemon, PokemonEvolutionType, get_pokemon, get_pokemon_base, get_pokemon_evolution_index, get_pokemon_name_span } from "../..//data/pokemon";
import { get_item, get_item_id_name_span, get_item_name_span } from "../../data/items";
import { Image } from "../Image";

type PokedexEvolutionPokemonProps = {
pokemon: Pokemon;
Expand All @@ -13,7 +14,7 @@ function PokedexEvolutionPokemon({ pokemon }: PokedexEvolutionPokemonProps) {
<tr>
<td>
<Link to={`/pokemon/${pokemon.id}`} className="pokedex-evolution-image">
<img
<Image
className="pokemon-image"
src={pokemon.imgGBC}
alt={pokemon.name}
Expand All @@ -35,7 +36,7 @@ function PokedexEvolutionPokemon({ pokemon }: PokedexEvolutionPokemonProps) {

function PokedexEvolutionArrow() {
return (
<img
<Image
className="pokedex-evolution-requirement-arrow"
src="/imgs/evolution_arrow.png"
alt="→"
Expand Down Expand Up @@ -66,7 +67,7 @@ function PokedexEvolutionRequirement({ pokemon, requirement }: PokedexEvolutionR
<tbody>
<tr>
<td>
<img
<Image
src="/imgs/evolution_trade.png"
alt="Trade"
width={26}
Expand All @@ -88,7 +89,7 @@ function PokedexEvolutionRequirement({ pokemon, requirement }: PokedexEvolutionR
<tbody>
<tr>
<td>
<img
<Image
src="/imgs/evolution_levelup.png"
alt="LevelUp"
width={26}
Expand All @@ -111,7 +112,7 @@ function PokedexEvolutionRequirement({ pokemon, requirement }: PokedexEvolutionR
<tr>
<td>
<Link to={`/item/${item.id}`}>
<img
<Image
src={item.img}
alt={item.name}
width={item.imgW}
Expand Down
7 changes: 4 additions & 3 deletions src/components/pokedex/PokedexGameAvailability.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Pokemon, PokemonAvailableGameVersionNames, PokemonGameVersionNames } from "../../data/pokemon";
import { Image } from "../Image";

export type PokedexGameAvailabilityProps = {
pokemon: Pokemon;
Expand All @@ -25,13 +26,13 @@ export function PokedexGameAvailability({ pokemon }: PokedexGameAvailabilityProp
<tr key={game}>
<td>
<div className="pokedex-game-availability">
<img
<Image
className="poke-card-ball"
src={`/imgs/pokeball-${game}.png`}
alt={PokemonGameVersionNames[game]}
title={PokemonAvailableGameVersionNames[game]}
width="24"
height="24"
width={24}
height={24}
/>
{PokemonGameVersionNames[game]}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/pokedex/PokedexPicture.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Pokemon } from "../../data/pokemon";
import { Image } from "../Image";

export type PokedexPictureProps = {
pokemon: Pokemon;
Expand All @@ -15,7 +16,7 @@ export function PokedexPicture({ pokemon }: PokedexPictureProps) {
<td>
<div className="pokemon-image-header">
<div className="pokemon-image-block-big">
<img
<Image
className="pokemon-image-big"
src={pokemon.imgGBC}
alt={pokemon.name}
Expand Down

0 comments on commit 79873fc

Please sign in to comment.