|
1 | 1 | import React from 'react'; |
2 | 2 | import { cx } from 'emotion'; |
| 3 | +import Collapse from '@material-ui/core/Collapse'; |
3 | 4 | import FileCopyOutlinedIcon from '@material-ui/icons/FileCopyOutlined'; |
| 5 | +import ExpandMoreIcon from '@material-ui/icons/ExpandMore'; |
| 6 | +import ExpandLessIcon from '@material-ui/icons/ExpandLess'; |
4 | 7 | import * as innerClasses from './header.styles'; |
5 | 8 |
|
6 | 9 | interface Props { |
@@ -39,28 +42,45 @@ interface CopyFieldProps { |
39 | 42 | export const CopyFieldComponent: React.FC<CopyFieldProps> = props => { |
40 | 43 | const { labelName, inputId, urlLink } = props; |
41 | 44 |
|
| 45 | + const [open, setOpen] = React.useState(true); |
| 46 | + |
| 47 | + const handleClick = () => { |
| 48 | + setOpen(!open); |
| 49 | + }; |
| 50 | + |
42 | 51 | return ( |
43 | 52 | <> |
44 | | - <label className={innerClasses.label} htmlFor={inputId}> |
| 53 | + <label |
| 54 | + className={innerClasses.label} |
| 55 | + htmlFor={inputId} |
| 56 | + onClick={handleClick} |
| 57 | + > |
45 | 58 | {labelName} |
| 59 | + {open ? ( |
| 60 | + <ExpandLessIcon className={innerClasses.collapseIcon} /> |
| 61 | + ) : ( |
| 62 | + <ExpandMoreIcon className={innerClasses.collapseIcon} /> |
| 63 | + )} |
46 | 64 | </label> |
47 | | - <div className={innerClasses.inputContainer}> |
48 | | - <input |
49 | | - id={inputId} |
50 | | - type="text" |
51 | | - className={innerClasses.input} |
52 | | - value={urlLink} |
53 | | - readOnly |
54 | | - aria-readonly |
55 | | - /> |
56 | | - <button |
57 | | - aria-label={`copy ${labelName}`} |
58 | | - className={innerClasses.button} |
59 | | - onClick={() => navigator.clipboard.writeText(urlLink)} |
60 | | - > |
61 | | - <FileCopyOutlinedIcon className={innerClasses.icon} /> |
62 | | - </button> |
63 | | - </div> |
| 65 | + <Collapse in={open} timeout="auto" unmountOnExit> |
| 66 | + <div className={innerClasses.inputContainer}> |
| 67 | + <input |
| 68 | + id={inputId} |
| 69 | + type="text" |
| 70 | + className={innerClasses.input} |
| 71 | + value={urlLink} |
| 72 | + readOnly |
| 73 | + aria-readonly |
| 74 | + /> |
| 75 | + <button |
| 76 | + aria-label={`copy ${labelName}`} |
| 77 | + className={innerClasses.button} |
| 78 | + onClick={() => navigator.clipboard.writeText(urlLink)} |
| 79 | + > |
| 80 | + <FileCopyOutlinedIcon className={innerClasses.icon} /> |
| 81 | + </button> |
| 82 | + </div> |
| 83 | + </Collapse> |
64 | 84 | </> |
65 | 85 | ); |
66 | 86 | }; |
0 commit comments