diff --git a/examples/avatar-generator/package.json b/examples/avatar-generator/package.json index 630679f..1dd9517 100644 --- a/examples/avatar-generator/package.json +++ b/examples/avatar-generator/package.json @@ -9,6 +9,7 @@ "preview": "vite preview" }, "dependencies": { + "party-js": "^2.2.0", "react": "^18.2.0", "react-dom": "^18.2.0" }, diff --git a/examples/avatar-generator/src/App.jsx b/examples/avatar-generator/src/App.jsx index a336d1f..c7fb5ef 100644 --- a/examples/avatar-generator/src/App.jsx +++ b/examples/avatar-generator/src/App.jsx @@ -1,12 +1,16 @@ -import { useState } from "react"; +import { useState, useRef } from "react"; import "./App.css"; import UserCard from "./components/UserCard"; import Button from "./components/Button"; +import Header from "./components/Header"; +import party from "party-js"; function App() { const [name, setName] = useState(""); const [avatar, setAvatar] = useState(""); const [isLoading, setIsLoading] = useState(false); + const [headerValue, setHeaderValue] = useState("Avatar Generator"); + const ref = useRef(null); async function getAvatar(name, gender) { const url = `https://avatars.dicebear.com/api/${gender}/${name}.svg`; @@ -26,11 +30,30 @@ function App() { getAvatar(fullName, gender); } + function startParty() { + party.confetti(ref.current, { + count: party.variation.range(20, 40), + spread: party.variation.range(10, 20), + size: party.variation.range(1, 3), + }); + setHeaderValue(name); + } + return (
-

Avatar Generator

- +
+ + {avatar !== "" && ( + + )}
); } diff --git a/examples/avatar-generator/src/components/Button.jsx b/examples/avatar-generator/src/components/Button.jsx index 79a48be..440daf1 100644 --- a/examples/avatar-generator/src/components/Button.jsx +++ b/examples/avatar-generator/src/components/Button.jsx @@ -1,9 +1,12 @@ +import { forwardRef } from "react"; import styles from "./Button.module.css"; -export default function Button(props) { +const Button = forwardRef((props, ref) => { return ( - ); -} +}); + +export default Button; diff --git a/examples/avatar-generator/src/components/Header.jsx b/examples/avatar-generator/src/components/Header.jsx new file mode 100644 index 0000000..18fdbc5 --- /dev/null +++ b/examples/avatar-generator/src/components/Header.jsx @@ -0,0 +1,25 @@ +import { useState } from "react"; +import Button from "./Button"; + +export default function Header(props) { + const [isEditMode, setIsEditMode] = useState(false); + + return ( +
+ {isEditMode ? ( + <> + props.setValue(e.target.value)} + /> + + + ) : ( +

setIsEditMode(true)} align="center"> + {props.value} +

+ )} +
+ ); +} diff --git a/examples/avatar-generator/src/components/UserCard.module.css b/examples/avatar-generator/src/components/UserCard.module.css index b8be6a7..0c9bb2e 100644 --- a/examples/avatar-generator/src/components/UserCard.module.css +++ b/examples/avatar-generator/src/components/UserCard.module.css @@ -1,8 +1,8 @@ .wrapper { - background: lightblue; + background: #eee; padding: 20px; width: 100%; - border: 1px solid black; + border: 1px solid #eee; border-radius: 10px; height: 200px; display: flex; diff --git a/examples/avatar-generator/src/index.css b/examples/avatar-generator/src/index.css index 9d43657..4c663a8 100644 --- a/examples/avatar-generator/src/index.css +++ b/examples/avatar-generator/src/index.css @@ -10,6 +10,6 @@ flex-direction: column; justify-content: center; align-items: center; - background-image: linear-gradient(to right, #439bff, #2f61fe); + background-image: linear-gradient(to right, #19FD8280, #17FE5B50); height: 100vh; } diff --git a/examples/todo-react/README.md b/examples/todo-react/README.md new file mode 100644 index 0000000..be66643 --- /dev/null +++ b/examples/todo-react/README.md @@ -0,0 +1,7 @@ +- [JavaScript modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) + +- [Controlled vs Uncontrolled Forms](https://reactjs.org/docs/uncontrolled-components.html#:~:text=In%20a%20controlled%20component%2C%20form,form%20values%20from%20the%20DOM.) + +- [vite](https://vitejs.dev/) + +- [React](https://beta.reactjs.org/learn) diff --git a/yarn.lock b/yarn.lock index 00bfa2c..62e0f2d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -611,6 +611,11 @@ node-releases@^2.0.6: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.6.tgz#8a7088c63a55e493845683ebf3c828d8c51c5503" integrity sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg== +party-js@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/party-js/-/party-js-2.2.0.tgz#3340026971c9e62fd34db102daaa645fbc9130b8" + integrity sha512-50hGuALCpvDTrQLPQ1fgUgxKIWAH28ShVkmeK/3zhO0YJyCqkhrZhQEkWPxDYLvbFJ7YAXyROmFEu35gKpZLtQ== + path-parse@^1.0.7: version "1.0.7" resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"