-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maps] keydown+scroll to zoom (#135330)
* [maps] shift+scroll to zoom * content * only enable keydown scroll zoom in embeddable * scss lint fix * one more scss lint fix * replace shift with control * lint * use smaller css transition so message hides faster when keydown+scrolling * h3 and small text * Update x-pack/plugins/maps/public/connected_components/mb_map/keydown_scroll_zoom/_index.scss Co-authored-by: Michael Marcialis <[email protected]> * Update x-pack/plugins/maps/public/connected_components/mb_map/keydown_scroll_zoom/_index.scss Co-authored-by: Michael Marcialis <[email protected]> * Update x-pack/plugins/maps/public/connected_components/mb_map/keydown_scroll_zoom/keydown_scroll_zoom.tsx Co-authored-by: Michael Marcialis <[email protected]> * Update x-pack/plugins/maps/public/connected_components/mb_map/keydown_scroll_zoom/keydown_scroll_zoom.tsx Co-authored-by: Michael Marcialis <[email protected]> * clean-up Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Michael Marcialis <[email protected]>
- Loading branch information
1 parent
40359a6
commit 4a82f98
Showing
12 changed files
with
119 additions
and
25 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
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
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/maps/public/connected_components/mb_map/keydown_scroll_zoom/_index.scss
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,22 @@ | ||
.mapKeydownScrollZoom { | ||
background: transparentize($euiColorInk, .5); | ||
left: 0; | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
position: absolute; | ||
z-index: $euiZLevel2; | ||
pointer-events: none; | ||
display: flex; | ||
justify-content: center; | ||
align-content: center; | ||
flex-direction: column; | ||
opacity: 0; | ||
transition: opacity $euiAnimSpeedNormal ease $euiAnimSpeedNormal; | ||
padding: $euiSize; | ||
} | ||
|
||
.mapKeydownScrollZoom--show { | ||
opacity: 1; | ||
transition-duration: $euiAnimSpeedFast; | ||
} |
87 changes: 87 additions & 0 deletions
87
...ugins/maps/public/connected_components/mb_map/keydown_scroll_zoom/keydown_scroll_zoom.tsx
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,87 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import classNames from 'classnames'; | ||
import { EuiText } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import type { Map as MbMap, MapMouseEvent } from '@kbn/mapbox-gl'; | ||
|
||
const isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0; | ||
|
||
interface Props { | ||
mbMap: MbMap; | ||
} | ||
|
||
interface State { | ||
show: boolean; | ||
} | ||
|
||
export class KeydownScrollZoom extends Component<Props, State> { | ||
private _isMounted = false; | ||
private _hideTimeout: ReturnType<typeof setTimeout> | undefined; | ||
|
||
state: State = { | ||
show: false, | ||
}; | ||
|
||
componentDidMount() { | ||
this._isMounted = true; | ||
this.props.mbMap.on('wheel', this._onWheel); | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
this.props.mbMap.off('wheel', this._onWheel); | ||
} | ||
|
||
_onWheel = (event: MapMouseEvent) => { | ||
if (this._hideTimeout) { | ||
clearTimeout(this._hideTimeout); | ||
this._hideTimeout = undefined; | ||
} | ||
|
||
if ((isMac && event.originalEvent.metaKey) || (!isMac && event.originalEvent.ctrlKey)) { | ||
this.setState({ show: false }); | ||
return; | ||
} | ||
|
||
this.setState({ show: true }); | ||
this._hideTimeout = setTimeout(() => { | ||
if (this._isMounted) { | ||
this.setState({ show: false }); | ||
} | ||
}, 1500); | ||
event.preventDefault(); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<aside | ||
className={classNames('mapKeydownScrollZoom', { | ||
'mapKeydownScrollZoom--show': this.state.show, | ||
})} | ||
> | ||
<EuiText textAlign="center" size="s" color="ghost"> | ||
<h3> | ||
{i18n.translate('xpack.maps.keydownScrollZoom.keydownToZoomInstructions', { | ||
defaultMessage: 'Use {key} + scroll to zoom the map', | ||
values: { key: isMac ? '⌘' : 'control' }, | ||
})} | ||
</h3> | ||
|
||
<p> | ||
{i18n.translate('xpack.maps.keydownScrollZoom.keydownClickAndDragZoomInstructions', { | ||
defaultMessage: | ||
'Use shift + click and drag to zoom the map to fit within a bounding box', | ||
})} | ||
</p> | ||
</EuiText> | ||
</aside> | ||
); | ||
} | ||
} |
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
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