forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Presentation mode (elastic#177)
* chore: fullscreen redux boilerplate * chore: fullscreen api wrapper module helper module for dealing with the fullscreen api, which exposes methods to setting up the change handlers, creating fullscreen element handlers, and check to see if the fullscreen api is accessible * chore: initialize the fullscreen module on startup * chore: add fullscreen logic and control components * feat: add fullscreen control to workpad header * fix: bug in firefox with fullscreen api in the event handler, the target isn't the element in firefox, it looks like the body is... * feat: use fullscreen component in workpad when workpad is in fullscreen mode, use css transform to scale it to the display * fix: correctly position the fullscreen workpad in firefox * feat: add keymap rules for presentation mode * fix: don't select elements in fullscreen mode * feat: add keyboard navigation in presentation mode
- Loading branch information
Showing
18 changed files
with
321 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export const Fullscreen = ({ ident, isFullscreen, windowSize, children }) => ( | ||
<div id={ident} allowFullScreen> | ||
{children({ isFullscreen, windowSize })} | ||
</div> | ||
); | ||
|
||
Fullscreen.propTypes = { | ||
ident: PropTypes.string.isRequired, | ||
isFullscreen: PropTypes.bool, | ||
windowSize: PropTypes.object, | ||
children: PropTypes.func, | ||
}; |
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,36 @@ | ||
import { connect } from 'react-redux'; | ||
import { compose, withProps, withState, withHandlers, lifecycle } from 'recompose'; | ||
import { debounce } from 'lodash'; | ||
import { Fullscreen as Component } from './fullscreen'; | ||
import { getFullscreen } from '../../state/selectors/app.js'; | ||
import { defaultIdent } from '../../lib/fullscreen.js'; | ||
|
||
const mapStateToProps = (state) => ({ | ||
isFullscreen: getFullscreen(state), | ||
}); | ||
|
||
const getWindowSize = () => ({ | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
}); | ||
|
||
export const Fullscreen = compose( | ||
withProps(({ ident }) => ({ | ||
ident: ident || defaultIdent, | ||
})), | ||
withState('windowSize', 'setWindowSize', getWindowSize()), | ||
withHandlers({ | ||
windowResizeHandler: ({ setWindowSize }) => debounce(() => { | ||
setWindowSize(getWindowSize()); | ||
}, 100), | ||
}), | ||
connect(mapStateToProps), | ||
lifecycle({ | ||
componentWillMount() { | ||
window.addEventListener('resize', this.props.windowResizeHandler); | ||
}, | ||
componentWillUnmount() { | ||
window.removeEventListener('resize', this.props.windowResizeHandler); | ||
}, | ||
}), | ||
)(Component); |
50 changes: 50 additions & 0 deletions
50
public/components/fullscreen_control/fullscreen_control.js
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,50 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { createListener, canFullscreen } from '../../lib/fullscreen.js'; | ||
|
||
// TODO: this is a class because this has to use ref, and it seemed best to allow | ||
// multile instances of this component... can we use ref with SFCs? | ||
export class FullscreenControl extends React.PureComponent { | ||
componentDidMount() { | ||
// check that the fullscreen api is available, deactivate control if not | ||
const el = this.node; | ||
if (!canFullscreen(el)) { | ||
this.props.setActive(false); | ||
return; | ||
} | ||
|
||
// listen for changes to the fullscreen element, update state to match | ||
this.fullscreenListener = createListener(({ fullscreen, element }) => { | ||
// if the app is the fullscreen element, set the app state | ||
if (!element || element.id === this.props.ident) this.props.setFullscreen(fullscreen); | ||
}); | ||
} | ||
|
||
componentWillUmount() { | ||
// remove the fullscreen event listener | ||
this.fullscreenListener && this.fullscreenListener(); | ||
} | ||
|
||
render() { | ||
const { isActive, children, isFullscreen, onFullscreen } = this.props; | ||
if (!isActive) return null; | ||
return ( | ||
<span ref={node => this.node = node}> | ||
{children({ isFullscreen, onFullscreen })} | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
FullscreenControl.propTypes = { | ||
isActive: PropTypes.bool.isRequired, | ||
setActive: PropTypes.func.isRequired, | ||
setFullscreen: PropTypes.func.isRequired, | ||
children: PropTypes.func.isRequired, | ||
ident: PropTypes.string.isRequired, | ||
onFullscreen: PropTypes.oneOfType([ | ||
PropTypes.func, | ||
PropTypes.bool, | ||
]), | ||
isFullscreen: PropTypes.bool, | ||
}; |
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,32 @@ | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { compose, withState, withProps } from 'recompose'; | ||
import { FullscreenControl as Component } from './fullscreen_control'; | ||
import { defaultIdent, createHandler } from '../../lib/fullscreen.js'; | ||
import { setFullscreen } from '../../state/actions/transient.js'; | ||
import { getFullscreen } from '../../state/selectors/app.js'; | ||
|
||
const mapStateToProps = (state) => ({ | ||
isFullscreen: getFullscreen(state), | ||
}); | ||
|
||
const mapDispatchToProps = { | ||
setFullscreen, | ||
}; | ||
|
||
export const FullscreenControl = compose( | ||
connect(mapStateToProps, mapDispatchToProps), | ||
withState('isActive', 'setActive', true), | ||
withProps(({ ident, isActive }) => ({ | ||
ident: ident || defaultIdent, | ||
onFullscreen: (ev) => { | ||
if (!isActive) return; | ||
const fullscreenHandler = createHandler(ident || defaultIdent); | ||
fullscreenHandler(ev); | ||
}, | ||
})), | ||
)(Component); | ||
|
||
FullscreenControl.propTypes = { | ||
ident: PropTypes.string, | ||
}; |
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
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
Oops, something went wrong.