lbry-desktop/ui/component/fileDescription/view.jsx
infiinte-persistence 108a898ebf Expandable: Fade out section when 'closed'
## Issue
The abrupt cut-off of the expandable section bugs me (looks like a rendering glitch), especially when it cuts off in the middle of a line.

## Change
In addition to the existing 'More' button, we fade out the section to provide additional visual cues.

## Approach
This solution doesn't require the background color to be known, so it will work regardless where <Expandable> is used, or whatever color-scheme is chosen.

However, it does utilize non-standard css -- for older browsers, it should simply cut-off like the before.
2020-10-02 11:54:43 -04:00

66 lines
2 KiB
JavaScript

// @flow
import React from 'react';
import classnames from 'classnames';
import MarkdownPreview from 'component/common/markdown-preview';
import ClaimTags from 'component/claimTags';
import Button from 'component/button';
type Props = {
uri: string,
claim: StreamClaim,
metadata: StreamMetadata,
user: ?any,
tags: any,
};
function FileDescription(props: Props) {
const { uri, claim, metadata, tags } = props;
const [expanded, setExpanded] = React.useState(false);
const [hasOverflow, setHasOverflow] = React.useState(false);
const [hasCalculatedOverflow, setHasCalculatedOverflow] = React.useState(false);
const descriptionRef = React.useRef();
React.useEffect(() => {
if (descriptionRef && descriptionRef.current) {
const element = descriptionRef.current;
const isOverflowing = element.scrollHeight > element.clientHeight;
setHasOverflow(isOverflowing);
setHasCalculatedOverflow(true);
}
}, [descriptionRef]);
if (!claim || !metadata) {
return <span className="empty">{__('Empty claim or metadata info.')}</span>;
}
const { description } = metadata;
if (!description && !(tags && tags.length)) return null;
return (
<div>
<div
ref={descriptionRef}
className={classnames({
'media__info-text--contracted': !expanded,
'media__info-text--expanded': expanded,
'media__info-text--fade': hasOverflow && !expanded,
})}
>
<MarkdownPreview className="markdown-preview--description" content={description} />
<ClaimTags uri={uri} type="large" />
</div>
{hasCalculatedOverflow && hasOverflow && (
<div className="media__info-expand">
{expanded ? (
<Button button="link" label={__('Less')} onClick={() => setExpanded(!expanded)} />
) : (
<Button button="link" label={__('More')} onClick={() => setExpanded(!expanded)} />
)}
</div>
)}
</div>
);
}
export default FileDescription;