@homefile/components-v2 2.23.3 → 2.23.5

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 { ItemNameHeaderI } from '../../interfaces';
2
- export declare const ItemNameHeader: ({ id, value, onSave, onValueChange, padding, }: ItemNameHeaderI) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const ItemNameHeader: ({ id, value, onSave, onValueChange, padding, required, }: ItemNameHeaderI) => import("react/jsx-runtime").JSX.Element;
@@ -4,7 +4,7 @@ import { Box, Flex, Button } from '@chakra-ui/react';
4
4
  import { TextInput } from '..';
5
5
  import { isEmptyField } from '../../utils';
6
6
  import { useState, useEffect } from 'react';
7
- export const ItemNameHeader = ({ id = '', value = '', onSave, onValueChange, padding = 'base', }) => {
7
+ export const ItemNameHeader = ({ id = '', value = '', onSave, onValueChange, padding = 'base', required = true, }) => {
8
8
  const [name, setName] = useState(value);
9
9
  useEffect(() => {
10
10
  setName(value);
@@ -13,5 +13,5 @@ export const ItemNameHeader = ({ id = '', value = '', onSave, onValueChange, pad
13
13
  setName(e.target.value);
14
14
  onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(e.target.value);
15
15
  };
16
- return (_jsx(Box, { bg: "lightBlue.2", p: padding, w: "100%", children: _jsxs(Flex, { gap: "base", align: "center", children: [_jsx(TextInput, { errorMessage: `${t('householdItems.headers.itemName')} ${t('forms.required')}`, hasError: isEmptyField(name), id: id, handleChange: handleChange, placeholder: t('householdItems.headers.placeholder'), value: name }), name && (_jsx(Button, { variant: "secondary", maxW: "fit-content", maxH: "input.md", onClick: () => onSave(name), children: t('createDocument.buttons.save') }))] }) }));
16
+ return (_jsx(Box, { bg: "lightBlue.2", p: padding, w: "100%", children: _jsxs(Flex, { gap: "base", align: "center", children: [_jsx(TextInput, { errorMessage: `${t('householdItems.headers.itemName')} ${t('forms.required')}`, hasError: required && isEmptyField(name), id: id, handleChange: handleChange, placeholder: t('householdItems.headers.placeholder'), value: name }), name && (_jsx(Button, { variant: "secondary", maxW: "fit-content", maxH: "input.md", onClick: () => onSave(name), children: t('createDocument.buttons.save') }))] }) }));
17
17
  };
@@ -51,6 +51,7 @@ export const useDynamicForm = ({ fields, onUpload }) => {
51
51
  };
52
52
  useEffect(() => {
53
53
  handleSetDefaultValues(fields);
54
+ setStateFields(fields);
54
55
  }, [fields]);
55
56
  return {
56
57
  form,
@@ -4,4 +4,5 @@ export interface ItemNameHeaderI {
4
4
  onValueChange?: (value: string) => void;
5
5
  onSave: (name: string) => void;
6
6
  padding?: string;
7
+ required?: boolean;
7
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homefile/components-v2",
3
- "version": "2.23.3",
3
+ "version": "2.23.5",
4
4
  "author": "Homefile",
5
5
  "license": "UNLICENSED",
6
6
  "typings": "dist/index.d.ts",
@@ -11,6 +11,7 @@ export const ItemNameHeader = ({
11
11
  onSave,
12
12
  onValueChange,
13
13
  padding = 'base',
14
+ required = true,
14
15
  }: ItemNameHeaderI) => {
15
16
  const [name, setName] = useState(value)
16
17
 
@@ -29,7 +30,7 @@ export const ItemNameHeader = ({
29
30
  errorMessage={`${t('householdItems.headers.itemName')} ${t(
30
31
  'forms.required'
31
32
  )}`}
32
- hasError={isEmptyField(name)}
33
+ hasError={required && isEmptyField(name)}
33
34
  id={id}
34
35
  handleChange={handleChange}
35
36
  placeholder={t('householdItems.headers.placeholder')}
@@ -91,6 +91,7 @@ export const useDynamicForm = ({ fields, onUpload }: UseDynamicFormI) => {
91
91
 
92
92
  useEffect(() => {
93
93
  handleSetDefaultValues(fields)
94
+ setStateFields(fields)
94
95
  }, [fields])
95
96
 
96
97
  return {
@@ -4,4 +4,5 @@ export interface ItemNameHeaderI {
4
4
  onValueChange?: (value: string) => void
5
5
  onSave: (name: string) => void
6
6
  padding?: string
7
+ required?: boolean
7
8
  }