Ejemplo n.º 1
0
def DataList(items, filter_by_priority=None, sort_by_priority=False):
    if filter_by_priority is not None:
        items = [i for i in items if i["priority"] <= filter_by_priority]
    if sort_by_priority:
        items = list(sorted(items, key=lambda i: i["priority"]))
    list_item_elements = [html.li(i["text"], key=i["id"]) for i in items]
    return html.ul(list_item_elements)
Ejemplo n.º 2
0
def ArtistList():
    artist_to_add, set_artist_to_add = use_state("")
    artists, set_artists = use_state(
        ["Marta Colvin Andrade", "Lamidi Olonade Fakeye", "Louise Nevelson"])

    def handle_change(event):
        set_artist_to_add(event["target"]["value"])

    def handle_add_click(event):
        if artist_to_add not in artists:
            set_artists([*artists, artist_to_add])
            set_artist_to_add("")

    def make_handle_delete_click(index):
        def handle_click(event):
            set_artists(artists[:index] + artists[index + 1:])

        return handle_click

    return html.div(
        html.h1("Inspiring sculptors:"),
        html.input({
            "value": artist_to_add,
            "onChange": handle_change
        }),
        html.button({"onClick": handle_add_click}, "add"),
        html.ul([
            html.li(
                name,
                html.button({"onClick": make_handle_delete_click(index)},
                            "delete"),
                key=name,
            ) for index, name in enumerate(artists)
        ]),
    )
Ejemplo n.º 3
0
def ArtistList():
    artists, set_artists = use_state(
        ["Marta Colvin Andrade", "Lamidi Olonade Fakeye", "Louise Nevelson"])

    def handle_sort_click(event):
        set_artists(list(sorted(artists)))

    def handle_reverse_click(event):
        set_artists(list(reversed(artists)))

    return html.div(
        html.h1("Inspiring sculptors:"),
        html.button({"onClick": handle_sort_click}, "sort"),
        html.button({"onClick": handle_reverse_click}, "reverse"),
        html.ul([html.li(name, key=name) for name in artists]),
    )
Ejemplo n.º 4
0
def CounterList():
    counters, set_counters = use_state([0, 0, 0])

    def make_increment_click_handler(index):
        def handle_click(event):
            new_value = counters[index] + 1
            set_counters(counters[:index] + [new_value] + counters[index + 1 :])

        return handle_click

    return html.ul(
        [
            html.li(
                count,
                html.button({"onClick": make_increment_click_handler(index)}, "+1"),
                key=index,
            )
            for index, count in enumerate(counters)
        ]
    )
Ejemplo n.º 5
0
def ArtistList():
    artist_to_add, set_artist_to_add = use_state("")
    artists, set_artists = use_state([])

    def handle_change(event):
        set_artist_to_add(event["target"]["value"])

    def handle_click(event):
        if artist_to_add and artist_to_add not in artists:
            set_artists([*artists, artist_to_add])
            set_artist_to_add("")

    return html.div(
        html.h1("Inspiring sculptors:"),
        html.input({
            "value": artist_to_add,
            "onChange": handle_change
        }),
        html.button({"onClick": handle_click}, "add"),
        html.ul([html.li(name, key=name) for name in artists]),
    )
Ejemplo n.º 6
0
def DataList(items):
    list_item_elements = [html.li(text) for text in items]
    return html.ul(list_item_elements)
Ejemplo n.º 7
0
def MyTodoList():
    return html.div(
        html.h1("My Todo List"),
        html.img({"src": "https://picsum.photos/id/0/500/300"}),
        html.ul(html.li("The first thing I need to do is...")),
    )
Ejemplo n.º 8
0
def Item(name, done):
    return html.li(name, " ✔" if done else "")
Ejemplo n.º 9
0
def Item(name, done):
    if done:
        return html.li(name, " ✔")
    else:
        return html.li(name)
Ejemplo n.º 10
0
def Item(name, done):
    return html.li(name)