-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from bensmithett/docs-and-hydration
Add documentation, rename isomorphic to hydration & remove document template
- Loading branch information
Showing
11 changed files
with
120 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Components | ||
|
||
Components are the building blocks that make up your pages and layouts. They're where you define HTML, CSS and (optionally) client-side JS behaviour. Build them quickly in Storybook, then compose them into pages. | ||
|
||
San Blas components are built with 2 opinionated conventions: | ||
|
||
- Style with Fela | ||
- Opt-in client-side JS | ||
|
||
## Style with Fela | ||
|
||
San Blas uses [Fela](https://fela.js.org/) for styling components. See the Fela docs and provided examples, but essentially you write CSS-in-JS that looks like inline styles, which Fela translates into optimised atomic classes: | ||
|
||
```js | ||
<button className={css({ | ||
background: 'green', | ||
borderRadius: 5 | ||
})}> | ||
|
||
// Renders <button class='a b'> | ||
``` | ||
|
||
## Opt-in client-side JS | ||
|
||
By default, San Blas components are **only prerendered** and have **no client-side JS behaviour**. | ||
|
||
For example, by default this button will appear in the page's prerendered HTML, but nothing will happen when it's clicked. | ||
|
||
```js | ||
const HiButton = () => ( | ||
<button onClick={() => alert('hi')}> | ||
Say Hi | ||
</button> | ||
) | ||
``` | ||
|
||
### Progressive enhancement | ||
|
||
Prerendered component HTML can be [progressively enhanced](https://en.wikipedia.org/wiki/Progressive_enhancement) in the browser by any client-side JS added to `entry.client.js`. | ||
|
||
### React component hydration | ||
|
||
A single React component can be used to both: | ||
|
||
- prerender static HTML in a server environment, and | ||
- attach client-side behaviour to that prerendered HTML in a browser environment via [hydration](https://reactjs.org/docs/react-dom.html#hydrate) | ||
|
||
In many React-based frameworks, the top-level page component is hydrated along with every component that makes up that page, regardless of whether they all actually have client-side behaviour that requires hydrating. | ||
|
||
By contrast, San Blas requires you to **opt specific components in** to hydration (you may of course choose to hydrate your top-level component). | ||
|
||
Helpers are provided in `hydration_helpers.js` simplify hydration (though you may hydrate manually in `entry.client.js`). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Layouts | ||
|
||
Layouts, a concept borrowed from [Rails](https://api.rubyonrails.org/classes/ActionView/Layouts.html), allow you to template the HTML _around_ your page content. | ||
|
||
This could include things like: | ||
|
||
- Tags for your `<head>` | ||
- "Wrapper" divs, or a shared header, footer or sidebar | ||
|
||
Unlike Rails, you don't need to directly template your layout's `html`, `head` or `body` tags. Instead, manage those tags with `Helmet` and the San Blas prerender function will put everything in the right place in the final rendered HTML document. | ||
|
||
## Layout props | ||
|
||
Layout components are rendered with 2 props: | ||
|
||
- `meta` (object): the `meta` object exported by each page | ||
- `children` (React Element): the page content | ||
|
||
## Specifying a layout for a page | ||
|
||
Pages use the `DefaultLayout` component unless another component is specified in the page's `meta.Layout`: | ||
|
||
```js | ||
import DifferentLayout from '../layouts/different_layout' | ||
|
||
export const meta = { | ||
title: 'My Page Title', | ||
description: 'This page has a different layout', | ||
Layout: DifferentLayout | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters