Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Wrapper components for `ActionGroup` and `ActionMenu` to support primitive items * `ListActionGroup` and `ListActionMenu` components to support providing actions prop to `ListView` * `ListView` `actions` prop support The branch in [this PR](deephaven/deephaven-plugins#448) can be used to see this in action. I also published an alpha this branch ([0.77.1-alpha-listview-actions.4](https://www.npmjs.com/package/@deephaven/components/v/0.77.1-alpha-listview-actions.4)) to make types work in plugins ### Example of standalone `ui.action_group` and `ui.action_menu` ```python from deephaven import ui @ui.component def action_group(): action, on_action = ui.use_state("") selected_keys, set_selected_keys = ui.use_state(['Aaa']) selection_text = ui.text("Selection: " + ", ".join(map(str, selected_keys)), grid_column="span 2") return 'Action Group', (" - " if action else "") + action, ui.action_group( ui.item( ui.icon('vsAccount'), 'Aaa', text_value="Aaa" ), 'Bbb', 'Ccc', selection_mode="multiple", selected_keys=selected_keys, on_action=on_action, on_change=set_selected_keys, ), selection_text, ag = action_group() @ui.component def action_menu(): action, on_action = ui.use_state("") return 'Action Menu', (" - " if action else "") + action, ui.action_menu( ui.item( ui.icon('vsAccount'), 'Aaa', text_value="Aaa" ), 'Bbb', 'Ccc', on_action=on_action, align_self="start" ) am = action_menu() ``` ### Example showing actions in `ui.list_view` with different densities ```python import deephaven.ui as ui from deephaven import time_table import datetime initial_row_count=2000 icon_names = ['vsAccount'] columns = [ "Id=new Integer(i)", "Display=new String(`Display `+i)", "Description=new String(`Description `+i)", "Icon=(String) icon_names[0]" ] # Tables with initial row count of 200 that adds a row every second column_types_ticking = time_table("PT1S", start_time=datetime.datetime.now() - datetime.timedelta(seconds=initial_row_count)).update([ columns ]) column_types = empty_table(initial_row_count).update(columns) #### Component definitions #### @ui.component def labeled_lv(label, *args, **kwargs): return ui.flex( ui.text(label), ui.list_view( *args, **kwargs ), direction="column", flex=1, min_width=0, ) @ui.component def ui_list_view_table(data, density): value, set_value = ui.use_state([2, 4, 5]) # Action Groups ag_action, set_ag_action = ui.use_state(['', '']) on_ag_action=ui.use_callback(lambda a,i : set_ag_action([a,str(i)]), []) lv_actions = labeled_lv( "Actions (text only)", data, density=density, max_height=5000, key_column="Id", label_column="Display", icon_column="Icon", aria_label="List View", on_change=set_value, selected_keys=value, actions=ui.list_action_group( 'Edit', 'Delete', on_action=on_ag_action, ), ) lv_actions_icon = labeled_lv( "Actions (icon only)", data, density=density, max_height=5000, key_column="Id", label_column="Display", icon_column="Icon", aria_label="List View", on_change=set_value, selected_keys=value, actions=ui.list_action_group( ui.item( ui.icon('vsEdit'), ui.text('Edit'), key='Edit', ), ui.item( ui.icon('vsTrash'), ui.text('Delete'), key='Delete' ), max_width=80, button_label_behavior="collapse", overflow_mode="collapse", on_action=on_ag_action, ), ) action_group_text = ui.text("Action: " + ag_action[0] + ", Item: " + ag_action[1]) # Action Menus am_action, set_am_action = ui.use_state(['', '']) on_am_action=ui.use_callback(lambda a,i : set_am_action([a,str(i)]), []) lv_action_menu = labeled_lv( "Action Menu (text only)", data, density=density, max_height=5000, key_column="Id", label_column="Display", icon_column="Icon", aria_label="List View", selected_keys=value, on_change=set_value, actions=ui.list_action_menu( 'Edit', 'Delete', on_action=on_am_action, ), ) lv_action_menu2 = labeled_lv( "Action Menu (icons)", data, density=density, max_height=5000, key_column="Id", label_column="Display", icon_column="Icon", aria_label="List View", selected_keys=value, on_change=set_value, actions=ui.list_action_menu( ui.item( ui.icon('vsEdit'), ui.text('Edit'), key='Edit', text_value="Edit" ), ui.item( ui.icon('vsTrash'), ui.text('Delete'), key='Delete', text_value="Delete" ), on_action=on_am_action, ), ) action_menu_text = ui.text("Action: " + am_action[0] + ", Item: " + am_action[1]) return ui.flex( ui.flex( lv_actions, lv_actions_icon, direction="row", ), action_group_text, ui.flex( lv_action_menu, lv_action_menu2, direction="row" ), action_menu_text, direction="column", ) @ui.component def examples(data): density, set_density = ui.use_state(["COMPACT"]) return 'Density', ui.action_group( 'COMPACT', 'REGULAR', 'SPACIOUS', selected_keys=density, selection_mode="SINGLE", on_change=set_density ), ui_list_view_table(data, density[0]) lv_table = examples(column_types) # lv_table = examples(column_types_ticking) ```
- Loading branch information