Skip to content

Commit 4ecc0a7

Browse files
committed
fix disabled and readOnly states for CodeEditor toolbar
1 parent 4820df9 commit 4ecc0a7

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/extensions/codemirror/CodeMirror.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ BasicExample.args = {
2929
defaultValue: "**test me**",
3030
useToolbar: true,
3131
disabled: false,
32+
readOnly: true,
3233
};
3334

3435
export const LinterExample = TemplateFull.bind({});

src/extensions/codemirror/CodeMirror.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ export const CodeEditor = ({
389389
togglePreviewStatus={() => setShowPreview((p) => !p)}
390390
showPreview={showPreview}
391391
translate={getTranslation}
392+
disabled={disabled}
393+
readonly={readOnly}
392394
/>
393395
</div>
394396
{showPreview && (

src/extensions/codemirror/toolbars/markdown.toolbar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ interface MarkdownToolbarProps {
1515
togglePreviewStatus: () => void;
1616
showPreview: boolean;
1717
translate: (key: string) => string | false;
18+
disabled?: boolean;
19+
readonly?: boolean;
1820
}
1921

2022
export const MarkdownToolbar: React.FC<MarkdownToolbarProps> = ({
2123
view,
2224
togglePreviewStatus,
2325
showPreview,
26+
disabled,
27+
readonly,
2428
translate
2529
}) => {
2630
const commandRef = React.useRef<MarkdownCommand | null>(null);
@@ -48,7 +52,7 @@ export const MarkdownToolbar: React.FC<MarkdownToolbarProps> = ({
4852
minimal
4953
fill
5054
ellipsizeText
51-
disabled={showPreview}
55+
disabled={showPreview || disabled || readonly}
5256
/>
5357
}
5458
>
@@ -82,7 +86,7 @@ export const MarkdownToolbar: React.FC<MarkdownToolbarProps> = ({
8286
name={command.icon}
8387
onClick={() => commandRef.current?.executeCommand(command.title)}
8488
text={getTranslation(command.title)}
85-
disabled={showPreview}
89+
disabled={showPreview || disabled || readonly}
8690
/>
8791
);
8892
})}
@@ -105,6 +109,7 @@ export const MarkdownToolbar: React.FC<MarkdownToolbarProps> = ({
105109
onClick={togglePreviewStatus}
106110
text={showPreview ? getTranslation("Continue editing") : getTranslation("Preview")}
107111
icon={showPreview ? "item-edit" : "item-viewdetails"}
112+
disabled={disabled}
108113
/>
109114
</ToolbarSection>
110115
</Toolbar>

0 commit comments

Comments
 (0)