Skip to content

Commit 9d05d27

Browse files
committed
Format examples
1 parent db98a5a commit 9d05d27

12 files changed

+64
-77
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.Error {
2-
color: red;
3-
}
2+
color: red;
3+
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
section {
2-
border-bottom: 1px solid #aaa;
3-
padding: 20px;
2+
border-bottom: 1px solid #aaa;
3+
padding: 20px;
44
}
55
h4 {
6-
color: #222;
6+
color: #222;
77
}
88
body {
9-
margin: 0;
9+
margin: 0;
1010
}
1111
.Error {
12-
color: red;
13-
}
12+
color: red;
13+
}

docs/examples/python/managing_state/all_possible_states.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from reactpy import hooks
22

3-
43
# start
54
is_empty, set_is_empty = hooks.use_state(True)
65
is_typing, set_is_typing = hooks.use_state(False)

docs/examples/python/managing_state/alt_stateful_picture_component.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,32 @@
66
def picture():
77
is_active, set_is_active = hooks.use_state(False)
88

9-
if (is_active):
9+
if is_active:
1010
return html.div(
1111
{
1212
"class_name": "background",
13-
"on_click": lambda event: set_is_active(False)
13+
"on_click": lambda event: set_is_active(False),
1414
},
1515
html.img(
1616
{
1717
"on_click": event(stop_propagation=True),
1818
"class_name": "picture picture--active",
1919
"alt": "Rainbow houses in Kampung Pelangi, Indonesia",
20-
"src": "https://i.imgur.com/5qwVYb1.jpeg"
20+
"src": "https://i.imgur.com/5qwVYb1.jpeg",
2121
}
22-
)
22+
),
2323
)
2424
else:
2525
return html.div(
26-
{
27-
"class_name": "background background--active"
28-
},
26+
{"class_name": "background background--active"},
2927
html.img(
3028
{
31-
"on_click": event(lambda event: set_is_active(True),
32-
stop_propagation=True),
29+
"on_click": event(
30+
lambda event: set_is_active(True), stop_propagation=True
31+
),
3332
"class_name": "picture",
3433
"alt": "Rainbow houses in Kampung Pelangi, Indonesia",
35-
"src": "https://i.imgur.com/5qwVYb1.jpeg"
34+
"src": "https://i.imgur.com/5qwVYb1.jpeg",
3635
}
37-
)
38-
)
36+
),
37+
)

docs/examples/python/managing_state/basic_form_component.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ def form(status="empty"):
99
else:
1010
return html._(
1111
html.h2("City quiz"),
12-
html.p("In which city is there a billboard that turns air into drinkable water?"),
13-
html.form(
14-
html.textarea(),
15-
html.br(),
16-
html.button("Submit")
17-
)
18-
)
12+
html.p(
13+
"In which city is there a billboard that turns air into drinkable water?"
14+
),
15+
html.form(html.textarea(), html.br(), html.button("Submit")),
16+
)

docs/examples/python/managing_state/conditional_form_component.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
def error(status):
77
if status == "error":
88
return html.p(
9-
{"class_name": "error"},
10-
"Good guess but a wrong answer. Try again!"
9+
{"class_name": "error"}, "Good guess but a wrong answer. Try again!"
1110
)
1211
else:
1312
return ""
@@ -27,19 +26,17 @@ def form(status="empty"):
2726
),
2827
html.form(
2928
html.textarea(
30-
{
31-
"disabled": "True" if status == "submitting"
32-
else "False"
33-
}
29+
{"disabled": "True" if status == "submitting" else "False"}
3430
),
3531
html.br(),
3632
html.button(
3733
{
38-
"disabled": True if status == "empty"
39-
or status == "submitting" else "False"
34+
"disabled": (
35+
True if status in ["empty", "submitting"] else "False"
36+
)
4037
},
41-
"Submit"
38+
"Submit",
4239
),
43-
error(status)
44-
)
45-
)
40+
error(status),
41+
),
42+
)

docs/examples/python/managing_state/multiple_form_components.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
from reactpy import component, html
21
from conditional_form_component import form
32

3+
from reactpy import component, html
4+
45

