From c48231454e4c498e7eddd5278e335bd9ccec6881 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Fri, 31 Dec 2021 18:21:32 +0800 Subject: [PATCH] :construction: add tag type picker --- website/src/components/Card/index.tsx | 49 +--- website/src/components/Modal/index.tsx | 6 +- website/src/components/ModalAction/index.tsx | 9 + website/src/components/ModalContent/index.tsx | 9 + website/src/components/ModalTitle/index.tsx | 9 + website/src/components/Plugin.tsx | 220 ++++++++++-------- website/src/components/Tag/index.tsx | 38 +++ 7 files changed, 195 insertions(+), 145 deletions(-) create mode 100644 website/src/components/ModalAction/index.tsx create mode 100644 website/src/components/ModalContent/index.tsx create mode 100644 website/src/components/ModalTitle/index.tsx create mode 100644 website/src/components/Tag/index.tsx diff --git a/website/src/components/Card/index.tsx b/website/src/components/Card/index.tsx index 636fb4aa..1f3c38f1 100644 --- a/website/src/components/Card/index.tsx +++ b/website/src/components/Card/index.tsx @@ -1,44 +1,10 @@ -import clsx from "clsx"; import React from "react"; import Link from "@docusaurus/Link"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import type { Obj, Tag as TagType } from "../../libs/store"; - -function pickTextColor(bgColor, lightColor, darkColor) { - var color = bgColor.charAt(0) === "#" ? bgColor.substring(1, 7) : bgColor; - var r = parseInt(color.substring(0, 2), 16); // hexToR - var g = parseInt(color.substring(2, 4), 16); // hexToG - var b = parseInt(color.substring(4, 6), 16); // hexToB - return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? darkColor : lightColor; -} - -export function Tag({ - label, - color, - className, - onClick, -}: TagType & { - className?: string; - onClick?: React.MouseEventHandler; -}): JSX.Element { - return ( - - {label} - - ); -} +import type { Obj } from "../../libs/store"; +import Tag from "../Tag"; export default function Card({ module_name, @@ -79,16 +45,7 @@ export default function Card({ {tags && (
{tags.map((tag, index) => ( - - {tag.label} - + ))}
)} diff --git a/website/src/components/Modal/index.tsx b/website/src/components/Modal/index.tsx index 06e4551b..70c75ca4 100644 --- a/website/src/components/Modal/index.tsx +++ b/website/src/components/Modal/index.tsx @@ -32,7 +32,11 @@ export default function Modal({ { hidden: !active } )} > - {children} +
+
+ {children} +
+
); diff --git a/website/src/components/ModalAction/index.tsx b/website/src/components/ModalAction/index.tsx new file mode 100644 index 00000000..e77e4add --- /dev/null +++ b/website/src/components/ModalAction/index.tsx @@ -0,0 +1,9 @@ +import React from "react"; + +export default function ModalAction({ + children, +}: { + children: React.ReactNode; +}): JSX.Element { + return
{children}
; +} diff --git a/website/src/components/ModalContent/index.tsx b/website/src/components/ModalContent/index.tsx new file mode 100644 index 00000000..4c2fab51 --- /dev/null +++ b/website/src/components/ModalContent/index.tsx @@ -0,0 +1,9 @@ +import React from "react"; + +export default function ModalContent({ + children, +}: { + children: React.ReactNode; +}): JSX.Element { + return
{children}
; +} diff --git a/website/src/components/ModalTitle/index.tsx b/website/src/components/ModalTitle/index.tsx new file mode 100644 index 00000000..d0f00b56 --- /dev/null +++ b/website/src/components/ModalTitle/index.tsx @@ -0,0 +1,9 @@ +import React from "react"; + +export default function ModalTitle({ title }: { title: string }): JSX.Element { + return ( +
+ {title} +
+ ); +} diff --git a/website/src/components/Plugin.tsx b/website/src/components/Plugin.tsx index 9651a167..28b669dc 100644 --- a/website/src/components/Plugin.tsx +++ b/website/src/components/Plugin.tsx @@ -1,13 +1,17 @@ import clsx from "clsx"; -import React, { useState } from "react"; +import React, { useRef, useState } from "react"; import { ChromePicker } from "react-color"; import { usePagination } from "react-use-pagination"; import plugins from "../../static/plugins.json"; import { Tag, useFilteredObjs } from "../libs/store"; -import Card, { Tag as TagComponent } from "./Card"; +import Card from "./Card"; import Modal from "./Modal"; +import ModalAction from "./ModalAction"; +import ModalContent from "./ModalContent"; +import ModalTitle from "./ModalTitle"; import Paginate from "./Paginate"; +import TagComponent from "./Tag"; export default function Adapter(): JSX.Element { const [modalOpen, setModalOpen] = useState(false); @@ -31,9 +35,12 @@ export default function Adapter(): JSX.Element { moduleName: string; homepage: string; }>({ name: "", desc: "", projectLink: "", moduleName: "", homepage: "" }); + + const ref = useRef(null); const [tags, setTags] = useState([]); const [label, setLabel] = useState(""); const [color, setColor] = useState("#ea5252"); + const onSubmit = () => { setModalOpen(false); const title = encodeURIComponent(`Plugin: ${form.name}`).replace( @@ -103,6 +110,10 @@ ${JSON.stringify(tags)} const delTag = (index: number) => { setTags(tags.filter((_, i) => i !== index)); }; + const insertTagType = (text: string) => { + setLabel(text + label); + ref.current.value = text + label; + }; return ( <> @@ -132,114 +143,127 @@ ${JSON.stringify(tags)} -
-
-
- 插件信息 -
-
-
-
- - - - - -
-
-
- -
-
+ + +
+
+
+ + + +
-
- +
+
+ +
-
+ + + + + ); diff --git a/website/src/components/Tag/index.tsx b/website/src/components/Tag/index.tsx new file mode 100644 index 00000000..303923ef --- /dev/null +++ b/website/src/components/Tag/index.tsx @@ -0,0 +1,38 @@ +import clsx from "clsx"; +import React from "react"; + +import { Tag as TagType } from "../../libs/store"; + +function pickTextColor(bgColor, lightColor, darkColor) { + var color = bgColor.charAt(0) === "#" ? bgColor.substring(1, 7) : bgColor; + var r = parseInt(color.substring(0, 2), 16); // hexToR + var g = parseInt(color.substring(2, 4), 16); // hexToG + var b = parseInt(color.substring(4, 6), 16); // hexToB + return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? darkColor : lightColor; +} + +export default function Tag({ + label, + color, + className, + onClick, +}: TagType & { + className?: string; + onClick?: React.MouseEventHandler; +}): JSX.Element { + return ( + + {label} + + ); +}