Skip to content

Commit ee80445

Browse files
committed
Adicionando markdown e estilizando a listagem
1 parent bf9ea8a commit ee80445

File tree

6 files changed

+97
-19
lines changed

6 files changed

+97
-19
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"dompurify": "^2.0.8",
7+
"marked": "^0.8.2",
68
"react": "^16.12.0",
79
"react-dom": "^16.12.0",
810
"react-redux": "^7.1.0-rc.1",

src/components/ComponentList/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, { useState } from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
3+
import marked from 'marked';
4+
import { sanitize } from 'dompurify'
35
import { Types } from '../../store/reducer/example-reducer';
46

57
import Note from '../../models/Note';
@@ -18,9 +20,12 @@ export default function ComponentList() {
1820
const dispatch = useDispatch();
1921

2022
function add() {
21-
let note = new Note(text)
22-
dispatch({ type: Types.ADD, note })
23-
setText('')
23+
if (text.length > 0) {
24+
let mdText = sanitize(marked.parse(text))
25+
let note = new Note(mdText)
26+
dispatch({ type: Types.ADD, note })
27+
setText('')
28+
}
2429
}
2530

2631
return (
@@ -31,12 +36,15 @@ export default function ComponentList() {
3136
rows={10}
3237
value={text}
3338
onChange={e => setText(e.target.value)}
39+
placeholder="Digite sua nota"
3440
/>
3541
<button type="button" onClick={add}>ADD</button>
3642
</div>
37-
<ul>
38-
{list.map(item => <li key={item.id}><ItemList item={item} /> </li>)}
39-
</ul>
43+
<div className="content-list">
44+
<ul>
45+
{list.map(item => <li key={item.id}><ItemList item={item} /> </li>)}
46+
</ul>
47+
</div>
4048
</>
4149
);
4250
}

src/components/ComponentList/styles.css

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,43 @@
99
.content-add textarea {
1010
padding: 10px;
1111
font-size: 18px;
12+
border-radius: 3px;
13+
border: 1px solid #ccc;
1214
}
1315

1416
.content-add button {
1517
padding: 10px;
1618
margin: 10px;
1719
}
1820

19-
ul {
20-
width: 100%;
21-
margin: 30px;
21+
.content-list {
2222
display: flex;
2323
align-items: center;
2424
justify-content: center;
2525
flex-direction: column;
2626
}
2727

28-
ul li {
29-
margin: 10px;
28+
ul {
29+
width: 80%;
3030
padding: 30px;
31-
height: 30px;
31+
}
32+
33+
ul li {
34+
margin: 20px;
35+
padding: 20px;
36+
min-height: 200px;
37+
height: auto;
38+
width: 100%;
3239
display: flex;
3340
align-items: center;
3441
justify-content: center;
42+
list-style: none;
43+
44+
-webkit-box-shadow: 0px 0px 7px 1px rgba(209,209,209,1);
45+
-moz-box-shadow: 0px 0px 7px 1px rgba(209,209,209,1);
46+
box-shadow: 0px 0px 7px 1px rgba(209,209,209,1);
47+
48+
border-radius: 3px;
3549

36-
border: 1px solid #717180;
37-
border-radius: 8px;
50+
position: relative;
3851
}

src/components/ItemList/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ export default function ItemList({ item }) {
1313
}
1414

1515
return (
16-
<span>
17-
<div>{item.text}</div>
18-
<small>{item.createAt}</small>
19-
<button type="button" onClick={remove} className="trach">DEL</button>
20-
</span>
16+
<div className="content-wrapper">
17+
<div className="head">
18+
<button type="button" onClick={remove} className="trach">x</button>
19+
</div>
20+
<div className="content" dangerouslySetInnerHTML={{ __html: item.text }} />
21+
<div className="footer">
22+
<small>Criado em: {item.createAt}</small>
23+
</div>
24+
</div>
2125
);
2226
}

src/components/ItemList/styles.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
span {
2+
width: 100%;
3+
}
4+
.content {
5+
padding-bottom: 30px;
6+
}
7+
8+
.trach {
9+
text-decoration: none;
10+
border: none;
11+
padding: 7px 10px;
12+
13+
-webkit-box-shadow: -1px 3px 15px -2px rgba(209,209,209,1);
14+
-moz-box-shadow: -1px 3px 15px -2px rgba(209,209,209,1);
15+
box-shadow: -1px 3px 15px -2px rgba(209,209,209,1);
16+
17+
margin: 3px;
18+
border-radius: 21px;
19+
color: #e02041;
20+
cursor: pointer;
21+
text-transform: uppercase;
22+
font-size: 16px;
23+
font-weight: bold;
24+
}
25+
26+
.content-wrapper {
27+
width: 100%;
28+
}
29+
30+
.head {
31+
position: absolute;
32+
top: -20px;
33+
right: -20px;
34+
}
35+
36+
.footer {
37+
display: flex;
38+
align-items: center;
39+
justify-content: space-between;
40+
width: 100%;
41+
}

yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3579,6 +3579,11 @@ domhandler@^2.3.0:
35793579
dependencies:
35803580
domelementtype "1"
35813581

3582+
dompurify@^2.0.8:
3583+
version "2.0.8"
3584+
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-2.0.8.tgz#6ef89d2d227d041af139c7b01d9f67ed59c2eb3c"
3585+
integrity sha512-vIOSyOXkMx81ghEalh4MLBtDHMx1bhKlaqHDMqM2yeitJ996SLOk5mGdDpI9ifJAgokred8Rmu219fX4OltqXw==
3586+
35823587
domutils@1.5.1:
35833588
version "1.5.1"
35843589
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf"
@@ -6375,6 +6380,11 @@ map-visit@^1.0.0:
63756380
dependencies:
63766381
object-visit "^1.0.0"
63776382

6383+
marked@^0.8.2:
6384+
version "0.8.2"
6385+
resolved "https://registry.yarnpkg.com/marked/-/marked-0.8.2.tgz#4faad28d26ede351a7a1aaa5fec67915c869e355"
6386+
integrity sha512-EGwzEeCcLniFX51DhTpmTom+dSA/MG/OBUDjnWtHbEnjAH180VzUeAw+oE4+Zv+CoYBWyRlYOTR0N8SO9R1PVw==
6387+
63786388
md5.js@^1.3.4:
63796389
version "1.3.5"
63806390
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"

0 commit comments

Comments
 (0)