1
- /* eslint-disable jsx-a11y/label-has-associated-control */
2
1
import React from 'react' ;
3
- import { LinkControlProps , ControlStyles , DropDownStyle , Node } from '../../../FrontendTypes' ;
4
2
5
- // Font size of the Controls label and Dropdowns
6
- const controlStyles : ControlStyles = {
7
- padding : '10px' ,
8
- } ;
9
-
10
- const dropDownStyle : DropDownStyle = {
11
- margin : '0.1em' ,
12
- fontFamily : 'Roboto, sans-serif' ,
13
- borderRadius : '4px' ,
14
- borderStyle : 'solid' ,
15
- borderWidth : '1px' ,
16
- backgroundColor : '#d9d9d9' ,
17
- color : '#161617' ,
18
- padding : '2px' ,
19
- } ;
20
-
21
- // use BFS to put all the nodes under snapShots(which is the tree node) into an array
22
- const nodeList : Node [ ] = [ ] ;
23
-
24
- const collectNodes = ( node : Node ) : void => {
25
- nodeList . splice ( 0 , nodeList . length ) ;
26
- /* We used the .splice method here to ensure that nodeList
27
- did not accumulate with page refreshes */
28
- nodeList . push ( node ) ;
29
- for ( let i = 0 ; i < nodeList . length ; i += 1 ) {
30
- const cur = nodeList [ i ] ;
31
- if ( cur . children ?. length > 0 ) {
32
- cur . children . forEach ( ( child ) => nodeList . push ( child ) ) ;
3
+ const LinkControls = ( {
4
+ linkType,
5
+ stepPercent,
6
+ setOrientation,
7
+ setLinkType,
8
+ setStepPercent,
9
+ setSelectedNode,
10
+ snapShots,
11
+ } ) => {
12
+ const collectNodes = ( node ) => {
13
+ const nodeList = [ ] ;
14
+ nodeList . push ( node ) ;
15
+ for ( let i = 0 ; i < nodeList . length ; i += 1 ) {
16
+ const cur = nodeList [ i ] ;
17
+ if ( cur . children ?. length > 0 ) {
18
+ cur . children . forEach ( ( child ) => nodeList . push ( child ) ) ;
19
+ }
33
20
}
34
- }
35
- } ;
21
+ return nodeList ;
22
+ } ;
36
23
37
- export default function LinkControls ( {
38
- linkType, // from linkType local state (initially 'vertical') in 'ComponentMap'
39
- stepPercent, // from stepPercent local state (initially '0.5') in 'ComponentMap'
40
- setOrientation, // from the orientation local state in 'ComponentMap'
41
- setLinkType, // from the linkType local state in 'ComponentMap'
42
- setStepPercent, // from the stepPercent local state in 'ComponentMap'
43
- setSelectedNode, // from the selectedNode local state in 'ComponentMap'
44
- snapShots,
45
- } : LinkControlProps ) : JSX . Element {
46
- collectNodes ( snapShots ) ;
24
+ const nodeList = collectNodes ( snapShots ) ;
47
25
48
26
return (
49
- < div className = 'comp-map-options' style = { controlStyles } >
50
- { ' ' }
51
- { /* This is a non-breaking space - Prevents an automatic line break at this position */ }
52
-
53
- < label > Orientation:</ label > { ' ' }
54
- { /* Toggle record button to pause state changes on target application */ }
55
- { /* Controls for the Orientation selection */ }
56
-
57
- < select
58
- onClick = { ( e ) => e . stopPropagation ( ) }
59
- onChange = { ( e ) => setOrientation ( e . target . value ) }
60
- style = { dropDownStyle }
61
- >
62
- < option value = 'vertical' > Vertical</ option >
63
- < option value = 'horizontal' > Horizontal</ option >
64
- </ select >
65
-
66
- < label > Link:</ label > { /* Controls for the link selections. */ }
67
-
68
- < select
69
- onClick = { ( e ) => e . stopPropagation ( ) }
70
- onChange = { ( e ) => setLinkType ( e . target . value ) }
71
- style = { dropDownStyle }
72
- >
73
- < option value = 'step' > Step</ option >
74
- < option value = 'diagonal' > Diagonal</ option >
75
- < option value = 'line' > Line</ option >
76
- </ select >
77
- < label > Select:</ label > { /* Controls for the select selections. */ }
78
-
79
- < select
80
- id = 'selectInput'
81
- name = 'nodeOptions'
82
- onChange = { ( e ) => setSelectedNode ( e . target . value ) }
83
- style = { dropDownStyle }
84
- >
85
- { nodeList . map (
86
- ( node ) =>
87
- node . children . length > 0 && (
27
+ < div className = 'link-controls' >
28
+ < div className = 'control-group' >
29
+ < label className = 'control-label' > Orientation:</ label >
30
+ < select
31
+ onClick = { ( e ) => e . stopPropagation ( ) }
32
+ onChange = { ( e ) => setOrientation ( e . target . value ) }
33
+ className = 'control-select'
34
+ >
35
+ < option value = 'vertical' > Vertical</ option >
36
+ < option value = 'horizontal' > Horizontal</ option >
37
+ </ select >
38
+ </ div >
39
+
40
+ < div className = 'control-group' >
41
+ < label className = 'control-label' > Link:</ label >
42
+ < select
43
+ onClick = { ( e ) => e . stopPropagation ( ) }
44
+ onChange = { ( e ) => setLinkType ( e . target . value ) }
45
+ className = 'control-select'
46
+ >
47
+ < option value = 'step' > Step</ option >
48
+ < option value = 'diagonal' > Diagonal</ option >
49
+ < option value = 'line' > Line</ option >
50
+ </ select >
51
+ </ div >
52
+
53
+ < div className = 'control-group' >
54
+ < label className = 'control-label' > Select:</ label >
55
+ < select
56
+ id = 'selectInput'
57
+ name = 'nodeOptions'
58
+ onChange = { ( e ) => setSelectedNode ( e . target . value ) }
59
+ className = 'control-select'
60
+ >
61
+ { nodeList . map ( ( node ) =>
62
+ node . children . length > 0 ? (
88
63
< option key = { node . name } value = { node . name } >
89
64
{ node . name }
90
65
</ option >
91
- ) ,
92
- ) }
93
- </ select >
94
- { /* This is the slider control for the step option */ }
66
+ ) : null ,
67
+ ) }
68
+ </ select >
69
+ </ div >
70
+
95
71
{ linkType === 'step' && (
96
- < >
97
-
98
- < label > Step:</ label >
99
-
72
+ < div className = 'control-group' >
73
+ < label className = 'control-label' > Step:</ label >
100
74
< input
101
75
onClick = { ( e ) => e . stopPropagation ( ) }
102
76
type = 'range'
@@ -106,9 +80,12 @@ export default function LinkControls({
106
80
onChange = { ( e ) => setStepPercent ( Number ( e . target . value ) ) }
107
81
value = { stepPercent }
108
82
disabled = { linkType !== 'step' }
83
+ className = 'control-range'
109
84
/>
110
- </ >
85
+ </ div >
111
86
) }
112
87
</ div >
113
88
) ;
114
- }
89
+ } ;
90
+
91
+ export default LinkControls ;
0 commit comments