-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Navigraph/chore/ui-improvements
- Loading branch information
Showing
5 changed files
with
235 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ComponentProps, DisplayComponent, FSComponent, Subscribable, UUID, VNode } from "@microsoft/msfs-sdk" | ||
|
||
interface InputProps extends ComponentProps { | ||
value?: string | ||
class?: string | Subscribable<string> | ||
textarea?: boolean | ||
} | ||
|
||
export class Input extends DisplayComponent<InputProps> { | ||
private readonly inputId = UUID.GenerateUuid() | ||
private readonly inputRef = FSComponent.createRef<HTMLInputElement>() | ||
|
||
get value() { | ||
return this.inputRef.instance.value | ||
} | ||
|
||
onAfterRender(node: VNode): void { | ||
super.onAfterRender(node) | ||
|
||
this.inputRef.instance.onfocus = this.onInputFocus | ||
this.inputRef.instance.onblur = this.onInputBlur | ||
} | ||
|
||
private getInputProps() { | ||
return { value: this.props.value, class: this.props.class } | ||
} | ||
|
||
/** | ||
* Method to handle when input focus is set | ||
* @param e The focus event. | ||
*/ | ||
private onInputFocus = (e: FocusEvent): void => { | ||
e.preventDefault() | ||
|
||
Coherent.trigger("FOCUS_INPUT_FIELD", this.inputId, "", "", this.inputRef.instance.value, false) | ||
Coherent.on("mousePressOutsideView", () => this.inputRef.instance.blur()) | ||
} | ||
|
||
/** | ||
* Method to handle on input blur | ||
*/ | ||
private onInputBlur = (): void => { | ||
Coherent.trigger("UNFOCUS_INPUT_FIELD", "") | ||
Coherent.off("mousePressOutsideView") | ||
} | ||
|
||
render() { | ||
if (this.props.textarea) | ||
return ( | ||
<textarea style="width:350px;height:100px;" ref={this.inputRef} {...this.getInputProps()}> | ||
{this.props.value} | ||
</textarea> | ||
) | ||
return <input ref={this.inputRef} {...this.getInputProps()} /> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
interface CoherentEngine { | ||
/** | ||
* Asynchronously call a C++ handler and retrieve the result | ||
* @param name name of the C++ handler to be called | ||
* @param args any extra parameters to be passed to the C++ handler | ||
* @return promise for the result of the C++ function | ||
*/ | ||
call(name: "PLAY_INSTRUMENT_SOUND", soundName: string): Promise<void> | ||
call(name: string, ...args: unknown[]): Promise<unknown> | ||
|
||
on(name: "SetInputTextFromOS" | "mousePressOutsideView", cb: () => void): void | ||
off(name: "SetInputTextFromOS" | "mousePressOutsideView", cb?: () => void): void | ||
|
||
trigger(name: "FOCUS_INPUT_FIELD" | "UNFOCUS_INPUT_FIELD", ...args: unknown[]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters