Skip to content

Commit 8dfaff8

Browse files
committed
feat: add tui.editor
1 parent f1b7987 commit 8dfaff8

File tree

6 files changed

+160
-11
lines changed

6 files changed

+160
-11
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
},
8585
"dependencies": {
8686
"@contentful/rich-text-react-renderer": "^13.4.0",
87+
"@toast-ui/editor": "^2.5.1",
8788
"appirio-tech-react-components": "git+https://github.com/appirio-tech/react-components.git#feature/connectv2",
8889
"axios": "^0.19.2",
8990
"brace": "^0.11.1",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
@import '~tc-ui/src/styles/tc-includes';
2+
3+
.editor {
4+
background: red;
5+
6+
> div {
7+
h1 {
8+
all: revert;
9+
font-size: 24px;
10+
}
11+
}
12+
13+
b,
14+
i,
15+
s,
16+
hr,
17+
blockquote,
18+
ul,
19+
li,
20+
ol,
21+
table,
22+
thead,
23+
tr,
24+
th,
25+
img,
26+
a,
27+
code,
28+
pre {
29+
all: revert;
30+
}
31+
32+
:global {
33+
.te-heading-add ul {
34+
list-style: none;
35+
}
36+
37+
.tui-editor-defaultUI .te-mode-switch-section {
38+
display: none !important
39+
}
40+
41+
// hide uplodd file
42+
.tui-editor-popup{
43+
box-shadow: 0px 0px 15px 5px rgba(0,0,0,0.26);
44+
}
45+
46+
.te-popup-add-image .te-tab button, .te-popup-add-image .te-file-type{
47+
display: none !important;
48+
}
49+
50+
.te-popup-add-image .te-url-type{
51+
display: block !important;
52+
}
53+
54+
}
55+
}

src/components/TuiEditor/index.jsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// wrap toast-ui editor with react and support react 15
2+
import React from 'react'
3+
import Editor from '@toast-ui/editor'
4+
import styles from './TuiEditor.scss'
5+
import cn from 'classnames'
6+
import 'codemirror/lib/codemirror.css'
7+
import '@toast-ui/editor/dist/toastui-editor.css'
8+
9+
export default class extends React.Component {
10+
constructor(props) {
11+
super(props)
12+
this.onValueChange = this.onValueChange.bind(this)
13+
}
14+
15+
getRootElement() {
16+
return this.refs.rootEl
17+
}
18+
19+
getInstance() {
20+
return this.editorInst
21+
}
22+
23+
bindEventHandlers(props) {
24+
Object.keys(props)
25+
.filter(key => /^on[A-Z][a-zA-Z]+/.test(key))
26+
.forEach(key => {
27+
const eventName = key[2].toLowerCase() + key.slice(3)
28+
this.editorInst.off(eventName)
29+
this.editorInst.on(eventName, props[key])
30+
})
31+
}
32+
33+
componentDidMount() {
34+
const props = {
35+
...this.props,
36+
onChange: this.onValueChange
37+
}
38+
this.editorInst = new Editor({
39+
el: this.refs.rootEl,
40+
...props
41+
})
42+
this.bindEventHandlers(props)
43+
}
44+
45+
onValueChange(){
46+
if (this.props.valueChange) {
47+
this.props.valueChange(this.getInstance().getMarkdown())
48+
}
49+
}
50+
51+
shouldComponentUpdate(nextProps) {
52+
const instance = this.getInstance()
53+
const { height, previewStyle, className } = nextProps
54+
55+
if (this.props.height !== height) {
56+
instance.height(height)
57+
}
58+
59+
if (this.props.previewStyle !== previewStyle) {
60+
instance.changePreviewStyle(previewStyle)
61+
}
62+
63+
if (this.props.className !== className) {
64+
return true
65+
}
66+
this.bindEventHandlers(nextProps, this.props)
67+
68+
return false
69+
}
70+
71+
render() {
72+
return <div ref="rootEl" className={cn(styles.editor, this.props.className)} />
73+
}
74+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
3+
import Editor from '../../../../components/TuiEditor'
4+
5+
const DescriptionField = (props) => (
6+
<Editor
7+
{...props}
8+
previewStyle="vertical"
9+
height="400px"
10+
initialEditType="wysiwyg"
11+
initialValue={props.value}
12+
/>
13+
)
14+
15+
export default DescriptionField

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

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

1112
import styles from './JobPickerRow.scss'
1213

@@ -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() {
@@ -229,20 +230,18 @@ class JobPickerRow extends React.PureComponent {
229230
/>
230231
</div>
231232
)
233+
232234
const descriptionColumn = (
233235
<div styleName="col col-skill-selection">
234236
<label className="tc-label" styleName="label">
235237
Job Description
236238
</label>
237-
<div styleName="job-description">
238-
<textarea
239-
className={`job-textarea ${isRowIncomplete && !value.description.trim() ? 'error' : 'empty'}`}
240-
onChange={this.handleDescriptionChange}
241-
placeholder="Job Description"
242-
type="text"
243-
value={value.description || ''}
244-
/>
245-
</div>
239+
<DescriptionField
240+
className={`${isRowIncomplete && !value.description.trim() ? 'error' : ''}`}
241+
valueChange={this.handleDescriptionChange}
242+
placeholder="Job Description"
243+
value={value.description || ''}
244+
/>
246245
</div>
247246
)
248247

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
}
4646

4747
.col {
48+
:global {
49+
.error > .tui-editor-defaultUI {
50+
border: 1px solid #ff5b52
51+
}
52+
}
4853
padding: 4px 7.5px;
4954
flex-grow: 0;
5055
flex-shrink: 0;

0 commit comments

Comments
 (0)