Skip to content

Commit 791b4e6

Browse files
committed
Improve react+typescript
1 parent 884126a commit 791b4e6

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

apps/components_guide_web/assets/css/app.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
:root {
1212
@apply bg-gray-900;
1313

14-
--links-color: currentColor;
14+
--link-color: currentColor;
1515

1616
--size-xs: .75rem;
1717
--size-sm: .875rem;
@@ -41,9 +41,9 @@ article a:hover {
4141
}
4242

4343
a {
44-
color: var(--links-color);
45-
padding: var(--links-padding);
46-
text-decoration: var(--links-decoration);
44+
color: var(--link-color);
45+
padding: var(--link-padding);
46+
text-decoration: var(--link-decoration);
4747
}
4848
a:hover {
4949
text-decoration: var(--hover\:links-decoration);
@@ -55,6 +55,7 @@ h2, p, li {
5555
}
5656
h2 {
5757
font-size: var(--heading-2-size);
58+
padding: var(--heading-2-padding);
5859
}
5960
p {
6061
padding: var(--paragraph-padding);
@@ -80,6 +81,7 @@ input {
8081
--item-spacing-left: 1rem;
8182
--item-spacing-right: 1rem;
8283
--heading-2-size: var(--size-3xl);
84+
--heading-2-padding: var(--size-base) 0;
8385
--paragraph-padding: 0.5rem 0;
8486
--listitem-padding: 0.5rem 0;
8587
--code-padding: 0 0.1875em;

apps/components_guide_web/lib/components_guide_web/templates/react_typescript/index.html.eex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<div class="text-white" style="<%= header_styles() %>">
2-
<section class="pt-8 pb-8">
3-
<h1 class="mx-auto max-w-4xl row space-x-4 text-4xl text-center font-bold leading-tight text-shadow">
2+
<header class="mx-auto max-w-4xl">
3+
<h1 class="pt-8 row space-x-4 text-4xl text-center font-bold leading-tight text-shadow">
44
<div class="row">
55
<img class="inline-block mr-2" src="<%= "https://cdn.jsdelivr.net/gh/gilbarbara/logos@618de63f309bbf56b67364fd6a441cbbf79403cc/logos/react.svg" %>" alt="React logo" width=48 height=48>
66
<span class="mr-2 text-3xl">❤️</span>
77
<img class="inline-block mr-2" src="<%= "https://cdn.jsdelivr.net/gh/gilbarbara/logos@02e637e09b55966e802dfe0bc93595594e0214bb/logos/typescript-icon.svg" %>" alt="TypeScript logo" width=48 height=48>
88
</div>
99
<span><%= "React & TypeScript Guide" %></span>
1010
</h1>
11-
</section>
11+
<nav class="pt-6 pb-4">
12+
<ul class="list-none row font-bold" style="--link-padding: 0.75em">
13+
<li><%= link("Fundamentals", to: '/react+typescript') %>
14+
<li><%= link("Testing", to: '/react+typescript/testing') %>
15+
</ul>
16+
</nav>
17+
</header>
1218
</div>
1319

1420
<div class="bg-white">

apps/components_guide_web/lib/components_guide_web/templates/react_typescript/tips.html.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,14 @@ function Card({ title, children }: CardProps): JSX.Element {
313313

314314
For this reason, I would recommend that components are functions that are declared at the top level of a file. A function declared nested inside another will be different each time that outer function is called — so either call these functions yourself or extract them out.
315315

316-
## Once props are passed to a component, they mustn’t be mutated
316+
## Once elements & props are given to React, they mustn’t be mutated
317+
318+
When you return an element tree from a component, it might be used immediately or it might be scheduled for use later.
319+
320+
If you kept a reference to an element you returned and mutated it later, React might see an inconsistent view, causing the result to be unpredictable or for it to crash.
321+
322+
React relies on immutability. It avoids creating defensive copies of elements and props, as that would just be overhead.
323+
324+
## Test behavior and markup over implementation detail
325+
326+
## Test roles

apps/components_guide_web/lib/components_guide_web/templates/research/index.html.eex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
</form>
1515
<dl
1616
class="text-xl grid gap-2 items-center pt-4 px-6"
17-
style="grid-template-columns: auto 1fr; --links-color: #1c64f2; --hover\:links-decoration: underline;"
17+
style="grid-template-columns: auto 1fr; --link-color: #1c64f2; --hover\:link-decoration: underline;"
1818
>
1919
<dt>HTML & Roles</dt>
2020
<dd>
21-
<ul class="list-none flex flex-wrap italic" style="--links-padding: 0.75em">
21+
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
2222
<li><%= link("form", to: "?q=form") %>
2323
<li><%= link("button", to: "?q=button") %>
2424
<li><%= link("contentinfo", to: "?q=contentinfo") %>
@@ -28,7 +28,7 @@
2828
</dd>
2929
<dt>Third-party</dt>
3030
<dd>
31-
<ul class="list-none flex flex-wrap italic" style="--links-padding: 0.75em">
31+
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
3232
<li><%= link("react-dom", to: "?q=react-dom") %>
3333
<li><%= link("preact", to: "?q=preact") %>
3434
<li><%= link("vue", to: "?q=vue") %>
@@ -41,7 +41,7 @@
4141
</dd>
4242
<dt>Concepts</dt>
4343
<dd>
44-
<ul class="list-none flex flex-wrap italic" style="--links-padding: 0.75em">
44+
<ul class="list-none flex flex-wrap italic" style="--link-padding: 0.75em">
4545
<li><%= link("error", to: "?q=error") %>
4646
</ul>
4747
</dd>

0 commit comments

Comments
 (0)