-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathExpandable.js
58 lines (52 loc) · 1.62 KB
/
Expandable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { useState } from 'react';
import IconButton from './IconButton';
import Scrollable from './Scrollable';
import { ChevronUpIcon, ChevronDownIcon } from '@primer/octicons-react';
function Expandable({ excerpt, children, className, variant, labelText }) {
const [expanded, setExpanded] = useState(false);
return (
<section
className={[
'flex-none py-2 px-4 flex justify-between w-full',
expanded ? 'expanded items-start' : 'collapsed items-center',
className,
]
.filter(Boolean)
.join(' ')}
aria-label={labelText}
>
{expanded && (
<div className="absolute bottom-0 -ml-4 h-full w-full overflow-hidden bg-inherit rounded-inherit">
<Scrollable variant={variant}>
<div className="whitespace-pre-wrap p-4">
{children} <div className="py-2 px-4"> </div>
</div>
</Scrollable>
<IconButton
className="bg-inherit absolute bottom-0 right-0 mx-4 my-2"
variant={variant}
onClick={() => setExpanded(!expanded)}
>
<ChevronDownIcon />
</IconButton>
</div>
)}
{expanded || !children ? (
<div> </div>
) : (
<div className="truncate mr-8 w-full flex justify-between direction">
{excerpt || children}
</div>
)}
<IconButton
className="bg-inherit"
variant={variant}
onClick={() => setExpanded(!expanded)}
title="expand"
>
<ChevronUpIcon />
</IconButton>
</section>
);
}
export default Expandable;