From cf30dc03f527728fd5610181dc0275f2c3fac2cf Mon Sep 17 00:00:00 2001 From: jessop Date: Wed, 24 Jul 2019 17:02:35 -0400 Subject: [PATCH] comments and expandable changes comments are collapsed if larger than 120 height expandable checks the useRect ref height before inserting itself --- src/ui/component/comment/view.jsx | 8 ++- src/ui/component/expandable/view.jsx | 73 +++++++++++--------------- src/ui/scss/component/_expandable.scss | 2 +- 3 files changed, 39 insertions(+), 44 deletions(-) diff --git a/src/ui/component/comment/view.jsx b/src/ui/component/comment/view.jsx index 0ce7c8068..f43eeae22 100644 --- a/src/ui/component/comment/view.jsx +++ b/src/ui/component/comment/view.jsx @@ -2,6 +2,7 @@ import React from 'react'; import relativeDate from 'tiny-relative-date'; import Button from 'component/button'; +import Expandable from 'component/expandable'; type Props = { author: string, @@ -25,8 +26,11 @@ function Comment(props: Props) { {relativeDate(timePosted)} - -

{message}

+
+ +

{message}

+
+
); } diff --git a/src/ui/component/expandable/view.jsx b/src/ui/component/expandable/view.jsx index 381dcfee3..607e713a8 100644 --- a/src/ui/component/expandable/view.jsx +++ b/src/ui/component/expandable/view.jsx @@ -1,7 +1,8 @@ // @flow -import React, { PureComponent } from 'react'; +import React, { useRef, useState } from 'react'; import classnames from 'classnames'; import Button from 'component/button'; +import { useRect } from '@reach/rect'; // Note: // When we use this in other parts of the app, we will probably need to @@ -11,48 +12,38 @@ type Props = { children: React$Node | Array, }; -type State = { - expanded: boolean, -}; +export default function Expandable(props: Props) { + const [expanded, setExpanded] = useState(false); + const { children } = props; + const ref = useRef(); + const rect = useRect(ref); -export default class Expandable extends PureComponent { - constructor() { - super(); - - this.state = { - expanded: false, - }; - - (this: any).handleClick = this.handleClick.bind(this); + function handleClick() { + setExpanded(!expanded); } - handleClick() { - this.setState({ - expanded: !this.state.expanded, - }); - } - - render() { - const { children } = this.props; - const { expanded } = this.state; - - return ( -
-
- {children} + return ( +
+ {rect && rect.height > 120 ? ( +
+
+ {children} +
+
-
- ); - } + ) : ( +
{children}
+ )} +
+ ); } diff --git a/src/ui/scss/component/_expandable.scss b/src/ui/scss/component/_expandable.scss index b65f8ec48..867b63e69 100644 --- a/src/ui/scss/component/_expandable.scss +++ b/src/ui/scss/component/_expandable.scss @@ -1,5 +1,5 @@ .expandable { - border-bottom: 1px solid $lbry-gray-1; + //border-bottom: 1px solid $lbry-gray-1; margin-bottom: var(--spacing-medium); padding-bottom: var(--spacing-medium);