Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,29 @@
border-spacing: 4px;
}
}

.arrow-navigation {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
}

.arrow-navigation button {
padding: 10px 18px;
border: none;
border-radius: 999px;
background: var(--accent);
color: white;
font-weight: bold;
cursor: pointer;
transition:
transform 0.1s ease,
background 0.15s ease;
}

.arrow-navigation button:hover,
.arrow-navigation button:focus-visible {
background: var(--accent-hover, #cc3f5a);
transform: translateY(-2px);
}
6 changes: 6 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FavoritesSidebar from './FavoritesSidebar';
import SearchBar, { SEARCH_STORAGE_KEY } from './SearchBar';
import { listAllPokemon } from './Api';
import PokemonDetails from './PokemonDetails';
import ArrowNavigation from './ArrowNavigation';

import './App.css';

Expand Down Expand Up @@ -73,6 +74,11 @@ function App() {
setSelectedPokemonId={setSelectedPokemonId}
/>

<ArrowNavigation
selectedPokemonId={selectedPokemonId}
setSelectedPokemonId={setSelectedPokemonId}
/>

<section className="search-bar">
<SearchBar onSearch={runSearch} isLoading={isPending} />
</section>
Expand Down
60 changes: 60 additions & 0 deletions src/ArrowNavigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Dispatch, SetStateAction } from 'react';

const MAX_POKEMON_ID = 1025;
const SPECIAL_POKEMON_START = 10001;
const SPECIAL_POKEMON_MAX = 10025;

type ArrowNavigationProps = {
selectedPokemonId: number | null;
setSelectedPokemonId: Dispatch<SetStateAction<number | null>>;
};

function ArrowNavigation({
selectedPokemonId,
setSelectedPokemonId,
}: ArrowNavigationProps) {
return (
<section className="arrow-navigation">
{selectedPokemonId !== null && selectedPokemonId > 1 && (
<button
type="button"
aria-label="Previous Pokemon"
onClick={() =>
setSelectedPokemonId((id) =>
id === SPECIAL_POKEMON_START
? MAX_POKEMON_ID
: (id ?? 1) - 1
)
}
>
<span aria-hidden="true">←</span>{' '}
{selectedPokemonId === SPECIAL_POKEMON_START
? MAX_POKEMON_ID
: selectedPokemonId - 1}
</button>
)}
{selectedPokemonId !== null &&
selectedPokemonId > 0 &&
selectedPokemonId < SPECIAL_POKEMON_MAX && (
<button
type="button"
aria-label="Next Pokemon"
onClick={() =>
setSelectedPokemonId((id) =>
id === MAX_POKEMON_ID
? SPECIAL_POKEMON_START
: (id ?? 0) + 1
)
}
>
{selectedPokemonId === MAX_POKEMON_ID
? SPECIAL_POKEMON_START
: selectedPokemonId + 1}{' '}
<span aria-hidden="true">→</span>
</button>
)}
</section>
);
}

export default ArrowNavigation;