From 9b07c526a507e47b7de166b00ffce76f13d7b887 Mon Sep 17 00:00:00 2001 From: Gustavo Maronato Date: Mon, 21 Aug 2023 10:45:56 -0300 Subject: [PATCH] unify button definition --- frontend/src/components/Button.tsx | 44 ++++++++++++++++++++++++++++ frontend/src/components/ItemBase.tsx | 15 +++++----- frontend/src/pages/Index.tsx | 7 ++--- frontend/src/pages/Login.tsx | 10 ++++--- frontend/src/pages/Signup.tsx | 10 ++++--- frontend/src/pages/Tokens.tsx | 16 ++++------ 6 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 frontend/src/components/Button.tsx diff --git a/frontend/src/components/Button.tsx b/frontend/src/components/Button.tsx new file mode 100644 index 0000000..41c8d38 --- /dev/null +++ b/frontend/src/components/Button.tsx @@ -0,0 +1,44 @@ +import { + FunctionComponent, + DetailedHTMLProps, + ButtonHTMLAttributes, +} from "react" + +import classNames from "classnames" + +type DefaultButtonProps = DetailedHTMLProps< + ButtonHTMLAttributes, + HTMLButtonElement +> + +const Button: FunctionComponent< + Pick< + DefaultButtonProps, + "className" | "onClick" | "type" | "disabled" | "children" + > & { + color?: "blue" | "red" | "green" + } +> = ({ color, children, className, ...props }) => { + let colorClasses = "bg-blue-100 text-blue-500 hover:bg-blue-500" + if (color === "red") { + colorClasses = "bg-red-100 text-red-500 hover:bg-red-500" + } else if (color === "green") { + colorClasses = "bg-green-100 text-green-500 hover:bg-green-500" + } + + return ( + + ) +} + +export default Button diff --git a/frontend/src/components/ItemBase.tsx b/frontend/src/components/ItemBase.tsx index 20c57fa..86a6dc3 100644 --- a/frontend/src/components/ItemBase.tsx +++ b/frontend/src/components/ItemBase.tsx @@ -16,6 +16,8 @@ import { Link } from "react-router-dom" import { useDoubleclickDelete } from "../hooks/useOnUpdateItem" +import Button from "./Button" + const ItemBase: FunctionComponent< PropsWithChildren<{ copyString?: string @@ -34,20 +36,19 @@ const ItemBase: FunctionComponent<
{copyString && ( - + )} {doDelete && ( - + className="px-2 py-1 text-sm" + color="red"> {deleting ? "Are you sure?" : "Delete"} - + )}
diff --git a/frontend/src/pages/Index.tsx b/frontend/src/pages/Index.tsx index 008e651..f690040 100644 --- a/frontend/src/pages/Index.tsx +++ b/frontend/src/pages/Index.tsx @@ -7,6 +7,7 @@ import { useNavigation, } from "react-router-dom" +import Button from "../components/Button" import Header from "../components/Header" import ItemList from "../components/ItemList" import ShortItem from "../components/ShortItem" @@ -111,11 +112,9 @@ export const Component: FunctionComponent = () => { {actionData.error}

) : null} - +
- + {`Don't have an account? `} - + {`Have an account? `}
- + {data.length > 0 ? : } ) @@ -59,7 +55,7 @@ export const loader: LoaderFunction = async (args) => { const resp = await protectedLoader(args) if (resp) return resp - // const data = await fetchAPI("/sessions") + // const data = await fetchAPI("/tokens") const data = { ok: true, data: [] } if (data.ok) { return data.data