Spaces:
Running
Running
feat: improve accessibility and UX with focus management, fullscreen fallback, and mobile-responsive enhancements
Browse files- src/app/page.tsx +22 -6
- src/components/MapLegend.tsx +1 -1
- src/components/MobileDrawer.tsx +52 -1
- src/components/Table.tsx +38 -2
src/app/page.tsx
CHANGED
|
@@ -261,6 +261,14 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 261 |
}, []);
|
| 262 |
|
| 263 |
const toggleFullscreen = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
if (!document.fullscreenElement) {
|
| 265 |
document.documentElement.requestFullscreen().catch((err) => {
|
| 266 |
console.warn(`Error attempting to enable fullscreen: ${err.message}`);
|
|
@@ -1003,7 +1011,10 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1003 |
</MobileDrawer>
|
| 1004 |
|
| 1005 |
{/* Main View Shell Container */}
|
| 1006 |
-
<main
|
|
|
|
|
|
|
|
|
|
| 1007 |
{/* Floating pill navigation */}
|
| 1008 |
<header className="absolute left-1/2 top-3 z-30 -translate-x-1/2 flex max-w-[calc(100%-1rem)] items-center gap-1 rounded-2xl border border-slate-700/50 bg-slate-800/60 p-1.5 shadow-sm backdrop-blur-md md:border-slate-200/50 md:bg-white/90">
|
| 1009 |
{/* Mobile Menu Button */}
|
|
@@ -1048,6 +1059,8 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1048 |
<button
|
| 1049 |
key={tab.id}
|
| 1050 |
onClick={() => switchTab(tab.id)}
|
|
|
|
|
|
|
| 1051 |
className={`flex items-center gap-2 px-4 py-2 min-h-12 rounded-xl text-sm font-bold transition-all cursor-pointer ${
|
| 1052 |
isActive
|
| 1053 |
? "bg-white/20 text-white md:bg-blue-100 md:text-blue-700 shadow-sm"
|
|
@@ -1061,12 +1074,14 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1061 |
})}
|
| 1062 |
</div>
|
| 1063 |
|
| 1064 |
-
<div className="
|
| 1065 |
<div className="w-px h-6 bg-slate-200 mx-1" />
|
| 1066 |
-
<Tooltip content="
|
| 1067 |
<button
|
|
|
|
| 1068 |
onClick={toggleFullscreen}
|
| 1069 |
-
|
|
|
|
| 1070 |
>
|
| 1071 |
{isFullscreen ? <Minimize size={18} /> : <Maximize size={18} />}
|
| 1072 |
</button>
|
|
@@ -1109,7 +1124,7 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1109 |
</div>
|
| 1110 |
|
| 1111 |
{/* Tab: Stations Info table — always mounted, hidden when inactive */}
|
| 1112 |
-
<div className="w-full h-full flex flex-col gap-4 p-1 pt-
|
| 1113 |
{isLoadingStations ? (
|
| 1114 |
<div className="flex-grow flex flex-col items-center justify-center gap-3">
|
| 1115 |
<div className="w-10 h-10 border-4 border-blue-500 border-t-transparent rounded-full animate-spin" />
|
|
@@ -1132,6 +1147,7 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1132 |
onRowDoubleClick={handleStationDoubleClick}
|
| 1133 |
searchPlaceholder="Search stations by name or WIGOS ID..."
|
| 1134 |
searchKey="name"
|
|
|
|
| 1135 |
/>
|
| 1136 |
</div>
|
| 1137 |
</>
|
|
@@ -1139,7 +1155,7 @@ function EuroMeteoApp({ initialUrlState }: { initialUrlState: InitialUrlState })
|
|
| 1139 |
</div>
|
| 1140 |
|
| 1141 |
{/* Tab: Dashboard charts & raw logs — always mounted, hidden when inactive */}
|
| 1142 |
-
<div ref={dashboardScrollRef} className="w-full h-full overflow-y-auto custom-scrollbar flex flex-col gap-4 sm:gap-6 pr-1 pb-2 sm:pb-6 p-1 pt-
|
| 1143 |
{isLoadingStations ? (
|
| 1144 |
<div className="flex-grow flex flex-col items-center justify-center gap-3">
|
| 1145 |
<div className="w-10 h-10 border-4 border-blue-500 border-t-transparent rounded-full animate-spin" />
|
|
|
|
| 261 |
}, []);
|
| 262 |
|
| 263 |
const toggleFullscreen = () => {
|
| 264 |
+
const canFullscreen = Boolean(document.fullscreenEnabled && document.documentElement.requestFullscreen);
|
| 265 |
+
if (!canFullscreen) {
|
| 266 |
+
const directUrl = new URL(window.location.href);
|
| 267 |
+
directUrl.searchParams.delete("embed");
|
| 268 |
+
window.open(directUrl.toString(), "_blank", "noopener,noreferrer");
|
| 269 |
+
return;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
if (!document.fullscreenElement) {
|
| 273 |
document.documentElement.requestFullscreen().catch((err) => {
|
| 274 |
console.warn(`Error attempting to enable fullscreen: ${err.message}`);
|
|
|
|
| 1011 |
</MobileDrawer>
|
| 1012 |
|
| 1013 |
{/* Main View Shell Container */}
|
| 1014 |
+
<main
|
| 1015 |
+
className="flex-1 h-full flex flex-col min-w-0 relative bg-slate-50 transition-all"
|
| 1016 |
+
inert={sidebarOpen ? true : undefined}
|
| 1017 |
+
>
|
| 1018 |
{/* Floating pill navigation */}
|
| 1019 |
<header className="absolute left-1/2 top-3 z-30 -translate-x-1/2 flex max-w-[calc(100%-1rem)] items-center gap-1 rounded-2xl border border-slate-700/50 bg-slate-800/60 p-1.5 shadow-sm backdrop-blur-md md:border-slate-200/50 md:bg-white/90">
|
| 1020 |
{/* Mobile Menu Button */}
|
|
|
|
| 1059 |
<button
|
| 1060 |
key={tab.id}
|
| 1061 |
onClick={() => switchTab(tab.id)}
|
| 1062 |
+
aria-label={tab.label}
|
| 1063 |
+
aria-pressed={isActive}
|
| 1064 |
className={`flex items-center gap-2 px-4 py-2 min-h-12 rounded-xl text-sm font-bold transition-all cursor-pointer ${
|
| 1065 |
isActive
|
| 1066 |
? "bg-white/20 text-white md:bg-blue-100 md:text-blue-700 shadow-sm"
|
|
|
|
| 1074 |
})}
|
| 1075 |
</div>
|
| 1076 |
|
| 1077 |
+
<div className="flex items-center gap-1">
|
| 1078 |
<div className="w-px h-6 bg-slate-200 mx-1" />
|
| 1079 |
+
<Tooltip content={isFullscreen ? "Exit fullscreen" : "View full screen or open in a new tab"} position="bottom">
|
| 1080 |
<button
|
| 1081 |
+
type="button"
|
| 1082 |
onClick={toggleFullscreen}
|
| 1083 |
+
aria-label={isFullscreen ? "Exit fullscreen" : "View full screen or open in a new tab"}
|
| 1084 |
+
className="text-slate-300 md:text-slate-400 hover:text-white md:hover:text-slate-700 hover:bg-white/10 md:hover:bg-slate-50 rounded-xl transition-colors cursor-pointer min-w-[36px] min-h-[36px] flex items-center justify-center"
|
| 1085 |
>
|
| 1086 |
{isFullscreen ? <Minimize size={18} /> : <Maximize size={18} />}
|
| 1087 |
</button>
|
|
|
|
| 1124 |
</div>
|
| 1125 |
|
| 1126 |
{/* Tab: Stations Info table — always mounted, hidden when inactive */}
|
| 1127 |
+
<div className="w-full h-full flex flex-col gap-4 p-1 pt-20 md:p-6 md:pt-20" style={{ display: activeTab === "stations" ? "flex" : "none" }}>
|
| 1128 |
{isLoadingStations ? (
|
| 1129 |
<div className="flex-grow flex flex-col items-center justify-center gap-3">
|
| 1130 |
<div className="w-10 h-10 border-4 border-blue-500 border-t-transparent rounded-full animate-spin" />
|
|
|
|
| 1147 |
onRowDoubleClick={handleStationDoubleClick}
|
| 1148 |
searchPlaceholder="Search stations by name or WIGOS ID..."
|
| 1149 |
searchKey="name"
|
| 1150 |
+
mobileLayout="cards"
|
| 1151 |
/>
|
| 1152 |
</div>
|
| 1153 |
</>
|
|
|
|
| 1155 |
</div>
|
| 1156 |
|
| 1157 |
{/* Tab: Dashboard charts & raw logs — always mounted, hidden when inactive */}
|
| 1158 |
+
<div ref={dashboardScrollRef} className="w-full h-full overflow-y-auto custom-scrollbar flex flex-col gap-4 sm:gap-6 pr-1 pb-2 sm:pb-6 p-1 pt-20 md:p-6 md:pt-20" style={{ display: activeTab === "dashboard" ? "flex" : "none" }}>
|
| 1159 |
{isLoadingStations ? (
|
| 1160 |
<div className="flex-grow flex flex-col items-center justify-center gap-3">
|
| 1161 |
<div className="w-10 h-10 border-4 border-blue-500 border-t-transparent rounded-full animate-spin" />
|
src/components/MapLegend.tsx
CHANGED
|
@@ -60,7 +60,7 @@ export const MapLegend: React.FC<MapLegendProps> = ({ parameter, values }) => {
|
|
| 60 |
const isTemperature = parameter.includes("temperature");
|
| 61 |
|
| 62 |
return (
|
| 63 |
-
<div className="flex absolute bottom-
|
| 64 |
<div className="font-bold text-slate-300 md:text-slate-700 text-center text-xs md:text-sm border-b border-white/20 md:border-slate-200 pb-1.5 md:pb-2 mb-1.5 md:mb-2 shrink-0">
|
| 65 |
{unit}
|
| 66 |
</div>
|
|
|
|
| 60 |
const isTemperature = parameter.includes("temperature");
|
| 61 |
|
| 62 |
return (
|
| 63 |
+
<div className="flex absolute bottom-24 right-2 md:bottom-6 md:right-2.5 bg-slate-800/80 md:bg-white/90 backdrop-blur-md p-2 md:p-3 rounded-xl shadow-lg border border-white/20 md:border-slate-200 z-10 font-sans text-xs flex-col text-white md:text-inherit overflow-hidden" style={{ maxHeight: 'calc(100% - 240px)' }}>
|
| 64 |
<div className="font-bold text-slate-300 md:text-slate-700 text-center text-xs md:text-sm border-b border-white/20 md:border-slate-200 pb-1.5 md:pb-2 mb-1.5 md:mb-2 shrink-0">
|
| 65 |
{unit}
|
| 66 |
</div>
|
src/components/MobileDrawer.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
import React, { useEffect, useRef } from "react";
|
|
|
|
| 4 |
|
| 5 |
interface MobileDrawerProps {
|
| 6 |
isOpen: boolean;
|
|
@@ -12,8 +13,14 @@ export function MobileDrawer({ isOpen, onClose, children }: MobileDrawerProps) {
|
|
| 12 |
const popoverRef = useRef<HTMLDivElement>(null);
|
| 13 |
const scrollerRef = useRef<HTMLDivElement>(null);
|
| 14 |
const sheetRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
| 15 |
const isTransitioningRef = useRef(false);
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
// Sync React state to Popover open state
|
| 18 |
useEffect(() => {
|
| 19 |
const popover = popoverRef.current;
|
|
@@ -23,6 +30,7 @@ export function MobileDrawer({ isOpen, onClose, children }: MobileDrawerProps) {
|
|
| 23 |
|
| 24 |
if (isOpen) {
|
| 25 |
if (!popover.matches(':popover-open')) {
|
|
|
|
| 26 |
isTransitioningRef.current = true;
|
| 27 |
// Show popover
|
| 28 |
popover.showPopover();
|
|
@@ -33,6 +41,7 @@ export function MobileDrawer({ isOpen, onClose, children }: MobileDrawerProps) {
|
|
| 33 |
requestAnimationFrame(() => {
|
| 34 |
requestAnimationFrame(() => {
|
| 35 |
scroller.scrollTo({ left: 0, behavior: 'smooth' });
|
|
|
|
| 36 |
setTimeout(() => { isTransitioningRef.current = false; }, 400); // approx smooth scroll time
|
| 37 |
});
|
| 38 |
});
|
|
@@ -67,6 +76,7 @@ export function MobileDrawer({ isOpen, onClose, children }: MobileDrawerProps) {
|
|
| 67 |
|
| 68 |
if (popover.matches(':popover-open')) {
|
| 69 |
popover.hidePopover();
|
|
|
|
| 70 |
}
|
| 71 |
if (isOpen) {
|
| 72 |
onClose(); // Notify parent that the user swiped to close manually
|
|
@@ -79,10 +89,42 @@ export function MobileDrawer({ isOpen, onClose, children }: MobileDrawerProps) {
|
|
| 79 |
return () => observer.disconnect();
|
| 80 |
}, [isOpen, onClose]);
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
return (
|
| 83 |
<div
|
| 84 |
popover="manual"
|
| 85 |
ref={popoverRef}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
className="mobile-drawer fixed inset-0 z-[60] h-[100dvh] w-full border-0 bg-transparent p-0 m-0"
|
| 87 |
>
|
| 88 |
<div
|
|
@@ -106,7 +148,16 @@ export function MobileDrawer({ isOpen, onClose, children }: MobileDrawerProps) {
|
|
| 106 |
` }} />
|
| 107 |
|
| 108 |
{/* The Drawer Sheet (Content) */}
|
| 109 |
-
<div ref={sheetRef} className="glass-sidebar h-full w-[280px] shrink-0 snap-start shadow-2xl">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
{children}
|
| 111 |
</div>
|
| 112 |
|
|
|
|
| 1 |
"use client";
|
| 2 |
|
| 3 |
import React, { useEffect, useRef } from "react";
|
| 4 |
+
import { X } from "lucide-react";
|
| 5 |
|
| 6 |
interface MobileDrawerProps {
|
| 7 |
isOpen: boolean;
|
|
|
|
| 13 |
const popoverRef = useRef<HTMLDivElement>(null);
|
| 14 |
const scrollerRef = useRef<HTMLDivElement>(null);
|
| 15 |
const sheetRef = useRef<HTMLDivElement>(null);
|
| 16 |
+
const closeButtonRef = useRef<HTMLButtonElement>(null);
|
| 17 |
+
const previousFocusRef = useRef<HTMLElement | null>(null);
|
| 18 |
const isTransitioningRef = useRef(false);
|
| 19 |
|
| 20 |
+
const restoreFocus = () => {
|
| 21 |
+
requestAnimationFrame(() => previousFocusRef.current?.focus({ preventScroll: true }));
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
// Sync React state to Popover open state
|
| 25 |
useEffect(() => {
|
| 26 |
const popover = popoverRef.current;
|
|
|
|
| 30 |
|
| 31 |
if (isOpen) {
|
| 32 |
if (!popover.matches(':popover-open')) {
|
| 33 |
+
previousFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
| 34 |
isTransitioningRef.current = true;
|
| 35 |
// Show popover
|
| 36 |
popover.showPopover();
|
|
|
|
| 41 |
requestAnimationFrame(() => {
|
| 42 |
requestAnimationFrame(() => {
|
| 43 |
scroller.scrollTo({ left: 0, behavior: 'smooth' });
|
| 44 |
+
closeButtonRef.current?.focus({ preventScroll: true });
|
| 45 |
setTimeout(() => { isTransitioningRef.current = false; }, 400); // approx smooth scroll time
|
| 46 |
});
|
| 47 |
});
|
|
|
|
| 76 |
|
| 77 |
if (popover.matches(':popover-open')) {
|
| 78 |
popover.hidePopover();
|
| 79 |
+
restoreFocus();
|
| 80 |
}
|
| 81 |
if (isOpen) {
|
| 82 |
onClose(); // Notify parent that the user swiped to close manually
|
|
|
|
| 89 |
return () => observer.disconnect();
|
| 90 |
}, [isOpen, onClose]);
|
| 91 |
|
| 92 |
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
| 93 |
+
if (event.key === "Escape") {
|
| 94 |
+
event.preventDefault();
|
| 95 |
+
onClose();
|
| 96 |
+
return;
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
if (event.key !== "Tab") return;
|
| 100 |
+
const popover = popoverRef.current;
|
| 101 |
+
if (!popover) return;
|
| 102 |
+
const focusable = Array.from(
|
| 103 |
+
popover.querySelectorAll<HTMLElement>(
|
| 104 |
+
'button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])'
|
| 105 |
+
)
|
| 106 |
+
).filter((element) => element.offsetParent !== null);
|
| 107 |
+
if (focusable.length === 0) return;
|
| 108 |
+
|
| 109 |
+
const first = focusable[0];
|
| 110 |
+
const last = focusable[focusable.length - 1];
|
| 111 |
+
if (event.shiftKey && document.activeElement === first) {
|
| 112 |
+
event.preventDefault();
|
| 113 |
+
last.focus();
|
| 114 |
+
} else if (!event.shiftKey && document.activeElement === last) {
|
| 115 |
+
event.preventDefault();
|
| 116 |
+
first.focus();
|
| 117 |
+
}
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
return (
|
| 121 |
<div
|
| 122 |
popover="manual"
|
| 123 |
ref={popoverRef}
|
| 124 |
+
role="dialog"
|
| 125 |
+
aria-modal="true"
|
| 126 |
+
aria-label="Filters"
|
| 127 |
+
onKeyDown={handleKeyDown}
|
| 128 |
className="mobile-drawer fixed inset-0 z-[60] h-[100dvh] w-full border-0 bg-transparent p-0 m-0"
|
| 129 |
>
|
| 130 |
<div
|
|
|
|
| 148 |
` }} />
|
| 149 |
|
| 150 |
{/* The Drawer Sheet (Content) */}
|
| 151 |
+
<div ref={sheetRef} className="glass-sidebar relative h-full w-[min(280px,calc(100vw-3rem))] shrink-0 snap-start shadow-2xl">
|
| 152 |
+
<button
|
| 153 |
+
ref={closeButtonRef}
|
| 154 |
+
type="button"
|
| 155 |
+
onClick={onClose}
|
| 156 |
+
aria-label="Close filters"
|
| 157 |
+
className="absolute right-3 top-3 z-10 flex min-h-11 min-w-11 items-center justify-center rounded-xl text-slate-300 transition-colors hover:bg-white/10 hover:text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
|
| 158 |
+
>
|
| 159 |
+
<X size={20} aria-hidden="true" />
|
| 160 |
+
</button>
|
| 161 |
{children}
|
| 162 |
</div>
|
| 163 |
|
src/components/Table.tsx
CHANGED
|
@@ -18,6 +18,7 @@ interface WeatherTableProps<T> {
|
|
| 18 |
onRowDoubleClick?: (row: T) => void;
|
| 19 |
searchPlaceholder?: string;
|
| 20 |
searchKey?: keyof T;
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
export function WeatherTable<T>({
|
|
@@ -26,7 +27,8 @@ export function WeatherTable<T>({
|
|
| 26 |
defaultSorting = [],
|
| 27 |
onRowDoubleClick,
|
| 28 |
searchPlaceholder = "Filter records...",
|
| 29 |
-
searchKey
|
|
|
|
| 30 |
}: WeatherTableProps<T>) {
|
| 31 |
const [sorting, setSorting] = useState<SortingState>(() => defaultSorting);
|
| 32 |
const [globalFilter, setGlobalFilter] = useState("");
|
|
@@ -73,8 +75,40 @@ export function WeatherTable<T>({
|
|
| 73 |
</div>
|
| 74 |
)}
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
{/* Grid container with sticky headers */}
|
| 77 |
-
<div className=
|
| 78 |
<table className="w-full text-left border-collapse">
|
| 79 |
<thead className="sticky top-0 bg-slate-50/95 backdrop-blur z-10 border-b border-slate-100">
|
| 80 |
{table.getHeaderGroups().map((headerGroup) => (
|
|
@@ -147,6 +181,7 @@ export function WeatherTable<T>({
|
|
| 147 |
<button
|
| 148 |
onClick={() => table.previousPage()}
|
| 149 |
disabled={!table.getCanPreviousPage()}
|
|
|
|
| 150 |
className="p-2 border border-slate-200 rounded-xl hover:bg-slate-50 active:scale-95 text-slate-600 disabled:opacity-40 disabled:pointer-events-none transition-all cursor-pointer min-w-[44px] min-h-[44px] flex items-center justify-center"
|
| 151 |
>
|
| 152 |
<ChevronLeft size={16} />
|
|
@@ -154,6 +189,7 @@ export function WeatherTable<T>({
|
|
| 154 |
<button
|
| 155 |
onClick={() => table.nextPage()}
|
| 156 |
disabled={!table.getCanNextPage()}
|
|
|
|
| 157 |
className="p-2 border border-slate-200 rounded-xl hover:bg-slate-50 active:scale-95 text-slate-600 disabled:opacity-40 disabled:pointer-events-none transition-all cursor-pointer min-w-[44px] min-h-[44px] flex items-center justify-center"
|
| 158 |
>
|
| 159 |
<ChevronRight size={16} />
|
|
|
|
| 18 |
onRowDoubleClick?: (row: T) => void;
|
| 19 |
searchPlaceholder?: string;
|
| 20 |
searchKey?: keyof T;
|
| 21 |
+
mobileLayout?: "table" | "cards";
|
| 22 |
}
|
| 23 |
|
| 24 |
export function WeatherTable<T>({
|
|
|
|
| 27 |
defaultSorting = [],
|
| 28 |
onRowDoubleClick,
|
| 29 |
searchPlaceholder = "Filter records...",
|
| 30 |
+
searchKey,
|
| 31 |
+
mobileLayout = "table"
|
| 32 |
}: WeatherTableProps<T>) {
|
| 33 |
const [sorting, setSorting] = useState<SortingState>(() => defaultSorting);
|
| 34 |
const [globalFilter, setGlobalFilter] = useState("");
|
|
|
|
| 75 |
</div>
|
| 76 |
)}
|
| 77 |
|
| 78 |
+
{mobileLayout === "cards" && (
|
| 79 |
+
<div className="flex-1 min-h-0 overflow-y-auto rounded-2xl border border-slate-100 bg-white shadow-sm sm:hidden">
|
| 80 |
+
{table.getRowModel().rows.map((row) => (
|
| 81 |
+
<button
|
| 82 |
+
key={row.id}
|
| 83 |
+
type="button"
|
| 84 |
+
onClick={() => onRowDoubleClick?.(row.original)}
|
| 85 |
+
aria-label={searchKey ? `Select ${String(row.original[searchKey])}` : "Select row"}
|
| 86 |
+
className="grid w-full grid-cols-2 gap-x-4 gap-y-3 border-b border-slate-100 p-4 text-left transition-colors last:border-b-0 hover:bg-slate-50 focus-visible:relative focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-blue-500"
|
| 87 |
+
>
|
| 88 |
+
{row.getVisibleCells().map((cell, index) => {
|
| 89 |
+
const metaClassName = (cell.column.columnDef.meta as { className?: string })?.className || "";
|
| 90 |
+
const header = table.getFlatHeaders().find((candidate) => candidate.column.id === cell.column.id);
|
| 91 |
+
return (
|
| 92 |
+
<span key={cell.id} className={`${index === 0 ? "col-span-2" : ""} ${metaClassName}`}>
|
| 93 |
+
<span className="block text-[11px] font-bold uppercase tracking-wider text-slate-400">
|
| 94 |
+
{header ? flexRender(header.column.columnDef.header, header.getContext()) : cell.column.id}
|
| 95 |
+
</span>
|
| 96 |
+
<span className={`mt-1 block break-words text-slate-700 ${index === 0 ? "text-base font-bold" : "text-sm font-medium"}`}>
|
| 97 |
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
| 98 |
+
</span>
|
| 99 |
+
</span>
|
| 100 |
+
);
|
| 101 |
+
})}
|
| 102 |
+
</button>
|
| 103 |
+
))}
|
| 104 |
+
{table.getRowModel().rows.length === 0 && (
|
| 105 |
+
<p className="p-8 text-center text-sm font-medium text-slate-400">No records matching your filters.</p>
|
| 106 |
+
)}
|
| 107 |
+
</div>
|
| 108 |
+
)}
|
| 109 |
+
|
| 110 |
{/* Grid container with sticky headers */}
|
| 111 |
+
<div className={`flex-1 w-full overflow-auto custom-scrollbar border border-slate-100 rounded-2xl bg-white shadow-sm min-h-0 ${mobileLayout === "cards" ? "hidden sm:block" : ""}`}>
|
| 112 |
<table className="w-full text-left border-collapse">
|
| 113 |
<thead className="sticky top-0 bg-slate-50/95 backdrop-blur z-10 border-b border-slate-100">
|
| 114 |
{table.getHeaderGroups().map((headerGroup) => (
|
|
|
|
| 181 |
<button
|
| 182 |
onClick={() => table.previousPage()}
|
| 183 |
disabled={!table.getCanPreviousPage()}
|
| 184 |
+
aria-label="Previous page"
|
| 185 |
className="p-2 border border-slate-200 rounded-xl hover:bg-slate-50 active:scale-95 text-slate-600 disabled:opacity-40 disabled:pointer-events-none transition-all cursor-pointer min-w-[44px] min-h-[44px] flex items-center justify-center"
|
| 186 |
>
|
| 187 |
<ChevronLeft size={16} />
|
|
|
|
| 189 |
<button
|
| 190 |
onClick={() => table.nextPage()}
|
| 191 |
disabled={!table.getCanNextPage()}
|
| 192 |
+
aria-label="Next page"
|
| 193 |
className="p-2 border border-slate-200 rounded-xl hover:bg-slate-50 active:scale-95 text-slate-600 disabled:opacity-40 disabled:pointer-events-none transition-all cursor-pointer min-w-[44px] min-h-[44px] flex items-center justify-center"
|
| 194 |
>
|
| 195 |
<ChevronRight size={16} />
|