diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-08-08 09:17:13 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-08-21 20:21:01 +0200 |
commit | d4a017262d4c7e510f9abbfe7f36b3d24b885776 (patch) | |
tree | 49a96201018149283724aba4bf6de600ef01fe08 /server/sonar-web/src/main/js/helpers/search.tsx | |
parent | 86be78388006563617ae841d577c8bcf98548741 (diff) | |
download | sonarqube-d4a017262d4c7e510f9abbfe7f36b3d24b885776.tar.gz sonarqube-d4a017262d4c7e510f9abbfe7f36b3d24b885776.zip |
SONAR-6400 Move the search box above the list of facet items (#592)
Diffstat (limited to 'server/sonar-web/src/main/js/helpers/search.tsx')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/search.tsx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/helpers/search.tsx b/server/sonar-web/src/main/js/helpers/search.tsx new file mode 100644 index 00000000000..2c516d10cf6 --- /dev/null +++ b/server/sonar-web/src/main/js/helpers/search.tsx @@ -0,0 +1,33 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; + +export function highlightTerm(str: string, term: string) { + const pos = str.toLowerCase().indexOf(term.toLowerCase()); + return pos !== -1 ? ( + <> + {pos > 0 && str.substring(0, pos)} + <mark>{str.substr(pos, term.length)}</mark> + {pos + term.length < str.length && str.substring(pos + term.length)} + </> + ) : ( + str + ); +} |