-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(events-v2) Improve scrolling for event modal #13710
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
src/sentry/static/sentry/app/components/modalDialog.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,140 @@ | ||
import React from 'react'; | ||
import styled from 'react-emotion'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import InlineSvg from 'app/components/inlineSvg'; | ||
import space from 'app/styles/space'; | ||
import {callIfFunction} from 'app/utils/callIfFunction'; | ||
|
||
/** | ||
* Simple/Naive implementation of a dialog/modal window. | ||
* | ||
* The API this component exposes is intentionally compatible with | ||
* reach-ui/dialog as in the near future we should replace this component | ||
* with that library. This implementation doesn't handle | ||
* focus-lock and has poorer accessibility support. | ||
*/ | ||
class ModalDialog extends React.Component { | ||
static propTypes = { | ||
/** | ||
* Function that returns the close button element | ||
* will be passed an object of options with `handleDismiss` | ||
* event handler for closing the modal | ||
*/ | ||
dismissButton: PropTypes.func, | ||
|
||
/** | ||
* Callback invoked when the modal is closed if set. | ||
*/ | ||
onDismiss: PropTypes.func.isRequired, | ||
|
||
/** | ||
* Whether or not the modal should display open. | ||
*/ | ||
isOpen: PropTypes.bool, | ||
|
||
className: PropTypes.string, | ||
}; | ||
|
||
static defaultProps = { | ||
isOpen: true, | ||
}; | ||
|
||
handleClose = event => { | ||
event.preventDefault(); | ||
callIfFunction(this.props.onDismiss); | ||
}; | ||
|
||
renderDismiss() { | ||
const {dismissButton} = this.props; | ||
if (dismissButton) { | ||
return dismissButton({handleDismiss: this.handleClose}); | ||
} | ||
return <DismissButton onClick={this.handleClose} size={30} />; | ||
} | ||
|
||
render() { | ||
const {isOpen, children, className} = this.props; | ||
|
||
if (!isOpen) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ModalScrollTrap> | ||
<ModalOverlay /> | ||
<ModalContainer aria-modal="true" className={className}> | ||
{this.renderDismiss()} | ||
{children} | ||
</ModalContainer> | ||
</ModalScrollTrap> | ||
); | ||
} | ||
} | ||
|
||
const ModalOverlay = styled('div')` | ||
position: fixed; | ||
top: 0px; | ||
left: 0px; | ||
right: 0px; | ||
bottom: 0px; | ||
background: ${p => p.theme.foreground}; | ||
opacity: 0.5; | ||
z-index: ${p => p.theme.zIndex.modal}; | ||
`; | ||
|
||
const ModalScrollTrap = styled('div')` | ||
position: fixed; | ||
top: 0px; | ||
left: 0px; | ||
right: 0px; | ||
bottom: 0px; | ||
overflow-x: hidden; | ||
overflow-y: auto; | ||
z-index: ${p => p.theme.zIndex.modal}; | ||
`; | ||
|
||
// Define some basic styling. Each modal usage | ||
// can pass a className prop with more styles. | ||
const ModalContainer = styled('div')` | ||
position: absolute; | ||
background: #fff; | ||
|
||
margin: ${space(3)}; | ||
padding: ${space(3)}; | ||
|
||
border: 1px solid ${p => p.theme.borderLight}; | ||
border-radius: ${p => p.theme.borderRadius}; | ||
box-shadow: ${p => p.theme.dropShadowHeavy}; | ||
|
||
z-index: ${p => p.theme.zIndex.modal}; | ||
`; | ||
|
||
const CircleButton = styled('button')` | ||
background: #fff; | ||
border-radius: ${p => p.size / 2}px; | ||
padding: ${p => p.size / 4}px; | ||
line-height: ${p => p.size * 0.4}px; | ||
height: ${p => p.size}px; | ||
box-shadow: ${p => p.theme.dropShadowLight}; | ||
border: 1px solid ${p => p.theme.borderDark}; | ||
|
||
position: absolute; | ||
top: -${p => p.size / 2}px; | ||
right: -${p => p.size / 2}px; | ||
`; | ||
|
||
const DismissButton = props => { | ||
const iconSize = props.size * 0.4; | ||
return ( | ||
<CircleButton size={props.size} onClick={props.onClick}> | ||
<InlineSvg src="icon-close" size={`${iconSize}px`} /> | ||
</CircleButton> | ||
); | ||
}; | ||
DismissButton.propTypes = { | ||
onClick: PropTypes.func, | ||
size: PropTypes.number.isRequired, | ||
}; | ||
|
||
export default ModalDialog; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a generic component? Should it extend
app/components/Button
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have more places we need circle buttons? I think the extension and general component would make sense if we had more places to use it. Another approach could be to have a
shape
property on button that acceptsrect
andcircle
.