-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
288 additions
and
149 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
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,99 @@ | ||
import { a2p } from '../lib/converters'; | ||
import React from 'react'; | ||
|
||
import { Context } from '../store'; | ||
import { setSearchQuery, search, setSearchCaseSensitive } from '../store/actions'; | ||
import { smartScroll } from '../lib/virtualization'; | ||
import { SearchIcon } from './svg/SearchIcon'; | ||
import { CloseIcon } from './svg/CloseIcon'; | ||
|
||
export const SearchBar: React.FC = () => { | ||
const { store, dispatch } = React.useContext(Context); | ||
const { | ||
rootRef, | ||
editorRef, | ||
searchInputRef, | ||
tabularRef, | ||
searchQuery, | ||
searchCaseSensitive, | ||
matchingCellIndex, | ||
matchingCells, | ||
table, | ||
} = store; | ||
|
||
const matchingCell = matchingCells[matchingCellIndex]; | ||
React.useEffect(() => { | ||
if (!matchingCell) { | ||
return; | ||
} | ||
const point = a2p(matchingCell); | ||
if (typeof point === 'undefined') { | ||
return; | ||
} | ||
smartScroll(table, tabularRef.current, point); | ||
}, [searchQuery, matchingCellIndex, searchCaseSensitive]); | ||
|
||
if (typeof searchQuery === 'undefined') { | ||
return null; | ||
} | ||
if (rootRef.current === null) { | ||
return null; | ||
} | ||
return ( | ||
<label className={`gs-search-bar ${matchingCells.length > 0 ? 'gs-search-found' : ''}`}> | ||
<div | ||
className="gs-search-progress" | ||
onClick={(e) => { | ||
const input = e.currentTarget.previousSibling as HTMLInputElement; | ||
input?.nodeName === 'INPUT' && input.focus(); | ||
}} | ||
> | ||
{matchingCells.length === 0 ? 0 : matchingCellIndex + 1} / {matchingCells.length} | ||
</div> | ||
<div className="gs-search-bar-icon" onClick={() => dispatch(search(1))}> | ||
<SearchIcon style={{ verticalAlign: 'middle', marginLeft: '5px' }} /> | ||
</div> | ||
<textarea | ||
ref={searchInputRef} | ||
value={searchQuery} | ||
onChange={(e) => dispatch(setSearchQuery(e.target.value))} | ||
onKeyDown={(e) => { | ||
if (e.key === 'Escape') { | ||
const el = editorRef?.current; | ||
if (el) { | ||
el.focus(); | ||
} | ||
dispatch(setSearchQuery(undefined)); | ||
} | ||
if (e.key === 'f' && (e.ctrlKey || e.metaKey)) { | ||
e.preventDefault(); | ||
return false; | ||
} | ||
if (e.key === 'Enter') { | ||
dispatch(search(e.shiftKey ? -1 : 1)); | ||
e.preventDefault(); | ||
return false; | ||
} | ||
return true; | ||
}} | ||
></textarea> | ||
<div className={`gs-search-casesensitive`}> | ||
<span | ||
className={`${searchCaseSensitive ? 'gs-search-casesensitive-on' : ''}`} | ||
onClick={() => dispatch(setSearchCaseSensitive(!searchCaseSensitive))} | ||
> | ||
Aa | ||
</span> | ||
</div> | ||
<a | ||
className="gs-search-close" | ||
onClick={() => { | ||
dispatch(setSearchQuery(undefined)); | ||
editorRef.current?.focus(); | ||
}} | ||
> | ||
<CloseIcon style={{ verticalAlign: 'middle' }} /> | ||
</a> | ||
</label> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
import React from 'react'; | ||
|
||
export interface IconProps { | ||
style?: React.CSSProperties; | ||
color?: string; | ||
size?: number; | ||
} | ||
|
||
interface BaseProps extends IconProps { | ||
children?: React.ReactNode; | ||
} | ||
|
||
// https://tabler.io/icons | ||
|
||
export const Base = ({ style, size = 24, children }: BaseProps) => { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width={size} | ||
height={size} | ||
viewBox={`0 0 24 24`} | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-width="2" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
style={style} | ||
className="icon-tabler" | ||
> | ||
{children} | ||
</svg> | ||
); | ||
}; |
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,14 @@ | ||
import React from 'react'; | ||
import { type IconProps, Base } from './Base'; | ||
|
||
// https://tabler.io/icons | ||
|
||
export const CloseIcon = ({ style, color = 'none', size = 24 }: IconProps) => { | ||
return ( | ||
<Base style={style} size={size}> | ||
<path stroke="none" d="M0 0h24v24H0z" fill={color} /> | ||
<path d="M18 6l-12 12" fill={color} /> | ||
<path d="M6 6l12 12" fill={color} /> | ||
</Base> | ||
); | ||
}; |
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,14 @@ | ||
import React from 'react'; | ||
import { type IconProps, Base } from './Base'; | ||
|
||
// https://tabler.io/icons | ||
|
||
export const SearchIcon = ({ style, color = 'none', size = 24 }: IconProps) => { | ||
return ( | ||
<Base style={style} size={size}> | ||
<path stroke="none" d="M0 0h24v24H0z" fill={color} /> | ||
<path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" fill={color} /> | ||
<path d="M21 21l-6 -6" fill={color} /> | ||
</Base> | ||
); | ||
}; |
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
Oops, something went wrong.