Merge pull request #2667 from lbryio/commentsExpandContained
comments and expandable changes
This commit is contained in:
commit
a9a6b7659e
4 changed files with 43 additions and 47 deletions
|
@ -42,6 +42,10 @@ export default function ClaimTags(props: Props) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tagsToDisplay.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classnames('file-properties', { 'file-properties--large': type === 'large' })}>
|
<div className={classnames('file-properties', { 'file-properties--large': type === 'large' })}>
|
||||||
{tagsToDisplay.map(tag => (
|
{tagsToDisplay.map(tag => (
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import relativeDate from 'tiny-relative-date';
|
import relativeDate from 'tiny-relative-date';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
|
import Expandable from 'component/expandable';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
author: string,
|
author: string,
|
||||||
|
@ -25,8 +26,11 @@ function Comment(props: Props) {
|
||||||
{relativeDate(timePosted)}
|
{relativeDate(timePosted)}
|
||||||
</time>
|
</time>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<Expandable>
|
||||||
<p className={'comment__message'}>{message}</p>
|
<p className={'comment__message'}>{message}</p>
|
||||||
|
</Expandable>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +1,29 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React, { PureComponent } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
|
import { useRect } from '@reach/rect';
|
||||||
|
|
||||||
// Note:
|
const COLLAPSED_HEIGHT = 120;
|
||||||
// When we use this in other parts of the app, we will probably need to
|
|
||||||
// add props for collapsed height
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: React$Node | Array<React$Node>,
|
children: React$Node | Array<React$Node>,
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
export default function Expandable(props: Props) {
|
||||||
expanded: boolean,
|
const [expanded, setExpanded] = useState(false);
|
||||||
};
|
const { children } = props;
|
||||||
|
const ref = useRef();
|
||||||
|
const rect = useRect(ref);
|
||||||
|
|
||||||
export default class Expandable extends PureComponent<Props, State> {
|
function handleClick() {
|
||||||
constructor() {
|
setExpanded(!expanded);
|
||||||
super();
|
|
||||||
|
|
||||||
this.state = {
|
|
||||||
expanded: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
(this: any).handleClick = this.handleClick.bind(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick() {
|
|
||||||
this.setState({
|
|
||||||
expanded: !this.state.expanded,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const { children } = this.props;
|
|
||||||
const { expanded } = this.state;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="expandable">
|
<div ref={ref}>
|
||||||
|
{rect && rect.height > COLLAPSED_HEIGHT ? (
|
||||||
|
<div ref={ref} className="expandable">
|
||||||
<div
|
<div
|
||||||
className={classnames({
|
className={classnames({
|
||||||
'expandable--open': expanded,
|
'expandable--open': expanded,
|
||||||
|
@ -50,9 +36,12 @@ export default class Expandable extends PureComponent<Props, State> {
|
||||||
button="link"
|
button="link"
|
||||||
className="expandable__button"
|
className="expandable__button"
|
||||||
label={expanded ? __('Less') : __('More')}
|
label={expanded ? __('Less') : __('More')}
|
||||||
onClick={this.handleClick}
|
onClick={handleClick}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
) : (
|
||||||
|
<div>{children}</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
.expandable {
|
.expandable {
|
||||||
border-bottom: 1px solid $lbry-gray-1;
|
|
||||||
margin-bottom: var(--spacing-medium);
|
margin-bottom: var(--spacing-medium);
|
||||||
padding-bottom: var(--spacing-medium);
|
padding-bottom: var(--spacing-medium);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue