-
Notifications
You must be signed in to change notification settings - Fork 2
Laxman feat #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: laxman
Are you sure you want to change the base?
Laxman feat #10
Changes from all commits
b76e246
ebb1252
b20a3d2
6fd619c
d10ff0e
fb781e8
bb8152a
9511c9d
534d40c
4c0b900
1289025
6637855
1fe996b
e8754d6
b99ea41
c246504
b589b25
9c3d03c
94dd440
090bffc
ac7b177
1af33e4
6f2b917
ee15de8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,128 +1,27 @@ | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import Counter from "./components/Counter/Counter"; | ||
| import UserForm from "./components/Form/UserForm/UserForm"; | ||
| import { useItems } from "./hooks/useItems"; | ||
| import Button from "./components/Button/Button"; | ||
| import { ItemList } from "./components/Item/ItemList/ItemList"; | ||
| import { ThemeToggle } from './components/ThemeToggle/ThemeToggle'; | ||
| import AddItem from "./components/Item/AddItem/AddItem"; | ||
|
|
||
| export default function App() { | ||
| const [count, setCount] = useState(0); | ||
| const [isDarkMode, setIsDarkMode] = useState(false); | ||
| const [name, setName] = useState(""); | ||
| const [email, setEmail] = useState(""); | ||
| const [isVisible, setIsVisible] = useState(true); | ||
| const [items, setItems] = useState<string[]>([]); | ||
| const [selectedItem, setSelectedItem] = useState<string | null>(null); | ||
|
|
||
| const inputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| const storedCount = localStorage.getItem("count"); | ||
| if (storedCount) { | ||
| setCount(parseInt(storedCount)); | ||
| } | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| localStorage.setItem("count", count.toString()); | ||
| }, [count]); | ||
|
|
||
| useEffect(() => { | ||
| document.title = `Hello ${name}`; | ||
| }, [name]); | ||
|
|
||
| useEffect(() => { | ||
| if (selectedItem) { | ||
| console.log(selectedItem); | ||
| } | ||
| }, [selectedItem]); | ||
|
|
||
| useEffect(() => { | ||
| document.body.classList.toggle("dark", isDarkMode); | ||
| }, [isDarkMode]); | ||
|
|
||
| const increment = () => { | ||
| setCount(count + 1); | ||
| }; | ||
|
|
||
| const decrement = () => { | ||
| setCount(count - 1); | ||
| }; | ||
|
|
||
| const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setName(e.target.value); | ||
| }; | ||
|
|
||
| const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setEmail(e.target.value); | ||
| }; | ||
|
|
||
| const toggleVisibility = () => { | ||
| setIsVisible(!isVisible); | ||
| }; | ||
|
|
||
| function addItem() { | ||
| if (inputRef.current && inputRef.current.value) { | ||
| setItems([...items, inputRef.current.value]); | ||
| inputRef.current.value = ""; | ||
| } | ||
| } | ||
|
|
||
| async function handleSubmit() { | ||
| // Do something with data... | ||
| } | ||
|
|
||
| const { items, isVisible, inputValue, setInputValue,setSelectedItem, addItem, toggleVisibility } = useItems(); | ||
| return ( | ||
| <div> | ||
| <h1 className="text-2xl font-bold">Outside</h1> | ||
| <div> | ||
| <button onClick={increment}>Increment</button> | ||
| <button onClick={decrement}>Decrement</button> | ||
| <p>Count: {count}</p> | ||
| </div> | ||
| <form onSubmit={handleSubmit}> | ||
| <div> | ||
| <input | ||
| type="text" | ||
| value={name} | ||
| onChange={handleNameChange} | ||
| placeholder="Enter your name" | ||
| /> | ||
| <p>Name: {name}</p> | ||
| </div> | ||
| <div> | ||
| <input | ||
| type="email" | ||
| value={email} | ||
| onChange={handleEmailChange} | ||
| placeholder="Enter your email" | ||
| /> | ||
| <p>Email: {email}</p> | ||
| </div> | ||
| <div> | ||
| <div> | ||
| <button onClick={toggleVisibility}> | ||
| {isVisible ? "Hide" : "Show"} Items | ||
| </button> | ||
| {isVisible && ( | ||
| <div> | ||
| <input type="text" ref={inputRef} placeholder="Add item" /> | ||
| <button onClick={addItem}>Add Item</button> | ||
| <ul> | ||
| {items.map((item, index) => ( | ||
| <li key={index} onClick={() => setSelectedItem(item)}> | ||
| {item} | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| )} | ||
| </div> | ||
| <div> | ||
| <p>Selected Item: {selectedItem}</p> | ||
| </div> | ||
| </div> | ||
| </form> | ||
| <div> | ||
| <button onClick={() => setIsDarkMode(!isDarkMode)}> | ||
| Toggle Dark Mode | ||
| </button> | ||
| <div className="container"> | ||
| <Counter /> | ||
| <UserForm/> | ||
| <div className="container items"> | ||
| <Button className="toggle-visible-btn" value={isVisible ? "Hide" : "Show"} onClick={toggleVisibility}></Button> | ||
| {isVisible && ( | ||
| <> | ||
| <AddItem addItem={addItem} inputValue={inputValue} setInputValue={setInputValue} /> | ||
| <ItemList items={items} setSelectedItem={setSelectedItem}/> | ||
| </> | ||
| )} | ||
| </div> | ||
| <ThemeToggle/> | ||
| </div> | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type React from "react"; | ||
|
|
||
| interface ButtonProps { | ||
| value: string; | ||
| onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void; | ||
| className?:string; | ||
| } | ||
|
|
||
| const Button = ({ value, onClick, className }: ButtonProps) => { | ||
| return ( | ||
| <button className={className} onClick={onClick}>{value}</button> | ||
| ); | ||
| }; | ||
|
|
||
| export default Button; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import Button from "../Button/Button"; | ||
| import styles from "./style.module.css" | ||
| import { useCounter } from "../../hooks/useCounters"; | ||
|
|
||
|
|
||
| const Counter = () => { | ||
| const { count, handleIncrement, handleDecrement } = useCounter(); | ||
| return ( | ||
| <div className='container'> | ||
| <section className={styles.background}> | ||
| <p className={styles.count}>COUNT: {count}</p> | ||
| <div className={styles.buttonSection}> | ||
| <Button className={styles.increment} value="Increment" onClick={handleIncrement} /> | ||
| <Button className={styles.decrement} value="Decrement" onClick={handleDecrement} /> | ||
| </div> | ||
| </section> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default Counter |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| .increment, .decrement{ | ||
| background-color: rgb(32, 175, 32); | ||
| padding: 15px 20px; | ||
| color: white; | ||
| border-radius: 12px; | ||
| border: none; | ||
| font-size: 15px; | ||
| font-weight: 700; | ||
| margin: 10px 10px; | ||
| cursor: pointer; | ||
| box-shadow: | ||
| 1px 1px rgb(161, 161, 161), | ||
| -0.4em 0 0.4em rgb(155, 155, 154); | ||
| } | ||
|
|
||
| .increment:hover, | ||
| .decrement:hover{ | ||
| opacity: 0.7; | ||
| } | ||
|
|
||
| .decrement{ | ||
| background-color: rgb(240, 66, 35); | ||
| } | ||
|
|
||
| .count{ | ||
| color: rgb(72, 72, 240); | ||
| font-size: 3rem; | ||
| text-align: center; | ||
| font-weight: 700; | ||
| } | ||
|
|
||
| .background{ | ||
| /* background-color: rgb(217, 217, 218); */ | ||
| padding: 10px 10px; | ||
| } | ||
|
|
||
| .buttonSection{ | ||
| display: flex; | ||
| justify-content: center; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import type React from "react"; | ||
| import styles from "./style.module.css"; | ||
|
|
||
| interface InputFieldProps { | ||
| label: string; | ||
| type: string; | ||
| value: string; | ||
| onChange: (e: React.ChangeEvent<HTMLInputElement>) => void; | ||
| } | ||
|
|
||
| const InputField = ({ label, type, value, onChange }: InputFieldProps) => { | ||
| return ( | ||
| <div className={styles["input-field"]}> | ||
| <label className={styles["input-field__label"]}> | ||
| {label.charAt(0).toUpperCase() + label.slice(1)} | ||
| </label> | ||
|
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use css |
||
| <input | ||
| type={type} | ||
| value={value} | ||
| onChange={onChange} | ||
| placeholder={`Enter your ${label}`} | ||
| className={styles["input-field__input"]} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default InputField; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| .input-field { | ||
| display: flex; | ||
| flex-direction: column; | ||
| margin-bottom: 16px; | ||
| width: 100%; | ||
| max-width: 400px; | ||
| margin: auto; | ||
| padding: 20px 20px; | ||
| } | ||
|
|
||
| .input-field__label { | ||
| font-weight: 600; | ||
| margin-bottom: 6px; | ||
| color: #333; | ||
| font-size: 14px; | ||
| } | ||
|
|
||
| .input-field__input { | ||
| padding: 8px 12px; | ||
| border: 1px solid #ccc; | ||
| border-radius: 6px; | ||
| font-size: 14px; | ||
| transition: border-color 0.2s, box-shadow 0.2s; | ||
| } | ||
|
|
||
| .input-field__input:focus { | ||
| outline: none; | ||
| border-color: #007bff; | ||
| box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); | ||
| } | ||
|
|
||
| .input-field__value { | ||
| margin-top: 4px; | ||
| font-size: 12px; | ||
| color: #555; | ||
| font-style: italic; | ||
| } | ||
|
Comment on lines
+32
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this class and its associated properties appear to be unused |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React, { useState } from 'react'; | ||
| import InputField from '../InputField/InputField'; | ||
| import useFormFields from '../../../hooks/useFormFields'; | ||
| import Button from '../../Button/Button'; | ||
| import styles from './style.module.css'; | ||
|
|
||
| const UserForm = () => { | ||
| const { name, email, setName, setEmail } = useFormFields(); | ||
| const [submittedName, setSubmittedName] = useState<string | null>(null); | ||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| setSubmittedName(name); | ||
| setName(''); | ||
| setEmail(''); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className='container '> | ||
| <div className={`${styles['user-form']} container`}> | ||
| <form className={`${styles['user-form__form']} container`} onSubmit={handleSubmit}> | ||
| <InputField label='name' type='text' value={name} onChange={(e) => setName(e.target.value)} /> | ||
| <InputField label='email' type='text' value={email} onChange={(e) => setEmail(e.target.value)} /> | ||
| <Button value="Submit" className={styles['user-form__button']} /> | ||
| </form> | ||
| {submittedName && ( | ||
| <p className={`${styles['user-form__welcome']} container`}> | ||
| Welcome, {submittedName}! | ||
| </p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default UserForm; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| .user-form { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| padding: 24px; | ||
| background-color: #f9f9f9; | ||
| border-radius: 12px; | ||
| max-width: 450px; | ||
| margin: 20px auto; | ||
| box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); | ||
| } | ||
|
|
||
| .user-form__form { | ||
| display: flex; | ||
| flex-direction: column; | ||
| width:30%; | ||
| margin: auto; | ||
| } | ||
|
|
||
| .user-form__button { | ||
| margin-top: 12px; | ||
| padding: 10px 16px; | ||
| background-color: #007bff; | ||
| border: none; | ||
| border-radius: 6px; | ||
| color: #fff; | ||
| font-weight: 600; | ||
| cursor: pointer; | ||
| transition: background-color 0.2s; | ||
| } | ||
|
|
||
| .user-form__button:hover { | ||
| background-color: #0056b3; | ||
| } | ||
|
|
||
| .user-form__welcome{ | ||
| margin-top: 16px; | ||
| font-size: 16px; | ||
| font-weight: 500; | ||
| color: black; | ||
| text-align: center; | ||
| } | ||
|
|
||
| .user-form__welcome .dark { | ||
| margin-top: 16px; | ||
| font-size: 16px; | ||
| font-weight: 500; | ||
| color: white; | ||
| text-align: center;; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
Just a suggestion but it might be a better idea to use only rgb color or hex code everywhere as I noticed you're using both