Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add readOnly prop #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/constants/editor/create_quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const create_quill = ({
theme,
customFonts = [],
customJS,
readOnly = false,
}: {
id: string;
toolbar: 'false' | string;
Expand All @@ -16,6 +17,7 @@ export const create_quill = ({
theme: 'snow' | 'bubble';
customFonts: Array<string>;
customJS: string;
readOnly?: boolean;
}) => {
let font = '';
if (customFonts.length > 0) {
Expand Down Expand Up @@ -46,7 +48,8 @@ export const create_quill = ({
var quill = new Quill('#${id}', {
modules: { ${modules} },
placeholder: '${placeholder}',
theme: '${theme}'
theme: '${theme}',
readOnly: ${readOnly}
});
</script>
`;
Expand Down
2 changes: 2 additions & 0 deletions src/editor/quill-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export default class QuillEditor extends React.Component<
toolbar: false,
},
theme: 'snow',
readOnly: false,
},
customFonts = [],
customStyles = [],
Expand All @@ -146,6 +147,7 @@ export default class QuillEditor extends React.Component<
clipboard: quill.modules?.clipboard,
keyboard: quill.modules?.keyboard,
libraries: import3rdParties,
readOnly: quill.readOnly,
editorId: quill.id ? quill.id : 'editor-container',
defaultFontFamily,
containerId,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export interface QuillConfig {
};
theme?: 'snow' | 'bubble';
placeholder: string;
readOnly?: boolean;
}

export type StyleFunc = (provided: object) => object;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/editor-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface CreateHtmlArgs {
fonts: Array<CustomFont>;
defaultFontFamily?: string;
customJS?: string;
readOnly?: boolean;
}

const Inital_Args = {
Expand All @@ -49,6 +50,7 @@ const Inital_Args = {
customStyles: [],
fonts: [],
customJS: '',
readOnly: false,
} as CreateHtmlArgs;

export const createHtml = (args: CreateHtmlArgs = Inital_Args) => {
Expand Down Expand Up @@ -101,6 +103,7 @@ export const createHtml = (args: CreateHtmlArgs = Inital_Args) => {
theme: args.theme,
customFonts: args.fonts.map((f) => getFontName(f.name)),
customJS: args.customJS ? args.customJS : '',
readOnly: args.readOnly,
})}
${editor_js}
</body>
Expand Down