@brightlocal/ui-components 2.20.0 → 2.21.0
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/AI_USAGE.md +2 -0
- package/README.md +26 -13
- package/component-meta.json +20 -10
- package/dist/blocks/data-table.cjs +1 -1
- package/dist/blocks/data-table.d.ts.map +1 -1
- package/dist/blocks/data-table.js +14 -16
- package/dist/blocks/sidebar.cjs +1 -1
- package/dist/blocks/sidebar.d.ts +2 -2
- package/dist/blocks/sidebar.js +18 -18
- package/dist/breadcrumb.cjs +1 -1
- package/dist/breadcrumb.d.ts +1 -1
- package/dist/breadcrumb.d.ts.map +1 -1
- package/dist/breadcrumb.js +9 -6
- package/dist/button.cjs +1 -1
- package/dist/button.d.ts.map +1 -1
- package/dist/button.js +12 -12
- package/dist/logo.cjs +1 -1
- package/dist/logo.d.ts +1 -1
- package/dist/logo.js +2 -2
- package/dist/navigation-menu.cjs +1 -1
- package/dist/navigation-menu.d.ts +19 -0
- package/dist/navigation-menu.d.ts.map +1 -1
- package/dist/navigation-menu.js +134 -96
- package/dist/pagination.cjs +1 -1
- package/dist/pagination.d.ts +12 -8
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +117 -113
- package/dist/progress.cjs +1 -1
- package/dist/progress.d.ts +28 -2
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +90 -49
- package/dist/skeleton.cjs +1 -1
- package/dist/skeleton.js +1 -1
- package/dist/sonner.d.ts +1 -1
- package/package.json +7 -3
- package/src/blocks/data-table.tsx +0 -2
- package/src/blocks/sidebar.tsx +5 -5
- package/src/components/breadcrumb.tsx +6 -3
- package/src/components/button.tsx +7 -1
- package/src/components/logo.tsx +3 -3
- package/src/components/navigation-menu.tsx +134 -32
- package/src/components/pagination.tsx +47 -67
- package/src/components/progress.tsx +118 -14
- package/src/components/skeleton.tsx +1 -1
- package/src/components/sonner.tsx +1 -1
package/src/blocks/sidebar.tsx
CHANGED
|
@@ -520,7 +520,7 @@ interface SidebarTriggerProps extends Omit<
|
|
|
520
520
|
dataHook?: string;
|
|
521
521
|
/**
|
|
522
522
|
* Accessible label for the toggle button.
|
|
523
|
-
* @default "Toggle
|
|
523
|
+
* @default "Toggle sidebar"
|
|
524
524
|
*/
|
|
525
525
|
toggleAriaLabel?: string;
|
|
526
526
|
}
|
|
@@ -541,14 +541,14 @@ const SidebarTrigger = React.forwardRef<
|
|
|
541
541
|
ref
|
|
542
542
|
) => {
|
|
543
543
|
const { toggleSidebar } = useSidebar();
|
|
544
|
-
const resolvedLabel = toggleAriaLabel ?? "Toggle
|
|
544
|
+
const resolvedLabel = toggleAriaLabel ?? "Toggle sidebar";
|
|
545
545
|
|
|
546
546
|
return (
|
|
547
547
|
<Button
|
|
548
548
|
ref={ref}
|
|
549
549
|
iconOnly
|
|
550
550
|
aria-label={resolvedLabel}
|
|
551
|
-
className={cn("h-7 w-7", className)}
|
|
551
|
+
className={cn("relative h-7 w-7", className)}
|
|
552
552
|
data-slot="sidebar-trigger"
|
|
553
553
|
dataHook={dataHook}
|
|
554
554
|
size="sm"
|
|
@@ -573,7 +573,7 @@ SidebarTrigger.displayName = "SidebarTrigger";
|
|
|
573
573
|
interface SidebarRailProps extends React.ComponentProps<"button"> {
|
|
574
574
|
/**
|
|
575
575
|
* Accessible label and tooltip for the rail toggle.
|
|
576
|
-
* @default "Toggle
|
|
576
|
+
* @default "Toggle sidebar"
|
|
577
577
|
*/
|
|
578
578
|
toggleAriaLabel?: string;
|
|
579
579
|
}
|
|
@@ -581,7 +581,7 @@ interface SidebarRailProps extends React.ComponentProps<"button"> {
|
|
|
581
581
|
const SidebarRail = React.forwardRef<HTMLButtonElement, SidebarRailProps>(
|
|
582
582
|
({ className, toggleAriaLabel, ...props }, ref) => {
|
|
583
583
|
const { toggleSidebar } = useSidebar();
|
|
584
|
-
const resolvedLabel = toggleAriaLabel ?? "Toggle
|
|
584
|
+
const resolvedLabel = toggleAriaLabel ?? "Toggle sidebar";
|
|
585
585
|
|
|
586
586
|
return (
|
|
587
587
|
<button
|
|
@@ -22,7 +22,7 @@ interface BreadcrumbProps extends React.ComponentProps<"nav"> {
|
|
|
22
22
|
trackingLabel?: string;
|
|
23
23
|
/**
|
|
24
24
|
* Accessible label for the breadcrumb navigation.
|
|
25
|
-
* @default "
|
|
25
|
+
* @default "Breadcrumb"
|
|
26
26
|
*/
|
|
27
27
|
ariaLabel?: string;
|
|
28
28
|
}
|
|
@@ -36,7 +36,7 @@ const Breadcrumb = React.forwardRef<HTMLElement, BreadcrumbProps>(
|
|
|
36
36
|
return (
|
|
37
37
|
<nav
|
|
38
38
|
ref={ref}
|
|
39
|
-
aria-label={ariaLabel ?? "
|
|
39
|
+
aria-label={ariaLabel ?? "Breadcrumb"}
|
|
40
40
|
data-hook={dataHook}
|
|
41
41
|
data-slot="breadcrumb"
|
|
42
42
|
data-tracking-el={trackingEl}
|
|
@@ -181,7 +181,10 @@ const BreadcrumbEllipsis = React.forwardRef<
|
|
|
181
181
|
<span
|
|
182
182
|
ref={ref}
|
|
183
183
|
aria-hidden="true"
|
|
184
|
-
className={cn(
|
|
184
|
+
className={cn(
|
|
185
|
+
"relative flex size-9 items-center justify-center",
|
|
186
|
+
className
|
|
187
|
+
)}
|
|
185
188
|
data-slot="breadcrumb-ellipsis"
|
|
186
189
|
role="presentation"
|
|
187
190
|
{...props}
|
|
@@ -203,9 +203,15 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
|
203
203
|
else if (disabled) visualState = "disabled";
|
|
204
204
|
|
|
205
205
|
// Ensure we always have an accessible label
|
|
206
|
+
const childrenIsPrimitive =
|
|
207
|
+
typeof children === "string" || typeof children === "number";
|
|
206
208
|
const effectiveAriaLabel =
|
|
207
209
|
ariaLabel ??
|
|
208
|
-
(loading
|
|
210
|
+
(loading
|
|
211
|
+
? childrenIsPrimitive
|
|
212
|
+
? `Loading: ${children}`
|
|
213
|
+
: "Loading"
|
|
214
|
+
: undefined);
|
|
209
215
|
|
|
210
216
|
// When asChild is used, render a simplified version that only forwards props
|
|
211
217
|
if (asChild) {
|
package/src/components/logo.tsx
CHANGED
|
@@ -30,7 +30,7 @@ interface LogoProps
|
|
|
30
30
|
dataHook: string;
|
|
31
31
|
/**
|
|
32
32
|
* Accessible label for the logo image.
|
|
33
|
-
* @default "BrightLocal
|
|
33
|
+
* @default "BrightLocal logo"
|
|
34
34
|
*/
|
|
35
35
|
ariaLabel?: string;
|
|
36
36
|
/**
|
|
@@ -64,7 +64,7 @@ function Logo({
|
|
|
64
64
|
>
|
|
65
65
|
{variant === "logotype" && (
|
|
66
66
|
<svg
|
|
67
|
-
aria-label={ariaLabel ?? "BrightLocal
|
|
67
|
+
aria-label={ariaLabel ?? "BrightLocal logo"}
|
|
68
68
|
fill="none"
|
|
69
69
|
height="24"
|
|
70
70
|
role="img"
|
|
@@ -82,7 +82,7 @@ function Logo({
|
|
|
82
82
|
)}
|
|
83
83
|
{variant === "mark" && (
|
|
84
84
|
<svg
|
|
85
|
-
aria-label={ariaLabel ?? "BrightLocal
|
|
85
|
+
aria-label={ariaLabel ?? "BrightLocal logo"}
|
|
86
86
|
fill="none"
|
|
87
87
|
height="21"
|
|
88
88
|
role="img"
|
|
@@ -15,12 +15,20 @@ interface NavigationMenuProps extends React.ComponentPropsWithoutRef<
|
|
|
15
15
|
> {
|
|
16
16
|
dataHook: string;
|
|
17
17
|
className?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Delay in ms before a hovered trigger opens its menu. Overrides Radix's
|
|
20
|
+
* laggy 200ms default with Base UI's snappier value.
|
|
21
|
+
* @default 50
|
|
22
|
+
*/
|
|
23
|
+
delayDuration?: number;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
const NavigationMenu = React.forwardRef<
|
|
21
27
|
React.ElementRef<typeof NavigationMenuPrimitive.Root>,
|
|
22
28
|
NavigationMenuProps
|
|
23
|
-
>(({ className, children, dataHook, ...props }, ref) => (
|
|
29
|
+
>(({ className, children, dataHook, delayDuration = 50, ...props }, ref) => (
|
|
30
|
+
// Radix defaults delayDuration to 200ms, which reads as a laggy hover-open.
|
|
31
|
+
// Match Base UI's snappier 50ms default (still overridable via props).
|
|
24
32
|
<NavigationMenuPrimitive.Root
|
|
25
33
|
ref={ref}
|
|
26
34
|
className={cn(
|
|
@@ -29,6 +37,7 @@ const NavigationMenu = React.forwardRef<
|
|
|
29
37
|
)}
|
|
30
38
|
data-hook={dataHook}
|
|
31
39
|
data-slot="navigation-menu"
|
|
40
|
+
delayDuration={delayDuration}
|
|
32
41
|
{...props}
|
|
33
42
|
>
|
|
34
43
|
{children}
|
|
@@ -82,42 +91,125 @@ type NavigationMenuTriggerProps = React.ComponentPropsWithoutRef<
|
|
|
82
91
|
typeof NavigationMenuPrimitive.Trigger
|
|
83
92
|
>;
|
|
84
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Window (ms) after the menu opens during which a mouse click is treated as
|
|
96
|
+
* instinctive and is NOT allowed to close the menu. Mirrors Base UI's
|
|
97
|
+
* "patient click" threshold (PATIENT_CLICK_THRESHOLD).
|
|
98
|
+
*/
|
|
99
|
+
const PATIENT_CLICK_THRESHOLD_MS = 500;
|
|
100
|
+
|
|
85
101
|
/**
|
|
86
102
|
* Trigger button that opens a dropdown menu
|
|
87
103
|
* Includes chevron icon that rotates when open
|
|
104
|
+
*
|
|
105
|
+
* Radix opens the menu on hover and then *toggles it closed* on the next click.
|
|
106
|
+
* Mouse users routinely click a trigger they have just hovered open, which
|
|
107
|
+
* closes it immediately (see radix-ui/primitives#1630).
|
|
108
|
+
*
|
|
109
|
+
* We port Base UI's "patient click" behaviour: an instinctive mouse click made
|
|
110
|
+
* within {@link PATIENT_CLICK_THRESHOLD_MS} of the menu opening keeps it open
|
|
111
|
+
* (calling `preventDefault()` makes Radix's internal `composeEventHandlers`
|
|
112
|
+
* skip its toggle). The window is measured from the `data-state` open
|
|
113
|
+
* transition — not the pointer enter — so it stays correct no matter how large
|
|
114
|
+
* `delayDuration` is. A deliberate click after that window still toggles the
|
|
115
|
+
* menu shut, and touch taps and keyboard activation are left untouched so they
|
|
116
|
+
* can toggle it too.
|
|
88
117
|
*/
|
|
89
118
|
const NavigationMenuTrigger = React.forwardRef<
|
|
90
119
|
React.ElementRef<typeof NavigationMenuPrimitive.Trigger>,
|
|
91
120
|
NavigationMenuTriggerProps
|
|
92
|
-
>(({ className, children, ...props }, ref) =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
+
>(({ className, children, onClick, onPointerDown, ...props }, ref) => {
|
|
122
|
+
// Pointer type of the interaction, so the keep-open behaviour only applies to
|
|
123
|
+
// mouse (the only input that hover-opens before a click).
|
|
124
|
+
const lastPointerTypeRef = React.useRef<string>("");
|
|
125
|
+
// Timestamp (event clock) of the last open transition, used to measure whether
|
|
126
|
+
// a click is "instinctive" (right after the menu opened) or "patient"
|
|
127
|
+
// (deliberate). Measuring from the open — not the pointer enter — keeps the
|
|
128
|
+
// window correct regardless of `delayDuration`. Starts at -Infinity so a click
|
|
129
|
+
// on a trigger that was already open at mount (no observed transition) is never
|
|
130
|
+
// misclassified as instinctive.
|
|
131
|
+
const openedAtRef = React.useRef(-Infinity);
|
|
132
|
+
const observerRef = React.useRef<MutationObserver | null>(null);
|
|
133
|
+
|
|
134
|
+
// Merge the forwarded ref with a `data-state` observer that stamps the open
|
|
135
|
+
// time. A callback ref (stable via useCallback) attaches once on mount and
|
|
136
|
+
// tears the observer down on unmount.
|
|
137
|
+
const composedRef = React.useCallback(
|
|
138
|
+
(node: React.ElementRef<typeof NavigationMenuPrimitive.Trigger> | null) => {
|
|
139
|
+
if (typeof ref === "function") {
|
|
140
|
+
ref(node);
|
|
141
|
+
} else if (ref) {
|
|
142
|
+
ref.current = node;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
observerRef.current?.disconnect();
|
|
146
|
+
if (node) {
|
|
147
|
+
const observer = new MutationObserver(() => {
|
|
148
|
+
if (node.getAttribute("data-state") === "open") {
|
|
149
|
+
openedAtRef.current = performance.now();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
observer.observe(node, {
|
|
153
|
+
attributes: true,
|
|
154
|
+
attributeFilter: ["data-state"],
|
|
155
|
+
});
|
|
156
|
+
observerRef.current = observer;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
[ref]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<NavigationMenuPrimitive.Trigger
|
|
164
|
+
ref={composedRef}
|
|
165
|
+
className={cn(
|
|
166
|
+
[
|
|
167
|
+
"group inline-flex h-9 w-max items-center justify-center gap-1",
|
|
168
|
+
"rounded-md px-4 py-2",
|
|
169
|
+
"text-sm font-medium",
|
|
170
|
+
"text-foreground",
|
|
171
|
+
"transition-colors",
|
|
172
|
+
"hover:bg-accent hover:text-accent-foreground",
|
|
173
|
+
"focus:bg-accent focus:text-accent-foreground",
|
|
174
|
+
"focus-visible:bg-accent focus-visible:ring-ring focus-visible:shadow-[0_0_0_4px_rgba(163,163,163,0.1)] focus-visible:ring-1 focus-visible:outline-none",
|
|
175
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
176
|
+
"data-[state=open]:bg-accent/50",
|
|
177
|
+
],
|
|
178
|
+
className
|
|
179
|
+
)}
|
|
180
|
+
data-slot="navigation-menu-trigger"
|
|
181
|
+
onClick={(event) => {
|
|
182
|
+
// `data-state` is "open" only when hover already opened this trigger.
|
|
183
|
+
// `event.detail > 0` excludes keyboard-synthesised clicks (detail === 0).
|
|
184
|
+
const isOpen =
|
|
185
|
+
event.currentTarget.getAttribute("data-state") === "open";
|
|
186
|
+
const isInstinctiveClick =
|
|
187
|
+
event.timeStamp - openedAtRef.current < PATIENT_CLICK_THRESHOLD_MS;
|
|
188
|
+
if (
|
|
189
|
+
lastPointerTypeRef.current === "mouse" &&
|
|
190
|
+
event.detail > 0 &&
|
|
191
|
+
isOpen &&
|
|
192
|
+
isInstinctiveClick
|
|
193
|
+
) {
|
|
194
|
+
event.preventDefault();
|
|
195
|
+
}
|
|
196
|
+
onClick?.(event);
|
|
197
|
+
}}
|
|
198
|
+
onPointerDown={(event) => {
|
|
199
|
+
lastPointerTypeRef.current = event.pointerType;
|
|
200
|
+
onPointerDown?.(event);
|
|
201
|
+
}}
|
|
202
|
+
{...props}
|
|
203
|
+
>
|
|
204
|
+
{children}
|
|
205
|
+
<ChevronDown
|
|
206
|
+
aria-hidden="true"
|
|
207
|
+
className="relative top-[1px] ml-1 transition duration-300 group-data-[state=open]:rotate-180"
|
|
208
|
+
size={12}
|
|
209
|
+
/>
|
|
210
|
+
</NavigationMenuPrimitive.Trigger>
|
|
211
|
+
);
|
|
212
|
+
});
|
|
121
213
|
|
|
122
214
|
NavigationMenuTrigger.displayName = "NavigationMenuTrigger";
|
|
123
215
|
|
|
@@ -144,6 +236,10 @@ const NavigationMenuContent = React.forwardRef<
|
|
|
144
236
|
"data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out",
|
|
145
237
|
"data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52",
|
|
146
238
|
"data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52",
|
|
239
|
+
// Match the viewport's easeOutQuint timing so the directional slide and
|
|
240
|
+
// the container morph feel like one motion (kept snappy so content
|
|
241
|
+
// appears without a perceptible fade-in delay).
|
|
242
|
+
"duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]",
|
|
147
243
|
"md:absolute md:w-auto",
|
|
148
244
|
],
|
|
149
245
|
className
|
|
@@ -205,8 +301,14 @@ const NavigationMenuViewport = React.forwardRef<
|
|
|
205
301
|
[
|
|
206
302
|
"origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)]",
|
|
207
303
|
"bg-popover text-popover-foreground w-full overflow-hidden rounded-md border shadow-sm",
|
|
208
|
-
|
|
209
|
-
|
|
304
|
+
// Base UI-style size morph: smoothly animate width/height between items
|
|
305
|
+
// with an easeOutQuint curve. The enter/exit stays snappy (200ms in,
|
|
306
|
+
// 150ms out) so the panel and its content appear immediately rather
|
|
307
|
+
// than fading in slowly. Reduced motion is neutralised globally by the
|
|
308
|
+
// token preset, so no per-element motion-reduce guard is needed.
|
|
309
|
+
"transition-[width,height] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]",
|
|
310
|
+
"data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
311
|
+
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=closed]:duration-150",
|
|
210
312
|
"md:w-[var(--radix-navigation-menu-viewport-width)]",
|
|
211
313
|
],
|
|
212
314
|
className
|
|
@@ -2,6 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { ChevronLeft, ChevronRight, MoreHorizontal } from "@brightlocal/icons";
|
|
3
3
|
import { cva, type VariantProps } from "class-variance-authority";
|
|
4
4
|
import { cn } from "@brightlocal/ui-components/lib/utils";
|
|
5
|
+
import { useIsBelowBreakpoint } from "@brightlocal/ui-components/hooks/use-breakpoint";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Pagination item variants
|
|
@@ -20,10 +21,6 @@ export interface UsePaginationParams {
|
|
|
20
21
|
page: number;
|
|
21
22
|
/** Total number of pages */
|
|
22
23
|
totalPages: number;
|
|
23
|
-
/** Number of siblings to show on each side of current page */
|
|
24
|
-
siblingCount?: number;
|
|
25
|
-
/** Number of boundary pages to show at start and end */
|
|
26
|
-
boundaryCount?: number;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
/**
|
|
@@ -32,88 +29,66 @@ export interface UsePaginationParams {
|
|
|
32
29
|
type PaginationItemType = number | "previous" | "next" | "ellipsis";
|
|
33
30
|
|
|
34
31
|
/**
|
|
35
|
-
* Custom hook for pagination logic
|
|
36
|
-
* Returns
|
|
32
|
+
* Custom hook for pagination logic.
|
|
33
|
+
* Returns a fixed-width list of pagination items — the count never changes
|
|
34
|
+
* as the user navigates. Page 1 and totalPages are always visible as boundary
|
|
35
|
+
* anchors. Ellipsis only appears when hiding 2+ pages.
|
|
37
36
|
*
|
|
38
37
|
* @example
|
|
39
|
-
* const items = usePagination({ page:
|
|
38
|
+
* const items = usePagination({ page: 2, totalPages: 10 });
|
|
39
|
+
* // Returns: ["previous", 1, 2, 3, 4, 5, "ellipsis", 10, "next"]
|
|
40
|
+
*
|
|
41
|
+
* const items = usePagination({ page: 5, totalPages: 10 });
|
|
40
42
|
* // Returns: ["previous", 1, "ellipsis", 4, 5, 6, "ellipsis", 10, "next"]
|
|
43
|
+
*
|
|
44
|
+
* // Automatically uses 5 slots below the `sm` breakpoint (640px)
|
|
45
|
+
* const items = usePagination({ page, totalPages });
|
|
41
46
|
*/
|
|
42
47
|
export function usePagination({
|
|
43
48
|
page,
|
|
44
49
|
totalPages,
|
|
45
|
-
siblingCount = 1,
|
|
46
|
-
boundaryCount = 1,
|
|
47
50
|
}: UsePaginationParams): PaginationItemType[] {
|
|
51
|
+
const isCompact = useIsBelowBreakpoint("sm");
|
|
52
|
+
const maxVisible = isCompact ? 5 : 7;
|
|
53
|
+
|
|
48
54
|
const items: PaginationItemType[] = React.useMemo(() => {
|
|
55
|
+
const slots = Math.max(5, maxVisible);
|
|
49
56
|
const result: PaginationItemType[] = [];
|
|
50
57
|
|
|
51
|
-
// Add previous button
|
|
52
58
|
result.push("previous");
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const rightSiblingIndex = Math.min(
|
|
57
|
-
page + siblingCount,
|
|
58
|
-
totalPages - boundaryCount
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
const showLeftEllipsis = leftSiblingIndex > boundaryCount + 2;
|
|
62
|
-
const showRightEllipsis =
|
|
63
|
-
rightSiblingIndex < totalPages - boundaryCount - 1;
|
|
64
|
-
|
|
65
|
-
// Add first boundary pages
|
|
66
|
-
for (let i = 1; i <= Math.min(boundaryCount, totalPages); i++) {
|
|
67
|
-
result.push(i);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Add left ellipsis if needed
|
|
71
|
-
if (showLeftEllipsis) {
|
|
72
|
-
result.push("ellipsis");
|
|
73
|
-
} else if (boundaryCount + 1 < leftSiblingIndex) {
|
|
74
|
-
// Add pages between boundary and left sibling
|
|
75
|
-
for (let i = boundaryCount + 1; i < leftSiblingIndex; i++) {
|
|
76
|
-
result.push(i);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Add sibling pages around current page
|
|
81
|
-
for (let i = leftSiblingIndex; i <= rightSiblingIndex; i++) {
|
|
82
|
-
if (i > boundaryCount && i <= totalPages - boundaryCount) {
|
|
60
|
+
if (totalPages <= slots) {
|
|
61
|
+
for (let i = 1; i <= totalPages; i++) {
|
|
83
62
|
result.push(i);
|
|
84
63
|
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
) {
|
|
107
|
-
if (i > boundaryCount) {
|
|
108
|
-
result.push(i);
|
|
64
|
+
} else {
|
|
65
|
+
const siblings = Math.floor((slots - 5) / 2);
|
|
66
|
+
const startThreshold = slots - 3; // e.g. 4 for slots=7, 2 for slots=5
|
|
67
|
+
const endThreshold = totalPages - startThreshold;
|
|
68
|
+
|
|
69
|
+
if (page <= startThreshold) {
|
|
70
|
+
for (let i = 1; i <= slots - 2; i++) {
|
|
71
|
+
result.push(i);
|
|
72
|
+
}
|
|
73
|
+
result.push("ellipsis", totalPages);
|
|
74
|
+
} else if (page >= endThreshold) {
|
|
75
|
+
result.push(1, "ellipsis");
|
|
76
|
+
for (let i = totalPages - (slots - 3); i <= totalPages; i++) {
|
|
77
|
+
result.push(i);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
result.push(1, "ellipsis");
|
|
81
|
+
for (let i = page - siblings; i <= page + siblings; i++) {
|
|
82
|
+
result.push(i);
|
|
83
|
+
}
|
|
84
|
+
result.push("ellipsis", totalPages);
|
|
109
85
|
}
|
|
110
86
|
}
|
|
111
87
|
|
|
112
|
-
// Add next button
|
|
113
88
|
result.push("next");
|
|
114
89
|
|
|
115
90
|
return result;
|
|
116
|
-
}, [page, totalPages,
|
|
91
|
+
}, [page, totalPages, maxVisible]);
|
|
117
92
|
|
|
118
93
|
return items;
|
|
119
94
|
}
|
|
@@ -125,7 +100,7 @@ const paginationItemVariants = cva(
|
|
|
125
100
|
"h-9 w-9",
|
|
126
101
|
"rounded-full",
|
|
127
102
|
"text-sm font-medium",
|
|
128
|
-
"transition-colors",
|
|
103
|
+
"transition-colors duration-200 ease-out",
|
|
129
104
|
"focus-visible:outline-none focus-visible:shadow-default",
|
|
130
105
|
],
|
|
131
106
|
{
|
|
@@ -154,7 +129,12 @@ const paginationItemVariants = cva(
|
|
|
154
129
|
// Disabled state
|
|
155
130
|
"aria-disabled:opacity-50 aria-disabled:cursor-default aria-disabled:pointer-events-none",
|
|
156
131
|
],
|
|
157
|
-
ellipsis: [
|
|
132
|
+
ellipsis: [
|
|
133
|
+
"relative",
|
|
134
|
+
"cursor-default",
|
|
135
|
+
"text-foreground",
|
|
136
|
+
"pointer-events-none",
|
|
137
|
+
],
|
|
158
138
|
},
|
|
159
139
|
},
|
|
160
140
|
defaultVariants: {
|