Skip to content

Commit 462bdbf

Browse files
committed
refine examples
1 parent da93698 commit 462bdbf

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

docs/source/custom_js/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/examples/snake_game.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@ def GameView():
2626
)
2727

2828
if game_state == GameState.won:
29-
return idom.html.div(idom.html.h1("You won!"), start_button)
29+
menu = idom.html.div(idom.html.h3("You won!"), start_button)
3030
elif game_state == GameState.lost:
31-
return idom.html.div(idom.html.h1("You lost"), start_button)
31+
menu = idom.html.div(idom.html.h3("You lost"), start_button)
3232
else:
33-
return idom.html.div(idom.html.h1("Click to play"), start_button)
33+
menu = idom.html.div(idom.html.h3("Click to play"), start_button)
34+
35+
menu_style = idom.html.style(
36+
"""
37+
.snake-game-menu h3 {
38+
margin-top: 0px !important;
39+
}
40+
"""
41+
)
42+
43+
return idom.html.div({"className": "snake-game-menu"}, menu_style, menu)
3444

3545

3646
class Direction(enum.Enum):
@@ -52,6 +62,7 @@ def GameLoop(grid_size, block_scale, set_game_state):
5262

5363
grid = create_grid(grid_size, block_scale)
5464

65+
@idom.event(prevent_default=True)
5566
def on_direction_change(event):
5667
if hasattr(Direction, event["key"]):
5768
maybe_new_direction = Direction[event["key"]].value

docs/source/examples/todo.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ async def remove_task(event, index=index):
2323
task_input = idom.html.input({"onKeyDown": add_new_task})
2424
task_table = idom.html.table(tasks)
2525

26-
return idom.html.div(task_input, task_table)
26+
return idom.html.div(
27+
idom.html.p("press enter to add a task:"),
28+
task_input,
29+
task_table,
30+
)
2731

2832

2933
idom.run(Todo)

docs/source/index.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,23 @@ A package for building responsive user interfaces in pure Python.
6565

6666
.. grid-item-card::
6767

68-
.. interactive-widget:: matplotlib_plot
68+
.. interactive-widget:: snake_game
69+
:no-activate-button:
70+
71+
.. grid-item-card::
72+
73+
.. interactive-widget:: slideshow
74+
:no-activate-button:
75+
76+
.. grid-item-card::
77+
78+
.. interactive-widget:: audio_player
6979
:no-activate-button:
7080

81+
.. grid-item-card::
7182

83+
.. interactive-widget:: todo
84+
:no-activate-button:
7285

7386
.. grid-item::
7487

@@ -80,12 +93,14 @@ A package for building responsive user interfaces in pure Python.
8093
.. interactive-widget:: simple_dashboard
8194
:no-activate-button:
8295

96+
97+
8398
.. grid-item-card::
8499

85-
.. interactive-widget:: slideshow
100+
.. interactive-widget:: matplotlib_plot
86101
:no-activate-button:
87102

88103
.. grid-item-card::
89104

90-
.. interactive-widget:: audio_player
105+
.. interactive-widget:: material_ui_button_on_click
91106
:no-activate-button:

0 commit comments

Comments
 (0)