Source code for duck.html.components.button

"""
This module contains various types of Button components.
"""
from typing import Dict

from duck.html.components import InnerComponent
from duck.html.components.theme import Theme


[docs] class Clickable: """ This is just a flag which tells us if a component is clickable. """
[docs] class Button(Clickable, InnerComponent): """ Basic button component. """
[docs] def get_element(self): return "button"
[docs] def on_create(self): super().on_create() btn_style = { "padding": "10px 20px", "cursor": "pointer", "transition": "background-color 0.3s ease", "border": "none", "border-radius": Theme.current.border_radius, "outline": "none", } # Set default button style. self.style.setdefaults(btn_style) # SEO and other metadata for the button self.props.setdefault("role", self.kwargs.get("role", "button")) self.props.setdefault("type", self.kwargs.get("type", "button"))
[docs] class RoundedButton(Button): """ Rounded button component. """
[docs] def on_create(self): super().on_create() self.style.update({"border-radius": "50%"})
[docs] class FlatButton(Button): """ Flat button component. """
[docs] def on_create(self): super().on_create() self.style.setdefaults({ "background-color": "transparent" })
[docs] class RaisedButton(Button): """ Raised button component. """
[docs] def on_create(self): super().on_create() self.style.update({"box-shadow": "0 2px 2px rgba(0, 0, 0, 0.2)"}) # override box shadow nomatter what