-
Notifications
You must be signed in to change notification settings - Fork 885
[EuiMarkdownEditor] Add readOnly prop
#5627
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
Changes from 20 commits
bf09b65
7c14d7c
6b623c0
1982f97
68f589b
e1c1bca
1a2bead
7dbe54d
23d70ed
2b4b314
9cf3408
5bf9372
4025a6d
53478ee
1cd7fde
0bc46e6
d0b553b
5b2d50a
cd2e9c6
f9312e0
b73a006
575a6fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,9 @@ import { | |
| EuiSpacer, | ||
| EuiCodeBlock, | ||
| EuiButton, | ||
| EuiSwitch, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| } from '../../../../src/components'; | ||
|
|
||
| const initialContent = `## Hello world! | ||
|
|
@@ -16,6 +19,10 @@ The editor also ships with some built in plugins. For example it can handle chec | |
| - [ ] Checkboxes | ||
| - [x] Can be filled | ||
| - [ ] Or empty | ||
|
|
||
| It can also handle emojis! :smile: | ||
|
|
||
| And it can render !{tooltip[tooltips like this](Look! I'm a very helpful tooltip content!)} | ||
| `; | ||
|
|
||
| const dropHandlers = [ | ||
|
|
@@ -46,6 +53,13 @@ export default () => { | |
| setMessages(err ? [err] : messages); | ||
| setAst(JSON.stringify(ast, null, 2)); | ||
| }, []); | ||
|
|
||
| const [isReadOnly, setIsReadOnly] = useState(false); | ||
|
|
||
| const onChange = (e) => { | ||
| setIsReadOnly(e.target.checked); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <EuiMarkdownEditor | ||
|
|
@@ -57,18 +71,32 @@ export default () => { | |
| onParse={onParse} | ||
| errors={messages} | ||
| dropHandlers={dropHandlers} | ||
| readOnly={isReadOnly} | ||
| initialViewMode="viewing" | ||
| /> | ||
| <EuiSpacer size="s" /> | ||
| <div className="eui-textRight"> | ||
| <EuiButton | ||
| size="s" | ||
| iconType={isAstShowing ? 'eyeClosed' : 'eye'} | ||
| onClick={() => setIsAstShowing(!isAstShowing)} | ||
| fill={isAstShowing} | ||
| > | ||
| {isAstShowing ? 'Hide editor AST' : 'Show editor AST'} | ||
| </EuiButton> | ||
| </div> | ||
| <EuiFlexGroup alignItems="center"> | ||
| <EuiFlexItem grow={true}> | ||
| <EuiSwitch | ||
| label="Read-only" | ||
| checked={isReadOnly} | ||
| onChange={onChange} | ||
| /> | ||
| </EuiFlexItem> | ||
|
Comment on lines
+79
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I highly suggest adding a sentence about the use of this prop to the text of this example. Maybe explaining, that if the consumer needs to disallow editing while submission is happening, then they should manually update this prop.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like it! I just have a quick suggestion to tighten up the language. |
||
| <EuiFlexItem grow={false}> | ||
| <EuiButton | ||
| size="s" | ||
| iconType={isAstShowing ? 'eyeClosed' : 'eye'} | ||
| onClick={() => setIsAstShowing(!isAstShowing)} | ||
| fill={isAstShowing} | ||
| > | ||
| {isAstShowing ? 'Hide editor AST' : 'Show editor AST'} | ||
| </EuiButton> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
|
|
||
| <EuiSpacer size="s" /> | ||
|
|
||
| {isAstShowing && <EuiCodeBlock language="json">{ast}</EuiCodeBlock>} | ||
| </> | ||
| ); | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.