-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
next: accordion tests and pagination (#493)
- Loading branch information
Showing
18 changed files
with
721 additions
and
278 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
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
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
55 changes: 33 additions & 22 deletions
55
packages/bits-ui/src/lib/bits/pagination/components/pagination-next-button.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 |
---|---|---|
@@ -1,32 +1,43 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import type { NextButtonEvents, NextButtonProps } from "../index.js"; | ||
import { getCtx } from "../ctx.js"; | ||
import { createDispatcher } from "$lib/internal/events.js"; | ||
import type { NextButtonProps } from "../index.js"; | ||
import { setPaginationButtonState } from "../pagination.svelte.js"; | ||
import { readonlyBox } from "$lib/internal/box.svelte.js"; | ||
import { noop } from "$lib/internal/callbacks.js"; | ||
import { generateId } from "$lib/internal/id.js"; | ||
import { styleToString } from "$lib/internal/style.js"; | ||
type $$Props = NextButtonProps; | ||
type $$Events = NextButtonEvents; | ||
let { | ||
id = generateId(), | ||
asChild, | ||
child, | ||
children, | ||
el = $bindable(), | ||
onclick = noop, | ||
onkeydown = noop, | ||
style = {}, | ||
type = "button", | ||
...restProps | ||
}: NextButtonProps = $props(); | ||
export let asChild: $$Props["asChild"] = undefined; | ||
export let el: $$Props["el"] = undefined; | ||
const state = setPaginationButtonState({ | ||
type: "next", | ||
id: readonlyBox(() => id), | ||
onclick: readonlyBox(() => onclick), | ||
onkeydown: readonlyBox(() => onkeydown), | ||
}); | ||
const { | ||
elements: { nextButton }, | ||
getAttrs, | ||
} = getCtx(); | ||
const attrs = getAttrs("next-button"); | ||
$: builder = $nextButton; | ||
$: Object.assign(builder, attrs); | ||
const dispatch = createDispatcher(); | ||
const mergedProps = $derived({ | ||
...restProps, | ||
...state.props, | ||
type, | ||
style: styleToString(style), | ||
}); | ||
</script> | ||
|
||
{#if asChild} | ||
<slot {builder} /> | ||
{@render child?.({ props: mergedProps })} | ||
{:else} | ||
<button bind:this={el} use:melt={builder} type="button" {...$$restProps} on:m-click={dispatch}> | ||
<slot {builder} /> | ||
<button bind:this={el} {...mergedProps}> | ||
{@render children?.()} | ||
</button> | ||
{/if} |
63 changes: 38 additions & 25 deletions
63
packages/bits-ui/src/lib/bits/pagination/components/pagination-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 |
---|---|---|
@@ -1,35 +1,48 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import { getCtx } from "../ctx.js"; | ||
import type { PageEvents, PageProps } from "../index.js"; | ||
import { createDispatcher } from "$lib/internal/events.js"; | ||
import type { PageProps } from "../index.js"; | ||
import { setPaginationPageState } from "../pagination.svelte.js"; | ||
import { readonlyBox } from "$lib/internal/box.svelte.js"; | ||
import { noop } from "$lib/internal/callbacks.js"; | ||
import { generateId } from "$lib/internal/id.js"; | ||
import { styleToString } from "$lib/internal/style.js"; | ||
type $$Props = PageProps; | ||
type $$Events = PageEvents; | ||
let { | ||
id = generateId(), | ||
page, | ||
asChild, | ||
child, | ||
children, | ||
type = "button", | ||
el = $bindable(), | ||
onclick = noop, | ||
onkeydown = noop, | ||
style = {}, | ||
...restProps | ||
}: PageProps = $props(); | ||
export let asChild: $$Props["asChild"] = undefined; | ||
export let page: $$Props["page"]; | ||
export let el: $$Props["el"] = undefined; | ||
const state = setPaginationPageState({ | ||
id: readonlyBox(() => id), | ||
page: readonlyBox(() => page), | ||
onclick: readonlyBox(() => onclick), | ||
onkeydown: readonlyBox(() => onkeydown), | ||
}); | ||
const { | ||
elements: { pageTrigger }, | ||
getAttrs, | ||
} = getCtx(); | ||
const attrs = getAttrs("page"); | ||
$: builder = $pageTrigger(page); | ||
$: Object.assign(builder, attrs); | ||
const dispatch = createDispatcher(); | ||
const mergedProps = $derived({ | ||
...restProps, | ||
...state.props, | ||
type, | ||
style: styleToString(style), | ||
}); | ||
</script> | ||
|
||
{#if asChild} | ||
<slot {builder} /> | ||
{@render child?.({ props: mergedProps })} | ||
{:else} | ||
<button bind:this={el} type="button" use:melt={builder} on:m-click={dispatch} {...$$restProps}> | ||
<slot {builder}> | ||
{page.value} | ||
</slot> | ||
<button bind:this={el} {...mergedProps}> | ||
{#if children} | ||
{@render children?.()} | ||
{:else} | ||
{page} | ||
{/if} | ||
</button> | ||
{/if} |
55 changes: 33 additions & 22 deletions
55
packages/bits-ui/src/lib/bits/pagination/components/pagination-prev-button.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 |
---|---|---|
@@ -1,32 +1,43 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import type { PrevButtonEvents, PrevButtonProps } from "../index.js"; | ||
import { getCtx } from "../ctx.js"; | ||
import { createDispatcher } from "$lib/internal/events.js"; | ||
import type { PrevButtonProps } from "../index.js"; | ||
import { setPaginationButtonState } from "../pagination.svelte.js"; | ||
import { readonlyBox } from "$lib/internal/box.svelte.js"; | ||
import { noop } from "$lib/internal/callbacks.js"; | ||
import { generateId } from "$lib/internal/id.js"; | ||
import { styleToString } from "$lib/internal/style.js"; | ||
type $$Props = PrevButtonProps; | ||
type $$Events = PrevButtonEvents; | ||
let { | ||
id = generateId(), | ||
asChild, | ||
child, | ||
children, | ||
el = $bindable(), | ||
onclick = noop, | ||
onkeydown = noop, | ||
style = {}, | ||
type = "button", | ||
...restProps | ||
}: PrevButtonProps = $props(); | ||
export let asChild: $$Props["asChild"] = undefined; | ||
export let el: $$Props["el"] = undefined; | ||
const state = setPaginationButtonState({ | ||
type: "prev", | ||
id: readonlyBox(() => id), | ||
onclick: readonlyBox(() => onclick), | ||
onkeydown: readonlyBox(() => onkeydown), | ||
}); | ||
const { | ||
elements: { prevButton }, | ||
getAttrs, | ||
} = getCtx(); | ||
const attrs = getAttrs("prev-button"); | ||
$: builder = $prevButton; | ||
$: Object.assign(builder, attrs); | ||
const dispatch = createDispatcher(); | ||
const mergedProps = $derived({ | ||
...restProps, | ||
...state.props, | ||
type, | ||
style: styleToString(style), | ||
}); | ||
</script> | ||
|
||
{#if asChild} | ||
<slot {builder} /> | ||
{@render child?.({ props: mergedProps })} | ||
{:else} | ||
<button bind:this={el} use:melt={builder} type="button" {...$$restProps} on:m-click={dispatch}> | ||
<slot {builder} /> | ||
<button bind:this={el} {...mergedProps}> | ||
{@render children?.()} | ||
</button> | ||
{/if} |
86 changes: 43 additions & 43 deletions
86
packages/bits-ui/src/lib/bits/pagination/components/pagination.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 |
---|---|---|
@@ -1,54 +1,54 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import { setCtx } from "../ctx.js"; | ||
import type { Props } from "../index.js"; | ||
type $$Props = Props; | ||
export let count: $$Props["count"]; | ||
export let page: $$Props["page"] = undefined; | ||
export let onPageChange: $$Props["onPageChange"] = undefined; | ||
export let perPage: $$Props["perPage"] = undefined; | ||
export let siblingCount: $$Props["siblingCount"] = undefined; | ||
export let asChild: $$Props["asChild"] = false; | ||
export let el: $$Props["el"] = undefined; | ||
const { | ||
elements: { root }, | ||
states: { pages, range, page: localPage }, | ||
getAttrs, | ||
updateOption, | ||
} = setCtx({ | ||
import type { RootProps } from "../index.js"; | ||
import { setPaginationRootState } from "../pagination.svelte.js"; | ||
import { box, readonlyBox } from "$lib/internal/box.svelte.js"; | ||
import { generateId } from "$lib/internal/id.js"; | ||
import { styleToString } from "$lib/internal/style.js"; | ||
let { | ||
id = generateId(), | ||
count, | ||
perPage, | ||
siblingCount, | ||
defaultPage: page, | ||
onPageChange: ({ next }) => { | ||
if (page !== next) { | ||
onPageChange?.(next); | ||
page = next; | ||
perPage = 1, | ||
page = $bindable(1), | ||
el = $bindable(), | ||
siblingCount = 1, | ||
onPageChange, | ||
asChild, | ||
loop = false, | ||
orientation = "horizontal", | ||
child, | ||
children, | ||
style = {}, | ||
...restProps | ||
}: RootProps = $props(); | ||
const state = setPaginationRootState({ | ||
id: readonlyBox(() => id), | ||
count: readonlyBox(() => count), | ||
perPage: readonlyBox(() => perPage), | ||
page: box( | ||
() => page, | ||
(v) => { | ||
page = v; | ||
onPageChange?.(v); | ||
} | ||
return next; | ||
}, | ||
), | ||
loop: readonlyBox(() => loop), | ||
siblingCount: readonlyBox(() => siblingCount), | ||
orientation: readonlyBox(() => orientation), | ||
}); | ||
$: page !== undefined && localPage.set(page); | ||
const attrs = getAttrs("root"); | ||
$: builder = $root; | ||
$: Object.assign(builder, attrs); | ||
$: updateOption("count", count); | ||
$: updateOption("perPage", perPage); | ||
$: updateOption("siblingCount", siblingCount); | ||
const mergedProps = $derived({ | ||
...restProps, | ||
...state.props, | ||
style: styleToString(style), | ||
}); | ||
</script> | ||
|
||
{#if asChild} | ||
<slot {builder} pages={$pages} range={$range} /> | ||
{@render child?.({ props: mergedProps, pages: state.pages, range: state.range })} | ||
{:else} | ||
<div bind:this={el} use:melt={builder} {...$$restProps}> | ||
<slot {builder} pages={$pages} range={$range} /> | ||
<div bind:this={el} {...mergedProps}> | ||
{@render children?.({ pages: state.pages, range: state.range })} | ||
</div> | ||
{/if} |
Oops, something went wrong.