Add Vite project sample

This commit is contained in:
2023-10-06 17:36:56 +07:00
parent 41c9384f23
commit 756103b07e
11 changed files with 2968 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
],
ignorePatterns: ["dist", ".eslintrc.cjs"],
parserOptions: { ecmaVersion: "latest", sourceType: "module" },
settings: { react: { version: "18.2" } },
plugins: ["react-refresh"],
rules: {
"react-refresh/only-export-components": [
"warn",
{ allowConstantExport: true },
],
"react/prop-types": "off",
},
};
+24
View 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?
+8
View File
@@ -0,0 +1,8 @@
# React + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
+13
View 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>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
+26
View File
@@ -0,0 +1,26 @@
{
"name": "use-popcorn",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@vitejs/plugin-react": "^4.0.3",
"eslint": "^8.45.0",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"vite": "^4.4.5"
}
}
+2240
View File
File diff suppressed because it is too large Load Diff
+1
View 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

+237
View File
@@ -0,0 +1,237 @@
import { useState } from "react";
const tempMovieData = [
{
imdbID: "tt1375666",
Title: "Inception",
Year: "2010",
Poster:
"https://m.media-amazon.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg",
},
{
imdbID: "tt0133093",
Title: "The Matrix",
Year: "1999",
Poster:
"https://m.media-amazon.com/images/M/MV5BNzQzOTk3OTAtNDQ0Zi00ZTVkLWI0MTEtMDllZjNkYzNjNTc4L2ltYWdlXkEyXkFqcGdeQXVyNjU0OTQ0OTY@._V1_SX300.jpg",
},
{
imdbID: "tt6751668",
Title: "Parasite",
Year: "2019",
Poster:
"https://m.media-amazon.com/images/M/MV5BYWZjMjk3ZTItODQ2ZC00NTY5LWE0ZDYtZTI3MjcwN2Q5NTVkXkEyXkFqcGdeQXVyODk4OTc3MTY@._V1_SX300.jpg",
},
];
const tempWatchedData = [
{
imdbID: "tt1375666",
Title: "Inception",
Year: "2010",
Poster:
"https://m.media-amazon.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg",
runtime: 148,
imdbRating: 8.8,
userRating: 10,
},
{
imdbID: "tt0088763",
Title: "Back to the Future",
Year: "1985",
Poster:
"https://m.media-amazon.com/images/M/MV5BZmU0M2Y1OGUtZjIxNi00ZjBkLTg1MjgtOWIyNThiZWIwYjRiXkEyXkFqcGdeQXVyMTQxNzMzNDI@._V1_SX300.jpg",
runtime: 116,
imdbRating: 8.5,
userRating: 9,
},
];
const average = (arr) =>
arr.reduce((acc, cur, i, arr) => acc + cur / arr.length, 0);
export default function App() {
return (
<>
<NavBar />
<Main />
</>
);
}
function NavBar() {
return (
<nav className="nav-bar">
<Logo />
<Search />
<NumResults />
</nav>
);
}
function Logo() {
return (
<div className="logo">
<span role="img">🍿</span>
<h1>usePopcorn</h1>
</div>
);
}
function Search() {
const [query, setQuery] = useState("");
return (
<input
className="search"
type="text"
placeholder="Search movies..."
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
);
}
function NumResults() {
return (
<p className="num-results">
Found <strong>X</strong> results
</p>
);
}
function Main() {
return (
<main className="main">
<ListBox />
<WatchedBox />
</main>
);
}
function ListBox() {
const [isOpen1, setIsOpen1] = useState(true);
return (
<div className="box">
<button
className="btn-toggle"
onClick={() => setIsOpen1((open) => !open)}
>
{isOpen1 ? "" : "+"}
</button>
{isOpen1 && <MovieList />}
</div>
);
}
function MovieList() {
const [movies, setMovies] = useState(tempMovieData);
return (
<ul className="list">
{movies?.map((movie) => (
<Movie movie={movie} key={movie.imdbID} />
))}
</ul>
);
}
function Movie({ movie }) {
return (
<li key={movie.imdbID}>
<img src={movie.Poster} alt={`${movie.Title} poster`} />
<h3>{movie.Title}</h3>
<div>
<p>
<span>🗓</span>
<span>{movie.Year}</span>
</p>
</div>
</li>
);
}
function WatchedBox() {
const [watched, setWatched] = useState(tempWatchedData);
const [isOpen2, setIsOpen2] = useState(true);
return (
<div className="box">
<button
className="btn-toggle"
onClick={() => setIsOpen2((open) => !open)}
>
{isOpen2 ? "" : "+"}
</button>
{isOpen2 && (
<>
<WatchedSummary watched={watched} />
<WatchMovieList watched={watched} />
</>
)}
</div>
);
}
function WatchedSummary({ watched }) {
const avgImdbRating = average(watched.map((movie) => movie.imdbRating));
const avgUserRating = average(watched.map((movie) => movie.userRating));
const avgRuntime = average(watched.map((movie) => movie.runtime));
return (
<div className="summary">
<h2>Movies you watched</h2>
<div>
<p>
<span>#</span>
<span>{watched.length} movies</span>
</p>
<p>
<span></span>
<span>{avgImdbRating}</span>
</p>
<p>
<span>🌟</span>
<span>{avgUserRating}</span>
</p>
<p>
<span></span>
<span>{avgRuntime} min</span>
</p>
</div>
</div>
);
}
function WatchMovieList({ watched }) {
return (
<ul className="list">
{watched.map((movie) => (
<WatchedMovie movie={movie} key={movie.imdbID} />
))}
</ul>
);
}
function WatchedMovie({ movie }) {
return (
<li key={movie.imdbID}>
<img src={movie.Poster} alt={`${movie.Title} poster`} />
<h3>{movie.Title}</h3>
<div>
<p>
<span></span>
<span>{movie.imdbRating}</span>
</p>
<p>
<span>🌟</span>
<span>{movie.userRating}</span>
</p>
<p>
<span></span>
<span>{movie.runtime} min</span>
</p>
</div>
</li>
);
}
+381
View File
@@ -0,0 +1,381 @@
:root {
--color-primary: #6741d9;
--color-primary-light: #7950f2;
--color-text: #dee2e6;
--color-text-dark: #adb5bd;
--color-background-100: #343a40;
--color-background-500: #2b3035;
--color-background-900: #212529;
--color-red: #fa5252;
--color-red-dark: #e03131;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
font-size: 62.5%;
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
color: var(--color-text);
background-color: var(--color-background-900);
padding: 2.4rem;
}
/* ******* */
.nav-bar {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
align-items: center;
height: 7.2rem;
padding: 0 3.2rem;
background-color: var(--color-primary);
border-radius: 0.9rem;
}
.main {
margin-top: 2.4rem;
height: calc(100vh - 7.2rem - 3 * 2.4rem);
display: flex;
gap: 2.4rem;
justify-content: center;
}
.box {
width: 42rem;
max-width: 42rem;
background-color: var(--color-background-500);
border-radius: 0.9rem;
/* overflow: scroll; */
position: relative;
}
.loader {
text-align: center;
text-transform: uppercase;
font-size: 2rem;
font-weight: 600;
margin: 4.8rem;
}
.error {
text-align: center;
font-size: 2rem;
padding: 4.8rem;
}
/* ******* */
.logo {
display: flex;
align-items: center;
gap: 0.8rem;
}
.logo span {
font-size: 3.2rem;
}
.logo h1 {
font-size: 2.4rem;
font-weight: 600;
color: #fff;
}
.search {
justify-self: center;
border: none;
padding: 1.1rem 1.6rem;
font-size: 1.8rem;
border-radius: 0.7rem;
width: 40rem;
transition: all 0.3s;
color: var(--color-text);
/* background-color: var(--color-background-900); */
background-color: var(--color-primary-light);
}
.search::placeholder {
color: var(--color-text-dark);
}
.search:focus {
outline: none;
box-shadow: 0 2.4rem 2.4rem rgba(0, 0, 0, 0.1);
transform: translateY(-2px);
}
.num-results {
justify-self: end;
font-size: 1.8rem;
}
.btn-toggle {
position: absolute;
top: 0.8rem;
right: 0.8rem;
height: 2.4rem;
aspect-ratio: 1;
border-radius: 50%;
border: none;
background-color: var(--color-background-900);
color: var(--color-text);
font-size: 1.4rem;
font-weight: bold;
cursor: pointer;
z-index: 999;
}
.list {
list-style: none;
padding: 0.8rem 0;
/* overflow: scroll; */
}
.list-watched {
height: calc(100% - 9rem);
}
.list li {
position: relative;
display: grid;
grid-template-columns: 4rem 1fr;
grid-template-rows: auto auto;
column-gap: 2.4rem;
font-size: 1.6rem;
align-items: center;
padding: 1.6rem 3.2rem;
border-bottom: 1px solid var(--color-background-100);
}
.list.list-movies li {
cursor: pointer;
transition: all 0.3s;
}
.list.list-movies li:hover {
background-color: var(--color-background-100);
}
.list img {
width: 100%;
grid-row: 1 / -1;
}
.list h3 {
font-size: 1.8rem;
}
.list div {
display: flex;
align-items: center;
gap: 2.4rem;
}
.list p {
display: flex;
align-items: center;
gap: 0.8rem;
}
.btn-delete {
position: absolute;
right: 2.4rem;
height: 1.8rem;
aspect-ratio: 1;
border-radius: 50%;
border: none;
background-color: var(--color-red);
color: var(--color-background-900);
font-size: 0.9rem;
font-weight: bold;
cursor: pointer;
transition: all 0.3s;
}
.btn-delete:hover {
background-color: var(--color-red-dark);
}
/* ******* */
.summary {
padding: 2.2rem 3.2rem 1.8rem 3.2rem;
border-radius: 0.9rem;
background-color: var(--color-background-100);
box-shadow: 0 1.2rem 2.4rem rgba(0, 0, 0, 0.2);
}
.summary h2 {
text-transform: uppercase;
font-size: 1.6rem;
margin-bottom: 0.6rem;
}
.summary div {
display: flex;
align-items: center;
gap: 2.4rem;
font-size: 1.6rem;
font-weight: 600;
}
.summary p {
display: flex;
align-items: center;
gap: 0.8rem;
}
/* ******* */
.details {
line-height: 1.4;
font-size: 1.4rem;
}
.details header {
display: flex;
}
.details section {
padding: 4rem;
display: flex;
flex-direction: column;
gap: 1.6rem;
}
.details img {
width: 33%;
}
.details-overview {
width: 100%;
padding: 2.4rem 3rem;
background-color: var(--color-background-100);
display: flex;
flex-direction: column;
gap: 1.4rem;
}
.details-overview h2 {
font-size: 2.4rem;
margin-bottom: 0.4rem;
line-height: 1.1;
}
.details-overview p {
display: flex;
align-items: center;
gap: 0.8rem;
}
.rating {
background-color: var(--color-background-100);
border-radius: 0.9rem;
padding: 2rem 2.4rem;
margin-bottom: 0.8rem;
font-weight: 600;
display: flex;
flex-direction: column;
gap: 2.4rem;
}
.btn-add {
background-color: var(--color-primary);
color: var(--color-text);
border: none;
border-radius: 10rem;
font-size: 1.4rem;
padding: 1rem;
font-weight: bold;
cursor: pointer;
transition: all 0.3s;
}
.btn-add:hover {
background-color: var(--color-primary-light);
}
.seconds {
background-color: var(--color-background-100);
width: 8rem;
border-radius: 10rem;
font-weight: 600;
text-align: center;
padding: 0.4rem;
margin-top: 2.4rem;
}
.btn-back {
position: absolute;
top: 0.6rem;
left: 0.6rem;
height: 3.2rem;
aspect-ratio: 1;
border-radius: 50%;
border: none;
/* background-color: var(--color-text); */
background-color: #fff;
color: var(--color-background-500);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.8);
font-family: sans-serif;
font-size: 2.4rem;
font-weight: bold;
cursor: pointer;
z-index: 999;
display: flex;
align-items: center;
justify-content: center;
}
/*
SPACING SYSTEM (px)
2 / 4 / 8 / 12 / 16 / 24 / 32 / 40 / 48 / 64 / 80 / 96 / 128
FONT SIZE SYSTEM (px)
10 / 12 / 14 / 16 / 18 / 20 / 24 / 30 / 36 / 44 /52 / 62 / 74 / 86 / 98
*/
/*
FULL STAR
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="#000"
stroke="#000"
>
<path
d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"
/>
</svg>
EMPTY STAR
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="#000"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="{2}"
d="M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"
/>
</svg>
*/
+10
View File
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
+7
View File
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})