Skip to content

Commit e4fc4a2

Browse files
chore(widgets) audit props and docs (#9796)
* Add viewId prop to all widgets for multi-view support Introduces a standardized `viewId` prop to all widget components, enabling them to attach to specific views when using multiple views. Updates defaultProps, constructors, and setProps methods to handle the new prop, and improves JSDoc comments for clarity. Also adds copyright headers to several files for consistency. * Refactor widget exports and update overview documentation Reorganized widget exports in index.ts into clearer categories: navigation, geospatial, view, information, control, and utility widgets. Updated the overview documentation to reflect the new structure and added missing widgets to the lists for improved clarity and discoverability. * Refactor widget docs to centralize WidgetProps Updated widget documentation to reference generic WidgetProps from core/widget.md, removing redundant prop listings from individual widget docs. This improves consistency and maintainability by centralizing prop definitions and reducing duplication. * Add usage sections and version badges to widget docs Updated documentation for multiple deck.gl widgets to include 'Usage' sections and version badges, improving clarity and consistency. * Document default prop values for widget API Updates API reference docs for all widgets to consistently document default values for props, improving clarity for users. Default values are now listed before descriptions for easier reference. * Add usage section to TimelineWidget docs * Add source links to widget API docs * Audit widget docs for missing props Added documentation for GimbalWidget, InfoWidget, ResetViewWidget, and ScreenshotWidget * [fix] Invoke onViewModeChange callback on mode select The ViewSelectorWidget now calls the onViewModeChange callback when the view mode is changed, enabling external handling of view mode changes. Updated documentation to reflect this behavior. * Remove 'none' option from initialTheme prop docs Updated the documentation for the ThemeWidget to remove the 'none' value from the initialTheme prop, clarifying that only 'auto', 'light', and 'dark' are valid options. * Fix merge for context menu widget doc * Fix inline CSS type * Refactor widget imports for type-only usage Updated imports in all widget components to use type-only imports for WidgetProps, WidgetPlacement, and related types from @deck.gl/core. * Fix link * Add placement and viewId props to StatsWidget Introduces 'placement' and 'viewId' properties to StatsWidget for improved positioning and multi-view support. * Update widget.md Co-authored-by: felixpalmer <[email protected]> * alphabetical --------- Co-authored-by: felixpalmer <[email protected]>
1 parent ab5b727 commit e4fc4a2

37 files changed

+439
-370
lines changed

docs/api-reference/core/widget.md

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,54 @@ The `Widget` class is a base class used to define new widgets and should not be
99

1010
## Types
1111

12-
#### `WidgetProps` (object) {#widgetprops}
12+
### `WidgetProps` (object) {#widgetprops}
1313

1414
Options for the widget, as passed into the constructor and can be updated with `setProps`.
1515

16-
#### `id` (string) {#id}
16+
#### `id` (string, optional) {#id}
17+
18+
* Default: the widget's name.
1719

1820
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.
1921

20-
#### `viewId` (string | null) {#viewid}
22+
Remarks:
2123

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.
24+
* `id` is used to match widgets between rendering calls. deck.gl requires each widget to have a unique `id`. A default `id` is assigned based on widget type, which means if you are using more than one widget of the same type (e.g. two `InfoWidget`s) you need to provide a custom `id` for at least one of them.
25+
26+
#### `style` (object, optional) {#style}
27+
28+
* Default: `{}`
29+
30+
Additional inline CSS styles on the top HTML element of the widget. camelCase CSS properties (e.g. `backgroundColor`) and kebab-case CSS variables are accepted (e.g. `--button-size`).
31+
32+
```ts
33+
style?: Partial<CSSStyleDeclaration>;
34+
```
35+
36+
#### `className` (string, optional) {#classname}
37+
38+
* Default: `''`
39+
40+
Additional CSS classnames on the top HTML element.
41+
42+
### Additional `WidgetProps` on UI Widgets
43+
44+
#### `viewId` (string | null) {#viewid}
2345

2446
* Default: `null`
2547

48+
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.
49+
2650
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.
2751

2852
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.
2953

3054
#### `placement` (string, optional) {#placement}
3155

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

58+
Widget position within the view relative to the map container.
59+
3660
Widget positioning within the view. One of:
3761

3862
- `'top-left'`
@@ -41,22 +65,6 @@ Widget positioning within the view. One of:
4165
- `'bottom-right'`
4266
- `'fill'`
4367

44-
#### `style` (object, optional) {#style}
45-
46-
Additional inline CSS styles on the top HTML element.
47-
48-
```ts
49-
style?: Partial<CSSStyleDeclaration>;
50-
```
51-
52-
* Default: `{}`
53-
54-
#### `className` (string, optional) {#classname}
55-
56-
Additional CSS classnames on the top HTML element.
57-
58-
* Default: `''`
59-
6068
### Methods for Widget Writers
6169

6270
#### `constructor` {#constructor}

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import {CompassWidget} from '@deck.gl/widgets';
33

44
# CompassWidget
55

6+
<img src="https://img.shields.io/badge/from-v9.0-green.svg?style=flat-square" alt="from v9.0" />
7+
68
This widget visualizes bearing and pitch. Click it once to reset bearing to 0, click it a second time to reset pitch to 0. Supports Map and Globe view.
79

10+
## Usage
11+
812
<WidgetPreview cls={CompassWidget}/>
913

1014
```ts
11-
import {CompassWidget} from '@deck.gl/widgets';
1215
import {Deck} from '@deck.gl/core';
16+
import {CompassWidget} from '@deck.gl/widgets';
1317

14-
const deck = new Deck({
18+
new Deck({
1519
widgets: [new CompassWidget()]
1620
});
1721
```
@@ -20,23 +24,17 @@ const deck = new Deck({
2024

2125
### `CompassWidgetProps` {#compasswidgetprops}
2226

23-
The `CompassWidget` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops):
24-
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.
27+
The `CompassWidget` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops) and:
3028

3129
#### `label` (string, optional) {#label}
3230

33-
Tooltip message displayed while hovering a mouse over the widget.
31+
* Default: `'Compass'`
3432

35-
Default: `'Compass'`
33+
Tooltip message displayed while hovering a mouse over the widget.
3634

3735
#### `transitionDuration` (number, optional) {#transitionduration}
3836

39-
Default: `200`
37+
* Default: `200`
4038

4139
Bearing and pitch reset transition duration in milliseconds.
4240

docs/api-reference/widgets/context-menu-widget.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const deck = new Deck({
1616
new ContextMenuWidget({
1717
getMenuItems: (info, widget) => {
1818
if (info.object) {
19-
const name = info.object.properties.name;
19+
const name = info.object.properties.name;
2020
return [
2121
{key: 'name', label: name},
2222
{key: 'delete', label: 'Delete'}
@@ -25,8 +25,8 @@ const deck = new Deck({
2525
return [{label: 'Add Point', key: 'add'}];
2626
},
2727
onMenuItemSelected: (key, pickInfo) => {
28-
if (key === 'add') addPoint(pickInfo);
29-
if (key === 'delete') deletePoint(pickInfo);
28+
if (key === 'add') addPoint(pickInfo);
29+
if (key === 'delete') deletePoint(pickInfo);
3030
}
3131
})
3232
]
@@ -39,7 +39,6 @@ const deck = new Deck({
3939

4040
The `ContextMenuWidget` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops) and:
4141

42-
- `id` (string, default: `'context'`) - **Required.** Unique id for this widget
4342
- `getMenuItems` (function) - **Required.** Function that returns menu items based on the picked object. Receives `PickingInfo` and returns an array of `ContextWidgetMenuItem` objects or `null`.
4443
- `onMenuItemSelected` (function, optional) - Callback invoked when a menu item is selected. Receives the selected item key and `PickingInfo`.
4544
- `visible` (boolean, default `false`) - Controls visibility of the context menu.
@@ -59,3 +58,7 @@ Menu item definition:
5958
- Menu items are dynamically generated based on what was clicked
6059
- Click elsewhere to hide the menu
6160
- Menu automatically positions itself at the cursor location
61+
62+
## Source
63+
64+
[modules/widgets/src/context-menu-widget.tsx](https://github.com/visgl/deck.gl/tree/master/modules/widgets/src/context-menu-widget.tsx)
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
# FpsWidget
1+
import {WidgetPreview} from '@site/src/doc-demos/widgets';
2+
import {_FpsWidget as FpsWidget} from '@deck.gl/widgets';
23

3-
Displays the measured frames per second (FPS) as reported by the attached
4-
`Deck` instance.
4+
# FpsWidget (Experimental)
55

6-
```ts
7-
import {FpsWidget} from '@deck.gl/widgets';
8-
```
6+
<img src="https://img.shields.io/badge/from-v9.2-green.svg?style=flat-square" alt="from v9.2" />
7+
8+
Displays the measured frames per second (FPS) as reported by the attached `Deck` instance.
99

1010
## Usage
1111

12+
<WidgetPreview cls={FpsWidget}/>
13+
1214
```ts
15+
import {Deck} from '@deck.gl/core';
16+
import {_FpsWidget as FpsWidget} from '@deck.gl/widgets';
17+
1318
new Deck({
1419
widgets: [new FpsWidget({placement: 'top-right'})]
1520
});
@@ -19,10 +24,8 @@ new Deck({
1924

2025
### `FpsWidgetProps` {#fpswidgetprops}
2126

22-
The `FpsWidget` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops):
27+
The `FpsWidget` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops).
28+
29+
## Source
2330

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.
31+
[modules/widgets/src/fps-widget.tsx](https://github.com/visgl/deck.gl/tree/master/modules/widgets/src/fps-widget.tsx)

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

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import {FullscreenWidget} from '@deck.gl/widgets';
33

44
# FullscreenWidget
55

6+
<img src="https://img.shields.io/badge/from-v9.0-green.svg?style=flat-square" alt="from v9.0" />
7+
68
This widget enlarges deck.gl to fill the full screen. Click the widget to enter or exit full screen.
79

10+
## Usage
11+
812
<WidgetPreview cls={FullscreenWidget}/>
913

1014
```ts
11-
import {FullscreenWidget} from '@deck.gl/widgets';
1215
import {Deck} from '@deck.gl/core';
16+
import {FullscreenWidget} from '@deck.gl/widgets';
1317

14-
const deck = new Deck({
18+
new Deck({
1519
widgets: [new FullscreenWidget()]
1620
});
1721
```
@@ -20,43 +24,25 @@ const deck = new Deck({
2024

2125
### `FullscreenWidgetProps` {#fullscreenwidgetprops}
2226

23-
The `FullscreenWidget` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops):
24-
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.
27+
The `FullscreenWidget` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops) and:
3028

3129
#### `container` (HTMLElement, optional) {#container}
3230

33-
Default: `undefined`
31+
* Default: `undefined`
3432

3533
A [compatible DOM element](https://developer.mozilla.org/en-US/docs/Web/API/Element/requestFullScreen#Compatible_elements) which should be made full screen. By default, the map container element will be made full screen.
3634

3735
#### `enterLabel` (string, optional) {#enterlabel}
3836

39-
Tooltip message displayed while hovering a mouse over the widget when out of fullscreen.
37+
* Default: `'Enter Fullscreen'`
4038

41-
Default: `'Enter Fullscreen'`
39+
Tooltip message displayed while hovering a mouse over the widget when out of fullscreen.
4240

4341
#### `exitLabel` (string, optional) {#exitlabel}
4442

45-
Tooltip message displayed while hovering a mouse over the widget when fullscreen.
43+
* Default: `'Exit Fullscreen'`
4644

47-
Default: `'Exit Fullscreen'`
48-
49-
#### `style` (object, optional) {#style}
50-
51-
Default: `{}`
52-
53-
Additional CSS styles for the widget. camelCase CSS properties (e.g. `backgroundColor`) and kabab-case CSS variables are accepted (e.g. `--button-size`).
54-
55-
#### `className` (string, optional) {#classname}
56-
57-
Default: `undefined`
58-
59-
Class name to attach to the widget element. The element has the default class name of `deck-widget deck-fullscreen-widget`.
45+
Tooltip message displayed while hovering a mouse over the widget when fullscreen.
6046

6147
## Styles
6248

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {_GeocoderWidget} from '@deck.gl/widgets';
33

44
# GeocoderWidget (Experimental)
55

6+
<img src="https://img.shields.io/badge/from-v9.2-green.svg?style=flat-square" alt="from v9.2" />
7+
68
The GeocoderWidget helps the user find positions on the map.
79

810
This widget provides an input box for entering an address or a pair of coordinates.
@@ -14,8 +16,8 @@ Addresses that return a valid location are stored in browser local storage (up t
1416
<WidgetPreview cls={_GeocoderWidget}/>
1517

1618
```ts
17-
import {_GeocoderWidget as GeocoderWidget} from '@deck.gl/widgets';
1819
import {Deck} from '@deck.gl/core';
20+
import {_GeocoderWidget as GeocoderWidget} from '@deck.gl/widgets';
1921

2022
new Deck({
2123
widgets: [new GeocoderWidget()]
@@ -26,43 +28,42 @@ new Deck({
2628

2729
### `GeocoderWidgetProps` {#geocoderwidgetprops}
2830

29-
The `GeocoderWidgetProps` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops):
30-
31-
- `id` (default `'geocoder'`) - Unique id for this widget
32-
- `placement` (default `'top-left'`) - Widget position within the view relative to the map container
33-
- `viewId` (default `null`) - The `viewId` prop controls how a widget interacts with views.
34-
- `style` (default `{}`) - Additional inline styles on the top HTML element.
35-
- `className` (default `''`) - Additional classnames on the top HTML element.
31+
The `GeocoderWidgetProps` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops) and:
3632

3733
#### `label` (string, optional) {#label}
3834

35+
* Default: `'Geocoder'`
36+
3937
Tooltip message displayed while hovering a mouse over the widget.
4038

41-
Default: `'Geocoder'`
39+
#### `transitionDuration` (number, optional) {#transitionduration}
40+
41+
* Default: `200`
42+
43+
View state transition duration in milliseconds.
4244

4345
#### `geocoder` (string, optional) {#geocoder}
4446

45-
Default: `'coordinates'`
47+
* Default: `'coordinates'`
4648

4749
Which geocoding service to use. Supported values are `'coordinates'`, `'google'`, `'mapbox'`, `'opencage'`, or `'custom'`.
4850

4951
#### `apiKey` (string, optional) {#apikey}
5052

53+
* Default: `''`
54+
5155
Required if `geocoder` is set to a third party provider. For quick testing, applications can use the `coordinates` geocode does not require an api key.
5256

5357
#### `customGeocoder` (optional) {#customgeocoder}
5458

5559
Only used when `geocoder` is `'custom'`. A function that receives the entered text and an API key, and resolves to a `{longitude, latitude}` object when successful.
5660

57-
#### `transitionDuration` (number, optional) {#transitionduration}
58-
59-
Default: `200`
60-
61-
View state transition duration in milliseconds.
62-
6361
#### `_geolocation` (optional) {#_geolocation}
6462

6563
In addition to addresses / coordinates, one position of obvious interest is the user's own current position. This experimental option adds a `current` menu item that calls the browser's geolocation API and navigates to the user's current position. Note that this requires the user to enable geolocation in the browser.
6664

6765
If `props._geolocation` **Current position** from the drop-down uses `navigator.geolocation` to center the map. The option is hidden if the browser does not provide the Geolocation API or the user denies access.
6866

67+
## Source
68+
69+
[modules/widgets/src/geocoder-widget.tsx](https://github.com/visgl/deck.gl/tree/master/modules/widgets/src/geocoder-widget.tsx)

0 commit comments

Comments
 (0)