|
| 1 | +# SelectorWidget |
| 2 | + |
| 3 | +<img src="https://img.shields.io/badge/from-v9.3-green.svg?style=flat-square" alt="from v9.3" /> |
| 4 | + |
| 5 | +This widget renders an icon button that opens a popover menu of selectable options. Each option provides an icon and an optional label, and the button updates to reflect the current selection. |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +```ts |
| 10 | +import {Deck} from '@deck.gl/core'; |
| 11 | +import {SelectorWidget} from '@deck.gl/widgets'; |
| 12 | + |
| 13 | +new Deck({ |
| 14 | + widgets: [ |
| 15 | + new SelectorWidget({ |
| 16 | + initialValue: 'single', |
| 17 | + options: [ |
| 18 | + { |
| 19 | + value: 'single', |
| 20 | + label: 'Single view', |
| 21 | + icon: `./single-view.svg` |
| 22 | + }, |
| 23 | + { |
| 24 | + value: 'split-horizontal', |
| 25 | + label: 'Split horizontal', |
| 26 | + icon: `./split-views-horizontal.svg` |
| 27 | + } |
| 28 | + ], |
| 29 | + onChange: value => { |
| 30 | + console.log('selected:', value); |
| 31 | + } |
| 32 | + }) |
| 33 | + ] |
| 34 | +}); |
| 35 | +``` |
| 36 | + |
| 37 | +## Types |
| 38 | + |
| 39 | +### `SelectorWidgetProps` {#selectorwidgetprops} |
| 40 | + |
| 41 | +The `SelectorWidget` accepts the generic [`WidgetProps`](../core/widget.md#widgetprops) and: |
| 42 | + |
| 43 | +#### `options` (`SelectorWidgetOption[]`, required) {#options} |
| 44 | + |
| 45 | +Selectable options displayed in the popover menu. |
| 46 | + |
| 47 | +#### `initialValue` (any, optional) {#initialvalue} |
| 48 | + |
| 49 | +* Default: value of the first option |
| 50 | + |
| 51 | +Initial selected value. If it does not match any option, the first option is displayed. |
| 52 | + |
| 53 | +#### `onChange` (function, optional) {#onchange} |
| 54 | + |
| 55 | +```ts |
| 56 | +(value: ValueT) => void |
| 57 | +``` |
| 58 | + |
| 59 | +Callback invoked when a new option is selected. |
| 60 | + |
| 61 | +### `SelectorWidgetOption` {#selectorwidgetoption} |
| 62 | + |
| 63 | +#### `value` (any, required) {#value} |
| 64 | + |
| 65 | +Value returned from `onChange` when this option is selected. |
| 66 | + |
| 67 | +#### `icon` (string, required) {#optionicon} |
| 68 | + |
| 69 | +Data URL used as the option icon mask. |
| 70 | + |
| 71 | +#### `label` (string, optional) {#optionlabel} |
| 72 | + |
| 73 | +Text shown in the menu and used as the button tooltip when selected. |
| 74 | + |
| 75 | +## Styles |
| 76 | + |
| 77 | +The `SelectorWidget` uses the shared button and menu theme variables described in the [styling guide](./styling.md). |
| 78 | + |
| 79 | + |
| 80 | +## Source |
| 81 | + |
| 82 | +[modules/widgets/src/selector-widget.tsx](https://github.com/visgl/deck.gl/tree/master/modules/widgets/src/selector-widget.tsx) |
0 commit comments