init: Initial Commit
This commit is contained in:
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
|
||||
}
|
||||
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Vue 3 + Vite
|
||||
|
||||
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).
|
||||
13
index.html
Normal file
13
index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Pokedex by xyvs</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
2318
package-lock.json
generated
Normal file
2318
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
23
package.json
Normal file
23
package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "pokedex",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"colorthief": "^2.4.0",
|
||||
"tinycolor2": "^1.6.0",
|
||||
"vue": "^3.3.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^4.2.3",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"postcss": "^8.4.31",
|
||||
"tailwindcss": "^3.3.3",
|
||||
"vite": "^4.4.5"
|
||||
}
|
||||
}
|
||||
6
postcss.config.js
Normal file
6
postcss.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
1
public/vite.svg
Normal file
1
public/vite.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
4
src/.prettierrc
Normal file
4
src/.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"tabWidth": 2,
|
||||
"useTabs": false
|
||||
}
|
||||
44
src/App.vue
Normal file
44
src/App.vue
Normal file
@@ -0,0 +1,44 @@
|
||||
<script setup>
|
||||
|
||||
import { ref } from 'vue'
|
||||
|
||||
import Pokedex from './components/Pokedex.vue'
|
||||
import About from './components/About.vue'
|
||||
import Page404 from './components/404.vue'
|
||||
|
||||
const pokemonId = ref(null)
|
||||
|
||||
const isPokemon = ref(false)
|
||||
const isAbout = ref(false)
|
||||
const is404 = ref(false)
|
||||
|
||||
|
||||
function getPage() {
|
||||
const url = window.location.href;
|
||||
const page = url.split("/").slice(-1)[0];
|
||||
|
||||
if (page > 0 && page < 1006) {
|
||||
isPokemon.value = true
|
||||
pokemonId.value = parseInt(page)
|
||||
} else if (page === 'about') {
|
||||
isAbout.value = true;
|
||||
} else {
|
||||
is404.value = true
|
||||
}
|
||||
}
|
||||
|
||||
getPage()
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="isPokemon">
|
||||
<Pokedex :pokemonId="pokemonId" />
|
||||
</div>
|
||||
<div v-if="isAbout">
|
||||
<About />
|
||||
</div>
|
||||
<div v-if="is404">
|
||||
<Page404 />
|
||||
</div>
|
||||
</template>
|
||||
1
src/assets/vue.svg
Normal file
1
src/assets/vue.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 496 B |
20
src/components/404.vue
Normal file
20
src/components/404.vue
Normal file
@@ -0,0 +1,20 @@
|
||||
<script setup>
|
||||
import Footer from './Footer.vue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-screen h-screen bg-red-500 text-red-100 flex flex-col items-center justify-between p-12">
|
||||
<div></div>
|
||||
<div class="space-y-3 text-center w-[50rem]">
|
||||
<div class="text-7xl font-semibold">
|
||||
404
|
||||
</div>
|
||||
<div class="text-3xl">
|
||||
Page not found
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
20
src/components/About.vue
Normal file
20
src/components/About.vue
Normal file
@@ -0,0 +1,20 @@
|
||||
<script setup>
|
||||
import Footer from './Footer.vue'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-screen h-screen bg-neutral-950 text-neutral-50 flex flex-col items-center justify-between p-12">
|
||||
<div></div>
|
||||
<div class="space-y-8 text-center w-[50rem]">
|
||||
<div class="text-5xl font-semibold">
|
||||
About
|
||||
</div>
|
||||
<div class="text-lg">
|
||||
Sit quis aut ipsum minima pariatur Totam laboriosam totam qui modi a Aliquam tenetur impedit quisquam nemo
|
||||
assumenda repudiandae sed Eligendi facere rem sequi voluptas vel? Fugit laudantium vero officia.
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
18
src/components/Description.vue
Normal file
18
src/components/Description.vue
Normal file
@@ -0,0 +1,18 @@
|
||||
<script setup>
|
||||
import { defineProps } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
pokemonData: Object,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-2 lg:w-96">
|
||||
<div class="text-xl lg:text-2xl font-semibold">
|
||||
Description
|
||||
</div>
|
||||
<div class="text-sm lg:text-base font-semibold">
|
||||
{{ pokemonData?.flavor_text_entries[0].flavor_text }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
13
src/components/Footer.vue
Normal file
13
src/components/Footer.vue
Normal file
@@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<div class="flex flex-col lg:flex-row items-center justify-center w-full gap-2">
|
||||
<div class="flex gap-4 justify-center items-center">
|
||||
<a href="/1">Pokedex</a>
|
||||
<a href="/about">About</a>
|
||||
<a href="https://dribbble.com/shots/2859891--025-Pikachu" target="_blank">Inspiration</a>
|
||||
<a href="https://dribbble.com/shots/2859891--025-Pikachu" target="_blank">Source Code</a>
|
||||
</div>
|
||||
<div class="hidden lg:block">-</div>
|
||||
<a href="https://github.com/xyvs" class="text-center font-semibold" target="_blank">Made by xyvs</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
22
src/components/Information.vue
Normal file
22
src/components/Information.vue
Normal file
@@ -0,0 +1,22 @@
|
||||
<script setup>
|
||||
import { defineProps } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
pokemonData: Object,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-2 text-sm lg:text-base">
|
||||
<div class="text-xl lg:text-2xl font-semibold">
|
||||
Information
|
||||
</div>
|
||||
<div class="">
|
||||
<span class="font-semibold">Height:</span> {{ pokemonData.height * 10 }}cm
|
||||
</div>
|
||||
<div class="">
|
||||
<span class="font-semibold">Height:</span> {{ pokemonData.weight / 10 }}kg
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
63
src/components/Pages.vue
Normal file
63
src/components/Pages.vue
Normal file
@@ -0,0 +1,63 @@
|
||||
<script setup>
|
||||
|
||||
import { ref, defineProps } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
numberPadding: Number,
|
||||
});
|
||||
|
||||
const activeId = ref(null)
|
||||
const pokedexNumbers = ref(null)
|
||||
|
||||
function calculatePageNumbers() {
|
||||
|
||||
const createArray = n => Array.from({ length: n }, (_, i) => i + 1);
|
||||
|
||||
const url = window.location.href;
|
||||
const pokemonId = parseInt(url.split("/").slice(-1)[0]);
|
||||
|
||||
const highestPokemon = 1005;
|
||||
const numberPadding = props.numberPadding;
|
||||
const numberSize = numberPadding / 2;
|
||||
|
||||
let lowerNumbers = numberSize;
|
||||
let upperNumbers = numberSize;
|
||||
|
||||
if (pokemonId < (numberSize + 1)) {
|
||||
lowerNumbers = pokemonId - 1;
|
||||
upperNumbers = numberPadding - lowerNumbers;
|
||||
} else if (pokemonId > (highestPokemon - (numberSize + 1))) {
|
||||
upperNumbers = highestPokemon - pokemonId;
|
||||
lowerNumbers = numberPadding - upperNumbers;
|
||||
}
|
||||
|
||||
let lowestNumbers = createArray(lowerNumbers)
|
||||
lowestNumbers = lowestNumbers.map((x, index) => {
|
||||
return pokemonId - (lowerNumbers - index)
|
||||
})
|
||||
|
||||
let highestNumbers = createArray(upperNumbers)
|
||||
highestNumbers = highestNumbers.map((x, index) => {
|
||||
return pokemonId + (index + 1)
|
||||
})
|
||||
|
||||
pokedexNumbers.value = [
|
||||
...lowestNumbers,
|
||||
pokemonId,
|
||||
...highestNumbers
|
||||
]
|
||||
activeId.value = pokemonId
|
||||
}
|
||||
|
||||
calculatePageNumbers()
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-for="number in pokedexNumbers" class="cursor-pointer">
|
||||
<a :href="'/' + number">
|
||||
<span v-if="number === activeId" class="font-bold text-lg">{{ number }}</span>
|
||||
<span v-else>{{ number }}</span>
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
137
src/components/Pokedex.vue
Normal file
137
src/components/Pokedex.vue
Normal file
@@ -0,0 +1,137 @@
|
||||
<script setup>
|
||||
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
import Pages from './Pages.vue'
|
||||
import Description from './Description.vue'
|
||||
import Information from './Information.vue'
|
||||
import Pokemon from './Pokemon.vue'
|
||||
import PokedexIndex from './PokemonIndex.vue'
|
||||
import Footer from './Footer.vue'
|
||||
|
||||
|
||||
import ColorThief from 'colorthief'
|
||||
import tinycolor from 'tinycolor2'
|
||||
|
||||
const props = defineProps({
|
||||
pokemonId: Number,
|
||||
});
|
||||
|
||||
const pokemon = ref(null)
|
||||
const pokemonImage = ref(null)
|
||||
const pokemonSpecies = ref(null)
|
||||
const pokemonId = ref(null)
|
||||
|
||||
const darkColor = ref(null)
|
||||
const lightColor = ref(null)
|
||||
|
||||
const isDark = ref(true)
|
||||
|
||||
function getPokemonColors(image) {
|
||||
const colorThief = new ColorThief()
|
||||
|
||||
const img = new Image();
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.src = image
|
||||
|
||||
img.onload = () => {
|
||||
const color = colorThief.getColor(img)
|
||||
const rgbColor = `rgb (${color[0]}, ${color[1]}, ${color[2]})`
|
||||
|
||||
let originalColor = tinycolor(rgbColor);
|
||||
|
||||
let light = originalColor.brighten(10).toString();
|
||||
let dark = originalColor.darken(30).toString();
|
||||
|
||||
|
||||
darkColor.value = dark
|
||||
lightColor.value = light
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function getPokemonData() {
|
||||
fetch(`https://pokeapi.co/api/v2/pokemon/${props.pokemonId}`)
|
||||
.then((response) => response.json())
|
||||
.then((json) => pokemon.value = json)
|
||||
.then(() => {
|
||||
pokemonImage.value = pokemon.value.sprites.other['official-artwork'].front_default
|
||||
getPokemonColors(pokemonImage.value)
|
||||
})
|
||||
|
||||
fetch(`https://pokeapi.co/api/v2/pokemon-species/${props.pokemonId}`)
|
||||
.then((response) => response.json())
|
||||
.then((json) => pokemonSpecies.value = json);
|
||||
|
||||
}
|
||||
|
||||
function changeTheme() {
|
||||
isDark.value = !isDark.value
|
||||
}
|
||||
|
||||
const pokemonColors = computed(() => {
|
||||
if (isDark.value) {
|
||||
return {
|
||||
backgroundColor: darkColor.value,
|
||||
color: lightColor.value
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
backgroundColor: lightColor.value,
|
||||
color: darkColor.value
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
getPokemonData()
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="pokemon && pokemonSpecies && pokemonColors">
|
||||
<div class="w-screen min-h-screen text-white p-8 lg:p-12 font-sans flex flex-col" :style="pokemonColors">
|
||||
<div class="flex flex-col items-center justify-between flex-grow">
|
||||
|
||||
<PokedexIndex :pokemon="pokemon" :pokemonData="pokemonSpecies" />
|
||||
|
||||
<div class="flex justify-between items-center w-full lg:gap-24 flex-grow">
|
||||
|
||||
<div class="relative text-center hidden lg:block">
|
||||
<div @click="changeTheme"
|
||||
class="lg:absolute top-0 left-0 -rotate-90 w-72 -translate-x-36 font-semibold">
|
||||
Change Theme
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-full space-y-24 flex flex-col items-center justify-center" @click="changeTheme">
|
||||
|
||||
<Pokemon :pokemonData="pokemonSpecies" :pokemonImage="pokemonImage" />
|
||||
|
||||
<div class="flex flex-col lg:flex-row justify-between gap-6 w-full">
|
||||
<Information :pokemonData="pokemon" />
|
||||
<Description :pokemonData="pokemonSpecies" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="hidden lg:block space-y-4 text-center">
|
||||
<Pages :numberPadding="16" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="space-y-8">
|
||||
|
||||
<div class="flex items-center justify-center text-center lg:hidden space-x-4">
|
||||
<Pages :numberPadding="6" />
|
||||
</div>
|
||||
|
||||
<Footer />
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
25
src/components/Pokemon.vue
Normal file
25
src/components/Pokemon.vue
Normal file
@@ -0,0 +1,25 @@
|
||||
<script setup>
|
||||
import { defineProps } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
pokemonData: Object,
|
||||
pokemonImage: String,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="lg-translate-x-24 relative">
|
||||
<div class="text-7xl lg:text-[15rem] font-semibold tracking-tighter text-center">
|
||||
{{ pokemonData.names[0].name }}
|
||||
</div>
|
||||
<div class="text-4xl lg:text-9xl font-semibold tracking-tighter text-center">
|
||||
({{ pokemonData.names[1].name }})
|
||||
</div>
|
||||
<div class="absolute top-0 left-0 w-full h-full flex items-center justify-center">
|
||||
<div class="w-64 h-64 lg:w-auto lg:h-auto">
|
||||
<img :src="pokemonImage" :alt="pokemonData.names[1].name">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
29
src/components/PokemonIndex.vue
Normal file
29
src/components/PokemonIndex.vue
Normal file
@@ -0,0 +1,29 @@
|
||||
<script setup>
|
||||
import { defineProps } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
pokemon: Object,
|
||||
pokemonData: Object,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center justify-between w-full">
|
||||
|
||||
<div class="space-y-1">
|
||||
<div class="text-sm lg:text-lg font-semibold">
|
||||
#{{ pokemon.id }}
|
||||
</div>
|
||||
<div class="text-lg lg:text-3xl font-semibold">
|
||||
{{ pokemonData.name.charAt(0).toUpperCase() + pokemonData.name.slice(1).toLowerCase() }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class=" text-lg lg:text-4xl font-bold">
|
||||
Pokedex
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
5
src/main.js
Normal file
5
src/main.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import { createApp } from 'vue'
|
||||
import './style.css'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
||||
3
src/style.css
Normal file
3
src/style.css
Normal file
@@ -0,0 +1,3 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
12
tailwind.config.js
Normal file
12
tailwind.config.js
Normal file
@@ -0,0 +1,12 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: [
|
||||
"./index.html",
|
||||
"./src/**/*.{vue,js,ts,jsx,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
||||
12
vite.config.js
Normal file
12
vite.config.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
watch: {
|
||||
usePolling: true,
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user