Skip to content

Commit 5bc8d47

Browse files
committed
Mapped ActionGroup and ListActionGroup (#445)
1 parent a703f8c commit 5bc8d47

7 files changed

Lines changed: 52 additions & 3 deletions

File tree

plugins/ui/docs/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,30 @@ my_checkbox = ui_checkbox()
203203

204204
![Checkbox](_assets/checkbox.png)
205205

206+
## ActionGroup (string values)
207+
An ActionGroup is a grouping of ActionButtons that are related to one another.
208+
209+
```python
210+
@ui.component
211+
def action_group():
212+
[action, on_action] = ui.use_state()
213+
214+
return ui.flex(
215+
ui.action_group(
216+
"Aaa",
217+
"Bbb",
218+
"Ccc",
219+
action=action,
220+
on_action=on_action,
221+
),
222+
ui.text(action),
223+
direction="column",
224+
)
225+
226+
227+
ag = action_group()
228+
```
229+
206230
## Picker (string values)
207231

208232
The `ui.picker` component can be used to select from a list of items. Here's a basic example for selecting from a list of string values and displaying the selected key in a text field.

plugins/ui/src/deephaven/ui/components/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .action_group import action_group
12
from .icon import icon
23
from .make_component import make_component as component
34
from .fragment import fragment
@@ -21,6 +22,7 @@
2122

2223
__all__ = [
2324
"action_button",
25+
"action_group",
2426
"button",
2527
"button_group",
2628
"checkbox",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from ..elements import BaseElement
2+
3+
4+
def action_group(*children, **props):
5+
"""
6+
An ActionGroup is a grouping of ActionButtons that are related to one another.
7+
8+
Args:
9+
children: A list of Item or primitive elements.
10+
**props: Any other ActionGroup prop.
11+
"""
12+
return BaseElement(f"deephaven.ui.components.ActionGroup", *children, **props)

plugins/ui/src/js/src/elements/ElementConstants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ export const ELEMENT_NAME = {
2323
stack: uiComponentName('Stack'),
2424

2525
/** Other Components */
26+
actionGroup: uiComponentName('ActionGroup'),
2627
fragment: uiComponentName('Fragment'),
2728
item: uiComponentName('Item'),
29+
listActionGroup: uiComponentName('ListActionGroup'),
2830
listView: uiComponentName('ListView'),
2931
picker: uiComponentName('Picker'),
3032
section: uiComponentName('Section'),

plugins/ui/src/js/src/elements/ElementUtils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { Text } from '@deephaven/components';
33
import type { dh } from '@deephaven/jsapi-types';
4-
import { ITEM_ELEMENT_NAME } from './ElementConstants';
4+
import { ELEMENT_NAME } from './ElementConstants';
55
import ObjectView from './ObjectView';
66

77
export const CALLABLE_KEY = '__dhCbid';
@@ -159,7 +159,7 @@ export function wrapElementChildren(element: ElementNode): ElementNode {
159159

160160
const newProps = { ...element.props };
161161

162-
const isItemElement = isElementNode(element, ITEM_ELEMENT_NAME);
162+
const isItemElement = isElementNode(element, ELEMENT_NAME.item);
163163

164164
// We will be wrapping all primitive `Item` children in a `Text` element to
165165
// ensure proper layout. Since `Item` components require a `textValue` prop

plugins/ui/src/js/src/elements/SpectrumElementUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const SPECTRUM_ELEMENT_TYPE_PREFIX = 'deephaven.ui.spectrum.';
3434

3535
export const SpectrumSupportedTypes = {
3636
ActionButton,
37+
ActionGroup,
3738
Button,
3839
ButtonGroup,
3940
Checkbox,
@@ -45,6 +46,7 @@ export const SpectrumSupportedTypes = {
4546
Heading,
4647
Icon,
4748
IllustratedMessage,
49+
ListActionGroup,
4850
NumberField,
4951
Item,
5052
RangeSlider,

plugins/ui/src/js/src/widget/WidgetUtils.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import React, { ComponentType } from 'react';
44
// Importing `Item` and `Section` compnents directly since they should not be
55
// wrapped due to how Spectrum collection components consume them.
6-
import { Item, Section } from '@deephaven/components';
6+
import {
7+
ActionGroup,
8+
Item,
9+
ListActionGroup,
10+
Section,
11+
} from '@deephaven/components';
712
import { ValueOf } from '@deephaven/utils';
813
import { ReadonlyWidgetData } from './WidgetTypes';
914
import {
@@ -43,8 +48,10 @@ export const elementComponentMap = {
4348
[ELEMENT_NAME.stack]: Stack,
4449

4550
// Other components
51+
[ELEMENT_NAME.actionGroup]: ActionGroup,
4652
[ELEMENT_NAME.fragment]: React.Fragment,
4753
[ELEMENT_NAME.item]: Item,
54+
[ELEMENT_NAME.listActionGroup]: ListActionGroup,
4855
[ELEMENT_NAME.listView]: ListView,
4956
[ELEMENT_NAME.picker]: Picker,
5057
[ELEMENT_NAME.section]: Section,

0 commit comments

Comments
 (0)