Skip to content

Commit bd0e459

Browse files
committed
fix light mode, fix link color in banner component
1 parent 56cbca4 commit bd0e459

13 files changed

Lines changed: 175 additions & 115 deletions

File tree

content/tutorials/getting-started-with-solid/building-ui-with-components.mdx

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { PrevSection, NextSection, PrevNextSection } from "~/components/NextSection";
2-
import { CodeTabs } from "~/components/Tabs";
31
import {
4-
FrameworkAside,
5-
Aside,
6-
} from "~/components/configurable/Aside";
2+
PrevSection,
3+
NextSection,
4+
PrevNextSection,
5+
} from "~/components/NextSection";
6+
import { CodeTabs } from "~/components/Tabs";
7+
import { FrameworkAside, Aside } from "~/components/configurable/Aside";
78
import HelloWorld from "./snippets/HelloWorld.mdx";
8-
import HelloWorldExport from "./snippets/HelloWorldExport.mdx"
9+
import HelloWorldExport from "./snippets/HelloWorldExport.mdx";
910
import HelloWorld2 from "./snippets/HelloWorld2.mdx";
1011
import HelloWorld3 from "./snippets/HelloWorld3.mdx";
1112
import IndexJS from "./snippets/indexjs.mdx";
@@ -36,14 +37,15 @@ inside our src folder. Then copy the following contents:
3637

3738
There are a couple of things to note in our first component:
3839

39-
- Our component name, `HelloWorld`, is title-cased (sometimes referred to as _Pascal_ case), with _*H*ello_ and _*W*orld_ capitalized.
40-
This helps us differentiate components from other JavaScript functions.
40+
- Our component name, `HelloWorld`, is title-cased (sometimes referred to as _Pascal_ case), with _*H*ello_ and _*W*orld_ capitalized.
41+
This helps us differentiate components from other JavaScript functions.
4142
- Our component returns something that looks a lot like HTML, but isn't—it's _JSX_.
4243

4344
<FrameworkAside framework="react">
4445
While Solid components look like React components, they differ in a few distinct ways. Solid component functions _only run once_ to set up and never run again. If you're used to placing a calculation in the function body of a React component and expecting it to recompute when the component re-renders, you may need to take a different approach with Solid. Don't worry&mdash; we'll cover all the best practices throughout this tutorial.
4546

4647
Like React, you can include as many components as you like within a file. You can even write a component _inside_ of another!
48+
4749
</FrameworkAside>
4850

4951
<FrameworkAside framework="vue">
@@ -57,12 +59,13 @@ In Solid, you can include as many components as you like within a file. You can
5759
</FrameworkAside>
5860
<FrameworkAside framework="svelte">
5961

60-
In Svelte, components have _lifecycles_ that are important to how you work with them.
62+
In Svelte, components have _lifecycles_ that are important to how you work with them.
6163
In Solid, components are simply functions that group your code. They
6264
don't have lifecycles, and Solid's rendering system is based on the _reactive_ features you use&mdash;we'll get
6365
to that!
6466

6567
Svelte uses Single-File Components, but Solid does not. You can include as many components as you like within a file. You can even write a component _inside_ of another!
68+
6669
</FrameworkAside>
6770
<FrameworkAside framework="angular">
6871
In Angular, components have _lifecycles_ that are important to how you work with
@@ -95,13 +98,13 @@ Then, let's replace the boilerplate in `App.tsx` with code that imports and disp
9598
We used our component just like any other element: after importing the `HelloWorld` function, we can now use `<HelloWorld />`.
9699

97100
<Aside>
98-
By building with components, we're able to separate and reuse code. Components let us
99-
create building blocks that we can put together to form new pieces.
101+
By building with components, we're able to separate and reuse code. Components
102+
let us create building blocks that we can put together to form new pieces.
100103
</Aside>
101104

102105
## What is JSX?
103106

104-
As we learned above, Solid components return JSX. JSX is an HTML-like syntax used in Solid JavaScript code to represent part of the Document Object Model (DOM).
107+
As we learned above, Solid components return JSX. JSX is an HTML-like syntax used in Solid JavaScript code to represent part of the Document Object Model (DOM).
105108
In our <IfTS fallback="HelloWorld.jsx">HelloWorld.tsx</IfTS> example above, we returned the following JSX from our component:
106109

