-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toggle button for file previews (#3290)
- Loading branch information
Showing
6 changed files
with
153 additions
and
67 deletions.
There are no files selected for viewing
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,44 @@ | ||
import cx from 'classnames' | ||
import * as React from 'react' | ||
import * as M from '@material-ui/core' | ||
|
||
import * as AWS from 'utils/AWS' | ||
import * as LogicalKeyResolver from 'utils/LogicalKeyResolver' | ||
|
||
const useStyles = M.makeStyles((t) => ({ | ||
root: { | ||
alignItems: 'center', | ||
display: 'flex', | ||
height: t.spacing(4), | ||
justifyContent: 'center', | ||
width: t.spacing(3), | ||
}, | ||
})) | ||
|
||
interface MenuProps { | ||
className?: string | ||
handle: LogicalKeyResolver.S3SummarizeHandle | ||
} | ||
|
||
export default function Menu({ className, handle }: MenuProps) { | ||
const classes = useStyles() | ||
const [anchorEl, setAnchorEl] = React.useState<HTMLElement | null>(null) | ||
const downloadUrl = AWS.Signer.useDownloadUrl(handle) | ||
const handleClose = React.useCallback(() => setAnchorEl(null), []) | ||
const handleOpen = React.useCallback((e) => setAnchorEl(e.currentTarget), []) | ||
return ( | ||
<div className={cx(classes.root, className)}> | ||
<M.IconButton onClick={handleOpen}> | ||
<M.Icon>more_vert</M.Icon> | ||
</M.IconButton> | ||
<M.Menu anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}> | ||
<M.MenuItem button component="a" href={downloadUrl} onClick={handleClose}> | ||
<M.ListItemIcon> | ||
<M.Icon>arrow_downward</M.Icon> | ||
</M.ListItemIcon> | ||
<M.ListItemText>Download</M.ListItemText> | ||
</M.MenuItem> | ||
</M.Menu> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import cx from 'classnames' | ||
import * as React from 'react' | ||
import * as M from '@material-ui/core' | ||
|
||
const useStyles = M.makeStyles((t) => ({ | ||
root: { | ||
alignItems: 'center', | ||
display: 'flex', | ||
height: t.spacing(4), | ||
justifyContent: 'center', | ||
}, | ||
icon: { | ||
transition: 'ease transform .15s', | ||
}, | ||
iconExpanded: { | ||
transform: `rotate(180deg)`, | ||
}, | ||
})) | ||
|
||
interface ToggleButtonProps extends M.BoxProps { | ||
className?: string | ||
expanded?: boolean | ||
onToggle?: () => void | ||
} | ||
|
||
export default function ToggleButton({ | ||
className, | ||
expanded, | ||
onToggle, | ||
...props | ||
}: ToggleButtonProps) { | ||
const classes = useStyles() | ||
return ( | ||
<M.Box className={cx(classes.root, className)} {...props}> | ||
<M.Button | ||
onClick={onToggle} | ||
startIcon={ | ||
<M.Icon className={cx(classes.icon, { [classes.iconExpanded]: expanded })}> | ||
{expanded ? 'unfold_less' : 'unfold_more'} | ||
</M.Icon> | ||
} | ||
variant="outlined" | ||
size="small" | ||
> | ||
{expanded ? 'Collapse' : 'Expand'} | ||
</M.Button> | ||
</M.Box> | ||
) | ||
} |
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