forked from nervosnetwork/ckb-explorer-frontend
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(xudt-tag): add xudt tag column in xudt page (#378)
- Loading branch information
Showing
13 changed files
with
457 additions
and
166 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Link, useLocation } from 'react-router-dom' | ||
import { Popover } from 'antd' | ||
import { useTranslation } from 'react-i18next' | ||
import { ReactComponent as FilterIcon } from '../../assets/filter_icon.svg' | ||
import { ReactComponent as SelectedIcon } from '../../assets/selected-icon.svg' | ||
import { ReactComponent as NotSelectedIcon } from '../../assets/not-selected-icon.svg' | ||
import { ReactComponent as PartialSelectedIcon } from '../../assets/partial-selected-icon.svg' | ||
import { useSearchParams } from '../../hooks' | ||
import styles from './styles.module.scss' | ||
|
||
export function MultiFilterButton({ | ||
filterList, | ||
isMobile, | ||
filterName, | ||
}: { | ||
filterName: string | ||
filterList: { key: string; value: string; to: string; title: string | JSX.Element }[] | ||
isMobile?: boolean | ||
}) { | ||
const { t } = useTranslation() | ||
const params = useSearchParams(filterName) | ||
const filter = params[filterName] | ||
let types = filterList.map(f => f.value) | ||
if (filter !== undefined) { | ||
types = filter.split(',').filter(t => !!t) | ||
} | ||
|
||
const isAllSelected = types.length === filterList.length | ||
const isNoneSelected = types.length === 0 | ||
const search = new URLSearchParams(useLocation().search) | ||
search.delete(filterName) | ||
search.delete('page') | ||
|
||
return ( | ||
<Popover | ||
className={styles.container} | ||
placement="bottomRight" | ||
trigger={isMobile ? 'click' : 'hover'} | ||
overlayClassName={styles.antPopover} | ||
content={ | ||
<div className={styles.filterItems}> | ||
<div className={styles.selectTitle}> | ||
<h2>{t('components.multi_filter_button.select')}</h2> | ||
<Link | ||
key="all" | ||
to={() => { | ||
const newSearch = new URLSearchParams(search) | ||
if (isNoneSelected) { | ||
newSearch.append(filterName, filterList.map(f => f.value).join(',')) | ||
} | ||
|
||
if (isAllSelected) { | ||
newSearch.append(filterName, '') | ||
} | ||
|
||
return `${filterList[0].to}?${newSearch.toString()}` | ||
}} | ||
> | ||
{types.length > 0 ? ( | ||
<>{isAllSelected ? <SelectedIcon /> : <PartialSelectedIcon />}</> | ||
) : ( | ||
<NotSelectedIcon /> | ||
)} | ||
</Link> | ||
</div> | ||
{filterList.map(f => ( | ||
<Link | ||
key={f.key} | ||
to={() => { | ||
const subTypes = new Set(types) | ||
if (subTypes.has(f.value)) { | ||
subTypes.delete(f.value) | ||
} else { | ||
subTypes.add(f.value) | ||
} | ||
|
||
const newSearch = new URLSearchParams(search) | ||
newSearch.append(filterName, Array.from(subTypes).join(',')) | ||
return `${f.to}?${newSearch.toString()}` | ||
}} | ||
data-is-active={types.includes(f.value)} | ||
> | ||
{f.title} | ||
{types.includes(f.value) ? <SelectedIcon /> : <NotSelectedIcon />} | ||
</Link> | ||
))} | ||
</div> | ||
} | ||
> | ||
<FilterIcon | ||
className={styles.filter} | ||
// if the filter is the empty string, display highlight | ||
// if the filter is the string list, display highlight | ||
// if the filter is undefined, not display highlight | ||
data-changed={filter !== undefined} | ||
/> | ||
</Popover> | ||
) | ||
} | ||
|
||
MultiFilterButton.displayName = 'MultiFilterButton' | ||
|
||
export default MultiFilterButton |
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,79 @@ | ||
.container { | ||
appearance: none; | ||
border: none; | ||
outline: none; | ||
background: none; | ||
display: inline-flex; | ||
vertical-align: text-top; | ||
margin-left: 8px; | ||
cursor: pointer; | ||
} | ||
|
||
.antPopover { | ||
:global { | ||
/* stylelint-disable-next-line selector-class-pattern */ | ||
.ant-popover-inner { | ||
border-radius: 8px; | ||
box-shadow: 0 2px 10px 0 #eee; | ||
} | ||
|
||
/* stylelint-disable-next-line selector-class-pattern */ | ||
.ant-popover-inner-content { | ||
padding: 14px 24px 14px 16px; | ||
} | ||
} | ||
} | ||
|
||
.filter { | ||
margin-left: 8px; | ||
color: #999; | ||
|
||
&[data-changed='true'] { | ||
color: var(--primary-color); | ||
} | ||
} | ||
|
||
.filterItems { | ||
display: flex; | ||
flex-direction: column; | ||
width: 200px; | ||
|
||
.selectTitle { | ||
color: var(--primary-color); | ||
|
||
h2 { | ||
color: #333; | ||
font-size: 14px; | ||
font-style: normal; | ||
font-weight: 500; | ||
line-height: normal; | ||
} | ||
|
||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 10px; | ||
border-radius: 8px; | ||
|
||
a { | ||
padding: 0; | ||
} | ||
} | ||
|
||
a { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
padding: 10px; | ||
border-radius: 8px; | ||
|
||
svg { | ||
color: var(--primary-color); | ||
} | ||
|
||
&:hover { | ||
background: var(--primary-hover-bg-color); | ||
cursor: pointer; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.