Skip to content

Commit 444125d

Browse files
committed
home code examples
1 parent 3c764e2 commit 444125d

11 files changed

+169
-62
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from reactpy import component, html, use_state
2+
3+
4+
def filter_videos(videos, search_text):
5+
return None
6+
7+
8+
def search_input(dictionary, value):
9+
return None
10+
11+
12+
def video_list(videos, empty_heading):
13+
return None
14+
15+
16+
@component
17+
def searchable_video_list(videos):
18+
search_text, set_search_text = use_state("")
19+
found_videos = filter_videos(videos, search_text)
20+
21+
return html._(
22+
search_input(
23+
{"on_change": lambda new_text: set_search_text(new_text)},
24+
value=search_text,
25+
),
26+
video_list(
27+
videos=found_videos,
28+
empty_heading=f"No matches for “{search_text}”",
29+
),
30+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="tabbed-set tabbed-alternate" data-tabs="{{ num }}:1"
2+
style="--md-indicator-x: 18px; --md-indicator-width: 84px">
3+
<input checked="checked" id="__tabbed_{{ num }}_1" name="__tabbed_{{ num }}" type="radio" />
4+
<div class="tabbed-labels"><label for="__tabbed_{{ num }}_1">app.py</label></div>
5+
<div class="tabbed-content">
6+
<img src="assets/img/{{ image }}">
7+
</div>
8+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from reactpy import component, html
2+
3+
4+
def thumbnail(video):
5+
return None
6+
7+
8+
def like_button(video):
9+
return None
10+
11+
12+
@component
13+
def video(video):
14+
return html.div(
15+
thumbnail(video),
16+
html.a(
17+
{"href": video.url},
18+
html.h3(video.title),
19+
html.p(video.description),
20+
),
21+
like_button(video),
22+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from reactpy import component, html
2+
3+
4+
@component
5+
def video_list(videos, empty_heading):
6+
count = len(videos)
7+
heading = empty_heading
8+
if count > 0:
9+
noun = "Videos" if count > 1 else "Video"
10+
heading = f"{count} {noun}"
11+
12+
return html.section(
13+
html.h2(heading),
14+
[video(video) for video in videos],
15+
)

docs/overrides/home.html

+49-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- TODO: Use markdown code blocks whenever mkdocs starts supported markdown embeds -->
12
{% extends "main.html" %}
23

34
<!-- Set the content block to empty -->
@@ -6,6 +7,28 @@
67
<!-- Override the tabs block to create the homepage -->
78
{% block tabs %}
89
<style>
10+
/* Variables */
11+
[data-md-color-scheme="slate"] {
12+
--row-stripe-bg-color: conic-gradient(from 90deg at -10% 100%,
13+
#2b303b 0deg,
14+
#2b303b 90deg,
15+
#16181d 1turn);
16+
--row-bg-color: conic-gradient(from -90deg at 110% 100%, #2b303b 0deg, #16181d 90deg, #16181d 1turn);
17+
--stripe-border-color: rgba(246, 247, 249, 0.1);
18+
--code-block-filter: none;
19+
}
20+
21+
[data-md-color-scheme="default"] {
22+
--row-stripe-bg-color: conic-gradient(from 90deg at -10% 100%,
23+
#bcc1cd 0deg,
24+
#bcc1cd 90deg,
25+
#fff 1turn);
26+
--row-bg-color: var(--row-stripe-bg-color);
27+
--stripe-border-color: rgba(35, 39, 47, 0.1);
28+
--code-block-filter: invert(1) contrast(1.3) hue-rotate(180deg) saturate(2);
29+
--code-tab-color: rgb(246 247 249);
30+
}
31+
932
/* Application header should be static for the landing page */
1033
.md-header {
1134
position: initial;
@@ -20,10 +43,10 @@
2043
display: none;
2144
}
2245
</style>
23-
<section class="md-typeset">
24-
<div class="home-row first">
46+
<section class="home md-typeset">
47+
<div class="row first">
2548
<img src="https://raw.githubusercontent.com/reactive-python/reactpy/main/branding/svg/reactpy-logo-square.svg"
26-
alt="Logo" class="home-logo">
49+
alt="ReactPy Logo" class="home-logo">
2750
<h1>{{ config.site_name }}</h1>
2851
<p>{{ config.site_description }}</p>
2952
<div class="home-btns">
@@ -36,50 +59,68 @@ <h1>{{ config.site_name }}</h1>
3659
</div>
3760
</div>
3861

39-
<div class="home-row stripe">
62+
<div class="row stripe">
4063
<h1>Create user interfaces from components</h1>
4164
<p class="md-grid">
4265
ReactPy lets you build user interfaces out of individual pieces called components. Create your own ReactPy
4366
components like <code>thumbnail</code>, <code>like_button</code>, and <code>video</code>. Then combine
4467
them into entire screens, pages, and apps.
4568
</p>
69+
<div class="code-container">
70+
{% with image="create-user-interfaces.png", num=1 %}
71+
{% include "home-code-examples/code-block.html" %}
72+
{% endwith %}
73+
</div>
4674
<p>
4775
Whether you work on your own or with thousands of other developers, using React feels the same. It is
4876
designed to let you seamlessly combine components written by independent people, teams, and
4977
organizations.
5078
</p>
5179
</div>
5280

53-
<div class="home-row">
54-
<h1>Write components with code and markup</h1>
81+
<div class="row">
82+
<h1>Write components with pure Python code</h1>
5583
<p>
5684
ReactPy components are Python functions. Want to show some content conditionally? Use an
5785
<code>if</code> statement. Displaying a list? Try using
5886
<a href="https://www.w3schools.com/python/python_lists_comprehension.asp">list comprehension</a>.
5987
Learning ReactPy is learning programming.
6088
</p>
89+
<div class="code-container">
90+
{% with image="write-components-with-python.png", num=2 %}
91+
{% include "home-code-examples/code-block.html" %}
92+
{% endwith %}
93+
</div>
6194
</div>
6295

63-
<div class="home-row stripe">
96+
<div class="row stripe">
6497
<h1>Add interactivity wherever you need it</h1>
6598
<p>
6699
ReactPy components receive data and return what should appear on the screen. You can pass them new data in
67100
response to an interaction, like when the user types into an input. ReactPy will then update the screen to
68101
match the new data.
69102
</p>
103+
<div class="code-container">
104+
{% with image="add-interactivity.png", num=3 %}
105+
{% include "home-code-examples/code-block.html" %}
106+
{% endwith %}
107+
</div>
70108
<p>
71109
You don't have to build your whole page in ReactPy. Add React to your existing HTML page, and render
72110
interactive ReactPy components anywhere on it.
73111
</p>
74112
</div>
75113

76-
<div class="home-row">
114+
<div class="row">
77115
<h1>Go full-stack with the Django framework</h1>
78116
<p>
79117
ReactPy is a library. It lets you put components together, but it doesn't prescribe how to do routing and
80118
data fetching. To build an entire app with ReactPy, we recommend a backend framework like
81119
<a href="https://www.djangoproject.com/">Django</a>.
82120
</p>
121+
<a href="{{ page.next_page.url | url }}" class="md-button md-button--primary">
122+
Get Started
123+
</a>
83124
</div>
84125
</section>
85126
{% endblock %}

docs/src/assets/css/home.css

+40-36
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,73 @@
1-
[data-md-color-scheme="slate"] {
2-
--stripe-bg-color: conic-gradient(
3-
from 90deg at -10% 100%,
4-
#2b303b 0deg,
5-
#2b303b 90deg,
6-
#16181d 1turn
7-
);
8-
--stripe-border-color: rgba(246, 247, 249, 0.1);
9-
}
10-
11-
[data-md-color-scheme="default"] {
12-
--stripe-bg-color: conic-gradient(
13-
from 90deg at -10% 100%,
14-
#bcc1cd 0deg,
15-
#bcc1cd 90deg,
16-
#fff 1turn
17-
);
18-
--stripe-border-color: rgba(35, 39, 47, 0.1);
19-
}
20-
211
img.home-logo {
222
height: 120px;
233
}
244

25-
.home-row {
5+
.home .row {
266
display: flex;
277
justify-content: center;
288
align-items: center;
299
flex-direction: column;
3010
padding: 6rem 0.8rem;
3111
}
3212

33-
.home-row.stripe {
34-
background: var(--stripe-bg-color);
13+
.home .row:not(.first, .stripe) {
14+
background: var(--row-bg-color);
15+
}
16+
17+
.home .row.stripe {
18+
background: var(--row-stripe-bg-color);
3519
border: 0 solid var(--stripe-border-color);
3620
border-top-width: 1px;
3721
border-bottom-width: 1px;
3822
}
3923

40-
.home-row h1 {
24+
.home .row.first {
25+
text-align: center;
26+
}
27+
28+
.home .row h1 {
4129
max-width: 28rem;
4230
line-height: 1.15;
4331
font-weight: 500;
4432
margin-bottom: 0.55rem;
4533
margin-top: -1rem;
4634
}
4735

48-
.home-row.first {
49-
text-align: center;
50-
}
51-
52-
.home-row.first h1 {
36+
.home .row.first h1 {
5337
margin-top: 0.55rem;
5438
margin-bottom: -0.75rem;
5539
}
5640

57-
.home-row p {
41+
.home .row p {
5842
max-width: 35rem;
5943
line-height: 1.5;
6044
font-weight: 400;
6145
}
6246

63-
.home-row.first p {
47+
.home .row.first p {
6448
font-size: 32px;
6549
font-weight: 500;
6650
}
6751

6852
/* Desktop Styling */
6953
@media screen and (min-width: 60em) {
70-
.home-row {
54+
.home .row {
7155
text-align: center;
7256
}
73-
.home-row p {
57+
.home .row p {
7458
font-size: 21px;
7559
}
76-
.home-row h1 {
60+
.home .row h1 {
7761
font-size: 52px;
7862
}
7963
}
8064

8165
/* Mobile Styling */
8266
@media screen and (max-width: 60em) {
83-
.home-row {
67+
.home .row {
8468
padding: 4rem 0.8rem;
8569
}
86-
.home-row.first {
70+
.home .row.first {
8771
padding-top: 2rem;
8872
}
8973
.home-btns {
@@ -93,3 +77,23 @@ img.home-logo {
9377
gap: 0.5rem;
9478
}
9579
}
80+
81+
/* Code blocks */
82+
.home .row .tabbed-content {
83+
background: #1f1f1f;
84+
padding: 20px 18px;
85+
width: 610px;
86+
}
87+
88+
.home .row .tabbed-content img {
89+
user-select: none;
90+
-moz-user-select: none;
91+
-webkit-user-drag: none;
92+
-webkit-user-select: none;
93+
-ms-user-select: none;
94+
}
95+
96+
.home .row .tabbed-content {
97+
-webkit-filter: var(--code-block-filter);
98+
filter: var(--code-block-filter);
99+
}

docs/src/assets/css/sidebar.css

+4-17
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
margin-left: 0;
88
margin-right: 0;
99
max-width: unset;
10-
display: flex;
11-
justify-content: center;
10+
display: grid;
11+
grid-template-columns: auto 1fr auto;
1212
}
1313

14-
.md-sidebar--primary {
15-
margin-right: auto;
16-
}
17-
18-
.md-sidebar.md-sidebar--secondary {
19-
margin-left: auto;
14+
.md-content {
15+
justify-self: center;
2016
}
2117

2218
/* Desktop Styling */
@@ -101,13 +97,4 @@
10197
font-weight: 400;
10298
padding-left: 1.25rem;
10399
}
104-
105-
/* Maintain content positioning even if sidebar or TOC is disabled */
106-
.md-sidebar {
107-
display: block;
108-
}
109-
110-
.md-sidebar[hidden] {
111-
visibility: hidden;
112-
}
113100
}
19.6 KB
Loading
12.1 KB
Loading
Loading

mkdocs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ extra_javascript:
9494

9595
extra_css:
9696
- assets/css/main.css
97-
- assets/css/home.css
9897
- assets/css/button.css
9998
- assets/css/admonition.css
10099
- assets/css/sidebar.css
101100
- assets/css/navbar.css
102101
- assets/css/table-of-contents.css
103102
- assets/css/code.css
104103
- assets/css/footer.css
104+
- assets/css/home.css
105105

106106
watch:
107107
- docs

0 commit comments

Comments
 (0)