@aereamart/design-system 0.3.0 → 0.3.1
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/package.json +43 -43
- package/src/Accordion.tsx +57 -57
- package/src/AlertBanner.tsx +61 -61
- package/src/Badge.tsx +27 -27
- package/src/BottomSheet.tsx +59 -59
- package/src/Button.tsx +54 -54
- package/src/Card.tsx +38 -38
- package/src/DataTable.tsx +63 -63
- package/src/DatePicker.tsx +43 -43
- package/src/Drawer.tsx +70 -70
- package/src/EmptyState.tsx +36 -36
- package/src/Input.tsx +30 -30
- package/src/Menu.tsx +72 -72
- package/src/Modal.tsx +62 -62
- package/src/NavigationBar.tsx +67 -67
- package/src/Pagination.tsx +68 -68
- package/src/Popover.tsx +33 -33
- package/src/SegmentedControl.tsx +62 -62
- package/src/Select.tsx +32 -32
- package/src/Sidebar.tsx +72 -72
- package/src/Snackbar.tsx +71 -71
- package/src/Spinner.tsx +19 -19
- package/src/Tabs.tsx +76 -76
- package/src/Textarea.tsx +30 -30
- package/src/Tooltip.tsx +24 -24
- package/src/TreeView.tsx +104 -104
- package/src/cn.ts +2 -2
package/src/Menu.tsx
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { cn } from './cn';
|
|
3
|
-
|
|
4
|
-
export interface MenuItem {
|
|
5
|
-
label: string;
|
|
6
|
-
onSelect?: () => void;
|
|
7
|
-
danger?: boolean;
|
|
8
|
-
disabled?: boolean;
|
|
9
|
-
icon?: React.ReactNode;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface MenuProps {
|
|
13
|
-
trigger: React.ReactNode;
|
|
14
|
-
items: MenuItem[];
|
|
15
|
-
align?: 'start' | 'end';
|
|
16
|
-
className?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function Menu({ trigger, items, align = 'end', className }: MenuProps) {
|
|
20
|
-
const [open, setOpen] = useState(false);
|
|
21
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (!open) return;
|
|
25
|
-
const onDown = (e: MouseEvent) => {
|
|
26
|
-
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
|
27
|
-
};
|
|
28
|
-
const onKey = (e: KeyboardEvent) => {
|
|
29
|
-
if (e.key === 'Escape') setOpen(false);
|
|
30
|
-
};
|
|
31
|
-
document.addEventListener('mousedown', onDown);
|
|
32
|
-
document.addEventListener('keydown', onKey);
|
|
33
|
-
return () => {
|
|
34
|
-
document.removeEventListener('mousedown', onDown);
|
|
35
|
-
document.removeEventListener('keydown', onKey);
|
|
36
|
-
};
|
|
37
|
-
}, [open]);
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<div ref={ref} className={cn('relative inline-flex', className)}>
|
|
41
|
-
<div onClick={() => setOpen(v => !v)}>{trigger}</div>
|
|
42
|
-
{open && (
|
|
43
|
-
<div
|
|
44
|
-
role="menu"
|
|
45
|
-
className={cn(
|
|
46
|
-
'absolute z-50 mt-1.5 min-w-40 overflow-hidden rounded-lg border border-slate-200 bg-white py-1 shadow-lg',
|
|
47
|
-
align === 'end' ? 'right-0' : 'left-0'
|
|
48
|
-
)}
|
|
49
|
-
>
|
|
50
|
-
{items.map((item, i) => (
|
|
51
|
-
<button
|
|
52
|
-
key={`${item.label}-${i}`}
|
|
53
|
-
type="button"
|
|
54
|
-
role="menuitem"
|
|
55
|
-
disabled={item.disabled}
|
|
56
|
-
onClick={() => {
|
|
57
|
-
setOpen(false);
|
|
58
|
-
item.onSelect?.();
|
|
59
|
-
}}
|
|
60
|
-
className={cn(
|
|
61
|
-
'flex w-full items-center gap-2.5 px-4 py-2 text-left text-sm transition-colors disabled:opacity-50 focus-visible:outline-none focus-visible:bg-slate-100',
|
|
62
|
-
item.danger ? 'text-red-700 hover:bg-red-50' : 'text-slate-700 hover:bg-slate-50'
|
|
63
|
-
)}
|
|
64
|
-
>
|
|
65
|
-
{item.icon}
|
|
66
|
-
<span className="flex-1">{item.label}</span>
|
|
67
|
-
</button>
|
|
68
|
-
))}
|
|
69
|
-
</div>
|
|
70
|
-
)}
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
|
|
4
|
+
export interface MenuItem {
|
|
5
|
+
label: string;
|
|
6
|
+
onSelect?: () => void;
|
|
7
|
+
danger?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MenuProps {
|
|
13
|
+
trigger: React.ReactNode;
|
|
14
|
+
items: MenuItem[];
|
|
15
|
+
align?: 'start' | 'end';
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Menu({ trigger, items, align = 'end', className }: MenuProps) {
|
|
20
|
+
const [open, setOpen] = useState(false);
|
|
21
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!open) return;
|
|
25
|
+
const onDown = (e: MouseEvent) => {
|
|
26
|
+
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
|
|
27
|
+
};
|
|
28
|
+
const onKey = (e: KeyboardEvent) => {
|
|
29
|
+
if (e.key === 'Escape') setOpen(false);
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener('mousedown', onDown);
|
|
32
|
+
document.addEventListener('keydown', onKey);
|
|
33
|
+
return () => {
|
|
34
|
+
document.removeEventListener('mousedown', onDown);
|
|
35
|
+
document.removeEventListener('keydown', onKey);
|
|
36
|
+
};
|
|
37
|
+
}, [open]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div ref={ref} className={cn('relative inline-flex', className)}>
|
|
41
|
+
<div onClick={() => setOpen(v => !v)}>{trigger}</div>
|
|
42
|
+
{open && (
|
|
43
|
+
<div
|
|
44
|
+
role="menu"
|
|
45
|
+
className={cn(
|
|
46
|
+
'absolute z-50 mt-1.5 min-w-40 overflow-hidden rounded-lg border border-slate-200 bg-white py-1 shadow-lg',
|
|
47
|
+
align === 'end' ? 'right-0' : 'left-0'
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
{items.map((item, i) => (
|
|
51
|
+
<button
|
|
52
|
+
key={`${item.label}-${i}`}
|
|
53
|
+
type="button"
|
|
54
|
+
role="menuitem"
|
|
55
|
+
disabled={item.disabled}
|
|
56
|
+
onClick={() => {
|
|
57
|
+
setOpen(false);
|
|
58
|
+
item.onSelect?.();
|
|
59
|
+
}}
|
|
60
|
+
className={cn(
|
|
61
|
+
'flex w-full items-center gap-2.5 px-4 py-2 text-left text-sm transition-colors disabled:opacity-50 focus-visible:outline-none focus-visible:bg-slate-100',
|
|
62
|
+
item.danger ? 'text-red-700 hover:bg-red-50' : 'text-slate-700 hover:bg-slate-50'
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
{item.icon}
|
|
66
|
+
<span className="flex-1">{item.label}</span>
|
|
67
|
+
</button>
|
|
68
|
+
))}
|
|
69
|
+
</div>
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
73
|
}
|
package/src/Modal.tsx
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
import { createPortal } from 'react-dom';
|
|
3
|
-
import { X } from 'lucide-react';
|
|
4
|
-
import { cn } from './cn';
|
|
5
|
-
|
|
6
|
-
export interface ModalProps {
|
|
7
|
-
open: boolean;
|
|
8
|
-
onClose: () => void;
|
|
9
|
-
title?: string;
|
|
10
|
-
children?: React.ReactNode;
|
|
11
|
-
className?: string;
|
|
12
|
-
maxWidth?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function Modal({
|
|
16
|
-
open,
|
|
17
|
-
onClose,
|
|
18
|
-
title,
|
|
19
|
-
children,
|
|
20
|
-
className,
|
|
21
|
-
maxWidth = 'max-w-md',
|
|
22
|
-
}: ModalProps) {
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (!open) return;
|
|
25
|
-
const onKey = (e: KeyboardEvent) => {
|
|
26
|
-
if (e.key === 'Escape') onClose();
|
|
27
|
-
};
|
|
28
|
-
document.body.style.overflow = 'hidden';
|
|
29
|
-
document.addEventListener('keydown', onKey);
|
|
30
|
-
return () => {
|
|
31
|
-
document.body.style.overflow = '';
|
|
32
|
-
document.removeEventListener('keydown', onKey);
|
|
33
|
-
};
|
|
34
|
-
}, [open, onClose]);
|
|
35
|
-
|
|
36
|
-
if (!open) return null;
|
|
37
|
-
|
|
38
|
-
return createPortal(
|
|
39
|
-
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
|
40
|
-
<div
|
|
41
|
-
className={cn('w-full rounded-2xl bg-white shadow-xl', maxWidth, className)}
|
|
42
|
-
role="dialog"
|
|
43
|
-
aria-modal="true"
|
|
44
|
-
>
|
|
45
|
-
{title && (
|
|
46
|
-
<div className="flex items-center justify-between border-b border-slate-100 px-6 py-4">
|
|
47
|
-
<h2 className="text-lg font-bold text-slate-900">{title}</h2>
|
|
48
|
-
<button
|
|
49
|
-
onClick={onClose}
|
|
50
|
-
className="rounded-lg p-1 text-slate-400 hover:bg-slate-100"
|
|
51
|
-
aria-label="Close"
|
|
52
|
-
>
|
|
53
|
-
<X className="h-5 w-5" />
|
|
54
|
-
</button>
|
|
55
|
-
</div>
|
|
56
|
-
)}
|
|
57
|
-
{children}
|
|
58
|
-
</div>
|
|
59
|
-
</div>,
|
|
60
|
-
document.body
|
|
61
|
-
);
|
|
62
|
-
}
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { X } from 'lucide-react';
|
|
4
|
+
import { cn } from './cn';
|
|
5
|
+
|
|
6
|
+
export interface ModalProps {
|
|
7
|
+
open: boolean;
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
title?: string;
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
maxWidth?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Modal({
|
|
16
|
+
open,
|
|
17
|
+
onClose,
|
|
18
|
+
title,
|
|
19
|
+
children,
|
|
20
|
+
className,
|
|
21
|
+
maxWidth = 'max-w-md',
|
|
22
|
+
}: ModalProps) {
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!open) return;
|
|
25
|
+
const onKey = (e: KeyboardEvent) => {
|
|
26
|
+
if (e.key === 'Escape') onClose();
|
|
27
|
+
};
|
|
28
|
+
document.body.style.overflow = 'hidden';
|
|
29
|
+
document.addEventListener('keydown', onKey);
|
|
30
|
+
return () => {
|
|
31
|
+
document.body.style.overflow = '';
|
|
32
|
+
document.removeEventListener('keydown', onKey);
|
|
33
|
+
};
|
|
34
|
+
}, [open, onClose]);
|
|
35
|
+
|
|
36
|
+
if (!open) return null;
|
|
37
|
+
|
|
38
|
+
return createPortal(
|
|
39
|
+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
|
40
|
+
<div
|
|
41
|
+
className={cn('w-full rounded-2xl bg-white shadow-xl', maxWidth, className)}
|
|
42
|
+
role="dialog"
|
|
43
|
+
aria-modal="true"
|
|
44
|
+
>
|
|
45
|
+
{title && (
|
|
46
|
+
<div className="flex items-center justify-between border-b border-slate-100 px-6 py-4">
|
|
47
|
+
<h2 className="text-lg font-bold text-slate-900">{title}</h2>
|
|
48
|
+
<button
|
|
49
|
+
onClick={onClose}
|
|
50
|
+
className="rounded-lg p-1 text-slate-400 hover:bg-slate-100"
|
|
51
|
+
aria-label="Close"
|
|
52
|
+
>
|
|
53
|
+
<X className="h-5 w-5" />
|
|
54
|
+
</button>
|
|
55
|
+
</div>
|
|
56
|
+
)}
|
|
57
|
+
{children}
|
|
58
|
+
</div>
|
|
59
|
+
</div>,
|
|
60
|
+
document.body
|
|
61
|
+
);
|
|
62
|
+
}
|
package/src/NavigationBar.tsx
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { cn } from './cn';
|
|
3
|
-
|
|
4
|
-
export interface NavItem {
|
|
5
|
-
value: string;
|
|
6
|
-
label: string;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface NavigationBarProps {
|
|
11
|
-
items: NavItem[];
|
|
12
|
-
value?: string;
|
|
13
|
-
defaultValue?: string;
|
|
14
|
-
onChange?: (value: string) => void;
|
|
15
|
-
variant?: 'pills' | 'links';
|
|
16
|
-
className?: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function NavigationBar({
|
|
20
|
-
items,
|
|
21
|
-
value,
|
|
22
|
-
defaultValue,
|
|
23
|
-
onChange,
|
|
24
|
-
variant = 'links',
|
|
25
|
-
className,
|
|
26
|
-
}: NavigationBarProps) {
|
|
27
|
-
const isControlled = value !== undefined;
|
|
28
|
-
const [inner, setInner] = useState<string | undefined>(defaultValue);
|
|
29
|
-
const active = isControlled ? value : inner;
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<nav aria-label="Primary" className={cn('flex items-center gap-1', className)}>
|
|
33
|
-
{items.map(item => {
|
|
34
|
-
const selected = active === item.value;
|
|
35
|
-
return (
|
|
36
|
-
<button
|
|
37
|
-
key={item.value}
|
|
38
|
-
type="button"
|
|
39
|
-
aria-current={selected ? 'page' : undefined}
|
|
40
|
-
disabled={item.disabled}
|
|
41
|
-
onClick={() => {
|
|
42
|
-
if (!isControlled) setInner(item.value);
|
|
43
|
-
onChange?.(item.value);
|
|
44
|
-
}}
|
|
45
|
-
className={cn(
|
|
46
|
-
'px-4 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40 disabled:opacity-50',
|
|
47
|
-
variant === 'pills'
|
|
48
|
-
? cn(
|
|
49
|
-
'rounded-lg',
|
|
50
|
-
selected
|
|
51
|
-
? 'bg-lime-600 text-white'
|
|
52
|
-
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
|
53
|
-
)
|
|
54
|
-
: cn(
|
|
55
|
-
'border-b-2',
|
|
56
|
-
selected
|
|
57
|
-
? 'border-lime-600 text-lime-700'
|
|
58
|
-
: 'border-transparent text-slate-500 hover:text-slate-900'
|
|
59
|
-
)
|
|
60
|
-
)}
|
|
61
|
-
>
|
|
62
|
-
{item.label}
|
|
63
|
-
</button>
|
|
64
|
-
);
|
|
65
|
-
})}
|
|
66
|
-
</nav>
|
|
67
|
-
);
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
|
|
4
|
+
export interface NavItem {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface NavigationBarProps {
|
|
11
|
+
items: NavItem[];
|
|
12
|
+
value?: string;
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
onChange?: (value: string) => void;
|
|
15
|
+
variant?: 'pills' | 'links';
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function NavigationBar({
|
|
20
|
+
items,
|
|
21
|
+
value,
|
|
22
|
+
defaultValue,
|
|
23
|
+
onChange,
|
|
24
|
+
variant = 'links',
|
|
25
|
+
className,
|
|
26
|
+
}: NavigationBarProps) {
|
|
27
|
+
const isControlled = value !== undefined;
|
|
28
|
+
const [inner, setInner] = useState<string | undefined>(defaultValue);
|
|
29
|
+
const active = isControlled ? value : inner;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<nav aria-label="Primary" className={cn('flex items-center gap-1', className)}>
|
|
33
|
+
{items.map(item => {
|
|
34
|
+
const selected = active === item.value;
|
|
35
|
+
return (
|
|
36
|
+
<button
|
|
37
|
+
key={item.value}
|
|
38
|
+
type="button"
|
|
39
|
+
aria-current={selected ? 'page' : undefined}
|
|
40
|
+
disabled={item.disabled}
|
|
41
|
+
onClick={() => {
|
|
42
|
+
if (!isControlled) setInner(item.value);
|
|
43
|
+
onChange?.(item.value);
|
|
44
|
+
}}
|
|
45
|
+
className={cn(
|
|
46
|
+
'px-4 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40 disabled:opacity-50',
|
|
47
|
+
variant === 'pills'
|
|
48
|
+
? cn(
|
|
49
|
+
'rounded-lg',
|
|
50
|
+
selected
|
|
51
|
+
? 'bg-lime-600 text-white'
|
|
52
|
+
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
|
53
|
+
)
|
|
54
|
+
: cn(
|
|
55
|
+
'border-b-2',
|
|
56
|
+
selected
|
|
57
|
+
? 'border-lime-600 text-lime-700'
|
|
58
|
+
: 'border-transparent text-slate-500 hover:text-slate-900'
|
|
59
|
+
)
|
|
60
|
+
)}
|
|
61
|
+
>
|
|
62
|
+
{item.label}
|
|
63
|
+
</button>
|
|
64
|
+
);
|
|
65
|
+
})}
|
|
66
|
+
</nav>
|
|
67
|
+
);
|
|
68
68
|
}
|
package/src/Pagination.tsx
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
2
|
-
import { cn } from './cn';
|
|
3
|
-
import { Button } from './Button';
|
|
4
|
-
|
|
5
|
-
export interface PaginationProps {
|
|
6
|
-
page: number;
|
|
7
|
-
totalPages: number;
|
|
8
|
-
onChange: (page: number) => void;
|
|
9
|
-
className?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function pageList(page: number, total: number): (number | '…')[] {
|
|
13
|
-
if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1);
|
|
14
|
-
const pages: (number | '…')[] = [1];
|
|
15
|
-
const start = Math.max(2, page - 1);
|
|
16
|
-
const end = Math.min(total - 1, page + 1);
|
|
17
|
-
if (start > 2) pages.push('…');
|
|
18
|
-
for (let i = start; i <= end; i++) pages.push(i);
|
|
19
|
-
if (end < total - 1) pages.push('…');
|
|
20
|
-
pages.push(total);
|
|
21
|
-
return pages;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function Pagination({ page, totalPages, onChange, className }: PaginationProps) {
|
|
25
|
-
return (
|
|
26
|
-
<nav aria-label="Pagination" className={cn('flex items-center gap-1', className)}>
|
|
27
|
-
<Button
|
|
28
|
-
variant="ghost"
|
|
29
|
-
size="sm"
|
|
30
|
-
disabled={page <= 1}
|
|
31
|
-
onClick={() => onChange(page - 1)}
|
|
32
|
-
aria-label="Previous page"
|
|
33
|
-
>
|
|
34
|
-
<ChevronLeft className="h-4 w-4" />
|
|
35
|
-
</Button>
|
|
36
|
-
{pageList(page, totalPages).map((p, i) =>
|
|
37
|
-
p === '…' ? (
|
|
38
|
-
<span key={`e-${i}`} className="px-1.5 text-sm text-slate-400">
|
|
39
|
-
…
|
|
40
|
-
</span>
|
|
41
|
-
) : (
|
|
42
|
-
<button
|
|
43
|
-
key={p}
|
|
44
|
-
type="button"
|
|
45
|
-
onClick={() => onChange(p)}
|
|
46
|
-
aria-current={p === page ? 'page' : undefined}
|
|
47
|
-
className={cn(
|
|
48
|
-
'h-8 min-w-8 rounded-lg px-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40',
|
|
49
|
-
p === page
|
|
50
|
-
? 'bg-lime-600 text-white'
|
|
51
|
-
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
|
52
|
-
)}
|
|
53
|
-
>
|
|
54
|
-
{p}
|
|
55
|
-
</button>
|
|
56
|
-
)
|
|
57
|
-
)}
|
|
58
|
-
<Button
|
|
59
|
-
variant="ghost"
|
|
60
|
-
size="sm"
|
|
61
|
-
disabled={page >= totalPages}
|
|
62
|
-
onClick={() => onChange(page + 1)}
|
|
63
|
-
aria-label="Next page"
|
|
64
|
-
>
|
|
65
|
-
<ChevronRight className="h-4 w-4" />
|
|
66
|
-
</Button>
|
|
67
|
-
</nav>
|
|
68
|
-
);
|
|
1
|
+
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
|
|
5
|
+
export interface PaginationProps {
|
|
6
|
+
page: number;
|
|
7
|
+
totalPages: number;
|
|
8
|
+
onChange: (page: number) => void;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function pageList(page: number, total: number): (number | '…')[] {
|
|
13
|
+
if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1);
|
|
14
|
+
const pages: (number | '…')[] = [1];
|
|
15
|
+
const start = Math.max(2, page - 1);
|
|
16
|
+
const end = Math.min(total - 1, page + 1);
|
|
17
|
+
if (start > 2) pages.push('…');
|
|
18
|
+
for (let i = start; i <= end; i++) pages.push(i);
|
|
19
|
+
if (end < total - 1) pages.push('…');
|
|
20
|
+
pages.push(total);
|
|
21
|
+
return pages;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Pagination({ page, totalPages, onChange, className }: PaginationProps) {
|
|
25
|
+
return (
|
|
26
|
+
<nav aria-label="Pagination" className={cn('flex items-center gap-1', className)}>
|
|
27
|
+
<Button
|
|
28
|
+
variant="ghost"
|
|
29
|
+
size="sm"
|
|
30
|
+
disabled={page <= 1}
|
|
31
|
+
onClick={() => onChange(page - 1)}
|
|
32
|
+
aria-label="Previous page"
|
|
33
|
+
>
|
|
34
|
+
<ChevronLeft className="h-4 w-4" />
|
|
35
|
+
</Button>
|
|
36
|
+
{pageList(page, totalPages).map((p, i) =>
|
|
37
|
+
p === '…' ? (
|
|
38
|
+
<span key={`e-${i}`} className="px-1.5 text-sm text-slate-400">
|
|
39
|
+
…
|
|
40
|
+
</span>
|
|
41
|
+
) : (
|
|
42
|
+
<button
|
|
43
|
+
key={p}
|
|
44
|
+
type="button"
|
|
45
|
+
onClick={() => onChange(p)}
|
|
46
|
+
aria-current={p === page ? 'page' : undefined}
|
|
47
|
+
className={cn(
|
|
48
|
+
'h-8 min-w-8 rounded-lg px-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40',
|
|
49
|
+
p === page
|
|
50
|
+
? 'bg-lime-600 text-white'
|
|
51
|
+
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
{p}
|
|
55
|
+
</button>
|
|
56
|
+
)
|
|
57
|
+
)}
|
|
58
|
+
<Button
|
|
59
|
+
variant="ghost"
|
|
60
|
+
size="sm"
|
|
61
|
+
disabled={page >= totalPages}
|
|
62
|
+
onClick={() => onChange(page + 1)}
|
|
63
|
+
aria-label="Next page"
|
|
64
|
+
>
|
|
65
|
+
<ChevronRight className="h-4 w-4" />
|
|
66
|
+
</Button>
|
|
67
|
+
</nav>
|
|
68
|
+
);
|
|
69
69
|
}
|
package/src/Popover.tsx
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { cn } from './cn';
|
|
2
|
-
|
|
3
|
-
export interface PopoverProps {
|
|
4
|
-
trigger: React.ReactNode;
|
|
5
|
-
content: React.ReactNode;
|
|
6
|
-
side?: 'top' | 'bottom' | 'left' | 'right';
|
|
7
|
-
className?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function Popover({ trigger, content, side = 'bottom', className }: PopoverProps) {
|
|
11
|
-
const isTop = side === 'top';
|
|
12
|
-
const isBottom = side === 'bottom';
|
|
13
|
-
const isLeft = side === 'left';
|
|
14
|
-
const isRight = side === 'right';
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<span className="group relative inline-flex">
|
|
18
|
-
{trigger}
|
|
19
|
-
<span
|
|
20
|
-
role="tooltip"
|
|
21
|
-
className={cn(
|
|
22
|
-
'pointer-events-none absolute z-50 w-64 rounded-xl border border-slate-200 bg-white p-4 text-sm text-slate-700 opacity-0 shadow-lg transition-opacity duration-200 group-hover:opacity-100 group-focus-within:opacity-100',
|
|
23
|
-
isBottom && 'left-1/2 top-full mt-2 -translate-x-1/2',
|
|
24
|
-
isTop && 'bottom-full left-1/2 mb-2 -translate-x-1/2',
|
|
25
|
-
isLeft && 'right-full top-1/2 mr-2 -translate-y-1/2',
|
|
26
|
-
isRight && 'left-full top-1/2 ml-2 -translate-y-1/2',
|
|
27
|
-
className
|
|
28
|
-
)}
|
|
29
|
-
>
|
|
30
|
-
{content}
|
|
31
|
-
</span>
|
|
32
|
-
</span>
|
|
33
|
-
);
|
|
1
|
+
import { cn } from './cn';
|
|
2
|
+
|
|
3
|
+
export interface PopoverProps {
|
|
4
|
+
trigger: React.ReactNode;
|
|
5
|
+
content: React.ReactNode;
|
|
6
|
+
side?: 'top' | 'bottom' | 'left' | 'right';
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Popover({ trigger, content, side = 'bottom', className }: PopoverProps) {
|
|
11
|
+
const isTop = side === 'top';
|
|
12
|
+
const isBottom = side === 'bottom';
|
|
13
|
+
const isLeft = side === 'left';
|
|
14
|
+
const isRight = side === 'right';
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<span className="group relative inline-flex">
|
|
18
|
+
{trigger}
|
|
19
|
+
<span
|
|
20
|
+
role="tooltip"
|
|
21
|
+
className={cn(
|
|
22
|
+
'pointer-events-none absolute z-50 w-64 rounded-xl border border-slate-200 bg-white p-4 text-sm text-slate-700 opacity-0 shadow-lg transition-opacity duration-200 group-hover:opacity-100 group-focus-within:opacity-100',
|
|
23
|
+
isBottom && 'left-1/2 top-full mt-2 -translate-x-1/2',
|
|
24
|
+
isTop && 'bottom-full left-1/2 mb-2 -translate-x-1/2',
|
|
25
|
+
isLeft && 'right-full top-1/2 mr-2 -translate-y-1/2',
|
|
26
|
+
isRight && 'left-full top-1/2 ml-2 -translate-y-1/2',
|
|
27
|
+
className
|
|
28
|
+
)}
|
|
29
|
+
>
|
|
30
|
+
{content}
|
|
31
|
+
</span>
|
|
32
|
+
</span>
|
|
33
|
+
);
|
|
34
34
|
}
|