Ivan - Add text editor to text area [skip ci]
This commit is contained in:
parent
95290e97f7
commit
99e9392c45
|
@ -8,7 +8,7 @@ import SubmitButton from 'core-components/submit-button';
|
|||
import Message from 'core-components/message';
|
||||
import Form from 'core-components/form';
|
||||
import Input from 'core-components/input';
|
||||
import TextEditor from 'core-components/text-editor';
|
||||
import TextArea from 'core-components/text-area';
|
||||
import DropDown from 'core-components/drop-down';
|
||||
import Widget from 'core-components/widget';
|
||||
|
||||
|
@ -23,7 +23,7 @@ class CreateTicketForm extends React.Component {
|
|||
{content: 'Department3'}
|
||||
]} />
|
||||
<Input label="Title" name="title" required />
|
||||
<TextEditor label="Content" name="content" required />
|
||||
<TextArea label="Content" name="content" required />
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -55,7 +55,7 @@ class MainLayoutHeader extends React.Component {
|
|||
return {
|
||||
className: 'main-layout-header__languages',
|
||||
items: this.getLanguageList(),
|
||||
selectedIndex: Object.values(codeLanguages).indexOf(this.props.config.language),
|
||||
selectedIndex: Object.keys(codeLanguages).map((key) => codeLanguages[key]).indexOf(this.props.config.language),
|
||||
onChange: this.changeLanguage.bind(this)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,6 +7,12 @@ import ValidationFactory from 'lib-app/validations/validations-factory';
|
|||
|
||||
import Input from 'core-components/input';
|
||||
import Checkbox from 'core-components/checkbox';
|
||||
//import TextArea from 'core-components/text-area';
|
||||
|
||||
const validFieldTypes = [
|
||||
Input,
|
||||
CheckBox
|
||||
];
|
||||
|
||||
class Form extends React.Component {
|
||||
|
||||
|
@ -75,7 +81,7 @@ class Form extends React.Component {
|
|||
getFieldProps({props, type}) {
|
||||
let additionalProps = {};
|
||||
|
||||
if (type === Input || type === Checkbox) {
|
||||
if (this.isValidFieldType({type})) {
|
||||
let fieldName = props.name;
|
||||
|
||||
additionalProps = {
|
||||
|
@ -145,6 +151,9 @@ class Form extends React.Component {
|
|||
else if (child.type === Checkbox) {
|
||||
form[child.props.name] = child.props.checked || false;
|
||||
}
|
||||
// else if (child.type === TextArea) {
|
||||
// DO SOMETHING
|
||||
// }
|
||||
|
||||
if (child.props.required) {
|
||||
validations[child.props.name] = ValidationFactory.getValidator(child.props.validation || 'DEFAULT');
|
||||
|
@ -183,7 +192,7 @@ class Form extends React.Component {
|
|||
}
|
||||
|
||||
isValidFieldType(child) {
|
||||
return child.type === Input || child.type === Checkbox;
|
||||
return _.includes(validFieldTypes, child.type);
|
||||
}
|
||||
|
||||
hasFormErrors() {
|
||||
|
|
|
@ -18,22 +18,13 @@ class TextArea extends React.Component {
|
|||
error: React.PropTypes.string
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
editorState: EditorState.createEmpty()
|
||||
};
|
||||
this.onChange = (editorState) => this.setState({editorState});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<label className={this.getClass()}>
|
||||
<span className={this.getClass()}>
|
||||
<span className="text-area__label">{this.props.label}</span>
|
||||
<TextEditor />
|
||||
<TextEditor {...this.getEditorProps()}/>
|
||||
{this.renderError()}
|
||||
</label>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -47,7 +38,7 @@ class TextArea extends React.Component {
|
|||
return error;
|
||||
}
|
||||
|
||||
/*getEditorProps() {
|
||||
getEditorProps() {
|
||||
let props = _.clone(this.props);
|
||||
|
||||
props['aria-required'] = this.props.required;
|
||||
|
@ -57,11 +48,10 @@ class TextArea extends React.Component {
|
|||
|
||||
delete props.required;
|
||||
delete props.validation;
|
||||
delete props.error;
|
||||
delete props.password;
|
||||
|
||||
return props;
|
||||
}*/
|
||||
}
|
||||
|
||||
getClass() {
|
||||
let classes = {
|
||||
|
|
|
@ -34,9 +34,6 @@
|
|||
display: block;
|
||||
position: absolute;
|
||||
}
|
||||
.text-area__text {
|
||||
border: 1px solid $primary-red;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,9 @@ import {Editor, EditorState, RichUtils} from 'draft-js';
|
|||
import Button from 'core-components/button';
|
||||
|
||||
class TextEditor extends React.Component {
|
||||
static propTypes = {
|
||||
error: React.PropTypes.bool
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
@ -54,6 +57,7 @@ class TextEditor extends React.Component {
|
|||
getClass() {
|
||||
let classes = {
|
||||
'text-editor': true,
|
||||
'text-editor_errored': (this.props.error),
|
||||
'text-editor_focused': (this.state.focused),
|
||||
|
||||
[this.props.className]: (this.props.className)
|
||||
|
|
|
@ -30,4 +30,10 @@
|
|||
border-color: $primary-blue;
|
||||
}
|
||||
}
|
||||
|
||||
&_errored {
|
||||
.text-editor__editor {
|
||||
border: 1px solid $primary-red;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue