Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds matching options to graph search
- Loading branch information
Showing
5 changed files
with
210 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { provideReactWrapper } from '@microsoft/fast-react-wrapper'; | ||
import React from 'react'; | ||
import { SearchField as fieldComponent } from './search-field'; | ||
import { SearchNav as navComponent } from './search-nav'; | ||
|
||
const { wrap } = provideReactWrapper(React); | ||
|
||
export const SearchField = wrap(fieldComponent, { | ||
events: { | ||
onChange: 'change', | ||
}, | ||
}); | ||
|
||
export const SearchNav = wrap(navComponent, { | ||
events: { | ||
onPrevious: 'previous', | ||
onNext: 'next', | ||
}, | ||
}); |
181 changes: 181 additions & 0 deletions
181
src/webviews/apps/shared/components/search/search-field.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
import { attr, css, customElement, FASTElement, html } from '@microsoft/fast-element'; | ||
import '../codicon'; | ||
|
||
// match case is disabled unless regex is true | ||
const template = html<SearchField>` | ||
<template role="search"> | ||
<label htmlFor="search"> | ||
<code-icon icon="search" aria-label="${x => x.label}" title="${x => x.label}"></code-icon> | ||
</label> | ||
<input | ||
id="search" | ||
type="search" | ||
spellcheck="false" | ||
placeholder="${x => x.placeholder}" | ||
value="${x => x.value}" | ||
@input="${(x, c) => x.handleInput(c.event)}" | ||
/> | ||
<div class="controls"> | ||
<button | ||
type="button" | ||
role="checkbox" | ||
aria-label="Match All" | ||
title="Match All" | ||
aria-checked="${x => x.all}" | ||
@click="${(x, c) => x.handleAll(c.event)}" | ||
> | ||
<code-icon icon="whole-word"></code-icon> | ||
</button> | ||
<button | ||
type="button" | ||
role="checkbox" | ||
aria-label="Match Case in Regular Expression" | ||
title="Match Case in Regular Expression" | ||
?disabled="${x => !x.regex}" | ||
aria-checked="${x => x.case}" | ||
@click="${(x, c) => x.handleCase(c.event)}" | ||
> | ||
<code-icon icon="case-sensitive"></code-icon> | ||
</button> | ||
<button | ||
type="button" | ||
role="checkbox" | ||
aria-label="Use Regular Expression" | ||
title="Use Regular Expression" | ||
aria-checked="${x => x.regex}" | ||
@click="${(x, c) => x.handleRegex(c.event)}" | ||
> | ||
<code-icon icon="regex"></code-icon> | ||
</button> | ||
</div> | ||
</template> | ||
`; | ||
|
||
const styles = css` | ||
:host { | ||
display: inline-flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 0.8rem; | ||
position: relative; | ||
} | ||
label { | ||
color: var(--vscode-input-foreground); | ||
} | ||
input { | ||
width: 30rem; | ||
height: 2.4rem; | ||
background-color: var(--vscode-input-background); | ||
color: var(--vscode-input-foreground); | ||
border: 1px solid var(--vscode-input-background); | ||
border-radius: 0.25rem; | ||
padding: 0 6.6rem 0 0.4rem; | ||
font-family: inherit; | ||
font-size: 1rem; | ||
} | ||
input:focus { | ||
outline: 1px solid var(--vscode-focusBorder); | ||
outline-offset: -1px; | ||
} | ||
input::placeholder { | ||
color: var(--vscode-input-placeholderForeground); | ||
} | ||
.controls { | ||
position: absolute; | ||
top: 0.2rem; | ||
right: 0.2rem; | ||
display: inline-flex; | ||
flex-direction: row; | ||
align-items: center; | ||
gap: 0.1rem; | ||
} | ||
button { | ||
display: inline-flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 2rem; | ||
height: 2rem; | ||
padding: 0; | ||
color: inherit; | ||
border: none; | ||
background: none; | ||
text-align: center; | ||
border-radius: 0.25rem; | ||
} | ||
button:focus:not([disabled]) { | ||
outline: 1px solid var(--vscode-focusBorder); | ||
outline-offset: -1px; | ||
} | ||
button:not([disabled]) { | ||
cursor: pointer; | ||
} | ||
button:hover:not([disabled]) { | ||
background-color: var(--vscode-inputOption-hoverBackground); | ||
} | ||
button[disabled] { | ||
opacity: 0.5; | ||
} | ||
button[aria-checked='true'] { | ||
background-color: var(--vscode-inputOption-activeBackground); | ||
color: var(--vscode-inputOption-activeForeground); | ||
} | ||
`; | ||
|
||
@customElement({ | ||
name: 'search-field', | ||
template: template, | ||
styles: styles, | ||
}) | ||
export class SearchField extends FASTElement { | ||
@attr | ||
label = 'Search'; | ||
|
||
@attr | ||
placeholder = 'Search...'; | ||
|
||
@attr | ||
value = ''; | ||
|
||
@attr({ mode: 'boolean' }) | ||
all = false; | ||
|
||
@attr({ mode: 'boolean' }) | ||
case = false; | ||
|
||
@attr({ mode: 'boolean' }) | ||
regex = false; | ||
|
||
handleInput(e: Event) { | ||
const value = (e.target as HTMLInputElement)?.value; | ||
this.value = value; | ||
this.emitSearch(); | ||
} | ||
handleAll(_e: Event) { | ||
this.all = !this.all; | ||
this.emitSearch(); | ||
} | ||
handleCase(_e: Event) { | ||
this.case = !this.case; | ||
this.emitSearch(); | ||
} | ||
handleRegex(_e: Event) { | ||
this.regex = !this.regex; | ||
if (!this.regex) { | ||
this.case = false; | ||
} | ||
this.emitSearch(); | ||
} | ||
|
||
emitSearch() { | ||
this.$emit('change', { | ||
pattern: this.value, | ||
matchAll: this.all, | ||
matchCase: this.case, | ||
matchRegex: this.regex, | ||
}); | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
src/webviews/apps/shared/components/search/search-nav-react.tsx
This file was deleted.
Oops, something went wrong.