Skip to content

Commit d1318b1

Browse files
author
Aishwarya Nair
committed
add accordion and delete button
1 parent 8734bc6 commit d1318b1

File tree

8 files changed

+164
-20
lines changed

8 files changed

+164
-20
lines changed

peer-prep.zip

78.6 MB
Binary file not shown.
4.16 KB
Loading
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
.question-container {
3+
display: flex;
4+
margin: auto;
5+
margin-top: 30px;
6+
width: 600px;
7+
gap: 20px;
8+
align-items: center;
9+
}
10+
11+
.question {
12+
width: 500px;
13+
background: #e9e9e9;
14+
padding: 0.5rem 1rem;
15+
border-radius: 5px;
16+
}
17+
18+
.q-header {
19+
display: flex;
20+
justify-content: space-between;
21+
align-items: center;
22+
cursor: pointer;
23+
}
24+
25+
.q-header span {
26+
padding: 0.5rem 1rem;
27+
}
28+
29+
.q-name {
30+
display: flex;
31+
align-items: center;
32+
height: 60px;
33+
font-size: 25px;
34+
}
35+
36+
.q-title {
37+
height: 30px;
38+
padding: 0.5rem 0.5rem;
39+
}
40+
41+
.q-tags {
42+
display: flex;
43+
align-items: center;
44+
gap: 10px;
45+
margin-left: 20px;
46+
47+
}
48+
49+
.q-tag {
50+
width: 80px;
51+
height: 25px;
52+
border-radius: 5px;
53+
background: #A98CD8;
54+
padding: 0.5rem 0.5rem;
55+
color: #fff;
56+
display: flex;
57+
justify-content: center;
58+
}
59+
60+
.q-id {
61+
padding: 0.5rem 1rem;
62+
}
63+
64+
.q-description {
65+
width: 400px;
66+
height: 250px;
67+
margin-left: 20px;
68+
border: none;
69+
}
70+
71+
.q-content {
72+
max-height: 0;
73+
overflow:hidden;
74+
}
75+
76+
.q-content-show {
77+
display: flex;
78+
flex-direction: column;
79+
gap: 20px;
80+
height:150px;
81+
82+
}
83+
84+
.delete-btn img {
85+
width: 40px;
86+
height: 40px;
87+
cursor: pointer;
88+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, {useState} from 'react'
2+
import './Question.css'
3+
import delete_icon from '../Assets/bin.png'
4+
5+
export const Question = ({question, i}) => {
6+
const [selected, setSelected] = useState(null);
7+
const toggle = (i) => {
8+
if(selected === i) {
9+
return setSelected(null)
10+
}
11+
setSelected(i)
12+
}
13+
return (
14+
<div className="question-container">
15+
<div className="question">
16+
<div className="q-header" onClick = {() => toggle(i)}>
17+
<div className="q-name">
18+
<div className="q-id">#{question.id}</div>
19+
<div className="q-title">{question.title}</div>
20+
</div>
21+
<span> {selected === i ? "-" : "+"}</span>
22+
</div>
23+
<div className= {selected === i ? "q-content-show": "q-content"}>
24+
<div className="q-tags">
25+
<div className="q-tag">{question.difficulty}</div>
26+
<div className="q-tag">{question.topic}</div>
27+
</div>
28+
<div className="q-description">{question.description}</div>
29+
</div>
30+
31+
32+
</div>
33+
<div className="delete-btn">
34+
<img src= {delete_icon} alt="" />
35+
</div>
36+
</div>
37+
38+
)
39+
}

peer-prep/src/Components/QuestionList/QuestionForm.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@
1111
border-radius: 5px;
1212
}
1313

