Skip to content

Commit 6a7dccd

Browse files
authored
Merge pull request #149 from kleros/feat/button-loading
feat: button-loading
2 parents 3433d89 + 8e557e1 commit 6a7dccd

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"use client";
2+
import { cn } from "@/lib/utils";
3+
import { useLocale, useTranslations } from "next-intl";
4+
import Image from "next/image";
5+
import { useFormStatus } from "react-dom";
6+
import { getLangDir } from "rtl-detect";
7+
8+
const FormSubmitButton: React.FC = () => {
9+
const { pending } = useFormStatus();
10+
11+
const t = useTranslations("landing");
12+
const tLoading = useTranslations("loading");
13+
const locale = useLocale();
14+
const langDir = getLangDir(locale);
15+
16+
return (
17+
<button
18+
type="submit"
19+
className={cn(
20+
"bg-primary-blue h-10",
21+
{
22+
"rounded-r": langDir === "ltr",
23+
"rounded-l": langDir === "rtl",
24+
},
25+
"text-base text-white-background font-semibold",
26+
"px-4 flex gap-2 justify-center items-center",
27+
!pending && "hover:bg-secondary-blue transition cursor-pointer",
28+
pending && "bg-stroke animate-pulse",
29+
)}
30+
disabled={pending}
31+
>
32+
<Image src="/search.svg" alt="Search" width="16" height="16" />
33+
{pending ? tLoading("title") : t("button")}
34+
</button>
35+
);
36+
};
37+
38+
export default FormSubmitButton;

src/app/[locale]/page.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import clsx from "clsx";
44
import { useLocale, useTranslations } from "next-intl";
5-
import Image from "next/image";
65
import { getLangDir } from "rtl-detect";
76

87
import { useRouter } from "@/i18n/routing";
8+
import FormSubmitButton from "./components/FormSubmitButton";
99

1010
const Home: React.FC = () => {
1111
const t = useTranslations("landing");
@@ -60,22 +60,7 @@ const Home: React.FC = () => {
6060
#
6161
</span>
6262
</div>
63-
<button
64-
type="submit"
65-
className={clsx(
66-
"bg-primary-blue h-10",
67-
{
68-
"rounded-r": langDir === "ltr",
69-
"rounded-l": langDir === "rtl",
70-
},
71-
"text-base text-white-background font-semibold",
72-
"px-4 flex gap-2 justify-center items-center",
73-
"hover:bg-secondary-blue transition",
74-
)}
75-
>
76-
<Image src="/search.svg" alt="Search" width="16" height="16" />
77-
{t("button")}
78-
</button>
63+
<FormSubmitButton />
7964
</form>
8065
</div>
8166
);

0 commit comments

Comments
 (0)