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,82 @@
|
|
|
1
|
+
import { cva } from "class-variance-authority";
|
|
2
|
+
import { cn } from "cn";
|
|
3
|
+
|
|
4
|
+
function Empty({ className, ...props }) {
|
|
5
|
+
return (
|
|
6
|
+
<div
|
|
7
|
+
data-slot="empty"
|
|
8
|
+
className={cn(
|
|
9
|
+
"flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-xl border-dashed p-6 text-center text-balance",
|
|
10
|
+
className,
|
|
11
|
+
)}
|
|
12
|
+
{...props}
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function EmptyHeader({ className, ...props }) {
|
|
18
|
+
return (
|
|
19
|
+
<div data-slot="empty-header" className={cn("flex max-w-sm flex-col items-center gap-2", className)} {...props} />
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const emptyMediaVariants = cva(
|
|
24
|
+
"mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
25
|
+
{
|
|
26
|
+
variants: {
|
|
27
|
+
variant: {
|
|
28
|
+
default: "bg-transparent",
|
|
29
|
+
icon: "flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-4",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
defaultVariants: {
|
|
33
|
+
variant: "default",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
function EmptyMedia({ className, variant = "default", ...props }) {
|
|
39
|
+
return (
|
|
40
|
+
<div
|
|
41
|
+
data-slot="empty-icon"
|
|
42
|
+
data-variant={variant}
|
|
43
|
+
className={cn(emptyMediaVariants({ variant, className }))}
|
|
44
|
+
{...props}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function EmptyTitle({ className, ...props }) {
|
|
50
|
+
return (
|
|
51
|
+
<div
|
|
52
|
+
data-slot="empty-title"
|
|
53
|
+
className={cn("font-heading text-sm font-medium tracking-tight", className)}
|
|
54
|
+
{...props}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function EmptyDescription({ className, ...props }) {
|
|
60
|
+
return (
|
|
61
|
+
<div
|
|
62
|
+
data-slot="empty-description"
|
|
63
|
+
className={cn(
|
|
64
|
+
"text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",
|
|
65
|
+
className,
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function EmptyContent({ className, ...props }) {
|
|
73
|
+
return (
|
|
74
|
+
<div
|
|
75
|
+
data-slot="empty-content"
|
|
76
|
+
className={cn("flex w-full max-w-sm min-w-0 flex-col items-center gap-2.5 text-sm text-balance", className)}
|
|
77
|
+
{...props}
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { Empty, EmptyHeader, EmptyTitle, EmptyDescription, EmptyContent, EmptyMedia };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
|
|
5
|
+
function Input({ className, type, ...props }) {
|
|
6
|
+
return (
|
|
7
|
+
<InputPrimitive
|
|
8
|
+
type={type}
|
|
9
|
+
data-slot="input"
|
|
10
|
+
className={cn(
|
|
11
|
+
"h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-primary focus-visible:ring-3 focus-visible:ring-primary/12 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
12
|
+
className,
|
|
13
|
+
)}
|
|
14
|
+
{...props}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { Input };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "cn";
|
|
5
|
+
|
|
6
|
+
function Label({ className, ...props }) {
|
|
7
|
+
return (
|
|
8
|
+
<label
|
|
9
|
+
data-slot="label"
|
|
10
|
+
className={cn(
|
|
11
|
+
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
|
12
|
+
className,
|
|
13
|
+
)}
|
|
14
|
+
{...props}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { Label };
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Select as SelectPrimitive } from "@base-ui/react/select";
|
|
3
|
+
import { cn } from "cn";
|
|
4
|
+
import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react";
|
|
5
|
+
|
|
6
|
+
const Select = SelectPrimitive.Root;
|
|
7
|
+
|
|
8
|
+
function SelectGroup({ className, ...props }) {
|
|
9
|
+
return <SelectPrimitive.Group data-slot="select-group" className={cn("scroll-my-1 p-1", className)} {...props} />;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function SelectValue({ className, ...props }) {
|
|
13
|
+
return (
|
|
14
|
+
<SelectPrimitive.Value data-slot="select-value" className={cn("flex flex-1 text-left", className)} {...props} />
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function SelectTrigger({ className, size = "default", children, ...props }) {
|
|
19
|
+
return (
|
|
20
|
+
<SelectPrimitive.Trigger
|
|
21
|
+
data-slot="select-trigger"
|
|
22
|
+
data-size={size}
|
|
23
|
+
className={cn(
|
|
24
|
+
"flex w-fit items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-primary focus-visible:ring-3 focus-visible:ring-primary/12 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
25
|
+
className,
|
|
26
|
+
)}
|
|
27
|
+
{...props}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
<SelectPrimitive.Icon render={<ChevronDownIcon className="pointer-events-none size-4 text-muted-foreground" />} />
|
|
31
|
+
</SelectPrimitive.Trigger>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function SelectContent({
|
|
36
|
+
className,
|
|
37
|
+
children,
|
|
38
|
+
side = "bottom",
|
|
39
|
+
sideOffset = 4,
|
|
40
|
+
align = "center",
|
|
41
|
+
alignOffset = 0,
|
|
42
|
+
alignItemWithTrigger = true,
|
|
43
|
+
...props
|
|
44
|
+
}) {
|
|
45
|
+
return (
|
|
46
|
+
<SelectPrimitive.Portal>
|
|
47
|
+
<SelectPrimitive.Positioner
|
|
48
|
+
side={side}
|
|
49
|
+
sideOffset={sideOffset}
|
|
50
|
+
align={align}
|
|
51
|
+
alignOffset={alignOffset}
|
|
52
|
+
alignItemWithTrigger={alignItemWithTrigger}
|
|
53
|
+
className="isolate z-50"
|
|
54
|
+
>
|
|
55
|
+
<SelectPrimitive.Popup
|
|
56
|
+
data-slot="select-content"
|
|
57
|
+
data-align-trigger={alignItemWithTrigger}
|
|
58
|
+
className={cn(
|
|
59
|
+
"relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
|
60
|
+
className,
|
|
61
|
+
)}
|
|
62
|
+
{...props}
|
|
63
|
+
>
|
|
64
|
+
<SelectScrollUpButton />
|
|
65
|
+
<SelectPrimitive.List>{children}</SelectPrimitive.List>
|
|
66
|
+
<SelectScrollDownButton />
|
|
67
|
+
</SelectPrimitive.Popup>
|
|
68
|
+
</SelectPrimitive.Positioner>
|
|
69
|
+
</SelectPrimitive.Portal>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function SelectLabel({ className, ...props }) {
|
|
74
|
+
return (
|
|
75
|
+
<SelectPrimitive.GroupLabel
|
|
76
|
+
data-slot="select-label"
|
|
77
|
+
className={cn("px-1.5 py-1 text-xs text-muted-foreground", className)}
|
|
78
|
+
{...props}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function SelectItem({ className, children, ...props }) {
|
|
84
|
+
return (
|
|
85
|
+
<SelectPrimitive.Item
|
|
86
|
+
data-slot="select-item"
|
|
87
|
+
className={cn(
|
|
88
|
+
"relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
|
89
|
+
className,
|
|
90
|
+
)}
|
|
91
|
+
{...props}
|
|
92
|
+
>
|
|
93
|
+
<SelectPrimitive.ItemText className="flex flex-1 shrink-0 gap-2 whitespace-nowrap">
|
|
94
|
+
{children}
|
|
95
|
+
</SelectPrimitive.ItemText>
|
|
96
|
+
<SelectPrimitive.ItemIndicator
|
|
97
|
+
render={<span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center" />}
|
|
98
|
+
>
|
|
99
|
+
<CheckIcon className="pointer-events-none" />
|
|
100
|
+
</SelectPrimitive.ItemIndicator>
|
|
101
|
+
</SelectPrimitive.Item>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function SelectSeparator({ className, ...props }) {
|
|
106
|
+
return (
|
|
107
|
+
<SelectPrimitive.Separator
|
|
108
|
+
data-slot="select-separator"
|
|
109
|
+
className={cn("pointer-events-none -mx-1 my-1 h-px bg-border", className)}
|
|
110
|
+
{...props}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function SelectScrollUpButton({ className, ...props }) {
|
|
116
|
+
return (
|
|
117
|
+
<SelectPrimitive.ScrollUpArrow
|
|
118
|
+
data-slot="select-scroll-up-button"
|
|
119
|
+
className={cn(
|
|
120
|
+
"top-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",
|
|
121
|
+
className,
|
|
122
|
+
)}
|
|
123
|
+
{...props}
|
|
124
|
+
>
|
|
125
|
+
<ChevronUpIcon />
|
|
126
|
+
</SelectPrimitive.ScrollUpArrow>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function SelectScrollDownButton({ className, ...props }) {
|
|
131
|
+
return (
|
|
132
|
+
<SelectPrimitive.ScrollDownArrow
|
|
133
|
+
data-slot="select-scroll-down-button"
|
|
134
|
+
className={cn(
|
|
135
|
+
"bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",
|
|
136
|
+
className,
|
|
137
|
+
)}
|
|
138
|
+
{...props}
|
|
139
|
+
>
|
|
140
|
+
<ChevronDownIcon />
|
|
141
|
+
</SelectPrimitive.ScrollDownArrow>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export {
|
|
146
|
+
Select,
|
|
147
|
+
SelectContent,
|
|
148
|
+
SelectGroup,
|
|
149
|
+
SelectItem,
|
|
150
|
+
SelectLabel,
|
|
151
|
+
SelectScrollDownButton,
|
|
152
|
+
SelectScrollUpButton,
|
|
153
|
+
SelectSeparator,
|
|
154
|
+
SelectTrigger,
|
|
155
|
+
SelectValue,
|
|
156
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useTheme } from "next-themes";
|
|
4
|
+
import { Toaster as Sonner } from "sonner";
|
|
5
|
+
import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
const Toaster = ({ ...props }) => {
|
|
8
|
+
const { theme = "system" } = useTheme();
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<Sonner
|
|
12
|
+
theme={theme}
|
|
13
|
+
className="toaster group"
|
|
14
|
+
icons={{
|
|
15
|
+
success: <CircleCheckIcon className="size-4" />,
|
|
16
|
+
info: <InfoIcon className="size-4" />,
|
|
17
|
+
warning: <TriangleAlertIcon className="size-4" />,
|
|
18
|
+
error: <OctagonXIcon className="size-4" />,
|
|
19
|
+
loading: <Loader2Icon className="size-4 animate-spin" />,
|
|
20
|
+
}}
|
|
21
|
+
style={{
|
|
22
|
+
"--normal-bg": "var(--popover)",
|
|
23
|
+
"--normal-text": "var(--popover-foreground)",
|
|
24
|
+
"--normal-border": "var(--border)",
|
|
25
|
+
"--border-radius": "var(--radius)",
|
|
26
|
+
}}
|
|
27
|
+
toastOptions={{
|
|
28
|
+
classNames: {
|
|
29
|
+
toast: "cn-toast",
|
|
30
|
+
},
|
|
31
|
+
}}
|
|
32
|
+
{...props}
|
|
33
|
+
/>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { Toaster };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Switch as SwitchPrimitive } from "@base-ui/react/switch";
|
|
2
|
+
import { cn } from "cn";
|
|
3
|
+
|
|
4
|
+
function Switch({ className, size = "default", ...props }) {
|
|
5
|
+
return (
|
|
6
|
+
<SwitchPrimitive.Root
|
|
7
|
+
data-slot="switch"
|
|
8
|
+
data-size={size}
|
|
9
|
+
className={cn(
|
|
10
|
+
"peer group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-all outline-none group-has-[:focus-visible]/field-label:border-transparent group-has-[:focus-visible]/field-label:ring-0 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-[size=default]:h-[18.4px] data-[size=default]:w-[32px] data-[size=sm]:h-[14px] data-[size=sm]:w-[24px] dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:bg-primary data-unchecked:bg-input dark:data-unchecked:bg-input/80 data-disabled:cursor-not-allowed data-disabled:opacity-50",
|
|
11
|
+
className,
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
>
|
|
15
|
+
<SwitchPrimitive.Thumb
|
|
16
|
+
data-slot="switch-thumb"
|
|
17
|
+
className="pointer-events-none block rounded-full bg-background ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 group-data-[size=default]/switch:data-checked:translate-x-[calc(100%-2px)] group-data-[size=sm]/switch:data-checked:translate-x-[calc(100%-2px)] dark:data-checked:bg-primary-foreground group-data-[size=default]/switch:data-unchecked:translate-x-0 group-data-[size=sm]/switch:data-unchecked:translate-x-0 dark:data-unchecked:bg-foreground"
|
|
18
|
+
/>
|
|
19
|
+
</SwitchPrimitive.Root>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { Switch };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "cn";
|
|
5
|
+
|
|
6
|
+
function Table({ className, ...props }) {
|
|
7
|
+
return (
|
|
8
|
+
<div data-slot="table-container" className="relative w-full">
|
|
9
|
+
<table data-slot="table" className={cn("w-full caption-bottom text-sm", className)} {...props} />
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function TableHeader({ className, ...props }) {
|
|
15
|
+
return <thead data-slot="table-header" className={cn("[&_tr]:border-b", className)} {...props} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function TableBody({ className, ...props }) {
|
|
19
|
+
return <tbody data-slot="table-body" className={cn("[&_tr:last-child]:border-0", className)} {...props} />;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function TableFooter({ className, ...props }) {
|
|
23
|
+
return (
|
|
24
|
+
<tfoot
|
|
25
|
+
data-slot="table-footer"
|
|
26
|
+
className={cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function TableRow({ className, ...props }) {
|
|
33
|
+
return (
|
|
34
|
+
<tr
|
|
35
|
+
data-slot="table-row"
|
|
36
|
+
className={cn(
|
|
37
|
+
"border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",
|
|
38
|
+
className,
|
|
39
|
+
)}
|
|
40
|
+
{...props}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function TableHead({ className, ...props }) {
|
|
46
|
+
return (
|
|
47
|
+
<th
|
|
48
|
+
data-slot="table-head"
|
|
49
|
+
className={cn(
|
|
50
|
+
"h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
|
|
51
|
+
className,
|
|
52
|
+
)}
|
|
53
|
+
{...props}
|
|
54
|
+
/>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function TableCell({ className, ...props }) {
|
|
59
|
+
return (
|
|
60
|
+
<td
|
|
61
|
+
data-slot="table-cell"
|
|
62
|
+
className={cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className)}
|
|
63
|
+
{...props}
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function TableCaption({ className, ...props }) {
|
|
69
|
+
return (
|
|
70
|
+
<caption data-slot="table-caption" className={cn("mt-4 text-sm text-muted-foreground", className)} {...props} />
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { cn } from "cn";
|
|
2
|
+
|
|
3
|
+
function Textarea({ className, ...props }) {
|
|
4
|
+
return (
|
|
5
|
+
<textarea
|
|
6
|
+
data-slot="textarea"
|
|
7
|
+
className={cn(
|
|
8
|
+
"flex min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-primary focus-visible:ring-3 focus-visible:ring-primary/12 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
9
|
+
className,
|
|
10
|
+
)}
|
|
11
|
+
{...props}
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { Textarea };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const APP_NAME = import.meta.env.VITE_APP_NAME || "React Project";
|
|
2
|
+
export const IS_PRODUCTION = import.meta.env.VITE_IS_PRODUCTION === "true";
|
|
3
|
+
|
|
4
|
+
export const BASE_URL = import.meta.env.VITE_BASE_URL || "";
|
|
5
|
+
export const API_SECRET = import.meta.env.VITE_API_SECRET || "";
|
|
6
|
+
|
|
7
|
+
export const getToken = () => localStorage.getItem("access_token");
|
|
8
|
+
export const setToken = (token) => localStorage.setItem("access_token", token);
|
|
9
|
+
|
|
10
|
+
export const getUser = () => JSON.parse(localStorage.getItem("user"));
|
|
11
|
+
export const setUser = (user) => localStorage.setItem("user", JSON.stringify(user));
|
|
12
|
+
export const getUserName = () => getUser()?.full_name || "DEMO";
|
|
13
|
+
export const getUserSymbol = () => getUser()?.full_name?.charAt(0) || "D";
|
|
14
|
+
export const getUserRole = () => getUser()?.role_name || "Admin";
|
|
15
|
+
|
|
16
|
+
export const getCurrentTime = () => Date.now();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
const ThemeProviderContext = createContext({
|
|
4
|
+
theme: "system",
|
|
5
|
+
setTheme: () => null,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export function ThemeProvider({ children, defaultTheme = "light", storageKey = "theme", ...props }) {
|
|
9
|
+
const [theme, setTheme] = useState(() => localStorage.getItem(storageKey) || defaultTheme);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const root = window.document.documentElement;
|
|
13
|
+
root.classList.remove("light", "dark");
|
|
14
|
+
|
|
15
|
+
if (theme === "system") {
|
|
16
|
+
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
17
|
+
|
|
18
|
+
root.classList.add(systemTheme);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
root.classList.add(theme);
|
|
23
|
+
}, [theme]);
|
|
24
|
+
|
|
25
|
+
const value = {
|
|
26
|
+
theme,
|
|
27
|
+
setTheme: (theme) => {
|
|
28
|
+
localStorage.setItem(storageKey, theme);
|
|
29
|
+
setTheme(theme);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<ThemeProviderContext.Provider {...props} value={value}>
|
|
35
|
+
{children}
|
|
36
|
+
</ThemeProviderContext.Provider>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const useTheme = () => {
|
|
41
|
+
const context = useContext(ThemeProviderContext);
|
|
42
|
+
|
|
43
|
+
if (context === undefined) {
|
|
44
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return context;
|
|
48
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { PackagePlus, SquarePen } from "lucide-react";
|
|
3
|
+
import DialogComponent from "@/components/common/DialogComponent";
|
|
4
|
+
import { COMPONENT_CATEGORIES, COMPONENT_TAGS } from "@/features/components/mockData";
|
|
5
|
+
|
|
6
|
+
const EMPTY_FORM = {
|
|
7
|
+
name: "",
|
|
8
|
+
path: "src/components/",
|
|
9
|
+
category: "Common",
|
|
10
|
+
tags: [],
|
|
11
|
+
description: "",
|
|
12
|
+
status: "Stable",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const toOptions = (items) => items.map((item) => ({ value: item, label: item }));
|
|
16
|
+
const CATEGORY_OPTIONS = toOptions(COMPONENT_CATEGORIES);
|
|
17
|
+
const TAG_OPTIONS = toOptions(COMPONENT_TAGS);
|
|
18
|
+
|
|
19
|
+
const PATH_PATTERN = /^src\/[\w./-]+\.(jsx?|tsx?)$/;
|
|
20
|
+
const MAX_DESCRIPTION_LENGTH = 160;
|
|
21
|
+
|
|
22
|
+
const validate = (form, { components, currentId }) => {
|
|
23
|
+
const errors = {};
|
|
24
|
+
const others = components.filter((c) => c.id !== currentId);
|
|
25
|
+
const name = form.name.trim();
|
|
26
|
+
const path = form.path.trim();
|
|
27
|
+
|
|
28
|
+
if (!name) errors.name = "Name is required";
|
|
29
|
+
else if (others.some((c) => c.name.toLowerCase() === name.toLowerCase()))
|
|
30
|
+
errors.name = "A component with this name already exists";
|
|
31
|
+
|
|
32
|
+
if (!path) errors.path = "File path is required";
|
|
33
|
+
else if (!PATH_PATTERN.test(path)) errors.path = "Use a path like src/components/common/Name.jsx";
|
|
34
|
+
|
|
35
|
+
if (form.tags.length === 0) errors.tags = "Add at least one tag";
|
|
36
|
+
|
|
37
|
+
if (form.description.trim().length > MAX_DESCRIPTION_LENGTH)
|
|
38
|
+
errors.description = `Keep it under ${MAX_DESCRIPTION_LENGTH} characters`;
|
|
39
|
+
|
|
40
|
+
return errors;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const ComponentFormDialog = ({ open, onOpenChange, component, components, onSubmit }) => {
|
|
44
|
+
const isEdit = Boolean(component);
|
|
45
|
+
const [form, setForm] = useState(() =>
|
|
46
|
+
component
|
|
47
|
+
? {
|
|
48
|
+
name: component.name,
|
|
49
|
+
path: component.path,
|
|
50
|
+
category: component.category,
|
|
51
|
+
tags: component.tags,
|
|
52
|
+
description: component.description,
|
|
53
|
+
status: component.status,
|
|
54
|
+
}
|
|
55
|
+
: EMPTY_FORM,
|
|
56
|
+
);
|
|
57
|
+
const [errors, setErrors] = useState({});
|
|
58
|
+
|
|
59
|
+
const setField = (name, value) => {
|
|
60
|
+
setForm((prev) => ({ ...prev, [name]: value }));
|
|
61
|
+
setErrors((prev) => ({ ...prev, [name]: undefined }));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const handleSubmit = (e) => {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
const nextErrors = validate(form, { components, currentId: component?.id });
|
|
67
|
+
if (Object.keys(nextErrors).length) {
|
|
68
|
+
setErrors(nextErrors);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
onSubmit({
|
|
72
|
+
...form,
|
|
73
|
+
name: form.name.trim(),
|
|
74
|
+
path: form.path.trim(),
|
|
75
|
+
description: form.description.trim(),
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<DialogComponent
|
|
81
|
+
open={open}
|
|
82
|
+
onOpenChange={onOpenChange}
|
|
83
|
+
title={isEdit ? "Edit component" : "Add component"}
|
|
84
|
+
description={isEdit ? "Update this component's details." : "Add a component to the catalog."}
|
|
85
|
+
icon={isEdit ? SquarePen : PackagePlus}
|
|
86
|
+
size="lg"
|
|
87
|
+
onSubmit={handleSubmit}
|
|
88
|
+
>
|
|
89
|
+
<DialogComponent.Section columns={2}>
|
|
90
|
+
<DialogComponent.Field
|
|
91
|
+
label="Name"
|
|
92
|
+
name="name"
|
|
93
|
+
placeholder="e.g. Pagination"
|
|
94
|
+
required
|
|
95
|
+
autoComplete="off"
|
|
96
|
+
value={form.name}
|
|
97
|
+
onChange={(e) => setField("name", e.target.value)}
|
|
98
|
+
error={errors.name}
|
|
99
|
+
/>
|
|
100
|
+
<DialogComponent.Field
|
|
101
|
+
label="Category"
|
|
102
|
+
name="category"
|
|
103
|
+
type="select"
|
|
104
|
+
options={CATEGORY_OPTIONS}
|
|
105
|
+
value={form.category}
|
|
106
|
+
onValueChange={(value) => setField("category", value || form.category)}
|
|
107
|
+
/>
|
|
108
|
+
<DialogComponent.Field
|
|
109
|
+
label="File path"
|
|
110
|
+
name="path"
|
|
111
|
+
placeholder="src/components/common/Name.jsx"
|
|
112
|
+
required
|
|
113
|
+
autoComplete="off"
|
|
114
|
+
value={form.path}
|
|
115
|
+
onChange={(e) => setField("path", e.target.value)}
|
|
116
|
+
error={errors.path}
|
|
117
|
+
className="sm:col-span-2"
|
|
118
|
+
/>
|
|
119
|
+
<DialogComponent.Field
|
|
120
|
+
label="Tags"
|
|
121
|
+
name="tags"
|
|
122
|
+
type="multi-select"
|
|
123
|
+
placeholder="Select one or more tags"
|
|
124
|
+
required
|
|
125
|
+
options={TAG_OPTIONS}
|
|
126
|
+
value={form.tags}
|
|
127
|
+
onValueChange={(value) => setField("tags", value)}
|
|
128
|
+
error={errors.tags}
|
|
129
|
+
className="sm:col-span-2"
|
|
130
|
+
/>
|
|
131
|
+
<DialogComponent.Field
|
|
132
|
+
label="Description"
|
|
133
|
+
name="description"
|
|
134
|
+
type="textarea"
|
|
135
|
+
placeholder="What does this component do?"
|
|
136
|
+
value={form.description}
|
|
137
|
+
onChange={(e) => setField("description", e.target.value)}
|
|
138
|
+
error={errors.description}
|
|
139
|
+
className="sm:col-span-2"
|
|
140
|
+
/>
|
|
141
|
+
<DialogComponent.Field
|
|
142
|
+
type="switch"
|
|
143
|
+
label="Stable"
|
|
144
|
+
name="status"
|
|
145
|
+
description={
|
|
146
|
+
form.status === "Stable" ? "Ready to use in production." : "Marked as Beta. The API may still change."
|
|
147
|
+
}
|
|
148
|
+
checked={form.status === "Stable"}
|
|
149
|
+
onCheckedChange={(checked) => setField("status", checked ? "Stable" : "Beta")}
|
|
150
|
+
className="sm:col-span-2"
|
|
151
|
+
/>
|
|
152
|
+
</DialogComponent.Section>
|
|
153
|
+
|
|
154
|
+
<DialogComponent.Footer
|
|
155
|
+
onCancel={() => onOpenChange(false)}
|
|
156
|
+
submitLabel={isEdit ? "Save changes" : "Add component"}
|
|
157
|
+
/>
|
|
158
|
+
</DialogComponent>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export default ComponentFormDialog;
|