From b6b0e6134c18c2f7d7d508d68dad61ac9ba65d0a Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Thu, 9 Nov 2017 09:22:48 -0800 Subject: [PATCH 01/18] [UI Framework] Add isReadOnly prop to KuiCodeEditor. (#14804) * Add isReadOnly prop to KuiCodeEditor. * Place cursor at beginning of code editor if it's read-only. * Surface prompt for isReadOnly mode. Only show cursor when the editor is focused. --- ui_framework/dist/ui_framework.css | 4 + .../views/code_editor/code_editor_example.js | 15 ++ .../src/views/code_editor/read_only.js | 27 +++ .../__snapshots__/code_editor.test.js.snap | 170 +++++++++++++++++- .../components/code_editor/_code_editor.scss | 10 ++ .../src/components/code_editor/code_editor.js | 106 ++++++++--- .../code_editor/code_editor.test.js | 81 +++++---- 7 files changed, 346 insertions(+), 67 deletions(-) create mode 100644 ui_framework/doc_site/src/views/code_editor/read_only.js diff --git a/ui_framework/dist/ui_framework.css b/ui_framework/dist/ui_framework.css index bd4e82c6b101d..a926f5382fb9b 100644 --- a/ui_framework/dist/ui_framework.css +++ b/ui_framework/dist/ui_framework.css @@ -688,6 +688,10 @@ input[type="button"] { .kuiCodeEditorWrapper { position: relative; } + .kuiCodeEditorWrapper .ace_hidden-cursors { + opacity: 0; } + .kuiCodeEditorWrapper.kuiCodeEditorWrapper-isEditing .ace_hidden-cursors { + opacity: 1; } .kuiCodeEditorKeyboardHint { position: absolute; diff --git a/ui_framework/doc_site/src/views/code_editor/code_editor_example.js b/ui_framework/doc_site/src/views/code_editor/code_editor_example.js index 35afd30f04473..e8af21a45ceb4 100644 --- a/ui_framework/doc_site/src/views/code_editor/code_editor_example.js +++ b/ui_framework/doc_site/src/views/code_editor/code_editor_example.js @@ -11,6 +11,9 @@ import { import CodeEditor from './code_editor'; const codeEditorSource = require('!!raw-loader!./code_editor'); +import ReadOnly from './read_only'; +const readOnlySource = require('!!raw-loader!./read_only'); + export default props => ( ( + + + + + + ); diff --git a/ui_framework/doc_site/src/views/code_editor/read_only.js b/ui_framework/doc_site/src/views/code_editor/read_only.js new file mode 100644 index 0000000000000..5c455e5e89a60 --- /dev/null +++ b/ui_framework/doc_site/src/views/code_editor/read_only.js @@ -0,0 +1,27 @@ +import React, { Component } from 'react'; + +import 'brace/mode/less'; +import 'brace/theme/github'; + +import { + KuiCodeEditor +} from '../../../../components'; + +export default class extends Component { + state = { + value: '

This code is read only

' + }; + + render() { + return ( + + ); + } +} diff --git a/ui_framework/src/components/code_editor/__snapshots__/code_editor.test.js.snap b/ui_framework/src/components/code_editor/__snapshots__/code_editor.test.js.snap index c4faf3450cac8..971c88b219d5f 100644 --- a/ui_framework/src/components/code_editor/__snapshots__/code_editor.test.js.snap +++ b/ui_framework/src/components/code_editor/__snapshots__/code_editor.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`KuiCodeEditor hint element should be disabled when the ui ace box gains focus 1`] = ` +exports[`KuiCodeEditor behavior hint element should be disabled when the ui ace box gains focus 1`] = `
- Press Enter to start editing. + Press Enter to start + editing + .

- When you’re done, press Escape to stop editing. + When you’re done, press Escape to stop + editing + .

`; -exports[`KuiCodeEditor hint element should be enabled when the ui ace box loses focus 1`] = ` +exports[`KuiCodeEditor behavior hint element should be enabled when the ui ace box loses focus 1`] = `
- Press Enter to start editing. + Press Enter to start + editing + .

- When you’re done, press Escape to stop editing. + When you’re done, press Escape to stop + editing + .

`; @@ -60,12 +68,28 @@ exports[`KuiCodeEditor is rendered 1`] = `

- Press Enter to start editing. + + Press Enter to start + + + editing + + + . +

- When you’re done, press Escape to stop editing. + + When you’re done, press Escape to stop + + + editing + + + . +

`; + +exports[`KuiCodeEditor props isReadOnly renders alternate hint text 1`] = ` +
+
+

+ + Press Enter to start + + + interacting with the code + + + . + +

+

+ + When you’re done, press Escape to stop + + + interacting with the code + + + . + +

+
+
+