-
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.
fix: IntersectionObserverShared once now works
- Loading branch information
Showing
14 changed files
with
154 additions
and
74 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
<script context="module" lang="ts"> | ||
// import type { Viewport } from 'kitbook' | ||
// override default full-width composition viewport (set width as null for it to be auto-adjusting full-width) | ||
// export const viewports: Viewport[] = [ | ||
// { width: 600, height: 400 }, | ||
// ] | ||
// at the moment only the first viewport will be shown - updates are coming to show all viewports | ||
</script> | ||
|
||
<script lang="ts"> | ||
import IntersectionObserver from './IntersectionObserver.svelte' | ||
</script> | ||
|
||
<IntersectionObserver let:intersecting> | ||
<div> | ||
{intersecting} | ||
</div> | ||
</IntersectionObserver> |
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 |
---|---|---|
@@ -1,35 +1 @@ | ||
<script lang="ts"> | ||
import IntersectionObserver from './IntersectionObserver.svelte'; | ||
import IntersectionObserverShared from './IntersectionObserverShared.svelte'; | ||
import { Story } from 'kitbook'; | ||
</script> | ||
|
||
# Intersection Observer | ||
|
||
Observes the first child element placed inside. | ||
|
||
<Story name="single Use"> | ||
<IntersectionObserver let:intersecting> | ||
<div> | ||
{intersecting} | ||
</div> | ||
</IntersectionObserver> | ||
</Story> | ||
|
||
Can be used to watch many items, efficiently. Note that the first element to init's `top`, `right`, `bottom`, `left` and `threshold` values will be used. We use -150 on the bottom here so you can see the observer working without needing dev tools. | ||
|
||
<Story name="shared use"> | ||
{#each Array(3) as _} | ||
<IntersectionObserverShared let:intersecting bottom={-150}> | ||
<div class:intersecting style="height: 500px;"> | ||
{intersecting} | ||
</div> | ||
</IntersectionObserverShared> | ||
{/each} | ||
</Story> | ||
|
||
<style> | ||
.intersecting { | ||
--at-apply: bg-red-100 border border-red-400; | ||
} | ||
</style> |
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 context="module" lang="ts"> | ||
import type { Viewport } from "kitbook"; | ||
export const viewports: Viewport[] = [{ width: 600, height: 600 }]; | ||
</script> | ||
|
||
<script lang="ts"> | ||
import IntersectionObserverShared from "./IntersectionObserverShared.svelte"; | ||
</script> | ||
|
||
{#each Array(10) as _} | ||
<IntersectionObserverShared once let:intersecting top={-150} bottom={-150}> | ||
<div class:intersecting style="height: 100px;"> | ||
{intersecting} | ||
</div> | ||
</IntersectionObserverShared> | ||
{/each} | ||
|
||
<style> | ||
.intersecting { | ||
--at-apply: bg-red-100 border border-red-400; | ||
} | ||
</style> |
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,3 @@ | ||
Can be used to watch many items, efficiently. Note that the first element to init's `top`, `right`, `bottom`, `left` and `threshold` values will be used. We use -150 on the bottom and top here so you can see the observer working without needing dev tools. | ||
|
||
In this demo we are using `once` to unobserve once an element comes into view. |
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
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
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,45 @@ | ||
<script lang="ts"> | ||
export let onclick: ( | ||
e: MouseEvent & { | ||
currentTarget: EventTarget & HTMLButtonElement; | ||
}, | ||
) => any = undefined; | ||
export let type: "button" | "submit" = "button"; | ||
export let loading = false; | ||
export let active = false; | ||
export let disabled = false; | ||
export let title: string = undefined; | ||
$: disable = disabled || loading; | ||
async function runWithSpinner(event) { | ||
if (onclick) { | ||
loading = true; | ||
try { | ||
await onclick(event); | ||
} catch (err) { | ||
console.error(err); | ||
alert(err); | ||
} | ||
loading = false; | ||
} | ||
} | ||
</script> | ||
|
||
<button | ||
class:active | ||
class:disabled={disable} | ||
class={$$props.class} | ||
{type} | ||
{title} | ||
on:click={runWithSpinner} | ||
disabled={disable} | ||
> | ||
<slot /> | ||
{#if loading} | ||
<span | ||
class="i-gg-spinner animate-spin ml-1 -mr-1" | ||
style="vertical-align: -2px;" | ||
/> | ||
{/if} | ||
</button> |
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
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 |
---|---|---|
@@ -1,4 +1,30 @@ | ||
// @ts-ignore - virtual import | ||
import { pages, settings } from 'virtual:kitbook'; | ||
import { layoutLoad } from 'kitbook'; | ||
export const load = layoutLoad({ pages, settings }); | ||
import { settings } from 'virtual:kitbook'; | ||
import { groupColocatedModulesIntoPages, layoutLoad, pagesStore } from 'kitbook'; | ||
/** | ||
* Vite glob patterns used for building your Kitbook. See https://vitejs.dev/guide/features.html#multiple-patterns. | ||
* Restrict these paths to be able to incrementally adopt Kitbook into your project. | ||
* Alternate extensions are not yet supported. | ||
* Kitbook changes in the future will cause this file to be regenerated. Your glob patterns will be preserved as long as you only edit the patterns inside the array brackets and nothing else. | ||
*/ | ||
const components = import.meta.glob(['/src/**/*.svelte']); | ||
const componentsRaw = import.meta.glob(['/src/**/*.svelte'], { as: 'raw' }); | ||
const variants = import.meta.glob(['/src/**/*.variants.ts']); | ||
const variantsRaw = import.meta.glob(['/src/**/*.variants.ts'], { as: 'raw' }); | ||
const compositions = import.meta.glob(['/src/**/*.composition']); | ||
const compositionsRaw = import.meta.glob(['/src/**/*.composition'], { as: 'raw' }); | ||
const markdown = import.meta.glob(['/src/**/*.md', '/README.md']); | ||
const markdownRaw = import.meta.glob(['/src/**/*.md', '/README.md'], { as: 'raw' }); | ||
export const _pages = groupColocatedModulesIntoPages({ components, componentsRaw, variants, variantsRaw, compositions, compositionsRaw, markdown, markdownRaw }); | ||
let firstLoad = true; | ||
if (firstLoad) { | ||
pagesStore.set(_pages); | ||
firstLoad = false; | ||
} | ||
if (import.meta.hot) { | ||
import.meta.hot.accept((module) => { | ||
if (module?._pages) | ||
pagesStore.set(module._pages); | ||
}); | ||
} | ||
export const load = layoutLoad({ pages: _pages, settings }); |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.