56
# start
67
@component
78
def item(status):
8-
return html.section(
9-
html.h4("Form", status, ':'),
10-
form(status)
11-
)
9+
return html.section(html.h4("Form", status, ":"), form(status))
1210

1311

1412
@component
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from reactpy import hooks
22

3-
43
# start
54
answer, set_answer = hooks.use_state("")
65
error, set_error = hooks.use_state(None)

docs/examples/python/managing_state/picture_component.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def picture():
1010
{
1111
"class_name": "picture",
1212
"alt": "Rainbow houses in Kampung Pelangi, Indonesia",
13-
"src": "https://i.imgur.com/5qwVYb1.jpeg"
13+
"src": "https://i.imgur.com/5qwVYb1.jpeg",
1414
}
15-
)
16-
)
15+
),
16+
)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from reactpy import hooks
22

3-
43
# start
54
answer, set_answer = hooks.use_state("")
65
error, set_error = hooks.use_state(None)
7-
status, set_status = hooks.use_state("typing") # 'typing', 'submitting', or 'success'
6+
status, set_status = hooks.use_state("typing") # 'typing', 'submitting', or 'success'
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from reactpy import component, event, html, hooks
21
import asyncio
32

3+
from reactpy import component, event, hooks, html
44

5-
async def submit_form():
5+
6+
async def submit_form(*args):
67
await asyncio.wait(5)
78

89

@@ -11,19 +12,18 @@ async def submit_form():
1112
def error_msg(error):
1213
if error:
1314
return html.p(
14-
{"class_name": "error"},
15-
"Good guess but a wrong answer. Try again!"
15+
{"class_name": "error"}, "Good guess but a wrong answer. Try again!"
1616
)
1717
else:
1818
return ""
19-
19+
2020

2121
@component
2222
def form(status="empty"):
2323
answer, set_answer = hooks.use_state("")
2424
error, set_error = hooks.use_state(None)
2525
status, set_status = hooks.use_state("typing")
26-
26+
2727
@event(prevent_default=True)
2828
async def handle_submit(event):
2929
set_status("submitting")
@@ -37,7 +37,7 @@ async def handle_submit(event):
3737
@event()
3838
def handle_textarea_change(event):
3939
set_answer(event["target"]["value"])
40-
40+
4141
if status == "success":
4242
return html.h1("That's right!")
4343
else:
@@ -51,19 +51,20 @@ def handle_textarea_change(event):
5151
{"on_submit": handle_submit},
5252
html.textarea(
5353
{
54-
"value": answer,
55-
"on_change": handle_textarea_change,
56-
"disabled": True if status == "submitting" else "False"
54+
"value": answer,
55+
"on_change": handle_textarea_change,
56+
"disabled": (True if status == "submitting" else "False"),
5757
}
5858
),
5959
html.br(),
6060
html.button(
61-
{
62-
"disabled": True if status == "empty"
63-
or status == "submitting" else "False"
64-
},
65-
"Submit"
61+
{
62+
"disabled": (
63+
True if status in ["empty", "submitting"] else "False"
64+
)
65+
},
66+
"Submit",
6667
),
67-
error_msg(error)
68-
)
69-
)
68+
error_msg(error),
69+
),
70+
)

docs/examples/python/managing_state/stateful_picture_component.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,23 @@ def picture():
88
background_class_name = "background"
99
picture_class_name = "picture"
1010

11-
if (is_active):
11+
if is_active:
1212
picture_class_name += " picture--active"
1313
else:
1414
background_class_name += " background--active"
15-
15+
1616
@event(stop_propagation=True)
1717
def handle_click(event):
1818
set_is_active(True)
1919

2020
return html.div(
21-
{
22-
"class_name": background_class_name,
23-
"on_click": set_is_active(False)
24-
},
21+
{"class_name": background_class_name, "on_click": set_is_active(False)},
2522
html.img(
2623
{
2724
"on_click": handle_click,
2825
"class_name": picture_class_name,
2926
"alt": "Rainbow houses in Kampung Pelangi, Indonesia",
30-
"src": "https://i.imgur.com/5qwVYb1.jpeg"
27+
"src": "https://i.imgur.com/5qwVYb1.jpeg",
3128
}
32-
)
29+
),
3330
)

0 commit comments

Comments
 (0)