-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #630 from subquery/feat/up-user-friendly
feat: up user exp friendly
- Loading branch information
Showing
13 changed files
with
225 additions
and
201 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020-2022 SubQuery Pte Ltd authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React, { FC, useCallback, useMemo, useRef, useState } from 'react'; | ||
import { Typography } from '@subql/components'; | ||
import { useUpdate } from 'ahooks'; | ||
|
||
import styles from './index.module.less'; | ||
|
||
interface IProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
const Expand: FC<IProps> = (props) => { | ||
const update = useUpdate(); | ||
|
||
const [expanded, setExpanded] = useState(false); | ||
const childrenRef = useRef<HTMLDivElement | null>(null); | ||
|
||
const setCallback = useCallback((ref: HTMLDivElement) => { | ||
childrenRef.current = ref; | ||
update(); | ||
}, []); | ||
|
||
const showExpandIcon = useMemo(() => { | ||
const rect = childrenRef.current?.getBoundingClientRect(); | ||
return !!(rect?.height && rect.height > 400); | ||
}, [childrenRef.current, props.children]); | ||
|
||
return ( | ||
<div> | ||
<div | ||
ref={setCallback} | ||
style={{ | ||
position: 'fixed', | ||
zIndex: '-9999', | ||
opacity: 0, | ||
}} | ||
> | ||
{props.children} | ||
</div> | ||
|
||
<div | ||
className={styles.expand} | ||
style={{ | ||
height: expanded ? 'auto' : showExpandIcon ? 400 : 'auto', | ||
overflow: 'hidden', | ||
}} | ||
> | ||
{props.children} | ||
</div> | ||
|
||
{showExpandIcon && ( | ||
<div style={{ display: 'flex', justifyContent: 'center', padding: 12 }}> | ||
<Typography.Link | ||
active | ||
onClick={() => { | ||
setExpanded(!expanded); | ||
}} | ||
> | ||
{expanded ? 'Show Less' : 'Show More'} | ||
</Typography.Link> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
export default Expand; |
Empty file.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.