Skip to content

Badge

Overview

Badge decorates a UI component and is oftentimes used for unread message count and is based on the Angular Material badge component.

Examples

import mesop as me


def load(e: me.LoadEvent):
  me.set_theme_mode("system")


@me.page(
  on_load=load,
  security_policy=me.SecurityPolicy(
    allowed_iframe_parents=["https://google.github.io"]
  ),
  path="/badge",
)
def app():
  with me.box(
    style=me.Style(
      display="block",
      padding=me.Padding(top=16, right=16, bottom=16, left=16),
      height=50,
      width=30,
    )
  ):
    with me.badge(content="1", size="medium"):
      me.text(text="text with badge")

API

badge

Creates a Badge component. Badge is a composite component.

PARAMETER DESCRIPTION
color

The color of the badge. Can be primary, accent, or warn.

TYPE: Literal['primary', 'accent', 'warn'] DEFAULT: 'primary'

overlap

Whether the badge should overlap its contents or not

TYPE: bool DEFAULT: False

disabled

Whether the badge is disabled.

TYPE: bool DEFAULT: False

position

Position the badge should reside. Accepts any combination of 'above'|'below' and 'before'|'after'

TYPE: Literal['above after', 'above before', 'below before', 'below after', 'before', 'after', 'above', 'below'] DEFAULT: 'above after'

content

The content for the badge

TYPE: str DEFAULT: ''

description

Message used to describe the decorated element via aria-describedby

TYPE: str DEFAULT: ''

size

Size of the badge. Can be 'small', 'medium', or 'large'.

TYPE: Literal['small', 'medium', 'large'] DEFAULT: 'small'

hidden

Whether the badge is hidden.

TYPE: bool DEFAULT: False

key

The component key.

TYPE: str | None DEFAULT: None