-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(widgets): New LoadingWidget #9485
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3ba23a1
feat(widgets): New LoadingWidget
ibgreen a836dc1
prettier
ibgreen 5a7c8e4
underscore
ibgreen 2441652
Merge branch 'master' into ib/loading-widget
ibgreen 0846673
Align icon definition with existing pattern
chrisgervang 132fdd1
wip
ibgreen 40c7559
Merge branch 'master' into ib/loading-widget
ibgreen 20a5414
prettier
ibgreen 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
This file contains hidden or 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,37 @@ | ||
# LoadingWidget | ||
|
||
This widget shows a spinning indicator while any deck.gl layers are loading data. | ||
|
||
## Props | ||
|
||
#### `id` (string, optional) {#id} | ||
|
||
Default: `'loading'` | ||
|
||
The `id` must be unique among all your widgets at a given time. | ||
|
||
Note: It is necessary to set `id` explicitly if you have more than once instance of the same widget. | ||
|
||
#### `placement` (string, optional) {#placement} | ||
|
||
Default: `'top-left'` | ||
|
||
Widget position within the view relative to the map container. Valid options are `top-left`, `top-right`, `bottom-left`, `bottom-right`, or `fill`. | ||
|
||
#### `label` (string, optional) {#label} | ||
|
||
Tooltip message displayed while hovering a mouse over the widget. | ||
|
||
Default: `'Loading data'` | ||
|
||
#### `style` (object, optional) {#style} | ||
|
||
Default: `{}` | ||
|
||
Additional CSS styles for the widget. camelCase CSS properties (e.g. `backgroundColor`) and kabab-case CSS variables are accepted (e.g. `--button-size`). | ||
|
||
#### `className` (string, optional) {#classname} | ||
|
||
Default: `undefined` | ||
|
||
Class name to attach to the widget element. The element has the default class name of `deck-widget deck-loading-widget`. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
// deck.gl | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) vis.gl contributors | ||
|
||
/* global document */ | ||
import type {WidgetPlacement, Layer} from '@deck.gl/core'; | ||
import {render} from 'preact'; | ||
import {WidgetImpl, WidgetImplProps} from './widget-impl'; | ||
import {IconButton} from './components'; | ||
|
||
/** Properties for the LoadingWidget */ | ||
export type LoadingWidgetProps = WidgetImplProps & { | ||
/** Widget positioning within the view. Default 'top-left'. */ | ||
placement?: WidgetPlacement; | ||
/** Tooltip message when loading */ | ||
label?: string; | ||
}; | ||
|
||
/** | ||
* A non-interactive widget that shows a loading spinner if any layers are loading data | ||
*/ | ||
export class LoadingWidget extends WidgetImpl<LoadingWidgetProps> { | ||
static defaultProps: Required<LoadingWidgetProps> = { | ||
...WidgetImpl.defaultProps, | ||
id: 'loading', | ||
placement: 'top-left', | ||
label: 'Loading layer data' | ||
}; | ||
|
||
className = 'deck-widget-loading'; | ||
placement: WidgetPlacement = 'top-left'; | ||
loading = true; | ||
|
||
constructor(props: LoadingWidgetProps = {}) { | ||
super({...LoadingWidget.defaultProps, ...props}); | ||
this.placement = props.placement ?? this.placement; | ||
} | ||
|
||
setProps(props: Partial<LoadingWidgetProps>) { | ||
this.placement = props.placement ?? this.placement; | ||
super.setProps(props); | ||
} | ||
|
||
onRenderHTML() { | ||
const element = this.element; | ||
if (!element) return; | ||
render( | ||
// TODO(ibgreen) - this should not be a button, but styling is so nested that it is easier to reuse this component. | ||
this.loading && ( | ||
<IconButton | ||
className="deck-widget-spinner-icon" | ||
label={this.props.label} | ||
onClick={this.handleClick.bind(this)} | ||
/> | ||
), | ||
element | ||
); | ||
} | ||
|
||
onRedraw({layers}: {layers: Layer[]}): void { | ||
const loading = !layers.some(layer => !layer.isLoaded); | ||
if (loading !== this.loading) { | ||
this.loading = loading; | ||
this.onRenderHTML(); | ||
} | ||
} | ||
|
||
// TODO(ibgreen) - this should not be a button, see above. | ||
handleClick() {} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -116,6 +116,16 @@ | |
); | ||
} | ||
|
||
@keyframes spin { | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.deck-widget.deck-widget-loading button.deck-widget-spinner-icon .deck-widget-icon { | ||
animation: spin 1s linear infinite; | ||
} | ||
|
||
.deck-pseudo-fullscreen { | ||
height: 100% !important; | ||
left: 0 !important; | ||
|
@@ -171,3 +181,8 @@ | |
); | ||
} | ||
|
||
.deck-widget-spinner-icon { | ||
--deck-widget-icon-loading: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" ><path d="M21 12a9 9 0 1 1-6.219-8.56" /></svg>'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this take priority over user defined variable from somewhere higher up in the DOM (e.g. |
||
mask-image: var(--deck-widget-icon-loading); | ||
-webkit-mask-image: var(--deck-widget-icon-loading); | ||
} | ||
chrisgervang marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
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.
Perhaps you can just disable pointer events with CSS for this widget?