diff --git a/leafmap/map_widgets.py b/leafmap/map_widgets.py index 7b1f2c380c..2bf4105ae0 100644 --- a/leafmap/map_widgets.py +++ b/leafmap/map_widgets.py @@ -4,6 +4,7 @@ import ipywidgets as widgets from . import common +from . import vuetify_compat as vc class Colorbar(widgets.Output): @@ -1050,35 +1051,41 @@ def __init__( # Toolbar self._title = v.ToolbarTitle(children=[title]) self._refresh_btn = v.Btn( - icon=True, children=[v.Icon(children=["mdi-refresh"])], tooltip="Refresh" + **vc.icon_button(), + children=[v.Icon(children=["mdi-refresh"])], + tooltip="Refresh", ) self._help_btn = v.Btn( - icon=True, + **vc.icon_button(), children=[v.Icon(children=["mdi-help-circle-outline"])], tooltip="Help", ) self._toolbar = v.Toolbar( - dense=True, + **vc.dense(), flat=True, color="primary" if dark_topbar else "white", - dark=dark_topbar, + **vc.dark_theme(dark_topbar), children=[self._title, v.Spacer(), self._refresh_btn, self._help_btn], ) # Tabs header & items (linked by jslink) self._tabs_header = v.Tabs( v_model=0, - background_color="transparent", + **vc.tabs_background("transparent"), slider_color="primary", class_="px-4" if show_tab_header else "px-4 d-none", children=[], ) - self._tabs_items = v.TabsItems(v_model=0, children=[]) + self._tabs_items = vc.TabsWindow(v_model=0, children=[]) widgets.jslink((self._tabs_header, "v_model"), (self._tabs_items, "v_model")) # Snackbar for quick feedback self._snackbar = v.Snackbar( - v_model=False, timeout=1400, color="primary", bottom=True, children=[""] + v_model=False, + timeout=1400, + color="primary", + **vc.location_bottom(), + children=[""], ) # Help dialog (default content) @@ -1090,7 +1097,9 @@ def __init__( """) self._help_title = v.CardTitle(class_="text-h6", children=["Help"]) self._help_cardtext = v.CardText(class_="py-4", children=[default_help]) - self._help_close_btn = v.Btn(text=True, color="primary", children=["Close"]) + self._help_close_btn = v.Btn( + **vc.text_button(), color="primary", children=["Close"] + ) self._help_card = v.Card( class_="rounded-xl", children=[ @@ -1271,7 +1280,10 @@ def set_tab_icon(self, index: int, icon: Optional[str]) -> None: tab = self._tabs_header.children[index] label = self._labels[index] if icon: - tab.children = [v.Icon(left=True, small=True, children=[icon]), label] + tab.children = [ + v.Icon(**vc.icon_start(), **vc.small(), children=[icon]), + label, + ] else: tab.children = [label] if index < len(self._icons): @@ -1448,13 +1460,18 @@ def _append_tab(self, label: str, icon: str, body: widgets.Widget) -> None: hdr_children = list(self._tabs_header.children) items_children = list(self._tabs_items.children) tab_hdr = ( - v.Tab(children=[v.Icon(left=True, small=True, children=[icon]), label]) + v.Tab( + children=[ + v.Icon(**vc.icon_start(), **vc.small(), children=[icon]), + label, + ] + ) if icon else v.Tab(children=[label]) ) hdr_children.append(tab_hdr) content = self._card(label, body) if self._wrap_in_card else body - items_children.append(v.TabItem(children=[content])) + items_children.append(vc.TabsWindowItem(children=[content])) self._tabs_header.children = tuple(hdr_children) self._tabs_items.children = tuple(items_children) @@ -1478,13 +1495,18 @@ def _insert_tab( if not (0 <= index <= n): raise IndexError(f"index {index} out of range (0..{n})") tab_hdr = ( - v.Tab(children=[v.Icon(left=True, small=True, children=[icon]), label]) + v.Tab( + children=[ + v.Icon(**vc.icon_start(), **vc.small(), children=[icon]), + label, + ] + ) if icon else v.Tab(children=[label]) ) hdr_children.insert(index, tab_hdr) content = self._card(label, body) if self._wrap_in_card else body - items_children.insert(index, v.TabItem(children=[content])) + items_children.insert(index, vc.TabsWindowItem(children=[content])) self._tabs_header.children = tuple(hdr_children) self._tabs_items.children = tuple(items_children) self._labels.insert(index, label) diff --git a/leafmap/maplibregl.py b/leafmap/maplibregl.py index c1971b72db..6fc662b3b1 100644 --- a/leafmap/maplibregl.py +++ b/leafmap/maplibregl.py @@ -32,6 +32,7 @@ from maplibre.sources import GeoJSONSource, RasterTileSource from . import common +from . import vuetify_compat as vc from .basemaps import xyz_to_leaflet from .common import ( _in_colab_shell, @@ -92,14 +93,18 @@ def _panel_header_chevron(color: str) -> List[Dict[str, Any]]: The default expand/collapse icon follows the Vuetify theme and is nearly invisible on the light sidebar headers in dark mode, so it is colored - explicitly. + explicitly. Vuetify 3 swaps between expand and collapse icons instead of + rotating a custom one, and its icon takes the header text color, so no slot + is needed there. Args: color (str): The CSS color of the chevron. Returns: - The ``v_slots`` list for ``v.ExpansionPanelHeader``. + The ``v_slots`` list for ``vc.ExpansionPanelTitle``. """ + if vc.VUETIFY3: + return [] return [ { "name": "actions", @@ -5567,11 +5572,11 @@ def add_floating_sidebar( # Create toggle button toggle_icon = v.Icon( children=["mdi-chevron-left"] if sidebar_visible else ["mdi-chevron-right"], - small=True, + **vc.small(), style_=f"color: {SIDEBAR_PANEL_TEXT_COLOR};", ) toggle_btn = v.Btn( - icon=True, + **vc.icon_button(), children=[toggle_icon], style_=( f"width: 22px; height: 22px; min-width: 22px; padding: 0; " @@ -5582,11 +5587,11 @@ def add_floating_sidebar( # Create settings/wrench button settings_icon = v.Icon( children=["mdi-wrench"], - small=True, + **vc.small(), style_=f"color: {SIDEBAR_PANEL_TEXT_COLOR};", ) settings_btn = v.Btn( - icon=True, + **vc.icon_button(), children=[settings_icon], style_=( f"width: 22px; height: 22px; min-width: 22px; padding: 0; " @@ -8250,6 +8255,37 @@ class Container(v.Container): row (v.Row): The main layout row containing the map and sidebar. """ + # ipyvuetify 3 adds synced ``min_width`` and ``max_width`` traits to + # ``v.Container``. These properties shadow them so the sidebar widths are + # kept in Python only and do not constrain the whole container. + @property + def min_width(self) -> int: + """int: Minimum width of the sidebar in pixels.""" + return self._sidebar_min_width + + @min_width.setter + def min_width(self, value: int) -> None: + """Sets the minimum width of the sidebar. + + Args: + value (int): The minimum width in pixels. + """ + self._sidebar_min_width = value + + @property + def max_width(self) -> int: + """int: Maximum width of the sidebar in pixels.""" + return self._sidebar_max_width + + @max_width.setter + def max_width(self, value: int) -> None: + """Sets the maximum width of the sidebar. + + Args: + value (int): The maximum width in pixels. + """ + self._sidebar_max_width = value + def __init__( self, host_map: Optional[Any] = None, @@ -8312,7 +8348,7 @@ def __init__( style_=f"color: {SIDEBAR_PANEL_TEXT_COLOR};", ) self.toggle_btn = v.Btn( - icon=True, + **vc.icon_button(), children=[self.toggle_icon], style_=( f"width: 48px; height: 48px; min-width: 48px; " @@ -8327,7 +8363,7 @@ def __init__( style_=f"color: {SIDEBAR_PANEL_TEXT_COLOR};", ) self.settings_btn = v.Btn( - icon=True, + **vc.icon_button(), children=[self.settings_icon], style_=f"width: 36px; height: 36px; color: {SIDEBAR_PANEL_TEXT_COLOR};", ) @@ -10469,8 +10505,8 @@ def __init__( # Close icon button close_btn = v.Btn( - icon=True, - small=True, + **vc.icon_button(), + **vc.small(), class_="ma-0", style_=f"min-width: 24px; width: 24px; color: {text_color};", children=[ @@ -10482,7 +10518,7 @@ def __init__( ) close_btn.on_event("click", self._handle_close) - header = v.ExpansionPanelHeader( + header = vc.ExpansionPanelTitle( style_=( f"height: {height}; min-height: {height}; " f"background-color: {background_color}; " @@ -10514,7 +10550,7 @@ def __init__( # uses a dark theme. panel_style = widgets.HTML( "