mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
Added Event Forwarding To Pagination
This commit is contained in:
parent
97873e5525
commit
eb3f8268fa
1 changed files with 21 additions and 3 deletions
|
@ -22,6 +22,19 @@
|
||||||
import CaretRight24 from 'carbon-icons-svelte/lib/CaretRight24';
|
import CaretRight24 from 'carbon-icons-svelte/lib/CaretRight24';
|
||||||
import { cx, fillArray } from '../../lib';
|
import { cx, fillArray } from '../../lib';
|
||||||
import Select, { SelectItem } from '../Select';
|
import Select, { SelectItem } from '../Select';
|
||||||
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
const handlePaginationChange = (type, value) => {
|
||||||
|
if (type === 'pageSize') {
|
||||||
|
page = 1;
|
||||||
|
pageSize = value;
|
||||||
|
} else {
|
||||||
|
page = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch('update', {pageSize, page});
|
||||||
|
};
|
||||||
|
|
||||||
$: totalPages = Math.max(Math.ceil(totalItems / pageSize), 1);
|
$: totalPages = Math.max(Math.ceil(totalItems / pageSize), 1);
|
||||||
$: selectItems = fillArray(totalPages);
|
$: selectItems = fillArray(totalPages);
|
||||||
|
@ -44,8 +57,8 @@
|
||||||
hideLabel
|
hideLabel
|
||||||
noLabel
|
noLabel
|
||||||
inline
|
inline
|
||||||
on:change={() => {
|
on:blur={() => {
|
||||||
page = 1;
|
handlePaginationChange('pageSize', pageSize);
|
||||||
}}
|
}}
|
||||||
bind:selected={pageSize}>
|
bind:selected={pageSize}>
|
||||||
{#each pageSizes as size, i (size)}
|
{#each pageSizes as size, i (size)}
|
||||||
|
@ -68,6 +81,9 @@
|
||||||
labelText={`Page number, of ${totalPages} pages`}
|
labelText={`Page number, of ${totalPages} pages`}
|
||||||
inline
|
inline
|
||||||
hideLabel
|
hideLabel
|
||||||
|
on:blur={() => {
|
||||||
|
handlePaginationChange('page', page);
|
||||||
|
}}
|
||||||
bind:selected={page}>
|
bind:selected={page}>
|
||||||
{#each selectItems as size, i (size)}
|
{#each selectItems as size, i (size)}
|
||||||
<SelectItem value={size + 1} text={(size + 1).toString()} />
|
<SelectItem value={size + 1} text={(size + 1).toString()} />
|
||||||
|
@ -82,6 +98,7 @@
|
||||||
class={cx('--pagination__button', '--pagination__button--backward', backButtonDisabled && '--pagination__button--no-index')}
|
class={cx('--pagination__button', '--pagination__button--backward', backButtonDisabled && '--pagination__button--no-index')}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
page--;
|
page--;
|
||||||
|
handlePaginationChange('page', page);
|
||||||
}}
|
}}
|
||||||
aria-label={backwardText}
|
aria-label={backwardText}
|
||||||
disabled={backButtonDisabled}>
|
disabled={backButtonDisabled}>
|
||||||
|
@ -93,6 +110,7 @@
|
||||||
aria-label={forwardText}
|
aria-label={forwardText}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
page++;
|
page++;
|
||||||
|
handlePaginationChange('page', page);
|
||||||
}}
|
}}
|
||||||
disabled={forwardButtonDisabled}>
|
disabled={forwardButtonDisabled}>
|
||||||
<CaretRight24 />
|
<CaretRight24 />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue