@gaulatti/bleecker 0.1.7 → 0.1.9
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/dist/components/accordion.js +2 -2
- package/dist/components/alert-dialog.d.ts +13 -0
- package/dist/components/alert-dialog.js +42 -0
- package/dist/components/avatar.d.ts +16 -0
- package/dist/components/avatar.js +36 -0
- package/dist/components/breadcrumb.d.ts +15 -0
- package/dist/components/breadcrumb.js +24 -0
- package/dist/components/button-group.d.ts +15 -0
- package/dist/components/button-group.js +23 -0
- package/dist/components/collection-filters.d.ts +1 -1
- package/dist/components/collection-filters.js +1 -1
- package/dist/components/command-spotlight.d.ts +30 -0
- package/dist/components/command-spotlight.js +214 -0
- package/dist/components/date-picker.d.ts +20 -0
- package/dist/components/date-picker.js +97 -0
- package/dist/components/drawer.d.ts +11 -0
- package/dist/components/drawer.js +42 -0
- package/dist/components/empty.d.ts +9 -0
- package/dist/components/empty.js +6 -0
- package/dist/components/hover-card.d.ts +12 -0
- package/dist/components/hover-card.js +9 -0
- package/dist/components/kbd.d.ts +7 -0
- package/dist/components/kbd.js +10 -0
- package/dist/components/menubar.d.ts +43 -0
- package/dist/components/menubar.js +58 -0
- package/dist/components/navigation-menu.d.ts +16 -0
- package/dist/components/navigation-menu.js +41 -0
- package/dist/components/otp-input.d.ts +11 -0
- package/dist/components/otp-input.js +53 -0
- package/dist/components/popover.d.ts +14 -0
- package/dist/components/popover.js +93 -0
- package/dist/components/progress.d.ts +11 -0
- package/dist/components/progress.js +17 -0
- package/dist/components/radio-group.d.ts +16 -0
- package/dist/components/radio-group.js +14 -0
- package/dist/components/scroll-area.d.ts +11 -0
- package/dist/components/scroll-area.js +12 -0
- package/dist/components/sheet.d.ts +12 -0
- package/dist/components/sheet.js +53 -0
- package/dist/components/slider.d.ts +11 -0
- package/dist/components/slider.js +9 -0
- package/dist/components/sonner.d.ts +29 -0
- package/dist/components/sonner.js +76 -0
- package/dist/components/sortable-table-header.js +4 -3
- package/dist/components/switch.d.ts +7 -0
- package/dist/components/switch.js +7 -0
- package/dist/components/table.d.ts +60 -0
- package/dist/components/table.js +92 -0
- package/dist/components/toggle-group.d.ts +26 -0
- package/dist/components/toggle-group.js +32 -0
- package/dist/components/toggle.d.ts +8 -0
- package/dist/components/toggle.js +26 -0
- package/dist/components/tooltip.d.ts +9 -0
- package/dist/components/tooltip.js +24 -0
- package/dist/index.d.ts +25 -1
- package/dist/index.js +25 -1
- package/dist/styles.css +1 -1
- package/dist/theme/theme-script.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { ChevronDown
|
|
2
|
+
import { ChevronDown } from 'lucide-react';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { cn } from '../utils/cn.js';
|
|
5
5
|
export function Accordion({ className, defaultExpandedId = null, items }) {
|
|
6
6
|
const [expandedId, setExpandedId] = React.useState(defaultExpandedId);
|
|
7
7
|
return (_jsx("div", { className: cn('overflow-hidden rounded-xl border border-sand/10 bg-white shadow-sm dark:border-sand/20 dark:bg-sand/10', className), children: _jsx("ul", { className: 'divide-y divide-sand/10 dark:divide-sand/20', children: items.map((item) => {
|
|
8
8
|
const isExpanded = expandedId === item.id;
|
|
9
|
-
return (_jsxs("li", { children: [_jsxs("div", { className: 'flex cursor-pointer items-center justify-between px-4 py-4 transition-colors hover:bg-sand/5 dark:hover:bg-sand/10 sm:px-6', onClick: () => setExpandedId(isExpanded ? null : item.id), children: [_jsxs("div", { className: 'flex min-w-0 items-center gap-3', children: [
|
|
9
|
+
return (_jsxs("li", { children: [_jsxs("div", { className: 'flex cursor-pointer items-center justify-between px-4 py-4 transition-colors hover:bg-sand/5 dark:hover:bg-sand/10 sm:px-6', onClick: () => setExpandedId(isExpanded ? null : item.id), children: [_jsxs("div", { className: 'flex min-w-0 items-center gap-3', children: [_jsx(ChevronDown, { size: 16, className: cn('flex-shrink-0 text-text-secondary transition-transform duration-300 ease-in-out', isExpanded ? 'rotate-0' : '-rotate-90') }), _jsxs("div", { className: 'min-w-0', children: [_jsx("div", { className: 'text-sm font-medium text-text-primary dark:text-text-primary', children: item.title }), item.subtitle ? _jsx("div", { className: 'mt-0.5 text-xs text-text-secondary dark:text-text-secondary', children: item.subtitle }) : null] })] }), item.actions ? (_jsx("div", { className: 'ml-4 flex items-center gap-2', onClick: (event) => event.stopPropagation(), children: item.actions })) : null] }), _jsx("div", { className: cn('grid transition-[grid-template-rows] duration-300 ease-in-out', isExpanded ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]'), children: _jsx("div", { className: 'overflow-hidden', children: _jsx("div", { className: 'bg-sand/5 dark:bg-sand/5', children: item.content }) }) })] }, item.id));
|
|
10
10
|
}) }) }));
|
|
11
11
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface AlertDialogProps {
|
|
3
|
+
cancelLabel?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
confirmLabel?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
onCancel: () => void;
|
|
9
|
+
onConfirm: () => void;
|
|
10
|
+
title: string;
|
|
11
|
+
variant?: 'default' | 'destructive';
|
|
12
|
+
}
|
|
13
|
+
export declare function AlertDialog({ cancelLabel, className, confirmLabel, description, isOpen, onCancel, onConfirm, title, variant }: AlertDialogProps): React.ReactPortal | null;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AlertTriangle } from 'lucide-react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { cn } from '../utils/cn.js';
|
|
6
|
+
export function AlertDialog({ cancelLabel = 'Cancel', className, confirmLabel = 'Continue', description, isOpen, onCancel, onConfirm, title, variant = 'default' }) {
|
|
7
|
+
const dialogRef = React.useRef(null);
|
|
8
|
+
React.useEffect(() => {
|
|
9
|
+
const dialog = dialogRef.current;
|
|
10
|
+
if (!dialog)
|
|
11
|
+
return;
|
|
12
|
+
if (isOpen && !dialog.open) {
|
|
13
|
+
dialog.showModal();
|
|
14
|
+
}
|
|
15
|
+
else if (!isOpen && dialog.open) {
|
|
16
|
+
dialog.close();
|
|
17
|
+
}
|
|
18
|
+
}, [isOpen]);
|
|
19
|
+
// Trap focus & handle keyboard dismissal
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (!isOpen)
|
|
22
|
+
return;
|
|
23
|
+
const handleKeyDown = (event) => {
|
|
24
|
+
if (event.key === 'Escape') {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
onCancel();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
30
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
31
|
+
}, [isOpen, onCancel]);
|
|
32
|
+
if (typeof document === 'undefined' || !isOpen) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return createPortal(_jsx("dialog", { ref: dialogRef, className: cn('m-auto w-full max-w-md rounded-[24px] border border-sand/10 bg-white p-0 text-text-primary shadow-xl outline-none backdrop:bg-black/50 backdrop:backdrop-blur-sm dark:border-sand/20 dark:bg-dark-sand dark:text-text-primary dark:backdrop:bg-black/70', className), onClick: (event) => {
|
|
36
|
+
if (event.target === dialogRef.current) {
|
|
37
|
+
onCancel();
|
|
38
|
+
}
|
|
39
|
+
}, onClose: onCancel, children: _jsxs("div", { className: 'p-6', children: [_jsxs("div", { className: 'mb-4 flex items-start gap-4', children: [_jsx("div", { className: cn('flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-full', variant === 'destructive'
|
|
40
|
+
? 'bg-terracotta/10 text-terracotta dark:bg-terracotta/20'
|
|
41
|
+
: 'bg-desert/10 text-desert dark:bg-desert/20 dark:text-accent-gold'), children: _jsx(AlertTriangle, { size: 20 }) }), _jsxs("div", { className: 'min-w-0 flex-1', children: [_jsx("h3", { className: 'text-lg font-semibold leading-tight text-text-primary dark:text-text-primary', children: title }), description ? _jsx("p", { className: 'mt-1.5 text-sm leading-relaxed text-text-secondary dark:text-text-secondary', children: description }) : null] })] }), _jsxs("div", { className: 'flex justify-end gap-3', children: [_jsx("button", { type: 'button', onClick: onCancel, className: 'inline-flex items-center justify-center rounded-full border border-sand/20 bg-white/65 px-4 py-2 text-sm font-medium tracking-refined text-text-primary transition-all duration-400 hover:-translate-y-0.5 hover:bg-white focus:outline-none focus-visible:ring-2 focus-visible:ring-sea dark:border-sand/50 dark:bg-sand/20 dark:text-text-primary dark:hover:bg-sand/30 dark:focus-visible:ring-accent-blue', children: cancelLabel }), _jsx("button", { type: 'button', onClick: onConfirm, className: cn('inline-flex items-center justify-center rounded-full border-transparent px-4 py-2 text-sm font-medium tracking-refined text-white transition-all duration-400 hover:-translate-y-0.5 focus:outline-none focus-visible:ring-2 focus-visible:ring-sea disabled:pointer-events-none disabled:opacity-50 dark:focus-visible:ring-accent-blue', variant === 'destructive' ? 'bg-terracotta hover:opacity-90' : 'bg-sea hover:bg-desert'), children: confirmLabel })] })] }) }), document.body);
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
2
|
+
export interface AvatarProps {
|
|
3
|
+
alt?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
fallback?: string;
|
|
6
|
+
size?: AvatarSize;
|
|
7
|
+
src?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function Avatar({ alt, className, fallback, size, src }: AvatarProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export interface AvatarGroupProps {
|
|
11
|
+
avatars: AvatarProps[];
|
|
12
|
+
className?: string;
|
|
13
|
+
max?: number;
|
|
14
|
+
size?: AvatarSize;
|
|
15
|
+
}
|
|
16
|
+
export declare function AvatarGroup({ avatars, className, max, size }: AvatarGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { cn } from '../utils/cn.js';
|
|
4
|
+
const sizeClasses = {
|
|
5
|
+
xs: 'h-6 w-6 text-[10px]',
|
|
6
|
+
sm: 'h-8 w-8 text-xs',
|
|
7
|
+
md: 'h-10 w-10 text-sm',
|
|
8
|
+
lg: 'h-12 w-12 text-base',
|
|
9
|
+
xl: 'h-16 w-16 text-lg'
|
|
10
|
+
};
|
|
11
|
+
function getInitials(fallback) {
|
|
12
|
+
return fallback
|
|
13
|
+
.trim()
|
|
14
|
+
.split(/\s+/)
|
|
15
|
+
.slice(0, 2)
|
|
16
|
+
.map((word) => word[0]?.toUpperCase() ?? '')
|
|
17
|
+
.join('');
|
|
18
|
+
}
|
|
19
|
+
export function Avatar({ alt, className, fallback, size = 'md', src }) {
|
|
20
|
+
const [imgError, setImgError] = React.useState(false);
|
|
21
|
+
const showFallback = !src || imgError;
|
|
22
|
+
const initials = fallback ? getInitials(fallback) : null;
|
|
23
|
+
return (_jsxs("span", { className: cn('relative inline-flex flex-shrink-0 items-center justify-center overflow-hidden rounded-full border border-sand/20 bg-sand/10 dark:border-sand/40 dark:bg-sand/20', sizeClasses[size], className), children: [!showFallback && _jsx("img", { src: src, alt: alt ?? fallback ?? '', className: 'h-full w-full object-cover', onError: () => setImgError(true) }), showFallback && initials ? _jsx("span", { className: 'select-none font-medium text-text-secondary dark:text-text-primary', children: initials }) : null, showFallback && !initials ? (_jsx("svg", { className: 'h-3/5 w-3/5 text-text-secondary dark:text-text-primary', viewBox: '0 0 24 24', fill: 'currentColor', "aria-hidden": 'true', children: _jsx("path", { d: 'M7.5 6a4.5 4.5 0 1 1 9 0 4.5 4.5 0 0 1-9 0ZM3.751 20.105a8.25 8.25 0 0 1 16.498 0 .75.75 0 0 1-.437.695A18.683 18.683 0 0 1 12 22.5c-2.786 0-5.433-.608-7.812-1.7a.75.75 0 0 1-.437-.695Z' }) })) : null] }));
|
|
24
|
+
}
|
|
25
|
+
export function AvatarGroup({ avatars, className, max = 4, size = 'md' }) {
|
|
26
|
+
const visible = avatars.slice(0, max);
|
|
27
|
+
const overflow = avatars.length - max;
|
|
28
|
+
const overflowSizeClasses = {
|
|
29
|
+
xs: 'h-6 w-6 text-[10px]',
|
|
30
|
+
sm: 'h-8 w-8 text-xs',
|
|
31
|
+
md: 'h-10 w-10 text-xs',
|
|
32
|
+
lg: 'h-12 w-12 text-sm',
|
|
33
|
+
xl: 'h-16 w-16 text-base'
|
|
34
|
+
};
|
|
35
|
+
return (_jsxs("div", { className: cn('flex -space-x-2', className), children: [visible.map((avatar, index) => (_jsx(Avatar, { ...avatar, size: size, className: 'ring-2 ring-white dark:ring-dark-sand' }, index))), overflow > 0 && (_jsxs("span", { className: cn('inline-flex flex-shrink-0 items-center justify-center rounded-full border border-sand/20 bg-sand/10 font-medium text-text-secondary ring-2 ring-white dark:border-sand/40 dark:bg-sand/20 dark:text-text-primary dark:ring-dark-sand', overflowSizeClasses[size]), children: ["+", overflow] }))] }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type NavItem, type RenderLink } from './nav-menu';
|
|
3
|
+
export interface BreadcrumbItem extends NavItem {
|
|
4
|
+
href: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}
|
|
7
|
+
export interface BreadcrumbProps {
|
|
8
|
+
className?: string;
|
|
9
|
+
/** Collapse items in the middle when there are more than this many items. 0 = never collapse. */
|
|
10
|
+
collapsedAfter?: number;
|
|
11
|
+
items: BreadcrumbItem[];
|
|
12
|
+
renderLink?: RenderLink<BreadcrumbItem>;
|
|
13
|
+
separator?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export declare function Breadcrumb({ className, collapsedAfter, items, renderLink, separator }: BreadcrumbProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronRight, Ellipsis } from 'lucide-react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { cn } from '../utils/cn.js';
|
|
5
|
+
import { renderDefaultLink } from './nav-menu.js';
|
|
6
|
+
export function Breadcrumb({ className, collapsedAfter = 0, items, renderLink, separator }) {
|
|
7
|
+
const [expanded, setExpanded] = React.useState(false);
|
|
8
|
+
const linkRenderer = renderLink ?? (renderDefaultLink);
|
|
9
|
+
const separatorNode = separator ?? _jsx(ChevronRight, { size: 14, className: 'flex-shrink-0 text-text-secondary', "aria-hidden": 'true' });
|
|
10
|
+
const shouldCollapse = collapsedAfter > 0 && !expanded && items.length > collapsedAfter + 1;
|
|
11
|
+
const visibleItems = shouldCollapse ? [items[0], null, ...items.slice(-(collapsedAfter > 0 ? 1 : items.length))] : items;
|
|
12
|
+
return (_jsx("nav", { "aria-label": 'Breadcrumb', className: cn('flex items-center', className), children: _jsx("ol", { className: 'flex flex-wrap items-center gap-1.5', children: visibleItems.map((item, index) => {
|
|
13
|
+
const isLast = index === visibleItems.length - 1;
|
|
14
|
+
if (item === null) {
|
|
15
|
+
// Collapsed placeholder
|
|
16
|
+
return (_jsxs(React.Fragment, { children: [_jsx("li", { className: 'flex items-center', children: _jsx("button", { type: 'button', onClick: () => setExpanded(true), "aria-label": 'Show full path', className: 'inline-flex h-6 w-6 items-center justify-center rounded-md text-text-secondary transition-colors hover:bg-sand/10 hover:text-text-primary dark:hover:bg-sand/20 dark:hover:text-text-primary', children: _jsx(Ellipsis, { size: 14 }) }) }), _jsx("li", { "aria-hidden": 'true', className: 'flex items-center', children: separatorNode })] }, 'ellipsis'));
|
|
17
|
+
}
|
|
18
|
+
return (_jsxs(React.Fragment, { children: [_jsx("li", { className: 'flex items-center', children: isLast ? (_jsx("span", { "aria-current": 'page', className: 'text-sm font-medium text-text-primary dark:text-text-primary', children: item.label })) : (linkRenderer({
|
|
19
|
+
item,
|
|
20
|
+
className: 'text-sm text-text-secondary transition-colors hover:text-text-primary dark:text-text-secondary dark:hover:text-text-primary',
|
|
21
|
+
children: item.label
|
|
22
|
+
})) }), !isLast && (_jsx("li", { "aria-hidden": 'true', className: 'flex items-center', children: separatorNode }))] }, `${item.href}:${item.label}`));
|
|
23
|
+
}) }) }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface ButtonGroupProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
orientation?: 'horizontal' | 'vertical';
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* ButtonGroup joins multiple Button (or button) elements into a connected
|
|
9
|
+
* strip with shared borders and no gap between items.
|
|
10
|
+
*
|
|
11
|
+
* Place regular <Button> or <button> elements as direct children.
|
|
12
|
+
* The group automatically adjusts border-radius so only the outer
|
|
13
|
+
* corners are rounded.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ButtonGroup({ children, className, orientation }: ButtonGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from '../utils/cn.js';
|
|
3
|
+
/**
|
|
4
|
+
* ButtonGroup joins multiple Button (or button) elements into a connected
|
|
5
|
+
* strip with shared borders and no gap between items.
|
|
6
|
+
*
|
|
7
|
+
* Place regular <Button> or <button> elements as direct children.
|
|
8
|
+
* The group automatically adjusts border-radius so only the outer
|
|
9
|
+
* corners are rounded.
|
|
10
|
+
*/
|
|
11
|
+
export function ButtonGroup({ children, className, orientation = 'horizontal' }) {
|
|
12
|
+
return (_jsx("div", { role: 'group', className: cn('inline-flex', orientation === 'horizontal' ? 'flex-row' : 'flex-col',
|
|
13
|
+
// Collapse inner borders between siblings and remove intermediate radius
|
|
14
|
+
'[&>*]:rounded-none', orientation === 'horizontal'
|
|
15
|
+
? [
|
|
16
|
+
'[&>*:not(:last-child)]:border-r-0',
|
|
17
|
+
'[&>*:first-child]:rounded-l-full',
|
|
18
|
+
'[&>*:last-child]:rounded-r-full',
|
|
19
|
+
// Ensure vertical borders between buttons are visible
|
|
20
|
+
'[&>*:not(:first-child)]:border-l'
|
|
21
|
+
]
|
|
22
|
+
: ['[&>*:not(:last-child)]:border-b-0', '[&>*:first-child]:rounded-t-full', '[&>*:last-child]:rounded-b-full', '[&>*:not(:first-child)]:border-t'], className), children: children }));
|
|
23
|
+
}
|
|
@@ -16,7 +16,7 @@ export function CollectionFilters({ className, currentFilters, currentSort, filt
|
|
|
16
16
|
}
|
|
17
17
|
onFilterChange(nextFilters);
|
|
18
18
|
};
|
|
19
|
-
return (_jsxs("div", { className: cn('mb-6 space-y-4', className), children: [_jsxs("div", { className: 'flex flex-wrap items-center gap-3', children: [_jsxs("button", { type: 'button', onClick: () => setShowFilters((open) => !open), className: 'inline-flex items-center gap-2 rounded-lg border border-sand/30 bg-white px-4 py-2 text-text-primary transition-colors hover:bg-sand/5 dark:border-sand/50 dark:bg-sand/10 dark:text-text-primary dark:hover:bg-sand/20', children: [_jsx(Filter, { size: 18 }), "Filters", activeFilterCount > 0 ? _jsx("span", { className: 'ml-1 rounded-full bg-sea px-2 py-0.5 text-xs text-white dark:bg-accent-blue', children: activeFilterCount }) : null] }), _jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Select, { value: currentSort.field, onChange: (value) => onSortChange({ field: value, order: currentSort.order }), options: sortOptions.map((option) => ({ label: option.label, value: option.field })) }), _jsx("button", { type: 'button', onClick: () => onSortChange({ field: currentSort.field, order: currentSort.order === 'asc' ? 'desc' : 'asc' }), className: 'rounded-lg border border-sand/30 bg-white p-2 text-text-primary transition-colors hover:bg-sand/5 dark:border-sand/50 dark:bg-sand/10 dark:text-text-primary dark:hover:bg-sand/20', title: `Sort ${currentSort.order === 'asc' ? 'Descending' : 'Ascending'}`, children: _jsx(ArrowUpDown, { size: 18, className: currentSort.order === 'desc' ? 'rotate-180' : '' }) })] }), activeFilterCount > 0 ? (_jsxs("button", { type: 'button', onClick: () => onFilterChange({}), className: 'inline-flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-terracotta transition-colors hover:bg-sand/5 dark:hover:bg-sand/10', children: [_jsx(X, { size: 16 }), "Clear all"] })) : null] }), showFilters ? (_jsx("div", { className: 'rounded-lg border border-sand/30 bg-white p-4 dark:border-sand/50 dark:bg-sand/10', children: _jsx("div", { className: 'grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3', children: filterOptions.map((option) => (_jsxs("div", { className: 'space-y-2', children: [_jsx("label", { className: 'block text-sm font-medium text-text-primary dark:text-text-primary', children: option.label }), option.type === 'select' && option.options ? (_jsx(Select, { value: currentFilters[option.field] || '', onChange: (value) => handleFilterChange(option.field, value), options: [{ label: 'All', value: '' }, ...option.options] })) : null, option.type === 'boolean' ? (_jsx(Select, { value: currentFilters[option.field] === undefined ? '' : String(currentFilters[option.field]), onChange: (value) => handleFilterChange(option.field, value === '' ? null : value === 'true'), options: [
|
|
19
|
+
return (_jsxs("div", { className: cn('mb-6 space-y-4', className), children: [_jsxs("div", { className: 'flex flex-wrap items-center gap-3', children: [_jsxs("button", { type: 'button', onClick: () => setShowFilters((open) => !open), className: 'inline-flex items-center gap-2 rounded-lg border border-sand/30 bg-white px-4 py-2 text-text-primary transition-colors hover:bg-sand/5 dark:border-sand/50 dark:bg-sand/10 dark:text-text-primary dark:hover:bg-sand/20', children: [_jsx(Filter, { size: 18 }), "Filters", activeFilterCount > 0 ? (_jsx("span", { className: 'ml-1 rounded-full bg-sea px-2 py-0.5 text-xs text-white dark:bg-accent-blue', children: activeFilterCount })) : null] }), _jsxs("div", { className: 'flex items-center gap-2', children: [_jsx(Select, { value: currentSort.field, onChange: (value) => onSortChange({ field: value, order: currentSort.order }), options: sortOptions.map((option) => ({ label: option.label, value: option.field })) }), _jsx("button", { type: 'button', onClick: () => onSortChange({ field: currentSort.field, order: currentSort.order === 'asc' ? 'desc' : 'asc' }), className: 'rounded-lg border border-sand/30 bg-white p-2 text-text-primary transition-colors hover:bg-sand/5 dark:border-sand/50 dark:bg-sand/10 dark:text-text-primary dark:hover:bg-sand/20', title: `Sort ${currentSort.order === 'asc' ? 'Descending' : 'Ascending'}`, children: _jsx(ArrowUpDown, { size: 18, className: currentSort.order === 'desc' ? 'rotate-180' : '' }) })] }), activeFilterCount > 0 ? (_jsxs("button", { type: 'button', onClick: () => onFilterChange({}), className: 'inline-flex items-center gap-2 rounded-lg px-3 py-2 text-sm text-terracotta transition-colors hover:bg-sand/5 dark:hover:bg-sand/10', children: [_jsx(X, { size: 16 }), "Clear all"] })) : null] }), showFilters ? (_jsx("div", { className: 'rounded-lg border border-sand/30 bg-white p-4 dark:border-sand/50 dark:bg-sand/10', children: _jsx("div", { className: 'grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3', children: filterOptions.map((option) => (_jsxs("div", { className: 'space-y-2', children: [_jsx("label", { className: 'block text-sm font-medium text-text-primary dark:text-text-primary', children: option.label }), option.type === 'select' && option.options ? (_jsx(Select, { value: currentFilters[option.field] || '', onChange: (value) => handleFilterChange(option.field, value), options: [{ label: 'All', value: '' }, ...option.options] })) : null, option.type === 'boolean' ? (_jsx(Select, { value: currentFilters[option.field] === undefined ? '' : String(currentFilters[option.field]), onChange: (value) => handleFilterChange(option.field, value === '' ? null : value === 'true'), options: [
|
|
20
20
|
{ label: 'All', value: '' },
|
|
21
21
|
{ label: 'Yes', value: 'true' },
|
|
22
22
|
{ label: 'No', value: 'false' }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface CommandSpotlightAction {
|
|
3
|
+
description?: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
external?: boolean;
|
|
6
|
+
group?: string;
|
|
7
|
+
href?: string;
|
|
8
|
+
icon?: React.ReactNode;
|
|
9
|
+
id: string;
|
|
10
|
+
keywords?: string[];
|
|
11
|
+
shortcut?: string[];
|
|
12
|
+
title: string;
|
|
13
|
+
onSelect?: () => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export interface CommandSpotlightProps {
|
|
16
|
+
actions: CommandSpotlightAction[];
|
|
17
|
+
className?: string;
|
|
18
|
+
dialogClassName?: string;
|
|
19
|
+
emptyMessage?: string;
|
|
20
|
+
hotkey?: string;
|
|
21
|
+
onActionSelect?: (action: CommandSpotlightAction) => void;
|
|
22
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
23
|
+
open?: boolean;
|
|
24
|
+
overlayClassName?: string;
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
showTrigger?: boolean;
|
|
27
|
+
triggerClassName?: string;
|
|
28
|
+
triggerLabel?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare function CommandSpotlight({ actions, className, dialogClassName, emptyMessage, hotkey, onActionSelect, onOpenChange, open, overlayClassName, placeholder, showTrigger, triggerClassName, triggerLabel }: CommandSpotlightProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Search } from 'lucide-react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { Kbd } from './kbd.js';
|
|
6
|
+
import { cn } from '../utils/cn.js';
|
|
7
|
+
const DEFAULT_GROUP = 'Actions';
|
|
8
|
+
function normalize(text) {
|
|
9
|
+
return text.trim().toLowerCase();
|
|
10
|
+
}
|
|
11
|
+
function isEditableTarget(target) {
|
|
12
|
+
if (!(target instanceof HTMLElement)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (target.isContentEditable) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
const tagName = target.tagName;
|
|
19
|
+
return tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT';
|
|
20
|
+
}
|
|
21
|
+
export function CommandSpotlight({ actions, className, dialogClassName, emptyMessage = 'No matching commands.', hotkey = 'k', onActionSelect, onOpenChange, open, overlayClassName, placeholder = 'Search commands...', showTrigger = true, triggerClassName, triggerLabel = 'Search' }) {
|
|
22
|
+
const [isOpenInternal, setIsOpenInternal] = React.useState(false);
|
|
23
|
+
const [query, setQuery] = React.useState('');
|
|
24
|
+
const [selectedActionId, setSelectedActionId] = React.useState(null);
|
|
25
|
+
const [isMacLike, setIsMacLike] = React.useState(false);
|
|
26
|
+
const inputRef = React.useRef(null);
|
|
27
|
+
const actionRefs = React.useRef({});
|
|
28
|
+
const isControlled = typeof open === 'boolean';
|
|
29
|
+
const isOpen = isControlled ? open : isOpenInternal;
|
|
30
|
+
const setIsOpen = React.useCallback((nextIsOpen) => {
|
|
31
|
+
if (!isControlled) {
|
|
32
|
+
setIsOpenInternal(nextIsOpen);
|
|
33
|
+
}
|
|
34
|
+
onOpenChange?.(nextIsOpen);
|
|
35
|
+
}, [isControlled, onOpenChange]);
|
|
36
|
+
const filteredActions = React.useMemo(() => {
|
|
37
|
+
const normalizedQuery = normalize(query);
|
|
38
|
+
if (!normalizedQuery) {
|
|
39
|
+
return actions;
|
|
40
|
+
}
|
|
41
|
+
return actions.filter((action) => {
|
|
42
|
+
const haystack = normalize([
|
|
43
|
+
action.title,
|
|
44
|
+
action.description || '',
|
|
45
|
+
action.group || '',
|
|
46
|
+
...(action.keywords || []),
|
|
47
|
+
action.href || ''
|
|
48
|
+
].join(' '));
|
|
49
|
+
return haystack.includes(normalizedQuery);
|
|
50
|
+
});
|
|
51
|
+
}, [actions, query]);
|
|
52
|
+
const selectableActionIds = React.useMemo(() => filteredActions.filter((action) => !action.disabled).map((action) => action.id), [filteredActions]);
|
|
53
|
+
const groupedActions = React.useMemo(() => {
|
|
54
|
+
const groups = new Map();
|
|
55
|
+
filteredActions.forEach((action) => {
|
|
56
|
+
const group = action.group?.trim() || DEFAULT_GROUP;
|
|
57
|
+
const existing = groups.get(group);
|
|
58
|
+
if (existing) {
|
|
59
|
+
existing.push(action);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
groups.set(group, [action]);
|
|
63
|
+
});
|
|
64
|
+
return Array.from(groups.entries());
|
|
65
|
+
}, [filteredActions]);
|
|
66
|
+
const closeSpotlight = React.useCallback(() => {
|
|
67
|
+
setIsOpen(false);
|
|
68
|
+
setQuery('');
|
|
69
|
+
}, [setIsOpen]);
|
|
70
|
+
const moveSelection = React.useCallback((direction) => {
|
|
71
|
+
if (selectableActionIds.length === 0) {
|
|
72
|
+
setSelectedActionId(null);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const currentIndex = selectedActionId ? selectableActionIds.indexOf(selectedActionId) : -1;
|
|
76
|
+
const nextIndex = currentIndex < 0 ? 0 : (currentIndex + direction + selectableActionIds.length) % selectableActionIds.length;
|
|
77
|
+
setSelectedActionId(selectableActionIds[nextIndex]);
|
|
78
|
+
}, [selectableActionIds, selectedActionId]);
|
|
79
|
+
const runAction = React.useCallback((action) => {
|
|
80
|
+
if (action.disabled) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
onActionSelect?.(action);
|
|
84
|
+
if (action.onSelect) {
|
|
85
|
+
try {
|
|
86
|
+
const result = action.onSelect();
|
|
87
|
+
if (result && typeof result.then === 'function') {
|
|
88
|
+
void result.catch((error) => {
|
|
89
|
+
console.error('Command spotlight action failed:', error);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error('Command spotlight action failed:', error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else if (action.href && typeof window !== 'undefined') {
|
|
98
|
+
if (action.external) {
|
|
99
|
+
window.open(action.href, '_blank', 'noopener,noreferrer');
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
window.location.assign(action.href);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
closeSpotlight();
|
|
106
|
+
}, [closeSpotlight, onActionSelect]);
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (typeof navigator === 'undefined') {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
setIsMacLike(/mac|iphone|ipad|ipod/i.test(navigator.platform));
|
|
112
|
+
}, []);
|
|
113
|
+
React.useEffect(() => {
|
|
114
|
+
if (!isOpen) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const timeout = window.setTimeout(() => {
|
|
118
|
+
inputRef.current?.focus();
|
|
119
|
+
}, 0);
|
|
120
|
+
return () => {
|
|
121
|
+
window.clearTimeout(timeout);
|
|
122
|
+
};
|
|
123
|
+
}, [isOpen]);
|
|
124
|
+
React.useEffect(() => {
|
|
125
|
+
if (!isOpen) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
setSelectedActionId((currentSelectedActionId) => {
|
|
129
|
+
if (currentSelectedActionId && selectableActionIds.includes(currentSelectedActionId)) {
|
|
130
|
+
return currentSelectedActionId;
|
|
131
|
+
}
|
|
132
|
+
return selectableActionIds[0] ?? null;
|
|
133
|
+
});
|
|
134
|
+
}, [isOpen, selectableActionIds]);
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
if (!isOpen || !selectedActionId) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
actionRefs.current[selectedActionId]?.scrollIntoView({ block: 'nearest' });
|
|
140
|
+
}, [isOpen, selectedActionId]);
|
|
141
|
+
React.useEffect(() => {
|
|
142
|
+
if (typeof window === 'undefined') {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const normalizedHotkey = hotkey.toLowerCase();
|
|
146
|
+
const handleWindowKeyDown = (event) => {
|
|
147
|
+
const pressedKey = event.key.toLowerCase();
|
|
148
|
+
if ((event.metaKey || event.ctrlKey) && pressedKey === normalizedHotkey) {
|
|
149
|
+
if (!isOpen && isEditableTarget(event.target)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
const nextIsOpen = !isOpen;
|
|
154
|
+
setIsOpen(nextIsOpen);
|
|
155
|
+
if (!nextIsOpen) {
|
|
156
|
+
setQuery('');
|
|
157
|
+
}
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (!isOpen || pressedKey !== 'escape') {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
closeSpotlight();
|
|
165
|
+
};
|
|
166
|
+
window.addEventListener('keydown', handleWindowKeyDown);
|
|
167
|
+
return () => {
|
|
168
|
+
window.removeEventListener('keydown', handleWindowKeyDown);
|
|
169
|
+
};
|
|
170
|
+
}, [closeSpotlight, hotkey, isOpen, setIsOpen]);
|
|
171
|
+
const hotkeyHint = React.useMemo(() => {
|
|
172
|
+
const modifier = isMacLike ? '⌘' : 'Ctrl';
|
|
173
|
+
return [modifier, hotkey.toUpperCase()];
|
|
174
|
+
}, [hotkey, isMacLike]);
|
|
175
|
+
const renderTrigger = showTrigger ? (_jsxs("button", { type: 'button', onClick: () => {
|
|
176
|
+
setIsOpen(true);
|
|
177
|
+
}, className: cn('inline-flex items-center gap-2 rounded-full border border-sand/20 bg-white/35 px-3 py-1.5 text-sm text-text-primary shadow-sm backdrop-blur-md transition-colors duration-200 hover:bg-white/65 dark:border-sand/70 dark:bg-sand/25 dark:hover:bg-sand/35', triggerClassName), "aria-label": 'Open command spotlight', children: [_jsx(Search, { size: 15, className: 'text-text-secondary dark:text-text-secondary' }), _jsx("span", { className: 'hidden sm:inline', children: triggerLabel }), _jsx(Kbd, { keys: hotkeyHint, className: 'hidden sm:inline-flex' })] })) : null;
|
|
178
|
+
const renderOverlay = isOpen && typeof document !== 'undefined'
|
|
179
|
+
? createPortal(_jsxs("div", { className: cn('fixed inset-0 z-[9999] flex items-start justify-center px-4 pt-[12vh]', overlayClassName), children: [_jsx("button", { type: 'button', onClick: closeSpotlight, className: 'absolute inset-0 bg-black/45 backdrop-blur-sm', "aria-label": 'Close command spotlight' }), _jsxs("div", { role: 'dialog', "aria-modal": 'true', className: cn('relative z-10 w-full max-w-2xl overflow-hidden rounded-[28px] border border-sand/10 bg-white/95 text-text-primary shadow-2xl backdrop-blur-xl dark:border-sand/20 dark:bg-dark-sand/95 dark:text-text-primary', dialogClassName), onClick: (event) => event.stopPropagation(), children: [_jsxs("div", { className: 'flex items-center gap-3 border-b border-sand/15 px-4 py-3 dark:border-sand/20', children: [_jsx(Search, { size: 18, className: 'flex-shrink-0 text-text-secondary dark:text-text-secondary' }), _jsx("input", { ref: inputRef, type: 'text', value: query, onChange: (event) => setQuery(event.target.value), onKeyDown: (event) => {
|
|
180
|
+
if (event.key === 'ArrowDown') {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
moveSelection(1);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (event.key === 'ArrowUp') {
|
|
186
|
+
event.preventDefault();
|
|
187
|
+
moveSelection(-1);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (event.key === 'Enter') {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
if (!selectedActionId) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const selectedAction = filteredActions.find((action) => action.id === selectedActionId);
|
|
196
|
+
if (selectedAction) {
|
|
197
|
+
runAction(selectedAction);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}, placeholder: placeholder, className: 'w-full bg-transparent text-base text-text-primary outline-none placeholder:text-text-secondary dark:text-text-primary dark:placeholder:text-text-secondary' }), _jsx(Kbd, { keys: hotkeyHint })] }), _jsx("div", { className: 'max-h-[55vh] overflow-y-auto p-2', children: groupedActions.length === 0 ? (_jsx("p", { className: 'px-3 py-12 text-center text-sm text-text-secondary dark:text-text-secondary', children: emptyMessage })) : (groupedActions.map(([group, groupActions]) => (_jsxs("section", { className: 'mb-3 last:mb-0', children: [_jsx("p", { className: 'px-3 pb-1 text-[11px] font-semibold uppercase tracking-wider text-text-secondary dark:text-text-secondary', children: group }), _jsx("div", { className: 'space-y-1', children: groupActions.map((action) => {
|
|
201
|
+
const isSelected = action.id === selectedActionId;
|
|
202
|
+
return (_jsxs("button", { type: 'button', ref: (element) => {
|
|
203
|
+
actionRefs.current[action.id] = element;
|
|
204
|
+
}, disabled: action.disabled, onClick: () => runAction(action), onMouseEnter: () => {
|
|
205
|
+
if (!action.disabled) {
|
|
206
|
+
setSelectedActionId(action.id);
|
|
207
|
+
}
|
|
208
|
+
}, className: cn('flex w-full items-center justify-between gap-3 rounded-xl px-3 py-2.5 text-left transition-colors', isSelected
|
|
209
|
+
? 'bg-sea/10 text-sea dark:bg-accent-blue/15 dark:text-accent-blue'
|
|
210
|
+
: 'text-text-primary hover:bg-sand/10 dark:text-text-primary dark:hover:bg-sand/15', action.disabled && 'cursor-not-allowed opacity-40'), children: [_jsxs("div", { className: 'flex min-w-0 items-center gap-3', children: [action.icon ? (_jsx("span", { className: 'flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full bg-sand/10 text-text-secondary dark:bg-sand/20 dark:text-text-secondary', children: action.icon })) : null, _jsxs("div", { className: 'min-w-0', children: [_jsx("p", { className: 'truncate text-sm font-medium', children: action.title }), action.description ? (_jsx("p", { className: 'truncate text-xs text-text-secondary dark:text-text-secondary', children: action.description })) : null] })] }), action.shortcut && action.shortcut.length > 0 ? _jsx(Kbd, { keys: action.shortcut }) : null] }, action.id));
|
|
211
|
+
}) })] }, group)))) })] })] }), document.body)
|
|
212
|
+
: null;
|
|
213
|
+
return (_jsxs("div", { className: className, children: [renderTrigger, renderOverlay] }));
|
|
214
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface CalendarProps {
|
|
2
|
+
className?: string;
|
|
3
|
+
disabled?: (date: Date) => boolean;
|
|
4
|
+
maxDate?: Date;
|
|
5
|
+
minDate?: Date;
|
|
6
|
+
onChange?: (date: Date) => void;
|
|
7
|
+
value?: Date | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function Calendar({ className, disabled: isDisabledFn, maxDate, minDate, onChange, value }: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export interface DatePickerProps {
|
|
11
|
+
className?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
disabledDates?: (date: Date) => boolean;
|
|
14
|
+
maxDate?: Date;
|
|
15
|
+
minDate?: Date;
|
|
16
|
+
onChange?: (date: Date | null) => void;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
value?: Date | null;
|
|
19
|
+
}
|
|
20
|
+
export declare function DatePicker({ className, disabled, disabledDates, maxDate, minDate, onChange, placeholder, value }: DatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CalendarDays, ChevronLeft, ChevronRight } from 'lucide-react';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { cn } from '../utils/cn.js';
|
|
5
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
6
|
+
function getDaysInMonth(year, month) {
|
|
7
|
+
return new Date(year, month + 1, 0).getDate();
|
|
8
|
+
}
|
|
9
|
+
function getFirstDayOfMonth(year, month) {
|
|
10
|
+
return new Date(year, month, 1).getDay();
|
|
11
|
+
}
|
|
12
|
+
function isSameDay(a, b) {
|
|
13
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
14
|
+
}
|
|
15
|
+
function isToday(date) {
|
|
16
|
+
return isSameDay(date, new Date());
|
|
17
|
+
}
|
|
18
|
+
const MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
19
|
+
const DAYS = ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
20
|
+
function formatDate(date) {
|
|
21
|
+
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
|
|
22
|
+
}
|
|
23
|
+
export function Calendar({ className, disabled: isDisabledFn, maxDate, minDate, onChange, value }) {
|
|
24
|
+
const today = new Date();
|
|
25
|
+
const [viewYear, setViewYear] = React.useState(value?.getFullYear() ?? today.getFullYear());
|
|
26
|
+
const [viewMonth, setViewMonth] = React.useState(value?.getMonth() ?? today.getMonth());
|
|
27
|
+
const days = getDaysInMonth(viewYear, viewMonth);
|
|
28
|
+
const firstDay = getFirstDayOfMonth(viewYear, viewMonth);
|
|
29
|
+
const prevMonth = () => {
|
|
30
|
+
if (viewMonth === 0) {
|
|
31
|
+
setViewMonth(11);
|
|
32
|
+
setViewYear((y) => y - 1);
|
|
33
|
+
}
|
|
34
|
+
else
|
|
35
|
+
setViewMonth((m) => m - 1);
|
|
36
|
+
};
|
|
37
|
+
const nextMonth = () => {
|
|
38
|
+
if (viewMonth === 11) {
|
|
39
|
+
setViewMonth(0);
|
|
40
|
+
setViewYear((y) => y + 1);
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
setViewMonth((m) => m + 1);
|
|
44
|
+
};
|
|
45
|
+
const cells = [...Array(firstDay).fill(null), ...Array.from({ length: days }, (_, i) => new Date(viewYear, viewMonth, i + 1))];
|
|
46
|
+
const isOutOfRange = (date) => {
|
|
47
|
+
if (minDate && date < minDate)
|
|
48
|
+
return true;
|
|
49
|
+
if (maxDate && date > maxDate)
|
|
50
|
+
return true;
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
53
|
+
return (_jsxs("div", { className: cn('w-full select-none', className), children: [_jsxs("div", { className: 'mb-4 flex items-center justify-between', children: [_jsx("button", { type: 'button', onClick: prevMonth, className: 'rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-sand/10 hover:text-text-primary dark:hover:bg-sand/20 dark:hover:text-text-primary', "aria-label": 'Previous month', children: _jsx(ChevronLeft, { size: 16 }) }), _jsxs("span", { className: 'text-sm font-semibold text-text-primary dark:text-text-primary', children: [MONTHS[viewMonth], " ", viewYear] }), _jsx("button", { type: 'button', onClick: nextMonth, className: 'rounded-lg p-1.5 text-text-secondary transition-colors hover:bg-sand/10 hover:text-text-primary dark:hover:bg-sand/20 dark:hover:text-text-primary', "aria-label": 'Next month', children: _jsx(ChevronRight, { size: 16 }) })] }), _jsx("div", { className: 'mb-1 grid grid-cols-7', children: DAYS.map((d) => (_jsx("div", { className: 'flex h-8 items-center justify-center text-[11px] font-medium uppercase tracking-wider text-text-secondary dark:text-text-secondary', children: d }, d))) }), _jsx("div", { className: 'grid grid-cols-7 gap-y-0.5', children: cells.map((date, index) => {
|
|
54
|
+
if (!date)
|
|
55
|
+
return _jsx("div", {}, `empty-${index}`);
|
|
56
|
+
const selected = value && isSameDay(date, value);
|
|
57
|
+
const todayCell = isToday(date);
|
|
58
|
+
const outOfRange = isOutOfRange(date);
|
|
59
|
+
const disabled = outOfRange || isDisabledFn?.(date);
|
|
60
|
+
return (_jsx("button", { type: 'button', disabled: !!disabled, onClick: () => onChange?.(date), "aria-label": date.toDateString(), "aria-pressed": !!selected, className: cn('flex h-8 w-full items-center justify-center rounded-full text-sm transition-colors duration-150 focus:outline-none focus-visible:ring-2 focus-visible:ring-sea dark:focus-visible:ring-accent-blue', selected
|
|
61
|
+
? 'bg-sea font-semibold text-white dark:bg-accent-blue'
|
|
62
|
+
: todayCell
|
|
63
|
+
? 'font-semibold text-sea ring-1 ring-inset ring-sea dark:text-accent-blue dark:ring-accent-blue'
|
|
64
|
+
: 'text-text-primary hover:bg-sand/10 dark:text-text-primary dark:hover:bg-sand/15', disabled && 'pointer-events-none opacity-30'), children: date.getDate() }, date.toISOString()));
|
|
65
|
+
}) })] }));
|
|
66
|
+
}
|
|
67
|
+
export function DatePicker({ className, disabled = false, disabledDates, maxDate, minDate, onChange, placeholder = 'Pick a date', value }) {
|
|
68
|
+
const [open, setOpen] = React.useState(false);
|
|
69
|
+
const containerRef = React.useRef(null);
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (!open)
|
|
72
|
+
return;
|
|
73
|
+
const handler = (e) => {
|
|
74
|
+
if (!containerRef.current?.contains(e.target))
|
|
75
|
+
setOpen(false);
|
|
76
|
+
};
|
|
77
|
+
document.addEventListener('pointerdown', handler);
|
|
78
|
+
return () => document.removeEventListener('pointerdown', handler);
|
|
79
|
+
}, [open]);
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (!open)
|
|
82
|
+
return;
|
|
83
|
+
const handler = (e) => {
|
|
84
|
+
if (e.key === 'Escape')
|
|
85
|
+
setOpen(false);
|
|
86
|
+
};
|
|
87
|
+
document.addEventListener('keydown', handler);
|
|
88
|
+
return () => document.removeEventListener('keydown', handler);
|
|
89
|
+
}, [open]);
|
|
90
|
+
return (_jsxs("div", { ref: containerRef, className: cn('relative inline-block', className), children: [_jsxs("button", { type: 'button', disabled: disabled, onClick: () => !disabled && setOpen((v) => !v), "aria-haspopup": 'dialog', "aria-expanded": open, className: cn('flex h-10 min-w-[200px] items-center gap-2 rounded-[18px] border bg-white px-4 text-sm transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-sea dark:bg-dark-sand dark:focus:ring-accent-blue', open ? 'border-sea ring-2 ring-sea/20 dark:border-accent-blue dark:ring-accent-blue/20' : 'border-sand/30 hover:border-sand/50 dark:border-sand/50', value ? 'text-text-primary dark:text-text-primary' : 'text-text-secondary dark:text-text-secondary', disabled && 'cursor-not-allowed opacity-50'), children: [_jsx(CalendarDays, { size: 15, className: 'flex-shrink-0 text-text-secondary' }), _jsx("span", { className: 'flex-1 text-left', children: value ? formatDate(value) : placeholder })] }), open && (_jsxs("div", { role: 'dialog', "aria-label": 'Date picker', className: 'absolute left-0 top-full z-50 mt-1.5 w-72 rounded-2xl border border-sand/10 bg-white p-4 shadow-xl dark:border-sand/20 dark:bg-dark-sand', children: [_jsx(Calendar, { value: value, minDate: minDate, maxDate: maxDate, disabled: disabledDates, onChange: (date) => {
|
|
91
|
+
onChange?.(date);
|
|
92
|
+
setOpen(false);
|
|
93
|
+
} }), value && (_jsx("button", { type: 'button', onClick: () => {
|
|
94
|
+
onChange?.(null);
|
|
95
|
+
setOpen(false);
|
|
96
|
+
}, className: 'mt-3 w-full rounded-lg py-1.5 text-xs text-text-secondary transition-colors hover:bg-sand/10 hover:text-text-primary dark:hover:bg-sand/15 dark:hover:text-text-primary', children: "Clear date" }))] }))] }));
|
|
97
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface DrawerProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
snapPoints?: string[];
|
|
9
|
+
title?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function Drawer({ children, className, description, isOpen, onClose, title }: DrawerProps): React.ReactPortal | null;
|