@trackunit/custom-field-components 0.0.1026 → 0.0.1029
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/index.cjs.js
CHANGED
|
@@ -7,6 +7,9 @@ var reactFormComponents = require('@trackunit/react-form-components');
|
|
|
7
7
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
8
8
|
var React = require('react');
|
|
9
9
|
var reactHookForm = require('react-hook-form');
|
|
10
|
+
var reactComponents = require('@trackunit/react-components');
|
|
11
|
+
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
12
|
+
var reactModal = require('@trackunit/react-modal');
|
|
10
13
|
|
|
11
14
|
function _interopNamespaceDefault(e) {
|
|
12
15
|
var n = Object.create(null);
|
|
@@ -28,6 +31,15 @@ function _interopNamespaceDefault(e) {
|
|
|
28
31
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
29
32
|
|
|
30
33
|
var defaultTranslations = {
|
|
34
|
+
"customfield.stringlistfield.add": "Add",
|
|
35
|
+
"customfield.stringlistfield.addField.Heading": "Add {{label}}",
|
|
36
|
+
"customfield.stringlistfield.addField.InputPlaceholder": "Enter {{label}}",
|
|
37
|
+
"customfield.stringlistfield.deleteField.Heading": "Delete {{label}}",
|
|
38
|
+
"customfield.stringlistfield.deleteField.Message": "Are you sure you want to delete this {{label}}?",
|
|
39
|
+
"customfield.stringlistfield.deleteField.PrimaryActionLabel": "Delete",
|
|
40
|
+
"customfield.stringlistfield.deleteField.SecondaryActionLabel": "Cancel",
|
|
41
|
+
"customfield.stringlistfield.discard": "Discard",
|
|
42
|
+
"customfield.stringlistfield.noValuesAddedYet": "No values added yet",
|
|
31
43
|
"customfield.unit.ACRE": "acre",
|
|
32
44
|
"customfield.unit.AMPERE": "A",
|
|
33
45
|
"customfield.unit.AMPERE_HOUR": "Ah",
|
|
@@ -227,6 +239,64 @@ const DropdownCustomField = ({ defaultValue, dataTestId, onChange, onBlur, id, d
|
|
|
227
239
|
return (jsxRuntime.jsx(reactFormComponents.FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon || null, helpText: errorMessage || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsxRuntime.jsx(reactFormComponents.Select, { "aria-labelledby": htmlForId + "-label", dataTestId: dataTestId, disabled: disabled, hasError: renderAsInvalid, inputId: htmlForId, isClearable: true, isMulti: multiSelect, onChange: onChangeHandler, options: options, value: selectedValue }) }));
|
|
228
240
|
};
|
|
229
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Modal for adding a new string list field
|
|
244
|
+
*/
|
|
245
|
+
const AddStringListField = ({ id, label, isEditing, setIsEditing, onAdd }) => {
|
|
246
|
+
const { Modal } = reactModal.useModal();
|
|
247
|
+
const [inputValue, setInputValue] = React.useState("");
|
|
248
|
+
const { t } = useTranslation();
|
|
249
|
+
const handleAdd = () => {
|
|
250
|
+
if (inputValue.trim()) {
|
|
251
|
+
onAdd(inputValue.trim());
|
|
252
|
+
setInputValue("");
|
|
253
|
+
setIsEditing(false);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const handleDiscard = () => {
|
|
257
|
+
setInputValue("");
|
|
258
|
+
setIsEditing(false);
|
|
259
|
+
};
|
|
260
|
+
return (jsxRuntime.jsxs(Modal, { className: "max-w-lg", dataTestId: `${id}-edit-modal`, isOpen: isEditing, onDismissClick: handleDiscard, children: [jsxRuntime.jsx(reactComponents.CardHeader, { heading: t("customfield.stringlistfield.addField.Heading", { label: label }), onClose: handleDiscard }), jsxRuntime.jsx(reactComponents.CardBody, { children: jsxRuntime.jsx(reactFormComponents.TextInput, { dataTestId: `${id}-edit-modal-input`, onChange: e => setInputValue(e.target.value), placeholder: t("customfield.stringlistfield.addField.InputPlaceholder", { label: label }), value: inputValue }) }), jsxRuntime.jsxs(reactComponents.CardFooter, { children: [jsxRuntime.jsx(reactComponents.Button, { dataTestId: `${id}-edit-modal-discard-button`, onClick: handleDiscard, variant: "secondary", children: t("customfield.stringlistfield.discard") }), jsxRuntime.jsx(reactComponents.Button, { dataTestId: `${id}-edit-modal-add-button`, onClick: handleAdd, children: t("customfield.stringlistfield.add") })] })] }));
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* A custom field that displays a list of strings.
|
|
265
|
+
*/
|
|
266
|
+
const StringListField = ({ defaultValue = [], label, description, disabled, validationRules, id, control, register, dataTestId, ...props }) => {
|
|
267
|
+
const [isEditing, setIsEditing] = React.useState(false);
|
|
268
|
+
const { confirm } = reactCoreHooks.useConfirmationDialog();
|
|
269
|
+
const { t } = useTranslation();
|
|
270
|
+
return (jsxRuntime.jsx(reactHookForm.Controller, { control: control, defaultValue: defaultValue, name: id, render: ({ field }) => {
|
|
271
|
+
const handleRemoveValue = (index) => {
|
|
272
|
+
const newValues = field.value.filter((_, i) => i !== index);
|
|
273
|
+
field.onChange(newValues);
|
|
274
|
+
};
|
|
275
|
+
const handleFieldChange = (index, value) => {
|
|
276
|
+
const newValues = [...field.value];
|
|
277
|
+
newValues[index] = value;
|
|
278
|
+
field.onChange(newValues);
|
|
279
|
+
};
|
|
280
|
+
const handleRemoveValueConfirmation = async (index) => {
|
|
281
|
+
const confirmResult = await confirm({
|
|
282
|
+
title: t("customfield.stringlistfield.deleteField.Heading", { label: label }),
|
|
283
|
+
message: t("customfield.stringlistfield.deleteField.Message", { label: label }),
|
|
284
|
+
primaryActionLabel: t("customfield.stringlistfield.deleteField.PrimaryActionLabel"),
|
|
285
|
+
secondaryActionLabel: t("customfield.stringlistfield.deleteField.SecondaryActionLabel"),
|
|
286
|
+
primaryActionType: "primary-danger",
|
|
287
|
+
});
|
|
288
|
+
if (confirmResult === "PRIMARY") {
|
|
289
|
+
handleRemoveValue(index);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
return (jsxRuntime.jsxs(reactComponents.Card, { ...props, className: "w-full", "data-testid": dataTestId, children: [jsxRuntime.jsx(reactComponents.CardHeader, { accessories: jsxRuntime.jsx(reactComponents.Tooltip, { label: description }), heading: label, headingVariant: "secondary" }), jsxRuntime.jsx(reactComponents.CardBody, { children: field.value.length === 0 ? (jsxRuntime.jsx(reactComponents.Text, { children: t("customfield.stringlistfield.noValuesAddedYet") })) : (jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: field.value.map((value, index) => (jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntime.jsx(reactFormComponents.TextInput, { disabled: disabled, ...register(`${id}-${index}`, {
|
|
293
|
+
onChange: e => handleFieldChange(index, e.target.value),
|
|
294
|
+
}), defaultValue: value }), jsxRuntime.jsx(reactComponents.IconButton, { disabled: disabled, icon: jsxRuntime.jsx(reactComponents.Icon, { name: "Trash", size: "small" }), onClick: () => handleRemoveValueConfirmation(index), variant: "secondary-danger" })] }, index))) })) }), !disabled ? (jsxRuntime.jsx(reactComponents.CardFooter, { children: jsxRuntime.jsx(reactComponents.Button, { disabled: disabled, onClick: () => setIsEditing(true), variant: "secondary", children: t("customfield.stringlistfield.add", { label: label }) }) })) : null, jsxRuntime.jsx(AddStringListField, { id: id, isEditing: isEditing, label: label, onAdd: (newItem) => {
|
|
295
|
+
field.onChange([...field.value, newItem]);
|
|
296
|
+
}, setIsEditing: setIsEditing })] }));
|
|
297
|
+
}, rules: validationRules }));
|
|
298
|
+
};
|
|
299
|
+
|
|
230
300
|
/**
|
|
231
301
|
* Generates validation rules for a web address field.
|
|
232
302
|
*
|
|
@@ -347,6 +417,46 @@ const getBooleanValidationRules = (definition) => {
|
|
|
347
417
|
const getDropdownValidationRules = (definition) => {
|
|
348
418
|
return getDefaultValidationRules();
|
|
349
419
|
};
|
|
420
|
+
/**
|
|
421
|
+
* Generates validation rules for a string list field.
|
|
422
|
+
*
|
|
423
|
+
* @param {GetStringListValidationRulesDefinition} definition - The definition of the string list field.
|
|
424
|
+
* @returns {ValidationRules} The generated validation rules.
|
|
425
|
+
*/
|
|
426
|
+
const getStringListValidationRules = (definition) => {
|
|
427
|
+
const defaultRules = {};
|
|
428
|
+
const itemMinLength = definition.itemMinimumLength
|
|
429
|
+
? {
|
|
430
|
+
minLength: {
|
|
431
|
+
value: definition.itemMinimumLength,
|
|
432
|
+
message: `minimum length for each item is ${definition.itemMinimumLength}`,
|
|
433
|
+
},
|
|
434
|
+
}
|
|
435
|
+
: undefined;
|
|
436
|
+
const itemMaxLength = definition.itemMaximumLength
|
|
437
|
+
? {
|
|
438
|
+
maxLength: {
|
|
439
|
+
value: definition.itemMaximumLength,
|
|
440
|
+
message: `maximum length for each item is ${definition.itemMaximumLength}`,
|
|
441
|
+
},
|
|
442
|
+
}
|
|
443
|
+
: undefined;
|
|
444
|
+
const pattern = definition.pattern
|
|
445
|
+
? {
|
|
446
|
+
pattern: {
|
|
447
|
+
value: RegExp(definition.pattern),
|
|
448
|
+
message: `Must match pattern: ${definition.pattern}`,
|
|
449
|
+
},
|
|
450
|
+
}
|
|
451
|
+
: undefined;
|
|
452
|
+
return definition.uiEditable
|
|
453
|
+
? {
|
|
454
|
+
...itemMaxLength,
|
|
455
|
+
...itemMinLength,
|
|
456
|
+
...pattern,
|
|
457
|
+
}
|
|
458
|
+
: defaultRules;
|
|
459
|
+
};
|
|
350
460
|
/**
|
|
351
461
|
* Generates validation rules for a date field.
|
|
352
462
|
*
|
|
@@ -482,7 +592,8 @@ const useCustomFieldResolver = ({ field, definition, register, setValue, formSta
|
|
|
482
592
|
return (jsxRuntime.jsx(DateCustomField, { dataTestId: `${key}`, defaultValue: value, disabled: !isEditableCombined, errorMessage: errorMessage, helpText: description, id: uniqueIdentifier, label: title || "", readOnly: !isEditableCombined, register: validation.register, setValue: validation.setValue, title: title || "", validationRules: rules }));
|
|
483
593
|
}
|
|
484
594
|
case "StringListFieldDefinition": {
|
|
485
|
-
|
|
595
|
+
const rules = getStringListValidationRules(def);
|
|
596
|
+
return (jsxRuntime.jsx(StringListField, { control: control, dataTestId: key, defaultValue: value !== null && value !== void 0 ? value : undefined, description: description !== null && description !== void 0 ? description : "", disabled: !isEditableCombined, errorMessage: errorMessage, id: uniqueIdentifier, label: title || "", register: validation.register, setValue: validation.setValue, validationRules: rules }));
|
|
486
597
|
}
|
|
487
598
|
case "JsonFieldDefinition": {
|
|
488
599
|
return null;
|
package/index.esm.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { getCustomFieldValueForDisplayInUI } from '@trackunit/iris-app-runtime-core';
|
|
4
|
-
import { FormGroup, Checkbox, DateField, Select, useGetPhoneValidationRules, NumberField, TextField, PhoneField, ActionButton } from '@trackunit/react-form-components';
|
|
4
|
+
import { FormGroup, Checkbox, DateField, Select, TextInput, useGetPhoneValidationRules, NumberField, TextField, PhoneField, ActionButton } from '@trackunit/react-form-components';
|
|
5
5
|
import { uuidv4, exhaustiveCheck } from '@trackunit/shared-utils';
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import { useCallback, useEffect, createElement, useState } from 'react';
|
|
8
|
-
import { useWatch } from 'react-hook-form';
|
|
8
|
+
import { Controller, useWatch } from 'react-hook-form';
|
|
9
|
+
import { CardHeader, CardBody, CardFooter, Button, Card, Tooltip, Text, IconButton, Icon } from '@trackunit/react-components';
|
|
10
|
+
import { useConfirmationDialog } from '@trackunit/react-core-hooks';
|
|
11
|
+
import { useModal } from '@trackunit/react-modal';
|
|
9
12
|
|
|
10
13
|
var defaultTranslations = {
|
|
14
|
+
"customfield.stringlistfield.add": "Add",
|
|
15
|
+
"customfield.stringlistfield.addField.Heading": "Add {{label}}",
|
|
16
|
+
"customfield.stringlistfield.addField.InputPlaceholder": "Enter {{label}}",
|
|
17
|
+
"customfield.stringlistfield.deleteField.Heading": "Delete {{label}}",
|
|
18
|
+
"customfield.stringlistfield.deleteField.Message": "Are you sure you want to delete this {{label}}?",
|
|
19
|
+
"customfield.stringlistfield.deleteField.PrimaryActionLabel": "Delete",
|
|
20
|
+
"customfield.stringlistfield.deleteField.SecondaryActionLabel": "Cancel",
|
|
21
|
+
"customfield.stringlistfield.discard": "Discard",
|
|
22
|
+
"customfield.stringlistfield.noValuesAddedYet": "No values added yet",
|
|
11
23
|
"customfield.unit.ACRE": "acre",
|
|
12
24
|
"customfield.unit.AMPERE": "A",
|
|
13
25
|
"customfield.unit.AMPERE_HOUR": "Ah",
|
|
@@ -207,6 +219,64 @@ const DropdownCustomField = ({ defaultValue, dataTestId, onChange, onBlur, id, d
|
|
|
207
219
|
return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon || null, helpText: errorMessage || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsx(Select, { "aria-labelledby": htmlForId + "-label", dataTestId: dataTestId, disabled: disabled, hasError: renderAsInvalid, inputId: htmlForId, isClearable: true, isMulti: multiSelect, onChange: onChangeHandler, options: options, value: selectedValue }) }));
|
|
208
220
|
};
|
|
209
221
|
|
|
222
|
+
/**
|
|
223
|
+
* Modal for adding a new string list field
|
|
224
|
+
*/
|
|
225
|
+
const AddStringListField = ({ id, label, isEditing, setIsEditing, onAdd }) => {
|
|
226
|
+
const { Modal } = useModal();
|
|
227
|
+
const [inputValue, setInputValue] = useState("");
|
|
228
|
+
const { t } = useTranslation();
|
|
229
|
+
const handleAdd = () => {
|
|
230
|
+
if (inputValue.trim()) {
|
|
231
|
+
onAdd(inputValue.trim());
|
|
232
|
+
setInputValue("");
|
|
233
|
+
setIsEditing(false);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
const handleDiscard = () => {
|
|
237
|
+
setInputValue("");
|
|
238
|
+
setIsEditing(false);
|
|
239
|
+
};
|
|
240
|
+
return (jsxs(Modal, { className: "max-w-lg", dataTestId: `${id}-edit-modal`, isOpen: isEditing, onDismissClick: handleDiscard, children: [jsx(CardHeader, { heading: t("customfield.stringlistfield.addField.Heading", { label: label }), onClose: handleDiscard }), jsx(CardBody, { children: jsx(TextInput, { dataTestId: `${id}-edit-modal-input`, onChange: e => setInputValue(e.target.value), placeholder: t("customfield.stringlistfield.addField.InputPlaceholder", { label: label }), value: inputValue }) }), jsxs(CardFooter, { children: [jsx(Button, { dataTestId: `${id}-edit-modal-discard-button`, onClick: handleDiscard, variant: "secondary", children: t("customfield.stringlistfield.discard") }), jsx(Button, { dataTestId: `${id}-edit-modal-add-button`, onClick: handleAdd, children: t("customfield.stringlistfield.add") })] })] }));
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* A custom field that displays a list of strings.
|
|
245
|
+
*/
|
|
246
|
+
const StringListField = ({ defaultValue = [], label, description, disabled, validationRules, id, control, register, dataTestId, ...props }) => {
|
|
247
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
248
|
+
const { confirm } = useConfirmationDialog();
|
|
249
|
+
const { t } = useTranslation();
|
|
250
|
+
return (jsx(Controller, { control: control, defaultValue: defaultValue, name: id, render: ({ field }) => {
|
|
251
|
+
const handleRemoveValue = (index) => {
|
|
252
|
+
const newValues = field.value.filter((_, i) => i !== index);
|
|
253
|
+
field.onChange(newValues);
|
|
254
|
+
};
|
|
255
|
+
const handleFieldChange = (index, value) => {
|
|
256
|
+
const newValues = [...field.value];
|
|
257
|
+
newValues[index] = value;
|
|
258
|
+
field.onChange(newValues);
|
|
259
|
+
};
|
|
260
|
+
const handleRemoveValueConfirmation = async (index) => {
|
|
261
|
+
const confirmResult = await confirm({
|
|
262
|
+
title: t("customfield.stringlistfield.deleteField.Heading", { label: label }),
|
|
263
|
+
message: t("customfield.stringlistfield.deleteField.Message", { label: label }),
|
|
264
|
+
primaryActionLabel: t("customfield.stringlistfield.deleteField.PrimaryActionLabel"),
|
|
265
|
+
secondaryActionLabel: t("customfield.stringlistfield.deleteField.SecondaryActionLabel"),
|
|
266
|
+
primaryActionType: "primary-danger",
|
|
267
|
+
});
|
|
268
|
+
if (confirmResult === "PRIMARY") {
|
|
269
|
+
handleRemoveValue(index);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
return (jsxs(Card, { ...props, className: "w-full", "data-testid": dataTestId, children: [jsx(CardHeader, { accessories: jsx(Tooltip, { label: description }), heading: label, headingVariant: "secondary" }), jsx(CardBody, { children: field.value.length === 0 ? (jsx(Text, { children: t("customfield.stringlistfield.noValuesAddedYet") })) : (jsx("div", { className: "flex flex-wrap gap-2", children: field.value.map((value, index) => (jsxs("div", { className: "flex items-center gap-2", children: [jsx(TextInput, { disabled: disabled, ...register(`${id}-${index}`, {
|
|
273
|
+
onChange: e => handleFieldChange(index, e.target.value),
|
|
274
|
+
}), defaultValue: value }), jsx(IconButton, { disabled: disabled, icon: jsx(Icon, { name: "Trash", size: "small" }), onClick: () => handleRemoveValueConfirmation(index), variant: "secondary-danger" })] }, index))) })) }), !disabled ? (jsx(CardFooter, { children: jsx(Button, { disabled: disabled, onClick: () => setIsEditing(true), variant: "secondary", children: t("customfield.stringlistfield.add", { label: label }) }) })) : null, jsx(AddStringListField, { id: id, isEditing: isEditing, label: label, onAdd: (newItem) => {
|
|
275
|
+
field.onChange([...field.value, newItem]);
|
|
276
|
+
}, setIsEditing: setIsEditing })] }));
|
|
277
|
+
}, rules: validationRules }));
|
|
278
|
+
};
|
|
279
|
+
|
|
210
280
|
/**
|
|
211
281
|
* Generates validation rules for a web address field.
|
|
212
282
|
*
|
|
@@ -327,6 +397,46 @@ const getBooleanValidationRules = (definition) => {
|
|
|
327
397
|
const getDropdownValidationRules = (definition) => {
|
|
328
398
|
return getDefaultValidationRules();
|
|
329
399
|
};
|
|
400
|
+
/**
|
|
401
|
+
* Generates validation rules for a string list field.
|
|
402
|
+
*
|
|
403
|
+
* @param {GetStringListValidationRulesDefinition} definition - The definition of the string list field.
|
|
404
|
+
* @returns {ValidationRules} The generated validation rules.
|
|
405
|
+
*/
|
|
406
|
+
const getStringListValidationRules = (definition) => {
|
|
407
|
+
const defaultRules = {};
|
|
408
|
+
const itemMinLength = definition.itemMinimumLength
|
|
409
|
+
? {
|
|
410
|
+
minLength: {
|
|
411
|
+
value: definition.itemMinimumLength,
|
|
412
|
+
message: `minimum length for each item is ${definition.itemMinimumLength}`,
|
|
413
|
+
},
|
|
414
|
+
}
|
|
415
|
+
: undefined;
|
|
416
|
+
const itemMaxLength = definition.itemMaximumLength
|
|
417
|
+
? {
|
|
418
|
+
maxLength: {
|
|
419
|
+
value: definition.itemMaximumLength,
|
|
420
|
+
message: `maximum length for each item is ${definition.itemMaximumLength}`,
|
|
421
|
+
},
|
|
422
|
+
}
|
|
423
|
+
: undefined;
|
|
424
|
+
const pattern = definition.pattern
|
|
425
|
+
? {
|
|
426
|
+
pattern: {
|
|
427
|
+
value: RegExp(definition.pattern),
|
|
428
|
+
message: `Must match pattern: ${definition.pattern}`,
|
|
429
|
+
},
|
|
430
|
+
}
|
|
431
|
+
: undefined;
|
|
432
|
+
return definition.uiEditable
|
|
433
|
+
? {
|
|
434
|
+
...itemMaxLength,
|
|
435
|
+
...itemMinLength,
|
|
436
|
+
...pattern,
|
|
437
|
+
}
|
|
438
|
+
: defaultRules;
|
|
439
|
+
};
|
|
330
440
|
/**
|
|
331
441
|
* Generates validation rules for a date field.
|
|
332
442
|
*
|
|
@@ -462,7 +572,8 @@ const useCustomFieldResolver = ({ field, definition, register, setValue, formSta
|
|
|
462
572
|
return (jsx(DateCustomField, { dataTestId: `${key}`, defaultValue: value, disabled: !isEditableCombined, errorMessage: errorMessage, helpText: description, id: uniqueIdentifier, label: title || "", readOnly: !isEditableCombined, register: validation.register, setValue: validation.setValue, title: title || "", validationRules: rules }));
|
|
463
573
|
}
|
|
464
574
|
case "StringListFieldDefinition": {
|
|
465
|
-
|
|
575
|
+
const rules = getStringListValidationRules(def);
|
|
576
|
+
return (jsx(StringListField, { control: control, dataTestId: key, defaultValue: value !== null && value !== void 0 ? value : undefined, description: description !== null && description !== void 0 ? description : "", disabled: !isEditableCombined, errorMessage: errorMessage, id: uniqueIdentifier, label: title || "", register: validation.register, setValue: validation.setValue, validationRules: rules }));
|
|
466
577
|
}
|
|
467
578
|
case "JsonFieldDefinition": {
|
|
468
579
|
return null;
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/custom-field-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1029",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=20.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
+
"@trackunit/react-components": "*",
|
|
11
|
+
"@trackunit/react-modal": "*",
|
|
12
|
+
"@trackunit/react-core-hooks": "*",
|
|
10
13
|
"@trackunit/react-form-components": "*",
|
|
11
14
|
"react": "18.3.1",
|
|
12
15
|
"react-hook-form": "7.53.1",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface AddStringListFieldProps {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
isEditing: boolean;
|
|
5
|
+
setIsEditing: (isEditing: boolean) => void;
|
|
6
|
+
onAdd: (newItem: string) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Modal for adding a new string list field
|
|
10
|
+
*/
|
|
11
|
+
export declare const AddStringListField: ({ id, label, isEditing, setIsEditing, onAdd }: AddStringListFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CommonProps } from "@trackunit/react-components";
|
|
2
|
+
import { Control, FieldValues, RegisterOptions, UseFormRegister, UseFormSetValue } from "react-hook-form";
|
|
3
|
+
export interface StringListFieldProps extends CommonProps {
|
|
4
|
+
defaultValue?: string[];
|
|
5
|
+
label: string;
|
|
6
|
+
helpText?: string;
|
|
7
|
+
errorMessage?: string;
|
|
8
|
+
register: UseFormRegister<FieldValues>;
|
|
9
|
+
setValue: UseFormSetValue<FieldValues>;
|
|
10
|
+
description?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
validationRules: RegisterOptions;
|
|
13
|
+
id: string;
|
|
14
|
+
control: Control<FieldValues>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A custom field that displays a list of strings.
|
|
18
|
+
*/
|
|
19
|
+
export declare const StringListField: ({ defaultValue, label, description, disabled, validationRules, id, control, register, dataTestId, ...props }: StringListFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -52,6 +52,19 @@ export declare const getBooleanValidationRules: (definition: CommonValidationRul
|
|
|
52
52
|
* @returns {ValidationRules} The generated validation rules.
|
|
53
53
|
*/
|
|
54
54
|
export declare const getDropdownValidationRules: (definition: CommonValidationRulesDefinition) => ValidationRules;
|
|
55
|
+
interface GetStringListValidationRulesDefinition extends CommonValidationRulesDefinition {
|
|
56
|
+
itemMaximumLength?: number | null;
|
|
57
|
+
itemMinimumLength?: number | null;
|
|
58
|
+
pattern?: string | null;
|
|
59
|
+
maximumItems?: number | null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Generates validation rules for a string list field.
|
|
63
|
+
*
|
|
64
|
+
* @param {GetStringListValidationRulesDefinition} definition - The definition of the string list field.
|
|
65
|
+
* @returns {ValidationRules} The generated validation rules.
|
|
66
|
+
*/
|
|
67
|
+
export declare const getStringListValidationRules: (definition: GetStringListValidationRulesDefinition) => ValidationRules;
|
|
55
68
|
/**
|
|
56
69
|
* Generates validation rules for a date field.
|
|
57
70
|
*
|
package/src/translation.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare const translations: TranslationResource<TranslationKeys>;
|
|
|
14
14
|
/**
|
|
15
15
|
* Local useTranslation for this specific library
|
|
16
16
|
*/
|
|
17
|
-
export declare const useTranslation: () => [TransForLibs<"customfield.unit.ACRE" | "customfield.unit.AMPERE" | "customfield.unit.AMPERE_HOUR" | "customfield.unit.ARE" | "customfield.unit.BAR" | "customfield.unit.CELSIUS" | "customfield.unit.CENTIMETRE" | "customfield.unit.CUBIC_FOOT" | "customfield.unit.CUBIC_METRE" | "customfield.unit.DAY" | "customfield.unit.DEGREE_ANGLE" | "customfield.unit.FAHRENHEIT" | "customfield.unit.FOOT" | "customfield.unit.G_FORCE" | "customfield.unit.GALLON_LIQUID" | "customfield.unit.GALLONS_PER_HOUR" | "customfield.unit.GRAM" | "customfield.unit.HECTARE" | "customfield.unit.HERTZ" | "customfield.unit.HOUR" | "customfield.unit.INCH" | "customfield.unit.INCHES_OF_WATER" | "customfield.unit.KILOGRAM" | "customfield.unit.KILOGRAM_PER_HOUR" | "customfield.unit.KILOGRAM_PER_SECOND" | "customfield.unit.KILOMETRE" | "customfield.unit.KILOMETRE_PER_HOUR" | "customfield.unit.KILOPASCAL" | "customfield.unit.KILOWATT" | "customfield.unit.KILOWATT_HOUR" | "customfield.unit.LITRE" | "customfield.unit.LITRES_PER_HOUR" | "customfield.unit.METRE" | "customfield.unit.METRE_PER_SECOND" | "customfield.unit.METRE_PER_SECOND_SQUARED" | "customfield.unit.METRIC_TON" | "customfield.unit.MILE" | "customfield.unit.MILE_PER_HOUR" | "customfield.unit.MILLIMETRE" | "customfield.unit.MILLISECOND" | "customfield.unit.MINUTE" | "customfield.unit.MONTH" | "customfield.unit.NEWTON" | "customfield.unit.OUNCE" | "customfield.unit.PASCAL" | "customfield.unit.PERCENT" | "customfield.unit.POUND" | "customfield.unit.POUND_PER_HOUR" | "customfield.unit.POUND_PER_SECOND" | "customfield.unit.POUND_PER_SQUARE_INCH" | "customfield.unit.REVOLUTIONS_PER_MINUTE" | "customfield.unit.SECOND" | "customfield.unit.SQUARE_FOOT" | "customfield.unit.SQUARE_KILOMETRE" | "customfield.unit.SQUARE_METRE" | "customfield.unit.TON" | "customfield.unit.US_TON" | "customfield.unit.VOLT" | "customfield.unit.VOLT_AMPERE" | "customfield.unit.WATT" | "customfield.unit.WEEK" | "customfield.unit.YARD" | "customfield.unit.YEAR">, import("i18next").i18n, boolean] & {
|
|
18
|
-
t: TransForLibs<"customfield.unit.ACRE" | "customfield.unit.AMPERE" | "customfield.unit.AMPERE_HOUR" | "customfield.unit.ARE" | "customfield.unit.BAR" | "customfield.unit.CELSIUS" | "customfield.unit.CENTIMETRE" | "customfield.unit.CUBIC_FOOT" | "customfield.unit.CUBIC_METRE" | "customfield.unit.DAY" | "customfield.unit.DEGREE_ANGLE" | "customfield.unit.FAHRENHEIT" | "customfield.unit.FOOT" | "customfield.unit.G_FORCE" | "customfield.unit.GALLON_LIQUID" | "customfield.unit.GALLONS_PER_HOUR" | "customfield.unit.GRAM" | "customfield.unit.HECTARE" | "customfield.unit.HERTZ" | "customfield.unit.HOUR" | "customfield.unit.INCH" | "customfield.unit.INCHES_OF_WATER" | "customfield.unit.KILOGRAM" | "customfield.unit.KILOGRAM_PER_HOUR" | "customfield.unit.KILOGRAM_PER_SECOND" | "customfield.unit.KILOMETRE" | "customfield.unit.KILOMETRE_PER_HOUR" | "customfield.unit.KILOPASCAL" | "customfield.unit.KILOWATT" | "customfield.unit.KILOWATT_HOUR" | "customfield.unit.LITRE" | "customfield.unit.LITRES_PER_HOUR" | "customfield.unit.METRE" | "customfield.unit.METRE_PER_SECOND" | "customfield.unit.METRE_PER_SECOND_SQUARED" | "customfield.unit.METRIC_TON" | "customfield.unit.MILE" | "customfield.unit.MILE_PER_HOUR" | "customfield.unit.MILLIMETRE" | "customfield.unit.MILLISECOND" | "customfield.unit.MINUTE" | "customfield.unit.MONTH" | "customfield.unit.NEWTON" | "customfield.unit.OUNCE" | "customfield.unit.PASCAL" | "customfield.unit.PERCENT" | "customfield.unit.POUND" | "customfield.unit.POUND_PER_HOUR" | "customfield.unit.POUND_PER_SECOND" | "customfield.unit.POUND_PER_SQUARE_INCH" | "customfield.unit.REVOLUTIONS_PER_MINUTE" | "customfield.unit.SECOND" | "customfield.unit.SQUARE_FOOT" | "customfield.unit.SQUARE_KILOMETRE" | "customfield.unit.SQUARE_METRE" | "customfield.unit.TON" | "customfield.unit.US_TON" | "customfield.unit.VOLT" | "customfield.unit.VOLT_AMPERE" | "customfield.unit.WATT" | "customfield.unit.WEEK" | "customfield.unit.YARD" | "customfield.unit.YEAR">;
|
|
17
|
+
export declare const useTranslation: () => [TransForLibs<"customfield.stringlistfield.add" | "customfield.stringlistfield.addField.Heading" | "customfield.stringlistfield.addField.InputPlaceholder" | "customfield.stringlistfield.deleteField.Heading" | "customfield.stringlistfield.deleteField.Message" | "customfield.stringlistfield.deleteField.PrimaryActionLabel" | "customfield.stringlistfield.deleteField.SecondaryActionLabel" | "customfield.stringlistfield.discard" | "customfield.stringlistfield.noValuesAddedYet" | "customfield.unit.ACRE" | "customfield.unit.AMPERE" | "customfield.unit.AMPERE_HOUR" | "customfield.unit.ARE" | "customfield.unit.BAR" | "customfield.unit.CELSIUS" | "customfield.unit.CENTIMETRE" | "customfield.unit.CUBIC_FOOT" | "customfield.unit.CUBIC_METRE" | "customfield.unit.DAY" | "customfield.unit.DEGREE_ANGLE" | "customfield.unit.FAHRENHEIT" | "customfield.unit.FOOT" | "customfield.unit.G_FORCE" | "customfield.unit.GALLON_LIQUID" | "customfield.unit.GALLONS_PER_HOUR" | "customfield.unit.GRAM" | "customfield.unit.HECTARE" | "customfield.unit.HERTZ" | "customfield.unit.HOUR" | "customfield.unit.INCH" | "customfield.unit.INCHES_OF_WATER" | "customfield.unit.KILOGRAM" | "customfield.unit.KILOGRAM_PER_HOUR" | "customfield.unit.KILOGRAM_PER_SECOND" | "customfield.unit.KILOMETRE" | "customfield.unit.KILOMETRE_PER_HOUR" | "customfield.unit.KILOPASCAL" | "customfield.unit.KILOWATT" | "customfield.unit.KILOWATT_HOUR" | "customfield.unit.LITRE" | "customfield.unit.LITRES_PER_HOUR" | "customfield.unit.METRE" | "customfield.unit.METRE_PER_SECOND" | "customfield.unit.METRE_PER_SECOND_SQUARED" | "customfield.unit.METRIC_TON" | "customfield.unit.MILE" | "customfield.unit.MILE_PER_HOUR" | "customfield.unit.MILLIMETRE" | "customfield.unit.MILLISECOND" | "customfield.unit.MINUTE" | "customfield.unit.MONTH" | "customfield.unit.NEWTON" | "customfield.unit.OUNCE" | "customfield.unit.PASCAL" | "customfield.unit.PERCENT" | "customfield.unit.POUND" | "customfield.unit.POUND_PER_HOUR" | "customfield.unit.POUND_PER_SECOND" | "customfield.unit.POUND_PER_SQUARE_INCH" | "customfield.unit.REVOLUTIONS_PER_MINUTE" | "customfield.unit.SECOND" | "customfield.unit.SQUARE_FOOT" | "customfield.unit.SQUARE_KILOMETRE" | "customfield.unit.SQUARE_METRE" | "customfield.unit.TON" | "customfield.unit.US_TON" | "customfield.unit.VOLT" | "customfield.unit.VOLT_AMPERE" | "customfield.unit.WATT" | "customfield.unit.WEEK" | "customfield.unit.YARD" | "customfield.unit.YEAR">, import("i18next").i18n, boolean] & {
|
|
18
|
+
t: TransForLibs<"customfield.stringlistfield.add" | "customfield.stringlistfield.addField.Heading" | "customfield.stringlistfield.addField.InputPlaceholder" | "customfield.stringlistfield.deleteField.Heading" | "customfield.stringlistfield.deleteField.Message" | "customfield.stringlistfield.deleteField.PrimaryActionLabel" | "customfield.stringlistfield.deleteField.SecondaryActionLabel" | "customfield.stringlistfield.discard" | "customfield.stringlistfield.noValuesAddedYet" | "customfield.unit.ACRE" | "customfield.unit.AMPERE" | "customfield.unit.AMPERE_HOUR" | "customfield.unit.ARE" | "customfield.unit.BAR" | "customfield.unit.CELSIUS" | "customfield.unit.CENTIMETRE" | "customfield.unit.CUBIC_FOOT" | "customfield.unit.CUBIC_METRE" | "customfield.unit.DAY" | "customfield.unit.DEGREE_ANGLE" | "customfield.unit.FAHRENHEIT" | "customfield.unit.FOOT" | "customfield.unit.G_FORCE" | "customfield.unit.GALLON_LIQUID" | "customfield.unit.GALLONS_PER_HOUR" | "customfield.unit.GRAM" | "customfield.unit.HECTARE" | "customfield.unit.HERTZ" | "customfield.unit.HOUR" | "customfield.unit.INCH" | "customfield.unit.INCHES_OF_WATER" | "customfield.unit.KILOGRAM" | "customfield.unit.KILOGRAM_PER_HOUR" | "customfield.unit.KILOGRAM_PER_SECOND" | "customfield.unit.KILOMETRE" | "customfield.unit.KILOMETRE_PER_HOUR" | "customfield.unit.KILOPASCAL" | "customfield.unit.KILOWATT" | "customfield.unit.KILOWATT_HOUR" | "customfield.unit.LITRE" | "customfield.unit.LITRES_PER_HOUR" | "customfield.unit.METRE" | "customfield.unit.METRE_PER_SECOND" | "customfield.unit.METRE_PER_SECOND_SQUARED" | "customfield.unit.METRIC_TON" | "customfield.unit.MILE" | "customfield.unit.MILE_PER_HOUR" | "customfield.unit.MILLIMETRE" | "customfield.unit.MILLISECOND" | "customfield.unit.MINUTE" | "customfield.unit.MONTH" | "customfield.unit.NEWTON" | "customfield.unit.OUNCE" | "customfield.unit.PASCAL" | "customfield.unit.PERCENT" | "customfield.unit.POUND" | "customfield.unit.POUND_PER_HOUR" | "customfield.unit.POUND_PER_SECOND" | "customfield.unit.POUND_PER_SQUARE_INCH" | "customfield.unit.REVOLUTIONS_PER_MINUTE" | "customfield.unit.SECOND" | "customfield.unit.SQUARE_FOOT" | "customfield.unit.SQUARE_KILOMETRE" | "customfield.unit.SQUARE_METRE" | "customfield.unit.TON" | "customfield.unit.US_TON" | "customfield.unit.VOLT" | "customfield.unit.VOLT_AMPERE" | "customfield.unit.WATT" | "customfield.unit.WEEK" | "customfield.unit.YARD" | "customfield.unit.YEAR">;
|
|
19
19
|
i18n: import("i18next").i18n;
|
|
20
20
|
ready: boolean;
|
|
21
21
|
};
|