@dashforge/tw 0.4.0-beta → 0.5.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +123 -0
- package/dist/index.esm.js +564 -2
- package/dist/src/components/Pagination/Pagination.d.ts +32 -0
- package/dist/src/components/Pagination/Pagination.d.ts.map +1 -0
- package/dist/src/components/Pagination/pagination.helpers.d.ts +23 -0
- package/dist/src/components/Pagination/pagination.helpers.d.ts.map +1 -0
- package/dist/src/components/Pagination/pagination.types.d.ts +120 -0
- package/dist/src/components/Pagination/pagination.types.d.ts.map +1 -0
- package/dist/src/components/Pagination/pagination.variants.d.ts +150 -0
- package/dist/src/components/Pagination/pagination.variants.d.ts.map +1 -0
- package/dist/src/components/Skeleton/Skeleton.d.ts +23 -0
- package/dist/src/components/Skeleton/Skeleton.d.ts.map +1 -0
- package/dist/src/components/Skeleton/skeleton.types.d.ts +56 -0
- package/dist/src/components/Skeleton/skeleton.types.d.ts.map +1 -0
- package/dist/src/components/Skeleton/skeleton.variants.d.ts +110 -0
- package/dist/src/components/Skeleton/skeleton.variants.d.ts.map +1 -0
- package/dist/src/index.d.ts +7 -1
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Pagination/Pagination.test.tsx +314 -0
- package/src/components/Pagination/Pagination.tsx +275 -0
- package/src/components/Pagination/pagination.helpers.ts +102 -0
- package/src/components/Pagination/pagination.types.ts +117 -0
- package/src/components/Pagination/pagination.variants.ts +111 -0
- package/src/components/Skeleton/Skeleton.test.tsx +127 -0
- package/src/components/Skeleton/Skeleton.tsx +49 -0
- package/src/components/Skeleton/skeleton.types.ts +59 -0
- package/src/components/Skeleton/skeleton.variants.ts +86 -0
- package/src/index.ts +18 -1
package/dist/index.esm.js
CHANGED
|
@@ -7282,6 +7282,568 @@ const accordionVariants = tv({
|
|
|
7282
7282
|
});
|
|
7283
7283
|
}
|
|
7284
7284
|
|
|
7285
|
+
/**
|
|
7286
|
+
* `<Skeleton>` variant recipe.
|
|
7287
|
+
*
|
|
7288
|
+
* Slots:
|
|
7289
|
+
* - `root` — single element (atomic component)
|
|
7290
|
+
*
|
|
7291
|
+
* Variant axes:
|
|
7292
|
+
* - `variant` (`text` | `rectangle` | `circle`) — shape / radius
|
|
7293
|
+
* - `animation` (`pulse` | `wave` | `none`) — how the placeholder
|
|
7294
|
+
* "breathes" while data loads. Always gated on
|
|
7295
|
+
* `prefers-reduced-motion` (no exception — animations are
|
|
7296
|
+
* purely cosmetic).
|
|
7297
|
+
*
|
|
7298
|
+
* Implementation notes:
|
|
7299
|
+
*
|
|
7300
|
+
* - `pulse` uses Tailwind's built-in `animate-pulse` (opacity
|
|
7301
|
+
* 1.0 ↔ 0.5 over 2s, ease-in-out infinite).
|
|
7302
|
+
* - `wave` overlays a moving gradient. Implemented with a
|
|
7303
|
+
* `relative` container + an `::after` pseudo-element via a
|
|
7304
|
+
* Tailwind arbitrary-value class. The gradient slides
|
|
7305
|
+
* horizontally over the surface, mimicking the MUI Skeleton
|
|
7306
|
+
* "wave" look.
|
|
7307
|
+
* - Color uses neutral-200 (light) and neutral-800 (dark) for
|
|
7308
|
+
* the base, picked up automatically by the dashforge preset's
|
|
7309
|
+
* CSS-variable layer.
|
|
7310
|
+
*
|
|
7311
|
+
* Accessibility: the root has `aria-hidden="true"` (set on the JSX
|
|
7312
|
+
* side, not here). Screen readers skip the skeleton entirely;
|
|
7313
|
+
* the surrounding component is responsible for announcing
|
|
7314
|
+
* loading state via `aria-busy` or `aria-live` if needed.
|
|
7315
|
+
*/ const skeletonVariants = tv({
|
|
7316
|
+
slots: {
|
|
7317
|
+
root: [
|
|
7318
|
+
'block',
|
|
7319
|
+
'bg-neutral-200 dark:bg-neutral-800',
|
|
7320
|
+
'motion-reduce:animate-none'
|
|
7321
|
+
]
|
|
7322
|
+
},
|
|
7323
|
+
variants: {
|
|
7324
|
+
variant: {
|
|
7325
|
+
text: {
|
|
7326
|
+
root: 'rounded h-[1em] w-full'
|
|
7327
|
+
},
|
|
7328
|
+
rectangle: {
|
|
7329
|
+
root: 'rounded-md w-full h-[100px]'
|
|
7330
|
+
},
|
|
7331
|
+
circle: {
|
|
7332
|
+
root: 'rounded-full w-10 h-10'
|
|
7333
|
+
}
|
|
7334
|
+
},
|
|
7335
|
+
animation: {
|
|
7336
|
+
pulse: {
|
|
7337
|
+
root: 'animate-pulse'
|
|
7338
|
+
},
|
|
7339
|
+
wave: {
|
|
7340
|
+
root: [
|
|
7341
|
+
'relative overflow-hidden',
|
|
7342
|
+
// The wave is rendered via an arbitrary-value ::after
|
|
7343
|
+
// pseudo-element with a moving linear gradient. Tailwind
|
|
7344
|
+
// doesn't ship a `wave` keyframe; we use the built-in
|
|
7345
|
+
// `animate-pulse` as a fallback if a consumer needs to
|
|
7346
|
+
// override. The gradient stop direction works in both
|
|
7347
|
+
// light and dark mode (white shimmer in light, lighter
|
|
7348
|
+
// overlay in dark).
|
|
7349
|
+
'after:absolute after:inset-0',
|
|
7350
|
+
'after:bg-gradient-to-r after:from-transparent after:via-white/40 after:to-transparent',
|
|
7351
|
+
'dark:after:via-white/10',
|
|
7352
|
+
'after:animate-pulse',
|
|
7353
|
+
'after:motion-reduce:animate-none'
|
|
7354
|
+
]
|
|
7355
|
+
},
|
|
7356
|
+
none: {
|
|
7357
|
+
root: ''
|
|
7358
|
+
}
|
|
7359
|
+
}
|
|
7360
|
+
},
|
|
7361
|
+
defaultVariants: {
|
|
7362
|
+
variant: 'text',
|
|
7363
|
+
animation: 'pulse'
|
|
7364
|
+
}
|
|
7365
|
+
});
|
|
7366
|
+
|
|
7367
|
+
/**
|
|
7368
|
+
* Dashforge TW `<Skeleton>` — loading placeholder primitive.
|
|
7369
|
+
*
|
|
7370
|
+
* Renders as a non-interactive `<span aria-hidden="true">` so screen
|
|
7371
|
+
* readers skip it. The surrounding component is responsible for
|
|
7372
|
+
* announcing loading state via `aria-busy` or `aria-live` if needed.
|
|
7373
|
+
*
|
|
7374
|
+
* Variants:
|
|
7375
|
+
* - `variant` — `text` (default, line shape) / `rectangle` / `circle`
|
|
7376
|
+
* - `animation` — `pulse` (default) / `wave` / `none`
|
|
7377
|
+
*
|
|
7378
|
+
* Both animations are gated by `prefers-reduced-motion` (WCAG 2.3.3).
|
|
7379
|
+
*
|
|
7380
|
+
* @example
|
|
7381
|
+
* ```tsx
|
|
7382
|
+
* <Skeleton variant="text" width="200px" />
|
|
7383
|
+
* <Skeleton variant="rectangle" width="100%" height="120px" />
|
|
7384
|
+
* <Skeleton variant="circle" width="40px" />
|
|
7385
|
+
* ```
|
|
7386
|
+
*/ function Skeleton(props) {
|
|
7387
|
+
var _slotProps_root;
|
|
7388
|
+
const { variant = 'text', animation = 'pulse', width, height, sx, slotProps } = props;
|
|
7389
|
+
const v = skeletonVariants({
|
|
7390
|
+
variant,
|
|
7391
|
+
animation
|
|
7392
|
+
});
|
|
7393
|
+
// Width / height come through as inline style — Tailwind doesn't
|
|
7394
|
+
// know about arbitrary user-supplied lengths. We default `circle`'s
|
|
7395
|
+
// height to `width` so consumers don't have to repeat themselves.
|
|
7396
|
+
const style = {};
|
|
7397
|
+
if (width != null) style.width = width;
|
|
7398
|
+
if (height != null) {
|
|
7399
|
+
style.height = height;
|
|
7400
|
+
} else if (variant === 'circle' && width != null) {
|
|
7401
|
+
style.height = width;
|
|
7402
|
+
}
|
|
7403
|
+
return jsx("span", {
|
|
7404
|
+
"aria-hidden": "true",
|
|
7405
|
+
role: "presentation",
|
|
7406
|
+
className: cn(v.root(), sx, slotProps == null ? void 0 : (_slotProps_root = slotProps.root) == null ? void 0 : _slotProps_root.className),
|
|
7407
|
+
style: style
|
|
7408
|
+
});
|
|
7409
|
+
}
|
|
7410
|
+
|
|
7411
|
+
/**
|
|
7412
|
+
* `<Pagination>` variant recipe.
|
|
7413
|
+
*
|
|
7414
|
+
* Slots:
|
|
7415
|
+
* - `root` — outer `<nav>` container
|
|
7416
|
+
* - `summary` — "Showing X-Y of Z" text
|
|
7417
|
+
* - `list` — `<ul>` of page buttons
|
|
7418
|
+
* - `pageButton` — individual page number button
|
|
7419
|
+
* - `activeButton` — modifier applied to the current page
|
|
7420
|
+
* - `navButton` — first/prev/next/last buttons
|
|
7421
|
+
* - `ellipsis` — `…` rendered when range gap
|
|
7422
|
+
* - `pageSizeSelector` — native `<select>` for page size
|
|
7423
|
+
* - `jumpInput` — direct page jump `<input>`
|
|
7424
|
+
*
|
|
7425
|
+
* Variant axes:
|
|
7426
|
+
* - `variant` — `default` (full kit) | `compact` (number buttons +
|
|
7427
|
+
* prev/next only) | `minimal` ("X / Y pages" + prev/next only).
|
|
7428
|
+
* - `size` — `sm` | `md` (default) | `lg`. Drives padding + text
|
|
7429
|
+
* size on the buttons.
|
|
7430
|
+
*/ const paginationVariants = tv({
|
|
7431
|
+
slots: {
|
|
7432
|
+
root: 'flex flex-wrap items-center gap-3',
|
|
7433
|
+
summary: 'text-neutral-600 dark:text-neutral-400',
|
|
7434
|
+
list: 'inline-flex items-center gap-1',
|
|
7435
|
+
pageButton: [
|
|
7436
|
+
'inline-flex items-center justify-center rounded-md',
|
|
7437
|
+
'border border-neutral-300 dark:border-neutral-700',
|
|
7438
|
+
'bg-white dark:bg-neutral-900',
|
|
7439
|
+
'text-neutral-700 dark:text-neutral-300',
|
|
7440
|
+
'hover:bg-neutral-50 dark:hover:bg-neutral-800',
|
|
7441
|
+
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
|
7442
|
+
'transition-colors motion-reduce:transition-none',
|
|
7443
|
+
'disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none'
|
|
7444
|
+
],
|
|
7445
|
+
activeButton: [
|
|
7446
|
+
'bg-primary-500 text-white border-primary-500',
|
|
7447
|
+
'hover:bg-primary-600 dark:hover:bg-primary-400'
|
|
7448
|
+
],
|
|
7449
|
+
navButton: [
|
|
7450
|
+
'inline-flex items-center justify-center rounded-md',
|
|
7451
|
+
'border border-neutral-300 dark:border-neutral-700',
|
|
7452
|
+
'bg-white dark:bg-neutral-900',
|
|
7453
|
+
'text-neutral-700 dark:text-neutral-300',
|
|
7454
|
+
'hover:bg-neutral-50 dark:hover:bg-neutral-800',
|
|
7455
|
+
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
|
7456
|
+
'transition-colors motion-reduce:transition-none',
|
|
7457
|
+
'disabled:opacity-50 disabled:cursor-not-allowed disabled:pointer-events-none'
|
|
7458
|
+
],
|
|
7459
|
+
ellipsis: 'inline-flex items-center justify-center text-neutral-500 px-1',
|
|
7460
|
+
pageSizeSelector: [
|
|
7461
|
+
'inline-flex items-center gap-2',
|
|
7462
|
+
'text-neutral-700 dark:text-neutral-300'
|
|
7463
|
+
],
|
|
7464
|
+
jumpInput: [
|
|
7465
|
+
'rounded-md border border-neutral-300 dark:border-neutral-700',
|
|
7466
|
+
'bg-white dark:bg-neutral-900',
|
|
7467
|
+
'text-neutral-900 dark:text-neutral-50',
|
|
7468
|
+
'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500',
|
|
7469
|
+
'transition-colors motion-reduce:transition-none'
|
|
7470
|
+
]
|
|
7471
|
+
},
|
|
7472
|
+
variants: {
|
|
7473
|
+
// Note: variant-driven visibility is enforced via conditional JSX
|
|
7474
|
+
// rendering (in `Pagination.tsx`), NOT via `hidden` Tailwind class.
|
|
7475
|
+
// Reason: `display: none` keeps the elements in the DOM (and in the
|
|
7476
|
+
// a11y tree depending on how it's applied), which leaks into
|
|
7477
|
+
// testing-library `queryByText` and feels semantically wrong for
|
|
7478
|
+
// "this UI piece doesn't exist in this variant". So compact and
|
|
7479
|
+
// minimal slots stay empty here.
|
|
7480
|
+
variant: {
|
|
7481
|
+
default: {},
|
|
7482
|
+
compact: {},
|
|
7483
|
+
minimal: {}
|
|
7484
|
+
},
|
|
7485
|
+
size: {
|
|
7486
|
+
sm: {
|
|
7487
|
+
summary: 'text-xs',
|
|
7488
|
+
pageButton: 'h-7 min-w-7 px-2 text-xs',
|
|
7489
|
+
navButton: 'h-7 min-w-7 px-2 text-xs',
|
|
7490
|
+
ellipsis: 'h-7 min-w-5 text-xs',
|
|
7491
|
+
pageSizeSelector: 'text-xs',
|
|
7492
|
+
jumpInput: 'h-7 px-2 text-xs w-14'
|
|
7493
|
+
},
|
|
7494
|
+
md: {
|
|
7495
|
+
summary: 'text-sm',
|
|
7496
|
+
pageButton: 'h-9 min-w-9 px-3 text-sm',
|
|
7497
|
+
navButton: 'h-9 min-w-9 px-3 text-sm',
|
|
7498
|
+
ellipsis: 'h-9 min-w-6 text-sm',
|
|
7499
|
+
pageSizeSelector: 'text-sm',
|
|
7500
|
+
jumpInput: 'h-9 px-2 text-sm w-16'
|
|
7501
|
+
},
|
|
7502
|
+
lg: {
|
|
7503
|
+
summary: 'text-base',
|
|
7504
|
+
pageButton: 'h-10 min-w-10 px-4 text-base',
|
|
7505
|
+
navButton: 'h-10 min-w-10 px-4 text-base',
|
|
7506
|
+
ellipsis: 'h-10 min-w-7 text-base',
|
|
7507
|
+
pageSizeSelector: 'text-base',
|
|
7508
|
+
jumpInput: 'h-10 px-3 text-base w-20'
|
|
7509
|
+
}
|
|
7510
|
+
}
|
|
7511
|
+
},
|
|
7512
|
+
defaultVariants: {
|
|
7513
|
+
variant: 'default',
|
|
7514
|
+
size: 'md'
|
|
7515
|
+
}
|
|
7516
|
+
});
|
|
7517
|
+
|
|
7518
|
+
/**
|
|
7519
|
+
* Compute the array of page indices (or `'ellipsis'` sentinels) to
|
|
7520
|
+
* render for a `<Pagination>`.
|
|
7521
|
+
*
|
|
7522
|
+
* Algorithm (standard "siblings + boundaries + ellipsis fill"):
|
|
7523
|
+
* 1. Always show `boundaryCount` pages at the start and `boundaryCount`
|
|
7524
|
+
* at the end.
|
|
7525
|
+
* 2. Show `siblingCount` pages on each side of the current page.
|
|
7526
|
+
* 3. Fill gaps wider than 1 with `'ellipsis'`.
|
|
7527
|
+
* 4. If a gap is exactly 1 page wide, include that page directly
|
|
7528
|
+
* (no ellipsis for a single hidden number).
|
|
7529
|
+
*
|
|
7530
|
+
* Output is 1-indexed page numbers OR the literal string `'ellipsis'`.
|
|
7531
|
+
*
|
|
7532
|
+
* @example
|
|
7533
|
+
* ```ts
|
|
7534
|
+
* range(1, 10, 1, 1) // [1, 'ellipsis', 5, 'ellipsis', 10] when current=5
|
|
7535
|
+
* range(1, 5, 1, 1) // [1, 2, 3, 4, 5]
|
|
7536
|
+
* range(1, 100, 1, 1) // edges varying with current
|
|
7537
|
+
* ```
|
|
7538
|
+
*/ function computePageRange(currentPage, totalPages, siblingCount, boundaryCount) {
|
|
7539
|
+
if (totalPages <= 0) return [];
|
|
7540
|
+
if (totalPages === 1) return [
|
|
7541
|
+
1
|
|
7542
|
+
];
|
|
7543
|
+
// Budget: if `totalPages` fits within boundaries + siblings + current
|
|
7544
|
+
// (plus the 2 hypothetical ellipsis slots), don't bother with ellipses
|
|
7545
|
+
// at all — list every page. Avoids the "[1, 2, …, 5]" footgun where
|
|
7546
|
+
// the user expected to see 3 and 4 explicitly.
|
|
7547
|
+
const minPagesForEllipsis = 2 * boundaryCount + 2 * siblingCount + 3;
|
|
7548
|
+
if (totalPages <= minPagesForEllipsis) {
|
|
7549
|
+
return range(1, totalPages);
|
|
7550
|
+
}
|
|
7551
|
+
const startBoundary = range(1, Math.min(boundaryCount, totalPages));
|
|
7552
|
+
const endBoundary = range(Math.max(totalPages - boundaryCount + 1, boundaryCount + 1), totalPages);
|
|
7553
|
+
const siblingsStart = Math.max(currentPage - siblingCount, boundaryCount + 2);
|
|
7554
|
+
const siblingsEnd = Math.min(currentPage + siblingCount, totalPages - boundaryCount - 1);
|
|
7555
|
+
const siblings = range(siblingsStart, siblingsEnd);
|
|
7556
|
+
const showStartEllipsis = siblingsStart > boundaryCount + 2;
|
|
7557
|
+
const showEndEllipsis = siblingsEnd < totalPages - boundaryCount - 1;
|
|
7558
|
+
const out = [
|
|
7559
|
+
...startBoundary
|
|
7560
|
+
];
|
|
7561
|
+
if (showStartEllipsis) {
|
|
7562
|
+
out.push('ellipsis');
|
|
7563
|
+
} else if (siblingsStart === boundaryCount + 2) {
|
|
7564
|
+
// Single hidden page → fill it directly instead of an ellipsis.
|
|
7565
|
+
out.push(boundaryCount + 1);
|
|
7566
|
+
}
|
|
7567
|
+
out.push(...siblings);
|
|
7568
|
+
if (showEndEllipsis) {
|
|
7569
|
+
out.push('ellipsis');
|
|
7570
|
+
} else if (siblingsEnd === totalPages - boundaryCount - 1) {
|
|
7571
|
+
out.push(totalPages - boundaryCount);
|
|
7572
|
+
}
|
|
7573
|
+
out.push(...endBoundary);
|
|
7574
|
+
// Dedupe while preserving order (overlapping ranges produce duplicates
|
|
7575
|
+
// when totalPages is small). Two distinct rules:
|
|
7576
|
+
// 1. Number entries: keep only the first occurrence.
|
|
7577
|
+
// 2. Ellipsis entries: collapse adjacent ellipses to one.
|
|
7578
|
+
const seen = new Set();
|
|
7579
|
+
const deduped = [];
|
|
7580
|
+
let prevWasEllipsis = false;
|
|
7581
|
+
for (const entry of out){
|
|
7582
|
+
if (entry === 'ellipsis') {
|
|
7583
|
+
if (!prevWasEllipsis) {
|
|
7584
|
+
deduped.push('ellipsis');
|
|
7585
|
+
prevWasEllipsis = true;
|
|
7586
|
+
}
|
|
7587
|
+
continue;
|
|
7588
|
+
}
|
|
7589
|
+
if (!seen.has(entry)) {
|
|
7590
|
+
seen.add(entry);
|
|
7591
|
+
deduped.push(entry);
|
|
7592
|
+
prevWasEllipsis = false;
|
|
7593
|
+
}
|
|
7594
|
+
}
|
|
7595
|
+
return deduped;
|
|
7596
|
+
}
|
|
7597
|
+
function range(start, end) {
|
|
7598
|
+
if (end < start) return [];
|
|
7599
|
+
return Array.from({
|
|
7600
|
+
length: end - start + 1
|
|
7601
|
+
}, (_, i)=>start + i);
|
|
7602
|
+
}
|
|
7603
|
+
|
|
7604
|
+
const DEFAULT_LABELS = {
|
|
7605
|
+
first: 'First',
|
|
7606
|
+
prev: 'Previous',
|
|
7607
|
+
next: 'Next',
|
|
7608
|
+
last: 'Last',
|
|
7609
|
+
page: 'Page',
|
|
7610
|
+
of: 'of',
|
|
7611
|
+
showing: 'Showing',
|
|
7612
|
+
perPage: 'per page',
|
|
7613
|
+
goToPage: 'Go to page'
|
|
7614
|
+
};
|
|
7615
|
+
const DEFAULT_PAGE_SIZE_OPTIONS = [
|
|
7616
|
+
10,
|
|
7617
|
+
20,
|
|
7618
|
+
50,
|
|
7619
|
+
100
|
|
7620
|
+
];
|
|
7621
|
+
/**
|
|
7622
|
+
* Dashforge TW `<Pagination>` — controlled pagination primitive.
|
|
7623
|
+
*
|
|
7624
|
+
* Three variants:
|
|
7625
|
+
* - `default` — page-size selector + summary + page numbers + nav buttons + jump input
|
|
7626
|
+
* - `compact` — page numbers + nav buttons only (no summary, no selector, no jump)
|
|
7627
|
+
* - `minimal` — "Page X of Y" + prev/next only
|
|
7628
|
+
*
|
|
7629
|
+
* Always controlled (no internal state besides the jump-input draft).
|
|
7630
|
+
*
|
|
7631
|
+
* A11Y:
|
|
7632
|
+
* - `<nav aria-label="Pagination">` root
|
|
7633
|
+
* - `aria-current="page"` on the active page button
|
|
7634
|
+
* - `aria-label` on every interactive element
|
|
7635
|
+
*
|
|
7636
|
+
* @example
|
|
7637
|
+
* ```tsx
|
|
7638
|
+
* const [page, setPage] = useState(1);
|
|
7639
|
+
* const [pageSize, setPageSize] = useState(20);
|
|
7640
|
+
*
|
|
7641
|
+
* <Pagination
|
|
7642
|
+
* page={page}
|
|
7643
|
+
* pageSize={pageSize}
|
|
7644
|
+
* totalCount={1437}
|
|
7645
|
+
* onPageChange={setPage}
|
|
7646
|
+
* onPageSizeChange={setPageSize}
|
|
7647
|
+
* />
|
|
7648
|
+
* ```
|
|
7649
|
+
*/ function Pagination(props) {
|
|
7650
|
+
var _slotProps_root, _slotProps_summary, _slotProps_summary1, _slotProps_list, _slotProps_navButton, _slotProps_navButton1, _slotProps_navButton2, _slotProps_navButton3, _slotProps_pageSizeSelector, _slotProps_jumpInput;
|
|
7651
|
+
const { page, pageSize, totalCount, onPageChange, onPageSizeChange, pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS, siblingCount = 1, boundaryCount = 1, showFirstLast = true, showJumpInput = true, disabled = false, labels: labelsProp, variant = 'default', size = 'md', sx, slotProps } = props;
|
|
7652
|
+
const labels = _extends({}, DEFAULT_LABELS, labelsProp);
|
|
7653
|
+
const v = paginationVariants({
|
|
7654
|
+
variant,
|
|
7655
|
+
size
|
|
7656
|
+
});
|
|
7657
|
+
const totalPages = Math.max(1, Math.ceil(totalCount / pageSize));
|
|
7658
|
+
const safePage = Math.min(Math.max(1, page), totalPages);
|
|
7659
|
+
const pages = computePageRange(safePage, totalPages, siblingCount, boundaryCount);
|
|
7660
|
+
// Summary range
|
|
7661
|
+
const firstItem = totalCount === 0 ? 0 : (safePage - 1) * pageSize + 1;
|
|
7662
|
+
const lastItem = Math.min(safePage * pageSize, totalCount);
|
|
7663
|
+
// Jump input local state (commit on Enter or blur)
|
|
7664
|
+
const [jumpDraft, setJumpDraft] = useState('');
|
|
7665
|
+
const goTo = useCallback((nextPage)=>{
|
|
7666
|
+
if (disabled) return;
|
|
7667
|
+
const clamped = Math.min(Math.max(1, nextPage), totalPages);
|
|
7668
|
+
if (clamped !== safePage) onPageChange(clamped);
|
|
7669
|
+
}, [
|
|
7670
|
+
disabled,
|
|
7671
|
+
totalPages,
|
|
7672
|
+
safePage,
|
|
7673
|
+
onPageChange
|
|
7674
|
+
]);
|
|
7675
|
+
const commitJump = useCallback(()=>{
|
|
7676
|
+
const parsed = Number(jumpDraft);
|
|
7677
|
+
if (!Number.isFinite(parsed) || parsed < 1) {
|
|
7678
|
+
setJumpDraft('');
|
|
7679
|
+
return;
|
|
7680
|
+
}
|
|
7681
|
+
goTo(Math.floor(parsed));
|
|
7682
|
+
setJumpDraft('');
|
|
7683
|
+
}, [
|
|
7684
|
+
jumpDraft,
|
|
7685
|
+
goTo
|
|
7686
|
+
]);
|
|
7687
|
+
const onJumpKeyDown = useCallback((e)=>{
|
|
7688
|
+
if (e.key === 'Enter') {
|
|
7689
|
+
e.preventDefault();
|
|
7690
|
+
commitJump();
|
|
7691
|
+
}
|
|
7692
|
+
}, [
|
|
7693
|
+
commitJump
|
|
7694
|
+
]);
|
|
7695
|
+
const handlePageSize = useCallback((e)=>{
|
|
7696
|
+
if (!onPageSizeChange) return;
|
|
7697
|
+
const next = Number(e.target.value);
|
|
7698
|
+
if (Number.isFinite(next) && next > 0) onPageSizeChange(next);
|
|
7699
|
+
}, [
|
|
7700
|
+
onPageSizeChange
|
|
7701
|
+
]);
|
|
7702
|
+
const isMinimal = variant === 'minimal';
|
|
7703
|
+
return jsxs("nav", {
|
|
7704
|
+
"aria-label": "Pagination",
|
|
7705
|
+
className: cn(v.root(), sx, slotProps == null ? void 0 : (_slotProps_root = slotProps.root) == null ? void 0 : _slotProps_root.className),
|
|
7706
|
+
children: [
|
|
7707
|
+
variant === 'default' && jsxs("span", {
|
|
7708
|
+
className: cn(v.summary(), slotProps == null ? void 0 : (_slotProps_summary = slotProps.summary) == null ? void 0 : _slotProps_summary.className),
|
|
7709
|
+
children: [
|
|
7710
|
+
labels.showing,
|
|
7711
|
+
" ",
|
|
7712
|
+
firstItem,
|
|
7713
|
+
"-",
|
|
7714
|
+
lastItem,
|
|
7715
|
+
" ",
|
|
7716
|
+
labels.of,
|
|
7717
|
+
" ",
|
|
7718
|
+
totalCount
|
|
7719
|
+
]
|
|
7720
|
+
}),
|
|
7721
|
+
isMinimal && jsxs("span", {
|
|
7722
|
+
className: cn(v.summary(), 'text-sm', slotProps == null ? void 0 : (_slotProps_summary1 = slotProps.summary) == null ? void 0 : _slotProps_summary1.className),
|
|
7723
|
+
children: [
|
|
7724
|
+
labels.page,
|
|
7725
|
+
" ",
|
|
7726
|
+
safePage,
|
|
7727
|
+
" ",
|
|
7728
|
+
labels.of,
|
|
7729
|
+
" ",
|
|
7730
|
+
totalPages
|
|
7731
|
+
]
|
|
7732
|
+
}),
|
|
7733
|
+
jsxs("ul", {
|
|
7734
|
+
className: cn(v.list(), slotProps == null ? void 0 : (_slotProps_list = slotProps.list) == null ? void 0 : _slotProps_list.className),
|
|
7735
|
+
children: [
|
|
7736
|
+
showFirstLast && !isMinimal && jsx("li", {
|
|
7737
|
+
children: jsx("button", {
|
|
7738
|
+
type: "button",
|
|
7739
|
+
"aria-label": labels.first,
|
|
7740
|
+
disabled: disabled || safePage === 1,
|
|
7741
|
+
onClick: ()=>goTo(1),
|
|
7742
|
+
className: cn(v.navButton(), slotProps == null ? void 0 : (_slotProps_navButton = slotProps.navButton) == null ? void 0 : _slotProps_navButton.className),
|
|
7743
|
+
children: "\u00AB"
|
|
7744
|
+
})
|
|
7745
|
+
}),
|
|
7746
|
+
jsx("li", {
|
|
7747
|
+
children: jsx("button", {
|
|
7748
|
+
type: "button",
|
|
7749
|
+
"aria-label": labels.prev,
|
|
7750
|
+
disabled: disabled || safePage === 1,
|
|
7751
|
+
onClick: ()=>goTo(safePage - 1),
|
|
7752
|
+
className: cn(v.navButton(), slotProps == null ? void 0 : (_slotProps_navButton1 = slotProps.navButton) == null ? void 0 : _slotProps_navButton1.className),
|
|
7753
|
+
children: "\u2039"
|
|
7754
|
+
})
|
|
7755
|
+
}),
|
|
7756
|
+
!isMinimal && pages.map((entry, idx)=>{
|
|
7757
|
+
var _slotProps_ellipsis, _slotProps_pageButton, _slotProps_activeButton;
|
|
7758
|
+
return entry === 'ellipsis' ? jsx("li", {
|
|
7759
|
+
children: jsx("span", {
|
|
7760
|
+
"aria-hidden": "true",
|
|
7761
|
+
className: cn(v.ellipsis(), slotProps == null ? void 0 : (_slotProps_ellipsis = slotProps.ellipsis) == null ? void 0 : _slotProps_ellipsis.className),
|
|
7762
|
+
children: "\u2026"
|
|
7763
|
+
})
|
|
7764
|
+
}, `e-${idx}`) : jsx("li", {
|
|
7765
|
+
children: jsx("button", {
|
|
7766
|
+
type: "button",
|
|
7767
|
+
"aria-label": `${labels.page} ${entry}`,
|
|
7768
|
+
"aria-current": entry === safePage ? 'page' : undefined,
|
|
7769
|
+
disabled: disabled,
|
|
7770
|
+
onClick: ()=>goTo(entry),
|
|
7771
|
+
className: cn(v.pageButton(), entry === safePage && v.activeButton(), slotProps == null ? void 0 : (_slotProps_pageButton = slotProps.pageButton) == null ? void 0 : _slotProps_pageButton.className, entry === safePage && (slotProps == null ? void 0 : (_slotProps_activeButton = slotProps.activeButton) == null ? void 0 : _slotProps_activeButton.className)),
|
|
7772
|
+
children: entry
|
|
7773
|
+
})
|
|
7774
|
+
}, entry);
|
|
7775
|
+
}),
|
|
7776
|
+
jsx("li", {
|
|
7777
|
+
children: jsx("button", {
|
|
7778
|
+
type: "button",
|
|
7779
|
+
"aria-label": labels.next,
|
|
7780
|
+
disabled: disabled || safePage === totalPages,
|
|
7781
|
+
onClick: ()=>goTo(safePage + 1),
|
|
7782
|
+
className: cn(v.navButton(), slotProps == null ? void 0 : (_slotProps_navButton2 = slotProps.navButton) == null ? void 0 : _slotProps_navButton2.className),
|
|
7783
|
+
children: "\u203A"
|
|
7784
|
+
})
|
|
7785
|
+
}),
|
|
7786
|
+
showFirstLast && !isMinimal && jsx("li", {
|
|
7787
|
+
children: jsx("button", {
|
|
7788
|
+
type: "button",
|
|
7789
|
+
"aria-label": labels.last,
|
|
7790
|
+
disabled: disabled || safePage === totalPages,
|
|
7791
|
+
onClick: ()=>goTo(totalPages),
|
|
7792
|
+
className: cn(v.navButton(), slotProps == null ? void 0 : (_slotProps_navButton3 = slotProps.navButton) == null ? void 0 : _slotProps_navButton3.className),
|
|
7793
|
+
children: "\u00BB"
|
|
7794
|
+
})
|
|
7795
|
+
})
|
|
7796
|
+
]
|
|
7797
|
+
}),
|
|
7798
|
+
variant === 'default' && onPageSizeChange && jsxs("label", {
|
|
7799
|
+
className: cn(v.pageSizeSelector(), slotProps == null ? void 0 : (_slotProps_pageSizeSelector = slotProps.pageSizeSelector) == null ? void 0 : _slotProps_pageSizeSelector.className),
|
|
7800
|
+
children: [
|
|
7801
|
+
jsx("span", {
|
|
7802
|
+
className: "sr-only",
|
|
7803
|
+
children: labels.perPage
|
|
7804
|
+
}),
|
|
7805
|
+
jsx("select", {
|
|
7806
|
+
value: pageSize,
|
|
7807
|
+
onChange: handlePageSize,
|
|
7808
|
+
disabled: disabled,
|
|
7809
|
+
"aria-label": labels.perPage,
|
|
7810
|
+
className: cn('rounded-md border border-neutral-300 dark:border-neutral-700 bg-white dark:bg-neutral-900 px-2 py-1', 'focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500'),
|
|
7811
|
+
children: pageSizeOptions.map((opt)=>jsx("option", {
|
|
7812
|
+
value: opt,
|
|
7813
|
+
children: opt
|
|
7814
|
+
}, opt))
|
|
7815
|
+
}),
|
|
7816
|
+
jsx("span", {
|
|
7817
|
+
children: labels.perPage
|
|
7818
|
+
})
|
|
7819
|
+
]
|
|
7820
|
+
}),
|
|
7821
|
+
variant === 'default' && showJumpInput && jsxs("label", {
|
|
7822
|
+
className: "inline-flex items-center gap-2",
|
|
7823
|
+
children: [
|
|
7824
|
+
jsx("span", {
|
|
7825
|
+
className: "sr-only",
|
|
7826
|
+
children: labels.goToPage
|
|
7827
|
+
}),
|
|
7828
|
+
jsx("input", {
|
|
7829
|
+
type: "number",
|
|
7830
|
+
min: 1,
|
|
7831
|
+
max: totalPages,
|
|
7832
|
+
value: jumpDraft,
|
|
7833
|
+
placeholder: labels.goToPage,
|
|
7834
|
+
disabled: disabled,
|
|
7835
|
+
onChange: (e)=>setJumpDraft(e.target.value),
|
|
7836
|
+
onKeyDown: onJumpKeyDown,
|
|
7837
|
+
onBlur: commitJump,
|
|
7838
|
+
"aria-label": labels.goToPage,
|
|
7839
|
+
className: cn(v.jumpInput(), slotProps == null ? void 0 : (_slotProps_jumpInput = slotProps.jumpInput) == null ? void 0 : _slotProps_jumpInput.className)
|
|
7840
|
+
})
|
|
7841
|
+
]
|
|
7842
|
+
})
|
|
7843
|
+
]
|
|
7844
|
+
});
|
|
7845
|
+
}
|
|
7846
|
+
|
|
7285
7847
|
/**
|
|
7286
7848
|
* @dashforge/tw
|
|
7287
7849
|
*
|
|
@@ -7309,6 +7871,6 @@ const accordionVariants = tv({
|
|
|
7309
7871
|
*/ // ───── Components ─────
|
|
7310
7872
|
/**
|
|
7311
7873
|
* Package version (synced with `package.json` at publish time).
|
|
7312
|
-
*/ const VERSION = '0.
|
|
7874
|
+
*/ const VERSION = '0.5.0-beta';
|
|
7313
7875
|
|
|
7314
|
-
export { Accordion, AppShell, AspectRatio, Autocomplete, Box, Breadcrumbs, Button, Checkbox, ConfirmDialogProvider, Container, DateTimePicker, Dialog, Divider, Grid, LeftNav, NumberField, OTPField, Popover, RadioGroup, SnackbarProvider, Stack, Switch, Tabs, TextField, Textarea, Tooltip, TopBar, Typography, VERSION, VisuallyHidden, accordionVariants, appShellVariants, autocompleteVariants, boxVariants, breadcrumbsVariants, buttonVariants, checkboxVariants, cn, confirmDialogVariants, containerVariants, dateTimePickerVariants, dialogVariants, dividerLineVariants, dividerVariants, gridVariants, isoToInputValue, leftNavVariants, numberFieldVariants, otpFieldVariants, popoverVariants, radioGroupVariants, snackbarVariants, stackVariants, switchVariants, tabsVariants, textFieldVariants, textareaVariants, tooltipVariants, topBarVariants, typographyVariants, useAccessState, useConfirm, useSnackbar };
|
|
7876
|
+
export { Accordion, AppShell, AspectRatio, Autocomplete, Box, Breadcrumbs, Button, Checkbox, ConfirmDialogProvider, Container, DateTimePicker, Dialog, Divider, Grid, LeftNav, NumberField, OTPField, Pagination, Popover, RadioGroup, Skeleton, SnackbarProvider, Stack, Switch, Tabs, TextField, Textarea, Tooltip, TopBar, Typography, VERSION, VisuallyHidden, accordionVariants, appShellVariants, autocompleteVariants, boxVariants, breadcrumbsVariants, buttonVariants, checkboxVariants, cn, confirmDialogVariants, containerVariants, dateTimePickerVariants, dialogVariants, dividerLineVariants, dividerVariants, gridVariants, isoToInputValue, leftNavVariants, numberFieldVariants, otpFieldVariants, paginationVariants, popoverVariants, radioGroupVariants, skeletonVariants, snackbarVariants, stackVariants, switchVariants, tabsVariants, textFieldVariants, textareaVariants, tooltipVariants, topBarVariants, typographyVariants, useAccessState, useConfirm, useSnackbar };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { PaginationProps } from './pagination.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Dashforge TW `<Pagination>` — controlled pagination primitive.
|
|
4
|
+
*
|
|
5
|
+
* Three variants:
|
|
6
|
+
* - `default` — page-size selector + summary + page numbers + nav buttons + jump input
|
|
7
|
+
* - `compact` — page numbers + nav buttons only (no summary, no selector, no jump)
|
|
8
|
+
* - `minimal` — "Page X of Y" + prev/next only
|
|
9
|
+
*
|
|
10
|
+
* Always controlled (no internal state besides the jump-input draft).
|
|
11
|
+
*
|
|
12
|
+
* A11Y:
|
|
13
|
+
* - `<nav aria-label="Pagination">` root
|
|
14
|
+
* - `aria-current="page"` on the active page button
|
|
15
|
+
* - `aria-label` on every interactive element
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* const [page, setPage] = useState(1);
|
|
20
|
+
* const [pageSize, setPageSize] = useState(20);
|
|
21
|
+
*
|
|
22
|
+
* <Pagination
|
|
23
|
+
* page={page}
|
|
24
|
+
* pageSize={pageSize}
|
|
25
|
+
* totalCount={1437}
|
|
26
|
+
* onPageChange={setPage}
|
|
27
|
+
* onPageSizeChange={setPageSize}
|
|
28
|
+
* />
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function Pagination(props: PaginationProps): import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
//# sourceMappingURL=Pagination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pagination.d.ts","sourceRoot":"","sources":["../../../../src/components/Pagination/Pagination.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAoB,MAAM,uBAAuB,CAAC;AAgB/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,2CAiOhD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute the array of page indices (or `'ellipsis'` sentinels) to
|
|
3
|
+
* render for a `<Pagination>`.
|
|
4
|
+
*
|
|
5
|
+
* Algorithm (standard "siblings + boundaries + ellipsis fill"):
|
|
6
|
+
* 1. Always show `boundaryCount` pages at the start and `boundaryCount`
|
|
7
|
+
* at the end.
|
|
8
|
+
* 2. Show `siblingCount` pages on each side of the current page.
|
|
9
|
+
* 3. Fill gaps wider than 1 with `'ellipsis'`.
|
|
10
|
+
* 4. If a gap is exactly 1 page wide, include that page directly
|
|
11
|
+
* (no ellipsis for a single hidden number).
|
|
12
|
+
*
|
|
13
|
+
* Output is 1-indexed page numbers OR the literal string `'ellipsis'`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* range(1, 10, 1, 1) // [1, 'ellipsis', 5, 'ellipsis', 10] when current=5
|
|
18
|
+
* range(1, 5, 1, 1) // [1, 2, 3, 4, 5]
|
|
19
|
+
* range(1, 100, 1, 1) // edges varying with current
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function computePageRange(currentPage: number, totalPages: number, siblingCount: number, boundaryCount: number): (number | 'ellipsis')[];
|
|
23
|
+
//# sourceMappingURL=pagination.helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.helpers.d.ts","sourceRoot":"","sources":["../../../../src/components/Pagination/pagination.helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,CAsEzB"}
|