-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f67158c
commit 31b3400
Showing
14 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "avatar-generator", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.15", | ||
"@types/react-dom": "^18.0.6", | ||
"@vitejs/plugin-react": "^2.0.0", | ||
"vite": "^3.0.0" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 20px; | ||
background-color: white; | ||
border-radius: 5px; | ||
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); | ||
padding: 15px; | ||
width: 500px | ||
} | ||
|
||
.title { | ||
font-size: 1.5em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useState } from "react"; | ||
import "./App.css"; | ||
import UserCard from "./components/UserCard"; | ||
import Button from "./components/Button"; | ||
|
||
function App() { | ||
const [name, setName] = useState(""); | ||
const [avatar, setAvatar] = useState(""); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
async function getAvatar(name, gender) { | ||
const url = `https://avatars.dicebear.com/api/${gender}/${name}.svg`; | ||
setAvatar(url); | ||
} | ||
|
||
async function generateRandomUser() { | ||
setIsLoading(true); | ||
const userRes = await fetch( | ||
"https://randomuser.me/api/?inc=gender,name&results=1" | ||
); | ||
const userData = await userRes.json(); | ||
const fullName = `${userData.results[0].name.title} ${userData.results[0].name.first} ${userData.results[0].name.last}`; | ||
const gender = userData.results[0].gender; | ||
setIsLoading(false); | ||
setName(fullName); | ||
getAvatar(fullName, gender); | ||
} | ||
|
||
return ( | ||
<div className="wrapper"> | ||
<h1 align="center">Avatar Generator</h1> | ||
<Button onClick={() => generateRandomUser()}>Generate User</Button> | ||
<UserCard isLoading={isLoading} name={name} avatar={avatar} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import styles from "./Button.module.css"; | ||
|
||
export default function Button(props) { | ||
return ( | ||
<button className={styles.btn} {...props}> | ||
{props.children} | ||
</button> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/avatar-generator/src/components/Button.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.btn { | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
padding: 10px 20px; | ||
background: none; | ||
font-size: 1.3em; | ||
cursor: pointer; | ||
} | ||
|
||
.btn:hover { | ||
background: #ccc; | ||
} | ||
|
||
.btn:active { | ||
transition: all 0.2s; | ||
transform: translateY(2px); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import styles from "./UserCard.module.css"; | ||
|
||
export default function UserCard(props) { | ||
if (!props.name || !props.avatar) { | ||
return ( | ||
<div className={styles.wrapper} styles={{ textAlign: "center" }}> | ||
Please click on generate avatar | ||
</div> | ||
); | ||
} | ||
|
||
if (props.isLoading) { | ||
return <div className={styles.wrapper}>loading...</div>; | ||
} | ||
|
||
return ( | ||
<div className={styles.wrapper}> | ||
<h2 className={styles.title}>{props.name}</h2> | ||
<img width={150} height={150} src={props.avatar} /> | ||
</div> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/avatar-generator/src/components/UserCard.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.wrapper { | ||
background: lightblue; | ||
padding: 20px; | ||
width: 100%; | ||
border: 1px solid black; | ||
border-radius: 10px; | ||
height: 200px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
:root { | ||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
font-size: 14px; | ||
color: #333; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
background-image: linear-gradient(to right, #439bff, #2f61fe); | ||
height: 100vh; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App' | ||
import './index.css' | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from "vite"; | ||
import react from "@vitejs/plugin-react"; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}); |
31b3400
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nit-news – ./
nit-news.vercel.app
nit-news-git-master-always-maap.vercel.app
nit-news-always-maap.vercel.app