107110
```tsx
@@ -183,6 +186,7 @@ This syntax of binding HTML and attribute values are two different syntaxes in V
183186
```html
184187
<div :style="style">Hello {{name}}!</div>
185188
```
189+
186190
</FrameworkAside>
187191

188192
Let's update our initial `HelloWorld` component with what we learned in our JSX exploration:
@@ -210,7 +214,7 @@ But the following is _not_ valid JSX because there is no single containing eleme
210214
<HelloWorld />
211215
```
212216

213-
However, we may not actually want a `div` surrounding this code when it's rendered to the DOM.
217+
However, we may not actually want a `div` surrounding this code when it's rendered to the DOM.
214218
_JSX fragments_ give us a way to write valid JSX and also not actually render a containing element to the DOM:
215219

216220
```tsx
@@ -232,24 +236,27 @@ _JSX fragments_ give us a way to write valid JSX and also not actually render a
232236
### JSX is compiled
233237

234238
JSX is syntax on top of JavaScript and is not directly part of any JavaScript standard. Therefore, JSX can't be run directly in the browser (or most other JavaScript runtimes). Solid and other frameworks that use JSX require their code to be run through a compiler. If you're using a starter template you don't have to worry about this&mdash;everything will just work out of the box.
235-
239+
236240
<Aside type="note">
237-
Remember how we discussed that component function names are title-cased? This is so the compiler understands the difference between native DOM elements (like `div`) and custom components (like `HelloWorld`).
241+
Remember how we discussed that component function names are title-cased? This
242+
is so the compiler understands the difference between native DOM elements
243+
(like `div`) and custom components (like `HelloWorld`).
238244
</Aside>
239245

240246
<Aside type="advanced" collapsible title="Read more about the compiler">
241247
Solid's JSX compiler doesn't just compile JSX to JavaScript; it also extracts reactive values (which we'll get to later in the tutorial) and makes things more efficient along the way.
242248

243-
This is more involved than React's JSX compiler, but much less involved than something like Svelte's compiler. Solid's compiler doesn't touch your JavaScript, only your JSX.
249+
This is more involved than React's JSX compiler, but much less involved than something like Svelte's compiler. Solid's compiler doesn't touch your JavaScript, only your JSX.
250+
251+
If you're curious about how Solid and other frameworks use compilation, check out [A Look at Compilation in JavaScript Frameworks](https://dev.to/this-is-learning/a-look-at-compilation-in-javascript-frameworks-3caj) by the creator of Solid.
244252

245-
If you're curious about how Solid and other frameworks use compilation, check out [A Look at Compilation in JavaScript Frameworks](https://dev.to/this-is-learning/a-look-at-compilation-in-javascript-frameworks-3caj) by the creator of Solid.
246253
</Aside>
247254
## Mounting Solid to the DOM
248255

249256
How does our `App` component make it on to the actual HTML page that we show our users?
250257

251-
252258
To add a Solid application to an HTML document, we first designate a containing element in our HTML and assign it an `id`. That usually looks like this:
259+
253260
```html
254261
<body>
255262
<div id="root"></div>
@@ -259,11 +266,13 @@ To add a Solid application to an HTML document, we first designate a containing
259266
Then, we call Solid's `render` function, passing in our `App` component and this element:
260267

261268
```jsx
262-
render(() => <App />, document.getElementById('root'));
269+
render(() => <App />, document.getElementById("root"));
263270
```
264271

265272
<FrameworkAside framework="vue">
266-
This is similar to Vue's [`app.mount`](https://vuejs.org/guide/essentials/application.html#mounting-the-app) function.
273+
This is similar to Vue's
274+
[`app.mount`](https://vuejs.org/guide/essentials/application.html#mounting-the-app)
275+
function.
267276
</FrameworkAside>
268277

269278
See how this plays out in our project in the `index.html` file, which creates the div, and <IfTS fallback="src/index.jsx" code>src/index.tsx</IfTS>, which calls that `render` function:
@@ -273,27 +282,27 @@ See how this plays out in our project in the `index.html` file, which creates th
273282
{ name: "src/HelloWorld.jsx", component: HelloWorld2 },
274283
{ name: "src/App.jsx", component: App },
275284
{ name: "src/index.tsx", component: IndexJS, default: true },
276-
{ name: "index.html", component: IndexHTML},
285+
{ name: "index.html", component: IndexHTML },
277286
]}
278287
ts={[
279288
{ name: "src/HelloWorld.tsx", component: HelloWorld2 },
280289
{ name: "src/App.tsx", component: App },
281290
{ name: "src/index.tsx", component: IndexTS, default: true },
282-
{ name: "index.html", component: IndexHTML},
291+
{ name: "index.html", component: IndexHTML },
283292
]}
284293
/>
285294

