Skip to content

Commit 1d43453

Browse files
committed
refactor search input
1 parent 4712199 commit 1d43453

2 files changed

Lines changed: 39 additions & 46 deletions

File tree

packages/components/src/SearchInput.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@
7070
padding: 1px 2px;
7171
}
7272

73-
.search-change-button__hidden {
74-
display: none;
75-
}
76-
7773
.search-change-text {
7874
background-color: rgba($white, 0.2);
7975
border-radius: 10px;

packages/components/src/SearchInput.tsx

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,44 @@ class SearchInput extends PureComponent<SearchInputProps> {
8282
queryParams,
8383
} = this.props;
8484

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+
85123
return (
86124
<div className={classNames('search-group', className)}>
87125
<input
@@ -103,48 +141,7 @@ class SearchInput extends PureComponent<SearchInputProps> {
103141
className="search-change-selection"
104142
ref={this.searchChangeSelection}
105143
>
106-
<Button
107-
kind="ghost"
108-
className={
109-
matchCount <= 1 && queryParams
110-
? 'search-change-button__hidden' // using the disabled prop messes up the paddingRight calculation
111-
: 'search-change-button'
112-
}
113-
type="button"
114-
onClick={() => {
115-
if (queryParams) {
116-
queryParams.changeQueriedColumnIndex('back');
117-
}
118-
}}
119-
icon={vsArrowLeft}
120-
tooltip="Next match"
121-
/>
122-
{queryParams && matchCount > 1 ? (
123-
<span className="search-change-text">
124-
{queryParams.queriedColumnIndex !== undefined &&
125-
`${queryParams.queriedColumnIndex + 1} of `}
126-
{matchCount}
127-
</span>
128-
) : (
129-
<span className="match_count">{matchCount}</span>
130-
)}
131-
132-
<Button
133-
kind="ghost"
134-
className={
135-
matchCount <= 1 && queryParams
136-
? 'search-change-button__hidden' // using the disabled prop messes up the paddingRight calculation
137-
: 'search-change-button'
138-
}
139-
type="button"
140-
onClick={() => {
141-
if (queryParams) {
142-
queryParams.changeQueriedColumnIndex('forward');
143-
}
144-
}}
145-
icon={vsArrowRight}
146-
tooltip="Next match"
147-
/>
144+
{matchCountSection}
148145
</div>
149146
) : (
150147
<span className="search-icon">

0 commit comments

Comments
 (0)