1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | 1x 1x | /** * @module FieldControls * */ /** */ import * as React from 'react' import { FieldSettings } from 'sn-client-js' import { IClientFieldSetting, IReactClientFieldSetting } from '../IClientFieldSetting' import { IRichTextEditorFieldSetting } from './IRichTextEditorFieldSetting' import * as ReactQuill from 'react-quill' import 'react-quill/dist/quill.snow.css' import { styles } from './RichTextEditorStyles' import './RichTextEditorStyles.css' import { Input } from 'react-materialize' import Radium from 'radium' /** * Interface for RichTextEditor properties */ export interface RichTextEditorProps extends IReactClientFieldSetting, IClientFieldSetting, IRichTextEditorFieldSetting { } /** * Field control that represents a LongText field. Available values will be populated from the FieldSettings. */ @Radium export class RichTextEditor extends React.Component<RichTextEditorProps, { value }> { /** * constructor * @param {object} props */ constructor(props) { super(props); /** * @type {object} * @property {string} value input value */ this.state = { value: this.setValue(this.props['data-fieldValue']) }; this.handleChange = this.handleChange.bind(this); } /** * returns default value of an input * @param {string} value */ setValue(value) { if (value) { return value; } else { if (this.props['data-defaultValue']) { return this.props['data-defaultValue'] } else { return '' } } } /** * handle change event on an input * @param {SytheticEvent} event */ handleChange(event) { this.setState({ value: event.target.value }); } /** * render * @return {ReactElement} markup */ render() { switch (this.props['data-actionName']) { case 'edit': return ( <ReactQuill name={this.props.name} label={ this.props.required ? this.props['data-labelText'] + ' *' : this.props['data-labelText'] } className={this.props.className} //placeholder={this.props['data-placeHolderText']} //placeHolderStyle?: object style={this.props.style} value={this.state.value} readOnly={this.props.readOnly} required={this.props.required} disabled={this.props.readOnly} error={this.props['data-errorText']} s={12} m={12} l={12} modules={modules} formats={formats} /> ) case 'new': return ( <ReactQuill name={this.props.name} label={ this.props.required ? this.props['data-labelText'] + ' *' : this.props['data-labelText'] } className={this.props.className} //placeholder={this.props['data-placeHolderText']} //placeHolderStyle?: object style={this.props.style} defaultValue={this.props['data-defaultValue']} readOnly={this.props.readOnly} required={this.props.required} disabled={this.props.readOnly} error={this.props['data-errorText']} s={12} m={12} l={12} modules={modules} formats={formats} /> ) case 'browse': return ( <div> <label> {this.props['data-labelText']} </label> <div dangerouslySetInnerHTML={{ __html: this.props['data-fieldValue'] }} /> </div> ) default: break; } } } const modules = { toolbar: [ ['bold', 'italic', 'underline', 'strike'], // toggled buttons ['blockquote', 'code-block'], [{ 'header': 1 }, { 'header': 2 }], // custom button values [{ 'list': 'ordered' }, { 'list': 'bullet' }], [{ 'script': 'sub' }, { 'script': 'super' }], // superscript/subscript [{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent [{ 'direction': 'rtl' }], // text direction [{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown [{ 'header': [1, 2, 3, 4, 5, 6, false] }], [{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme [{ 'font': [] }], [{ 'align': [] }], ['clean'] // remove formatting button ] }; const formats = [ 'header', 'font', 'size', 'bold', 'italic', 'underline', 'strike', 'blockquote', 'list', 'bullet', 'indent', 'link', 'image', 'video' ] |