Skip to content

docs: update transitions tutorial #8822

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

Merged
merged 7 commits into from
Jun 23, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

{#if showItems}
{#each items.slice(0, i) as item}
<div transition:slide|local>
<div transition:slide|global>
{item}
</div>
{/each}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Global transitions
---

Ordinarily, transitions will only play on elements when their direct containing block is added or destroyed. In the example here, toggling the visibility of the entire list does not apply transitions to individual list elements.

Instead, we'd like transitions to not only play when individual items are added and removed with the slider but also when we toggle the checkbox.

We can achieve this with a _global_ transition, which plays when _any_ block containing the transitions is added or removed:

```svelte
<div transition:slide|global>
{item}
</div>
```

> In Svelte 3, transitions were global by default and you had to use the `|local` modifier to make them local.
15 changes: 0 additions & 15 deletions documentation/tutorial/10-transitions/07-local-transitions/text.md

This file was deleted.

6 changes: 2 additions & 4 deletions packages/playground/start.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { watch } from 'rollup';
import serve from 'rollup-plugin-serve';
import * as svelte from '../svelte/src/compiler/index.js';

let __dirname = new URL('.', import.meta.url).pathname;
if (process.platform === 'win32') {
__dirname = __dirname.slice(1); // else path.resolve fucks up
}
const __dirname = fileURLToPath(new URL('.', import.meta.url));

/** @returns {import('rollup').Plugin}*/
function create_plugin(ssr = false) {
Expand Down
3 changes: 2 additions & 1 deletion sites/svelte.dev/scripts/generate_examples.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { fileURLToPath } from 'node:url';
import { get_examples_data } from '../src/lib/server/examples/index.js';
import fs from 'node:fs';

const examples_data = get_examples_data(
new URL('../../../documentation/examples', import.meta.url).pathname
fileURLToPath(new URL('../../../documentation/examples', import.meta.url))
);

try {
Expand Down
2 changes: 1 addition & 1 deletion sites/svelte.dev/src/routes/docs/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
}

onMount(() => {
console.log(get_old_new_ids_map());
console.log(get_old_new_ids_map()); // for debugging purposes in prod
goto(get_url_to_redirect_to(), { replaceState: true });
});
</script>
11 changes: 9 additions & 2 deletions sites/svelte.dev/src/routes/tutorial/[slug]/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {
get_tutorial_data,
get_tutorial_list
} from '$lib/server/tutorial/index.js';
import { error } from '@sveltejs/kit';
import { error, redirect } from '@sveltejs/kit';

export const prerender = true;

export async function load({ params }) {
if (params.slug === 'local-transitions') throw redirect(307, '/tutorial/global-transitions');

const tutorial_data = get_tutorial_data();
const tutorials_list = get_tutorial_list(tutorial_data);

Expand All @@ -24,7 +26,12 @@ export async function load({ params }) {

export async function entries() {
const tutorials_list = get_tutorial_list(get_tutorial_data());
return tutorials_list
const slugs = tutorials_list
.map(({ tutorials }) => tutorials)
.flatMap((val) => val.map(({ slug }) => ({ slug })));

// to force redirect
slugs.push({ slug: 'local-transitions' });

return slugs;
}