redesigned NewPostForm component for title and textarea

This commit is contained in:
Pete Gerlach
2024-06-11 13:23:13 +02:00
parent 3094e30575
commit 5bddc03d5c
2 changed files with 49 additions and 3 deletions

View File

@@ -34,6 +34,37 @@ h1 {
font-size: 1em;
}
.textarea-container {
position: relative;
width: 100%;
textarea {
width: 100%;
box-sizing: border-box;
padding: 15px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 10px;
font-size: 1em;
font-family: Arial, sans-serif;
}
.char-count-container {
position: absolute;
bottom: 8px;
right: 12px;
font-size: 12px;
color: grey;
background: white;
padding: 2px 4px;
border-radius: 4px;
}
.max-char-count {
background-color: rgba(255, 0, 0, 0.25);
}
}
button {
padding: 15px;
background-color: #ff9908;

View File

@@ -1,6 +1,7 @@
import React, { useState } from 'react';
const NewPostForm = ({ addPost }) => {
const [title, setTitle] = useState('');
const [text, setText] = useState('');
const handleSubmit = (e) => {
@@ -15,10 +16,24 @@ const NewPostForm = ({ addPost }) => {
<form className="new-post-form" onSubmit={handleSubmit}>
<input
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
placeholder="Titel"
/>
<div className="textarea-container">
<textarea
rows={5}
value={text}
onChange={(e) => setText(e.target.value)}
placeholder="Schreibe einen neuen Jodel..."
maxLength={500}
/>
<div className="char-count-container">
<span className={text.length === 500 ? "char-count max-char-count" : "char-count"}>
{text.length} / 500
</span>
</div>
</div>
<button type="submit">Posten</button>
</form>
);