Skip to content

Commit 45c395a

Browse files
authored
Merge pull request #4302 from yoution/issue-4298
fix: add easymde #4298
2 parents 9b2d9fd + d7bae5b commit 45c395a

File tree

6 files changed

+309
-22
lines changed

6 files changed

+309
-22
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"draft-js-mention-plugin": "^2.0.0-rc2",
9797
"draft-js-plugins-editor": "^2.0.0-rc2",
9898
"draft-js-utils": "^0.1.7",
99+
"easymde": "^2.14.0",
99100
"expression-evaluator": "git+https://github.com/topcoder-platform/expression-evaluator.git#dev",
100101
"fbemitter": "^2.1.1",
101102
"fbjs": "^0.8.12",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React, { Component } from 'react'
2+
import styles from './MarkdownText.scss'
3+
import PropTypes from 'prop-types'
4+
import EasyMDE from 'easymde'
5+
import { markdownToHTML } from '../../helpers/markdownToState'
6+
7+
class MarkdownText extends Component {
8+
constructor (props) {
9+
super(props)
10+
this.updateDescription = this.updateDescription.bind(this)
11+
}
12+
13+
updateDescription () {
14+
const { onChange } = this.props
15+
onChange(this.easymde.value())
16+
}
17+
18+
componentDidMount () {
19+
const { value, readOnly } = this.props
20+
if (!readOnly) {
21+
this.easymde = new EasyMDE({ element: this.refs.textarea, initialValue: value })
22+
this.easymde.codemirror.on('change', () => {
23+
this.updateDescription()
24+
})
25+
} else {
26+
this.refs.textarea.innerHTML = value ? markdownToHTML(value) : ''
27+
}
28+
}
29+
30+
render () {
31+
const { readOnly, placeholder } = this.props
32+
return (<div className={styles.editor}>
33+
{readOnly ? (
34+
<div ref="textarea" className="EasyMDEContainer-readonly"/>
35+
) : (
36+
<textarea
37+
ref="textarea"
38+
placeholder={placeholder}
39+
/>
40+
)}
41+
</div>)
42+
}
43+
}
44+
45+
MarkdownText.defaultProps = {
46+
readOnly: false
47+
}
48+
49+
MarkdownText.propTypes = {
50+
onChange: PropTypes.func.isRequired,
51+
value: PropTypes.string,
52+
placeholder: PropTypes.string,
53+
readOnly: PropTypes.bool
54+
}
55+
export default MarkdownText
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
@import '~tc-ui/src/styles/tc-includes';
2+
3+
.editor {
4+
@include roboto-light();
5+
6+
border-radius: 2px;
7+
font-size: 16px;
8+
max-height: 410px;
9+
display: flex;
10+
11+
:global {
12+
.EasyMDEContainer-readonly {
13+
border: 1px solid #aaaaab;
14+
border-radius: 4px;
15+
padding: 0 10px;
16+
}
17+
18+
.EasyMDEContainer, .EasyMDEContainer-readonly {
19+
display: flex;
20+
width: 100%;
21+
flex-direction: column;
22+
overflow: auto;
23+
24+
// preview styles
25+
.h1,.h2,.h3,.h4,.h5,.h6,h1,h2,h3,h4,h5,h6 {
26+
text-align:initial;
27+
margin-bottom: .5rem;
28+
font-weight: 500;
29+
line-height: 1.2
30+
}
31+
32+
.h1,h1 {
33+
font-size: 2.5rem
34+
}
35+
36+
.h2,h2 {
37+
font-size: 2rem
38+
}
39+
40+
.h3,h3 {
41+
font-size: 1.75rem
42+
}
43+
44+
.h4,h4 {
45+
font-size: 1.5rem
46+
}
47+
48+
.h5,h5 {
49+
font-size: 1.25rem
50+
}
51+
52+
.h6,h6 {
53+
font-size: 1rem
54+
}
55+
h1,h2,h3,h4,h5,h6 {
56+
margin-top: 0;
57+
margin-bottom: .5rem
58+
}
59+
60+
p {
61+
margin-top: 0;
62+
margin-bottom: 1rem
63+
}
64+
65+
66+
dl,ol,ul {
67+
margin-top: 0;
68+
margin-bottom: 1rem;
69+
padding: revert;
70+
}
71+
ul {
72+
list-style-type: disc;
73+
}
74+
ul ul {
75+
list-style-type: circle;
76+
}
77+
ul ul ul {
78+
list-style-type: square;
79+
}
80+
ol {
81+
list-style-type: decimal;
82+
}
83+
84+
ol ol,ol ul,ul ol,ul ul {
85+
margin-bottom: 0
86+
}
87+
88+
dt {
89+
font-weight: 700
90+
}
91+
92+
dd {
93+
margin-bottom: .5rem;
94+
margin-left: 0
95+
}
96+
97+
blockquote {
98+
margin: 0 0 1rem
99+
}
100+
101+
b,strong {
102+
font-weight: bolder
103+
}
104+
105+
small {
106+
font-size: 80%
107+
}
108+
109+
sub,sup {
110+
position: relative;
111+
font-size: 75%;
112+
line-height: 0;
113+
vertical-align: initial
114+
}
115+
116+
sub {
117+
bottom: -.25em
118+
}
119+
120+
sup {
121+
top: -.5em
122+
}
123+
124+
a {
125+
color: #007bff;
126+
text-decoration: none;
127+
background-color: initial
128+
}
129+
130+
a:hover {
131+
color: #0056b3;
132+
text-decoration: underline
133+
}
134+
135+
a:not([href]),a:not([href]):hover {
136+
color: inherit;
137+
text-decoration: none
138+
}
139+
140+
code,kbd,pre,samp {
141+
font-family: SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;
142+
font-size: 1em
143+
}
144+
145+
pre {
146+
margin-top: 0;
147+
margin-bottom: 1rem;
148+
overflow: auto
149+
}
150+
151+
figure {
152+
margin: 0 0 1rem
153+
}
154+
155+
img {
156+
border-style: none
157+
}
158+
159+
img,svg {
160+
vertical-align: middle
161+
}
162+
163+
svg {
164+
overflow: hidden
165+
}
166+
167+
table {
168+
border-collapse: collapse
169+
}
170+
171+
caption {
172+
padding-top: .75rem;
173+
padding-bottom: .75rem;
174+
color: #6c757d;
175+
text-align: left;
176+
caption-side: bottom
177+
}
178+
179+
th {
180+
text-align: inherit
181+
}
182+
183+
184+
small {
185+
font-size: 80%;
186+
font-weight: 400
187+
}
188+
189+
mark {
190+
padding: .2em;
191+
background-color: #fcf8e3
192+
}
193+
194+
code {
195+
font-size: 87.5%;
196+
color: #e83e8c;
197+
word-wrap: break-word
198+
}
199+
200+
a>code {
201+
color: inherit
202+
}
203+
204+
kbd {
205+
padding: .2rem .4rem;
206+
font-size: 87.5%;
207+
color: #fff;
208+
background-color: #212529;
209+
border-radius: .2rem
210+
}
211+
212+
kbd kbd {
213+
padding: 0;
214+
font-size: 100%;
215+
font-weight: 700
216+
}
217+
218+
pre {
219+
display: block;
220+
font-size: 87.5%;
221+
color: #212529
222+
}
223+
224+
pre code {
225+
font-size: inherit;
226+
color: inherit;
227+
word-break: normal
228+
}
229+
230+
}
231+
232+
.CodeMirror.CodeMirror-wrap {
233+
min-height: 0;
234+
flex: 1;
235+
}
236+
}
237+
238+
}

