-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor the code for the search component and adapt the style …
…to the latest design draft (#251) * refactor: move components\Search\Filter to components\Filter * refactor: Search component * feat: refactor the code for the search component and adapt the style to the latest design draft
- Loading branch information
1 parent
f142459
commit 7b278f0
Showing
17 changed files
with
274 additions
and
264 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/components/Search/Filter/index.tsx → src/components/Filter/index.tsx
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
4 changes: 2 additions & 2 deletions
4
src/components/Search/Filter/styled.tsx → src/components/Filter/styled.tsx
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 |
---|---|---|
@@ -1,47 +1,56 @@ | ||
.searchResultsPanelWrapper { | ||
position: absolute; | ||
width: 100%; | ||
z-index: 2; | ||
top: calc(100% + 8px); | ||
left: 0; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 12px; | ||
width: 100%; | ||
max-height: 292px; | ||
padding: 12px 8px; | ||
max-height: 232px; | ||
overflow-y: auto; | ||
background: white; | ||
color: black; | ||
top: 38px; | ||
left: 0; | ||
border-radius: 0 0 4px 4px; | ||
border-radius: 4px; | ||
box-shadow: 0 4px 4px 0 rgb(16 16 16 / 5%); | ||
} | ||
|
||
.loadingWrapper { | ||
margin: 0; | ||
} | ||
.empty { | ||
padding: 28px 0; | ||
text-align: center; | ||
font-size: 16px; | ||
color: #333; | ||
} | ||
|
||
.searchResult { | ||
user-select: none; | ||
cursor: pointer; | ||
display: flex; | ||
align-items: center; | ||
display: block; | ||
width: 100%; | ||
height: 44px; | ||
border-radius: 4px; | ||
padding: 12px 4px; | ||
font-weight: 500; | ||
font-size: 16px; | ||
border-bottom: solid 1px #e5e5e5; | ||
padding: 0 4px; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
background: #f5f5f5; | ||
} | ||
} | ||
|
||
.content { | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
width: 100%; | ||
height: 44px; | ||
padding: 12px 0; | ||
border-bottom: solid 1px #e5e5e5; | ||
} | ||
|
||
.tokenSymbol { | ||
min-width: 100px; | ||
font-size: 16px; | ||
color: #333; | ||
} | ||
|
||
.typeHash { | ||
font-size: 14px; | ||
font-weight: 500; | ||
margin-left: 8px; | ||
flex: 1; | ||
min-width: 0; | ||
color: #666; | ||
} |
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 |
---|---|---|
@@ -1,57 +1,62 @@ | ||
import { useTranslation } from 'react-i18next' | ||
import classNames from 'classnames' | ||
import { FC } from 'react' | ||
import { UDTQueryResult } from '../../services/ExplorerService/fetcher' | ||
import styles from './SearchByNameResults.module.scss' | ||
import EllipsisMiddle from '../EllipsisMiddle' | ||
import SmallLoading from '../Loading/SmallLoading' | ||
|
||
type Props = { | ||
loading?: boolean | ||
udtQueryResults: UDTQueryResult[] | null | ||
udtQueryResults: UDTQueryResult[] | ||
} | ||
|
||
export const SearchByNameResults = (props: Props) => { | ||
const { udtQueryResults, loading } = props | ||
if (loading) { | ||
return ( | ||
<div className={styles.searchResultsPanelWrapper}> | ||
<SmallLoading className={styles.loadingWrapper} /> | ||
</div> | ||
) | ||
} | ||
if (udtQueryResults) { | ||
return ( | ||
<div className={styles.searchResultsPanelWrapper}> | ||
{udtQueryResults.length === 0 ? ( | ||
<EmptySearchByNameResult /> | ||
) : ( | ||
udtQueryResults.map(item => { | ||
return <SearchByNameResult key={item.typeHash} item={item} /> | ||
}) | ||
)} | ||
</div> | ||
) | ||
} | ||
return null | ||
} | ||
|
||
const EmptySearchByNameResult = () => { | ||
export const SearchByNameResults: FC<Props> = ({ udtQueryResults, loading }) => { | ||
const { t } = useTranslation() | ||
return <>{t('search.no_search_result')}</> | ||
|
||
return ( | ||
<div className={styles.searchResultsPanelWrapper}> | ||
{/* eslint-disable-next-line no-nested-ternary */} | ||
{loading ? ( | ||
<SmallLoading className={styles.loadingWrapper} /> | ||
) : udtQueryResults.length === 0 ? ( | ||
<div className={styles.empty}>{t('search.no_search_result')}</div> | ||
) : ( | ||
udtQueryResults.map(item => <SearchByNameResult key={item.typeHash} item={item} />) | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
const SearchByNameResult = (props: { item: UDTQueryResult }) => { | ||
const SearchByNameResult: FC<{ item: UDTQueryResult }> = ({ item }) => { | ||
const { t } = useTranslation() | ||
const { item } = props | ||
const { typeHash, fullName, symbol, udtType } = item | ||
const displayName = symbol ?? fullName | ||
|
||
return ( | ||
<a | ||
className={styles.searchResult} | ||
href={`${window.origin}/${udtType === 'omiga_inscription' ? 'inscription' : 'sudt'}/${typeHash}`} | ||
> | ||
<EllipsisMiddle className={styles.tokenSymbol}>{displayName ?? t('udt.unknown_token')}</EllipsisMiddle> | ||
<EllipsisMiddle className={classNames(styles.typeHash, 'monospace')}>{typeHash}</EllipsisMiddle> | ||
<div className={styles.content}> | ||
{/* TODO: Need to implement highlighting for the matched keywords. */} | ||
<EllipsisMiddle | ||
className={styles.tokenSymbol} | ||
style={{ maxWidth: 'min(180px, 40%)' }} | ||
useTextWidthForPlaceholderWidth | ||
title={displayName} | ||
> | ||
{displayName ?? t('udt.unknown_token')} | ||
</EllipsisMiddle> | ||
<EllipsisMiddle | ||
className={classNames(styles.typeHash, 'monospace')} | ||
style={{ maxWidth: 'min(200px, 60%)' }} | ||
useTextWidthForPlaceholderWidth | ||
title={typeHash} | ||
> | ||
{typeHash} | ||
</EllipsisMiddle> | ||
</div> | ||
</a> | ||
) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.