Skip to content
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

docs(widgets) Custom Widget Developer Guide #9304

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
101aaf9
docs(widgets) Widget Developer Guide
chrisgervang Dec 18, 2024
ebd2b50
Update docs/developer-guide/custom-widgets/README.md
chrisgervang Dec 18, 2024
70248ce
Update docs/developer-guide/custom-widgets/universal-widgets.md
chrisgervang Dec 18, 2024
026fd27
Update docs/developer-guide/custom-widgets/README.md
chrisgervang Dec 18, 2024
41cdfb3
adding preact page and vanilla example
chrisgervang Dec 18, 2024
077ddd9
onViewportChange
chrisgervang Dec 18, 2024
775c7b8
misc react docs
chrisgervang Dec 18, 2024
e68bd41
Styling Your React Widget
chrisgervang Dec 18, 2024
5291a26
TOC
chrisgervang Dec 18, 2024
dcb07be
type cleanup
chrisgervang Dec 18, 2024
8daa0c6
Merge branch 'master' into chr/widget-dev-guide
chrisgervang Dec 18, 2024
e48c1c9
Adding required class members
chrisgervang Dec 19, 2024
98a82a4
Add reactivity to examples
chrisgervang Dec 21, 2024
5366ae2
[docs] rewrite React widget dev guide
chrisgervang Jan 2, 2025
f17de11
Merge branch 'master' into chr/widget-dev-guide
chrisgervang Jan 4, 2025
a45ba17
use type instead of interface
chrisgervang Jan 5, 2025
225cd33
Update preact-widgets.md
chrisgervang Jan 6, 2025
2548071
Fix example in preact-widgets.md
chrisgervang Jan 7, 2025
9a1ffe5
Merge branch 'master' into chr/widget-dev-guide
chrisgervang Jan 7, 2025
90e62a8
After testing react-widgets.md
chrisgervang Jan 8, 2025
afba3b8
Update react-widgets.md
chrisgervang Jan 8, 2025
5152e49
Use a portal instead of a ref
chrisgervang Jan 8, 2025
1392345
Update preact-widgets.md
chrisgervang Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
type cleanup
  • Loading branch information
chrisgervang committed Dec 18, 2024
commit dcb07be1df9156707db77c0c87325ad70bddb8ab
6 changes: 2 additions & 4 deletions docs/developer-guide/custom-widgets/preact-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ interface LayerListWidgetProps {
className?: string;
}

class LayerListWidget implements Widget {
class LayerListWidget implements Widget<LayerListWidgetProps> {
id = 'layer-list-widget';
props: LayerListWidgetProps;
placement: WidgetPlacement = 'top-left';
viewId?: string | null = null;
viewports: {[id: string]: Viewport} = {};
layers: Layer[] = [];
deck?: Deck<any>;
Expand Down Expand Up @@ -110,7 +108,7 @@ class LayerListWidget implements Widget {
this.update();
}

onViewportChange(viewport: Viewport) {
onViewportChange(viewport) {
this.viewports[viewport.id] = viewport
}

Expand Down
4 changes: 2 additions & 2 deletions docs/developer-guide/custom-widgets/react-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ interface RotateWidgetProps {
ref: RefObject<HTMLDivElement>
}

class RotateWidget {
constructor(props: BearingWidgetProps) {
class RotateWidget implements Widget<RotateWidgetProps> {
constructor(props: RotateWidgetProps) {
this.id = props.id || 'bearing-widget';
this.placement = props.placement || 'top-right';
this.props = props;
Expand Down
21 changes: 10 additions & 11 deletions docs/developer-guide/custom-widgets/universal-widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class AwesomeWidget implements Widget {

### Updating Properties

[`setProps(props)`](../../api-reference/core/widget.md#setprops) - This method is called whenever widget properties are updated. Use this to apply changes dynamically.
[`setProps(props: Partial<PropsT>)`](../../api-reference/core/widget.md#setprops) - This method is called whenever widget properties are updated. Use this to apply changes dynamically.

```ts
class AwesomeWidget implements Widget {
setProps(props: Partial<ZoomWidgetProps>) {
class AwesomeWidget implements Widget<AwesomeWidgetProps> {
setProps(props) {
Object.assign(this.props, props);
}
}
Expand All @@ -44,7 +44,7 @@ Specific viewport:
class AwesomeWidget implements Widget {
viewId = 'minimap'

onViewportChange(viewport: Viewport) {
onViewportChange(viewport) {
// Handle updates for the "minimap" viewport
}
}
Expand All @@ -56,7 +56,7 @@ All viewports:
class AwesomeWidget implements Widget {
viewId = null

onViewportChange(viewport: Viewport) {
onViewportChange(viewport) {
// Handle updates for all viewports
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ import {
_removeStyles as removeStyles
} from '@deck.gl/core'

class AwesomeWidget implements Widget {
class AwesomeWidget implements Widget<AwesomeWidgetProps> {

constructor(props: AwesomeWidgetProps) {
...
Expand All @@ -149,7 +149,7 @@ class AwesomeWidget implements Widget {
...
}

setProps(props: Partial<AwesomeWidgetProps>) {
setProps(props) {
const el = this.element;
if (el) {
if (!deepEqual(oldProps.style, props.style, 1)) {
Expand Down Expand Up @@ -181,7 +181,7 @@ Apply the CSS class to your widget
```ts
import { type Widget } from '@deck.gl/core'

class AwesomeWidget implements Widget {
class AwesomeWidget implements Widget<AwesomeWidgetProps> {

onAdd() {
const {className} = this.props;
Expand All @@ -190,7 +190,7 @@ class AwesomeWidget implements Widget {
...
}

setProps(props: Partial<AwesomeWidgetProps>) {
setProps(props) {
const oldProps = this.props;
const el = this.element;
if (el) {
Expand Down Expand Up @@ -256,9 +256,8 @@ interface LayerLoadingWidgetProps {
className?: string;
}

class LayerListWidget implements Widget {
class LayerListWidget implements Widget<LayerLoadingWidgetProps> {
id = 'layer-loading-widget';
props: LayerLoadingWidgetProps;
placement: WidgetPlacement = 'top-left';
layers: Layer[] = [];
deck?: Deck<any>;
Expand Down
Loading