Skip to content

Commit 00f6a05

Browse files
CopilotTechQuery
andcommitted
Add Loading component based on Idea-React reference
Co-authored-by: TechQuery <[email protected]>
1 parent 86e4f81 commit 00f6a05

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

app/page.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FilePickerExample } from "@/registry/new-york/blocks/file-picker/exampl
77
import { FilePreviewExample } from "@/registry/new-york/blocks/file-preview/example";
88
import { FormFieldExample } from "@/registry/new-york/blocks/form-field/example";
99
import { ImagePreviewExample } from "@/registry/new-york/blocks/image-preview/example";
10+
import LoadingExample from "@/registry/new-york/blocks/loading/example";
1011
import { PagerExample } from "@/registry/new-york/blocks/pager/example";
1112
import { RangeInputExample } from "@/registry/new-york/blocks/range-input/example";
1213
import { RestTableExample } from "@/registry/new-york/blocks/rest-table/example";
@@ -33,6 +34,13 @@ export default function Home() {
3334
<SpinnerExample />
3435
</ComponentCard>
3536

37+
<ComponentCard
38+
name="loading"
39+
description="A full-screen loading overlay component with spinner and customizable message."
40+
>
41+
<LoadingExample />
42+
</ComponentCard>
43+
3644
<ComponentCard
3745
name="badge-bar"
3846
description="A component for displaying a list of badges with optional click and delete handlers."

registry.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
}
1717
]
1818
},
19+
{
20+
"name": "loading",
21+
"type": "registry:component",
22+
"title": "Loading",
23+
"description": "A full-screen loading overlay component with spinner and customizable message.",
24+
"registryDependencies": ["@mobx-restful-shadcn/spinner"],
25+
"files": [
26+
{
27+
"type": "registry:component",
28+
"path": "registry/new-york/blocks/loading/index.tsx",
29+
"target": "components/ui/mobx-restful-shadcn/loading/index.tsx"
30+
}
31+
]
32+
},
1933
{
2034
"name": "badge-bar",
2135
"type": "registry:component",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use client";
2+
3+
import { useState } from "react";
4+
5+
import { Button } from "@/components/ui/button";
6+
import { Loading } from ".";
7+
8+
export default function LoadingExample() {
9+
const [isLoading, setIsLoading] = useState(false);
10+
11+
return (
12+
<div className="flex flex-col gap-4 items-center p-8">
13+
<Button onClick={() => setIsLoading(!isLoading)}>
14+
{isLoading ? "Hide Loading" : "Show Loading"}
15+
</Button>
16+
17+
<p className="text-sm text-muted-foreground">
18+
Click the button to toggle the full-screen loading overlay
19+
</p>
20+
21+
{isLoading && (
22+
<Loading>
23+
<span>Please wait...</span>
24+
</Loading>
25+
)}
26+
</div>
27+
);
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FC, HTMLAttributes, ReactNode } from "react";
2+
3+
import { cn } from "@/lib/utils";
4+
import { Spinner } from "../spinner";
5+
6+
export interface LoadingProps extends HTMLAttributes<HTMLDivElement> {
7+
children?: ReactNode;
8+
}
9+
10+
export const Loading: FC<LoadingProps> = ({
11+
className,
12+
children = "Loading...",
13+
...props
14+
}) => (
15+
<div
16+
className={cn(
17+
"fixed inset-0 z-50 flex h-full w-full items-center justify-center bg-black/25",
18+
className,
19+
)}
20+
{...props}
21+
>
22+
<div className="flex items-center gap-3">
23+
<Spinner className="text-primary" />
24+
{children && <span className="text-white">{children}</span>}
25+
</div>
26+
</div>
27+
);
28+
29+
Loading.displayName = "Loading";

0 commit comments

Comments
 (0)