14-
.q-header {
14+
.q-form-header {
1515
display: flex;
1616
align-items: center;
1717
height: 60px;
1818
font-size: 25px;
1919

2020
}
2121

22-
.q-title {
22+
.q-form-title {
2323
height: 30px;
2424
padding: 0.5rem 0.5rem;
2525
}
2626

27-
.q-tags {
27+
.q-form-tags {
2828
display: flex;
2929
align-items: center;
3030
gap: 10px;
3131
margin-left: 20px;
3232
}
3333

34-
.q-tag {
34+
.q-form-tag {
3535
width: 80px;
3636
height: 25px;
3737
border-radius: 5px;
3838

3939
}
4040

41-
.q-id {
41+
.q-form-id {
4242
padding: 0.5rem 1rem;
4343
}
44-
.q-input {
44+
.q-form-input {
4545
outline: none;
4646
border: none;
4747
background: #c9c9c9;
@@ -51,14 +51,14 @@
5151
sans-serif;
5252
}
5353

54-
.q-input::placeholder {
54+
.q-form-input::placeholder {
5555
color: #797979;
5656
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
5757
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5858
sans-serif;
5959
}
6060

61-
.q-description {
61+
.q-form-description {
6262
width: 400px;
6363
height: 250px;
6464
margin-left: 20px;

peer-prep/src/Components/QuestionList/QuestionForm.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,28 @@ export const QuestionForm = ({qId, addQuestion, setAddQ}) => {
1515
}
1616
return (
1717
<form className = "container" onSubmit={handleSubmit(setAddQ, addQuestion)}>
18-
<div className="q-header">
19-
<div className="q-id">#{qId}</div>
20-
<input type="text" className="q-title q-input"
18+
<div className="q-form-header">
19+
<div className="q-form-id">#{qId}</div>
20+
<input type="text" className="q-form-title q-form-input"
2121
placeholder='Question Title' onChange = {
2222
(e) => setTitle(e.target.value)
2323
}/>
2424
</div>
2525

26-
<div className="q-tags">
27-
<input type="text" className="q-tag q-input"
26+
<div className="q-form-tags">
27+
<input type="text" className="q-form-tag q-form-input"
2828
placeholder = 'Difficulty'
2929
onChange = {
3030
(e) => setDifficulty(e.target.value)
3131
}/>
32-
<input type="text" className="q-tag q-input"
32+
<input type="text" className="q-form-tag q-form-input"
3333
placeholder = 'Topic'
3434
onChange = {
3535
(e) => setTopic(e.target.value)
3636
}
3737
/>
3838
</div>
39-
<textarea type="text" className="q-description q-input"
39+
<textarea type="text" className="q-form-description q-form-input"
4040
placeholder = "Question description"
4141
onChange = {
4242
(e) => setDescription(e.target.value)

peer-prep/src/Components/QuestionList/QuestionList.css

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
}
1010

1111
.add-q-btn {
12-
position: absolute;
13-
right: 30px;
12+
position: fixed;
13+
right: 60px;
1414
bottom: 30px;
1515
display: flex;
1616
justify-content: center;
@@ -22,4 +22,8 @@
2222
border-radius: 5px;
2323
font-size: 19px;
2424
cursor: pointer;
25+
}
26+
27+
.accordion {
28+
2529
}
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import React, { useState, useEffect} from 'react'
22
import { QuestionForm } from './QuestionForm'
3+
import {Question} from './Question'
34
import './QuestionList.css'
45

56
export const Questions = () => {
67
const [qId, setQId] = useState(0);
78
const [isAddQ, setAddQ] = useState(false);
89
const [qs, setQs] = useState([])
10+
const toggle = (i) => {
11+
return i
12+
}
913

1014
const addQuestion = (qTitle, qDifficulty, qTopic, qDescription) => {
1115
setQs([...qs, {id: qId, title: qTitle, difficulty: qDifficulty,
@@ -15,14 +19,23 @@ export const Questions = () => {
1519
useEffect(() => console.log(qs), [qs]);
1620

1721
return (
22+
1823
<div className="q-wrapper">
24+
<div className="accordion">
25+
{qs.map((q, i) => (
26+
<Question question = {q} key = {q.id} i = {i}/>
27+
))}
28+
</div>
29+
1930
{isAddQ === false ? <div></div> : <QuestionForm qId = {qId} addQuestion = {addQuestion}
2031
setAddQ = {setAddQ}/>}
2132
<div className="add-q-btn" onClick = {() => {
22-
setQId(qId + 1);
23-
setAddQ(true);
24-
}}> Add question</div>
33+
setQId(qId + 1);
34+
setAddQ(true);
35+
}}> Add question</div>
2536
</div>
2637

38+
39+
2740
)
2841
}

0 commit comments

Comments
 (0)