Skip to content

Commit

Permalink
Add clickable demos to the introduction
Browse files Browse the repository at this point in the history
Co-authored-by: oljfte <[email protected]>
  • Loading branch information
shouichi and oljfte committed Jun 22, 2022
1 parent d429944 commit f095429
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
5 changes: 5 additions & 0 deletions _source/_assets/css/components/_demo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.demo {
background-color: $color-tint;
padding: 1em;
margin-bottom: 2em;
}
4 changes: 2 additions & 2 deletions _source/_assets/css/main.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

@import
"base/mixins",
"base/fonts",
Expand All @@ -13,4 +12,5 @@
"components/landing",
"components/highlighter",
"components/callout",
"components/grid";
"components/grid",
"components/demo";
20 changes: 20 additions & 0 deletions _source/handbook/01_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ With Turbo Frames, you can place those independent segments inside frame element

To wrap an independent segment in its own navigation context, enclose it in a `<turbo-frame>` tag. For example:

<h6>HTML</h6>

```html
<turbo-frame id="new_message">
<form action="/messages" method="post">
Expand All @@ -43,16 +45,34 @@ To wrap an independent segment in its own navigation context, enclose it in a `<
</turbo-frame>
```

<h6>DEMO</h6>
<div class="demo">
<turbo-frame id="new_message">
<form action="/handbook/demos/introduction/new_message" method="get">
<input type="submit" value="Submit" />
</form>
</turbo-frame>
</div>

When you submit the form above, Turbo extracts the matching `<turbo-frame id="new_message">` element from the redirected HTML response and swaps its content into the existing `new_message` frame element. The rest of the page stays just as it was.

Frames can also defer loading their contents in addition to scoping navigation. To defer loading a frame, add a `src` attribute whose value is the URL to be automatically loaded. As with scoped navigation, Turbo finds and extracts the matching frame from the resulting response and swaps its content into place:

<h6>HTML</h6>

```html
<turbo-frame id="messages" src="/messages">
<p>This message will be replaced by the response from /messages.</p>
</turbo-frame>
```

<h6>DEMO</h6>
<div class="demo">
<turbo-frame id="messages" src="/handbook/demos/introduction/messages">
<p>This message will be replaced by the response from /messages.</p>
</turbo-frame>
</div>

This may sound a lot like old-school frames, or even `<iframe>`s, but Turbo Frames are part of the same DOM, so there's none of the weirdness or compromises associated with "real" frames. Turbo Frames are styled by the same CSS, part of the same JavaScript context, and are not placed under any additional content security restrictions.

In addition to turning your segments into independent contexts, Turbo Frames affords you:
Expand Down
6 changes: 6 additions & 0 deletions _source/handbook/demos/introduction/messages.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<turbo-frame id="messages">
<ol>
<li>A message loaded via turbo-frame</li>
<li>Yet another message</li>
</ol>
</turbo-frame>
3 changes: 3 additions & 0 deletions _source/handbook/demos/introduction/new_message.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<turbo-frame id="new_message">
<span>Hello, Turbo Frames!</span>
</turbo-frame>

0 comments on commit f095429

Please sign in to comment.