Skip to content
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

レスポンシブ対応と名前入力欄の追加、投稿ごとの区切り線の追加 #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/app/page.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
gap: 1em;
padding: 1em;

.text_area {
.text_content_area {
flex: 1;
}
.post_button {
Expand All @@ -15,8 +15,42 @@
max-width: 90%;
margin: auto;


.content_list {
display: inline-block;
width: 25%;
}

.content {
border-bottom: 1px solid #ccc;
}
}

@media screen and (max-width: 767px) {
.post_form{
.text_content_area {
position: fixed;
bottom: 0;
left: 40%;
width: 40%;
padding: 15px;
background-color: #fff;
}
.text_name_area {
position: fixed;
bottom: 10px;
left: 0;
width: 40%;
padding: 15px;
background-color: #fff;
}

.post_button {
position: fixed;
bottom: 25px;
right: 0;
width: 20%;
background-color: #fff;
}
}
}
23 changes: 19 additions & 4 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { Button, Textarea } from '@mantine/core';
import { Button, TextInput, Textarea } from '@mantine/core';
import React, { useState } from 'react';
import styles from './page.module.scss';

Expand Down Expand Up @@ -29,38 +29,53 @@ export default function HomePage() {
{ id: 2, postedBy: '田中次郎', postedAt: '2024/01/01 16:00:01', content: '無事です' },
{ id: 3, postedBy: '田中三郎', postedAt: '2024/01/01 16:00:02', content: '無事です' },
]);
const [postName,setPostName] = useState<string>('');

const handlePostContentChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
setPostContent(event.target.value);
};

const handlePostNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setPostName(event.target.value);
}

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
setPosts([
...posts,
{
id: posts[posts.length - 1].id + 1,
postedBy: '田中四郎',
postedBy: postName,
postedAt: getFormattedDate(new Date()),
content: postContent,
},
]);
setPostName('');
setPostContent('');
};
return (
<main>
<form className={styles.post_form} onSubmit={handleSubmit}>
<TextInput
className={styles.text_name_area}
value={postName}
onChange={handlePostNameChange}
placeholder="名前を入力"
/>
<Textarea
className={styles.text_area}
className={styles.text_content_area}
value={postContent}
onChange={handlePostContentChange}
placeholder="投稿内容を入力"
/>

<Button type="submit" className={styles.post_button} variant="outline" disabled={!postContent}>
投稿
</Button>
</form>
<div className={styles.content_list__wrapper}>
{posts.map((post) => (
<div key={post.id}>
<div key={post.id} className={styles.content}>
<span className={styles.content_list}>{post.id}</span>
<span className={styles.content_list}>{post.postedBy}</span>
<span className={styles.content_list}>{post.postedAt}</span>
Expand Down