286-
287295
<Aside type="note">
288296

289-
You'll want to make sure the first argument passed to the render function is a function that returns a component `() => <Component />` rather than just the component itself.
297+
You'll want to make sure the first argument passed to the render function is a function that returns a component `() => <Component />` rather than just the component itself.
290298

291299
</Aside>
292300

293301
<FrameworkAside framework="react">
294302
React defaults to having a `StrictMode` component added to the root of your app, which [changes the render behavior of your code depending on whether you're in a development mode or not](https://beta.reactjs.org/learn/keeping-components-pure#side-effects-unintended-consequences:~:text=Detecting%20impure%20calculations%20with%20StrictMode).
295303

296304
Solid has no such behavioral differences between production and development rendering.
305+
297306
</FrameworkAside>
298307

299308
## Composing multiple components together
@@ -326,7 +335,11 @@ Next, we create an `AddBook` component. This will be a form that eventually allo
326335
/>
327336

328337
Finally, we can _compose_ our `BookList` and `AddBook` components together. Let's create a `Bookshelf` component within
329-
<IfTS code fallback="App.jsx">App.tsx</IfTS>:
338+
339+
<IfTS code fallback="App.jsx">
340+
App.tsx
341+
</IfTS>
342+
:
330343

331344
<CodeTabs
332345
js={[
@@ -390,12 +403,9 @@ function Bookshelf({ name }) {
390403
Thus far, we learned about Solid components, JSX, and built the foundation of a handy bookshelf app. Next, we'll bring our bookshelf to life using Solid's reactive system!
391404

392405
<PrevNextSection>
393-
<PrevSection
394-
title="Welcome"
395-
href="../building-ui-with-components"
396-
/>
406+
<PrevSection title="Welcome" href="../building-ui-with-components" />
397407
<NextSection
398408
title="Adding Interactivity with State"
399409
href="../adding-interactivity-with-state"
400410
/>
401-
</PrevNextSection>
411+
</PrevNextSection>

content/tutorials/getting-started-with-solid/components/FinishedBookshelf.tsx

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function FinishedBookshelf(props: IBookshelfProps) {
2727

2828
return (
2929
<InteractiveExample>
30-
<div class="bg-solid-darkbg border dark:border-solid-darkitem rounded-lg">
30+
<div class="dark:bg-solid-darkbg border dark:border-solid-darkitem rounded-lg">
3131
<div class="p-4">
3232
<h2 class="text-2xl font-semibold mb-4">{props.name}'s Bookshelf</h2>
3333
<BookList books={books()} />
@@ -36,19 +36,13 @@ export function FinishedBookshelf(props: IBookshelfProps) {
3636
<Show
3737
when={showForm()}
3838
fallback={
39-
<Button
40-
type="button"
41-
onClick={toggleForm}
42-
>
39+
<Button type="button" onClick={toggleForm}>
4340
Add a book
4441
</Button>
4542
}
4643
>
4744
<AddBook setBooks={setBooks} />
48-
<Button
49-
type="button"
50-
onClick={toggleForm}
51-
>
45+
<Button type="button" onClick={toggleForm}>
5246
Finished adding books
5347
</Button>
5448
</Show>
@@ -67,7 +61,9 @@ export function BookList(props: IBookListProps) {
6761

6862
return (
6963
<>
70-
<p class="font-semibold flex items-center gap-2">My books <Dot number={totalBooks()}/></p>
64+
<p class="font-semibold flex items-center gap-2">
65+
My books <Dot number={totalBooks()} />
66+
</p>
7167
<ul class="list-disc ml-4 mt-2">
7268
<For each={props.books}>
7369
{(book) => {
@@ -108,23 +104,31 @@ function AddBook(props: IAddBookProps) {
108104

109105
return (
110106
<>
111-
<form>
112-
<SearchInput label="search books" id="title" input={input()} onInput={(e) => {
113-
setInput(e.currentTarget.value);
114-
}}/>
115-
<button
116-
class="px-3 py-2 rounded bg-blue-200 text-black"
107+
<form class="flex items-center gap-2">
108+
<SearchInput
109+
label="search books"
110+
id="title"
111+
input={input()}
112+
onInput={(e) => {
113+
setInput(e.currentTarget.value);
114+
}}
115+
small={true}
116+
/>
117+
<Button
117118
type="submit"
118119
onClick={(e) => {
119120
e.preventDefault();
120121
setQuery(input());
121122
}}
122123
>
123124
Search
124-
</button>
125+
</Button>
125126
</form>
126-
<Show when={!data.loading} fallback={<>Searching...</>}>
127-
<ul class="list-disc ml-5 my-4">
127+
<Show
128+
when={!data.loading}
129+
fallback={<div class="py-2">Searching...</div>}
130+
>
131+
<ul class="list-disc ml-4 my-2">
128132
<For each={data()}>
129133
{(book) => (
130134
<li class="mb-1">

src/components/Button.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { JSXElement } from "solid-js";
22

3-
export default function Button(props: {type: 'submit' | 'button', onClick?: () => void, children: JSXElement}) {
4-
return <button type={props.type} onClick={props.onClick} class="bg-solid-accent hover:bg-solid-accent/90 rounded p-2 font-semibold text-white flex items-center justify-center">{props.children}</button>
5-
}
3+
export default function Button(props: {
4+
type: "submit" | "button";
5+
onClick?: (e: any) => void;
6+
children: JSXElement;
7+
}) {
8+
return (
9+
<button
10+
type={props.type}
11+
onClick={props.onClick}
12+
class="bg-solid-accent hover:bg-solid-accent/90 rounded p-2 font-semibold text-white flex items-center justify-center"
13+
>
14+
{props.children}
15+
</button>
16+
);
17+
}

src/components/Dot.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
export default function Dot(props: {number: number}) {
2-
return <div class="rounded-full w-6 h-6 grid place-content-center bg-white text-solid-accent">{props.number}</div>
3-
}
1+
export default function Dot(props: { number: number }) {
2+
return (
3+
<div class="rounded-full pt-1 w-6 h-6 border border-solid-lightitem dark:border-solid-darkitem grid place-content-center bg-solid-light dark:bg-white text-solid-accent font-bold">
4+
{props.number}
5+
</div>
6+
);
7+
}

src/components/Main.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Title as MetaTitle } from "@solidjs/meta";
44
import Footer from "./footer/Footer";
55
import { getStartSection } from "./nav/Nav";
66
import { usePageState } from "./context/PageStateContext";
7+
import Dot from "./Dot";
78

89
export function Main(props) {
910
const location = useLocation();
@@ -13,7 +14,7 @@ export function Main(props) {
1314

1415
return (
1516
<main class="flex-grow flex flex-col md:flex-row items-start justify-between">
16-
<article class="min-w-0 max-w-4xl mx-auto">
17+
<article class="min-w-0 md:max-w-4xl lg:max-w-3xl mx-auto">
1718
<div class="flex justify-start">
1819
<div class="flex w-full flex-col min-h-screen md:px-5 sm:px-12">
1920
<div
@@ -36,20 +37,21 @@ export function Main(props) {
3637
</div>
3738
</div>
3839
</article>
39-
<div class="pt-10 ml-4 max-w-xs sticky top-0">
40-
<p class="text-2xl font-bold">
41-
Summary
42-
</p>
43-
<ol class="pl-5 mt-2 list-decimal space-y-1">
44-
<For each={sections()}>
45-
{(item) => (
46-
<li class="text-base py-2">
47-
<a href={"#" + item.href}>{item.title}</a>
48-
</li>
49-
)}
50-
</For>
51-
</ol>
52-
</div>
40+
<div class="pt-10 max-w-xs sticky top-0 pr-4">
41+
<p class="text-2xl font-bold">Summary</p>
42+
<ol class="mt-2 list-none space-y-1">
43+
<For each={sections()}>
44+
{(item, index) => (
45+
<li class="text-base py-2 flex items-center gap-2 rounded hover:bg-solid-light hover:dark:bg-solid-darkbg px-2">
46+
<Dot number={index()} />
47+
<a class="font-semibold" href={"#" + item.href}>
48+
{item.title}
49+
</a>
50+
</li>
51+
)}
52+
</For>
53+
</ol>
54+
</div>
5355
</main>
5456
);
5557
}

0 commit comments

Comments
 (0)