Пример #1
0
 def vote_option(choice):
     kwargs = {'checked': True} if choice == voted else {}
     return Block([
         label([
             input_(value=choice.name, name=name, type='radio', **kwargs),
             choice.description,
         ]),
     ])
Пример #2
0
    def render(self, name, value, attrs=None, renderer=None):
        widget = self.get_context(name, value, attrs)["widget"]

        w_name = widget.get("name", "")
        w_type = widget.get("type", "")
        w_attrs = widget.get("attrs", {})

        return div(class_="FileInput")[div(class_="PickFileButton")[
            input_(style="opacity: 0", type_=w_type, name=w_name, **w_attrs),
            _("Choose a file")],
                                       div(class_="FileStatus"
                                           )[_("No file chosen")], ].render()
Пример #3
0
def button(
    text,
    *,
    href=None,
    submit=False,
    reset=False,
    form=False,
    outline=False,
    clear=False,
    **kwargs,
):
    """
    A styled button element.

    Args:
        text (str or HTML element):
            Text content of the button.
        href (str):
            Optional hyperlink target. If given, the button is create as an
            anchor tag.
        submit (bool):
            If True, renders element as an <input type='submit'> element.
        reset (bool):
            If True, renders element as an <input type='reset'> element.
        form (bool):
            If True, renders element as an <input type='button'> element.
        outline (bool):
            If True, paints only the outline.
        clear:
            If True, renders a plain-text button with no background color or
            outline.

        ``button`` also accepts additional HTML attributes as keyword arguments.
    """
    classes = ["button"]
    if clear:
        classes.append("button-clear")
    if outline:
        classes.append("button-outline")

    if href:
        return hp.a(text, href=href, **kwargs).add_class(classes)
    elif submit or reset or form:
        if not isinstance(text, (str, int, float)):
            raise ValueError("submit inputs do not accept rich element children.")
        kind = "submit" if submit else "reset" if reset else "button"
        return hp.input_(value=text, type=kind, **kwargs).add_class(classes)
    else:
        return hp.button(text, **kwargs).add_class(classes)
Пример #4
0
def button(
    text,
    *,
    href=None,
    submit=False,
    reset=False,
    form=False,
    outline=False,
    clear=False,
    primary=False,
    secondary=False,
    dark=False,
    error=False,
    success=False,
    **kwargs,
):
    """
    A styled button element.

    Args:
        text (str or HTML element):
            Text content of the button.
        href (str):
            Optional hyperlink target. If given, the button is create as an
            anchor tag.
        submit (bool):
            If True, renders element as an <input type='submit'> element.
        reset (bool):
            If True, renders element as an <input type='reset'> element.
        form (bool):
            If True, renders element as an <input type='button'> element.
        outline (bool):
            If True, paints only the outline.
        clear:
            If True, renders a plain-text button with no background color or
            outline.
        primary (bool):
            Render button with strong color emphasis.
        secondary (bool):
            Render button with intermediate color emphasis.
        dark (bool):
            Render button with dark colors.
        success (bool):
            Render button with a color that denotes success (usually green).
        error (bool):
            Render button with a color that denotes failure (usually red).

        ``button`` also accepts additional HTML attributes as keyword arguments.
    """

    options = {
        "clear": clear,
        "outline": outline,
        "primary": primary,
        "secondary": secondary,
        "dark": dark,
        "error": error,
        "success": success,
    }
    classes = ["button"]
    classes.extend(cls for cls, enable in options.items() if enable)
    if href:
        return hp.a(text, href=href, **kwargs).add_class(classes)
    elif submit or reset or form:
        if not isinstance(text, (str, int, float)):
            raise ValueError(
                "submit inputs do not accept rich element children.")
        kind = "submit" if submit else "reset" if reset else "button"
        return hp.input_(value=text, type=kind, **kwargs).add_class(classes)
    else:
        return hp.button(text, **kwargs).add_class(classes)