Skip to content

Commit

Permalink
Default density to compact (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed May 1, 2024
1 parent e4c509f commit 9cc3abb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions plugins/ui/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1247,11 +1247,13 @@ ui.list_view(
*children: Item | Table,
key_column: ColumnName | None = None,
label_column: ColumnName | None = None,
density: Density | None = "COMPACT",
description_column: ColumnName | None = None,
icon_column: ColumnName | None = None,
actions: ListActionGroupElement | ListActionMenuElement | None = None,
default_selected_keys: Selection | None = None,
selected_keys: Selection | None = None,
selection_mode: SelectionMode | None = "MULTIPLE",
render_empty_state: Element | None = None,
on_selection_change: Callable[[Selection], None] | None = None,
on_change: Callable[[Selection], None] | None = None,
Expand Down
5 changes: 4 additions & 1 deletion plugins/ui/src/deephaven/ui/components/list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .list_action_menu import ListActionMenuElement
from ..elements import BaseElement, Element
from .._internal.utils import create_props
from ..types import ColumnName, Stringable, Selection, SelectionMode
from ..types import ColumnName, Density, Stringable, Selection, SelectionMode

ListViewItem = Union[Stringable, ItemElement]
ListViewElement = Element
Expand All @@ -19,6 +19,7 @@ def list_view(
*children: ListViewItem | Table,
key_column: ColumnName | None = None,
label_column: ColumnName | None = None,
density: Density | None = "COMPACT",
description_column: ColumnName | None = None,
icon_column: ColumnName | None = None,
actions: ListActionGroupElement | ListActionMenuElement | None = None,
Expand All @@ -45,6 +46,8 @@ def list_view(
label_column:
Only valid if children are of type Table.
The column of values to display as primary text. Defaults to the key_column value.
density:
Sets the amount of vertical padding within each cell.
description_column:
Only valid if children are of type Table.
The column of values to display as descriptions.
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/deephaven/ui/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ class RowDataValue(CellData):
ZonedDateTimeConvertible,
]
Granularity = Literal["DAY", "HOUR", "MINUTE", "SECOND"]

Density = Literal["COMPACT", "NORMAL", "SPACIOUS"]
Dependencies = Union[Tuple[Any], List[Any]]
Selection = Sequence[Key]
20 changes: 14 additions & 6 deletions plugins/ui/src/js/src/elements/useListViewProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ import {
useSelectionEventCallback,
} from './spectrum/useSelectionEventCallback';

type Density = Required<DHListViewProps>['density'];

type WrappedDHListViewJSApiProps = Omit<DHListViewJSApiProps, 'table'> & {
children: ReactElement<ObjectViewProps>;
};

type WrappedDHListViewProps = Omit<DHListViewProps, 'selectionMode'> & {
// The dh UI spec specifies that selectionMode should be uppercase, but the
// Spectrum prop is lowercase. We'll accept either to keep things more
// flexible.
type WrappedDHListViewProps = Omit<
DHListViewProps,
'density' | 'selectionMode'
> & {
// The dh UI spec specifies that density and selectionMode should be uppercase,
// but the Spectrum props are lowercase. We'll accept either to keep things
// more flexible.
density?: Density | Uppercase<Density>;
selectionMode?: SelectionMode | Uppercase<SelectionMode>;
};

Expand All @@ -42,19 +48,21 @@ export type SerializedListViewProps = (
* @returns Wrapped props
*/
export function useListViewProps({
density,
selectionMode,
onChange,
onSelectionChange,
...otherProps
}: SerializedListViewProps): DHListViewProps | WrappedDHListViewJSApiProps {
const selectionModeLc = (selectionMode?.toLowerCase() ??
'none') as SelectionMode;
const densityLc = density?.toLowerCase() as Density;
const selectionModeLc = selectionMode?.toLowerCase() as SelectionMode;

const serializedOnChange = useSelectionEventCallback(onChange);
const serializedOnSelectionChange =
useSelectionEventCallback(onSelectionChange);

return {
density: densityLc,
selectionMode: selectionModeLc,
onChange: serializedOnChange,
onSelectionChange: serializedOnSelectionChange,
Expand Down

0 comments on commit 9cc3abb

Please sign in to comment.