From 0b7d070146c249db822a2215d068f6f7c4b60ac8 Mon Sep 17 00:00:00 2001 From: Lukas Jakob Date: Mon, 27 Feb 2023 09:20:49 -0600 Subject: [PATCH] refactor(AsyncButton): add loader --- packages/app/src/Element/AsyncButton.css | 27 ++++++++++++++++++++++++ packages/app/src/Element/AsyncButton.tsx | 25 +++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 packages/app/src/Element/AsyncButton.css diff --git a/packages/app/src/Element/AsyncButton.css b/packages/app/src/Element/AsyncButton.css new file mode 100644 index 0000000..0f8fef5 --- /dev/null +++ b/packages/app/src/Element/AsyncButton.css @@ -0,0 +1,27 @@ +button { + position: relative; +} + +.spinner { + position: absolute; + width: 100%; + height: 100%; + top: 0; + left: 0; + display: flex; + justify-content: center; + align-items: center; + animation-name: spin; + animation-duration: 800ms; + animation-iteration-count: infinite; + animation-timing-function: linear; +} + +@keyframes spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } +} diff --git a/packages/app/src/Element/AsyncButton.tsx b/packages/app/src/Element/AsyncButton.tsx index 59bdaf8..34e6e10 100644 --- a/packages/app/src/Element/AsyncButton.tsx +++ b/packages/app/src/Element/AsyncButton.tsx @@ -1,3 +1,4 @@ +import "./AsyncButton.css"; import { useState } from "react"; interface AsyncButtonProps extends React.ButtonHTMLAttributes { @@ -5,6 +6,27 @@ interface AsyncButtonProps extends React.ButtonHTMLAttributes children?: React.ReactNode; } +interface LoaderProps { + className: string +} + +const Loader = ({ className }: LoaderProps ) => ( +
+ + + +
+) + export default function AsyncButton(props: AsyncButtonProps) { const [loading, setLoading] = useState(false); @@ -25,7 +47,8 @@ export default function AsyncButton(props: AsyncButtonProps) { return ( ); }