GitHub

API reference for Button.

A button definition. of gives the element to post, taking the value when the definition has a schema for one; label and style override this one element's. of raises when the value cannot be encoded.

Attributes

AttributeTypeDescription
idI_co
labelstr
styleU.ButtonStyle | None
valueValueSchema[Any] | None
kindLiteral['button'] = field(default='button', init=False)

Functions

__init__

__init__(id, label, style, value) -> None
ParameterTypeDescription
idI_co
labelstr
styleU.ButtonStyle | None
valueValueSchema[Any] | None

of

of(*, label: str | None = None, style: U.ButtonStyle | None = None) -> U.Button
of[VV](value: VV, /, *, label: str | None = None, style: U.ButtonStyle | None = None) -> U.Button
ParameterTypeDescription
value= None
label= None
style= None
@overload
def of(
    self: Button[Any, None],
    /,
    *,
    label: str | None = None,
    style: U.ButtonStyle | None = None,
) -> U.Button: ...
@overload
def of[VV](
    self: Button[Any, VV],
    value: VV,
    /,
    *,
    label: str | None = None,
    style: U.ButtonStyle | None = None,
) -> U.Button: ...
def of(
    self: Button[Any, Any],
    value: object = None,
    /,
    *,
    label: str | None = None,
    style: U.ButtonStyle | None = None,
) -> U.Button:
    return U.Button(
        id=self.id,
        label=self.label if label is None else label,
        style=style if style is not None else self.style,
        value=None if self.value is None else encode_value(self.value, value),
    )

handler

handler[VV, RR = Never](fn) -> Handled[I_co, RR]

This button's handler: it answers ack or a modal to open.

ParameterTypeDescription
fnCallable[[Click[VV]], Effect[ClickReply, Never, RR]]

Returns Handled[I_co, RR]

def handler[VV, RR = Never](
    self: Button[I_co, VV], fn: Callable[[Click[VV]], Effect[ClickReply, Never, RR]]
) -> Handled[I_co, RR]:
    """This button's handler: it answers ``ack`` or a modal to open."""
    return Handled(cast("Definition", self), fn)