mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
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 Message from 'core-components/message';
|
||||||
import Form from 'core-components/form';
|
import Form from 'core-components/form';
|
||||||
import Input from 'core-components/input';
|
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 DropDown from 'core-components/drop-down';
|
||||||
import Widget from 'core-components/widget';
|
import Widget from 'core-components/widget';
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ class CreateTicketForm extends React.Component {
|
|||||||
{content: 'Department3'}
|
{content: 'Department3'}
|
||||||
]} />
|
]} />
|
||||||
<Input label="Title" name="title" required />
|
<Input label="Title" name="title" required />
|
||||||
<TextEditor label="Content" name="content" required />
|
<TextArea label="Content" name="content" required />
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -55,7 +55,7 @@ class MainLayoutHeader extends React.Component {
|
|||||||
return {
|
return {
|
||||||
className: 'main-layout-header__languages',
|
className: 'main-layout-header__languages',
|
||||||
items: this.getLanguageList(),
|
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)
|
onChange: this.changeLanguage.bind(this)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,12 @@ import ValidationFactory from 'lib-app/validations/validations-factory';
|
|||||||
|
|
||||||
import Input from 'core-components/input';
|
import Input from 'core-components/input';
|
||||||
import Checkbox from 'core-components/checkbox';
|
import Checkbox from 'core-components/checkbox';
|
||||||
|
//import TextArea from 'core-components/text-area';
|
||||||
|
|
||||||
|
const validFieldTypes = [
|
||||||
|
Input,
|
||||||
|
CheckBox
|
||||||
|
];
|
||||||
|
|
||||||
class Form extends React.Component {
|
class Form extends React.Component {
|
||||||
|
|
||||||
@ -75,7 +81,7 @@ class Form extends React.Component {
|
|||||||
getFieldProps({props, type}) {
|
getFieldProps({props, type}) {
|
||||||
let additionalProps = {};
|
let additionalProps = {};
|
||||||
|
|
||||||
if (type === Input || type === Checkbox) {
|
if (this.isValidFieldType({type})) {
|
||||||
let fieldName = props.name;
|
let fieldName = props.name;
|
||||||
|
|
||||||
additionalProps = {
|
additionalProps = {
|
||||||
@ -145,6 +151,9 @@ class Form extends React.Component {
|
|||||||
else if (child.type === Checkbox) {
|
else if (child.type === Checkbox) {
|
||||||
form[child.props.name] = child.props.checked || false;
|
form[child.props.name] = child.props.checked || false;
|
||||||
}
|
}
|
||||||
|
// else if (child.type === TextArea) {
|
||||||
|
// DO SOMETHING
|
||||||
|
// }
|
||||||
|
|
||||||
if (child.props.required) {
|
if (child.props.required) {
|
||||||
validations[child.props.name] = ValidationFactory.getValidator(child.props.validation || 'DEFAULT');
|
validations[child.props.name] = ValidationFactory.getValidator(child.props.validation || 'DEFAULT');
|
||||||
@ -183,7 +192,7 @@ class Form extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isValidFieldType(child) {
|
isValidFieldType(child) {
|
||||||
return child.type === Input || child.type === Checkbox;
|
return _.includes(validFieldTypes, child.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasFormErrors() {
|
hasFormErrors() {
|
||||||
|
@ -18,22 +18,13 @@ class TextArea extends React.Component {
|
|||||||
error: React.PropTypes.string
|
error: React.PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
|
|
||||||
this.state = {
|
|
||||||
editorState: EditorState.createEmpty()
|
|
||||||
};
|
|
||||||
this.onChange = (editorState) => this.setState({editorState});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<label className={this.getClass()}>
|
<span className={this.getClass()}>
|
||||||
<span className="text-area__label">{this.props.label}</span>
|
<span className="text-area__label">{this.props.label}</span>
|
||||||
<TextEditor />
|
<TextEditor {...this.getEditorProps()}/>
|
||||||
{this.renderError()}
|
{this.renderError()}
|
||||||
</label>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +38,7 @@ class TextArea extends React.Component {
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*getEditorProps() {
|
getEditorProps() {
|
||||||
let props = _.clone(this.props);
|
let props = _.clone(this.props);
|
||||||
|
|
||||||
props['aria-required'] = this.props.required;
|
props['aria-required'] = this.props.required;
|
||||||
@ -57,11 +48,10 @@ class TextArea extends React.Component {
|
|||||||
|
|
||||||
delete props.required;
|
delete props.required;
|
||||||
delete props.validation;
|
delete props.validation;
|
||||||
delete props.error;
|
|
||||||
delete props.password;
|
delete props.password;
|
||||||
|
|
||||||
return props;
|
return props;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
getClass() {
|
getClass() {
|
||||||
let classes = {
|
let classes = {
|
||||||
|
@ -34,9 +34,6 @@
|
|||||||
display: block;
|
display: block;
|
||||||
position: absolute;
|
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';
|
import Button from 'core-components/button';
|
||||||
|
|
||||||
class TextEditor extends React.Component {
|
class TextEditor extends React.Component {
|
||||||
|
static propTypes = {
|
||||||
|
error: React.PropTypes.bool
|
||||||
|
};
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -54,6 +57,7 @@ class TextEditor extends React.Component {
|
|||||||
getClass() {
|
getClass() {
|
||||||
let classes = {
|
let classes = {
|
||||||
'text-editor': true,
|
'text-editor': true,
|
||||||
|
'text-editor_errored': (this.props.error),
|
||||||
'text-editor_focused': (this.state.focused),
|
'text-editor_focused': (this.state.focused),
|
||||||
|
|
||||||
[this.props.className]: (this.props.className)
|
[this.props.className]: (this.props.className)
|
||||||
|
@ -30,4 +30,10 @@
|
|||||||
border-color: $primary-blue;
|
border-color: $primary-blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&_errored {
|
||||||
|
.text-editor__editor {
|
||||||
|
border: 1px solid $primary-red;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user