nexstruct 1.0.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/AGENTS.md +122 -0
- package/LICENSE +21 -0
- package/README.md +103 -0
- package/package.json +99 -0
- package/scaffold/generator.js +409 -0
- package/scaffold/index.js +20 -0
- package/scaffold/prompts.js +108 -0
- package/templates/api/axios/src/api/axios/client.api.ts +30 -0
- package/templates/api/axios/src/api/axios/users.api.ts +15 -0
- package/templates/api/fetch/src/api/fetch/client.api.ts +68 -0
- package/templates/api/fetch/src/api/fetch/users.api.ts +15 -0
- package/templates/api/trpc/src/api/trpc/client.api.ts +4 -0
- package/templates/api/trpc/src/api/trpc/router.api.ts +15 -0
- package/templates/api/trpc/src/api/trpc/server.client.api.ts +4 -0
- package/templates/api/trpc/src/providers/trpc.provider.tsx +24 -0
- package/templates/auth/clerk/src/auth/clerk/auth.service.ts +4 -0
- package/templates/auth/clerk/src/hooks/use-auth.hook.ts +13 -0
- package/templates/auth/clerk/src/middleware.ts +7 -0
- package/templates/auth/clerk/src/providers/auth.provider.tsx +6 -0
- package/templates/auth/next-auth/src/app/api/auth/[...nextauth]/route.ts +5 -0
- package/templates/auth/next-auth/src/auth/next-auth/auth.service.ts +45 -0
- package/templates/auth/next-auth/src/hooks/use-session.hook.ts +13 -0
- package/templates/auth/next-auth/src/providers/session.provider.tsx +6 -0
- package/templates/forms/formik/src/components/forms/login-form.component.tsx +30 -0
- package/templates/forms/formik/src/forms/formik/hooks/use-form-config.hook.ts +7 -0
- package/templates/forms/formik/src/forms/formik/schemas/example.schema.ts +8 -0
- package/templates/forms/react-hook-form/src/components/forms/login-form.component.tsx +27 -0
- package/templates/forms/react-hook-form/src/forms/react-hook-form/hooks/use-form.hook.ts +13 -0
- package/templates/forms/react-hook-form/src/forms/react-hook-form/schemas/example.schema.ts +15 -0
- package/templates/nextjs-base/next.config.ts +5 -0
- package/templates/nextjs-base/postcss.config.mjs +9 -0
- package/templates/nextjs-base/src/app/_components/navbar.tsx +88 -0
- package/templates/nextjs-base/src/app/_components/sidebar.tsx +223 -0
- package/templates/nextjs-base/src/app/error.tsx +39 -0
- package/templates/nextjs-base/src/app/globals.css +71 -0
- package/templates/nextjs-base/src/app/layout.tsx +21 -0
- package/templates/nextjs-base/src/app/loading.tsx +13 -0
- package/templates/nextjs-base/src/app/not-found.tsx +22 -0
- package/templates/nextjs-base/src/app/page.tsx +10 -0
- package/templates/nextjs-base/tailwind.config.ts +69 -0
- package/templates/shared/src/components/common/theme-toggle.component.tsx +31 -0
- package/templates/shared/src/components/common/toast/custom-message.component.tsx +18 -0
- package/templates/shared/src/components/common/toast/index.ts +8 -0
- package/templates/shared/src/components/common/toast/toast-message.component.tsx +112 -0
- package/templates/shared/src/hooks/use-debounce.hook.ts +12 -0
- package/templates/shared/src/hooks/use-fetch.hook.ts +42 -0
- package/templates/shared/src/hooks/use-intersection-observer.hook.ts +39 -0
- package/templates/shared/src/hooks/use-local-storage.hook.ts +30 -0
- package/templates/shared/src/hooks/use-media-query.hook.ts +26 -0
- package/templates/shared/src/hooks/use-toggle.hook.ts +12 -0
- package/templates/shared/src/lib/utils.util.ts +361 -0
- package/templates/shared/src/providers/theme.provider.tsx +17 -0
- package/templates/shared/src/providers/toast.provider.tsx +32 -0
- package/templates/shared/src/types/common.type.ts +34 -0
- package/templates/state/context/src/store/context/auth.context.tsx +47 -0
- package/templates/state/context/src/store/context/counter.context.tsx +41 -0
- package/templates/state/context/src/store/context/index.ts +2 -0
- package/templates/state/redux/src/providers/redux.provider.tsx +7 -0
- package/templates/state/redux/src/store/redux/hooks.store.ts +5 -0
- package/templates/state/redux/src/store/redux/index.ts +4 -0
- package/templates/state/redux/src/store/redux/slices/api.slice.ts +8 -0
- package/templates/state/redux/src/store/redux/slices/counter.slice.ts +24 -0
- package/templates/state/redux/src/store/redux/store.store.ts +13 -0
- package/templates/state/zustand/src/store/zustand/counter.store.ts +15 -0
- package/templates/state/zustand/src/store/zustand/index.ts +2 -0
- package/templates/state/zustand/src/store/zustand/user.store.ts +32 -0
- package/templates/ui/antd/COMPONENT_GUIDE.md +326 -0
- package/templates/ui/antd/src/app/examples/dialog/page.tsx +205 -0
- package/templates/ui/antd/src/app/examples/form/page.tsx +160 -0
- package/templates/ui/antd/src/app/examples/layout.tsx +125 -0
- package/templates/ui/antd/src/app/examples/page.tsx +64 -0
- package/templates/ui/antd/src/app/examples/table/page.tsx +118 -0
- package/templates/ui/antd/src/app/page.tsx +283 -0
- package/templates/ui/antd/src/components/common/DynamicTable/dynamic-table.component.tsx +79 -0
- package/templates/ui/antd/src/components/common/button/action-button.component.tsx +63 -0
- package/templates/ui/antd/src/components/common/dialog/dialog-wrapper.component.tsx +63 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/check-field.component.tsx +55 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/date-picker-field.component.tsx +80 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/limit-field.component.tsx +26 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/multi-check-field.component.tsx +56 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/number-field.component.tsx +100 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/otp-field.component.tsx +63 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/password-field.component.tsx +106 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/phone-number-field.component.tsx +78 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/radio-field.component.tsx +55 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/range-date-picker.component.tsx +66 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/search-field.component.tsx +24 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/select-field.component.tsx +82 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/single-check-field.component.tsx +50 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/single-select-field.component.tsx +86 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/string-number-field.component.tsx +80 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/switch-field.component.tsx +62 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/text-area-field.component.tsx +85 -0
- package/templates/ui/antd/src/components/common/fields/assets/components/text-field.component.tsx +88 -0
- package/templates/ui/antd/src/components/common/fields/assets/interface/input-props.type.ts +233 -0
- package/templates/ui/antd/src/components/common/fields/cusInputField.component.tsx +40 -0
- package/templates/ui/antd/src/components/common/pagination/pagination.component.tsx +27 -0
- package/templates/ui/antd/src/components/ui/avatar.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/badge.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/button.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/card.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/checkbox.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/dialog.component.tsx +9 -0
- package/templates/ui/antd/src/components/ui/dropdown-menu.component.tsx +10 -0
- package/templates/ui/antd/src/components/ui/form.component.tsx +12 -0
- package/templates/ui/antd/src/components/ui/input.component.tsx +13 -0
- package/templates/ui/antd/src/components/ui/label.component.tsx +18 -0
- package/templates/ui/antd/src/components/ui/popover.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/progress.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/radio-group.component.tsx +10 -0
- package/templates/ui/antd/src/components/ui/scroll-area.component.tsx +25 -0
- package/templates/ui/antd/src/components/ui/select.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/separator.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/sheet.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/switch.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/table.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/tabs.component.tsx +8 -0
- package/templates/ui/antd/src/components/ui/textarea.component.tsx +9 -0
- package/templates/ui/antd/src/components/ui/tooltip.component.tsx +8 -0
- package/templates/ui/antd/src/lib/theme.util.ts +40 -0
- package/templates/ui/antd/src/providers/antd.provider.tsx +13 -0
- package/templates/ui/mui/src/app/examples/layout.tsx +113 -0
- package/templates/ui/mui/src/app/examples/page.tsx +716 -0
- package/templates/ui/mui/src/app/page.tsx +298 -0
- package/templates/ui/mui/src/components/common/DynamicTable/dynamic-table.component.tsx +131 -0
- package/templates/ui/mui/src/components/common/button/action-button.component.tsx +57 -0
- package/templates/ui/mui/src/components/common/dialog/dialog-wrapper.component.tsx +55 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/check-field.component.tsx +51 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/date-picker-field.component.tsx +50 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/multi-check-field.component.tsx +14 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/number-field.component.tsx +59 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/password-field.component.tsx +87 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/phone-number-field.component.tsx +48 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/radio-field.component.tsx +37 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/search-field.component.tsx +41 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/select-field.component.tsx +77 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/single-check-field.component.tsx +39 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/single-select-field.component.tsx +56 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/string-number-field.component.tsx +52 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/switch-field.component.tsx +35 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/text-area-field.component.tsx +46 -0
- package/templates/ui/mui/src/components/common/fields/assets/components/text-field.component.tsx +51 -0
- package/templates/ui/mui/src/components/common/fields/assets/interface/input-props.type.ts +193 -0
- package/templates/ui/mui/src/components/common/fields/cusInputField.component.tsx +34 -0
- package/templates/ui/mui/src/components/common/pagination/pagination.component.tsx +59 -0
- package/templates/ui/mui/src/components/ui/avatar.component.tsx +19 -0
- package/templates/ui/mui/src/components/ui/badge.component.tsx +18 -0
- package/templates/ui/mui/src/components/ui/button.component.tsx +22 -0
- package/templates/ui/mui/src/components/ui/card.component.tsx +39 -0
- package/templates/ui/mui/src/components/ui/checkbox.component.tsx +21 -0
- package/templates/ui/mui/src/components/ui/dialog.component.tsx +38 -0
- package/templates/ui/mui/src/components/ui/dropdown-menu.component.tsx +43 -0
- package/templates/ui/mui/src/components/ui/form.component.tsx +98 -0
- package/templates/ui/mui/src/components/ui/input.component.tsx +15 -0
- package/templates/ui/mui/src/components/ui/label.component.tsx +15 -0
- package/templates/ui/mui/src/components/ui/popover.component.tsx +20 -0
- package/templates/ui/mui/src/components/ui/progress.component.tsx +19 -0
- package/templates/ui/mui/src/components/ui/radio-group.component.tsx +25 -0
- package/templates/ui/mui/src/components/ui/scroll-area.component.tsx +27 -0
- package/templates/ui/mui/src/components/ui/select.component.tsx +26 -0
- package/templates/ui/mui/src/components/ui/separator.component.tsx +11 -0
- package/templates/ui/mui/src/components/ui/sheet.component.tsx +44 -0
- package/templates/ui/mui/src/components/ui/switch.component.tsx +23 -0
- package/templates/ui/mui/src/components/ui/table.component.tsx +34 -0
- package/templates/ui/mui/src/components/ui/tabs.component.tsx +38 -0
- package/templates/ui/mui/src/components/ui/textarea.component.tsx +18 -0
- package/templates/ui/mui/src/components/ui/tooltip.component.tsx +24 -0
- package/templates/ui/mui/src/lib/theme.util.ts +73 -0
- package/templates/ui/mui/src/providers/mui.provider.tsx +13 -0
- package/templates/ui/shadcn/COMPONENT_GUIDE.md +306 -0
- package/templates/ui/shadcn/src/app/examples/dialog/page.tsx +122 -0
- package/templates/ui/shadcn/src/app/examples/form/page.tsx +107 -0
- package/templates/ui/shadcn/src/app/examples/layout.tsx +24 -0
- package/templates/ui/shadcn/src/app/examples/page.tsx +30 -0
- package/templates/ui/shadcn/src/app/examples/table/page.tsx +77 -0
- package/templates/ui/shadcn/src/app/page.tsx +20 -0
- package/templates/ui/shadcn/src/components/common/DynamicTable/dynamic-table.component.tsx +136 -0
- package/templates/ui/shadcn/src/components/common/button/action-button.component.tsx +68 -0
- package/templates/ui/shadcn/src/components/common/dialog/dialog-wrapper.component.tsx +58 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/check-field.component.tsx +52 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/date-picker-field.component.tsx +62 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/dynamic-file-upload-field.component.tsx +152 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/limit-field.component.tsx +73 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/multi-check-field.component.tsx +46 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/number-field.component.tsx +124 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/otp-field.component.tsx +61 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/password-field.component.tsx +110 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/phone-number-field.component.tsx +90 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/radio-field.component.tsx +41 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/range-date-picker.component.tsx +71 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/rich-text-editor.component.tsx +91 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/search-field.component.tsx +34 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/select-field.component.tsx +231 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/single-check-field.component.tsx +42 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/single-select-field.component.tsx +82 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/string-number-field.component.tsx +68 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/switch-field.component.tsx +61 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/text-area-field.component.tsx +62 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/text-area-with-file.component.tsx +142 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/text-field.component.tsx +80 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/tiny-editor.component.tsx +51 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/upload-profile-picture.component.tsx +103 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/components/upload-video-file.component.tsx +86 -0
- package/templates/ui/shadcn/src/components/common/fields/assets/interface/input-props.type.ts +198 -0
- package/templates/ui/shadcn/src/components/common/fields/cusInputField.component.tsx +52 -0
- package/templates/ui/shadcn/src/components/common/pagination/pagination.component.tsx +68 -0
- package/templates/ui/shadcn/src/components/ui/avatar.component.tsx +37 -0
- package/templates/ui/shadcn/src/components/ui/badge.component.tsx +28 -0
- package/templates/ui/shadcn/src/components/ui/button.component.tsx +52 -0
- package/templates/ui/shadcn/src/components/ui/card.component.tsx +46 -0
- package/templates/ui/shadcn/src/components/ui/checkbox.component.tsx +25 -0
- package/templates/ui/shadcn/src/components/ui/dialog.component.tsx +98 -0
- package/templates/ui/shadcn/src/components/ui/dropdown-menu.component.tsx +163 -0
- package/templates/ui/shadcn/src/components/ui/form.component.tsx +110 -0
- package/templates/ui/shadcn/src/components/ui/input-otp.component.tsx +64 -0
- package/templates/ui/shadcn/src/components/ui/input.component.tsx +23 -0
- package/templates/ui/shadcn/src/components/ui/label.component.tsx +23 -0
- package/templates/ui/shadcn/src/components/ui/popover.component.tsx +27 -0
- package/templates/ui/shadcn/src/components/ui/progress.component.tsx +22 -0
- package/templates/ui/shadcn/src/components/ui/radio-group.component.tsx +33 -0
- package/templates/ui/shadcn/src/components/ui/scroll-area.component.tsx +37 -0
- package/templates/ui/shadcn/src/components/ui/select.component.tsx +139 -0
- package/templates/ui/shadcn/src/components/ui/separator.component.tsx +23 -0
- package/templates/ui/shadcn/src/components/ui/sheet.component.tsx +89 -0
- package/templates/ui/shadcn/src/components/ui/switch.component.tsx +26 -0
- package/templates/ui/shadcn/src/components/ui/table.component.tsx +71 -0
- package/templates/ui/shadcn/src/components/ui/tabs.component.tsx +52 -0
- package/templates/ui/shadcn/src/components/ui/textarea.component.tsx +20 -0
- package/templates/ui/shadcn/src/components/ui/tooltip.component.tsx +25 -0
package/templates/ui/shadcn/src/components/common/fields/assets/components/check-field.component.tsx
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form.component';
|
|
2
|
+
import { Checkbox } from '@/components/ui/checkbox.component';
|
|
3
|
+
import type { CheckboxProps } from '../interface/input-props.type';
|
|
4
|
+
|
|
5
|
+
export const CheckField = ({
|
|
6
|
+
form, name, labelName, required = false, disabled = false, options = [],
|
|
7
|
+
}: CheckboxProps & { options: { label: string; value: string }[] }) => {
|
|
8
|
+
if (!form) return null;
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<FormField
|
|
12
|
+
control={form.control}
|
|
13
|
+
name={name}
|
|
14
|
+
render={() => (
|
|
15
|
+
<FormItem>
|
|
16
|
+
{labelName && (
|
|
17
|
+
<label className="font-semibold leading-6 text-[14px] tracking-[0.02em]">
|
|
18
|
+
{labelName}
|
|
19
|
+
{required && <span className="text-destructive"> *</span>}
|
|
20
|
+
</label>
|
|
21
|
+
)}
|
|
22
|
+
{options.map((opt) => (
|
|
23
|
+
<FormField
|
|
24
|
+
key={opt.value}
|
|
25
|
+
control={form.control}
|
|
26
|
+
name={name}
|
|
27
|
+
render={({ field }) => (
|
|
28
|
+
<div className="flex items-center space-x-2">
|
|
29
|
+
<FormControl>
|
|
30
|
+
<Checkbox
|
|
31
|
+
checked={field.value?.includes(opt.value)}
|
|
32
|
+
onCheckedChange={(checked) => {
|
|
33
|
+
const current = field.value || [];
|
|
34
|
+
const updated = checked
|
|
35
|
+
? [...current, opt.value]
|
|
36
|
+
: current.filter((v: string) => v !== opt.value);
|
|
37
|
+
field.onChange(updated);
|
|
38
|
+
}}
|
|
39
|
+
disabled={disabled}
|
|
40
|
+
/>
|
|
41
|
+
</FormControl>
|
|
42
|
+
<FormLabel className="font-normal">{opt.label}</FormLabel>
|
|
43
|
+
</div>
|
|
44
|
+
)}
|
|
45
|
+
/>
|
|
46
|
+
))}
|
|
47
|
+
<FormMessage />
|
|
48
|
+
</FormItem>
|
|
49
|
+
)}
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form.component';
|
|
2
|
+
import { Input } from '@/components/ui/input.component';
|
|
3
|
+
import { LabelAndPlaceholderTextFormat } from '@/lib/utils.util';
|
|
4
|
+
import type { InputInterface } from '../interface/input-props.type';
|
|
5
|
+
|
|
6
|
+
export const DatePickerField = ({
|
|
7
|
+
form, name, labelName, placeholder, required = false, disabled = false,
|
|
8
|
+
viewOnly = false, disableLabelFormatting = false, customMessage,
|
|
9
|
+
}: InputInterface['DatePicker']) => {
|
|
10
|
+
const placeholderText = disableLabelFormatting
|
|
11
|
+
? placeholder || labelName
|
|
12
|
+
: LabelAndPlaceholderTextFormat(placeholder || labelName || '');
|
|
13
|
+
|
|
14
|
+
const LabelEl = () =>
|
|
15
|
+
labelName ? (
|
|
16
|
+
<label className="font-semibold leading-6 text-[14px] tracking-[0.02em]">
|
|
17
|
+
{disableLabelFormatting ? labelName : LabelAndPlaceholderTextFormat(labelName)}
|
|
18
|
+
{required && <span className="text-destructive"> *</span>}
|
|
19
|
+
</label>
|
|
20
|
+
) : null;
|
|
21
|
+
|
|
22
|
+
if (form) {
|
|
23
|
+
return (
|
|
24
|
+
<FormField
|
|
25
|
+
control={form.control}
|
|
26
|
+
name={name || 'date'}
|
|
27
|
+
render={({ field }) => {
|
|
28
|
+
const error = form.formState.errors?.[name || ''];
|
|
29
|
+
return (
|
|
30
|
+
<FormItem>
|
|
31
|
+
<LabelEl />
|
|
32
|
+
{viewOnly ? (
|
|
33
|
+
<div className="py-2 px-3 text-sm text-foreground bg-background rounded-md border border-border min-h-10">
|
|
34
|
+
{field.value ? new Date(field.value).toLocaleDateString() : ''}
|
|
35
|
+
</div>
|
|
36
|
+
) : (
|
|
37
|
+
<>
|
|
38
|
+
<FormControl>
|
|
39
|
+
<Input
|
|
40
|
+
type="date"
|
|
41
|
+
placeholder={placeholderText}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
{...field}
|
|
44
|
+
/>
|
|
45
|
+
</FormControl>
|
|
46
|
+
<FormMessage>{error ? String(error?.message || '') : customMessage || ''}</FormMessage>
|
|
47
|
+
</>
|
|
48
|
+
)}
|
|
49
|
+
</FormItem>
|
|
50
|
+
);
|
|
51
|
+
}}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
<LabelEl />
|
|
59
|
+
<Input type="date" placeholder={placeholderText} />
|
|
60
|
+
</>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
import { FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form.component';
|
|
5
|
+
import { Button } from '@/components/ui/button.component';
|
|
6
|
+
import { Upload, X, File, Eye } from 'lucide-react';
|
|
7
|
+
import { useRef, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
interface FilePreview {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
url: string;
|
|
13
|
+
size: number;
|
|
14
|
+
isUploaded: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface DynamicFileUploadFieldProps {
|
|
18
|
+
form: any;
|
|
19
|
+
name: string;
|
|
20
|
+
labelName?: string;
|
|
21
|
+
optional?: boolean;
|
|
22
|
+
viewOnly?: boolean;
|
|
23
|
+
multiple?: boolean;
|
|
24
|
+
maxSizeMB?: number;
|
|
25
|
+
accept?: string;
|
|
26
|
+
onUpload?: (file: File) => Promise<string>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* DynamicFileUploadField — Drag-and-drop style file upload.
|
|
31
|
+
*
|
|
32
|
+
* ⚠️ Stores URL strings in the form value, NOT raw File objects.
|
|
33
|
+
* - If onUpload is provided: stores the returned URL after upload
|
|
34
|
+
* - If onUpload is omitted: stores an object with file metadata
|
|
35
|
+
* (no raw File objects in form state)
|
|
36
|
+
*/
|
|
37
|
+
export const DynamicFileUploadField = ({
|
|
38
|
+
form, name, labelName, optional = false, viewOnly = false,
|
|
39
|
+
multiple = false, maxSizeMB = 5, accept = '*', onUpload,
|
|
40
|
+
}: DynamicFileUploadFieldProps) => {
|
|
41
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
42
|
+
const filesRef = useRef<Map<string, File>>(new Map());
|
|
43
|
+
const [uploading, setUploading] = useState(false);
|
|
44
|
+
const [previews, setPreviews] = useState<FilePreview[]>([]);
|
|
45
|
+
|
|
46
|
+
const handleFiles = async (files: FileList | null) => {
|
|
47
|
+
if (!files?.length) return;
|
|
48
|
+
const fileArray = Array.from(files);
|
|
49
|
+
|
|
50
|
+
for (const file of fileArray) {
|
|
51
|
+
if (file.size > maxSizeMB * 1024 * 1024) {
|
|
52
|
+
alert(`File ${file.name} exceeds ${maxSizeMB}MB`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const newPreviews: FilePreview[] = fileArray.map((f) => ({
|
|
58
|
+
id: `${f.name}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
59
|
+
name: f.name,
|
|
60
|
+
url: URL.createObjectURL(f),
|
|
61
|
+
size: f.size,
|
|
62
|
+
isUploaded: false,
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
// Store File refs for later upload
|
|
66
|
+
newPreviews.forEach((p, i) => filesRef.current.set(p.id, fileArray[i]));
|
|
67
|
+
|
|
68
|
+
if (onUpload) {
|
|
69
|
+
setUploading(true);
|
|
70
|
+
try {
|
|
71
|
+
const urls = await Promise.all(fileArray.map((f) => onUpload(f)));
|
|
72
|
+
const updated = newPreviews.map((p, i) => ({ ...p, url: urls[i], isUploaded: true }));
|
|
73
|
+
setPreviews((prev) => [...prev, ...updated]);
|
|
74
|
+
// Store URL strings in form
|
|
75
|
+
form.setValue(name, multiple ? updated.map((u) => u.url) : updated[0].url, { shouldValidate: true });
|
|
76
|
+
} finally {
|
|
77
|
+
setUploading(false);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
// No upload handler: store metadata objects (strings only, no File objects)
|
|
81
|
+
const metadata = newPreviews.map((p) => ({ id: p.id, name: p.name, size: p.size, type: 'pending' }));
|
|
82
|
+
setPreviews((prev) => [...prev, ...newPreviews]);
|
|
83
|
+
form.setValue(name, multiple ? metadata : metadata[0], { shouldValidate: true });
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const handleRemove = (id: string) => {
|
|
88
|
+
setPreviews((prev) => {
|
|
89
|
+
const removed = prev.find((p) => p.id === id);
|
|
90
|
+
if (removed) URL.revokeObjectURL(removed.url);
|
|
91
|
+
const updated = prev.filter((p) => p.id !== id);
|
|
92
|
+
filesRef.current.delete(id);
|
|
93
|
+
// Update form value
|
|
94
|
+
if (multiple) {
|
|
95
|
+
form.setValue(name, updated.map((u) => onUpload ? u.url : { id: u.id, name: u.name, size: u.size }), { shouldValidate: true });
|
|
96
|
+
} else {
|
|
97
|
+
form.setValue(name, null, { shouldValidate: true });
|
|
98
|
+
}
|
|
99
|
+
return updated;
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<FormField
|
|
105
|
+
control={form.control}
|
|
106
|
+
name={name}
|
|
107
|
+
render={() => (
|
|
108
|
+
<FormItem>
|
|
109
|
+
{labelName && (
|
|
110
|
+
<label className="font-semibold leading-6 text-[14px] tracking-[0.02em]">
|
|
111
|
+
{labelName}
|
|
112
|
+
{!optional && <span className="text-destructive"> *</span>}
|
|
113
|
+
</label>
|
|
114
|
+
)}
|
|
115
|
+
{!viewOnly && (
|
|
116
|
+
<div className="border-2 border-dashed rounded-lg p-6 text-center hover:border-primary/50 transition-colors cursor-pointer"
|
|
117
|
+
onClick={() => fileInputRef.current?.click()}>
|
|
118
|
+
<Upload className="h-8 w-8 mx-auto text-muted-foreground" />
|
|
119
|
+
<p className="mt-2 text-sm text-muted-foreground">
|
|
120
|
+
{uploading ? 'Uploading...' : `Click to upload${multiple ? ' (multiple)' : ''}`}
|
|
121
|
+
</p>
|
|
122
|
+
<p className="text-xs text-muted-foreground">Max {maxSizeMB}MB per file</p>
|
|
123
|
+
<input ref={fileInputRef} type="file" accept={accept} multiple={multiple} className="hidden"
|
|
124
|
+
onChange={(e) => handleFiles(e.target.files)} />
|
|
125
|
+
</div>
|
|
126
|
+
)}
|
|
127
|
+
{previews.length > 0 && (
|
|
128
|
+
<div className="space-y-2">
|
|
129
|
+
{previews.map((p) => (
|
|
130
|
+
<div key={p.id} className="flex items-center justify-between p-2 border rounded">
|
|
131
|
+
<div className="flex items-center gap-2">
|
|
132
|
+
<File className="h-4 w-4 text-muted-foreground" />
|
|
133
|
+
<span className="text-sm truncate max-w-[200px]">{p.name}</span>
|
|
134
|
+
</div>
|
|
135
|
+
<div className="flex items-center gap-1">
|
|
136
|
+
{p.isUploaded && <Eye className="h-4 w-4 text-muted-foreground cursor-pointer" />}
|
|
137
|
+
{!viewOnly && (
|
|
138
|
+
<button type="button" onClick={() => handleRemove(p.id)}>
|
|
139
|
+
<X className="h-4 w-4 text-destructive" />
|
|
140
|
+
</button>
|
|
141
|
+
)}
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
))}
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
<FormMessage />
|
|
148
|
+
</FormItem>
|
|
149
|
+
)}
|
|
150
|
+
/>
|
|
151
|
+
);
|
|
152
|
+
};
|
package/templates/ui/shadcn/src/components/common/fields/assets/components/limit-field.component.tsx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip.component';
|
|
7
|
+
import { SingleSelectField } from './single-select-field.component';
|
|
8
|
+
|
|
9
|
+
interface LimitFieldProps {
|
|
10
|
+
setLimit: (limit: string) => void;
|
|
11
|
+
options?: string[];
|
|
12
|
+
totalItems?: number;
|
|
13
|
+
setCurrentPage?: (data: number) => void;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* LimitField — Dropdown for selecting items per page.
|
|
19
|
+
* Syncs with URL query param `pageSize`. Resets to page 1 on change.
|
|
20
|
+
*/
|
|
21
|
+
export const LimitField = ({
|
|
22
|
+
setLimit,
|
|
23
|
+
options,
|
|
24
|
+
totalItems = 100,
|
|
25
|
+
setCurrentPage,
|
|
26
|
+
placeholder = 'Entries per page',
|
|
27
|
+
}: LimitFieldProps) => {
|
|
28
|
+
const pathname = usePathname();
|
|
29
|
+
const searchParams = useSearchParams();
|
|
30
|
+
const router = useRouter();
|
|
31
|
+
|
|
32
|
+
const defaultOptions = ['10', '20', '30', '40', '50', '100'];
|
|
33
|
+
const baseOptions = options ?? defaultOptions;
|
|
34
|
+
|
|
35
|
+
// Only show options up to the total items count
|
|
36
|
+
const lastIndex = baseOptions.findIndex((opt) => Number(opt) >= totalItems);
|
|
37
|
+
const OptionsList = lastIndex === -1 ? baseOptions : baseOptions.slice(0, lastIndex + 1);
|
|
38
|
+
|
|
39
|
+
const currentLimit = searchParams.get('pageSize') || '10';
|
|
40
|
+
|
|
41
|
+
const handleLimitChange = (newLimit: string) => {
|
|
42
|
+
const params = new URLSearchParams(searchParams);
|
|
43
|
+
params.set('pageSize', newLimit);
|
|
44
|
+
params.set('page', '1'); // reset to first page
|
|
45
|
+
router.push(`${pathname}?${params.toString()}`);
|
|
46
|
+
|
|
47
|
+
setLimit(newLimit);
|
|
48
|
+
setCurrentPage?.(1);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
setLimit(currentLimit);
|
|
53
|
+
}, [currentLimit, setLimit]);
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<Tooltip>
|
|
57
|
+
<TooltipTrigger asChild>
|
|
58
|
+
<div>
|
|
59
|
+
<SingleSelectField
|
|
60
|
+
name="limit"
|
|
61
|
+
placeholder={placeholder}
|
|
62
|
+
options={OptionsList}
|
|
63
|
+
onValueChange={handleLimitChange}
|
|
64
|
+
defaultValue={currentLimit}
|
|
65
|
+
/>
|
|
66
|
+
</div>
|
|
67
|
+
</TooltipTrigger>
|
|
68
|
+
<TooltipContent className="bg-muted-foreground text-primary-foreground">
|
|
69
|
+
<p className="text-[10px]">Number of entries per page</p>
|
|
70
|
+
</TooltipContent>
|
|
71
|
+
</Tooltip>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form.component';
|
|
2
|
+
import { Checkbox } from '@/components/ui/checkbox.component';
|
|
3
|
+
|
|
4
|
+
export const MultiCheckField = ({
|
|
5
|
+
form, name, labelName, options = [],
|
|
6
|
+
}: {
|
|
7
|
+
form: any; name: string; labelName?: string; options?: { label: string; value: string }[];
|
|
8
|
+
}) => {
|
|
9
|
+
if (!form) return null;
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<FormField
|
|
13
|
+
control={form.control}
|
|
14
|
+
name={name}
|
|
15
|
+
render={() => (
|
|
16
|
+
<FormItem>
|
|
17
|
+
{labelName && <label className="font-semibold leading-6 text-[14px] tracking-[0.02em]">{labelName}</label>}
|
|
18
|
+
{options.map((opt) => (
|
|
19
|
+
<FormField
|
|
20
|
+
key={opt.value}
|
|
21
|
+
control={form.control}
|
|
22
|
+
name={name}
|
|
23
|
+
render={({ field }) => (
|
|
24
|
+
<div className="flex items-center space-x-2">
|
|
25
|
+
<FormControl>
|
|
26
|
+
<Checkbox
|
|
27
|
+
checked={field.value?.includes(opt.value)}
|
|
28
|
+
onCheckedChange={(checked) => {
|
|
29
|
+
const current = field.value || [];
|
|
30
|
+
field.onChange(
|
|
31
|
+
checked ? [...current, opt.value] : current.filter((v: string) => v !== opt.value)
|
|
32
|
+
);
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
</FormControl>
|
|
36
|
+
<FormLabel className="font-normal">{opt.label}</FormLabel>
|
|
37
|
+
</div>
|
|
38
|
+
)}
|
|
39
|
+
/>
|
|
40
|
+
))}
|
|
41
|
+
<FormMessage />
|
|
42
|
+
</FormItem>
|
|
43
|
+
)}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
import { FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form.component';
|
|
5
|
+
import { Input } from '@/components/ui/input.component';
|
|
6
|
+
import { LabelAndPlaceholderTextFormat } from '@/lib/utils.util';
|
|
7
|
+
import type { InputInterface } from '../interface/input-props.type';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Number — A robust numeric input field with:
|
|
11
|
+
* - Integer or float mode
|
|
12
|
+
* - Scroll prevention (blurs on wheel)
|
|
13
|
+
* - Key filtering (blocks non-numeric chars)
|
|
14
|
+
* - Minimum value of 0
|
|
15
|
+
* - Edge case handling for empty/NaN values
|
|
16
|
+
* - Dual-mode: with or without react-hook-form
|
|
17
|
+
*/
|
|
18
|
+
export const Number = ({
|
|
19
|
+
form, name, labelName, placeholder, required = false, disabled = false,
|
|
20
|
+
viewOnly = false, disableLabelFormatting = false, numberType = 'integer', customMessage,
|
|
21
|
+
}: InputInterface['Number']) => {
|
|
22
|
+
const placeholderText = disableLabelFormatting
|
|
23
|
+
? placeholder || labelName
|
|
24
|
+
: LabelAndPlaceholderTextFormat(placeholder || labelName || '');
|
|
25
|
+
|
|
26
|
+
const LabelEl = () =>
|
|
27
|
+
labelName ? (
|
|
28
|
+
<label className="font-semibold leading-6 text-[14px] tracking-[0.02em]">
|
|
29
|
+
{disableLabelFormatting ? labelName : LabelAndPlaceholderTextFormat(labelName)}
|
|
30
|
+
{required && <span className="text-destructive"> *</span>}
|
|
31
|
+
</label>
|
|
32
|
+
) : null;
|
|
33
|
+
|
|
34
|
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
35
|
+
// Allow: backspace, delete, tab, escape, enter, arrows
|
|
36
|
+
const allowedKeys = [
|
|
37
|
+
'Backspace', 'Delete', 'Tab', 'Escape', 'Enter',
|
|
38
|
+
'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End',
|
|
39
|
+
];
|
|
40
|
+
if (allowedKeys.includes(e.key)) return;
|
|
41
|
+
// Allow Ctrl/Cmd shortcuts
|
|
42
|
+
if (e.ctrlKey || e.metaKey) return;
|
|
43
|
+
|
|
44
|
+
// For integers: only digits
|
|
45
|
+
if (numberType === 'integer') {
|
|
46
|
+
if (!/^\d$/.test(e.key)) { e.preventDefault(); }
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// For floats: digits and single decimal point
|
|
51
|
+
if (numberType === 'float') {
|
|
52
|
+
const currentValue = (e.target as HTMLInputElement).value;
|
|
53
|
+
if (e.key === '.' && !currentValue.includes('.')) return;
|
|
54
|
+
if (!/^\d$/.test(e.key)) { e.preventDefault(); }
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const handleChange = (value: string, onChange: (val: any) => void) => {
|
|
59
|
+
if (value === '') {
|
|
60
|
+
onChange('');
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const parsed = numberType === 'float' ? parseFloat(value) : parseInt(value, 10);
|
|
65
|
+
if (!isNaN(parsed) && parsed >= 0) {
|
|
66
|
+
onChange(parsed);
|
|
67
|
+
} else {
|
|
68
|
+
onChange('');
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (form) {
|
|
73
|
+
return (
|
|
74
|
+
<FormField
|
|
75
|
+
control={form.control}
|
|
76
|
+
name={name || 'number'}
|
|
77
|
+
render={({ field }) => {
|
|
78
|
+
const error = form.formState.errors?.[name || ''];
|
|
79
|
+
return (
|
|
80
|
+
<FormItem>
|
|
81
|
+
<LabelEl />
|
|
82
|
+
{viewOnly ? (
|
|
83
|
+
<div className="py-2 px-3 text-sm text-foreground bg-background rounded-md border border-border min-h-10">
|
|
84
|
+
{field.value ?? ''}
|
|
85
|
+
</div>
|
|
86
|
+
) : (
|
|
87
|
+
<>
|
|
88
|
+
<FormControl>
|
|
89
|
+
<Input
|
|
90
|
+
type="number"
|
|
91
|
+
step={numberType === 'float' ? 'any' : '0'}
|
|
92
|
+
min={0}
|
|
93
|
+
placeholder={placeholderText}
|
|
94
|
+
disabled={disabled}
|
|
95
|
+
value={field.value ?? ''}
|
|
96
|
+
onWheel={(e) => (e.target as HTMLInputElement).blur()}
|
|
97
|
+
onKeyDown={handleKeyDown}
|
|
98
|
+
onChange={(e) => handleChange(e.target.value, field.onChange)}
|
|
99
|
+
className="[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [appearance:textfield]"
|
|
100
|
+
/>
|
|
101
|
+
</FormControl>
|
|
102
|
+
<FormMessage>{error ? String(error?.message || '') : customMessage || ''}</FormMessage>
|
|
103
|
+
</>
|
|
104
|
+
)}
|
|
105
|
+
</FormItem>
|
|
106
|
+
);
|
|
107
|
+
}}
|
|
108
|
+
/>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<>
|
|
114
|
+
<LabelEl />
|
|
115
|
+
<Input
|
|
116
|
+
type="number"
|
|
117
|
+
step={numberType === 'float' ? 'any' : '0'}
|
|
118
|
+
placeholder={placeholderText}
|
|
119
|
+
onWheel={(e) => (e.target as HTMLInputElement).blur()}
|
|
120
|
+
onKeyDown={handleKeyDown}
|
|
121
|
+
/>
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
124
|
+
};
|
package/templates/ui/shadcn/src/components/common/fields/assets/components/otp-field.component.tsx
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form.component';
|
|
2
|
+
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp.component';
|
|
3
|
+
import { LabelAndPlaceholderTextFormat } from '@/lib/utils.util';
|
|
4
|
+
|
|
5
|
+
export const OTP = ({
|
|
6
|
+
form, name, labelName, required = false, disableLabelFormatting = false,
|
|
7
|
+
maxLength = 6, customMessage,
|
|
8
|
+
}: {
|
|
9
|
+
form?: any; name?: string; labelName?: string; required?: boolean;
|
|
10
|
+
disableLabelFormatting?: boolean; maxLength?: number; customMessage?: React.ReactNode;
|
|
11
|
+
}) => {
|
|
12
|
+
if (!form) {
|
|
13
|
+
return (
|
|
14
|
+
<div>
|
|
15
|
+
{labelName && (
|
|
16
|
+
<label className="font-semibold leading-6 text-[14px] tracking-[0.02em]">
|
|
17
|
+
{disableLabelFormatting ? labelName : LabelAndPlaceholderTextFormat(labelName)}
|
|
18
|
+
{required && <span className="text-destructive"> *</span>}
|
|
19
|
+
</label>
|
|
20
|
+
)}
|
|
21
|
+
<InputOTP maxLength={maxLength}>
|
|
22
|
+
<InputOTPGroup>
|
|
23
|
+
{Array.from({ length: maxLength }).map((_, i) => (
|
|
24
|
+
<InputOTPSlot key={i} index={i} />
|
|
25
|
+
))}
|
|
26
|
+
</InputOTPGroup>
|
|
27
|
+
</InputOTP>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<FormField
|
|
34
|
+
control={form.control}
|
|
35
|
+
name={name || 'otp'}
|
|
36
|
+
render={({ field }) => {
|
|
37
|
+
const error = form.formState.errors?.[name || ''];
|
|
38
|
+
return (
|
|
39
|
+
<FormItem>
|
|
40
|
+
{labelName && (
|
|
41
|
+
<label className="font-semibold leading-6 text-[14px] tracking-[0.02em]">
|
|
42
|
+
{disableLabelFormatting ? labelName : LabelAndPlaceholderTextFormat(labelName)}
|
|
43
|
+
{required && <span className="text-destructive"> *</span>}
|
|
44
|
+
</label>
|
|
45
|
+
)}
|
|
46
|
+
<FormControl>
|
|
47
|
+
<InputOTP maxLength={maxLength} value={field.value} onChange={field.onChange}>
|
|
48
|
+
<InputOTPGroup>
|
|
49
|
+
{Array.from({ length: maxLength }).map((_, i) => (
|
|
50
|
+
<InputOTPSlot key={i} index={i} />
|
|
51
|
+
))}
|
|
52
|
+
</InputOTPGroup>
|
|
53
|
+
</InputOTP>
|
|
54
|
+
</FormControl>
|
|
55
|
+
<FormMessage>{error ? String(error?.message || '') : customMessage || ''}</FormMessage>
|
|
56
|
+
</FormItem>
|
|
57
|
+
);
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form.component';
|
|
6
|
+
import { Input } from '@/components/ui/input.component';
|
|
7
|
+
import { LabelAndPlaceholderTextFormat, passwordRules } from '@/lib/utils.util';
|
|
8
|
+
import { Eye, EyeOff } from 'lucide-react';
|
|
9
|
+
import type { InputInterface } from '../interface/input-props.type';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Password — Reusable password input with:
|
|
13
|
+
* - Show/hide toggle
|
|
14
|
+
* - Optional strength validation rules (mode="validate")
|
|
15
|
+
* - Dual-mode: with or without react-hook-form
|
|
16
|
+
*/
|
|
17
|
+
export const Password = ({
|
|
18
|
+
form, name, labelName, placeholder, required = false, disabled = false,
|
|
19
|
+
disableLabelFormatting = false, mode = 'normal', customMessage,
|
|
20
|
+
}: InputInterface['Password']) => {
|
|
21
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
22
|
+
const [passwordValue, setPasswordValue] = useState('');
|
|
23
|
+
|
|
24
|
+
const placeholderText = disableLabelFormatting
|
|
25
|
+
? placeholder || labelName
|
|
26
|
+
: LabelAndPlaceholderTextFormat(placeholder || labelName || '');
|
|
27
|
+
|
|
28
|
+
const LabelEl = () =>
|
|
29
|
+
labelName ? (
|
|
30
|
+
<label className="font-semibold leading-6 text-[14px] tracking-[0.02em]">
|
|
31
|
+
{disableLabelFormatting ? labelName : LabelAndPlaceholderTextFormat(labelName)}
|
|
32
|
+
{required && <span className="text-destructive"> *</span>}
|
|
33
|
+
</label>
|
|
34
|
+
) : null;
|
|
35
|
+
|
|
36
|
+
const renderStrengthRules = () => {
|
|
37
|
+
if (mode !== 'validate' || !passwordValue) return null;
|
|
38
|
+
if (passwordRules.every((rule) => rule.test(passwordValue))) return null;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<ul className="mt-2 space-y-1 text-sm">
|
|
42
|
+
{passwordRules.map((rule, index) => {
|
|
43
|
+
const passed = rule.test(passwordValue);
|
|
44
|
+
return (
|
|
45
|
+
<li
|
|
46
|
+
key={index}
|
|
47
|
+
className={`flex items-center gap-2 ${passed ? 'text-green-600' : 'text-muted-foreground'}`}
|
|
48
|
+
>
|
|
49
|
+
<span className={`w-2 h-2 rounded-full inline-block ${passed ? 'bg-green-500' : 'bg-muted-foreground/30'}`} />
|
|
50
|
+
{rule.label}
|
|
51
|
+
</li>
|
|
52
|
+
);
|
|
53
|
+
})}
|
|
54
|
+
</ul>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const renderInput = (fieldProps?: Record<string, any>) => (
|
|
59
|
+
<div className="w-full relative">
|
|
60
|
+
<Input
|
|
61
|
+
type={showPassword ? 'text' : 'password'}
|
|
62
|
+
placeholder={placeholderText}
|
|
63
|
+
disabled={disabled}
|
|
64
|
+
className="pr-10"
|
|
65
|
+
{...fieldProps}
|
|
66
|
+
onChange={(e) => {
|
|
67
|
+
fieldProps?.onChange?.(e);
|
|
68
|
+
setPasswordValue(e.target.value);
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
onClick={() => setShowPassword(!showPassword)}
|
|
74
|
+
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors"
|
|
75
|
+
tabIndex={-1}
|
|
76
|
+
>
|
|
77
|
+
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
|
78
|
+
</button>
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
if (form) {
|
|
83
|
+
return (
|
|
84
|
+
<FormField
|
|
85
|
+
control={form.control}
|
|
86
|
+
name={name || 'password'}
|
|
87
|
+
render={({ field }) => {
|
|
88
|
+
const error = form.formState.errors?.[name || ''];
|
|
89
|
+
return (
|
|
90
|
+
<FormItem>
|
|
91
|
+
<LabelEl />
|
|
92
|
+
<FormControl>
|
|
93
|
+
{renderInput({ ...field, value: passwordValue || field.value || '' })}
|
|
94
|
+
</FormControl>
|
|
95
|
+
{renderStrengthRules()}
|
|
96
|
+
<FormMessage>{error ? String(error?.message || '') : customMessage || ''}</FormMessage>
|
|
97
|
+
</FormItem>
|
|
98
|
+
);
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<>
|
|
106
|
+
<LabelEl />
|
|
107
|
+
{renderInput()}
|
|
108
|
+
</>
|
|
109
|
+
);
|
|
110
|
+
};
|