@homefile/components-v2 2.23.0 → 2.23.1

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.
@@ -1,2 +1,2 @@
1
1
  import { DragDropAreaI } from '../../interfaces';
2
- export declare const DragDropArea: ({ align, direction, errorMessage, getInputProps, getRootProps, height, message, message2, variant, }: DragDropAreaI) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const DragDropArea: ({ align, direction, errorMessage, getInputProps, getRootProps, height, message, message2, variant, multiple, }: DragDropAreaI) => import("react/jsx-runtime").JSX.Element;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { t } from 'i18next';
3
3
  import { Container, Flex, Stack, Text } from '@chakra-ui/react';
4
4
  import { Upload } from '..';
5
- export const DragDropArea = ({ align = 'center', direction = 'row', errorMessage, getInputProps, getRootProps, height = '4rem', message = t('dragDrop.message'), message2 = t('dragDrop.message2'), variant = 'dragDropDashed', }) => {
5
+ export const DragDropArea = ({ align = 'center', direction = 'row', errorMessage, getInputProps, getRootProps, height = '4rem', message = t('dragDrop.message'), message2 = t('dragDrop.message2'), variant = 'dragDropDashed', multiple = false, }) => {
6
6
  const hasError = !!errorMessage;
7
- return (_jsxs(Stack, { spacing: "1", children: [_jsxs(Container, Object.assign({ variant: variant, minW: "full", h: height }, getRootProps(), { children: [_jsx("input", Object.assign({}, getInputProps())), _jsx(Flex, { h: height, align: align, justify: "center", p: "base", children: _jsxs(Flex, { align: "center", direction: direction, gap: "2", children: [_jsx(Upload, {}), _jsxs(Flex, { align: "center", gap: "1", children: [message && _jsx(Text, { variant: "dragDrop", children: message }), message2 && _jsx(Text, { variant: "dragDropLink", children: message2 })] })] }) })] })), hasError && _jsx(Text, { variant: "error", children: errorMessage })] }));
7
+ return (_jsxs(Stack, { spacing: "1", children: [_jsxs(Container, Object.assign({ variant: variant, minW: "full", h: height }, getRootProps(), { children: [_jsx("input", Object.assign({}, getInputProps({ multiple }))), _jsx(Flex, { h: height, align: align, justify: "center", p: "base", children: _jsxs(Flex, { align: "center", direction: direction, gap: "2", children: [_jsx(Upload, {}), _jsxs(Flex, { align: "center", gap: "1", children: [message && _jsx(Text, { variant: "dragDrop", children: message }), message2 && _jsx(Text, { variant: "dragDropLink", children: message2 })] })] }) })] })), hasError && _jsx(Text, { variant: "error", children: errorMessage })] }));
8
8
  };
@@ -1,2 +1,2 @@
1
1
  import { DynamicFormI } from '../../../interfaces';
2
- export declare const DynamicForm: ({ callback, displayImages, form: fields, menuItems, onAISend, onRemoveImage, onUpload, searching, showTitle, title, uploadingFieldId, ...props }: DynamicFormI) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const DynamicForm: ({ callback, displayImages, form: fields, menuItems, onAISend, onRemoveImage, onUpload, searching, showTitle, singleFileUpload, title, uploadingFieldId, ...props }: DynamicFormI) => import("react/jsx-runtime").JSX.Element;
@@ -18,7 +18,7 @@ import { HiddenFieldSection, GroupField, TextField, TextAreaField, SelectField,
18
18
  import { useDynamicForm } from '../../../hooks';
19
19
  import { fieldIcons } from '../../../helpers';
20
20
  export const DynamicForm = (_a) => {
21
- var { callback, displayImages, form: fields, menuItems, onAISend, onRemoveImage, onUpload, searching = false, showTitle = true, title, uploadingFieldId } = _a, props = __rest(_a, ["callback", "displayImages", "form", "menuItems", "onAISend", "onRemoveImage", "onUpload", "searching", "showTitle", "title", "uploadingFieldId"]);
21
+ var { callback, displayImages, form: fields, menuItems, onAISend, onRemoveImage, onUpload, searching = false, showTitle = true, singleFileUpload, title, uploadingFieldId } = _a, props = __rest(_a, ["callback", "displayImages", "form", "menuItems", "onAISend", "onRemoveImage", "onUpload", "searching", "showTitle", "singleFileUpload", "title", "uploadingFieldId"]);
22
22
  const { form, visibleFields, hiddenFields, handleAddAll, handleAdd, handleFilesUpload, handleRemove, } = useDynamicForm({ fields, onUpload });
23
23
  if (searching) {
24
24
  return _jsx(SearchItemLoader, {});
@@ -76,7 +76,7 @@ export const DynamicForm = (_a) => {
76
76
  _jsx(SwitchField, Object.assign({}, baseProps, { description: description }))));
77
77
  case 'file':
78
78
  return (_createElement(FieldWithDelete, Object.assign({}, fieldWithDeleteBaseProps, { key: id }),
79
- _jsx(FileField, { icon: baseProps.icon, description: description, onRemove: onRemoveImage, onUpload: (files) => handleFilesUpload({ id, files }), uploading: uploadingFieldId === id, displayImages: displayImages })));
79
+ _jsx(FileField, Object.assign({}, baseProps, { description: description, onRemove: onRemoveImage, onUpload: (files) => handleFilesUpload({ id, files }), uploading: uploadingFieldId === id, displayImages: displayImages, singleFileUpload: singleFileUpload, value: value }))));
80
80
  case 'group':
81
81
  return (_jsx(GroupField, { id: id, fields: children, onRemove: handleRemove, canBeHidden: canBeHidden }, id));
82
82
  case 'checkbox-group':
@@ -1,2 +1,2 @@
1
1
  import { FileFieldI } from '../../../../interfaces';
2
- export declare const FileField: ({ description, icon, onRemove, onUpload, uploading, displayImages, }: FileFieldI) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const FileField: ({ description, icon, onRemove, onUpload, uploading, displayImages, singleFileUpload, }: FileFieldI) => import("react/jsx-runtime").JSX.Element;
@@ -3,13 +3,13 @@ import { AspectRatio, Box, Flex, Grid, IconButton, Image, Stack, Text, } from '@
3
3
  import { Close, DragDropArea } from '../../..';
4
4
  import { useFilesUploader } from '../../../../hooks';
5
5
  import { colors } from '../../../../theme/colors';
6
- export const FileField = ({ description, icon, onRemove, onUpload, uploading = false, displayImages = [], }) => {
6
+ export const FileField = ({ description, icon, onRemove, onUpload, uploading = false, displayImages = [], singleFileUpload = false, }) => {
7
7
  const { errorMessage, getInputProps, getRootProps, thumbnails } = useFilesUploader({
8
8
  onUpload,
9
9
  uploading,
10
10
  displayImages,
11
11
  });
12
12
  const isStringArray = Array.isArray(thumbnails) && typeof thumbnails[0] === 'string';
13
- return (_jsxs(Flex, { gap: "base", align: "center", flex: "auto", children: [icon && _jsx(Image, { h: "auto", w: "icon.md", src: icon, marginTop: "2" }), _jsxs(Stack, { spacing: "base", flex: "auto", children: [description && _jsx(Text, { fontFamily: "secondary", children: description }), _jsx(DragDropArea, { errorMessage: errorMessage, getInputProps: getInputProps, getRootProps: getRootProps, height: "85px" }), _jsx(Grid, { gridTemplateColumns: `repeat(auto-fill, minmax(22px, 1fr))`, gap: "base", children: isStringArray &&
13
+ return (_jsxs(Flex, { gap: "base", align: "center", flex: "auto", children: [icon && _jsx(Image, { h: "auto", w: "icon.md", src: icon, marginTop: "2" }), _jsxs(Stack, { spacing: "base", flex: "auto", children: [description && _jsx(Text, { fontFamily: "secondary", children: description }), _jsx(DragDropArea, { errorMessage: errorMessage, getInputProps: getInputProps, getRootProps: getRootProps, height: "85px", multiple: !singleFileUpload }), _jsx(Grid, { gridTemplateColumns: `repeat(auto-fill, minmax(22px, 1fr))`, gap: "base", children: isStringArray &&
14
14
  thumbnails.map((file, index) => (_jsxs(Box, { position: "relative", children: [_jsx(IconButton, { variant: "ghost", "aria-label": "close", maxW: "fit-content", onClick: () => onRemove === null || onRemove === void 0 ? void 0 : onRemove(file), icon: _jsx(Close, { size: 11, stroke: colors.error['2'] }), disabled: uploading, position: "absolute", bg: "neutral.white", p: "0.5", borderRadius: "full", top: "-2", right: "-2", zIndex: "1" }), _jsx(AspectRatio, { maxW: "100%", ratio: 1, children: _jsx(Image, { src: file, objectFit: "cover", alt: `file-${index}` }) })] }, file))) })] })] }));
15
15
  };
@@ -9,5 +9,6 @@ export interface DragDropAreaI {
9
9
  height?: number | string;
10
10
  message?: string;
11
11
  message2?: string;
12
+ multiple?: boolean;
12
13
  variant?: 'dragDrop' | 'dragDropDashed';
13
14
  }
@@ -31,6 +31,7 @@ export interface DynamicFormI extends Partial<PartnerFooterI> {
31
31
  onUpload?: (filesByFieldId: Record<string, FolderFileI[] | File[]>) => void;
32
32
  searching?: boolean;
33
33
  showTitle?: boolean;
34
+ singleFileUpload?: boolean;
34
35
  title?: string;
35
36
  uploadingFieldId?: string;
36
37
  }
@@ -4,6 +4,7 @@ export interface FileFieldI extends Pick<ReportI, 'description' | 'icon'> {
4
4
  onUpload?: (files: FolderFileI[]) => void;
5
5
  uploading?: boolean;
6
6
  displayImages?: string[];
7
+ singleFileUpload?: boolean;
7
8
  value?: string;
8
9
  }
9
10
  export interface SingleImageI extends Omit<FileFieldI, 'onUpload'> {
@@ -28,7 +28,7 @@ export const AddReceiptPanel = () => {
28
28
  };
29
29
  function StepOne({ onSave }) {
30
30
  const [value, setValue] = useState('');
31
- return (_jsxs(_Fragment, { children: [_jsx(Box, { p: "base", bg: "lightBlue.2", children: _jsx(EditItemName, { isRequired: false, placeholder: "Add receipt name", onChange: (e) => setValue(e.target.value), onSave: onSave, showSaveButton: !!value, value: value }) }), _jsx(DynamicForm, { form: receiptFieldsMock, showTitle: false }), _jsx(Box, { h: "120px" }), _jsx(DrawerFooter, { children: _jsx(FooterDrawer, { isOpen: true, variant: "footerSquare", children: _jsx(FooterButtons, { button1: {
31
+ return (_jsxs(_Fragment, { children: [_jsx(Box, { p: "base", bg: "lightBlue.2", children: _jsx(EditItemName, { isRequired: false, placeholder: "Add receipt name", onChange: (e) => setValue(e.target.value), onSave: onSave, showSaveButton: !!value, value: value }) }), _jsx(DynamicForm, { form: receiptFieldsMock, showTitle: false, singleFileUpload: true }), _jsx(Box, { h: "120px" }), _jsx(DrawerFooter, { children: _jsx(FooterDrawer, { isOpen: true, variant: "footerSquare", children: _jsx(FooterButtons, { button1: {
32
32
  buttonStyle: 'primaryFooter',
33
33
  label: t('buttons.save'),
34
34
  onClick: onSave,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homefile/components-v2",
3
- "version": "2.23.0",
3
+ "version": "2.23.1",
4
4
  "author": "Homefile",
5
5
  "license": "UNLICENSED",
6
6
  "typings": "dist/index.d.ts",
@@ -13,12 +13,13 @@ export const DragDropArea = ({
13
13
  message = t('dragDrop.message'),
14
14
  message2 = t('dragDrop.message2'),
15
15
  variant = 'dragDropDashed',
16
+ multiple = false,
16
17
  }: DragDropAreaI) => {
17
18
  const hasError = !!errorMessage
18
19
  return (
19
20
  <Stack spacing="1">
20
21
  <Container variant={variant} minW="full" h={height} {...getRootProps()}>
21
- <input {...getInputProps()} />
22
+ <input {...getInputProps({ multiple })} />
22
23
  <Flex h={height} align={align} justify="center" p="base">
23
24
  <Flex align="center" direction={direction} gap="2">
24
25
  <Upload />
@@ -35,6 +35,7 @@ export const DynamicForm = ({
35
35
  onUpload,
36
36
  searching = false,
37
37
  showTitle = true,
38
+ singleFileUpload,
38
39
  title,
39
40
  uploadingFieldId,
40
41
  ...props
@@ -183,12 +184,14 @@ export const DynamicForm = ({
183
184
  return (
184
185
  <FieldWithDelete {...fieldWithDeleteBaseProps} key={id}>
185
186
  <FileField
186
- icon={baseProps.icon}
187
+ {...baseProps}
187
188
  description={description}
188
189
  onRemove={onRemoveImage}
189
190
  onUpload={(files) => handleFilesUpload({ id, files })}
190
191
  uploading={uploadingFieldId === id}
191
192
  displayImages={displayImages}
193
+ singleFileUpload={singleFileUpload}
194
+ value={value as string | undefined}
192
195
  />
193
196
  </FieldWithDelete>
194
197
  )
@@ -21,6 +21,7 @@ export const FileField = ({
21
21
  onUpload,
22
22
  uploading = false,
23
23
  displayImages = [],
24
+ singleFileUpload = false,
24
25
  }: FileFieldI) => {
25
26
  const { errorMessage, getInputProps, getRootProps, thumbnails } =
26
27
  useFilesUploader({
@@ -41,6 +42,7 @@ export const FileField = ({
41
42
  getInputProps={getInputProps}
42
43
  getRootProps={getRootProps}
43
44
  height="85px"
45
+ multiple={!singleFileUpload}
44
46
  />
45
47
  <Grid
46
48
  gridTemplateColumns={`repeat(auto-fill, minmax(22px, 1fr))`}
@@ -10,5 +10,6 @@ export interface DragDropAreaI {
10
10
  height?: number | string
11
11
  message?: string
12
12
  message2?: string
13
+ multiple?: boolean
13
14
  variant?: 'dragDrop' | 'dragDropDashed'
14
15
  }
@@ -155,6 +155,7 @@ export interface DynamicFormI extends Partial<PartnerFooterI> {
155
155
  onUpload?: (filesByFieldId: Record<string, FolderFileI[] | File[]>) => void
156
156
  searching?: boolean
157
157
  showTitle?: boolean
158
+ singleFileUpload?: boolean
158
159
  title?: string
159
160
  uploadingFieldId?: string
160
161
  }
@@ -5,6 +5,7 @@ export interface FileFieldI extends Pick<ReportI, 'description' | 'icon'> {
5
5
  onUpload?: (files: FolderFileI[]) => void
6
6
  uploading?: boolean
7
7
  displayImages?: string[]
8
+ singleFileUpload?: boolean
8
9
  value?: string
9
10
  }
10
11
 
@@ -76,7 +76,11 @@ function StepOne({ onSave }: { onSave: () => void }) {
76
76
  />
77
77
  </Box>
78
78
 
79
- <DynamicForm form={receiptFieldsMock} showTitle={false} />
79
+ <DynamicForm
80
+ form={receiptFieldsMock}
81
+ showTitle={false}
82
+ singleFileUpload
83
+ />
80
84
  <Box h="120px" />
81
85
  <DrawerFooter>
82
86
  <FooterDrawer isOpen variant="footerSquare">