-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(videodetail): add collapsible text
- Loading branch information
Showing
12 changed files
with
164 additions
and
22 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/components/CollapsibleText/CollapsibleText.module.scss
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,36 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.collapsibleText { | ||
position: relative; | ||
padding-bottom: 20px; | ||
} | ||
.dummyDiv { | ||
position: absolute; | ||
visibility: hidden; | ||
} | ||
.textContainer { | ||
overflow: hidden; | ||
&.collapsed { | ||
mask-image: linear-gradient(-180deg, rgba(0, 0, 0, 1) 50%, rgba(0, 0, 0, 0) 100%); | ||
-webkit-mask-image: linear-gradient(-180deg, rgba(0, 0, 0, 1) 50%, rgba(0, 0, 0, 0) 100%); | ||
} | ||
} | ||
.chevron { | ||
position: absolute; | ||
width: 24px; | ||
height: 24px; | ||
bottom: 25px; | ||
left: calc(50% - 24px / 2); | ||
z-index: 1; | ||
cursor: pointer; | ||
|
||
> svg { | ||
transform: rotate(90deg); | ||
} | ||
&.expanded { | ||
> svg { | ||
transform: rotate(270deg); | ||
} | ||
} | ||
} |
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,12 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import CollapsibleText from './CollapsibleText'; | ||
|
||
describe('<CollapsibleText>', () => { | ||
test('renders and matches snapshot', () => { | ||
const { container } = render(<CollapsibleText text="Test..." />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
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,50 @@ | ||
import classNames from 'classnames'; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
|
||
import IconButton from '../IconButton/IconButton'; | ||
import ChevronRight from '../../icons/ChevronRight'; | ||
|
||
import styles from './CollapsibleText.module.scss'; | ||
|
||
type Props = { | ||
text: string; | ||
className?: string; | ||
maxHeight?: 'none' | number; | ||
}; | ||
|
||
const CollapsibleText: React.FC<Props> = ({ text, className, maxHeight = 'none' }: Props) => { | ||
const dummyDiv = useRef<HTMLDivElement>() as React.MutableRefObject<HTMLDivElement>; | ||
const [doesFlowOver, setDoesFlowOver] = useState(false); | ||
const [collapsed, setCollapsed] = useState(true); | ||
|
||
const ariaLabel = collapsed ? 'Expand' : 'Collapse'; | ||
|
||
useEffect(() => { | ||
dummyDiv.current && setDoesFlowOver(dummyDiv.current.scrollHeight > dummyDiv.current?.offsetHeight); | ||
}, [maxHeight]); | ||
|
||
return ( | ||
<div className={classNames(styles.collapsibleText)}> | ||
<div ref={dummyDiv} className={styles.dummyDiv} style={{ maxHeight }}> | ||
{text} | ||
</div> | ||
<div | ||
className={classNames(styles.textContainer, className, { [styles.collapsed]: collapsed && doesFlowOver })} | ||
style={{ maxHeight: collapsed ? maxHeight : 'none' }} | ||
> | ||
{text} | ||
</div> | ||
{doesFlowOver && ( | ||
<IconButton | ||
aria-label={ariaLabel} | ||
className={classNames(styles.chevron, { [styles.expanded]: !collapsed })} | ||
onClick={() => setCollapsed(!collapsed)} | ||
> | ||
<ChevronRight /> | ||
</IconButton> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CollapsibleText; |
22 changes: 22 additions & 0 deletions
22
src/components/CollapsibleText/__snapshots__/CollapsibleText.test.tsx.snap
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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<CollapsibleText> renders and matches snapshot 1`] = ` | ||
<div> | ||
<div | ||
class="collapsibleText" | ||
> | ||
<div | ||
class="dummyDiv" | ||
style="max-height: none;" | ||
> | ||
Test... | ||
</div> | ||
<div | ||
class="textContainer" | ||
style="max-height: none;" | ||
> | ||
Test... | ||
</div> | ||
</div> | ||
</div> | ||
`; |
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 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 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