Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clickable demos to the introduction #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>