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

@@ -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={text}
onChange={(e) => setText(e.target.value)}
placeholder="Schreibe einen neuen Jodel..."
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>
);