Exemplo n.º 1
0
def annotation(body, label="", background="#ddd", color="#333", **style):
    """Build an HtmlElement span object with the given body and annotation label.

    The end result will look something like this:

        [body | label]

    Parameters
    ----------
    body : string
        The string to put in the "body" part of the annotation.
    label : string
        The string to put in the "label" part of the annotation.
    background : string
        The color to use for the background "chip" containing this annotation.
    color : string
        The color to use for the body and label text.
    **style : dict
        Any CSS you want to use to customize the containing "chip".

    Examples
    --------

    Produce a simple annotation with default colors:

    >>> annotation("apple", "fruit")

    Produce an annotation with custom colors:

    >>> annotation("apple", "fruit", background="#FF0", color="black")

    Produce an annotation with crazy CSS:

    >>> annotation("apple", "fruit", background="#FF0", border="1px dashed red")

    """

    if "font_family" not in style:
        style["font_family"] = "sans-serif"

    return span(style=styles(
        background=background,
        border_radius=rem(0.33),
        color=color,
        padding=(rem(0.17), rem(0.67)),
        display="inline-flex",
        justify_content="center",
        align_items="center",
        **style,
    ))(body,
       span(style=styles(
           color=color,
           font_size=em(0.67),
           opacity=0.5,
           padding_left=rem(0.5),
           text_transform="uppercase",
           margin_bottom=px(-2),
       ))(label))
Exemplo n.º 2
0
def annotate(body, label="", background="#ddd", color="#333", **style):
    if "font_family" not in style:
        style["font_family"] = "sans-serif"

    return span(style=styles(
        background=background,
        border_radius=rem(0.33),
        color=color,
        padding=(rem(0.17), rem(0.67)),
        display="inline",
        justify_content="center",
        align_items="center",
        **style,
    ))(body,
       span(style=styles(
           color=color,
           font_size=em(0.67),
           opacity=0.5,
           padding_left=rem(0.5),
           text_transform="uppercase",
           margin_bottom=px(-2),
       ))(label))
Exemplo n.º 3
0
 def test_varargs(self):
     self.assertEqual(px(10, 9, 8), ('10px', '9px', '8px'))
     self.assertEqual(px(0, 1), ('0', '1px'))
     self.assertEqual(em(5, 7), ('5em', '7em'))
     self.assertEqual(percent(99, 99.9), ('99%', '99.9%'))
Exemplo n.º 4
0
 def test_basic_usage(self):
     self.assertEqual(px(10), ('10px', ))
     self.assertEqual(px(0), ('0', ))
     self.assertEqual(em(5), ('5em', ))
     self.assertEqual(percent(99), ('99%', ))