src/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import _ from 'lodash'
66
import { render } from 'react-dom'
77
import { SEGMENT_KEY } from './config/constants'
88
import App from './App'
9+
import 'easymde/dist/easymde.min.css'
910

1011
import 'styles/main.scss'
1112

src/projects/detail/components/JobPickerRow/JobPickerRow.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import IconX from '../../../../assets/icons/ui-16px-1_bold-remove.svg'
66
import IconAdd from '../../../../assets/icons/ui-16px-1_bold-add.svg'
77
import SkillsQuestion from '../SkillsQuestion/SkillsQuestionBase'
88
import PositiveNumberInput from '../../../../components/PositiveNumberInput/PositiveNumberInput'
9+
import MarkdownText from '../../../../components/MarkdownText/MarkdownText'
910
import SelectDropdown from 'appirio-tech-react-components/components/SelectDropdown/SelectDropdown'
1011

1112
import styles from './JobPickerRow.scss'
@@ -73,8 +74,8 @@ class JobPickerRow extends React.PureComponent {
7374
this.props.onChange(this.props.rowIndex, 'role', evt)
7475
}
7576

76-
handleDescriptionChange(evt) {
77-
this.props.onChange(this.props.rowIndex, 'description', evt.target.value)
77+
handleDescriptionChange(value) {
78+
this.props.onChange(this.props.rowIndex, 'description', value)
7879
}
7980

8081
resetDuration() {
@@ -234,13 +235,11 @@ class JobPickerRow extends React.PureComponent {
234235
<label className="tc-label" styleName="label">
235236
Job Description
236237
</label>
237-
<div styleName="job-description">
238-
<textarea
239-
className={`job-textarea ${isRowIncomplete && !value.description.trim() ? 'error' : 'empty'}`}
238+
<div styleName={`job-description ${isRowIncomplete && !value.description.trim() ? 'error' : ''}`} >
239+
<MarkdownText
240+
value={value.description || ''}
240241
onChange={this.handleDescriptionChange}
241242
placeholder="Job Description"
242-
type="text"
243-
value={value.description || ''}
244243
/>
245244
</div>
246245
</div>

src/projects/detail/components/JobPickerRow/JobPickerRow.scss

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,15 @@
8686
display: block;
8787
}
8888

89-
.job-description textarea,
90-
.job-textarea[type="text"] {
91-
&.empty {
92-
color: $tc-gray-30;
89+
.job-description {
90+
&.error {
91+
:global {
92+
.CodeMirror {
93+
border:1px solid $tc-red-70;
94+
}
95+
}
9396
}
94-
min-height : 90px;
95-
96-
@include placeholder {
97-
@include roboto;
98-
color: $tc-gray-30;
99-
text-transform: none;
100-
font-style: italic;
101-
font-size: $base-unit*3;
102-
line-height: $base-unit*4;
103-
}
104-
}
97+
}
10598
}
10699

107100
.col-role-container {

0 commit comments

Comments
 (0)