@pagamio/frontend-commons-lib 0.8.325 → 0.8.327
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/lib/components/ui/UploadField.d.ts +2 -0
- package/lib/components/ui/UploadField.js +3 -3
- package/lib/form-engine/components/inputs/upload-field/UploadFieldForm.js +1 -1
- package/lib/form-engine/types/index.d.ts +2 -0
- package/lib/shared/hooks/usePagamioTable.d.ts +16 -1
- package/lib/shared/hooks/usePagamioTable.js +31 -0
- package/lib/styles.css +0 -4
- package/package.json +1 -1
|
@@ -9,6 +9,8 @@ type UploadProps = {
|
|
|
9
9
|
allowedFileTypes?: string[];
|
|
10
10
|
maxFileSize?: number;
|
|
11
11
|
helperText?: string;
|
|
12
|
+
/** Optional label for the inline trigger (defaults to "Choose file"). */
|
|
13
|
+
chooseFileLabel?: string;
|
|
12
14
|
value?: never;
|
|
13
15
|
};
|
|
14
16
|
declare const UploadField: React.ForwardRefExoticComponent<UploadProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useState } from 'react';
|
|
3
3
|
import { Button, Icon } from '../../components';
|
|
4
|
-
const UploadField = forwardRef(({ onChange, id, type = 'file', hideUploadButton = false, className = '', disabled = false, allowedFileTypes, maxFileSize, helperText, value, // Explicitly exclude value prop becuase it's not allowed for security reasons.
|
|
4
|
+
const UploadField = forwardRef(({ onChange, id, type = 'file', hideUploadButton = false, className = '', disabled = false, allowedFileTypes, maxFileSize, helperText, chooseFileLabel = 'Choose file', value, // Explicitly exclude value prop becuase it's not allowed for security reasons.
|
|
5
5
|
...props }, ref) => {
|
|
6
6
|
const [fileName, setFileName] = useState(null);
|
|
7
7
|
const [key, setKey] = useState(0);
|
|
@@ -42,11 +42,11 @@ const UploadField = forwardRef(({ onChange, id, type = 'file', hideUploadButton
|
|
|
42
42
|
setKey((prev) => prev + 1);
|
|
43
43
|
};
|
|
44
44
|
const acceptValue = allowedFileTypes?.map((ext) => `.${ext}`).join(',');
|
|
45
|
-
return (_jsxs("div", { className: `flex flex-col gap-3 w-full ${className}`, children: [_jsxs("div", { className: "flex gap-3 w-full items-center", children: [_jsxs("label", { htmlFor: id, className: "flex items-center gap-2 cursor-pointer flex-1", children: [_jsx("div", { className: "bg-primary rounded-full h-10 w-10 flex items-center justify-center", children: _jsx(Icon, { name: "FiUpload", size: 20, className: "text-white" }) }), _jsx("span", { className: "text-sm font-medium text-foreground", children:
|
|
45
|
+
return (_jsxs("div", { className: `flex flex-col gap-3 w-full ${className}`, children: [_jsxs("div", { className: "flex gap-3 w-full items-center", children: [_jsxs("label", { htmlFor: id, className: "flex items-center gap-2 cursor-pointer flex-1", children: [_jsx("div", { className: "bg-primary rounded-full h-10 w-10 flex items-center justify-center", children: _jsx(Icon, { name: "FiUpload", size: 20, className: "text-white" }) }), _jsx("span", { className: "text-sm font-medium text-foreground", children: chooseFileLabel }), _jsx("input", { type: type, onChange: handleFileChange, className: "hidden", id: id, ref: ref, disabled: disabled, accept: acceptValue, ...props }, key)] }), !hideUploadButton && (_jsx(Button, { onClick: () => {
|
|
46
46
|
if (ref && typeof ref === 'object' && ref.current) {
|
|
47
47
|
ref.current.click();
|
|
48
48
|
}
|
|
49
|
-
}, disabled: disabled, children: "Upload" }))] }), fileName && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsxs("span", { className: "text-sm text-muted-foreground", children: ["Selected: ", fileName] }), _jsx(Button, { variant: "destructive", size: "sm", onClick: handleClearFile, disabled: disabled, children: "Clear" })] })), helperText &&
|
|
49
|
+
}, disabled: disabled, children: "Upload" }))] }), fileName && (_jsxs("div", { className: "flex items-center gap-2", children: [_jsxs("span", { className: "text-sm text-muted-foreground", children: ["Selected: ", fileName] }), _jsx(Button, { variant: "destructive", size: "sm", onClick: handleClearFile, disabled: disabled, children: "Clear" })] })), helperText && _jsx("p", { className: "text-sm text-muted-foreground", children: helperText }), error && _jsx("div", { className: "text-red-500 text-sm", children: error })] }));
|
|
50
50
|
});
|
|
51
51
|
UploadField.displayName = 'UploadField';
|
|
52
52
|
export default UploadField;
|
|
@@ -53,7 +53,7 @@ const UploadFieldForm = forwardRef(({ field, error, ...props }, ref) => {
|
|
|
53
53
|
return _jsx("span", { className: "text-muted-foreground", children: "File uploaded." });
|
|
54
54
|
}, [preview, field.name]);
|
|
55
55
|
const previewLabel = preview.type === 'pdf' ? 'Uploaded PDF:' : 'Uploaded Image:';
|
|
56
|
-
return (_jsxs("div", { className: "flex flex-col space-y-4", children: [_jsxs("div", { className: "flex flex-col space-y-2", children: [_jsx("label", { htmlFor: field.name, className: "text-sm font-medium text-foreground", children: field.label }), _jsx(UploadField, { ...props, id: field.name, ref: ref, value: props.value || null, onChange: handleFileChange, className: "w-full p-2 border border-input rounded-md", hideUploadButton: field.hideUploadButton, allowedFileTypes: field.allowedFileTypes, maxFileSize: field.maxFileSize, helperText: field.fileUploadHelperText }), error && _jsx("p", { className: "mt-1 text-sm text-red-500", children: error.message })] }), field.showFileUploadPreview && (_jsxs("div", { className: "mt-4", children: [_jsx("label", { htmlFor: `${field.name}-preview`, className: "text-sm font-medium text-foreground", children: previewLabel }), _jsx("div", { className: "mt-2 flex flex-col items-center p-4 border border-input rounded-md", children: previewElement })] }))] }));
|
|
56
|
+
return (_jsxs("div", { className: "flex flex-col space-y-4", children: [_jsxs("div", { className: "flex flex-col space-y-2", children: [_jsx("label", { htmlFor: field.name, className: "text-sm font-medium text-foreground", children: field.label }), _jsx(UploadField, { ...props, id: field.name, ref: ref, value: props.value || null, onChange: handleFileChange, className: "w-full p-2 border border-input rounded-md", hideUploadButton: field.hideUploadButton, allowedFileTypes: field.allowedFileTypes, maxFileSize: field.maxFileSize, helperText: field.fileUploadHelperText, chooseFileLabel: field.chooseFileLabel }), error && _jsx("p", { className: "mt-1 text-sm text-red-500", children: error.message })] }), field.showFileUploadPreview && (_jsxs("div", { className: "mt-4", children: [_jsx("label", { htmlFor: `${field.name}-preview`, className: "text-sm font-medium text-foreground", children: previewLabel }), _jsx("div", { className: "mt-2 flex flex-col items-center p-4 border border-input rounded-md", children: previewElement })] }))] }));
|
|
57
57
|
});
|
|
58
58
|
UploadFieldForm.displayName = 'UploadFieldForm';
|
|
59
59
|
export default UploadFieldForm;
|
|
@@ -157,6 +157,8 @@ export interface Field {
|
|
|
157
157
|
showFileUploadPreview?: boolean;
|
|
158
158
|
/** To display file upload helper text */
|
|
159
159
|
fileUploadHelperText?: string;
|
|
160
|
+
/** Custom label for the inline upload trigger (defaults to "Choose file") */
|
|
161
|
+
chooseFileLabel?: string;
|
|
160
162
|
/** Default country for phone input */
|
|
161
163
|
defaultCountry?: string;
|
|
162
164
|
/** Disables the field */
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import type { ResponseMapping } from '../../api';
|
|
1
|
+
import type { QueryParamConfig, ResponseMapping } from '../../api';
|
|
2
2
|
import type { BaseEntity, UsePagamioTableConfig, UsePagamioTableReturn } from '../../pagamio-table/data-table/types';
|
|
3
3
|
export declare const springBootMapping: ResponseMapping;
|
|
4
4
|
export declare const arrayResponseMapping: ResponseMapping;
|
|
5
|
+
/**
|
|
6
|
+
* Response mapping for Pagamio NestJS backends (commerce-os-core,
|
|
7
|
+
* nestjs-api-commons). Matches `PaginatedResponseDto<T>`:
|
|
8
|
+
* { data: T[], meta: { page, limit, total, totalPages, hasNextPage, hasPreviousPage } }
|
|
9
|
+
*
|
|
10
|
+
* Pair with `pagamioQueryConfig` so request params line up too.
|
|
11
|
+
*/
|
|
12
|
+
export declare const pagamioMapping: ResponseMapping;
|
|
13
|
+
/**
|
|
14
|
+
* Query-param config for Pagamio NestJS backends. Matches `PaginationDto`:
|
|
15
|
+
* page (1-based), limit, search, sortBy, sortOrder ('asc'|'desc')
|
|
16
|
+
*
|
|
17
|
+
* The hook tracks `page` zero-indexed internally; we bump on the way out.
|
|
18
|
+
*/
|
|
19
|
+
export declare const pagamioQueryConfig: QueryParamConfig;
|
|
5
20
|
export declare const usePagamioTable: <T extends BaseEntity>({ queryKey, queryFn, enabled: queryEnabled, staleTime, gcTime, data: clientData, columns, defaultFilters, responseMapping, queryParamConfig, pagination: paginationConfig, filtering: filteringConfig, sorting: sortingConfig, toolbar, searchPlaceholder, onRowClick, rowClassName, expandable, renderDetailPanel, }: UsePagamioTableConfig<T>) => UsePagamioTableReturn<T>;
|
|
@@ -30,6 +30,37 @@ export const arrayResponseMapping = {
|
|
|
30
30
|
pageSize: '',
|
|
31
31
|
defaultValues: { data: [], total: 0, page: 0, pageSize: 10 },
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Response mapping for Pagamio NestJS backends (commerce-os-core,
|
|
35
|
+
* nestjs-api-commons). Matches `PaginatedResponseDto<T>`:
|
|
36
|
+
* { data: T[], meta: { page, limit, total, totalPages, hasNextPage, hasPreviousPage } }
|
|
37
|
+
*
|
|
38
|
+
* Pair with `pagamioQueryConfig` so request params line up too.
|
|
39
|
+
*/
|
|
40
|
+
export const pagamioMapping = {
|
|
41
|
+
responseType: 'default',
|
|
42
|
+
data: 'data',
|
|
43
|
+
total: 'meta.total',
|
|
44
|
+
page: 'meta.page',
|
|
45
|
+
pageSize: 'meta.limit',
|
|
46
|
+
defaultValues: { data: [], total: 0, page: 1, pageSize: 10 },
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Query-param config for Pagamio NestJS backends. Matches `PaginationDto`:
|
|
50
|
+
* page (1-based), limit, search, sortBy, sortOrder ('asc'|'desc')
|
|
51
|
+
*
|
|
52
|
+
* The hook tracks `page` zero-indexed internally; we bump on the way out.
|
|
53
|
+
*/
|
|
54
|
+
export const pagamioQueryConfig = {
|
|
55
|
+
pagination: {
|
|
56
|
+
transform: (page, size) => ({
|
|
57
|
+
page: (page + 1).toString(),
|
|
58
|
+
limit: size.toString(),
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
sorting: { sortByParam: 'sortBy', sortDirParam: 'sortOrder' },
|
|
62
|
+
filtering: { searchParam: 'search', filterFormat: 'flat' },
|
|
63
|
+
};
|
|
33
64
|
const defaultQueryConfig = {
|
|
34
65
|
pagination: {
|
|
35
66
|
transform: (page, size) => ({ page: page.toString(), size: size.toString() }),
|
package/lib/styles.css
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagamio/frontend-commons-lib",
|
|
3
3
|
"description": "Pagamio library for Frontend reusable components like the form engine and table container",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.327",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"provenance": false
|