1
- import { ComponentProps , DisplayComponent , FSComponent , Subscribable , UUID , VNode } from "@microsoft/msfs-sdk"
1
+ import {
2
+ ComponentProps ,
3
+ DisplayComponent ,
4
+ FSComponent ,
5
+ Subscribable ,
6
+ SubscribableUtils ,
7
+ UUID ,
8
+ VNode ,
9
+ } from "@microsoft/msfs-sdk"
10
+ import { InterfaceNavbarItemV2 } from "./Utils"
2
11
3
12
interface InputProps extends ComponentProps {
4
- value ?: string
13
+ value : Subscribable < string >
14
+ setValue : ( value : string ) => void
15
+ default ?: Subscribable < string > | string
5
16
class ?: string | Subscribable < string >
6
17
textarea ?: boolean
7
18
}
@@ -10,13 +21,16 @@ export class Input extends DisplayComponent<InputProps> {
10
21
private readonly inputId = UUID . GenerateUuid ( )
11
22
private readonly inputRef = FSComponent . createRef < HTMLInputElement > ( )
12
23
13
- get value ( ) {
14
- return this . inputRef . instance . value
15
- }
16
-
17
24
onAfterRender ( node : VNode ) : void {
18
25
super . onAfterRender ( node )
19
26
27
+ this . props . value . map ( val => ( this . inputRef . instance . value = val ) )
28
+ SubscribableUtils . toSubscribable ( this . props . default ?? "" , true ) . map ( val => {
29
+ this . inputRef . instance . placeholder = val
30
+ } )
31
+
32
+ this . inputRef . instance . addEventListener ( "input" , ( ) => this . props . setValue ( this . inputRef . instance . value ?? "" ) )
33
+
20
34
this . inputRef . instance . onfocus = this . onInputFocus
21
35
this . inputRef . instance . onblur = this . onInputBlur
22
36
}
@@ -54,3 +68,34 @@ export class Input extends DisplayComponent<InputProps> {
54
68
return < input ref = { this . inputRef } { ...this . getInputProps ( ) } />
55
69
}
56
70
}
71
+
72
+ interface CheckboxProps extends ComponentProps {
73
+ value : Subscribable < string >
74
+ setValue : ( value : string ) => void
75
+ default ?: Subscribable < string > | string
76
+ class ?: string
77
+ }
78
+
79
+ export class Checkbox extends DisplayComponent < CheckboxProps > {
80
+ private readonly isActive = this . props . value . map ( val => ( val == "true" ? true : false ) )
81
+
82
+ private onClick = ( ) => {
83
+ this . props . setValue ( this . isActive . get ( ) ? "false" : "true" )
84
+ }
85
+
86
+ render ( ) : VNode {
87
+ return (
88
+ < InterfaceNavbarItemV2
89
+ content = { "" }
90
+ active = { this . isActive }
91
+ class = { `h-full flex-grow bg-white text-black flex items-center justify-center hover:bg-gray-400 ${
92
+ this . props . class ?? ""
93
+ } `}
94
+ activeClass = "hover:!bg-green-700 !bg-green-500 !text-white"
95
+ setActive = { ( ) => this . onClick ( ) }
96
+ >
97
+ < span class = "text-4xl" > { this . isActive . map ( val => ( val ? "✔" : "X" ) ) } </ span >
98
+ </ InterfaceNavbarItemV2 >
99
+ )
100
+ }
101
+ }
0 commit comments