openreader/src/components/doclist/window/FinderToolbar.tsx
Richard R f2c7760381
Redesign: shared UI design system + app-wide migration (#96)
* phase 0: token foundation

* phase 1: motion language

* phase 2: primitives and semantic tokens

* phase 3: depth and rhythm polish

* phase 4: enforce design system lint rules

* phase 5: split ui primitives into modules

* phase 7: refactor app surfaces to ui layer

* phase 9: enforce ui architecture imports

* phase 10: add ui system harness

* fix compact reader auth control

* fix pdf loader flash

* Converge sidebar and reader controls

* refactor: remove initial loader state and related logic from PDFViewerPage

* Remove legacy UI shim imports

* Converge modal and drawer frames

* Migrate secondary modals to shared frame

* Move settings modal onto shared frame

* Use shared cards in audiobook settings

* Converge choice and popover surfaces

* Converge reader navigation buttons

* Refactor UI components to use consistent button and icon styles across the application

* refactor(ui): unify button usage in settings, admin, and doclist components

Replace native button elements with shared Button, ChoiceTile, and IconButton
components for consistent UI behavior and styling. Update classNames and
props to match new component APIs. Adjust FinderSidebar to use utility
function for conditional class merging.

* feat(ui): introduce shared Listbox components for unified select and dropdown styling

Replace direct usage of Headless UI Listbox primitives with new SharedListboxButton,
SharedListboxOption, and SharedListboxOptions components across AudiobookExportModal,
FinderToolbar, VoicesControlBase, and select UI. Refactor related imports and classNames
to centralize dropdown styling and logic. Simplify UserMenu button markup for improved
consistency.

This change consolidates dropdown/select UI patterns, reduces duplication, and
improves maintainability by providing a single source of truth for Listbox styling
and behavior.

* refactor(ui): consolidate button, menu, popover, and range primitives for unified usage

Remove legacy UI harness and dev/demo files. Replace scattered button, menu, popover, and range input utilities with shared, composable primitives: Button, ButtonLink, ButtonAnchor, MenuActionItem, MenuItemsSurface, PopoverSurface, PopoverTrigger, and RangeInput. Update all usages across app, admin, player, and document components to use these new primitives, eliminating duplicated class logic and improving consistency. Remove obsolete utility files and class exports. This change streamlines UI code, centralizes styling, and reduces maintenance overhead.

* feat(ui): redesign range input with dynamic progress styling and improved accessibility

Revamp the range input component to support dynamic progress indication using CSS custom properties and linear gradients. Add logic to compute and set the progress percentage based on current value, min, and max. Refine focus and disabled states for better accessibility and usability. Update styling for both WebKit and Mozilla engines to ensure consistent appearance. This change enhances visual feedback and modernizes the range slider UI.

* style(ui): update range input to use secondary accent color for progress

Switch range input progress styling from primary to secondary accent color
for both WebKit and Mozilla engines. Remove drop shadow from slider thumb
for a cleaner appearance. This change aligns the component with the updated
design palette and simplifies visual effects.

* refactor(app): remove unused Link imports from public pages and components

Eliminate redundant imports of the Link component from Next.js in several
public-facing pages and components. These imports were no longer in use
after recent UI refactoring and consolidation of navigation elements.
This cleanup reduces bundle size and improves code clarity.

* chore(ui): remove unused export of segmented control classes from select component

Eliminate unnecessary export statements for segmentedButtonClass and
segmentedGroupClass in the select component to streamline the module's
public API and reduce potential confusion.

* test(accessibility): improve confirm dialog test coverage and refactor media state helper

Expand accessibility tests for ConfirmDialog to assert dialog semantics,
ARIA attributes, and visible destructive actions using test IDs. Refactor
expectMediaState helper to check both UI control state and underlying
media signals for more robust playback state detection.

* refactor(ui): improve segmented control accessibility and update danger color tokens

Update SegmentedControl to support full keyboard navigation and focus management,
enhancing accessibility. Replace string indicator in Select with icon, and update
button danger variant to use new --danger-strong variable for hover states. Add
danger-strong token to Tailwind config and globals. Refine dropzone disabled
behavior, adjust focus ring for better contrast, and apply minor UI consistency
tweaks across components.

* feat(ui): convert SidebarNavLink to forwardRef component

Refactor SidebarNavLink to use React.forwardRef, enabling parent components
to access the underlying anchor element's ref. Update prop typing and
function signature accordingly for improved composability and integration
with higher-order components.
2026-06-01 16:17:12 -06:00

184 lines
6.6 KiB
TypeScript

'use client';
import { Listbox } from '@headlessui/react';
import type { IconSize, SortBy, SortDirection, ViewMode } from '@/types/documents';
import {
IconsViewIcon,
ListViewIcon,
GalleryViewIcon,
SearchIcon,
HamburgerIcon,
} from './finderIcons';
import { ChevronUpDownIcon } from '@/components/icons/Icons';
import { SearchField, SharedListboxButton, SharedListboxOption, SharedListboxOptions, Toolbar, ToolbarButton, ToolbarGroup, ToolbarSegment } from '@/components/ui';
import type { ReactNode } from 'react';
interface FinderToolbarProps {
viewMode: ViewMode;
onViewModeChange: (mode: ViewMode) => void;
iconSize: IconSize;
onIconSizeChange: (size: IconSize) => void;
sortBy: SortBy;
sortDirection: SortDirection;
onSortByChange: (s: SortBy) => void;
onSortDirectionToggle: () => void;
query: string;
onQueryChange: (q: string) => void;
onToggleSidebar: () => void;
isSidebarOpen: boolean;
showSortControls?: boolean;
/** App-level content rendered at the far left (brand/logo). */
leftSlot?: ReactNode;
/** App-level content rendered at the far right (settings, user menu). */
rightSlot?: ReactNode;
}
const VIEW_BUTTONS: Array<{ value: ViewMode; label: string; Icon: typeof IconsViewIcon }> = [
{ value: 'icons', label: 'Icons', Icon: IconsViewIcon },
{ value: 'list', label: 'List', Icon: ListViewIcon },
{ value: 'gallery', label: 'Gallery', Icon: GalleryViewIcon },
];
const SORT_OPTIONS: Array<{ value: SortBy; label: string; asc: string; desc: string }> = [
{ value: 'name', label: 'Name', asc: 'A → Z', desc: 'Z → A' },
{ value: 'type', label: 'Kind', asc: 'A → Z', desc: 'Z → A' },
{ value: 'date', label: 'Modified', asc: 'Oldest', desc: 'Newest' },
{ value: 'size', label: 'Size', asc: 'Smallest', desc: 'Largest' },
];
const ICON_SIZES: Array<{ value: IconSize; label: string }> = [
{ value: 'sm', label: 'S' },
{ value: 'md', label: 'M' },
{ value: 'lg', label: 'L' },
{ value: 'xl', label: 'XL' },
];
export function FinderToolbar({
viewMode,
onViewModeChange,
iconSize,
onIconSizeChange,
sortBy,
sortDirection,
onSortByChange,
onSortDirectionToggle,
query,
onQueryChange,
onToggleSidebar,
isSidebarOpen,
showSortControls = true,
leftSlot,
rightSlot,
}: FinderToolbarProps) {
const currentSort = SORT_OPTIONS.find((o) => o.value === sortBy) ?? SORT_OPTIONS[0];
const directionLabel = sortDirection === 'asc' ? currentSort.asc : currentSort.desc;
return (
<Toolbar>
{leftSlot && (
<div className="shrink-0 flex items-center gap-2 pr-1 sm:pr-2 sm:border-r sm:border-line">
{leftSlot}
</div>
)}
<ToolbarButton
onClick={onToggleSidebar}
active={isSidebarOpen}
className="shrink-0"
aria-pressed={isSidebarOpen}
aria-label="Toggle sidebar"
title="Toggle sidebar"
>
<HamburgerIcon className="w-4 h-4" />
</ToolbarButton>
<ToolbarGroup>
{VIEW_BUTTONS.map(({ value, label, Icon }) => {
const active = viewMode === value;
const isIconsToggle = value === 'icons';
return (
<div
key={value}
className={isIconsToggle ? 'relative group/icons inline-flex items-center' : 'inline-flex items-center'}
>
<ToolbarSegment
onClick={() => onViewModeChange(value)}
active={active}
aria-pressed={active}
aria-label={`${label} view`}
title={`${label} view`}
className="w-7"
>
<Icon className="w-4 h-4" />
</ToolbarSegment>
{isIconsToggle && viewMode === 'icons' && (
<div
className="absolute top-full left-1/2 z-30 -translate-x-1/2 pt-1 opacity-0 pointer-events-none transition-opacity duration-fast group-hover/icons:opacity-100 group-hover/icons:pointer-events-auto group-focus-within/icons:opacity-100 group-focus-within/icons:pointer-events-auto"
>
<ToolbarGroup className="shadow-elev-2">
{ICON_SIZES.map(({ value: sizeValue, label: sizeLabel }) => {
const sizeActive = iconSize === sizeValue;
return (
<ToolbarSegment
key={sizeValue}
onClick={() => onIconSizeChange(sizeValue)}
active={sizeActive}
aria-pressed={sizeActive}
aria-label={`Icon size ${sizeLabel}`}
className="min-w-[26px] px-1.5 font-semibold tracking-wide"
>
{sizeLabel}
</ToolbarSegment>
);
})}
</ToolbarGroup>
</div>
)}
</div>
);
})}
</ToolbarGroup>
{showSortControls && (
<div className="flex items-center gap-1 shrink-0">
<ToolbarButton onClick={onSortDirectionToggle} className="whitespace-nowrap" title="Toggle sort direction">
{directionLabel}
</ToolbarButton>
<Listbox value={sortBy} onChange={onSortByChange}>
<SharedListboxButton tone="toolbar" className="gap-1 min-w-[86px] justify-between">
<span>{currentSort.label}</span>
<ChevronUpDownIcon className="h-3 w-3 opacity-60" />
</SharedListboxButton>
<SharedListboxOptions anchor="bottom end" tone="compact">
{SORT_OPTIONS.map((opt) => (
<SharedListboxOption
key={opt.value}
value={opt.value}
tone="compact"
>
{opt.label}
</SharedListboxOption>
))}
</SharedListboxOptions>
</Listbox>
</div>
)}
<div className="flex-1 min-w-0" />
<SearchField
value={query}
onChange={(e) => onQueryChange(e.target.value)}
placeholder="Search"
className="hidden w-[160px] md:w-[200px] sm:flex"
icon={<SearchIcon className="w-3.5 h-3.5" />}
/>
{rightSlot && (
<div className="shrink-0 flex items-center gap-2 pl-1 sm:pl-2 sm:border-l sm:border-line ml-0.5">
{rightSlot}
</div>
)}
</Toolbar>
);
}