fix: complete first version issue remediation

This commit is contained in:
hectorzhao
2026-07-11 10:14:37 +08:00
parent 709ac97764
commit 208a6c23f8
73 changed files with 1549 additions and 245 deletions
+17 -1
View File
@@ -1,4 +1,4 @@
import type { ReactNode } from 'react';
import { useEffect, useState, type ReactNode } from 'react';
import { Button } from '@/components/ui/Button';
type QueryPanelProps = {
@@ -10,10 +10,12 @@ type QueryPanelProps = {
type PaginationProps = {
total?: number;
page?: number;
totalPages?: number;
previousDisabled?: boolean;
nextDisabled?: boolean;
onPrevious?: () => void;
onNext?: () => void;
onPageChange?: (page: number) => void;
};
type InlineTextPreviewProps = {
@@ -35,17 +37,31 @@ export function QueryPanel({ title, summary, children }: QueryPanelProps) {
export function Pagination({
total,
page = 1,
totalPages,
previousDisabled = true,
nextDisabled = true,
onPrevious,
onNext,
onPageChange,
}: PaginationProps) {
const pages = Math.max(1, totalPages ?? (typeof total === 'number' ? Math.ceil(total / 10) : page));
const [targetPage, setTargetPage] = useState(String(page));
useEffect(() => setTargetPage(String(page)), [page]);
function changePage(nextPage: number) {
onPageChange?.(Math.min(pages, Math.max(1, nextPage)));
}
return (
<div className="ui-pagination">
{typeof total === 'number' ? <span> {total} </span> : <span />}
<div>
<Button disabled={previousDisabled} onClick={onPrevious} size="sm" variant="ghost"></Button>
{onPageChange ? <Button disabled={page <= 1} onClick={() => changePage(1)} size="sm" variant="ghost"></Button> : null}
<Button size="sm" variant="secondary">{page}</Button>
{onPageChange ? <label className="ui-pagination__jump"> <input aria-label="跳转页码" min="1" max={pages} onChange={(event) => setTargetPage(event.target.value)} onKeyDown={(event) => { if (event.key === 'Enter') changePage(Number(targetPage)); }} type="number" value={targetPage} /> / {pages} </label> : null}
{onPageChange ? <Button disabled={page >= pages} onClick={() => changePage(pages)} size="sm" variant="ghost"></Button> : null}
<Button disabled={nextDisabled} onClick={onNext} size="sm" variant="ghost"></Button>
</div>
</div>