mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: input clear button
This commit is contained in:
parent
20ed9b9a59
commit
0492784b70
1 changed files with 21 additions and 15 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { SearchIcon } from '@primer/octicons-react'
|
||||
import { SearchIcon, XIcon } from '@primer/octicons-react'
|
||||
import { TextInput, TextInputProps } from '@primer/react'
|
||||
import { useConfigs } from 'containers/ConfigsContext'
|
||||
import * as React from 'react'
|
||||
|
|
@ -48,20 +48,26 @@ export function SearchBar({ onSearch, onFocus, value }: Props) {
|
|||
value={value}
|
||||
validationStatus={validationStatus}
|
||||
trailingAction={
|
||||
<TextInput.Action
|
||||
aria-label={toggleButtonDescription}
|
||||
sx={{ color: 'fg.subtle' }}
|
||||
onClick={() => {
|
||||
const newMode = searchMode === 'regex' ? 'fuzzy' : 'regex'
|
||||
configs.onChange({
|
||||
searchMode: newMode,
|
||||
})
|
||||
// Skip search if no input to prevent resetting folder expansions
|
||||
if (value) onSearch(value, newMode)
|
||||
}}
|
||||
>
|
||||
{searchMode === 'regex' ? '.*$' : 'a/b'}
|
||||
</TextInput.Action>
|
||||
<>
|
||||
<TextInput.Action
|
||||
disabled={!value}
|
||||
onClick={() => onSearch('', searchMode)}
|
||||
icon={XIcon}
|
||||
aria-label="Clear"
|
||||
/>
|
||||
<TextInput.Action
|
||||
aria-label={toggleButtonDescription}
|
||||
sx={{ color: 'fg.subtle' }}
|
||||
onClick={() => {
|
||||
const newMode = searchMode === 'regex' ? 'fuzzy' : 'regex'
|
||||
configs.onChange({ searchMode: newMode })
|
||||
// Skip search if no input to prevent resetting folder expansions
|
||||
if (value) onSearch(value, newMode)
|
||||
}}
|
||||
>
|
||||
{searchMode === 'regex' ? '.*$' : 'a/b'}
|
||||
</TextInput.Action>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue