-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script lang="ts"> | ||
import Page from './example/+page.svelte' | ||
import PageSource from './example/+page.svelte?raw' | ||
import Snippet from '../../Snippet.svelte' | ||
</script> | ||
|
||
<h1>Active element</h1> | ||
|
||
<p> | ||
The <code>activeElement</code> store keeps track of the currently focused element | ||
in the document. | ||
</p> | ||
|
||
<h2>Example</h2> | ||
|
||
<div> | ||
<Page /> | ||
</div> | ||
|
||
<h2>Source</h2> | ||
|
||
<Snippet code={PageSource} /> |
24 changes: 24 additions & 0 deletions
24
src/routes/(docs)/store/active-element/example/+page.svelte
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,24 @@ | ||
<script lang="ts"> | ||
import { activeElement } from '$lib' | ||
$: number = $activeElement?.dataset.number ?? null | ||
</script> | ||
|
||
<p class="text-sm opacity-60"> | ||
{#if number} | ||
The active element is <strong>{number}</strong>. | ||
{:else} | ||
Focus an element in the grid to see its number. | ||
{/if} | ||
</p> | ||
|
||
<div class="grid w-max grid-cols-5 grid-rows-4 gap-2"> | ||
{#each Array.from({ length: 20 }) as _, i} | ||
<button | ||
class="flex h-16 w-16 items-center justify-center rounded-full bg-accent-200 shadow hover:bg-accent-100 active:scale-90 dark:bg-accent-700 dark:hover:bg-accent-600" | ||
data-number={i + 1} | ||
> | ||
{i + 1} | ||
</button> | ||
{/each} | ||
</div> |