-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Viewer bottomSheet for mobile
- Loading branch information
Showing
4 changed files
with
167 additions
and
4 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,74 @@ | ||
import React, { useState } from 'react' | ||
import { BottomSheet } from 'mui-bottom-sheet' | ||
import { makeStyles } from '@material-ui/core/styles' | ||
|
||
const useStyles = ({ isTopPosition }) => ({ | ||
root: { | ||
borderTopLeftRadius: '1rem', | ||
borderTopRightRadius: '1rem', | ||
transition: 'border-radius 0.5s', | ||
boxShadow: '0 6px 16px 0 rgba(0, 0, 0, 0.5)', | ||
...(isTopPosition && { | ||
borderTopLeftRadius: 0, | ||
borderTopRightRadius: 0 | ||
}) | ||
} | ||
}) | ||
|
||
const useClasses = makeStyles({ | ||
header: { | ||
height: '2.5rem', | ||
width: '100%', | ||
position: 'relative', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'center' | ||
}, | ||
indicator: { | ||
width: '4rem', | ||
height: '0.25rem', | ||
borderRadius: '99px', | ||
backgroundColor: 'var(--dividerColor)' | ||
} | ||
}) | ||
|
||
const BottomSheetWrapper = ({ children }) => { | ||
const [isTopPosition, setIsTopPosition] = useState(false) | ||
const classes = useClasses() | ||
const styles = useStyles({ isTopPosition }) | ||
|
||
const toolbar = document.querySelector('[role="viewer-toolbar"]') | ||
const maxHeight = toolbar | ||
? window.innerHeight - toolbar.offsetHeight | ||
: window.innerHeight | ||
const mediumHeight = maxHeight * 0.6 | ||
const minHeight = 87 | ||
|
||
const handleOnIndexChange = snapIndex => { | ||
const maxHeightSnapIndex = 2 | ||
if (snapIndex === maxHeightSnapIndex && !isTopPosition) { | ||
setIsTopPosition(true) | ||
} | ||
if (snapIndex !== maxHeightSnapIndex && isTopPosition) { | ||
setIsTopPosition(false) | ||
} | ||
} | ||
|
||
return ( | ||
<BottomSheet | ||
peekHeights={[minHeight, mediumHeight, maxHeight]} | ||
defaultHeight={minHeight} | ||
backdrop={false} | ||
fullHeight={false} | ||
onIndexChange={snapIndex => handleOnIndexChange(snapIndex)} | ||
styles={{ root: styles.root }} | ||
> | ||
<div data-testid="bottomSheet-header" className={classes.header}> | ||
<div className={classes.indicator} /> | ||
</div> | ||
{children} | ||
</BottomSheet> | ||
) | ||
} | ||
|
||
export default BottomSheetWrapper |
55 changes: 55 additions & 0 deletions
55
src/drive/web/modules/viewer/Footer/BottomSheetContent.jsx
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,55 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import cx from 'classnames' | ||
import { makeStyles } from '@material-ui/core/styles' | ||
|
||
import { isMobileApp } from 'cozy-device-helper' | ||
import Paper from 'cozy-ui/transpiled/react/Paper' | ||
import Typography from 'cozy-ui/transpiled/react/Typography' | ||
import Stack from 'cozy-ui/transpiled/react/Stack' | ||
|
||
import Sharing from './Sharing' | ||
import ForwardButton from './ForwardButton' | ||
import DownloadButton from './DownloadButton' | ||
import getPanelBlocks, { panelBlocksSpecs } from '../Panel/getPanelBlocks' | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
stack: { | ||
backgroundColor: theme.palette.background.default | ||
} | ||
})) | ||
|
||
const BottomSheetContent = ({ file }) => { | ||
const panelBlocks = getPanelBlocks({ panelBlocksSpecs, file }) | ||
const FileActionButton = isMobileApp() ? ForwardButton : DownloadButton | ||
const styles = useStyles() | ||
|
||
return ( | ||
<Stack | ||
spacing="s" | ||
className={cx('u-flex u-flex-column u-ov-hidden', styles.stack)} | ||
> | ||
<Paper className={'u-flex u-ph-1 u-pb-1'} elevation={2} square> | ||
<Sharing file={file} /> | ||
<FileActionButton file={file} /> | ||
</Paper> | ||
{panelBlocks.map((PanelBlock, index) => ( | ||
<Paper | ||
key={index} | ||
elevation={index === panelBlocks.length - 1 ? 0 : 2} | ||
square | ||
> | ||
<Typography variant="h4"> | ||
<PanelBlock file={file} /> | ||
</Typography> | ||
</Paper> | ||
))} | ||
</Stack> | ||
) | ||
} | ||
|
||
BottomSheetContent.propTypes = { | ||
file: PropTypes.object.isRequired | ||
} | ||
|
||
export default BottomSheetContent |
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