Skip to content

Commit 8385d78

Browse files
committed
more fixes
1 parent 4bff3bb commit 8385d78

File tree

20 files changed

+171
-92
lines changed

20 files changed

+171
-92
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ async def handle_pointer_move(event):
1919
html.div(
2020
style={
2121
"position": "absolute",
22-
"backgroundColor": "red",
23-
"borderRadius": "50%",
22+
"background_color": "red",
23+
"border_radius": "50%",
2424
"width": "20px",
2525
"height": "20px",
2626
"left": "-10px",
@@ -33,7 +33,7 @@ async def handle_pointer_move(event):
3333
"position": "relative",
3434
"height": "200px",
3535
"width": "100%",
36-
"backgroundColor": "white",
36+
"background_color": "white",
3737
},
3838
)
3939

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def handle_pointer_move(event):
1717
html.div(
1818
style={
1919
"position": "absolute",
20-
"backgroundColor": "red",
21-
"borderRadius": "50%",
20+
"background_color": "red",
21+
"border_radius": "50%",
2222
"width": "20px",
2323
"height": "20px",
2424
"left": "-10px",
@@ -31,7 +31,7 @@ def handle_pointer_move(event):
3131
"position": "relative",
3232
"height": "200px",
3333
"width": "100%",
34-
"backgroundColor": "white",
34+
"background_color": "white",
3535
},
3636
)
3737

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def handle_click(event):
2323
style={
2424
"height": "30px",
2525
"width": "30px",
26-
"backgroundColor": "black"
26+
"background_color": "black"
2727
if index in selected_indices
2828
else "white",
2929
"outline": "1px solid grey",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def handle_click(event):
2020
style={
2121
"height": "30px",
2222
"width": "30px",
23-
"backgroundColor": "black"
23+
"background_color": "black"
2424
if index in selected_indices
2525
else "white",
2626
"outline": "1px solid grey",

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

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

1616
return html.div(
1717
html.button(
18-
"Set Color", on_click=handle_click, style={"backgroundColor": color}
18+
"Set Color", on_click=handle_click, style={"background_color": color}
1919
),
20-
html.button("Reset", on_click=handle_reset, style={"backgroundColor": color}),
20+
html.button("Reset", on_click=handle_reset, style={"background_color": color}),
2121
)
2222

2323

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def DivInDiv():
1313
lambda event: set_inner_count(inner_count + 1),
1414
stop_propagation=stop_propagatation,
1515
),
16-
style={"height": "50px", "width": "50px", "backgroundColor": "blue"},
16+
style={"height": "50px", "width": "50px", "background_color": "blue"},
1717
),
1818
on_click=lambda event: set_outer_count(outer_count + 1),
19-
style={"height": "100px", "width": "100px", "backgroundColor": "red"},
19+
style={"height": "100px", "width": "100px", "background_color": "red"},
2020
)
2121

2222
return html.div(

docs/source/reference/_examples/matplotlib_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def poly_coef_input(index, callback):
6161
idom.html.label("C", idom.html.sub(index), " × X", idom.html.sup(index)),
6262
idom.html.input(type="number", on_change=callback),
6363
key=index,
64-
style={"margin-top": "5px"},
64+
style={"margin_top": "5px"},
6565
)
6666

6767

docs/source/reference/_examples/simple_dashboard.py

Lines changed: 1 addition & 1 deletion
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-
idom.html.legend(label, style={"font-size": "medium"}),
86+
idom.html.legend(label, style={"font_size": "medium"}),
8787
Input(update_value, "number", value, attributes=attrs, cast=float),
8888
Input(update_value, "range", value, attributes=attrs, cast=float),
8989
class_="number-input-container",

docs/source/reference/_examples/snake_game.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def create_grid(grid_size, block_scale):
154154
"width": f"{block_scale * grid_size}px",
155155
"cursor": "pointer",
156156
"display": "grid",
157-
"grid-gap": 0,
158-
"grid-template-columns": f"repeat({grid_size}, {block_scale}px)",
159-
"grid-template-rows": f"repeat({grid_size}, {block_scale}px)",
157+
"grid_gap": 0,
158+
"grid_template_columns": f"repeat({grid_size}, {block_scale}px)",
159+
"grid_template_rows": f"repeat({grid_size}, {block_scale}px)",
160160
},
161161
tab_index=-1,
162162
)
@@ -168,7 +168,7 @@ def create_grid_block(color, block_scale, key):
168168
style={
169169
"height": f"{block_scale}px",
170170
"width": f"{block_scale}px",
171-
"backgroundColor": color,
171+
"background_color": color,
172172
"outline": "1px solid grey",
173173
},
174174
)
@@ -177,7 +177,7 @@ def create_grid_block(color, block_scale, key):
177177
def assign_grid_block_color(grid, point, color):
178178
x, y = point
179179
block = grid["children"][x]["children"][y]
180-
block["attributes"]["style"]["backgroundColor"] = color
180+
block["attributes"]["style"]["background_color"] = color
181181

182182

183183
idom.run(GameView)

src/client/packages/idom-client-react/src/element-utils.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ export function createElementAttributes(model, sendEvent) {
2626
}
2727
}
2828

29-
return Object.fromEntries(
30-
Object.entries(attributes).map(([key, value]) => [snakeToCamel(key), value])
29+
const attrs = Object.fromEntries(
30+
Object.entries(attributes).map(normalizeAttribute)
3131
);
32+
console.log(attrs);
33+
return attrs;
3234
}
3335

3436
function createEventHandler(sendEvent, eventSpec) {
@@ -53,12 +55,32 @@ function createEventHandler(sendEvent, eventSpec) {
5355
};
5456
}
5557

56-
function snakeToCamel(str) {
57-
if (str.startsWith("data_") || str.startsWith("aria_")) {
58-
return str.replace("_", "-");
58+
function normalizeAttribute([key, value]) {
59+
let normKey = key;
60+
let normValue = value;
61+
62+
if (key === "style" && typeof value === "object") {
63+
normValue = Object.fromEntries(
64+
Object.entries(value).map(([k, v]) => [snakeToCamel(k), v])
65+
);
66+
} else if (
67+
key.startsWith("data_") ||
68+
key.startsWith("aria_") ||
69+
DASHED_HTML_ATTRS.includes(key)
70+
) {
71+
normKey = key.replace("_", "-");
5972
} else {
60-
return str
61-
.toLowerCase()
62-
.replace(/([-_][a-z])/g, (group) => group.toUpperCase().replace("_", ""));
73+
normKey = snakeToCamel(key);
6374
}
75+
return [normKey, normValue];
6476
}
77+
78+
function snakeToCamel(str) {
79+
return str.replace(/([_][a-z])/g, (group) =>
80+
group.toUpperCase().replace("_", "")
81+
);
82+
}
83+
84+
// see list of HTML attributes with dashes in them:
85+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes#attribute_list
86+
const DASHED_HTML_ATTRS = ["accept_charset", "http_equiv"];

0 commit comments

Comments
 (0)