Skip to content

Commit bb1038c

Browse files
committed
modify vdom interface usage
1 parent 18daa75 commit bb1038c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+223
-346
lines changed

docs/examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def Wrapper():
122122
def PrintView():
123123
text, set_text = idom.hooks.use_state(print_buffer.getvalue())
124124
print_buffer.set_callback(set_text)
125-
return idom.html.pre({"class": "printout"}, text) if text else idom.html.div()
125+
return idom.html.pre(text, class_="printout") if text else idom.html.div()
126126

127127
return Wrapper()
128128

docs/source/guides/adding-interactivity/components-with-state/_examples/adding_state_variable/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def handle_click(event):
2525
url = sculpture["url"]
2626

2727
return html.div(
28-
html.button({"onClick": handle_click}, "Next"),
28+
html.button("Next", on_click=handle_click),
2929
html.h2(name, " by ", artist),
3030
html.p(f"({bounded_index + 1} of {len(sculpture_data)})"),
31-
html.img({"src": url, "alt": alt, "style": {"height": "200px"}}),
31+
html.img(src=url, alt=alt, style={"height": "200px"}),
3232
html.p(description),
3333
)
3434

docs/source/guides/adding-interactivity/components-with-state/_examples/isolated_state/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ def handle_more_click(event):
2929
url = sculpture["url"]
3030

3131
return html.div(
32-
html.button({"onClick": handle_next_click}, "Next"),
32+
html.button("Next", on_click=handle_next_click),
3333
html.h2(name, " by ", artist),
3434
html.p(f"({bounded_index + 1} or {len(sculpture_data)})"),
35-
html.img({"src": url, "alt": alt, "style": {"height": "200px"}}),
35+
html.img(src=url, alt=alt, style={"height": "200px"}),
3636
html.div(
3737
html.button(
38-
{"onClick": handle_more_click},
39-
f"{'Show' if show_more else 'Hide'} details",
38+
f"{('Show' if show_more else 'Hide')} details",
39+
on_click=handle_more_click,
4040
),
41-
(html.p(description) if show_more else ""),
41+
html.p(description) if show_more else "",
4242
),
4343
)
4444

4545

4646
@component
4747
def App():
4848
return html.div(
49-
html.section({"style": {"width": "50%", "float": "left"}}, Gallery()),
50-
html.section({"style": {"width": "50%", "float": "left"}}, Gallery()),
49+
html.section(Gallery(), style={"width": "50%", "float": "left"}),
50+
html.section(Gallery(), style={"width": "50%", "float": "left"}),
5151
)
5252

5353

docs/source/guides/adding-interactivity/components-with-state/_examples/multiple_state_variables/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ def handle_more_click(event):
2929
url = sculpture["url"]
3030

3131
return html.div(
32-
html.button({"onClick": handle_next_click}, "Next"),
32+
html.button("Next", on_click=handle_next_click),
3333
html.h2(name, " by ", artist),
3434
html.p(f"({bounded_index + 1} or {len(sculpture_data)})"),
35-
html.img({"src": url, "alt": alt, "style": {"height": "200px"}}),
35+
html.img(src=url, alt=alt, style={"height": "200px"}),
3636
html.div(
3737
html.button(
38-
{"onClick": handle_more_click},
39-
f"{'Show' if show_more else 'Hide'} details",
38+
f"{('Show' if show_more else 'Hide')} details",
39+
on_click=handle_more_click,
4040
),
41-
(html.p(description) if show_more else ""),
41+
html.p(description) if show_more else "",
4242
),
4343
)
4444

docs/source/guides/adding-interactivity/components-with-state/_examples/when_variables_are_not_enough/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def handle_click(event):
3131
url = sculpture["url"]
3232

3333
return html.div(
34-
html.button({"onClick": handle_click}, "Next"),
34+
html.button("Next", on_click=handle_click),
3535
html.h2(name, " by ", artist),
3636
html.p(f"({bounded_index + 1} or {len(sculpture_data)})"),
37-
html.img({"src": url, "alt": alt, "style": {"height": "200px"}}),
37+
html.img(src=url, alt=alt, style={"height": "200px"}),
3838
html.p(description),
3939
)
4040

docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/dict_remove.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,25 @@ def handle_click(event):
2626
return handle_click
2727

2828
return html.div(
29-
html.button({"onClick": handle_add_click}, "add term"),
29+
html.button("add term", on_click=handle_add_click),
3030
html.label(
31-
"Term: ",
32-
html.input({"value": term_to_add, "onChange": handle_term_to_add_change}),
31+
"Term: ", html.input(value=term_to_add, on_change=handle_term_to_add_change)
3332
),
3433
html.label(
3534
"Definition: ",
3635
html.input(
37-
{
38-
"value": definition_to_add,
39-
"onChange": handle_definition_to_add_change,
40-
}
36+
value=definition_to_add, on_change=handle_definition_to_add_change
4137
),
4238
),
4339
html.hr(),
4440
[
4541
html.div(
46-
html.button(
47-
{"onClick": make_delete_click_handler(term)}, "delete term"
48-
),
42+
html.button("delete term", on_click=make_delete_click_handler(term)),
4943
html.dt(term),
5044
html.dd(definition),
5145
key=term,
5246
)
53-
for term, definition in all_terms.items()
47+
for (term, definition) in all_terms.items()
5448
],
5549
)
5650

docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/dict_update.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,14 @@ def handle_email_change(event):
2323
return html.div(
2424
html.label(
2525
"First name: ",
26-
html.input(
27-
{"value": person["first_name"], "onChange": handle_first_name_change},
28-
),
26+
html.input(value=person["first_name"], on_change=handle_first_name_change),
2927
),
3028
html.label(
3129
"Last name: ",
32-
html.input(
33-
{"value": person["last_name"], "onChange": handle_last_name_change},
34-
),
30+
html.input(value=person["last_name"], on_change=handle_last_name_change),
3531
),
3632
html.label(
37-
"Email: ",
38-
html.input(
39-
{"value": person["email"], "onChange": handle_email_change},
40-
),
33+
"Email: ", html.input(value=person["email"], on_change=handle_email_change)
4134
),
4235
html.p(f"{person['first_name']} {person['last_name']} {person['email']}"),
4336
)

docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/list_insert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def handle_click(event):
1616

1717
return html.div(
1818
html.h1("Inspiring sculptors:"),
19-
html.input({"value": artist_to_add, "onChange": handle_change}),
20-
html.button({"onClick": handle_click}, "add"),
19+
html.input(value=artist_to_add, on_change=handle_change),
20+
html.button("add", on_click=handle_click),
2121
html.ul([html.li(name, key=name) for name in artists]),
2222
)
2323

docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/list_re_order.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def handle_reverse_click(event):
1515

1616
return html.div(
1717
html.h1("Inspiring sculptors:"),
18-
html.button({"onClick": handle_sort_click}, "sort"),
19-
html.button({"onClick": handle_reverse_click}, "reverse"),
18+
html.button("sort", on_click=handle_sort_click),
19+
html.button("reverse", on_click=handle_reverse_click),
2020
html.ul([html.li(name, key=name) for name in artists]),
2121
)
2222

docs/source/guides/adding-interactivity/dangers-of-mutability/_examples/list_remove.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ def handle_click(event):
2424

2525
return html.div(
2626
html.h1("Inspiring sculptors:"),
27-
html.input({"value": artist_to_add, "onChange": handle_change}),
28-
html.button({"onClick": handle_add_click}, "add"),
27+
html.input(value=artist_to_add, on_change=handle_change),
28+
html.button("add", on_click=handle_add_click),
2929
html.ul(
3030
[
3131
html.li(
3232
name,
33-
html.button({"onClick": make_handle_delete_click(index)}, "delete"),
33+
html.button("delete", on_click=make_handle_delete_click(index)),
3434
key=name,
3535
)
36-
for index, name in enumerate(artists)
36+
for (index, name) in enumerate(artists)
3737
]
3838
),
3939
)

0 commit comments

Comments
 (0)