11import React , { PureComponent } from 'react' ;
22import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
3- import { vsSearch } from '@deephaven/icons' ;
3+ import { vsArrowLeft , vsArrowRight , vsSearch } from '@deephaven/icons' ;
44import classNames from 'classnames' ;
5+ import Button from './Button' ;
56import './SearchInput.scss' ;
67
8+ interface QueryParams {
9+ queriedColumnIndex : number | undefined ;
10+ changeQueriedColumnIndex : ( direction : 'forward' | 'back' ) => void ;
11+ }
712interface SearchInputProps {
813 value : string ;
914 placeholder : string ;
@@ -15,6 +20,7 @@ interface SearchInputProps {
1520 matchCount : number ;
1621 id : string ;
1722 'data-testid' ?: string ;
23+ queryParams ?: QueryParams ;
1824}
1925
2026class SearchInput extends PureComponent < SearchInputProps > {
@@ -27,19 +33,40 @@ class SearchInput extends PureComponent<SearchInputProps> {
2733 } ,
2834 id : '' ,
2935 'data-testid' : undefined ,
36+ queryParams : undefined ,
3037 } ;
3138
3239 constructor ( props : SearchInputProps ) {
3340 super ( props ) ;
3441 this . inputField = React . createRef ( ) ;
42+ this . searchChangeSelection = React . createRef ( ) ;
3543 }
3644
37- inputField : React . RefObject < HTMLInputElement > ;
45+ componentDidMount ( ) : void {
46+ this . setInputPaddingRight ( ) ;
47+ }
48+
49+ componentDidUpdate ( ) : void {
50+ this . setInputPaddingRight ( ) ;
51+ }
3852
3953 focus ( ) : void {
4054 this . inputField . current ?. focus ( ) ;
4155 }
4256
57+ inputField : React . RefObject < HTMLInputElement > ;
58+
59+ searchChangeSelection : React . RefObject < HTMLDivElement > ;
60+
61+ setInputPaddingRight ( ) : void {
62+ const inputField = this . inputField . current ;
63+ const searchChangeSelection = this . searchChangeSelection . current ;
64+ if ( inputField && searchChangeSelection ) {
65+ const paddingRight = searchChangeSelection . getBoundingClientRect ( ) . width ;
66+ inputField . style . paddingRight = `${ paddingRight } px` ;
67+ }
68+ }
69+
4370 render ( ) : JSX . Element {
4471 const {
4572 value,
@@ -52,7 +79,47 @@ class SearchInput extends PureComponent<SearchInputProps> {
5279 id,
5380 onKeyDown,
5481 'data-testid' : dataTestId ,
82+ queryParams,
5583 } = this . props ;
84+
85+ let matchCountSection ;
86+
87+ if ( queryParams && matchCount > 1 ) {
88+ matchCountSection = (
89+ < >
90+ < Button
91+ kind = "ghost"
92+ className = "search-change-button"
93+ type = "button"
94+ onClick = { ( ) => {
95+ queryParams . changeQueriedColumnIndex ( 'back' ) ;
96+ } }
97+ icon = { vsArrowLeft }
98+ tooltip = "Next match"
99+ />
100+ < span className = "search-change-text" >
101+ { queryParams . queriedColumnIndex !== undefined &&
102+ `${ queryParams . queriedColumnIndex + 1 } of ` }
103+ { matchCount }
104+ </ span >
105+ < Button
106+ kind = "ghost"
107+ className = "search-change-button"
108+ type = "button"
109+ onClick = { ( ) => {
110+ queryParams . changeQueriedColumnIndex ( 'forward' ) ;
111+ } }
112+ icon = { vsArrowRight }
113+ tooltip = "Next match"
114+ />
115+ </ >
116+ ) ;
117+ } else {
118+ matchCountSection = matchCount > 0 && (
119+ < span className = "match_count" > { matchCount } </ span >
120+ ) ;
121+ }
122+
56123 return (
57124 < div className = { classNames ( 'search-group' , className ) } >
58125 < input
@@ -68,12 +135,19 @@ class SearchInput extends PureComponent<SearchInputProps> {
68135 id = { id }
69136 data-testid = { dataTestId }
70137 />
71- { matchCount != null && (
72- < span className = "search-match" > { matchCount } </ span >
138+
139+ { matchCount != null ? (
140+ < div
141+ className = "search-change-selection"
142+ ref = { this . searchChangeSelection }
143+ >
144+ { matchCountSection }
145+ </ div >
146+ ) : (
147+ < span className = "search-icon" >
148+ < FontAwesomeIcon icon = { vsSearch } />
149+ </ span >
73150 ) }
74- < span className = "search-icon" >
75- < FontAwesomeIcon icon = { vsSearch } />
76- </ span >
77151 </ div >
78152 ) ;
79153 }
0 commit comments