Skip to content

Commit bcb19fb

Browse files
committed
Adicionando Preview
1 parent ee80445 commit bcb19fb

File tree

5 files changed

+97
-13
lines changed

5 files changed

+97
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"marked": "^0.8.2",
88
"react": "^16.12.0",
99
"react-dom": "^16.12.0",
10+
"react-icons": "^3.9.0",
1011
"react-redux": "^7.1.0-rc.1",
1112
"react-scripts": "3.2.0",
1213
"redux": "^4.0.4",

src/components/ComponentList/index.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React, { useState } from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
33
import marked from 'marked';
4-
import { sanitize } from 'dompurify'
4+
import { sanitize } from 'dompurify';
5+
import { MdDone, MdDvr, MdEdit } from 'react-icons/md';
6+
57
import { Types } from '../../store/reducer/example-reducer';
68

79
import Note from '../../models/Note';
@@ -13,6 +15,7 @@ export default function ComponentList() {
1315

1416
const qty = 20
1517
const [text, setText] = useState('')
18+
const [previewText, setPreviewText] = useState('')
1619

1720
const list = useSelector(
1821
state => state.exampleReducer.data.slice(0, qty)
@@ -25,20 +28,56 @@ export default function ComponentList() {
2528
let note = new Note(mdText)
2629
dispatch({ type: Types.ADD, note })
2730
setText('')
31+
setPreviewText('')
32+
}
33+
}
34+
35+
function preview() {
36+
if (previewText.length > 0) {
37+
setPreviewText('')
38+
} else {
39+
setPreviewText(`${sanitize(marked.parse(text))}`)
40+
}
41+
}
42+
43+
function show() {
44+
if (previewText.length > 0) {
45+
return 'hide'
46+
} else {
47+
return ''
48+
}
49+
}
50+
51+
function hide() {
52+
if (previewText.length > 0) {
53+
return ''
54+
} else {
55+
return 'hide'
2856
}
2957
}
3058

3159
return (
3260
<>
3361
<div className="content-add">
34-
<textarea
35-
cols={100}
36-
rows={10}
37-
value={text}
38-
onChange={e => setText(e.target.value)}
39-
placeholder="Digite sua nota"
40-
/>
41-
<button type="button" onClick={add}>ADD</button>
62+
<div className={show()}>
63+
<textarea
64+
autoFocus
65+
cols={100}
66+
rows={10}
67+
value={text}
68+
onChange={e => setText(e.target.value)}
69+
placeholder="Digite sua nota"
70+
/>
71+
</div>
72+
<div className={`preview ${hide()}`} dangerouslySetInnerHTML={{ __html: previewText }} />
73+
<div className="actions">
74+
<button type="button" className="color-success" onClick={add}>
75+
<MdDone width={24} />
76+
</button>
77+
<button type="button" onClick={preview}>
78+
{hide() ? <MdDvr width={24} /> : <MdEdit width={24} />}
79+
</button>
80+
</div>
4281
</div>
4382
<div className="content-list">
4483
<ul>

src/components/ComponentList/styles.css

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.content-add {
22
width: 100%;
3-
margin: 10px;
3+
margin: 50px;
44
display: flex;
5-
align-items: center;
5+
align-items: flex-end;
66
justify-content: center;
77
}
88

@@ -11,11 +11,45 @@
1111
font-size: 18px;
1212
border-radius: 3px;
1313
border: 1px solid #ccc;
14+
resize: vertical;
15+
overflow: auto;
1416
}
1517

16-
.content-add button {
18+
.content-add .actions button {
1719
padding: 10px;
1820
margin: 10px;
21+
22+
border: none;
23+
font-size: 24px;
24+
color: #434343;
25+
26+
cursor: pointer;
27+
}
28+
29+
.color-success {
30+
color: #008002 !important;
31+
}
32+
33+
.actions {
34+
display: flex;
35+
justify-content: space-between;
36+
align-items: center;
37+
flex-direction: column-reverse;
38+
height: 100%;
39+
}
40+
41+
.preview {
42+
border: 1px solid #cccccc;
43+
min-height: 235px;
44+
height: auto;
45+
width: 65%;
46+
margin-left: 0;
47+
border-radius: 3px;
48+
padding: 10px;
49+
}
50+
51+
.hide {
52+
display: none;
1953
}
2054

2155
.content-list {

src/components/ItemList/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { useDispatch } from 'react-redux';
33
import { Types } from '../../store/reducer/example-reducer';
4+
import { MdDeleteForever } from 'react-icons/md';
45
import './styles.css';
56

67
export default function ItemList({ item }) {
@@ -15,7 +16,9 @@ export default function ItemList({ item }) {
1516
return (
1617
<div className="content-wrapper">
1718
<div className="head">
18-
<button type="button" onClick={remove} className="trach">x</button>
19+
<button type="button" onClick={remove} className="trach">
20+
<MdDeleteForever width={16} />
21+
</button>
1922
</div>
2023
<div className="content" dangerouslySetInnerHTML={{ __html: item.text }} />
2124
<div className="footer">

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8407,6 +8407,13 @@ react-error-overlay@^6.0.3:
84078407
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.3.tgz#c378c4b0a21e88b2e159a3e62b2f531fd63bf60d"
84088408
integrity sha512-bOUvMWFQVk5oz8Ded9Xb7WVdEi3QGLC8tH7HmYP0Fdp4Bn3qw0tRFmr5TW6mvahzvmrK4a6bqWGfCevBflP+Xw==
84098409

8410+
react-icons@^3.9.0:
8411+
version "3.9.0"
8412+
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-3.9.0.tgz#89a00f20a0e02e6bfd899977eaf46eb4624239d5"
8413+
integrity sha512-gKbYKR+4QsD3PmIHLAM9TDDpnaTsr3XZeK1NTAb6WQQ+gxEdJ0xuCgLq0pxXdS7Utg2AIpcVhM1ut/jlDhcyNg==
8414+
dependencies:
8415+
camelcase "^5.0.0"
8416+
84108417
react-is@^16.7.0, react-is@^16.8.6:
84118418
version "16.12.0"
84128419
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.12.0.tgz#2cc0fe0fba742d97fd527c42a13bec4eeb06241c"

0 commit comments

Comments
 (0)