|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import random |
| 4 | +import warnings |
4 | 5 | from typing import Literal, Optional, cast |
5 | 6 |
|
6 | | -from htmltools import Tag, TagAttrs, TagAttrValue, TagChild, TagList, css, div |
7 | | -from htmltools import svg as svgtags |
8 | | -from htmltools import tags |
| 7 | +from htmltools import ( |
| 8 | + HTML, |
| 9 | + Tag, |
| 10 | + TagAttrs, |
| 11 | + TagAttrValue, |
| 12 | + TagChild, |
| 13 | + TagList, |
| 14 | + css, |
| 15 | + div, |
| 16 | + tags, |
| 17 | +) |
9 | 18 |
|
10 | 19 | from .._deprecated import warn_deprecated |
11 | 20 | from .._docstring import add_example |
@@ -184,10 +193,10 @@ def sidebar( |
184 | 193 | CSS classes for the sidebar container element, in addition to the fixed |
185 | 194 | `.sidebar` class. |
186 | 195 | max_height_mobile |
187 | | - The maximum height of the horizontal sidebar when viewed on mobile devices. |
188 | | - The default is `250px` unless the sidebar is included in a |
189 | | - :func:`~shiny.ui.layout_sidebar` with a specified height, in |
190 | | - which case the default is to take up no more than 50% of the layout container. |
| 196 | + A CSS length unit (passed through :func:`~shiny.ui.css.as_css_unit`) defining |
| 197 | + the maximum height of the horizontal sidebar when viewed on mobile devices. Only |
| 198 | + applies to always-open sidebars that use `open = "always"`, where by default the |
| 199 | + sidebar container is placed below the main content container on mobile devices. |
191 | 200 | gap |
192 | 201 | A CSS length unit defining the vertical `gap` (i.e., spacing) between elements |
193 | 202 | provided to `*args`. |
@@ -215,6 +224,14 @@ def sidebar( |
215 | 224 | """ |
216 | 225 | # TODO-future; validate `open`, bg, fg, class_, max_height_mobile |
217 | 226 |
|
| 227 | + if max_height_mobile is not None and open != "always": |
| 228 | + warnings.warn( |
| 229 | + "The `shiny.ui.sidebar(max_height_mobile=)` argument only applies to when `open = 'always'`. The `max_height_mobile` argument will be ignored.", |
| 230 | + # `stacklevel=2`: Refers to the caller of `sidebar()` |
| 231 | + stacklevel=2, |
| 232 | + ) |
| 233 | + max_height_mobile = None |
| 234 | + |
218 | 235 | if id is None and open != "always": |
219 | 236 | # but always provide id when collapsible for accessibility reasons |
220 | 237 | id = f"bslib_sidebar_{random.randint(1000, 10000)}" |
@@ -360,8 +377,6 @@ def layout_sidebar( # TODO-barret-API; Should this be `layout_sidebar(*args, si |
360 | 377 | "class": f"main{' bslib-gap-spacing' if fillable else ''}", |
361 | 378 | "" |
362 | 379 | "style": css( |
363 | | - background_color=bg, |
364 | | - color=fg, |
365 | 380 | gap=as_css_unit(gap), |
366 | 381 | padding=as_css_padding(padding), |
367 | 382 | ), |
@@ -391,8 +406,10 @@ def layout_sidebar( # TODO-barret-API; Should this be `layout_sidebar(*args, si |
391 | 406 | data_bslib_sidebar_border_radius=trinary(border_radius), |
392 | 407 | style=css( |
393 | 408 | __bslib_sidebar_width=as_css_unit(sidebar.width), |
394 | | - __bslib_sidebar_bg=as_css_unit(sidebar.color_bg), |
395 | | - __bslib_sidebar_fg=as_css_unit(sidebar.color_fg), |
| 409 | + __bslib_sidebar_bg=sidebar.color_bg, |
| 410 | + __bslib_sidebar_fg=sidebar.color_fg, |
| 411 | + __bslib_sidebar_main_fg=fg, |
| 412 | + __bslib_sidebar_main_bg=bg, |
396 | 413 | __bs_card_border_color=border_color, |
397 | 414 | height=as_css_unit(height), |
398 | 415 | __bslib_sidebar_max_height_mobile=as_css_unit(max_height_mobile), |
@@ -532,18 +549,9 @@ def callback() -> None: |
532 | 549 | _sidebar_func = sidebar |
533 | 550 |
|
534 | 551 |
|
535 | | -def _collapse_icon() -> Tag: |
536 | | - return tags.svg( |
537 | | - svgtags.path( |
538 | | - fill_rule="evenodd", |
539 | | - d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z", |
540 | | - ), |
541 | | - xmlns="http://www.w3.org/2000/svg", |
542 | | - viewBox="0 0 16 16", |
543 | | - class_="bi bi-chevron-down collapse-icon", |
544 | | - style="fill:currentColor;", |
545 | | - aria_hidden="true", |
546 | | - role="img", |
| 552 | +def _collapse_icon() -> TagChild: |
| 553 | + return HTML( |
| 554 | + '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" class="bi bi-arrow-bar-left collapse-icon" style="fill:currentColor;" aria-hidden="true" role="img" ><path fill-rule="evenodd" d="M12.5 15a.5.5 0 0 1-.5-.5v-13a.5.5 0 0 1 1 0v13a.5.5 0 0 1-.5.5ZM10 8a.5.5 0 0 1-.5.5H3.707l2.147 2.146a.5.5 0 0 1-.708.708l-3-3a.5.5 0 0 1 0-.708l3-3a.5.5 0 1 1 .708.708L3.707 7.5H9.5a.5.5 0 0 1 .5.5Z"></path></svg>' |
547 | 555 | ) |
548 | 556 |
|
549 | 557 |
|
|
0 commit comments