@@ -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,14 @@ 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 )
641+ ? effectiveIntent
642+ : undefined ;
643+ const inputIntentClass = effectiveIntent ? ` ${ eccgui } -intent--${ effectiveIntent } ` : "" ;
644+
633645 const codeEditor = React . useMemo ( ( ) => {
634646 return (
635647 < ExtendedCodeEditor
@@ -648,6 +660,9 @@ export const CodeAutocompleteField = ({
648660 onMouseDown = { handleInputMouseDown }
649661 height = { height }
650662 readOnly = { readOnly }
663+ codeEditorProps = { {
664+ intent : effectiveIntent ,
665+ } }
651666 />
652667 ) ;
653668 } , [
@@ -661,9 +676,8 @@ export const CodeAutocompleteField = ({
661676 multiline ,
662677 handleInputMouseDown ,
663678 readOnly ,
679+ effectiveIntent ,
664680 ] ) ;
665-
666- const hasError = ! ! value . current && ! pathIsValid && ! pathValidationPending ;
667681 const autoSuggestionInput = (
668682 < div
669683 id = { id }
@@ -674,7 +688,7 @@ export const CodeAutocompleteField = ({
674688 < div
675689 className = { ` ${ eccgui } -autosuggestion__inputfield ${ BlueprintClassNames . INPUT_GROUP } ${
676690 BlueprintClassNames . FILL
677- } ${ hasError ? BlueprintClassNames . INTENT_DANGER : "" } `}
691+ } ${ blueprintIntent ? BlueprintClassNames . intentClass ( blueprintIntent as any ) : "" } ${ inputIntentClass } `}
678692 >
679693 < ContextOverlay
680694 minimal
@@ -740,7 +754,7 @@ export const CodeAutocompleteField = ({
740754 </ >
741755 ) ,
742756 } }
743- intent = { hasError ? "danger" : undefined }
757+ intent = { effectiveIntent }
744758 messageText = { hasError ? validationErrorText : undefined }
745759 >
746760 { withRightElement }
0 commit comments