nonebot2/website/src/components/Driver.tsx

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-12-29 13:33:36 +08:00
import React from "react";
2021-12-30 12:50:30 +08:00
import { usePagination } from "react-use-pagination";
2021-12-29 13:33:36 +08:00
2021-12-29 21:09:31 +08:00
import drivers from "../../static/drivers.json";
import { useFilteredObjs } from "../libs/store";
2021-12-30 12:50:30 +08:00
import Paginate from "./Paginate";
2021-12-29 21:09:31 +08:00
2021-12-30 12:50:30 +08:00
export default function Driver(): JSX.Element {
2021-12-29 21:09:31 +08:00
const {
filter,
setFilter,
filteredObjs: filteredDrivers,
} = useFilteredObjs(drivers);
2021-12-30 12:50:30 +08:00
const props = usePagination({
totalItems: filteredDrivers.length,
initialPageSize: 10,
});
const { startIndex, endIndex } = props;
const currentDrivers = filteredDrivers.slice(startIndex, endIndex);
2021-12-29 21:09:31 +08:00
return (
<>
2021-12-30 12:50:30 +08:00
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 mt-4 px-4">
2021-12-29 21:09:31 +08:00
<input
2021-12-30 12:50:30 +08:00
className="w-full px-4 py-2 border rounded-full bg-light-nonepress-100 dark:bg-dark-nonepress-100"
2021-12-29 21:09:31 +08:00
value={filter}
2021-12-30 12:50:30 +08:00
placeholder="搜索驱动器"
2021-12-29 21:09:31 +08:00
onChange={(event) => setFilter(event.target.value)}
/>
2021-12-30 12:50:30 +08:00
<button className="w-full rounded bg-hero text-white" disabled>
</button>
</div>
<div className="grid grid-cols-1 p-4">
<Paginate {...props} />
</div>
<div>
{currentDrivers.map((driver, index) => (
<p key={index}>{driver.name}</p>
))}
</div>
<div className="grid grid-cols-1 p-4">
<Paginate {...props} />
2021-12-29 21:09:31 +08:00
</div>
</>
);
2021-12-29 13:33:36 +08:00
}