23bd5a0530 6components
23bd5a0530 6components
const styles = {
app: {
maxWidth: '800px',
padding: '20px',
backgroundColor: 'var(--bg-color)',
color: 'var(--text-color)',
minHeight: '100vh',
},
component: {
backgroundColor: 'var(--card-bg)',
padding: '20px',
borderRadius: '8px',
},
input: {
padding: '10px',
margin: '5px',
borderRadius: '4px',
fontSize: '14px',
backgroundColor: 'var(--input-bg)',
color: 'var(--text-color)'
},
button: {
margin: '5px',
border: 'none',
borderRadius: '4px',
backgroundColor: '#007bff',
color: 'white',
cursor: 'pointer',
fontSize: '14px'
},
buttonDanger: {
backgroundColor: '#dc3545'
},
buttonSuccess: {
backgroundColor: '#28a745'
},
list: {
listStyle: 'none',
padding: '0'
},
listItem: {
padding: '10px',
backgroundColor: 'var(--item-bg)',
borderRadius: '4px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
},
title: {
paddingBottom: '10px',
marginBottom: '20px'
},
form: {
display: 'flex',
flexDirection: 'column',
gap: '10px'
},
textarea: {
padding: '10px',
borderRadius: '4px',
resize: 'vertical',
minHeight: '100px',
backgroundColor: 'var(--input-bg)',
color: 'var(--text-color)'
};
// Theme Context
if (inputValue.trim()) {
setItems([...items, { id: Date.now(), text: inputValue }]);
setInputValue('');
};
};
return (
<div style={styles.component}>
<div>
<input
style={styles.input}
type="text"
value={inputValue}
placeholder="Enter item"
/>
</div>
<ul style={styles.list}>
{items.map(item => (
{item.text}
<button
style={{...styles.button, ...styles.buttonDanger}}
>
Remove
</button>
</li>
))}
</ul>
</div>
);
};
inputRef.current.focus();
};
return (
<div style={styles.component}>
<input
ref={inputRef}
style={styles.input}
type="text"
/>
</div>
);
};
// 3. Theme Toggle Component
return (
<div style={styles.component}>
</button>
</div>
);
};
useEffect(() => {
prevValueRef.current = value;
});
return (
<div style={styles.component}>
<input
style={styles.input}
type="text"
value={value}
onChange={(e) => setValue(e.target.value)}
placeholder="Type something"
/>
<p>Current: {value}</p>
<p>Previous: {prevValueRef.current}</p>
</div>
);
};
// 5. Contact Us Component
name: '',
email: '',
message: ''
});
setSubmitted(true);
setTimeout(() => {
setSubmitted(false);
}, 2000);
} else {
}
};
setFormData({
...formData,
[e.target.name]: e.target.value
});
};
return (
<div style={styles.component}>
{submitted ? (
):(
<div style={styles.form}>
<input
style={styles.input}
type="text"
name="name"
value={formData.name}
onChange={handleChange}
placeholder="Your Name"
/>
<input
style={styles.input}
type="email"
name="email"
value={formData.email}
onChange={handleChange}
placeholder="Your Email"
/>
<textarea
style={styles.textarea}
name="message"
value={formData.message}
onChange={handleChange}
placeholder="Your Message"
/>
Send Message
</button>
</div>
)}
</div>
);
};
// 6. Login Component
// Predefined users
const users = [
];
);
if (foundUser) {
setIsLoggedIn(true);
setUser(foundUser);
} else {
alert('Invalid credentials!');
};
setIsLoggedIn(false);
setUser(null);
};
useEffect(() => {
// if (savedUser) {
// setUser(JSON.parse(savedUser));
// setIsLoggedIn(true);
// }
}, []);
if (isLoggedIn) {
return (
<div style={styles.component}>
<p>Welcome, {user.username}!</p>
</div>
);
return (
<div style={styles.component}>
<input
style={styles.input}
type="text"
placeholder="Username"
value={credentials.username}
required
/>
<input
style={styles.input}
type="password"
placeholder="Password"
value={credentials.password}
required
/>
<button style={{...styles.button, ...styles.buttonSuccess}} type="submit">
Login
</button>
</form>
<p>Demo accounts:</p>
</div>
</div>
);
};
};
'--bg-color': '#ffffff',
'--text-color': '#333333',
'--card-bg': '#f8f9fa',
'--border-color': '#dee2e6',
'--input-bg': '#ffffff',
'--item-bg': '#ffffff'
}:{
'--bg-color': '#1a1a1a',
'--text-color': '#ffffff',
'--card-bg': '#2d2d2d',
'--border-color': '#444444',
'--input-bg': '#333333',
'--item-bg': '#3d3d3d'
};
return (
{children}
</div>
</ThemeContext.Provider>
);
};
return (
<ThemeProvider>
<div style={styles.app}>
<ItemList />
<FocusInput />
<ThemeToggle />
<PreviousValue />
<ContactUs />
<Login />
</div>
</ThemeProvider>
);
};
export default App;
Output: