Skip to content

Commit e8263de

Browse files
authored
Rewrite style props (#936)
* rewrite style prop + other fixes * apply rewrites * changelog * remove extra print * minor annotation improvement * fix class_name * more helpful error message * fix types * fix typo
1 parent 3aa249d commit e8263de

29 files changed

+157
-115
lines changed

docs/examples.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ 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 (
126+
idom.html.pre({"class_name": "printout"}, text) if text else idom.html.div()
127+
)
126128

127129
return Wrapper()
128130

docs/source/_exts/custom_autosectionlabel.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
https://github.com/sphinx-doc/sphinx/blob/f9968594206e538f13fa1c27c065027f10d4ea27/LICENSE
55
"""
66

7+
from __future__ import annotations
8+
79
from fnmatch import fnmatch
8-
from typing import Any, Dict, cast
10+
from typing import Any, cast
911

1012
from docutils import nodes
1113
from docutils.nodes import Node
@@ -30,7 +32,6 @@ def get_node_depth(node: Node) -> int:
3032

3133
def register_sections_as_label(app: Sphinx, document: Node) -> None:
3234
docname = app.env.docname
33-
print(docname)
3435

3536
for pattern in app.config.autosectionlabel_skip_docs:
3637
if fnmatch(docname, pattern):
@@ -67,7 +68,7 @@ def register_sections_as_label(app: Sphinx, document: Node) -> None:
6768
domain.labels[name] = docname, labelid, sectname
6869

6970

70-
def setup(app: Sphinx) -> Dict[str, Any]:
71+
def setup(app: Sphinx) -> dict[str, Any]:
7172
app.add_config_value("autosectionlabel_prefix_document", False, "env")
7273
app.add_config_value("autosectionlabel_maxdepth", None, "env")
7374
app.add_config_value("autosectionlabel_skip_docs", [], "env")

docs/source/about/changelog.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ more info, see the :ref:`Contributor Guide <Creating a Changelog Entry>`.
2323
Unreleased
2424
----------
2525

26-
No changes.
26+
**Fixed**
27+
28+
- :pull:`936` - remaining issues from :pull:`934`
2729

2830

2931
v1.0.0-a5

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ async def handle_pointer_move(event):
2222
"position": "relative",
2323
"height": "200px",
2424
"width": "100%",
25-
"backgroundColor": "white",
25+
"background_color": "white",
2626
},
2727
},
2828
html.div(
2929
{
3030
"style": {
3131
"position": "absolute",
32-
"backgroundColor": "red",
33-
"borderRadius": "50%",
32+
"background_color": "red",
33+
"border_radius": "50%",
3434
"width": "20px",
3535
"height": "20px",
3636
"left": "-10px",

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def handle_pointer_move(event):
2020
"position": "relative",
2121
"height": "200px",
2222
"width": "100%",
23-
"backgroundColor": "white",
23+
"background_color": "white",
2424
},
2525
},
2626
html.div(
2727
{
2828
"style": {
2929
"position": "absolute",
30-
"backgroundColor": "red",
31-
"borderRadius": "50%",
30+
"background_color": "red",
31+
"border_radius": "50%",
3232
"width": "20px",
3333
"height": "20px",
3434
"left": "-10px",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def handle_click(event):
2424
"style": {
2525
"height": "30px",
2626
"width": "30px",
27-
"backgroundColor": "black"
27+
"background_color": "black"
2828
if index in selected_indices
2929
else "white",
3030
"outline": "1px solid grey",

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def handle_click(event):
2121
"style": {
2222
"height": "30px",
2323
"width": "30px",
24-
"backgroundColor": "black"
24+
"background_color": "black"
2525
if index in selected_indices
2626
else "white",
2727
"outline": "1px solid grey",

docs/source/guides/adding-interactivity/multiple-state-updates/_examples/set_color_3_times.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ def handle_reset(event):
1515

1616
return html.div(
1717
html.button(
18-
{"on_click": handle_click, "style": {"backgroundColor": color}}, "Set Color"
18+
{"on_click": handle_click, "style": {"background_color": color}},
19+
"Set Color",
1920
),
2021
html.button(
21-
{"on_click": handle_reset, "style": {"backgroundColor": color}}, "Reset"
22+
{"on_click": handle_reset, "style": {"background_color": color}}, "Reset"
2223
),
2324
)
2425

docs/source/guides/adding-interactivity/responding-to-events/_examples/audio_player.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def PlayDinosaurSound():
1010
idom.html.audio(
1111
{
1212
"controls": True,
13-
"onTimeUpdate": lambda e: set_event(e),
13+
"on_time_update": lambda e: set_event(e),
1414
"src": "https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3",
1515
}
1616
),

docs/source/guides/adding-interactivity/responding-to-events/_examples/stop_event_propagation.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ def DivInDiv():
1010
div_in_div = html.div(
1111
{
1212
"on_click": lambda event: set_outer_count(outer_count + 1),
13-
"style": {"height": "100px", "width": "100px", "backgroundColor": "red"},
13+
"style": {"height": "100px", "width": "100px", "background_color": "red"},
1414
},
1515
html.div(
1616
{
1717
"on_click": event(
1818
lambda event: set_inner_count(inner_count + 1),
1919
stop_propagation=stop_propagatation,
2020
),
21-
"style": {"height": "50px", "width": "50px", "backgroundColor": "blue"},
21+
"style": {
22+
"height": "50px",
23+
"width": "50px",
24+
"background_color": "blue",
25+
},
2226
}
2327
),
2428
)

docs/source/reference/_examples/character_movement/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def Scene():
4242
"style": {
4343
"width": "200px",
4444
"height": "200px",
45-
"backgroundColor": "slategray",
45+
"background_color": "slategray",
4646
}
4747
},
4848
image(

docs/source/reference/_examples/click_count.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ def ClickCount():
66
count, set_count = idom.hooks.use_state(0)
77

88
return idom.html.button(
9-
{"onClick": lambda event: set_count(count + 1)},
10-
[f"Click count: {count}"],
9+
{"on_click": lambda event: set_count(count + 1)}, [f"Click count: {count}"]
1110
)
1211

1312

docs/source/reference/_examples/matplotlib_plot.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def del_input():
3939
return idom.html.div(
4040
idom.html.div(
4141
"add/remove term:",
42-
idom.html.button({"onClick": lambda event: add_input()}, "+"),
43-
idom.html.button({"onClick": lambda event: del_input()}, "-"),
42+
idom.html.button({"on_click": lambda event: add_input()}, "+"),
43+
idom.html.button({"on_click": lambda event: del_input()}, "-"),
4444
),
4545
inputs,
4646
)
@@ -65,12 +65,7 @@ def poly_coef_input(index, callback):
6565
" × X",
6666
idom.html.sup(index),
6767
),
68-
idom.html.input(
69-
{
70-
"type": "number",
71-
"onChange": callback,
72-
},
73-
),
68+
idom.html.input({"type": "number", "on_change": callback}),
7469
)
7570

7671

docs/source/reference/_examples/simple_dashboard.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def update_value(value):
8383
set_value_callback(value)
8484

8585
return idom.html.fieldset(
86-
{"class": "number-input-container"},
86+
{"class_name": "number-input-container"},
8787
idom.html.legend({"style": {"font-size": "medium"}}, label),
8888
Input(update_value, "number", value, attributes=attrs, cast=float),
8989
Input(update_value, "range", value, attributes=attrs, cast=float),

docs/source/reference/_examples/slideshow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def next_image(event):
1212
{
1313
"src": f"https://picsum.photos/id/{index}/800/300",
1414
"style": {"cursor": "pointer"},
15-
"onClick": next_image,
15+
"on_click": next_image,
1616
}
1717
)
1818

docs/source/reference/_examples/snake_game.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def GameView():
2121
return GameLoop(grid_size=6, block_scale=50, set_game_state=set_game_state)
2222

2323
start_button = idom.html.button(
24-
{"onClick": lambda event: set_game_state(GameState.play)},
25-
"Start",
24+
{"on_click": lambda event: set_game_state(GameState.play)}, "Start"
2625
)
2726

2827
if game_state == GameState.won:
@@ -40,7 +39,7 @@ def GameView():
4039
"""
4140
)
4241

43-
return idom.html.div({"className": "snake-game-menu"}, menu_style, menu)
42+
return idom.html.div({"class_name": "snake-game-menu"}, menu_style, menu)
4443

4544

4645
class Direction(enum.Enum):
@@ -72,7 +71,7 @@ def on_direction_change(event):
7271
if direction_vector_sum != (0, 0):
7372
direction.current = maybe_new_direction
7473

75-
grid_wrapper = idom.html.div({"onKeyDown": on_direction_change}, grid)
74+
grid_wrapper = idom.html.div({"on_key_down": on_direction_change}, grid)
7675

7776
assign_grid_block_color(grid, food, "blue")
7877

@@ -149,7 +148,7 @@ def create_grid(grid_size, block_scale):
149148
"grid-template-columns": f"repeat({grid_size}, {block_scale}px)",
150149
"grid-template-rows": f"repeat({grid_size}, {block_scale}px)",
151150
},
152-
"tabIndex": -1,
151+
"tab_index": -1,
153152
},
154153
[
155154
idom.html.div(
@@ -170,11 +169,11 @@ def create_grid_block(color, block_scale, key):
170169
"style": {
171170
"height": f"{block_scale}px",
172171
"width": f"{block_scale}px",
173-
"backgroundColor": color,
172+
"background_color": color,
174173
"outline": "1px solid grey",
175174
},
176175
"key": key,
177-
},
176+
}
178177
)
179178

180179

docs/source/reference/_examples/todo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ async def remove_task(event, index=index):
1717
set_items(items[:index] + items[index + 1 :])
1818

1919
task_text = idom.html.td(idom.html.p(text))
20-
delete_button = idom.html.td({"onClick": remove_task}, idom.html.button(["x"]))
20+
delete_button = idom.html.td({"on_click": remove_task}, idom.html.button(["x"]))
2121
tasks.append(idom.html.tr(task_text, delete_button))
2222

23-
task_input = idom.html.input({"onKeyDown": add_new_task})
23+
task_input = idom.html.input({"on_key_down": add_new_task})
2424
task_table = idom.html.table(tasks)
2525

2626
return idom.html.div(

docs/source/reference/_examples/use_reducer_counter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ def Counter():
1717
count, dispatch = idom.hooks.use_reducer(reducer, 0)
1818
return idom.html.div(
1919
f"Count: {count}",
20-
idom.html.button({"onClick": lambda event: dispatch("reset")}, "Reset"),
21-
idom.html.button({"onClick": lambda event: dispatch("increment")}, "+"),
22-
idom.html.button({"onClick": lambda event: dispatch("decrement")}, "-"),
20+
idom.html.button({"on_click": lambda event: dispatch("reset")}, "Reset"),
21+
idom.html.button({"on_click": lambda event: dispatch("increment")}, "+"),
22+
idom.html.button({"on_click": lambda event: dispatch("decrement")}, "-"),
2323
)
2424

2525

docs/source/reference/_examples/use_state_counter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def Counter():
1515
count, set_count = idom.hooks.use_state(initial_count)
1616
return idom.html.div(
1717
f"Count: {count}",
18-
idom.html.button({"onClick": lambda event: set_count(initial_count)}, "Reset"),
19-
idom.html.button({"onClick": lambda event: set_count(increment)}, "+"),
20-
idom.html.button({"onClick": lambda event: set_count(decrement)}, "-"),
18+
idom.html.button({"on_click": lambda event: set_count(initial_count)}, "Reset"),
19+
idom.html.button({"on_click": lambda event: set_count(increment)}, "+"),
20+
idom.html.button({"on_click": lambda event: set_count(decrement)}, "-"),
2121
)
2222

2323

src/idom/_console/ast_utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ def find_element_constructor_usages(
101101
continue
102102

103103
func = node.func
104-
if (
105-
isinstance(func, ast.Attribute)
106-
and isinstance(func.value, ast.Name)
107-
and func.value.id == "html"
104+
if isinstance(func, ast.Attribute) and (
105+
(isinstance(func.value, ast.Name) and func.value.id == "html")
106+
or (isinstance(func.value, ast.Attribute) and func.value.attr == "html")
108107
):
109108
name = func.attr
110109
elif isinstance(func, ast.Name):

0 commit comments

Comments
 (0)