@trackunit/custom-field-components 0.0.615 → 0.0.616
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 +130 -23
- package/index.esm.js +116 -10
- package/package.json +3 -2
- package/src/index.d.ts +1 -0
- package/src/translation.d.ts +34 -0
- package/src/useUnitTranslation.d.ts +8 -0
- package/translation.cjs.js +7 -0
- package/translation.cjs10.js +7 -0
- package/translation.cjs11.js +7 -0
- package/translation.cjs12.js +7 -0
- package/translation.cjs13.js +7 -0
- package/translation.cjs14.js +7 -0
- package/translation.cjs15.js +7 -0
- package/translation.cjs16.js +7 -0
- package/translation.cjs17.js +7 -0
- package/translation.cjs2.js +7 -0
- package/translation.cjs3.js +7 -0
- package/translation.cjs4.js +7 -0
- package/translation.cjs5.js +7 -0
- package/translation.cjs6.js +7 -0
- package/translation.cjs7.js +7 -0
- package/translation.cjs8.js +7 -0
- package/translation.cjs9.js +7 -0
- package/translation.esm.js +5 -0
- package/translation.esm10.js +5 -0
- package/translation.esm11.js +5 -0
- package/translation.esm12.js +5 -0
- package/translation.esm13.js +5 -0
- package/translation.esm14.js +5 -0
- package/translation.esm15.js +5 -0
- package/translation.esm16.js +5 -0
- package/translation.esm17.js +5 -0
- package/translation.esm2.js +5 -0
- package/translation.esm3.js +5 -0
- package/translation.esm4.js +5 -0
- package/translation.esm5.js +5 -0
- package/translation.esm6.js +5 -0
- package/translation.esm7.js +5 -0
- package/translation.esm8.js +5 -0
- package/translation.esm9.js +5 -0
package/index.cjs.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
6
7
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
7
8
|
var reactFormComponents = require('@trackunit/react-form-components');
|
|
8
9
|
var sharedUtils = require('@trackunit/shared-utils');
|
|
@@ -11,25 +12,110 @@ var uuid = require('uuid');
|
|
|
11
12
|
var libphonenumberJs = require('libphonenumber-js');
|
|
12
13
|
|
|
13
14
|
function _interopNamespace(e) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
}
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
25
24
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n["default"] = e;
|
|
29
|
+
return Object.freeze(n);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
32
33
|
|
|
34
|
+
var defaultTranslations = {
|
|
35
|
+
"customfield.unit.acre": "acre",
|
|
36
|
+
"customfield.unit.bar": "bar",
|
|
37
|
+
"customfield.unit.centimetre": "cm",
|
|
38
|
+
"customfield.unit.cubic_foot": "ft³",
|
|
39
|
+
"customfield.unit.cubic_metre": "m³",
|
|
40
|
+
"customfield.unit.foot": "ft",
|
|
41
|
+
"customfield.unit.gallon_liquid": "gal",
|
|
42
|
+
"customfield.unit.gram": "g",
|
|
43
|
+
"customfield.unit.hectare": "ha",
|
|
44
|
+
"customfield.unit.hour": "hr",
|
|
45
|
+
"customfield.unit.inch": "in",
|
|
46
|
+
"customfield.unit.kilogram": "kg",
|
|
47
|
+
"customfield.unit.kilogram_per_hour": "kg/hr",
|
|
48
|
+
"customfield.unit.kilogram_per_second": "kg/s",
|
|
49
|
+
"customfield.unit.kilometre": "km",
|
|
50
|
+
"customfield.unit.kilometre_per_hour": "km/h",
|
|
51
|
+
"customfield.unit.kilopascal": "kPa",
|
|
52
|
+
"customfield.unit.kilowatt": "kW",
|
|
53
|
+
"customfield.unit.kilowatthour": "kWh",
|
|
54
|
+
"customfield.unit.litre": "L",
|
|
55
|
+
"customfield.unit.metre": "m",
|
|
56
|
+
"customfield.unit.metre_per_second": "m/s",
|
|
57
|
+
"customfield.unit.metre_per_second_squared": "m/s²",
|
|
58
|
+
"customfield.unit.mile": "mi",
|
|
59
|
+
"customfield.unit.mile_per_hour": "mph",
|
|
60
|
+
"customfield.unit.millimetre": "mm",
|
|
61
|
+
"customfield.unit.newton": "N",
|
|
62
|
+
"customfield.unit.ounce": "oz",
|
|
63
|
+
"customfield.unit.pascal": "Pa",
|
|
64
|
+
"customfield.unit.pound": "lb",
|
|
65
|
+
"customfield.unit.pound_per_hour": "lb/hr",
|
|
66
|
+
"customfield.unit.pound_per_second": "lb/s",
|
|
67
|
+
"customfield.unit.pound_per_square_inch": "psi",
|
|
68
|
+
"customfield.unit.square_foot": "ft²",
|
|
69
|
+
"customfield.unit.square_kilometre": "km²",
|
|
70
|
+
"customfield.unit.square_metre": "m²",
|
|
71
|
+
"customfield.unit.ton": "ton",
|
|
72
|
+
"customfield.unit.ton_us": "ton (US)",
|
|
73
|
+
"customfield.unit.watt": "W",
|
|
74
|
+
"customfield.unit.yard": "yd"
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** The translation namespace for this library */
|
|
78
|
+
const namespace = "custom-field.components";
|
|
79
|
+
/**
|
|
80
|
+
* The TranslationResource for this Library.
|
|
81
|
+
* Holds lazy loaded imports for all languages supported by the library.
|
|
82
|
+
*
|
|
83
|
+
* This is used to register the translations for this library before initializing i18next.
|
|
84
|
+
*/
|
|
85
|
+
const translations = {
|
|
86
|
+
ns: namespace,
|
|
87
|
+
default: defaultTranslations,
|
|
88
|
+
languages: {
|
|
89
|
+
de: () => Promise.resolve().then(function () { return require('./translation.cjs.js'); }),
|
|
90
|
+
da: () => Promise.resolve().then(function () { return require('./translation.cjs2.js'); }),
|
|
91
|
+
cs: () => Promise.resolve().then(function () { return require('./translation.cjs3.js'); }),
|
|
92
|
+
nl: () => Promise.resolve().then(function () { return require('./translation.cjs4.js'); }),
|
|
93
|
+
fr: () => Promise.resolve().then(function () { return require('./translation.cjs5.js'); }),
|
|
94
|
+
fi: () => Promise.resolve().then(function () { return require('./translation.cjs6.js'); }),
|
|
95
|
+
hu: () => Promise.resolve().then(function () { return require('./translation.cjs7.js'); }),
|
|
96
|
+
it: () => Promise.resolve().then(function () { return require('./translation.cjs8.js'); }),
|
|
97
|
+
nb: () => Promise.resolve().then(function () { return require('./translation.cjs9.js'); }),
|
|
98
|
+
pl: () => Promise.resolve().then(function () { return require('./translation.cjs10.js'); }),
|
|
99
|
+
pt: () => Promise.resolve().then(function () { return require('./translation.cjs11.js'); }),
|
|
100
|
+
ru: () => Promise.resolve().then(function () { return require('./translation.cjs12.js'); }),
|
|
101
|
+
ro: () => Promise.resolve().then(function () { return require('./translation.cjs13.js'); }),
|
|
102
|
+
es: () => Promise.resolve().then(function () { return require('./translation.cjs14.js'); }),
|
|
103
|
+
sv: () => Promise.resolve().then(function () { return require('./translation.cjs15.js'); }),
|
|
104
|
+
ja: () => Promise.resolve().then(function () { return require('./translation.cjs16.js'); }),
|
|
105
|
+
th: () => Promise.resolve().then(function () { return require('./translation.cjs17.js'); }),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Local useTranslation for this specific library
|
|
110
|
+
*/
|
|
111
|
+
const useTranslation = () => i18nLibraryTranslation.useNamespaceTranslation(namespace);
|
|
112
|
+
/**
|
|
113
|
+
* Registers the translations for this library
|
|
114
|
+
*/
|
|
115
|
+
const setupLibraryTranslations = () => {
|
|
116
|
+
i18nLibraryTranslation.registerTranslations(translations);
|
|
117
|
+
};
|
|
118
|
+
|
|
33
119
|
/******************************************************************************
|
|
34
120
|
Copyright (c) Microsoft Corporation.
|
|
35
121
|
|
|
@@ -286,6 +372,20 @@ const getPhoneNumberValidationRules = (definition) => {
|
|
|
286
372
|
? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
|
|
287
373
|
};
|
|
288
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Returns the translation for a unit.
|
|
377
|
+
*/
|
|
378
|
+
const useUnitTranslation = () => {
|
|
379
|
+
const { t } = useTranslation();
|
|
380
|
+
const unitTranslation = React.useCallback((unit) => {
|
|
381
|
+
if (!unit) {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
return t(`customfield.unit.${unit}`);
|
|
385
|
+
}, [t]);
|
|
386
|
+
return { unitTranslation };
|
|
387
|
+
};
|
|
388
|
+
|
|
289
389
|
/**
|
|
290
390
|
* A hook that resolves and returns a JSX Element for a given custom field.
|
|
291
391
|
* It handles various custom field types by providing appropriate validation rules
|
|
@@ -298,14 +398,13 @@ const getPhoneNumberValidationRules = (definition) => {
|
|
|
298
398
|
const useCustomFieldResolver = ({ field, register, setValue, formState, unitPreference = "SI", language, fieldId, isEditable, }) => {
|
|
299
399
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
300
400
|
const validation = { register, setValue, formState };
|
|
401
|
+
const { unitTranslation } = useUnitTranslation();
|
|
301
402
|
const [numberValue, setNumberValue] = React.useState(() => {
|
|
302
403
|
if (field.definition && field.__typename === "NumberFieldValueAndDefinition") {
|
|
303
404
|
const fieldValue = field.numberValue;
|
|
304
405
|
const unit = unitPreference === "US_CUSTOMARY" && field.definition.unitUs
|
|
305
|
-
?
|
|
306
|
-
: field.definition.unitSi
|
|
307
|
-
? `${field.definition.unitSi}`
|
|
308
|
-
: null;
|
|
406
|
+
? field.definition.unitUs
|
|
407
|
+
: field.definition.unitSi;
|
|
309
408
|
const value = irisAppRuntimeCore.CustomFieldRuntime.getCustomFieldValueForDisplayInUI(fieldValue, unit, unitPreference, language);
|
|
310
409
|
return value;
|
|
311
410
|
}
|
|
@@ -349,13 +448,11 @@ const useCustomFieldResolver = ({ field, register, setValue, formState, unitPref
|
|
|
349
448
|
const value = field.numberValue;
|
|
350
449
|
const rules = getNumberValidationRules(field.definition);
|
|
351
450
|
const unit = unitPreference === "US_CUSTOMARY" && field.definition.unitUs
|
|
352
|
-
?
|
|
353
|
-
: field.definition.unitSi
|
|
354
|
-
? `${field.definition.unitSi}`
|
|
355
|
-
: null;
|
|
451
|
+
? field.definition.unitUs
|
|
452
|
+
: field.definition.unitSi;
|
|
356
453
|
const numberProps = {
|
|
357
454
|
placeholder: title !== null && title !== void 0 ? title : "",
|
|
358
|
-
addonAfter: unit,
|
|
455
|
+
addonAfter: unitTranslation(unit),
|
|
359
456
|
};
|
|
360
457
|
return (jsxRuntime.jsx(reactFormComponents.NumberField, Object.assign({ label: title, id: uniqueIdentifier, defaultValue: value !== null && value !== void 0 ? value : "", step: field.definition.isInteger ? 1 : "any", min: (_b = field.definition.minimumNumber) !== null && _b !== void 0 ? _b : undefined, max: (_c = field.definition.maximumNumber) !== null && _c !== void 0 ? _c : undefined, readOnly: !isEditableCombined, helpText: description, errorMessage: errorMessage, dataTestId: `${field.definition.key}` }, validation.register(key, rules), numberProps)));
|
|
361
458
|
}
|
|
@@ -413,5 +510,15 @@ const CustomField = (props) => {
|
|
|
413
510
|
return fieldComponent;
|
|
414
511
|
};
|
|
415
512
|
|
|
513
|
+
/*
|
|
514
|
+
* ----------------------------
|
|
515
|
+
* | SETUP TRANSLATIONS START |
|
|
516
|
+
* ----------------------------
|
|
517
|
+
* This import and function call is needed to register translations for this library.
|
|
518
|
+
* Do not remove this if this library has translations.
|
|
519
|
+
*/
|
|
520
|
+
setupLibraryTranslations();
|
|
521
|
+
|
|
416
522
|
exports.CustomField = CustomField;
|
|
417
523
|
exports.useCustomFieldResolver = useCustomFieldResolver;
|
|
524
|
+
exports.useUnitTranslation = useUnitTranslation;
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
2
3
|
import { CustomFieldRuntime } from '@trackunit/iris-app-runtime-core';
|
|
3
4
|
import { FormGroup, Checkbox, DateField, Select, NumberField, TextField, PhoneField, ActionButton } from '@trackunit/react-form-components';
|
|
4
5
|
import { exhaustiveCheck } from '@trackunit/shared-utils';
|
|
@@ -7,6 +8,91 @@ import { useCallback, useEffect, createElement, useState } from 'react';
|
|
|
7
8
|
import { v4 } from 'uuid';
|
|
8
9
|
import { isValidPhoneNumber } from 'libphonenumber-js';
|
|
9
10
|
|
|
11
|
+
var defaultTranslations = {
|
|
12
|
+
"customfield.unit.acre": "acre",
|
|
13
|
+
"customfield.unit.bar": "bar",
|
|
14
|
+
"customfield.unit.centimetre": "cm",
|
|
15
|
+
"customfield.unit.cubic_foot": "ft³",
|
|
16
|
+
"customfield.unit.cubic_metre": "m³",
|
|
17
|
+
"customfield.unit.foot": "ft",
|
|
18
|
+
"customfield.unit.gallon_liquid": "gal",
|
|
19
|
+
"customfield.unit.gram": "g",
|
|
20
|
+
"customfield.unit.hectare": "ha",
|
|
21
|
+
"customfield.unit.hour": "hr",
|
|
22
|
+
"customfield.unit.inch": "in",
|
|
23
|
+
"customfield.unit.kilogram": "kg",
|
|
24
|
+
"customfield.unit.kilogram_per_hour": "kg/hr",
|
|
25
|
+
"customfield.unit.kilogram_per_second": "kg/s",
|
|
26
|
+
"customfield.unit.kilometre": "km",
|
|
27
|
+
"customfield.unit.kilometre_per_hour": "km/h",
|
|
28
|
+
"customfield.unit.kilopascal": "kPa",
|
|
29
|
+
"customfield.unit.kilowatt": "kW",
|
|
30
|
+
"customfield.unit.kilowatthour": "kWh",
|
|
31
|
+
"customfield.unit.litre": "L",
|
|
32
|
+
"customfield.unit.metre": "m",
|
|
33
|
+
"customfield.unit.metre_per_second": "m/s",
|
|
34
|
+
"customfield.unit.metre_per_second_squared": "m/s²",
|
|
35
|
+
"customfield.unit.mile": "mi",
|
|
36
|
+
"customfield.unit.mile_per_hour": "mph",
|
|
37
|
+
"customfield.unit.millimetre": "mm",
|
|
38
|
+
"customfield.unit.newton": "N",
|
|
39
|
+
"customfield.unit.ounce": "oz",
|
|
40
|
+
"customfield.unit.pascal": "Pa",
|
|
41
|
+
"customfield.unit.pound": "lb",
|
|
42
|
+
"customfield.unit.pound_per_hour": "lb/hr",
|
|
43
|
+
"customfield.unit.pound_per_second": "lb/s",
|
|
44
|
+
"customfield.unit.pound_per_square_inch": "psi",
|
|
45
|
+
"customfield.unit.square_foot": "ft²",
|
|
46
|
+
"customfield.unit.square_kilometre": "km²",
|
|
47
|
+
"customfield.unit.square_metre": "m²",
|
|
48
|
+
"customfield.unit.ton": "ton",
|
|
49
|
+
"customfield.unit.ton_us": "ton (US)",
|
|
50
|
+
"customfield.unit.watt": "W",
|
|
51
|
+
"customfield.unit.yard": "yd"
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** The translation namespace for this library */
|
|
55
|
+
const namespace = "custom-field.components";
|
|
56
|
+
/**
|
|
57
|
+
* The TranslationResource for this Library.
|
|
58
|
+
* Holds lazy loaded imports for all languages supported by the library.
|
|
59
|
+
*
|
|
60
|
+
* This is used to register the translations for this library before initializing i18next.
|
|
61
|
+
*/
|
|
62
|
+
const translations = {
|
|
63
|
+
ns: namespace,
|
|
64
|
+
default: defaultTranslations,
|
|
65
|
+
languages: {
|
|
66
|
+
de: () => import('./translation.esm.js'),
|
|
67
|
+
da: () => import('./translation.esm2.js'),
|
|
68
|
+
cs: () => import('./translation.esm3.js'),
|
|
69
|
+
nl: () => import('./translation.esm4.js'),
|
|
70
|
+
fr: () => import('./translation.esm5.js'),
|
|
71
|
+
fi: () => import('./translation.esm6.js'),
|
|
72
|
+
hu: () => import('./translation.esm7.js'),
|
|
73
|
+
it: () => import('./translation.esm8.js'),
|
|
74
|
+
nb: () => import('./translation.esm9.js'),
|
|
75
|
+
pl: () => import('./translation.esm10.js'),
|
|
76
|
+
pt: () => import('./translation.esm11.js'),
|
|
77
|
+
ru: () => import('./translation.esm12.js'),
|
|
78
|
+
ro: () => import('./translation.esm13.js'),
|
|
79
|
+
es: () => import('./translation.esm14.js'),
|
|
80
|
+
sv: () => import('./translation.esm15.js'),
|
|
81
|
+
ja: () => import('./translation.esm16.js'),
|
|
82
|
+
th: () => import('./translation.esm17.js'),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Local useTranslation for this specific library
|
|
87
|
+
*/
|
|
88
|
+
const useTranslation = () => useNamespaceTranslation(namespace);
|
|
89
|
+
/**
|
|
90
|
+
* Registers the translations for this library
|
|
91
|
+
*/
|
|
92
|
+
const setupLibraryTranslations = () => {
|
|
93
|
+
registerTranslations(translations);
|
|
94
|
+
};
|
|
95
|
+
|
|
10
96
|
/******************************************************************************
|
|
11
97
|
Copyright (c) Microsoft Corporation.
|
|
12
98
|
|
|
@@ -263,6 +349,20 @@ const getPhoneNumberValidationRules = (definition) => {
|
|
|
263
349
|
? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
|
|
264
350
|
};
|
|
265
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Returns the translation for a unit.
|
|
354
|
+
*/
|
|
355
|
+
const useUnitTranslation = () => {
|
|
356
|
+
const { t } = useTranslation();
|
|
357
|
+
const unitTranslation = useCallback((unit) => {
|
|
358
|
+
if (!unit) {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
return t(`customfield.unit.${unit}`);
|
|
362
|
+
}, [t]);
|
|
363
|
+
return { unitTranslation };
|
|
364
|
+
};
|
|
365
|
+
|
|
266
366
|
/**
|
|
267
367
|
* A hook that resolves and returns a JSX Element for a given custom field.
|
|
268
368
|
* It handles various custom field types by providing appropriate validation rules
|
|
@@ -275,14 +375,13 @@ const getPhoneNumberValidationRules = (definition) => {
|
|
|
275
375
|
const useCustomFieldResolver = ({ field, register, setValue, formState, unitPreference = "SI", language, fieldId, isEditable, }) => {
|
|
276
376
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
277
377
|
const validation = { register, setValue, formState };
|
|
378
|
+
const { unitTranslation } = useUnitTranslation();
|
|
278
379
|
const [numberValue, setNumberValue] = useState(() => {
|
|
279
380
|
if (field.definition && field.__typename === "NumberFieldValueAndDefinition") {
|
|
280
381
|
const fieldValue = field.numberValue;
|
|
281
382
|
const unit = unitPreference === "US_CUSTOMARY" && field.definition.unitUs
|
|
282
|
-
?
|
|
283
|
-
: field.definition.unitSi
|
|
284
|
-
? `${field.definition.unitSi}`
|
|
285
|
-
: null;
|
|
383
|
+
? field.definition.unitUs
|
|
384
|
+
: field.definition.unitSi;
|
|
286
385
|
const value = CustomFieldRuntime.getCustomFieldValueForDisplayInUI(fieldValue, unit, unitPreference, language);
|
|
287
386
|
return value;
|
|
288
387
|
}
|
|
@@ -326,13 +425,11 @@ const useCustomFieldResolver = ({ field, register, setValue, formState, unitPref
|
|
|
326
425
|
const value = field.numberValue;
|
|
327
426
|
const rules = getNumberValidationRules(field.definition);
|
|
328
427
|
const unit = unitPreference === "US_CUSTOMARY" && field.definition.unitUs
|
|
329
|
-
?
|
|
330
|
-
: field.definition.unitSi
|
|
331
|
-
? `${field.definition.unitSi}`
|
|
332
|
-
: null;
|
|
428
|
+
? field.definition.unitUs
|
|
429
|
+
: field.definition.unitSi;
|
|
333
430
|
const numberProps = {
|
|
334
431
|
placeholder: title !== null && title !== void 0 ? title : "",
|
|
335
|
-
addonAfter: unit,
|
|
432
|
+
addonAfter: unitTranslation(unit),
|
|
336
433
|
};
|
|
337
434
|
return (jsx(NumberField, Object.assign({ label: title, id: uniqueIdentifier, defaultValue: value !== null && value !== void 0 ? value : "", step: field.definition.isInteger ? 1 : "any", min: (_b = field.definition.minimumNumber) !== null && _b !== void 0 ? _b : undefined, max: (_c = field.definition.maximumNumber) !== null && _c !== void 0 ? _c : undefined, readOnly: !isEditableCombined, helpText: description, errorMessage: errorMessage, dataTestId: `${field.definition.key}` }, validation.register(key, rules), numberProps)));
|
|
338
435
|
}
|
|
@@ -390,4 +487,13 @@ const CustomField = (props) => {
|
|
|
390
487
|
return fieldComponent;
|
|
391
488
|
};
|
|
392
489
|
|
|
393
|
-
|
|
490
|
+
/*
|
|
491
|
+
* ----------------------------
|
|
492
|
+
* | SETUP TRANSLATIONS START |
|
|
493
|
+
* ----------------------------
|
|
494
|
+
* This import and function call is needed to register translations for this library.
|
|
495
|
+
* Do not remove this if this library has translations.
|
|
496
|
+
*/
|
|
497
|
+
setupLibraryTranslations();
|
|
498
|
+
|
|
499
|
+
export { CustomField, useCustomFieldResolver, useUnitTranslation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/custom-field-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.616",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"react-select": "^5.8.0",
|
|
19
19
|
"libphonenumber-js": "1.10.36",
|
|
20
20
|
"@testing-library/react": "14.0.0",
|
|
21
|
-
"jest-fetch-mock": "^3.0.3"
|
|
21
|
+
"jest-fetch-mock": "^3.0.3",
|
|
22
|
+
"@trackunit/i18n-library-translation": "*"
|
|
22
23
|
},
|
|
23
24
|
"module": "./index.esm.js",
|
|
24
25
|
"main": "./index.cjs.js"
|
package/src/index.d.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { NamespaceTransProps, TransForLibs, TranslationResource } from "@trackunit/i18n-library-translation";
|
|
3
|
+
import defaultTranslations from "./locales/en/translation.json";
|
|
4
|
+
/** A type for all available translation keys in this library */
|
|
5
|
+
export type TranslationKeys = keyof typeof defaultTranslations;
|
|
6
|
+
/** The translation namespace for this library */
|
|
7
|
+
export declare const namespace = "custom-field.components";
|
|
8
|
+
/**
|
|
9
|
+
* The TranslationResource for this Library.
|
|
10
|
+
* Holds lazy loaded imports for all languages supported by the library.
|
|
11
|
+
*
|
|
12
|
+
* This is used to register the translations for this library before initializing i18next.
|
|
13
|
+
*/
|
|
14
|
+
export declare const translations: TranslationResource<TranslationKeys>;
|
|
15
|
+
/**
|
|
16
|
+
* Local useTranslation for this specific library
|
|
17
|
+
*/
|
|
18
|
+
export declare const useTranslation: () => [TransForLibs<"customfield.unit.acre" | "customfield.unit.bar" | "customfield.unit.centimetre" | "customfield.unit.cubic_foot" | "customfield.unit.cubic_metre" | "customfield.unit.foot" | "customfield.unit.gallon_liquid" | "customfield.unit.gram" | "customfield.unit.hectare" | "customfield.unit.hour" | "customfield.unit.inch" | "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.kilowatthour" | "customfield.unit.litre" | "customfield.unit.metre" | "customfield.unit.metre_per_second" | "customfield.unit.metre_per_second_squared" | "customfield.unit.mile" | "customfield.unit.mile_per_hour" | "customfield.unit.millimetre" | "customfield.unit.newton" | "customfield.unit.ounce" | "customfield.unit.pascal" | "customfield.unit.pound" | "customfield.unit.pound_per_hour" | "customfield.unit.pound_per_second" | "customfield.unit.pound_per_square_inch" | "customfield.unit.square_foot" | "customfield.unit.square_kilometre" | "customfield.unit.square_metre" | "customfield.unit.ton" | "customfield.unit.ton_us" | "customfield.unit.watt" | "customfield.unit.yard">, import("i18next").i18n, boolean] & {
|
|
19
|
+
t: TransForLibs<"customfield.unit.acre" | "customfield.unit.bar" | "customfield.unit.centimetre" | "customfield.unit.cubic_foot" | "customfield.unit.cubic_metre" | "customfield.unit.foot" | "customfield.unit.gallon_liquid" | "customfield.unit.gram" | "customfield.unit.hectare" | "customfield.unit.hour" | "customfield.unit.inch" | "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.kilowatthour" | "customfield.unit.litre" | "customfield.unit.metre" | "customfield.unit.metre_per_second" | "customfield.unit.metre_per_second_squared" | "customfield.unit.mile" | "customfield.unit.mile_per_hour" | "customfield.unit.millimetre" | "customfield.unit.newton" | "customfield.unit.ounce" | "customfield.unit.pascal" | "customfield.unit.pound" | "customfield.unit.pound_per_hour" | "customfield.unit.pound_per_second" | "customfield.unit.pound_per_square_inch" | "customfield.unit.square_foot" | "customfield.unit.square_kilometre" | "customfield.unit.square_metre" | "customfield.unit.ton" | "customfield.unit.ton_us" | "customfield.unit.watt" | "customfield.unit.yard">;
|
|
20
|
+
i18n: import("i18next").i18n;
|
|
21
|
+
ready: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Type of the t function for the local useTranslation for this specific library
|
|
25
|
+
*/
|
|
26
|
+
export type TranslationFunction = TransForLibs<TranslationKeys>;
|
|
27
|
+
/**
|
|
28
|
+
* Trans for this specific library.
|
|
29
|
+
*/
|
|
30
|
+
export declare const Trans: (props: NamespaceTransProps<TranslationKeys>) => JSX.Element;
|
|
31
|
+
/**
|
|
32
|
+
* Registers the translations for this library
|
|
33
|
+
*/
|
|
34
|
+
export declare const setupLibraryTranslations: () => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UnitSiType, UnitUsType } from "@trackunit/iris-app-runtime-core-api";
|
|
2
|
+
export type UnitType = UnitSiType | UnitUsType | undefined | null;
|
|
3
|
+
/**
|
|
4
|
+
* Returns the translation for a unit.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useUnitTranslation: () => {
|
|
7
|
+
unitTranslation: (unit: UnitType) => string | null;
|
|
8
|
+
};
|