@@ -4,6 +4,7 @@ import { Classes as BlueprintClassNames } from "@blueprintjs/core";
44import { EditorView , Rect } from "@codemirror/view" ;
55import { debounce } from "lodash" ;
66
7+ import { IntentTypes } from "../../common/Intent" ;
78import { CLASSPREFIX as eccgui } from "../../configuration/constants" ;
89import { SupportedCodeEditorModes } from "../../extensions/codemirror/hooks/useCodemirrorModeExtension.hooks" ;
910
@@ -154,6 +155,8 @@ export interface CodeAutocompleteFieldProps {
154155 readOnly ?: boolean ;
155156 /** Properties that should be added to the outer div container. */
156157 outerDivAttributes ?: Omit < React . HTMLAttributes < HTMLDivElement > , "id" | "data-test-id" > ;
158+ /** Intent state of the input field. Validation errors override this. */
159+ intent ?: IntentTypes ;
157160}
158161
159162// Meta data regarding a request
@@ -192,6 +195,7 @@ export const CodeAutocompleteField = ({
192195 height,
193196 readOnly,
194197 outerDivAttributes,
198+ intent,
195199} : CodeAutocompleteFieldProps ) => {
196200 const value = React . useRef < string > ( initialValue ) ;
197201 const cursorPosition = React . useRef ( 0 ) ;
@@ -630,6 +634,12 @@ export const CodeAutocompleteField = ({
630634 [ ]
631635 ) ;
632636
637+ const hasError = ! ! value . current && ! pathIsValid && ! pathValidationPending ;
638+ const effectiveIntent = hasError ? "danger" : intent ;
639+ const blueprintIntent =
640+ effectiveIntent && ! [ "info" , "accent" , "neutral" ] . includes ( effectiveIntent ) ? effectiveIntent : undefined ;
641+ const inputIntentClass = effectiveIntent ? ` ${ eccgui } -intent--${ effectiveIntent } ` : "" ;
642+
633643 const codeEditor = React . useMemo ( ( ) => {
634644 return (
635645 < ExtendedCodeEditor
@@ -661,9 +671,8 @@ export const CodeAutocompleteField = ({
661671 multiline ,
662672 handleInputMouseDown ,
663673 readOnly ,
674+ effectiveIntent ,
664675 ] ) ;
665-
666- const hasError = ! ! value . current && ! pathIsValid && ! pathValidationPending ;
667676 const autoSuggestionInput = (
668677 < div
669678 id = { id }
@@ -674,7 +683,7 @@ export const CodeAutocompleteField = ({
674683 < div
675684 className = { ` ${ eccgui } -autosuggestion__inputfield ${ BlueprintClassNames . INPUT_GROUP } ${
676685 BlueprintClassNames . FILL
677- } ${ hasError ? BlueprintClassNames . INTENT_DANGER : "" } `}
686+ } ${ blueprintIntent ? BlueprintClassNames . intentClass ( blueprintIntent as any ) : "" } ${ inputIntentClass } `}
678687 >
679688 < ContextOverlay
680689 minimal
@@ -734,13 +743,11 @@ export const CodeAutocompleteField = ({
734743 < >
735744 { label }
736745
737- { ( pathValidationPending || suggestionsPending ) && (
738- < Spinner size = "tiny" position = "inline" />
739- ) }
746+ { ( pathValidationPending || suggestionsPending ) && < Spinner size = "tiny" position = "inline" /> }
740747 </ >
741748 ) ,
742749 } }
743- intent = { hasError ? "danger" : undefined }
750+ intent = { effectiveIntent }
744751 messageText = { hasError ? validationErrorText : undefined }
745752 >
746753 { withRightElement }
0 commit comments