docs: update transitions tutorial (#8822)

fixes #8820
pull/8830/head
Simon H 1 year ago committed by GitHub
parent 79e7ccc415
commit 037ac2f55a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,7 @@
{#if showItems}
{#each items.slice(0, i) as item}
<div transition:slide|local>
<div transition:slide|global>
{item}
</div>
{/each}

@ -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.

@ -1,15 +0,0 @@
---
title: Local transitions
---
Ordinarily, transitions will play on elements when any container block is added or destroyed. In the example here, toggling the visibility of the entire list also applies transitions to individual list elements.
Instead, we'd like transitions to play only when individual items are added and removed — in other words, when the user drags the slider.
We can achieve this with a _local_ transition, which only plays when the block with the transition itself is added or removed:
```svelte
<div transition:slide|local>
{item}
</div>
```

@ -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) {

@ -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 {

@ -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>

@ -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);
@ -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;
}

Loading…
Cancel
Save