Skip to content

Commit

Permalink
fix: label prop typing (#1071)
Browse files Browse the repository at this point in the history
- Fixes #988 
- Adds `NodeType`, which mirrors the React Node type
  • Loading branch information
wusteven815 authored Dec 20, 2024
1 parent 4478013 commit 716b3d9
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions plugins/ui/src/deephaven/ui/components/combo_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .section import SectionElement
from .item import Item
from .item_table_source import ItemTableSource
from ..elements import BaseElement, Element
from ..elements import BaseElement, Element, NodeType
from .._internal.utils import create_props, unpack_item_table_source
from ..types import Key, Undefined, UndefinedType
from .basic import component_element
Expand Down Expand Up @@ -67,7 +67,7 @@ def combo_box(
is_required: bool | None = None,
validation_behavior: ValidationBehavior = "aria",
auto_focus: bool | None = None,
label: Element | None = None,
label: NodeType = None,
description: Element | None = None,
error_message: Element | None = None,
name: str | None = None,
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/deephaven/ui/components/date_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Alignment,
)

from ..elements import Element
from ..elements import Element, NodeType
from .._internal.utils import (
create_props,
convert_date_props,
Expand Down Expand Up @@ -93,7 +93,7 @@ def date_field(
is_required: bool | None = None,
validation_behavior: ValidationBehavior | None = None,
auto_focus: bool | None = None,
label: Element | None = None,
label: NodeType = None,
description: Element | None = None,
error_message: Element | None = None,
is_open: bool | None = None,
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/deephaven/ui/components/date_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)

from ..hooks import use_memo
from ..elements import Element
from ..elements import Element, NodeType
from .._internal.utils import (
create_props,
convert_date_props,
Expand Down Expand Up @@ -98,7 +98,7 @@ def date_picker(
is_required: bool | None = None,
validation_behavior: ValidationBehavior | None = None,
auto_focus: bool | None = None,
label: Element | None = None,
label: NodeType = None,
description: Element | None = None,
error_message: Element | None = None,
is_open: bool | None = None,
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/deephaven/ui/components/date_range_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)

from ..hooks import use_memo
from ..elements import Element
from ..elements import Element, NodeType
from .._internal.utils import (
create_props,
convert_date_props,
Expand Down Expand Up @@ -96,7 +96,7 @@ def date_range_picker(
is_required: bool | None = None,
validation_behavior: ValidationBehavior | None = None,
auto_focus: bool | None = None,
label: Element | None = None,
label: NodeType = None,
description: Element | None = None,
error_message: Element | None = None,
is_open: bool | None = None,
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/deephaven/ui/components/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .basic import component_element
from .section import SectionElement, Item
from .item_table_source import ItemTableSource
from ..elements import BaseElement, Element
from ..elements import BaseElement, Element, NodeType
from .._internal.utils import create_props, unpack_item_table_source
from ..types import Key, Undefined, UndefinedType
from .types import (
Expand Down Expand Up @@ -60,7 +60,7 @@ def picker(
validation_behavior: ValidationBehavior | None = None,
description: Element | None = None,
error_message: Element | None = None,
label: Element | None = None,
label: NodeType = None,
placeholder: str | None = None,
is_loading: bool | None = None,
label_position: LabelPosition = "top",
Expand Down
7 changes: 3 additions & 4 deletions plugins/ui/src/deephaven/ui/components/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
Position,
ProgressBarSize,
)

from .basic import component_element
from ..elements import Element
from ..elements import Element, NodeType

ProgressBarElement = Element

Expand All @@ -26,9 +25,9 @@ def progress_bar(
static_color: StaticColor | None = None,
label_position: LabelPosition = "top",
show_value_label: bool | None = None,
label: Element | None = None,
label: NodeType = None,
# format_options, # omitted because need to connect it to Deephaven formatting options as well
value_label: Element | None = None,
value_label: NodeType = None,
value: float = 0,
min_value: float = 0,
max_value: float = 100,
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/deephaven/ui/components/time_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Alignment,
)

from ..elements import Element
from ..elements import Element, NodeType
from .._internal.utils import (
create_props,
convert_time_props,
Expand Down Expand Up @@ -86,7 +86,7 @@ def time_field(
is_required: bool | None = None,
validation_behavior: ValidationBehavior | None = None,
auto_focus: bool | None = None,
label: Element | None = None,
label: NodeType = None,
description: Element | None = None,
error_message: Element | None = None,
name: str | None = None,
Expand Down
6 changes: 5 additions & 1 deletion plugins/ui/src/deephaven/ui/elements/Element.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any, Dict
from typing import Any, Dict, List, Union
from .._internal import RenderContext

PropsType = Dict[str, Any]
Expand Down Expand Up @@ -45,3 +45,7 @@ def render(self, context: RenderContext) -> PropsType:
The props of this element.
"""
pass


# Some props don't support Undefined, so they need to add it themselves
NodeType = Union[None, bool, int, str, Element, List["NodeType"]]
2 changes: 1 addition & 1 deletion plugins/ui/src/deephaven/ui/elements/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .Element import Element, PropsType
from .Element import Element, PropsType, NodeType
from .BaseElement import BaseElement
from .DashboardElement import DashboardElement
from .FunctionElement import FunctionElement
Expand Down

0 comments on commit 716b3d9

Please sign in to comment.