Skip to content

Commit 6444526

Browse files
committed
Update RichText component to use forwarding & add theme prop
1 parent ec032b4 commit 6444526

File tree

10 files changed

+61
-27
lines changed

10 files changed

+61
-27
lines changed

dist/components/form/Form.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ declare const Form: {
1818
({ type, className, ...rest }: import("./components/FormCheck").FormCheckProps): React.JSX.Element;
1919
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;
2020
};
21-
RichText: ({ modules, value, valueChange, ...rest }: import("./components/FormRichText").QuillEditorProps) => React.JSX.Element;
21+
RichText: {
22+
({ theme, modules, value, onChange, ...rest }: import("./components/FormRichText").QuillEditorProps): React.JSX.Element;
23+
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;
24+
};
2225
DateTime: {
2326
({ className, ...rest }: import("./components/FormDateTime").FormDateTimeProps): React.JSX.Element;
2427
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/esm/Feedback").FeedbackProps>;

dist/components/form/Form.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/components/form/components/FormRichText.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ export interface QuillEditorProps {
55
id?: string;
66
modules?: Record<string, unknown>;
77
value?: string;
8-
valueChange?(value: string): any;
8+
theme?: string;
9+
onChange?(value: string): any;
910
}
10-
declare const FormRichText: ({ modules, value, valueChange, ...rest }: QuillEditorProps) => React.JSX.Element;
11+
declare const FormRichText: {
12+
({ theme, modules, value, onChange, ...rest }: QuillEditorProps): React.JSX.Element;
13+
Feedback: import("react-bootstrap/esm/helpers").BsPrefixRefForwardingComponent<"div", import("react-bootstrap/Feedback").FeedbackProps>;
14+
};
1115
export default FormRichText;
1216
//# sourceMappingURL=FormRichText.d.ts.map

dist/components/form/components/FormRichText.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/components/form/components/FormRichText.js

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/components/form/components/FormRichText.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25532,24 +25532,25 @@ Quill.register({
2553225532
}, true);
2553325533

2553425534
var FormRichText = function (_a) {
25535-
var modules = _a.modules, value = _a.value, valueChange = _a.valueChange, rest = __rest(_a, ["modules", "value", "valueChange"]);
25535+
var theme = _a.theme, modules = _a.modules, value = _a.value, onChange = _a.onChange, rest = __rest(_a, ["theme", "modules", "value", "onChange"]);
2553625536
var editorRef = React.useRef(null);
2553725537
var quillRef = React.useRef(null);
25538+
var quillOptions = __assign(__assign({}, modules), { theme: theme || 'snow' });
2553825539
var setValue = function (quillRef) {
2553925540
var delta = quillRef.clipboard.convert({ html: value });
2554025541
quillRef.setContents(delta, 'silent');
2554125542
};
2554225543
var configureListeners = function (quill) {
2554325544
quill.on('text-change', function () {
2554425545
var _a;
25545-
if (valueChange) {
25546-
valueChange(((_a = quillRef.current) === null || _a === void 0 ? void 0 : _a.getSemanticHTML()) || '');
25546+
if (onChange) {
25547+
onChange(((_a = quillRef.current) === null || _a === void 0 ? void 0 : _a.getSemanticHTML()) || '');
2554725548
}
2554825549
});
2554925550
};
2555025551
React.useEffect(function () {
2555125552
if (editorRef.current) {
25552-
var quill = new Quill(editorRef.current, modules);
25553+
var quill = new Quill(editorRef.current, quillOptions);
2555325554
quillRef.current = quill; // Store the Quill instance in a ref
2555425555
if (value) {
2555525556
setValue(quill);
@@ -25559,6 +25560,7 @@ var FormRichText = function (_a) {
2555925560
}, []);
2556025561
return React.createElement("div", { ref: editorRef, style: rest.style, id: rest.id });
2556125562
};
25563+
FormRichText.Feedback = Feedback$1;
2556225564

2556325565
var FormDateTime = function (_a) {
2556425566
var className = _a.className, rest = __rest(_a, ["className"]);

dist/index.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
11
import React, { useRef, CSSProperties, useEffect } from 'react';
22
import Quill from 'quill';
3+
import Feedback from 'react-bootstrap/Feedback';
34

45
export interface QuillEditorProps {
56
className?: string;
67
style?: CSSProperties;
78
id?: string;
89
modules?: Record<string, unknown>;
910
value?: string;
11+
theme?: string;
1012

11-
valueChange?(value: string): any;
13+
onChange?(value: string): any;
1214
}
1315

1416
const FormRichText = ({
17+
theme,
1518
modules,
1619
value,
17-
valueChange,
20+
onChange,
1821
...rest
1922
}: QuillEditorProps) => {
2023
const editorRef = useRef<HTMLDivElement | null>(null);
2124
const quillRef = useRef<Quill | null>(null);
2225

26+
const quillOptions = {
27+
...modules,
28+
theme: theme || 'snow',
29+
};
30+
2331
const setValue = (quillRef: Quill) => {
2432
const delta = quillRef.clipboard.convert({ html: value });
2533
quillRef.setContents(delta, 'silent');
2634
};
2735

2836
const configureListeners = (quill: Quill) => {
2937
quill.on('text-change', () => {
30-
if (valueChange) {
31-
valueChange(quillRef.current?.getSemanticHTML() || '');
38+
if (onChange) {
39+
onChange(quillRef.current?.getSemanticHTML() || '');
3240
}
3341
});
3442
};
3543

3644
useEffect(() => {
3745
if (editorRef.current) {
38-
const quill = new Quill(editorRef.current, modules);
46+
const quill = new Quill(editorRef.current, quillOptions);
3947
quillRef.current = quill; // Store the Quill instance in a ref
4048

4149
if (value) {
@@ -47,4 +55,7 @@ const FormRichText = ({
4755

4856
return <div ref={editorRef} style={rest.style} id={rest.id} />;
4957
};
58+
59+
FormRichText.Feedback = Feedback;
60+
5061
export default FormRichText;

0 commit comments

Comments
 (0)