Slide toggle
Overview¶
Slide Toggle allows the user to toggle on and off and is based on the Angular Material slide toggle component.
Examples¶
import mesop as me
@me.stateclass
class State:
toggled: bool = False
def on_change(event: me.SlideToggleChangeEvent):
s = me.state(State)
s.toggled = not s.toggled
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="/slide_toggle",
)
def app():
with me.box(style=me.Style(margin=me.Margin.all(15))):
me.slide_toggle(label="Slide toggle", on_change=on_change)
s = me.state(State)
me.text(text=f"Toggled: {s.toggled}")
API¶
slide_toggle
¶
Creates a simple Slide toggle component with a text label.
PARAMETER | DESCRIPTION |
---|---|
label |
Text label for slide toggle
TYPE:
|
on_change |
An event will be dispatched each time the slide-toggle changes its value.
TYPE:
|
label_position |
Whether the label should appear after or before the slide-toggle. Defaults to 'after'.
TYPE:
|
required |
Whether the slide-toggle is required.
TYPE:
|
color |
Palette color of slide toggle.
TYPE:
|
disabled |
Whether the slide toggle is disabled.
TYPE:
|
disable_ripple |
Whether the slide toggle has a ripple.
TYPE:
|
tab_index |
Tabindex of slide toggle.
TYPE:
|
checked |
Whether the slide-toggle element is checked or not.
TYPE:
|
hide_icon |
Whether to hide the icon inside of the slide toggle.
TYPE:
|
key |
The component key.
TYPE:
|
content_slide_toggle
¶
Creates a Slide toggle component which is a composite component. Typically, you would use a text or icon component as a child.
Intended for advanced use cases.
PARAMETER | DESCRIPTION |
---|---|
on_change |
An event will be dispatched each time the slide-toggle changes its value.
TYPE:
|
label_position |
Whether the label should appear after or before the slide-toggle. Defaults to 'after'.
TYPE:
|
required |
Whether the slide-toggle is required.
TYPE:
|
color |
Palette color of slide toggle.
TYPE:
|
disabled |
Whether the slide toggle is disabled.
TYPE:
|
disable_ripple |
Whether the slide toggle has a ripple.
TYPE:
|
tab_index |
Tabindex of slide toggle.
TYPE:
|
checked |
Whether the slide-toggle element is checked or not.
TYPE:
|
hide_icon |
Whether to hide the icon inside of the slide toggle.
TYPE:
|
key |
The component key.
TYPE:
|
SlideToggleChangeEvent
dataclass
¶
Bases: MesopEvent
Event triggered when the slide toggle state changes.
ATTRIBUTE | DESCRIPTION |
---|---|
key |
Key of the component that emitted this event.
TYPE:
|