How to use the idom.html.button function in idom

To help you get started, weโ€™ve selected a few idom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rmorshea / idom / tests / test_core / test_events.py View on Github external
async def Button(self):
        async def on_click(event):
            clicked.set(True)
            self.update()

        if not clicked.get():
            return idom.html.button({"onClick": on_click, "id": "click"}, ["Click Me!"])
        else:
            return idom.html.p({"id": "complete"}, ["Complete"])
github rmorshea / idom / tests / test_server / test_sanic / test_shared_state_client.py View on Github external
async def IncrCounter(self, count=0):
        @idom.event
        async def incr_on_click(event):
            self.update(count + 1)

        button = idom.html.button(
            {"onClick": incr_on_click, "id": "incr-button"}, "click to increment"
        )

        return idom.html.div(button, Counter(count))
github rmorshea / idom / tests / test_widgets / test_jupyter.py View on Github external
async def SimpleButton(self):
        @idom.event
        async def on_click(event):
            clicked.set(True)

        return idom.html.button(
            {"id": "simple-button", "onClick": on_click}, "click me same origin"
        )
github rmorshea / idom / tests / test_core / test_hooks.py View on Github external
async def ComponentWithMemo():
        location, set_location = idom.hooks.use_state("left")
        count = idom.hooks.use_memo(function_to_memoize, location)

        async def on_left_button_click(event):
            set_location("left")

        async def on_right_button_click(event):
            set_location("right")

        return idom.html.div(
            idom.html.button(
                {"onClick": on_left_button_click, "id": "left-button"}, "left button"
            ),
            idom.html.button(
                {"onClick": on_right_button_click, "id": "right-button"}, "right button"
            ),
            f"Memo trigger count: {count}",
        )
github rmorshea / idom / tests / test_widgets / test_utils.py View on Github external
async def ButtonSwapsDivs(self):
        count = idom.Var(0)

        @idom.event
        async def on_click(event):
            count.value += 1
            mount(idom.html.div, {"id": f"hotswap-{count.value}"}, count.value)

        incr = idom.html.button({"onClick": on_click, "id": "incr-button"}, "incr")

        mount, make_hostswap = idom.widgets.hotswap(shared=True)
        mount(idom.html.div, {"id": f"hotswap-{count.value}"}, count.value)
        hotswap_view = make_hostswap()

        return idom.html.div(incr, hotswap_view)
github rmorshea / idom / tests / test_core / test_element.py View on Github external
async def CounterOnClick(self, count=0):
        count_thread.set(current_thread())

        @idom.event
        async def increment(event):
            self.update(count + 1)

        return idom.html.div(
            idom.html.button(
                {"onClick": increment, "id": "button"}, "click to increment"
            ),
            idom.html.p({"id": f"count-{count}"}, f"count: {count}"),
        )
github rmorshea / idom / tests / test_core / test_hooks.py View on Github external
async def ComponentWithMemo():
        location, set_location = idom.hooks.use_state("left")
        memoized_func = idom.hooks.use_lru_cache(function_to_memoize, maxsize=2)
        last_memoized_location = memoized_func(location)

        async def on_left_button_click(event):
            set_location("left")

        async def on_center_button_click(event):
            set_location("center")

        async def on_right_button_click(event):
            set_location("right")

        return idom.html.div(
            idom.html.button(
                {"onClick": on_left_button_click, "id": "left-button"}, "left button"
            ),
            idom.html.button(
                {"onClick": on_center_button_click, "id": "center-button"},
                "center button",
            ),
            idom.html.button(
                {"onClick": on_right_button_click, "id": "right-button"}, "right button"
            ),
            f"Last triggered on click: {last_memoized_location}",
        )
github rmorshea / idom / docs / source / widgets / click_count.py View on Github external
async def ClickCount(self):
    count, set_count = idom.hook.use_state(0)

    async def increment(event):
        set_count(count + 1)

    return idom.html.button({"onClick": increment}, [f"Click count: {count}"])
github rmorshea / idom / docs / source / widgets / todo.py View on Github external
async def Todo():
    items, set_items = idom.hooks.use_state([])

    async def add_new_task(event):
        if event["key"] == "Enter":
            set_items(items + [event["value"]])

    tasks = []

    for index, text in enumerate(items):

        async def remove_task(event, index=index):
            set_items(items[:index] + items[index + 1 :])

        task_text = idom.html.td(idom.html.p(text))
        delete_button = idom.html.td({"onClick": remove_task}, idom.html.button(["x"]))
        tasks.append(idom.html.tr(task_text, delete_button))

    task_input = idom.html.input({"onKeyDown": add_new_task})
    task_table = idom.html.table(tasks)

    return idom.html.div(task_input, task_table)