@dartech/arsenal-ui 1.4.41 → 1.4.43
Sign up to get free protection for your applications and to get access to all the features.
package/index.js
CHANGED
@@ -35,7 +35,7 @@ import { langs } from '@uiw/codemirror-extensions-langs';
|
|
35
35
|
import { abcdef } from '@uiw/codemirror-theme-abcdef';
|
36
36
|
import Switch from '@mui/material/Switch';
|
37
37
|
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
|
38
|
-
import { format, parse,
|
38
|
+
import { format, parse, isValid, isMatch } from 'date-fns';
|
39
39
|
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
|
40
40
|
import { TimePicker } from '@mui/x-date-pickers/TimePicker';
|
41
41
|
import Chip from '@mui/material/Chip';
|
@@ -257,6 +257,7 @@ const defaultDefinitionObjectValue = {
|
|
257
257
|
properties: {}
|
258
258
|
};
|
259
259
|
const DEFAULT_REQUIRED_ERROR_TEXT = 'Please, fill this field';
|
260
|
+
const DEFAULT_DATE_VALIDATION_ERROR_TEXT = 'Incorrect date format';
|
260
261
|
|
261
262
|
/**
|
262
263
|
* Material UI `TextField` controlled component. Used with react-hook-form
|
@@ -648,8 +649,7 @@ const ControlCheckbox = _a => {
|
|
648
649
|
onChange: customOnChange ? customOnChange : onChange,
|
649
650
|
name: name,
|
650
651
|
inputRef: ref,
|
651
|
-
disabled: disabled
|
652
|
-
defaultChecked: checked
|
652
|
+
disabled: disabled
|
653
653
|
}, checkboxProps)),
|
654
654
|
label: label
|
655
655
|
}), !hideErrorMessage && (error === null || error === void 0 ? void 0 : error.message) && jsx(FormHelperText, Object.assign({
|
@@ -2231,10 +2231,18 @@ const ControlDate = _a => {
|
|
2231
2231
|
format: format$1 = DATE_DEFAULT_FORMAT,
|
2232
2232
|
hideErrorMessage = false,
|
2233
2233
|
textFieldProps = {},
|
2234
|
-
requiredErrorText = ''
|
2234
|
+
requiredErrorText = '',
|
2235
|
+
validate,
|
2236
|
+
validateErrorText
|
2235
2237
|
} = _a,
|
2236
|
-
datePickerProps = __rest(_a, ["control", "name", "required", "label", "placeholder", "format", "hideErrorMessage", "textFieldProps", "requiredErrorText"]);
|
2238
|
+
datePickerProps = __rest(_a, ["control", "name", "required", "label", "placeholder", "format", "hideErrorMessage", "textFieldProps", "requiredErrorText", "validate", "validateErrorText"]);
|
2237
2239
|
const [localFormat, setLocalFormat] = useState(DATE_DEFAULT_FORMAT);
|
2240
|
+
const defaultValidate = val => {
|
2241
|
+
if (val === '' || isMatch(val, localFormat)) {
|
2242
|
+
return true;
|
2243
|
+
}
|
2244
|
+
return validateErrorText ? validateErrorText : DEFAULT_DATE_VALIDATION_ERROR_TEXT;
|
2245
|
+
};
|
2238
2246
|
const {
|
2239
2247
|
field,
|
2240
2248
|
fieldState: {
|
@@ -2245,12 +2253,7 @@ const ControlDate = _a => {
|
|
2245
2253
|
name,
|
2246
2254
|
rules: {
|
2247
2255
|
required: required ? requiredErrorText || DEFAULT_REQUIRED_ERROR_TEXT : false,
|
2248
|
-
validate:
|
2249
|
-
if (val === '' || isMatch(val, localFormat)) {
|
2250
|
-
return true;
|
2251
|
-
}
|
2252
|
-
return 'Incorrect date format';
|
2253
|
-
}
|
2256
|
+
validate: validate ? validate : defaultValidate
|
2254
2257
|
}
|
2255
2258
|
});
|
2256
2259
|
const handleChange = useCallback(date => {
|
@@ -2312,10 +2315,18 @@ const ControlDateTime = _a => {
|
|
2312
2315
|
format: format$1 = DATE_TIME_DEFAULT_FORMAT,
|
2313
2316
|
hideErrorMessage = false,
|
2314
2317
|
textFieldProps,
|
2315
|
-
requiredErrorText = ''
|
2318
|
+
requiredErrorText = '',
|
2319
|
+
validate,
|
2320
|
+
validateErrorText
|
2316
2321
|
} = _a,
|
2317
|
-
dateTimePickerProps = __rest(_a, ["control", "name", "required", "label", "format", "hideErrorMessage", "textFieldProps", "requiredErrorText"]);
|
2322
|
+
dateTimePickerProps = __rest(_a, ["control", "name", "required", "label", "format", "hideErrorMessage", "textFieldProps", "requiredErrorText", "validate", "validateErrorText"]);
|
2318
2323
|
const [localFormat, setLocalFormat] = useState();
|
2324
|
+
const defaultValidate = val => {
|
2325
|
+
if (val === '' || isMatch(val, localFormat)) {
|
2326
|
+
return true;
|
2327
|
+
}
|
2328
|
+
return validateErrorText ? validateErrorText : DEFAULT_DATE_VALIDATION_ERROR_TEXT;
|
2329
|
+
};
|
2319
2330
|
const {
|
2320
2331
|
field,
|
2321
2332
|
fieldState: {
|
@@ -2326,12 +2337,7 @@ const ControlDateTime = _a => {
|
|
2326
2337
|
name,
|
2327
2338
|
rules: {
|
2328
2339
|
required: required ? requiredErrorText || DEFAULT_REQUIRED_ERROR_TEXT : false,
|
2329
|
-
validate:
|
2330
|
-
if (isMatch(val, localFormat)) {
|
2331
|
-
return true;
|
2332
|
-
}
|
2333
|
-
return 'Incorrect date format';
|
2334
|
-
}
|
2340
|
+
validate: validate ? validate : defaultValidate
|
2335
2341
|
}
|
2336
2342
|
});
|
2337
2343
|
const handleChange = useCallback(date => {
|
@@ -2460,36 +2466,41 @@ const ControlTime = ({
|
|
2460
2466
|
}));
|
2461
2467
|
};
|
2462
2468
|
|
2463
|
-
const ControlArrayInput =
|
2464
|
-
|
2465
|
-
|
2466
|
-
|
2467
|
-
|
2468
|
-
|
2469
|
-
|
2470
|
-
|
2469
|
+
const ControlArrayInput = _a => {
|
2470
|
+
var _b, _c, _d;
|
2471
|
+
var {
|
2472
|
+
name,
|
2473
|
+
control,
|
2474
|
+
label,
|
2475
|
+
required,
|
2476
|
+
defaultValue = null,
|
2477
|
+
onChange: customOnChange,
|
2478
|
+
textFieldLabel
|
2479
|
+
} = _a,
|
2480
|
+
textFieldProps = __rest(_a, ["name", "control", "label", "required", "defaultValue", "onChange", "textFieldLabel"]);
|
2471
2481
|
const [localValue, setLoacalValue] = useState('');
|
2472
2482
|
const [error, setError] = useState(null);
|
2473
|
-
const
|
2483
|
+
const _e = useController({
|
2474
2484
|
control,
|
2475
2485
|
name,
|
2476
|
-
defaultValue
|
2486
|
+
defaultValue,
|
2477
2487
|
rules: {
|
2478
2488
|
required: required && DEFAULT_REQUIRED_ERROR_TEXT
|
2479
2489
|
}
|
2480
2490
|
}),
|
2481
|
-
|
2491
|
+
_f = _e.field,
|
2482
2492
|
{
|
2483
|
-
onChange,
|
2493
|
+
onChange: innerOnChange,
|
2484
2494
|
value: values
|
2485
|
-
} =
|
2486
|
-
fieldData = __rest(
|
2495
|
+
} = _f,
|
2496
|
+
fieldData = __rest(_f, ["onChange", "value"]),
|
2487
2497
|
{
|
2488
2498
|
// fieldState: { error },
|
2489
2499
|
formState: {
|
2490
2500
|
errors
|
2491
2501
|
}
|
2492
|
-
} =
|
2502
|
+
} = _e;
|
2503
|
+
const onChange = useMemo(() => customOnChange ? customOnChange : innerOnChange, [customOnChange, innerOnChange]);
|
2493
2504
|
const handleInputChange = useCallback(e => {
|
2494
2505
|
const {
|
2495
2506
|
value
|
@@ -2518,17 +2529,10 @@ const ControlArrayInput = ({
|
|
2518
2529
|
}
|
2519
2530
|
}, [handleAdd]);
|
2520
2531
|
return jsxs(Fragment, {
|
2521
|
-
children: [jsx(
|
2522
|
-
|
2532
|
+
children: [jsx(FormLabel, Object.assign({
|
2533
|
+
required: required
|
2523
2534
|
}, {
|
2524
|
-
children:
|
2525
|
-
children: [label, ' ', jsx(Box, Object.assign({
|
2526
|
-
component: "span",
|
2527
|
-
color: "#D6331F"
|
2528
|
-
}, {
|
2529
|
-
children: "*"
|
2530
|
-
}))]
|
2531
|
-
}) : label
|
2535
|
+
children: label
|
2532
2536
|
})), jsx(Box, Object.assign({
|
2533
2537
|
display: "flex",
|
2534
2538
|
flexWrap: "wrap"
|
@@ -2547,15 +2551,15 @@ const ControlArrayInput = ({
|
|
2547
2551
|
}, control.register(name), {
|
2548
2552
|
onChange: onChange,
|
2549
2553
|
value: values
|
2550
|
-
}, fieldData)), jsx(TextField, {
|
2554
|
+
}, fieldData)), jsx(TextField, Object.assign({
|
2551
2555
|
fullWidth: true,
|
2552
2556
|
variant: "outlined",
|
2553
2557
|
size: "small",
|
2554
|
-
label: `Add ${label}`,
|
2558
|
+
label: textFieldLabel || textFieldLabel === '' ? textFieldLabel : `Add ${label}`,
|
2555
2559
|
value: localValue,
|
2556
2560
|
onChange: handleInputChange,
|
2557
|
-
error: !!((
|
2558
|
-
helperText: (
|
2561
|
+
error: !!((_b = errors[name]) === null || _b === void 0 ? void 0 : _b.message),
|
2562
|
+
helperText: (_c = errors[name]) === null || _c === void 0 ? void 0 : _c.message,
|
2559
2563
|
FormHelperTextProps: {
|
2560
2564
|
variant: 'standard'
|
2561
2565
|
},
|
@@ -2572,8 +2576,9 @@ const ControlArrayInput = ({
|
|
2572
2576
|
})
|
2573
2577
|
})
|
2574
2578
|
}))
|
2575
|
-
}
|
2576
|
-
|
2579
|
+
},
|
2580
|
+
inputProps: Object.assign({}, (_d = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.inputProps) !== null && _d !== void 0 ? _d : {})
|
2581
|
+
}, textFieldProps)), error && jsx(FormHelperText, Object.assign({
|
2577
2582
|
error: true
|
2578
2583
|
}, {
|
2579
2584
|
children: error
|
@@ -8034,4 +8039,4 @@ const Breadcrumbs = ({
|
|
8034
8039
|
}));
|
8035
8040
|
};
|
8036
8041
|
|
8037
|
-
export { AlertDialog, BackButton, Breadcrumbs, ContentLayout, ControlAceEditor, ControlArrayInput, ControlAutocomplete, ControlCheckbox, ControlDate, ControlDateTime, ControlDebouncedInput, ControlInput, ControlNumberInput, ControlPeriodInput, ControlPhoneInput, ControlQueryAutocomplete, ControlRadio, ControlSelect, ControlSwitch, ControlTime, CopyButton, CreateDefinition, CreatePropertiesList, CreatePropertiesListContext, CreatePropertyFormFields, DATE_DEFAULT_FORMAT, DATE_TIME_DEFAULT_FORMAT, DEFAULT_ERROR_TEXT, DEFAULT_REQUIRED_ERROR_TEXT, DefinitionFiller, DefinitionValueView, InfoItem, JsonModalView, JsonPathPicker, JsonView, Loader, MenuIcon, MultiplePropertyFiller, PropertyFiller, PropertyType, PropertyValueField, RoundingMode, RouteTabs, Sidebar, SimpleTable, Status, StepperView, TIME_DEFAULT_FORMAT, TabPanel, Table, TableAction, TableActionCell, ViewPropertiesList, ViewProperty, capitalize, deepParseJson, defaultDefinitionArrayValue, defaultDefinitionObjectValue, digitsOnly, floatsOnly, formatDefinitionData, formatTableRowValue, getDemPropertyDateFormat, getEntityStarterValue, getJsonStringValue, getMultiplePropertyFillOptions, getSinglePropertyFillOptions, isDateType, isExpression, isPropertyValueEmpty, numberFormat, propertiesArrayToObject, propertiesObjectToArray, removeArrayItem, safeParseJson, sortArrayOfObjects, theme, useDebounce, useToggle, validateJson };
|
8042
|
+
export { AlertDialog, BackButton, Breadcrumbs, ContentLayout, ControlAceEditor, ControlArrayInput, ControlAutocomplete, ControlCheckbox, ControlDate, ControlDateTime, ControlDebouncedInput, ControlInput, ControlNumberInput, ControlPeriodInput, ControlPhoneInput, ControlQueryAutocomplete, ControlRadio, ControlSelect, ControlSwitch, ControlTime, CopyButton, CreateDefinition, CreatePropertiesList, CreatePropertiesListContext, CreatePropertyFormFields, DATE_DEFAULT_FORMAT, DATE_TIME_DEFAULT_FORMAT, DEFAULT_DATE_VALIDATION_ERROR_TEXT, DEFAULT_ERROR_TEXT, DEFAULT_REQUIRED_ERROR_TEXT, DefinitionFiller, DefinitionValueView, InfoItem, JsonModalView, JsonPathPicker, JsonView, Loader, MenuIcon, MultiplePropertyFiller, PropertyFiller, PropertyType, PropertyValueField, RoundingMode, RouteTabs, Sidebar, SimpleTable, Status, StepperView, TIME_DEFAULT_FORMAT, TabPanel, Table, TableAction, TableActionCell, ViewPropertiesList, ViewProperty, capitalize, deepParseJson, defaultDefinitionArrayValue, defaultDefinitionObjectValue, digitsOnly, floatsOnly, formatDefinitionData, formatTableRowValue, getDemPropertyDateFormat, getEntityStarterValue, getJsonStringValue, getMultiplePropertyFillOptions, getSinglePropertyFillOptions, isDateType, isExpression, isPropertyValueEmpty, numberFormat, propertiesArrayToObject, propertiesObjectToArray, removeArrayItem, safeParseJson, sortArrayOfObjects, theme, useDebounce, useToggle, validateJson };
|
package/package.json
CHANGED
package/src/consts/index.d.ts
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
import { ReactNode } from 'react';
|
2
2
|
import { Control } from 'react-hook-form';
|
3
|
-
|
3
|
+
import { TextFieldProps } from '@mui/material/TextField';
|
4
|
+
type Props = TextFieldProps & {
|
4
5
|
name: string;
|
5
6
|
control: Control<any>;
|
6
7
|
label: ReactNode;
|
7
8
|
required?: boolean;
|
8
9
|
defaultValue?: [] | null;
|
10
|
+
onChange?: any;
|
11
|
+
textFieldLabel?: string;
|
9
12
|
};
|
10
|
-
export declare const ControlArrayInput: ({ name, control, label, required, defaultValue, }: Props) => JSX.Element;
|
13
|
+
export declare const ControlArrayInput: ({ name, control, label, required, defaultValue, onChange: customOnChange, textFieldLabel, ...textFieldProps }: Props) => JSX.Element;
|
11
14
|
export {};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ReactNode } from 'react';
|
2
2
|
import { TextFieldProps } from '@mui/material/TextField';
|
3
3
|
import { DatePickerProps } from '@mui/x-date-pickers/DatePicker';
|
4
|
-
import { Control } from 'react-hook-form';
|
4
|
+
import { Control, Validate } from 'react-hook-form';
|
5
5
|
type ControlDateProps = Partial<DatePickerProps<unknown, unknown>> & {
|
6
6
|
/**
|
7
7
|
* React Hook Form `control`
|
@@ -18,6 +18,8 @@ type ControlDateProps = Partial<DatePickerProps<unknown, unknown>> & {
|
|
18
18
|
hideErrorMessage?: boolean;
|
19
19
|
textFieldProps?: TextFieldProps;
|
20
20
|
requiredErrorText?: string;
|
21
|
+
validate?: Validate<any, any>;
|
22
|
+
validateErrorText?: string;
|
21
23
|
};
|
22
|
-
export declare const ControlDate: ({ control, name, required, label, placeholder, format, hideErrorMessage, textFieldProps, requiredErrorText, ...datePickerProps }: ControlDateProps) => JSX.Element;
|
24
|
+
export declare const ControlDate: ({ control, name, required, label, placeholder, format, hideErrorMessage, textFieldProps, requiredErrorText, validate, validateErrorText, ...datePickerProps }: ControlDateProps) => JSX.Element;
|
23
25
|
export default ControlDate;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ReactNode } from 'react';
|
2
2
|
import { TextFieldProps } from '@mui/material/TextField';
|
3
3
|
import { DateTimePickerProps } from '@mui/x-date-pickers/DateTimePicker';
|
4
|
-
import { Control } from 'react-hook-form';
|
4
|
+
import { Control, Validate } from 'react-hook-form';
|
5
5
|
type dateTimePickerProps = Partial<DateTimePickerProps<unknown, unknown>> & {
|
6
6
|
/**
|
7
7
|
* React Hook Form `control`
|
@@ -17,6 +17,8 @@ type dateTimePickerProps = Partial<DateTimePickerProps<unknown, unknown>> & {
|
|
17
17
|
hideErrorMessage?: boolean;
|
18
18
|
textFieldProps?: TextFieldProps;
|
19
19
|
requiredErrorText?: string;
|
20
|
+
validate?: Validate<any, any>;
|
21
|
+
validateErrorText?: string;
|
20
22
|
};
|
21
|
-
export declare const ControlDateTime: ({ control, name, required, label, format, hideErrorMessage, textFieldProps, requiredErrorText, ...dateTimePickerProps }: dateTimePickerProps) => JSX.Element;
|
23
|
+
export declare const ControlDateTime: ({ control, name, required, label, format, hideErrorMessage, textFieldProps, requiredErrorText, validate, validateErrorText, ...dateTimePickerProps }: dateTimePickerProps) => JSX.Element;
|
22
24
|
export default ControlDateTime;
|