-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathTextOptions.jsx
More file actions
71 lines (66 loc) · 2.61 KB
/
Copy pathTextOptions.jsx
File metadata and controls
71 lines (66 loc) · 2.61 KB
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
/*
* Copyright 2018, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, { useState } from "react";
import { Col, Form, FormControl, FormGroup } from "react-bootstrap";
import localizedProps from "../../../../misc/enhancers/localizedProps";
import {
htmlToDraftJSEditorState,
draftJSEditorStateToHtml
} from "../../../../../utils/EditorUtils";
import withDebounceOnCallback from "../../../../misc/enhancers/withDebounceOnCallback";
import CompactRichTextEditor from "../../../../mapviews/settings/CompactRichTextEditor";
const TitleInput = localizedProps("placeholder")(FormControl);
const DescriptorEditor = withDebounceOnCallback(
"onEditorStateChange",
"editorState"
)(CompactRichTextEditor);
function TextOptions({ data = {}, onChange = () => {} }) {
const [editorState, setEditorState] = useState(
htmlToDraftJSEditorState(data.text || "")
);
return (
<div>
<Col key="form" xs={12}>
<Form>
<FormGroup controlId="title">
<Col sm={12}>
<TitleInput
style={{ marginBottom: 10 }}
placeholder="widgets.builder.wizard.titlePlaceholder"
value={data.title}
cy-data="add-widget-text-title"
type="text"
onChange={(e) =>
onChange("title", e.target.value)
}
/>
</Col>
</FormGroup>
</Form>
</Col>
<DescriptorEditor
uploadEnabled
editorState={editorState}
onEditorStateChange={(newEditorState) => {
const previousHTML = draftJSEditorStateToHtml(editorState);
const newHTML = draftJSEditorStateToHtml(newEditorState);
if (newHTML !== previousHTML) {
onChange(
"text",
draftJSEditorStateToHtml(newEditorState)
);
setEditorState(newEditorState);
}
}}
// Array of custom or built in fonts can be set via props
// fonts={["Arial", "Impact", "Roman"]}
/>
</div>
);
}
export default TextOptions;