AvatarMenu
Show a menu with the user's avatar and a list of items.
@solara.component
def AvatarMenu(image_url: Optional[str] = None, size: Union[int, str] = 40, color: str = "primary", children=[]):
...
By default the menu shows a logout button.
Example
import solara
from solara_enterprise import auth
@solara.component
def Page():
if not auth.user.value:
solara.Info("Login to see your avatar")
solara.Button("Login", icon_name="mdi-login", href=auth.get_login_url())
else:
auth.AvatarMenu() # this shows the user's picture
solara.Button("Logout", icon_name="mdi-logout", href=auth.get_logout_url())
Login to see your avatar
Live output
Note that a common use case is to put the avatar in the AppBar.
import solara
from solara_enterprise import auth
@solara.component
def Page():
solara.Title("Avatar in the app bar demo")
if not auth.user.value:
solara.Info("Login to see your avatar (see the button in the app bar)")
with solara.AppBar():
solara.Button(icon_name="mdi-login", href=auth.get_login_url(), icon=True)
else:
with solara.AppBar(): # this shows the user's picture in the app bar
with auth.AvatarMenu():
solara.Button("Logout", icon_name="mdi-logout", href=auth.get_logout_url(), text=True)
solara.Button("Fake user settings", icon_name="mdi-account-cog", text=True)
solara.Info("Logout via the appbar")
Live output
Arguments
- image_url: if not given, the picture from the user's profile will be used (OAuth only)
- size: size of the avatar (in pixels)
- color: color of the avatar (if no picture is available)
- children: list of elements to show in the menu