From ab2c73856dc79a9cb9613aea4716242e5ac7a0d6 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Fri, 31 Dec 2021 02:06:20 +0800 Subject: [PATCH] :construction: add modal --- website/package.json | 1 + website/src/components/Modal/index.tsx | 39 ++++++++ website/src/components/Paginate/index.tsx | 9 +- website/src/components/Plugin.tsx | 103 +++++++++++++++++++++- website/src/libs/resize.ts | 67 ++++++++++++++ website/src/libs/store.ts | 3 +- website/src/libs/width.ts | 64 ++++++++++++++ yarn.lock | 5 ++ 8 files changed, 286 insertions(+), 5 deletions(-) create mode 100644 website/src/components/Modal/index.tsx create mode 100644 website/src/libs/resize.ts create mode 100644 website/src/libs/width.ts diff --git a/website/package.json b/website/package.json index 7b4fb2f3..bdbe2031 100644 --- a/website/package.json +++ b/website/package.json @@ -34,6 +34,7 @@ "react-dom": "^17.0.1", "react-paginate": "^8.1.0", "react-use-pagination": "^2.0.1", + "resize-observer-polyfill": "^1.5.1", "url-loader": "^4.1.1" }, "devDependencies": { diff --git a/website/src/components/Modal/index.tsx b/website/src/components/Modal/index.tsx new file mode 100644 index 00000000..06e4551b --- /dev/null +++ b/website/src/components/Modal/index.tsx @@ -0,0 +1,39 @@ +import clsx from "clsx"; +import React from "react"; + +export default function Modal({ + active, + setActive, + children, +}: { + active: boolean; + setActive: (active: boolean) => void; + children: React.ReactNode; +}): JSX.Element { + return ( + <> + {/* overlay */} +
setActive(false)} + > +
+
+ {/* modal */} +
+ {children} +
+ + ); +} diff --git a/website/src/components/Paginate/index.tsx b/website/src/components/Paginate/index.tsx index 24681dc9..3e288faa 100644 --- a/website/src/components/Paginate/index.tsx +++ b/website/src/components/Paginate/index.tsx @@ -1,9 +1,10 @@ -import React, { useCallback } from "react"; +import React, { useCallback, useRef } from "react"; import ReactPaginate from "react-paginate"; import { usePagination } from "react-use-pagination"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { useContentWidth } from "../../libs/width"; import styles from "./styles.module.css"; export default function Paginate({ @@ -11,6 +12,9 @@ export default function Paginate({ setPage, currentPage, }: ReturnType): JSX.Element { + const ref = useRef(); + const maxWidth = useContentWidth(ref.current?.parentElement ?? undefined); + const onPageChange = useCallback( (selectedItem: { selected: number }) => { setPage(selectedItem.selected); @@ -18,8 +22,9 @@ export default function Paginate({ [setPage] ); + // FIXME: responsive width return ( -