Skip to content

Commit 5777f94

Browse files
authored
docs(widgets): Document new widgets (#9590)
1 parent 9c213f4 commit 5777f94

16 files changed

+439
-239
lines changed

docs/api-reference/core/widget.md

Lines changed: 36 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,36 @@
11
# Widget
22

3-
A widget is a UI component that can interact with deck.gl's cameras and layers. Some examples are:
3+
A widget is a UI component that can interact with deck.gl's layers and views.
4+
You can write your own widgets, or use any of the many ready-to-use widgets in the [`@deck.gl/widgets`](../widgets/overview.md) module.
45

5-
- A tooltip that follows the pointer and provide information for the hovered object
6-
- A marker pinned to a geo-location containing HTML content
7-
- Buttons to manipulate the camera, such as +/- zoom buttons, a compass rose for the MapView, a gimble widget for the OrbitView, etc.
8-
- A legend that offers visual comparison of sizes, colors etc. corresponding to the rendered layers and viewport. For example a distance ruler, a color scale for the HeatmapLayer, etc.
6+
## Usage
97

10-
You may find many ready-to-use widgets in the `@deck.gl/widgets` module.
8+
The `Widget` class is a base class used to define new widgets and should not be instantiated directly by an application. See the [Widget Documentation](../widgets/overview.md) for information about how to write your own widgets.
119

12-
The `Widget` class is not used directly by an app. It is a base class used to define new widgets.
10+
## Types
1311

12+
#### `WidgetProps` (object) {#props}
1413

15-
A widget should inherit the `Widget` class. Here is a custom widget that shows a spinner while layers are loading:
16-
17-
```ts
18-
import {Deck, Widget} from '@deck.gl/core';
19-
20-
class LoadingIndicator extends Widget {
21-
element?: HTMLDivElement;
22-
size: number;
23-
24-
constructor(options: {
25-
size: number;
26-
}) {
27-
this.size = options.size;
28-
}
29-
30-
onRenderHTML(el: HTMLElement) {
31-
el.className = 'spinner';
32-
el.style.width = `${this.size}px`;
33-
// TODO - create animation for .spinner in the CSS stylesheet
34-
}
35-
36-
onRedraw({layers}) {
37-
const isVisible = layers.some(layer => !layer.isLoaded);
38-
this.rootElement.style.display = isVisible ? 'block' : 'none';
39-
}
40-
}
41-
42-
new Deck({
43-
widgets: [new LoadingIndicator({size: 48})]
44-
});
45-
```
46-
47-
## Widget Interface
48-
49-
When a widget instance is added to Deck, the user can optionally specify a `viewId` that it is attached to (default `null`). If assigned, this widget will only respond to events occurred inside the specific view that matches this id.
50-
51-
### Members
52-
53-
A `Widget` implements the following members.
14+
Options for the widget, as passed into the constructor and can be updated with `setProps`.
5415

5516
#### `id` {#id}
5617

57-
Unique identifier of the widget.
58-
59-
#### `props` (object) {#props}
60-
61-
Any options for the widget, as passed into the constructor and can be updated with `setProps`.
18+
The `id` string must be unique among all your widgets at a given time. While a default `id` is provided, it is recommended to set `id` explicitly if you have multiple widgets of the same type.
6219

6320
#### `viewId` (string | null) {#viewid}
6421

22+
The `viewId` prop controls how a widget interacts with views. If `viewId` is defined, the widget is placed in that view and interacts exclusively with it; otherwise, it is placed in the root widget container and affects all views.
23+
6524
* Default: `null`
6625

26+
When a widget instance is added to Deck, the user can optionally specify a `viewId` that it is attached to (default `null`). If assigned, this widget will only respond to events occurred inside the specific view that matches this id.
27+
6728
The id of the view that the widget is attached to. If `null`, the widget receives events from all views. Otherwise, it only receives events from the view that matches this id.
6829

6930
#### `placement` (string, optional) {#placement}
7031

32+
Widget position within the view relative to the map container.
33+
7134
* Default: `'top-left'`
7235

7336
Widget positioning within the view. One of:
@@ -78,27 +41,40 @@ Widget positioning within the view. One of:
7841
- `'bottom-right'`
7942
- `'fill'`
8043

81-
### Methods
44+
#### `style`
8245

83-
#### `setProps` {#setprops}
46+
CSS inline style overrides.
8447

85-
Optional. Called to update widget options.
86-
87-
#### `updateHTML` {#updatehtml}
88-
89-
Updates the widget. Normally called automatically.
48+
```ts
49+
style?: Partial<CSSStyleDeclaration>;
50+
```
9051

52+
#### `className`
9153

92-
### Lifecycle Methods
54+
Additional CSS classnames for interaction with custom stylesheets.
55+
56+
```ts
57+
className?: string;
58+
```
9359

94-
The following methods are available when implementing a new widget.
60+
### Methods for Widget Writers
9561

9662
#### `constructor`
9763

9864
Supply the props and default props to the base class.
9965

66+
#### `setProps` {#setprops}
67+
68+
Called to update widget options.
69+
70+
#### `updateHTML` {#updatehtml}
71+
72+
Updates the widget. Called by the specific widget when state has changed. Calls `onRenderHTML()`
73+
10074
#### `onRenderHTML`
10175

76+
This function is implemented by the specific widget subclass to update the HTML for the widget
77+
10278
#### `onAdd` {#onadd}
10379

10480
Required. Called when the widget is added to a Deck instance.

docs/api-reference/widgets/compass-widget.md

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,17 @@ const deck = new Deck({
1616
});
1717
```
1818

19-
## Props
19+
## Types
2020

21-
#### `id` (string, optional) {#id}
21+
### `CompassWidgetProps`
2222

23-
Default: `'compass'`
23+
The `CompassWidget` accepts the generic [`WidgetProps`](../core/widget.md#props):
2424

25-
The `id` must be unique among all your widgets at a given time. It's recommended to set `id` explicitly if you have multiple widgets of the same type.
26-
27-
#### `viewId` (string, optional) {#viewid}
28-
29-
Default: `null`
30-
31-
The `viewId` prop controls how a widget interacts with views. If `viewId` is defined, the widget is placed in that view and interacts exclusively with it; otherwise, it is placed in the root widget container and affects all views.
32-
33-
#### `placement` (string, optional) {#placement}
34-
35-
Default: `'top-left'`
36-
37-
Widget position within the view relative to the map container. Valid options are `top-left`, `top-right`, `bottom-left`, `bottom-right`, or `fill`.
25+
- `id` (default `'compass'`) - Unique id for this widget
26+
- `placement` (default `'top-left'`) - Widget position within the view relative to the map container
27+
- `viewId` (default `null`) - The `viewId` prop controls how a widget interacts with views.
28+
- `style` (default `{}`) - Additional inline styles on the top HTML element.
29+
- `className` (default `''`) - Additional classnames on the top HTML element.
3830

3931
#### `label` (string, optional) {#label}
4032

@@ -48,18 +40,6 @@ Default: `200`
4840

4941
Bearing and pitch reset transition duration in milliseconds.
5042

51-
#### `style` (object, optional) {#style}
52-
53-
Default: `{}`
54-
55-
Additional CSS styles for the widget. camelCase CSS properties (e.g. `backgroundColor`) and kabab-case CSS variables are accepted (e.g. `--button-size`).
56-
57-
#### `className` (string, optional) {#classname}
58-
59-
Default: `undefined`
60-
61-
Class name to attach to the widget element. The element has the default class name of `deck-widget deck-compass-widget`.
62-
6343
## Styles
6444

6545
Learn more about how to replace icons in the [styling guide](/docs/api-reference/widgets/styling#replacing-icons).

docs/api-reference/widgets/fps-widget.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ new Deck({
1515
});
1616
```
1717

18-
## Properties
18+
## Types
1919

20-
The `FpsWidget` accepts the generic [`WidgetProps`](./overview.md#widgetprops) and
21-
supports one additional option:
20+
### `FpsWidgetProps`
2221

23-
### `placement` (String)
24-
25-
- Default: `'top-left'`
26-
- Position of the widget within the view. One of `top-left`, `top-right`, `bottom-left`,
27-
`bottom-right`.
22+
The `FpsWidget` accepts the generic [`WidgetProps`](../core/widget.md#props):
2823

24+
- `id` (default `'fps'`) - Unique id for this widget
25+
- `placement` (default `'top-left'`) - Widget position within the view relative to the map container
26+
- `viewId` (default `null`) - The `viewId` prop controls how a widget interacts with views.
27+
- `style` (default `{}`) - Additional inline styles on the top HTML element.
28+
- `className` (default `''`) - Additional classnames on the top HTML element.

docs/api-reference/widgets/fullscreen-widget.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ const deck = new Deck({
1616
});
1717
```
1818

19-
## Props
19+
## Types
2020

21-
#### `id` (string, optional) {#id}
21+
### `FullscreenWidgetProps`
2222

23-
Default: `'fullscreen'`
23+
The `FullscreenWidget` accepts the generic [`WidgetProps`](../core/widget.md#props):
2424

25-
The `id` must be unique among all your widgets at a given time. It's recommended to set `id` explicitly if you have multiple widgets of the same type.
26-
27-
#### `placement` (string, optional) {#placement}
28-
29-
Default: `'top-left'`
30-
31-
Widget position within the view relative to the map container. Valid options are `top-left`, `top-right`, `bottom-left`, `bottom-right`, or `fill`.
25+
- `id` (default `'fullscreen'`) - Unique id for this widget
26+
- `placement` (default `'top-left'`) - Widget position within the view relative to the map container
27+
- `viewId` (default `null`) - The `viewId` prop controls how a widget interacts with views.
28+
- `style` (default `{}`) - Additional inline styles on the top HTML element.
29+
- `className` (default `''`) - Additional classnames on the top HTML element.
3230

3331
#### `container` (HTMLElement, optional) {#container}
3432

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {WidgetPreview} from '@site/src/doc-demos/widgets';
2+
import {_GeolocateWidget} from '@deck.gl/widgets';
3+
4+
# GeolocateWidget (Experimental)
5+
6+
<img src="https://img.shields.io/badge/from-v9.2-green.svg?style=flat-square" alt="from v9.2" />
7+
8+
This widget allows users to input geographic coordinates (decimal or DMS format) and fly the view to that location. Enter coordinates in the text box and click "Go" or press Enter.
9+
10+
<WidgetPreview cls={_GeolocateWidget}/>
11+
12+
```ts
13+
import {_GeolocateWidget as GeolocateWidget} from '@deck.gl/widgets';
14+
import {Deck} from '@deck.gl/core';
15+
16+
const deck = new Deck({
17+
widgets: [new GeolocateWidget({label: 'Geolocate', transitionDuration: 300})]
18+
});
19+
```
20+
21+
## Types
22+
23+
### `GeolocateWidgetProps`
24+
25+
The `GeolocateWidget` accepts the generic [`WidgetProps`](../core/widget.md#props):
26+
27+
- `id` (default `'geolocate'`) - Unique id for this widget
28+
- `placement` (default `'top-left'`) - Widget position within the view relative to the map container
29+
- `viewId` (default `null`) - The `viewId` prop controls how a widget interacts with views.
30+
- `style` (default `{}`) - Additional inline styles on the top HTML element.
31+
- `className` (default `''`) - Additional classnames on the top HTML element.
32+
33+
#### `label` (string, optional) {#label}
34+
35+
Default: `'Geolocate'`
36+
37+
Placeholder text and tooltip for the input box.
38+
39+
#### `transitionDuration` (number, optional) {#transitionduration}
40+
41+
Default: `200`
42+
43+
View transition duration in milliseconds.
44+
45+
#### `style` (object, optional) {#style}
46+
47+
Default: `{}`
48+
49+
Additional CSS styles for the widget container.
50+
51+
#### `className` (string, optional) {#classname}
52+
53+
Default: None
54+
55+
Custom class name for the widget element.
56+
57+
## Source
58+
59+
[modules/widgets/src/geolocate-widget.tsx](https://github.com/visgl/deck.gl/tree/master/modules/widgets/src/geolocate-widget.tsx)

docs/api-reference/widgets/info-widget.md

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ const deck = new Deck({
3030
});
3131
```
3232

33-
## Props
33+
## Types
3434

35-
#### `id` (string, optional) {#id}
35+
### `InfoWidgetProps`
3636

37-
Default: `'info'`
37+
The `InfoWidget` accepts the generic [`WidgetProps`](../core/widget.md#props):
3838

39-
The `id` must be unique among all your widgets at a given time. It's recommended to set `id` explicitly if you have multiple widgets of the same type.
39+
- `id` (default `'info'`) - Unique id for this widget
40+
- `placement` (default `'top-left'`) - Widget position within the view relative to the map container
41+
- `viewId` (default `null`) - The `viewId` prop controls how a widget interacts with views.
42+
- `style` (default `{}`) - Additional inline styles on the top HTML element.
43+
- `className` (default `''`) - Additional classnames on the top HTML element.
4044

4145
#### position ([number, number]) {#position}
4246

@@ -60,22 +64,6 @@ Minimum offset (in pixels) to keep the popup away from the canvas edges.
6064

6165
`(widget: _InfoWidget, info: PickingInfo) => boolean`
6266

63-
#### `viewId` (string, optional) {#viewid}
64-
65-
View to attach to and interact with. Required when using multiple views.
66-
67-
#### `style` (object, optional) {#style}
68-
69-
Default: `{}`
70-
71-
Additional CSS styles for the widget. camelCase CSS properties (e.g. `backgroundColor`) and kabab-case CSS variables are accepted (e.g. `--button-size`).
72-
73-
#### `className` (string, optional) {#classname}
74-
75-
Default: `undefined`
76-
77-
Class name to attach to the widget element. The element has the default class name of `deck-widget deck-widget-info`.
78-
7967
## Source
8068

8169
[modules/widgets/src/info-widget.tsx](https://github.com/visgl/deck.gl/tree/master/modules/widgets/src/info-widget.tsx)

docs/api-reference/widgets/loading-widget.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ const deck = new Deck({
1818
});
1919
```
2020

21+
## Types
22+
23+
### `LoadingnWidgetProps`
24+
25+
The `LoadingnWidget` accepts the generic [`WidgetProps`](../core/widget.md#props):
26+
27+
- `id` (default `'loading'`) - Unique id for this widget
28+
- `placement` (default `'top-left'`) - Widget position within the view relative to the map container
29+
- `viewId` (default `null`) - The `viewId` prop controls how a widget interacts with views.
30+
- `style` (default `{}`) - Additional inline styles on the top HTML element.
31+
- `className` (default `''`) - Additional classnames on the top HTML element.
32+
2133
## Props
2234

2335
#### `id` (string, optional) {#id}
@@ -40,18 +52,6 @@ Tooltip message displayed while hovering a mouse over the widget.
4052

4153
Default: `'Loading data'`
4254

43-
#### `style` (object, optional) {#style}
44-
45-
Default: `{}`
46-
47-
Additional CSS styles for the widget. camelCase CSS properties (e.g. `backgroundColor`) and kabab-case CSS variables are accepted (e.g. `--button-size`).
48-
49-
#### `className` (string, optional) {#classname}
50-
51-
Default: `undefined`
52-
53-
Class name to attach to the widget element. The element has the default class name of `deck-widget deck-widget-loading`.
54-
5555
## Source
5656

5757
[modules/widgets/src/loading-widget.tsx](https://github.com/visgl/deck.gl/tree/master/modules/widgets/src/loading-widget.tsx)

0 commit comments

Comments
 (0)