react-groundwork 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +6 -0
- package/.gitattributes +2 -0
- package/.prettierignore +7 -0
- package/.prettierrc.json +12 -0
- package/README.md +24 -2
- package/cli/index.js +119 -0
- package/components.json +25 -0
- package/eslint.config.js +17 -0
- package/index.html +13 -0
- package/jsconfig.json +8 -0
- package/package.json +111 -4
- package/public/.htaccess +11 -0
- package/public/logo.png +0 -0
- package/src/App.jsx +14 -0
- package/src/api/api.routes.js +12 -0
- package/src/api/api.services.js +8 -0
- package/src/api/apiCall.js +128 -0
- package/src/api/apiHelpers.js +20 -0
- package/src/assets/css/index.css +173 -0
- package/src/assets/images/placeholders/placeholder-170x166.png +0 -0
- package/src/assets/images/placeholders/placeholder-360x260.png +0 -0
- package/src/assets/images/placeholders/placeholder-372x225.png +0 -0
- package/src/assets/images/placeholders/placeholder-40x40.png +0 -0
- package/src/assets/images/placeholders/placeholder-451x392.png +0 -0
- package/src/components/common/AppChart.jsx +56 -0
- package/src/components/common/Breadcrumbs.jsx +90 -0
- package/src/components/common/DataTable.jsx +203 -0
- package/src/components/common/DatePicker.jsx +275 -0
- package/src/components/common/DialogComponent.jsx +308 -0
- package/src/components/common/ErrorStateComponent.jsx +46 -0
- package/src/components/common/FullscreenToggle.jsx +54 -0
- package/src/components/common/HeadingComponent.jsx +29 -0
- package/src/components/common/LoadingComponent.jsx +33 -0
- package/src/components/common/NetworkStatus.jsx +103 -0
- package/src/components/common/NoDataComponent.jsx +45 -0
- package/src/components/common/Pagination.jsx +128 -0
- package/src/components/common/ParagraphComponent.jsx +14 -0
- package/src/components/common/PhoneInputComponent.jsx +242 -0
- package/src/components/common/ReactSelect.jsx +145 -0
- package/src/components/common/SearchSelect.jsx +176 -0
- package/src/components/common/SeeMore.jsx +26 -0
- package/src/components/common/SortableHeader.jsx +23 -0
- package/src/components/common/theme-toggle.jsx +39 -0
- package/src/components/layout/AuthLayout.jsx +90 -0
- package/src/components/layout/PageLayout.jsx +32 -0
- package/src/components/layout/SidebarLayout.jsx +233 -0
- package/src/components/ui/avatar.jsx +84 -0
- package/src/components/ui/badge.jsx +43 -0
- package/src/components/ui/button.jsx +44 -0
- package/src/components/ui/card.jsx +69 -0
- package/src/components/ui/checkbox.jsx +25 -0
- package/src/components/ui/dialog.jsx +149 -0
- package/src/components/ui/empty.jsx +82 -0
- package/src/components/ui/input.jsx +19 -0
- package/src/components/ui/label.jsx +19 -0
- package/src/components/ui/select.jsx +156 -0
- package/src/components/ui/skeleton.jsx +7 -0
- package/src/components/ui/sonner.jsx +37 -0
- package/src/components/ui/switch.jsx +23 -0
- package/src/components/ui/table.jsx +74 -0
- package/src/components/ui/textarea.jsx +16 -0
- package/src/constants/constant.js +16 -0
- package/src/context/theme-provider.jsx +48 -0
- package/src/features/components/ComponentFormDialog.jsx +162 -0
- package/src/features/components/ComponentsTable.jsx +219 -0
- package/src/features/components/componentStyles.js +16 -0
- package/src/features/components/mockData.js +407 -0
- package/src/features/playground/BasicsSection.jsx +122 -0
- package/src/features/playground/DataSection.jsx +210 -0
- package/src/features/playground/DemoCard.jsx +21 -0
- package/src/features/playground/FeedbackSection.jsx +309 -0
- package/src/features/playground/FormsSection.jsx +188 -0
- package/src/features/playground/UtilitiesSection.jsx +200 -0
- package/src/hooks/useApiHandler.jsx +82 -0
- package/src/hooks/useDebounce.js +12 -0
- package/src/lib/utils.js +1 -0
- package/src/main.jsx +16 -0
- package/src/pages/auth/ForgotPasswordPage.jsx +101 -0
- package/src/pages/auth/LoginPage.jsx +120 -0
- package/src/pages/auth/SignupPage.jsx +135 -0
- package/src/pages/views/ComponentsPage.jsx +316 -0
- package/src/pages/views/DashboardPage.jsx +260 -0
- package/src/pages/views/LandingPage.jsx +772 -0
- package/src/pages/views/NotFoundPage.jsx +30 -0
- package/src/pages/views/PlaygroundPage.jsx +50 -0
- package/src/routes/AppRoutes.jsx +29 -0
- package/src/routes/ProtectedRoute.jsx +18 -0
- package/src/utils/exportCsv.js +17 -0
- package/src/utils/formatCurrency.js +19 -0
- package/src/utils/formatDateTime.js +34 -0
- package/src/utils/handleSessionExpire.js +22 -0
- package/src/utils/logger.js +34 -0
- package/vite.config.js +23 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { ArrowRight, Loader2, Plus, Settings, Trash2 } from "lucide-react";
|
|
3
|
+
import { Button } from "@/components/ui/button";
|
|
4
|
+
import { Badge } from "@/components/ui/badge";
|
|
5
|
+
import HeadingComponent from "@/components/common/HeadingComponent";
|
|
6
|
+
import ParagraphComponent from "@/components/common/ParagraphComponent";
|
|
7
|
+
import SeeMore from "@/components/common/SeeMore";
|
|
8
|
+
import DemoCard from "@/features/playground/DemoCard";
|
|
9
|
+
|
|
10
|
+
const BUTTON_VARIANTS = ["default", "secondary", "outline", "ghost", "destructive", "link"];
|
|
11
|
+
const BADGE_VARIANTS = ["default", "secondary", "outline", "destructive", "ghost", "link"];
|
|
12
|
+
|
|
13
|
+
const LONG_TEXT =
|
|
14
|
+
"This template gives every new project the same starting point: routing with protected routes, a central API layer with toasts and session handling, a themeable component kit, layouts for the app and auth screens, and helpers for dates, currency and CSV export. Keep what you need and delete the rest.";
|
|
15
|
+
|
|
16
|
+
const BasicsSection = () => {
|
|
17
|
+
const [saving, setSaving] = useState(false);
|
|
18
|
+
|
|
19
|
+
const fakeSave = () => {
|
|
20
|
+
setSaving(true);
|
|
21
|
+
setTimeout(() => setSaving(false), 1500);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div className="grid grid-cols-1 gap-4 xl:grid-cols-3">
|
|
26
|
+
<DemoCard
|
|
27
|
+
title="Button"
|
|
28
|
+
description="Variants, sizes, icons and a loading state."
|
|
29
|
+
file="src/components/ui/button.jsx"
|
|
30
|
+
className="xl:col-span-2"
|
|
31
|
+
contentClassName="space-y-4"
|
|
32
|
+
>
|
|
33
|
+
<div className="flex flex-wrap gap-2">
|
|
34
|
+
{BUTTON_VARIANTS.map((variant) => (
|
|
35
|
+
<Button key={variant} variant={variant} className="capitalize">
|
|
36
|
+
{variant}
|
|
37
|
+
</Button>
|
|
38
|
+
))}
|
|
39
|
+
</div>
|
|
40
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
41
|
+
<Button size="xs">Extra small</Button>
|
|
42
|
+
<Button size="sm">Small</Button>
|
|
43
|
+
<Button>Default</Button>
|
|
44
|
+
<Button size="lg">Large</Button>
|
|
45
|
+
<Button size="icon" variant="outline" title="Settings">
|
|
46
|
+
<Settings />
|
|
47
|
+
</Button>
|
|
48
|
+
<Button size="icon-sm" variant="destructive" title="Delete">
|
|
49
|
+
<Trash2 />
|
|
50
|
+
</Button>
|
|
51
|
+
</div>
|
|
52
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
53
|
+
<Button>
|
|
54
|
+
<Plus />
|
|
55
|
+
With icon
|
|
56
|
+
</Button>
|
|
57
|
+
<Button variant="outline">
|
|
58
|
+
Continue
|
|
59
|
+
<ArrowRight />
|
|
60
|
+
</Button>
|
|
61
|
+
<Button onClick={fakeSave} disabled={saving}>
|
|
62
|
+
{saving && <Loader2 className="animate-spin" />}
|
|
63
|
+
{saving ? "Saving..." : "Click to load"}
|
|
64
|
+
</Button>
|
|
65
|
+
<Button disabled>Disabled</Button>
|
|
66
|
+
</div>
|
|
67
|
+
</DemoCard>
|
|
68
|
+
|
|
69
|
+
<DemoCard title="Badge" description="Small labels for status and counts." file="src/components/ui/badge.jsx">
|
|
70
|
+
<div className="flex flex-wrap gap-2">
|
|
71
|
+
{BADGE_VARIANTS.map((variant) => (
|
|
72
|
+
<Badge key={variant} variant={variant} className="capitalize">
|
|
73
|
+
{variant}
|
|
74
|
+
</Badge>
|
|
75
|
+
))}
|
|
76
|
+
</div>
|
|
77
|
+
</DemoCard>
|
|
78
|
+
|
|
79
|
+
<DemoCard
|
|
80
|
+
title="HeadingComponent"
|
|
81
|
+
description="Title, subtitle and actions in three sizes."
|
|
82
|
+
file="src/components/common/HeadingComponent.jsx"
|
|
83
|
+
contentClassName="space-y-4"
|
|
84
|
+
>
|
|
85
|
+
<HeadingComponent title="Page heading" subtitle="Used at the top of a page" size="page" />
|
|
86
|
+
<HeadingComponent
|
|
87
|
+
title="Section heading"
|
|
88
|
+
subtitle="With an action on the right"
|
|
89
|
+
size="section"
|
|
90
|
+
actions={
|
|
91
|
+
<Button size="sm" variant="outline">
|
|
92
|
+
Action
|
|
93
|
+
</Button>
|
|
94
|
+
}
|
|
95
|
+
/>
|
|
96
|
+
<HeadingComponent title="Small heading" subtitle="For cards and lists" size="sm" />
|
|
97
|
+
</DemoCard>
|
|
98
|
+
|
|
99
|
+
<DemoCard
|
|
100
|
+
title="ParagraphComponent"
|
|
101
|
+
description="Text styles that follow the theme."
|
|
102
|
+
file="src/components/common/ParagraphComponent.jsx"
|
|
103
|
+
contentClassName="space-y-2"
|
|
104
|
+
>
|
|
105
|
+
<ParagraphComponent variant="lead">Lead text for introductions.</ParagraphComponent>
|
|
106
|
+
<ParagraphComponent>Default body text.</ParagraphComponent>
|
|
107
|
+
<ParagraphComponent variant="muted">Muted text for secondary details.</ParagraphComponent>
|
|
108
|
+
<ParagraphComponent variant="small">Small text for hints and captions.</ParagraphComponent>
|
|
109
|
+
</DemoCard>
|
|
110
|
+
|
|
111
|
+
<DemoCard
|
|
112
|
+
title="SeeMore"
|
|
113
|
+
description="Shortens long text with a toggle."
|
|
114
|
+
file="src/components/common/SeeMore.jsx"
|
|
115
|
+
>
|
|
116
|
+
<SeeMore text={LONG_TEXT} limit={110} />
|
|
117
|
+
</DemoCard>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default BasicsSection;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { toast } from "sonner";
|
|
3
|
+
import { Eye, Pencil, Trash2 } from "lucide-react";
|
|
4
|
+
import DataTable from "@/components/common/DataTable";
|
|
5
|
+
import Pagination from "@/components/common/Pagination";
|
|
6
|
+
import AppChart from "@/components/common/AppChart";
|
|
7
|
+
import { CategoryBadge, StatusBadge } from "@/features/components/ComponentsTable";
|
|
8
|
+
import DemoCard from "@/features/playground/DemoCard";
|
|
9
|
+
import { COMPONENT_CATEGORIES, COMPONENT_STATUSES, INITIAL_COMPONENTS } from "@/features/components/mockData";
|
|
10
|
+
|
|
11
|
+
const TABLE_PAGE_SIZE = 5;
|
|
12
|
+
|
|
13
|
+
const COLUMNS = [
|
|
14
|
+
{ key: "name", label: "Name", sortable: true, render: (row) => <span className="font-medium">{row.name}</span> },
|
|
15
|
+
{ key: "category", label: "Category", sortable: true, render: (row) => <CategoryBadge category={row.category} /> },
|
|
16
|
+
{ key: "status", label: "Status", sortable: true, render: (row) => <StatusBadge status={row.status} /> },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const ROW_ACTIONS = [
|
|
20
|
+
{ key: "view", label: "View", icon: Eye, onClick: (row) => toast.info(`Viewing ${row.name}`) },
|
|
21
|
+
{ key: "edit", label: "Edit", icon: Pencil, onClick: (row) => toast.info(`Editing ${row.name}`) },
|
|
22
|
+
{
|
|
23
|
+
key: "delete",
|
|
24
|
+
label: "Delete",
|
|
25
|
+
icon: Trash2,
|
|
26
|
+
tone: "destructive",
|
|
27
|
+
onClick: (row) => toast.error(`Deleted ${row.name}`),
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const CHART_COLORS = ["#3B7BF5", "#737373", "#8F8F8F", "#A8A8A8", "#C2C2C2", "#DADADA"];
|
|
32
|
+
const AXIS = {
|
|
33
|
+
grid: { color: "rgba(115, 115, 115, 0.15)" },
|
|
34
|
+
border: { display: false },
|
|
35
|
+
ticks: { color: "#8A8A8A", font: { size: 11 }, precision: 0 },
|
|
36
|
+
};
|
|
37
|
+
const CARTESIAN_OPTIONS = {
|
|
38
|
+
plugins: { legend: { display: false } },
|
|
39
|
+
scales: { x: { ...AXIS, grid: { display: false } }, y: { ...AXIS, beginAtZero: true } },
|
|
40
|
+
};
|
|
41
|
+
const ROUND_OPTIONS = {
|
|
42
|
+
plugins: { legend: { position: "bottom", labels: { color: "#8A8A8A", boxWidth: 10, font: { size: 11 } } } },
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const categoryCounts = COMPONENT_CATEGORIES.map((c) => INITIAL_COMPONENTS.filter((item) => item.category === c).length);
|
|
46
|
+
const statusCounts = COMPONENT_STATUSES.map((s) => INITIAL_COMPONENTS.filter((item) => item.status === s).length);
|
|
47
|
+
|
|
48
|
+
const monthKeys = [...new Set(INITIAL_COMPONENTS.map((item) => item.updatedAt.slice(0, 7)))].sort();
|
|
49
|
+
const updatesPerMonth = monthKeys.map(
|
|
50
|
+
(key) => INITIAL_COMPONENTS.filter((item) => item.updatedAt.startsWith(key)).length,
|
|
51
|
+
);
|
|
52
|
+
const monthLabels = monthKeys.map((key) => new Date(`${key}-01`).toLocaleString("en-US", { month: "short" }));
|
|
53
|
+
|
|
54
|
+
const CHARTS = [
|
|
55
|
+
{
|
|
56
|
+
type: "line",
|
|
57
|
+
title: "Line",
|
|
58
|
+
data: {
|
|
59
|
+
labels: monthLabels,
|
|
60
|
+
datasets: [
|
|
61
|
+
{
|
|
62
|
+
data: updatesPerMonth,
|
|
63
|
+
borderColor: CHART_COLORS[0],
|
|
64
|
+
pointBackgroundColor: CHART_COLORS[0],
|
|
65
|
+
tension: 0.4,
|
|
66
|
+
borderWidth: 2,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
options: CARTESIAN_OPTIONS,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: "bar",
|
|
74
|
+
title: "Bar",
|
|
75
|
+
data: {
|
|
76
|
+
labels: COMPONENT_CATEGORIES,
|
|
77
|
+
datasets: [{ data: categoryCounts, backgroundColor: CHART_COLORS[0], borderRadius: 6, maxBarThickness: 28 }],
|
|
78
|
+
},
|
|
79
|
+
options: CARTESIAN_OPTIONS,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: "pie",
|
|
83
|
+
title: "Pie",
|
|
84
|
+
data: {
|
|
85
|
+
labels: COMPONENT_CATEGORIES,
|
|
86
|
+
datasets: [{ data: categoryCounts, backgroundColor: CHART_COLORS, borderWidth: 0 }],
|
|
87
|
+
},
|
|
88
|
+
options: ROUND_OPTIONS,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: "doughnut",
|
|
92
|
+
title: "Doughnut",
|
|
93
|
+
data: {
|
|
94
|
+
labels: COMPONENT_STATUSES,
|
|
95
|
+
datasets: [{ data: statusCounts, backgroundColor: [CHART_COLORS[0], CHART_COLORS[3]], borderWidth: 0 }],
|
|
96
|
+
},
|
|
97
|
+
options: { ...ROUND_OPTIONS, cutout: "68%" },
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
const DataSection = () => {
|
|
102
|
+
const [search, setSearch] = useState("");
|
|
103
|
+
const [sortBy, setSortBy] = useState("name");
|
|
104
|
+
const [sortOrder, setSortOrder] = useState("asc");
|
|
105
|
+
const [page, setPage] = useState(1);
|
|
106
|
+
const [loading, setLoading] = useState(false);
|
|
107
|
+
|
|
108
|
+
const q = search.trim().toLowerCase();
|
|
109
|
+
const rows = INITIAL_COMPONENTS.filter((item) => item.name.toLowerCase().includes(q)).sort((a, b) => {
|
|
110
|
+
const result = String(a[sortBy]).localeCompare(String(b[sortBy]));
|
|
111
|
+
return sortOrder === "asc" ? result : -result;
|
|
112
|
+
});
|
|
113
|
+
const totalPages = Math.max(1, Math.ceil(rows.length / TABLE_PAGE_SIZE));
|
|
114
|
+
const currentPage = Math.min(page, totalPages);
|
|
115
|
+
const pageRows = rows.slice((currentPage - 1) * TABLE_PAGE_SIZE, currentPage * TABLE_PAGE_SIZE);
|
|
116
|
+
|
|
117
|
+
const handleSort = (key) => {
|
|
118
|
+
if (key === sortBy) setSortOrder((prev) => (prev === "asc" ? "desc" : "asc"));
|
|
119
|
+
else {
|
|
120
|
+
setSortBy(key);
|
|
121
|
+
setSortOrder("asc");
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const reload = () => {
|
|
126
|
+
setLoading(true);
|
|
127
|
+
setTimeout(() => setLoading(false), 1200);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div className="grid grid-cols-1 gap-4 xl:grid-cols-2">
|
|
132
|
+
<DemoCard
|
|
133
|
+
title="DataTable"
|
|
134
|
+
description="Search, sortable headers, row actions, loading state and page buttons."
|
|
135
|
+
file="src/components/common/DataTable.jsx"
|
|
136
|
+
>
|
|
137
|
+
<DataTable
|
|
138
|
+
card={false}
|
|
139
|
+
title="Components"
|
|
140
|
+
subtitle="Uses SortableHeader and Pagination inside"
|
|
141
|
+
headerActions={
|
|
142
|
+
<button type="button" onClick={reload} className="text-xs font-medium text-primary hover:underline">
|
|
143
|
+
Reload
|
|
144
|
+
</button>
|
|
145
|
+
}
|
|
146
|
+
searchValue={search}
|
|
147
|
+
onSearchChange={(value) => {
|
|
148
|
+
setSearch(value);
|
|
149
|
+
setPage(1);
|
|
150
|
+
}}
|
|
151
|
+
searchPlaceholder="Search by name"
|
|
152
|
+
resultsLabel={`${rows.length} results`}
|
|
153
|
+
columns={COLUMNS}
|
|
154
|
+
data={pageRows}
|
|
155
|
+
rowActions={ROW_ACTIONS}
|
|
156
|
+
loading={loading}
|
|
157
|
+
sortBy={sortBy}
|
|
158
|
+
sortOrder={sortOrder}
|
|
159
|
+
onSort={handleSort}
|
|
160
|
+
page={currentPage}
|
|
161
|
+
totalPages={totalPages}
|
|
162
|
+
onPageChange={setPage}
|
|
163
|
+
bodyHeight="22rem"
|
|
164
|
+
emptyTitle="No components match"
|
|
165
|
+
emptyDescription="Try a different search term."
|
|
166
|
+
/>
|
|
167
|
+
</DemoCard>
|
|
168
|
+
|
|
169
|
+
<DemoCard
|
|
170
|
+
title="Pagination"
|
|
171
|
+
description="Give it a list and it handles pages, rows per page and the summary."
|
|
172
|
+
file="src/components/common/Pagination.jsx"
|
|
173
|
+
contentClassName="flex flex-col overflow-hidden rounded-b-xl p-0"
|
|
174
|
+
>
|
|
175
|
+
<Pagination items={INITIAL_COMPONENTS} label="components">
|
|
176
|
+
{(items) => (
|
|
177
|
+
<ul className="max-h-88 min-h-0 flex-1 divide-y divide-border overflow-y-auto border-t border-border">
|
|
178
|
+
{items.map((item) => (
|
|
179
|
+
<li key={item.id} className="flex items-center justify-between gap-3 px-4 py-2.5">
|
|
180
|
+
<div className="min-w-0">
|
|
181
|
+
<p className="truncate text-sm font-medium">{item.name}</p>
|
|
182
|
+
<p className="truncate font-mono text-[11px] text-muted-foreground">{item.path}</p>
|
|
183
|
+
</div>
|
|
184
|
+
<CategoryBadge category={item.category} />
|
|
185
|
+
</li>
|
|
186
|
+
))}
|
|
187
|
+
</ul>
|
|
188
|
+
)}
|
|
189
|
+
</Pagination>
|
|
190
|
+
</DemoCard>
|
|
191
|
+
|
|
192
|
+
<DemoCard
|
|
193
|
+
title="AppChart"
|
|
194
|
+
description="One wrapper for line, bar, pie and doughnut charts."
|
|
195
|
+
file="src/components/common/AppChart.jsx"
|
|
196
|
+
className="xl:col-span-2"
|
|
197
|
+
contentClassName="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-4"
|
|
198
|
+
>
|
|
199
|
+
{CHARTS.map((chart) => (
|
|
200
|
+
<div key={chart.type} className="min-w-0">
|
|
201
|
+
<p className="mb-2 text-xs font-medium text-muted-foreground">{chart.title}</p>
|
|
202
|
+
<AppChart type={chart.type} data={chart.data} options={chart.options} height={200} />
|
|
203
|
+
</div>
|
|
204
|
+
))}
|
|
205
|
+
</DemoCard>
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export default DataSection;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FileCode2 } from "lucide-react";
|
|
2
|
+
import { cn } from "@/lib/utils";
|
|
3
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
4
|
+
|
|
5
|
+
const DemoCard = ({ title, description, file, className, contentClassName, children }) => (
|
|
6
|
+
<Card className={cn("min-w-0", className)}>
|
|
7
|
+
<CardHeader>
|
|
8
|
+
<CardTitle>{title}</CardTitle>
|
|
9
|
+
{description && <CardDescription>{description}</CardDescription>}
|
|
10
|
+
{file && (
|
|
11
|
+
<p className="mt-1 inline-flex w-fit max-w-full items-center gap-1 rounded-md bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground">
|
|
12
|
+
<FileCode2 className="h-3 w-3 shrink-0" />
|
|
13
|
+
<span className="truncate">{file}</span>
|
|
14
|
+
</p>
|
|
15
|
+
)}
|
|
16
|
+
</CardHeader>
|
|
17
|
+
<CardContent className={contentClassName}>{children}</CardContent>
|
|
18
|
+
</Card>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export default DemoCard;
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { toast } from "sonner";
|
|
3
|
+
import { PackagePlus, SearchX } from "lucide-react";
|
|
4
|
+
import { Button } from "@/components/ui/button";
|
|
5
|
+
import { Skeleton } from "@/components/ui/skeleton";
|
|
6
|
+
import {
|
|
7
|
+
Avatar,
|
|
8
|
+
AvatarBadge,
|
|
9
|
+
AvatarFallback,
|
|
10
|
+
AvatarGroup,
|
|
11
|
+
AvatarGroupCount,
|
|
12
|
+
AvatarImage,
|
|
13
|
+
} from "@/components/ui/avatar";
|
|
14
|
+
import DialogComponent from "@/components/common/DialogComponent";
|
|
15
|
+
import LoadingComponent from "@/components/common/LoadingComponent";
|
|
16
|
+
import NoDataComponent from "@/components/common/NoDataComponent";
|
|
17
|
+
import ErrorStateComponent from "@/components/common/ErrorStateComponent";
|
|
18
|
+
import DemoCard from "@/features/playground/DemoCard";
|
|
19
|
+
import { COMPONENT_CATEGORIES, COMPONENT_TAGS } from "@/features/components/mockData";
|
|
20
|
+
import placeholderImage from "@/assets/images/placeholders/placeholder-40x40.png";
|
|
21
|
+
|
|
22
|
+
const toOptions = (items) => items.map((item) => ({ value: item, label: item }));
|
|
23
|
+
const CATEGORY_OPTIONS = toOptions(COMPONENT_CATEGORIES);
|
|
24
|
+
const TAG_OPTIONS = toOptions(COMPONENT_TAGS);
|
|
25
|
+
|
|
26
|
+
const EMPTY_FORM = { name: "", category: "Common", tags: [], releaseDate: "", owner: "", notes: "", stable: true };
|
|
27
|
+
|
|
28
|
+
const FormDialogDemo = () => {
|
|
29
|
+
const [open, setOpen] = useState(false);
|
|
30
|
+
const [form, setForm] = useState(EMPTY_FORM);
|
|
31
|
+
const [error, setError] = useState("");
|
|
32
|
+
const [saving, setSaving] = useState(false);
|
|
33
|
+
|
|
34
|
+
const setField = (name, value) => setForm((prev) => ({ ...prev, [name]: value }));
|
|
35
|
+
|
|
36
|
+
const openDialog = () => {
|
|
37
|
+
setForm(EMPTY_FORM);
|
|
38
|
+
setError("");
|
|
39
|
+
setOpen(true);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const handleSubmit = (e) => {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
if (!form.name.trim()) {
|
|
45
|
+
setError("Name is required");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
setSaving(true);
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
setSaving(false);
|
|
51
|
+
setOpen(false);
|
|
52
|
+
toast.success(`"${form.name.trim()}" saved.`);
|
|
53
|
+
}, 1000);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<Button onClick={openDialog}>
|
|
59
|
+
<PackagePlus />
|
|
60
|
+
Open form dialog
|
|
61
|
+
</Button>
|
|
62
|
+
<DialogComponent
|
|
63
|
+
open={open}
|
|
64
|
+
onOpenChange={setOpen}
|
|
65
|
+
title="Add component"
|
|
66
|
+
description="Every field type that DialogComponent.Field supports."
|
|
67
|
+
icon={PackagePlus}
|
|
68
|
+
size="lg"
|
|
69
|
+
loading={saving}
|
|
70
|
+
onSubmit={handleSubmit}
|
|
71
|
+
>
|
|
72
|
+
<DialogComponent.Section title="Details" columns={2}>
|
|
73
|
+
<DialogComponent.Field
|
|
74
|
+
label="Name"
|
|
75
|
+
name="pg-dialog-name"
|
|
76
|
+
placeholder="e.g. Pagination"
|
|
77
|
+
required
|
|
78
|
+
value={form.name}
|
|
79
|
+
onChange={(e) => {
|
|
80
|
+
setField("name", e.target.value);
|
|
81
|
+
setError("");
|
|
82
|
+
}}
|
|
83
|
+
error={error}
|
|
84
|
+
/>
|
|
85
|
+
<DialogComponent.Field
|
|
86
|
+
label="Category"
|
|
87
|
+
name="pg-dialog-category"
|
|
88
|
+
type="select"
|
|
89
|
+
options={CATEGORY_OPTIONS}
|
|
90
|
+
value={form.category}
|
|
91
|
+
onValueChange={(value) => setField("category", value || form.category)}
|
|
92
|
+
/>
|
|
93
|
+
<DialogComponent.Field
|
|
94
|
+
label="Tags"
|
|
95
|
+
name="pg-dialog-tags"
|
|
96
|
+
type="multi-select"
|
|
97
|
+
placeholder="Select tags"
|
|
98
|
+
options={TAG_OPTIONS}
|
|
99
|
+
value={form.tags}
|
|
100
|
+
onValueChange={(value) => setField("tags", value)}
|
|
101
|
+
className="sm:col-span-2"
|
|
102
|
+
/>
|
|
103
|
+
<DialogComponent.Field
|
|
104
|
+
label="Release date"
|
|
105
|
+
name="pg-dialog-date"
|
|
106
|
+
type="date"
|
|
107
|
+
value={form.releaseDate}
|
|
108
|
+
onValueChange={(value) => setField("releaseDate", value)}
|
|
109
|
+
/>
|
|
110
|
+
<DialogComponent.Field
|
|
111
|
+
label="Owner"
|
|
112
|
+
name="pg-dialog-owner"
|
|
113
|
+
type="select-list"
|
|
114
|
+
options={[
|
|
115
|
+
{ value: "frontend", label: "Frontend team" },
|
|
116
|
+
{ value: "design", label: "Design team" },
|
|
117
|
+
]}
|
|
118
|
+
value={form.owner}
|
|
119
|
+
onValueChange={(value) => setField("owner", value)}
|
|
120
|
+
placeholder="Choose a team"
|
|
121
|
+
/>
|
|
122
|
+
</DialogComponent.Section>
|
|
123
|
+
<DialogComponent.Section title="More">
|
|
124
|
+
<DialogComponent.Field
|
|
125
|
+
label="Notes"
|
|
126
|
+
name="pg-dialog-notes"
|
|
127
|
+
type="textarea"
|
|
128
|
+
placeholder="Anything worth knowing?"
|
|
129
|
+
value={form.notes}
|
|
130
|
+
onChange={(e) => setField("notes", e.target.value)}
|
|
131
|
+
/>
|
|
132
|
+
<DialogComponent.Field
|
|
133
|
+
type="switch"
|
|
134
|
+
label="Stable"
|
|
135
|
+
name="pg-dialog-stable"
|
|
136
|
+
description="Turn off to mark it as Beta."
|
|
137
|
+
checked={form.stable}
|
|
138
|
+
onCheckedChange={(checked) => setField("stable", checked)}
|
|
139
|
+
/>
|
|
140
|
+
</DialogComponent.Section>
|
|
141
|
+
<DialogComponent.Footer
|
|
142
|
+
onCancel={() => setOpen(false)}
|
|
143
|
+
submitLabel="Save"
|
|
144
|
+
loading={saving}
|
|
145
|
+
loadingLabel="Saving..."
|
|
146
|
+
/>
|
|
147
|
+
</DialogComponent>
|
|
148
|
+
</>
|
|
149
|
+
);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const ConfirmDialogDemo = () => {
|
|
153
|
+
const [open, setOpen] = useState(false);
|
|
154
|
+
const [deleting, setDeleting] = useState(false);
|
|
155
|
+
|
|
156
|
+
const handleConfirm = () => {
|
|
157
|
+
setDeleting(true);
|
|
158
|
+
setTimeout(() => {
|
|
159
|
+
setDeleting(false);
|
|
160
|
+
setOpen(false);
|
|
161
|
+
toast.success("Component deleted.");
|
|
162
|
+
}, 1000);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<>
|
|
167
|
+
<Button variant="destructive" onClick={() => setOpen(true)}>
|
|
168
|
+
Open confirm dialog
|
|
169
|
+
</Button>
|
|
170
|
+
<DialogComponent.Confirm
|
|
171
|
+
open={open}
|
|
172
|
+
onOpenChange={setOpen}
|
|
173
|
+
title="Delete component?"
|
|
174
|
+
description='"Pagination" will be removed from the catalog. This can’t be undone.'
|
|
175
|
+
onConfirm={handleConfirm}
|
|
176
|
+
loading={deleting}
|
|
177
|
+
loadingLabel="Deleting..."
|
|
178
|
+
/>
|
|
179
|
+
</>
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const STATES = ["loading", "empty", "error"];
|
|
184
|
+
|
|
185
|
+
const FeedbackSection = () => {
|
|
186
|
+
const [state, setState] = useState("loading");
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3">
|
|
190
|
+
<DemoCard
|
|
191
|
+
title="DialogComponent"
|
|
192
|
+
description="Form dialog and confirm dialog with loading states."
|
|
193
|
+
file="src/components/common/DialogComponent.jsx"
|
|
194
|
+
contentClassName="flex flex-wrap gap-2"
|
|
195
|
+
>
|
|
196
|
+
<FormDialogDemo />
|
|
197
|
+
<ConfirmDialogDemo />
|
|
198
|
+
</DemoCard>
|
|
199
|
+
|
|
200
|
+
<DemoCard
|
|
201
|
+
title="Toasts"
|
|
202
|
+
description="Sonner toasts, the same ones apiCall() shows."
|
|
203
|
+
file="src/components/ui/sonner.jsx"
|
|
204
|
+
contentClassName="flex flex-wrap gap-2"
|
|
205
|
+
>
|
|
206
|
+
<Button variant="outline" onClick={() => toast.success("Changes saved.")}>
|
|
207
|
+
Success
|
|
208
|
+
</Button>
|
|
209
|
+
<Button variant="outline" onClick={() => toast.error("Something went wrong. Please try again.")}>
|
|
210
|
+
Error
|
|
211
|
+
</Button>
|
|
212
|
+
<Button variant="outline" onClick={() => toast.info("A new version is available.")}>
|
|
213
|
+
Info
|
|
214
|
+
</Button>
|
|
215
|
+
<Button
|
|
216
|
+
variant="outline"
|
|
217
|
+
onClick={() =>
|
|
218
|
+
toast.promise(new Promise((resolve) => setTimeout(resolve, 1500)), {
|
|
219
|
+
loading: "Uploading...",
|
|
220
|
+
success: "Upload complete.",
|
|
221
|
+
error: "Upload failed.",
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
>
|
|
225
|
+
Promise
|
|
226
|
+
</Button>
|
|
227
|
+
</DemoCard>
|
|
228
|
+
|
|
229
|
+
<DemoCard
|
|
230
|
+
title="Avatar and Skeleton"
|
|
231
|
+
description="Profile images, fallbacks and loading placeholders."
|
|
232
|
+
file="src/components/ui/avatar.jsx"
|
|
233
|
+
contentClassName="space-y-5"
|
|
234
|
+
>
|
|
235
|
+
<div className="flex items-center gap-4">
|
|
236
|
+
<Avatar size="lg">
|
|
237
|
+
<AvatarImage src={placeholderImage} alt="Placeholder" />
|
|
238
|
+
<AvatarFallback>RP</AvatarFallback>
|
|
239
|
+
</Avatar>
|
|
240
|
+
<Avatar>
|
|
241
|
+
<AvatarFallback>UI</AvatarFallback>
|
|
242
|
+
<AvatarBadge className="bg-emerald-500" />
|
|
243
|
+
</Avatar>
|
|
244
|
+
<AvatarGroup>
|
|
245
|
+
<Avatar size="sm">
|
|
246
|
+
<AvatarFallback>A</AvatarFallback>
|
|
247
|
+
</Avatar>
|
|
248
|
+
<Avatar size="sm">
|
|
249
|
+
<AvatarFallback>B</AvatarFallback>
|
|
250
|
+
</Avatar>
|
|
251
|
+
<Avatar size="sm">
|
|
252
|
+
<AvatarFallback>C</AvatarFallback>
|
|
253
|
+
</Avatar>
|
|
254
|
+
<AvatarGroupCount>+4</AvatarGroupCount>
|
|
255
|
+
</AvatarGroup>
|
|
256
|
+
</div>
|
|
257
|
+
<div className="flex items-center gap-3">
|
|
258
|
+
<Skeleton className="size-10 rounded-full" />
|
|
259
|
+
<div className="flex-1 space-y-2">
|
|
260
|
+
<Skeleton className="h-3 w-3/4" />
|
|
261
|
+
<Skeleton className="h-3 w-1/2" />
|
|
262
|
+
</div>
|
|
263
|
+
</div>
|
|
264
|
+
</DemoCard>
|
|
265
|
+
|
|
266
|
+
<DemoCard
|
|
267
|
+
title="Loading, empty and error states"
|
|
268
|
+
description="LoadingComponent, NoDataComponent and ErrorStateComponent."
|
|
269
|
+
file="src/components/common/"
|
|
270
|
+
className="md:col-span-2 xl:col-span-3"
|
|
271
|
+
contentClassName="space-y-3"
|
|
272
|
+
>
|
|
273
|
+
<div className="inline-flex rounded-lg bg-muted p-1">
|
|
274
|
+
{STATES.map((item) => (
|
|
275
|
+
<button
|
|
276
|
+
key={item}
|
|
277
|
+
type="button"
|
|
278
|
+
onClick={() => setState(item)}
|
|
279
|
+
className={
|
|
280
|
+
state === item
|
|
281
|
+
? "rounded-md bg-card px-3 py-1.5 text-xs font-medium capitalize shadow-sm"
|
|
282
|
+
: "rounded-md px-3 py-1.5 text-xs font-medium text-muted-foreground capitalize hover:text-foreground"
|
|
283
|
+
}
|
|
284
|
+
>
|
|
285
|
+
{item}
|
|
286
|
+
</button>
|
|
287
|
+
))}
|
|
288
|
+
</div>
|
|
289
|
+
<div className="rounded-xl border border-dashed border-border">
|
|
290
|
+
{state === "loading" && <LoadingComponent label="Loading components..." />}
|
|
291
|
+
{state === "empty" && (
|
|
292
|
+
<NoDataComponent
|
|
293
|
+
icon={SearchX}
|
|
294
|
+
title="No components found"
|
|
295
|
+
description="Try a different search term."
|
|
296
|
+
actionLabel="Clear search"
|
|
297
|
+
onAction={() => toast.info("Search cleared.")}
|
|
298
|
+
/>
|
|
299
|
+
)}
|
|
300
|
+
{state === "error" && (
|
|
301
|
+
<ErrorStateComponent description="We couldn't load the catalog." onRetry={() => setState("loading")} />
|
|
302
|
+
)}
|
|
303
|
+
</div>
|
|
304
|
+
</DemoCard>
|
|
305
|
+
</div>
|
|
306
|
+
);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
export default FeedbackSection;
|