mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 06:19:05 +08:00
feat(CodeEditor): enable readOnly for CodeEditor (v2) (#10517)
* feat(CodeEditor): enable readOnly for CodeEditor (v2) * docs: update prop comments
This commit is contained in:
parent
a6e58776d2
commit
de5fb03efb
@ -31,6 +31,7 @@ const CodeEditor = ({
|
|||||||
style,
|
style,
|
||||||
className,
|
className,
|
||||||
editable = true,
|
editable = true,
|
||||||
|
readOnly = false,
|
||||||
expanded = true,
|
expanded = true,
|
||||||
wrapped = true
|
wrapped = true
|
||||||
}: CodeEditorProps) => {
|
}: CodeEditorProps) => {
|
||||||
@ -111,6 +112,7 @@ const CodeEditor = ({
|
|||||||
maxHeight={expanded ? undefined : maxHeight}
|
maxHeight={expanded ? undefined : maxHeight}
|
||||||
minHeight={minHeight}
|
minHeight={minHeight}
|
||||||
editable={editable}
|
editable={editable}
|
||||||
|
readOnly={readOnly}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
extensions={customExtensions}
|
extensions={customExtensions}
|
||||||
onCreateEditor={(view: EditorView) => {
|
onCreateEditor={(view: EditorView) => {
|
||||||
|
|||||||
@ -91,10 +91,15 @@ export interface CodeEditorProps {
|
|||||||
/** CSS class name appended to the default `code-editor` class. */
|
/** CSS class name appended to the default `code-editor` class. */
|
||||||
className?: string
|
className?: string
|
||||||
/**
|
/**
|
||||||
* Whether the editor is editable.
|
* Whether the editor view is editable.
|
||||||
* @default true
|
* @default true
|
||||||
*/
|
*/
|
||||||
editable?: boolean
|
editable?: boolean
|
||||||
|
/**
|
||||||
|
* Set the editor state to read only but keep some user interactions, e.g., keymaps.
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
readOnly?: boolean
|
||||||
/**
|
/**
|
||||||
* Whether the editor is expanded.
|
* Whether the editor is expanded.
|
||||||
* If true, the height and maxHeight props are ignored.
|
* If true, the height and maxHeight props are ignored.
|
||||||
|
|||||||
@ -66,6 +66,7 @@ const meta: Meta<typeof CodeEditor> = {
|
|||||||
},
|
},
|
||||||
fontSize: { control: { type: 'range', min: 12, max: 22, step: 1 } },
|
fontSize: { control: { type: 'range', min: 12, max: 22, step: 1 } },
|
||||||
editable: { control: 'boolean' },
|
editable: { control: 'boolean' },
|
||||||
|
readOnly: { control: 'boolean' },
|
||||||
expanded: { control: 'boolean' },
|
expanded: { control: 'boolean' },
|
||||||
wrapped: { control: 'boolean' },
|
wrapped: { control: 'boolean' },
|
||||||
height: { control: 'text' },
|
height: { control: 'text' },
|
||||||
@ -89,6 +90,7 @@ export const Default: Story = {
|
|||||||
value: `function greet(name: string) {\n return 'Hello ' + name\n}`,
|
value: `function greet(name: string) {\n return 'Hello ' + name\n}`,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
editable: true,
|
editable: true,
|
||||||
|
readOnly: false,
|
||||||
expanded: true,
|
expanded: true,
|
||||||
wrapped: true
|
wrapped: true
|
||||||
},
|
},
|
||||||
@ -101,6 +103,7 @@ export const Default: Story = {
|
|||||||
theme={getCmThemeByName((args as any).theme || 'light')}
|
theme={getCmThemeByName((args as any).theme || 'light')}
|
||||||
fontSize={args.fontSize as number}
|
fontSize={args.fontSize as number}
|
||||||
editable={args.editable as boolean}
|
editable={args.editable as boolean}
|
||||||
|
readOnly={args.readOnly as boolean}
|
||||||
expanded={args.expanded as boolean}
|
expanded={args.expanded as boolean}
|
||||||
wrapped={args.wrapped as boolean}
|
wrapped={args.wrapped as boolean}
|
||||||
height={args.height as string | undefined}
|
height={args.height as string | undefined}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user