Skip to content

Commit

Permalink
Update imports
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke committed Oct 10, 2023
1 parent 886b202 commit dcf550f
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 92 deletions.
9 changes: 5 additions & 4 deletions shiny/experimental/ui/_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

from htmltools import Tag, TagAttrs, TagAttrValue, TagChild, css, div

from ._css_unit import CssUnit, as_css_unit
from ._fill import as_fill_item, as_fillable_container
from ._htmldeps import grid_dependency
from ._utils import consolidate_attrs, is_01_scalar
from ...ui._x._htmldeps import grid_dependency
from ...ui._x._utils import consolidate_attrs
from ...ui.css_unit import CssUnit, as_css_unit
from ...ui.fill import as_fill_item, as_fillable_container
from ._utils import is_01_scalar


def layout_column_wrap(
Expand Down
8 changes: 4 additions & 4 deletions shiny/experimental/ui/_navs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
from ..._utils import private_random_int
from ...types import NavSetArg
from ...ui._html_dependencies import bootstrap_deps
from ...ui._tag import tag_add_style
from ...ui.css_unit import CssUnit, as_css_padding, as_css_unit
from ...ui.fill import as_fill_carrier
from ._card import CardItem, card, card_body, card_footer, card_header
from ._css_unit import CssUnit, as_css_padding, as_css_unit
from ._fill import as_fill_carrier
from ._sidebar import Sidebar, layout_sidebar
from ._tag import tag_add_style


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -81,7 +81,7 @@ def tagify(self) -> None:


class NavSet:
args: tuple[NavSetArg | MetadataNode]
args: tuple[NavSetArg | MetadataNode, ...]
ul_class: str
id: Optional[str]
selected: Optional[str]
Expand Down
2 changes: 1 addition & 1 deletion shiny/experimental/ui/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
format_opt_names,
hover_opts,
)
from ._fill import as_fill_item, as_fillable_container
from ...ui.fill import as_fill_item, as_fillable_container


# @add_example()
Expand Down
8 changes: 4 additions & 4 deletions shiny/experimental/ui/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
from ...types import MISSING, MISSING_TYPE, NavSetArg
from ...ui._page import page_bootstrap
from ...ui._utils import get_window_title
from ._css_unit import CssUnit, as_css_padding, as_css_unit
from ._fill import as_fillable_container
from ._htmldeps import page_fillable_dependency, page_sidebar_dependency
from ...ui._x._htmldeps import page_fillable_dependency, page_sidebar_dependency
from ...ui._x._utils import consolidate_attrs
from ...ui.css_unit import CssUnit, as_css_padding, as_css_unit
from ...ui.fill import as_fillable_container
from ._navs import navset_bar
from ._sidebar import Sidebar, layout_sidebar
from ._utils import consolidate_attrs


def page_sidebar(
Expand Down
10 changes: 4 additions & 6 deletions shiny/experimental/ui/_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
from ... import Session
from ..._namespaces import resolve_id_or_none
from ...session import require_active_session

# from ._color import get_color_contrast
from ...ui._x._htmldeps import sidebar_dependency
from ...ui._x._utils import consolidate_attrs, trinary
from ...ui.css_unit import CssUnit, as_css_padding, as_css_unit
from ...ui.fill import as_fill_item, as_fillable_container
from ._card import CardItem
from ._css_unit import CssUnit, as_css_padding, as_css_unit
from ._fill import as_fill_item, as_fillable_container
from ._htmldeps import sidebar_dependency
from ._utils import consolidate_attrs, trinary


class Sidebar:
Expand Down
62 changes: 0 additions & 62 deletions shiny/experimental/ui/_utils.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,7 @@
from __future__ import annotations

import typing
from typing import overload

from htmltools import TagAttrs, TagAttrValue, TagChild, div

from ..._typing_extensions import TypeGuard

TagChildT = typing.TypeVar("TagChildT", bound=TagChild)


# If no children are provided, it will not be able to infer the type of `TagChildT`.
# Using `TagChild`
@overload
def consolidate_attrs(
*args: TagAttrs,
**kwargs: TagAttrValue,
) -> tuple[TagAttrs, list[TagChild]]:
...


# Same as original definition
@overload
def consolidate_attrs(
*args: TagChildT | TagAttrs,
**kwargs: TagAttrValue,
) -> tuple[TagAttrs, list[TagChildT]]:
...


def consolidate_attrs(
*args: TagChildT | TagAttrs,
**kwargs: TagAttrValue,
) -> tuple[TagAttrs, list[TagChildT]]:
tag = div(*args, **kwargs)

# `TagAttrs` currently isn't compatible with `htmltools._core.TagAttrDict`
# https://github.com/posit-dev/py-htmltools/pull/55
# Convert to a plain dict to avoid getting custom methods from TagAttrDict
# Cast to `TagAttrs` so that `Tag` functions will accept the dictionary.
attrs = typing.cast(TagAttrs, dict(tag.attrs))

# Do not alter children structure (like `TagList` does)
children = [child for child in args if not isinstance(child, dict)]
return (attrs, children)


def is_01_scalar(x: object) -> TypeGuard[float]:
return isinstance(x, (int, float)) and x >= 0.0 and x <= 1.0


@overload
def trinary(x: None) -> None:
...


@overload
def trinary(x: bool | str) -> str:
...


def trinary(x: bool | str | None) -> None | str:
if x is None:
return None
elif x:
return "true"
else:
return "false"
9 changes: 5 additions & 4 deletions shiny/experimental/ui/_valuebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

from htmltools import Tag, TagAttrs, TagAttrValue, TagChild, css, div, tags

from ...ui._x._htmldeps import value_box_dependency
from ...ui._x._utils import consolidate_attrs
from ...ui.css_unit import CssUnit, as_css_unit, as_width_unit
from ...ui.fill import as_fill_carrier
from ._card import CardItem, card, card_body
from ._css_unit import CssUnit, as_css_unit, as_width_unit
from ._fill import as_fill_carrier
from ._htmldeps import value_box_dependency
from ._layout import layout_column_wrap
from ._utils import consolidate_attrs, is_01_scalar
from ._utils import is_01_scalar

__all__ = (
"value_box",
Expand Down
7 changes: 4 additions & 3 deletions shiny/ui/_x/_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from htmltools import svg as svgtags
from htmltools import tags

from ...ui._x._htmldeps import sidebar_dependency

# from ._color import get_color_contrast
from ._css_unit import CssUnit, as_css_padding, as_css_unit
from ._fill import as_fill_item, as_fillable_container
from ._htmldeps import sidebar_dependency
from ...ui.css_unit import CssUnit, as_css_padding, as_css_unit
from ..fill import as_fill_item, as_fillable_container
from ._utils import consolidate_attrs, trinary


Expand Down
6 changes: 2 additions & 4 deletions shiny/ui/dataframe/_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ... import __version__
from ..._namespaces import resolve_id
from ...experimental.ui._fill import bind_fill_role
from ..fill import as_fill_carrier


def data_frame_deps() -> HTMLDependency:
Expand Down Expand Up @@ -40,12 +40,10 @@ def output_data_frame(id: str) -> Tag:
--------
:func:`~shiny.render.data_frame`
"""
return bind_fill_role(
return as_fill_carrier(
Tag(
"shiny-data-frame",
data_frame_deps(),
id=resolve_id(id),
),
item=True,
container=True,
)

0 comments on commit dcf550f

Please sign in to comment.