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(react) React widgets and useWidget hook documentation #9309

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chrisgervang
Copy link
Collaborator

@chrisgervang chrisgervang commented Dec 19, 2024

For #9278 #9056 #9298

Background

A features not "done" until its documented.. react widget docs.

Change List

  • useWidget api reference
  • JSX widgets usage


const App = (data) => (
<DeckGL
initialViewState={{longitude: -122.45, latitude: 37.78, zoom: 12}}
controller={true}
layers={[new ScatterplotLayer({data})]}
>
<StaticMap
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be good to do an audit for this and use maplibre since it doesn't need a token.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - Add a bullet to our v9.1 tracker task?

@coveralls
Copy link

coveralls commented Dec 19, 2024

Coverage Status

coverage: 91.701% (-0.006%) from 91.707%
when pulling 027397d on chr/use-widget-docs
into 05bca74 on master.

@chrisgervang chrisgervang mentioned this pull request Dec 19, 2024
36 tasks

const App = (data) => (
<DeckGL
initialViewState={{longitude: -122.45, latitude: 37.78, zoom: 12}}
controller={true}
layers={[new ScatterplotLayer({data})]}
>
<StaticMap
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - Add a bullet to our v9.1 tracker task?

docs/api-reference/react/use-widget.md Outdated Show resolved Hide resolved
Comment on lines +7 to +19
import {CompassWidget as VanillaCompassWidget, CompassWidgetProps} from '@deck.gl/widgets';

export const CompassWidget = (props: CompassWidgetProps = {}) => {
const widget = useWidget(VanillaCompassWidget, props);
return null;
};

<DeckGL>
<CompassWidget/>
</DeckGL>
```

See a full example [here](../../developer-guide/custom-widgets/react-widgets.md).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vanilla sounds so weird... And the fact that I can't easily think of a better name makes me feel this is an indication of the dual usage of the word "widget" here being more problematic than initially expected.

How about we reserve the word "widget" for actual widgets, and talk about wrapping widgets into react "components"? I realize it will required rewriting the docs a bit, but I think a ton of confusion can be avoided.

Suggested change
import {CompassWidget as VanillaCompassWidget, CompassWidgetProps} from '@deck.gl/widgets';
export const CompassWidget = (props: CompassWidgetProps = {}) => {
const widget = useWidget(VanillaCompassWidget, props);
return null;
};
<DeckGL>
<CompassWidget/>
</DeckGL>
```
See a full example [here](../../developer-guide/custom-widgets/react-widgets.md).
import {CompassWidget, CompassWidgetProps} from '@deck.gl/widgets';
export type CompassProps = CompassWidgetProps;
export const Compass = (props: CompassProps = {}) => {
const widget = useWidget(CompassWidget, props);
return null;
};
<DeckGL>
<CompassWidget/>
</DeckGL>

See a full example here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a fair point. A Widget is just a hook. You could compose multiple widgets in one component.. widgets may or may not mount a DOM element. So yeah these components could really be anything.. we're just suggesting a usage.

I'll try reworking the PRs with this idea.

The open question I have is how to implement a widget nested in a JSX view..

<MapView id="minimap">
  <Compass />
</MapView>

I was originally going to inject a viewId prop, assuming all props were passed into the hook, or introduce something new like a ViewContext. I've been putting this off thinking the community react library might be a better solution.

Co-authored-by: Ib Green <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants