@trackunit/custom-field-components 0.0.279 → 0.0.281-alpha-0b53b6cf53.0

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.
Files changed (2) hide show
  1. package/index.cjs +399 -0
  2. package/package.json +6 -6
package/index.cjs ADDED
@@ -0,0 +1,399 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var irisAppRuntimeCoreApi = require('@trackunit/iris-app-runtime-core-api');
7
+ var reactComponents = require('@trackunit/react-components');
8
+ var tailwindStyledComponents = require('@trackunit/tailwind-styled-components');
9
+ var React = require('react');
10
+ var libphonenumberJs = require('libphonenumber-js');
11
+
12
+ function _interopNamespace(e) {
13
+ if (e && e.__esModule) return e;
14
+ var n = Object.create(null);
15
+ if (e) {
16
+ Object.keys(e).forEach(function (k) {
17
+ if (k !== 'default') {
18
+ var d = Object.getOwnPropertyDescriptor(e, k);
19
+ Object.defineProperty(n, k, d.get ? d : {
20
+ enumerable: true,
21
+ get: function () { return e[k]; }
22
+ });
23
+ }
24
+ });
25
+ }
26
+ n["default"] = e;
27
+ return Object.freeze(n);
28
+ }
29
+
30
+ var React__namespace = /*#__PURE__*/_interopNamespace(React);
31
+
32
+ /******************************************************************************
33
+ Copyright (c) Microsoft Corporation.
34
+
35
+ Permission to use, copy, modify, and/or distribute this software for any
36
+ purpose with or without fee is hereby granted.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
39
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
40
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
41
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
42
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
43
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
44
+ PERFORMANCE OF THIS SOFTWARE.
45
+ ***************************************************************************** */
46
+
47
+ function __rest(s, e) {
48
+ var t = {};
49
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
50
+ t[p] = s[p];
51
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
52
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
53
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
54
+ t[p[i]] = s[p[i]];
55
+ }
56
+ return t;
57
+ }
58
+
59
+ /**
60
+ * A component that can be used to render a boolean field
61
+ *
62
+ * @param options BooleanCustomFieldProps - options for the component
63
+ * @returns { JSX.Element } JSX.Element - a component that can be used to render a boolean field
64
+ */
65
+ const BooleanCustomField = (_a) => {
66
+ var { defaultValue, dataTestId = "booleanField", onChange, value, id, setValue, register, validationRules, disabled = false, label, tip, isInvalid, errorMessage, helpAddon, maxLength, helpText } = _a, rest = __rest(_a, ["defaultValue", "dataTestId", "onChange", "value", "id", "setValue", "register", "validationRules", "disabled", "label", "tip", "isInvalid", "errorMessage", "helpAddon", "maxLength", "helpText"]);
67
+ const initialValue = value !== undefined ? value : defaultValue ? defaultValue : false;
68
+ const renderAsInvalid = isInvalid || Boolean(errorMessage);
69
+ const [internalValue, setInternalValue] = React__namespace.useState(initialValue);
70
+ React__namespace.useEffect(() => {
71
+ setInternalValue((value === undefined ? defaultValue : value) || false);
72
+ }, [value, setInternalValue, defaultValue]);
73
+ const onChangeHandler = React__namespace.useCallback((event) => {
74
+ var _a;
75
+ onChange && onChange(event);
76
+ const isChecked = ((_a = event.target) === null || _a === void 0 ? void 0 : _a.checked) || false;
77
+ if (setValue) {
78
+ setValue(id, isChecked);
79
+ }
80
+ setInternalValue(isChecked);
81
+ }, [setInternalValue, onChange, id, setValue]);
82
+ React__namespace.useEffect(() => {
83
+ register && register(id, Object.assign(Object.assign({}, validationRules), { value: internalValue.toString() }));
84
+ // eslint-disable-next-line react-hooks/exhaustive-deps
85
+ }, []); // register only once
86
+ return (jsxRuntime.jsx(reactComponents.FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, helpAddon: helpAddon || null, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsxRuntime.jsx(reactComponents.Checkbox, Object.assign({ checked: internalValue, dataTestId: dataTestId, id: id, disabled: disabled, name: id, onChange: onChangeHandler, isInvalid: renderAsInvalid }, rest)) })));
87
+ };
88
+
89
+ /**
90
+ * A component that can be used to render a date field
91
+ *
92
+ * @param props DateCustomFieldProps - options for the component
93
+ * @returns { JSX.Element } JSX.Element - a component that can be used to render a date field
94
+ */
95
+ const DateCustomField = (props) => {
96
+ const { setValue, defaultValue, register, id, validationRules } = props, rest = __rest(props, ["setValue", "defaultValue", "register", "id", "validationRules"]);
97
+ const onChangeHandler = React.useCallback((e) => {
98
+ var _a, _b, _c, _d;
99
+ if (((_b = (_a = e.target) === null || _a === void 0 ? void 0 : _a.valueAsDate) === null || _b === void 0 ? void 0 : _b.toISOString()) !== undefined) {
100
+ setValue && setValue(id, (_d = (_c = e.target) === null || _c === void 0 ? void 0 : _c.valueAsDate) === null || _d === void 0 ? void 0 : _d.toISOString());
101
+ }
102
+ }, [setValue, id]);
103
+ React.useEffect(() => {
104
+ const value = defaultValue && new Date(defaultValue);
105
+ register && register(id, Object.assign(Object.assign({}, validationRules), { value }));
106
+ }, [register, validationRules, defaultValue, id]);
107
+ return (jsxRuntime.jsx(reactComponents.DateField, Object.assign({}, rest, { helpAddon: props.helpAddon || null, helpText: props.errorMessage || props.helpText, onChange: onChangeHandler, label: props.title, defaultValue: defaultValue })));
108
+ };
109
+
110
+ const convertToValueFormat = (value) => {
111
+ return { label: value, value };
112
+ };
113
+ /**
114
+ * A custom field that can be used to render a dropdown
115
+ *
116
+ * @param options DropdownCustomFieldProps - an object with all the props
117
+ * @returns {JSX.Element} - a dropdown component
118
+ */
119
+ const DropdownCustomField = ({ defaultValue, dataTestId, onChange, onBlur, id, disabled = false, allValues, multiSelect = false, register, validationRules, setValue, label, tip, errorMessage, helpText, isInvalid, helpAddon, }) => {
120
+ const renderAsInvalid = isInvalid || Boolean(errorMessage);
121
+ const [selectedValue, setSelectedValue] = React__namespace.useState(defaultValue ? defaultValue.map(convertToValueFormat) : []);
122
+ const onChangeHandler = React__namespace.useCallback((selected) => {
123
+ if (selected) {
124
+ const values = Array.isArray(selected) ? selected : [selected];
125
+ setSelectedValue(values);
126
+ setValue && setValue(id, values);
127
+ }
128
+ else {
129
+ setSelectedValue([]);
130
+ setValue && setValue(id, []);
131
+ }
132
+ }, [onChange]);
133
+ const options = React__namespace.useMemo(() => {
134
+ return allValues ? allValues.map(convertToValueFormat) : [];
135
+ }, [allValues]);
136
+ React__namespace.useEffect(() => {
137
+ register && register(id, Object.assign(Object.assign({}, validationRules), { value: selectedValue }));
138
+ }, [register, validationRules, selectedValue, id]);
139
+ return (jsxRuntime.jsx(reactComponents.FormGroup, Object.assign({ label: label, tip: tip, isInvalid: renderAsInvalid, helpText: errorMessage || helpText, helpAddon: helpAddon || null, dataTestId: dataTestId && `${dataTestId}-FormGroup` }, { children: jsxRuntime.jsx(reactComponents.Select, { disabled: disabled, dataTestId: dataTestId, onChange: onChangeHandler, hasError: renderAsInvalid, options: options, value: selectedValue, isMulti: multiSelect, isClearable: true }) })));
140
+ };
141
+
142
+ /**
143
+ * Get validation rules for a field
144
+ *
145
+ * @param { WebAddressFieldDefinition } definition the field definition
146
+ * @returns { ValidationRules} the validation rules
147
+ */
148
+ const getWebAddressValidationRules = (definition) => {
149
+ const defaultRules = {};
150
+ const pattern = {
151
+ pattern: {
152
+ value: RegExp("^(((https?|ftps?)://)(%[0-9A-Fa-f]{2}|[-()_.!~*';/?:@&=+$,A-Za-z0-9])+)([).!';/?:,][[:blank:|:blank:]])?$"),
153
+ message: `Must match url pattern`,
154
+ },
155
+ };
156
+ return definition.uiEditable
157
+ ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
158
+ };
159
+ /**
160
+ * Get validation rules for a field.
161
+ *
162
+ * @param { NumberFieldDefinition } definition the field definition
163
+ * @returns { ValidationRules} the validation rules
164
+ */
165
+ const getNumberValidationRules = (definition) => {
166
+ const defaultRules = { valueAsNumber: true };
167
+ const minimum = definition.minimumNumber && {
168
+ min: {
169
+ value: definition.minimumNumber,
170
+ message: `minimum value is ${definition.minimumNumber}`,
171
+ },
172
+ };
173
+ const maximum = definition.maximumNumber && {
174
+ max: {
175
+ value: definition.maximumNumber,
176
+ message: `maximum value is ${definition.maximumNumber}`,
177
+ },
178
+ };
179
+ // TODO: Validate if integer if definition requires integer
180
+ return definition.uiEditable
181
+ ? Object.assign(Object.assign(Object.assign({}, maximum), minimum), defaultRules) : defaultRules;
182
+ };
183
+ /**
184
+ * Get validation rules for a string field.
185
+ *
186
+ * @param { StringFieldDefinition } definition the field definition
187
+ * @returns { ValidationRules} the validation rules
188
+ */
189
+ const getStringValidationRules = (definition) => {
190
+ const defaultRules = {};
191
+ const minLength = definition.minimumLength
192
+ ? {
193
+ minLength: {
194
+ value: definition.minimumLength,
195
+ message: `minimum length is ${definition.minimumLength}`,
196
+ },
197
+ required: {
198
+ value: true,
199
+ message: `minimum length is ${definition.minimumLength}`,
200
+ },
201
+ }
202
+ : undefined;
203
+ const maxLength = definition.maximumLength
204
+ ? {
205
+ maxLength: {
206
+ value: definition.maximumLength,
207
+ message: `maximum length is ${definition.maximumLength}`,
208
+ },
209
+ }
210
+ : undefined;
211
+ const pattern = definition.pattern
212
+ ? {
213
+ pattern: {
214
+ value: RegExp(definition.pattern),
215
+ message: `Must match pattern: ${definition.pattern}`,
216
+ },
217
+ }
218
+ : undefined;
219
+ return definition.uiEditable
220
+ ? Object.assign(Object.assign(Object.assign(Object.assign({}, maxLength), minLength), pattern), defaultRules) : defaultRules;
221
+ };
222
+ /**
223
+ * Get validation rules for a boolean field.
224
+ *
225
+ * @param { BooleanFieldDefinition } definition the field definition
226
+ * @returns { ValidationRules} the validation rules
227
+ */
228
+ const getBooleanValidationRules = (definition) => {
229
+ const defaultRules = {};
230
+ return defaultRules;
231
+ };
232
+ /**
233
+ * Get validation rules for a dropdown field.
234
+ *
235
+ * @param { DropDownFieldDefinition } definition the field definition
236
+ * @returns { ValidationRules} the validation rules
237
+ */
238
+ const getDropdownValidationRules = (definition) => {
239
+ const defaultRules = {};
240
+ return defaultRules;
241
+ };
242
+ /**
243
+ * Get validation rules for a date field.
244
+ *
245
+ * @param { DateFieldDefinition } definition the field definition
246
+ * @returns { ValidationRules} the validation rules
247
+ */
248
+ const getDateValidationRules = (definition) => {
249
+ const defaultRules = {};
250
+ return defaultRules;
251
+ };
252
+ /**
253
+ * Get validation rules for an email field.
254
+ *
255
+ * @param { EmailFieldDefinition } definition the field definition
256
+ * @returns { ValidationRules} the validation rules
257
+ */
258
+ const getEmailValidationRules = (definition) => {
259
+ const defaultRules = {};
260
+ const pattern = {
261
+ pattern: {
262
+ value: RegExp("^[a-zA-Z0-9_+&*-]+(?:.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,7}$"),
263
+ message: `Must match email pattern`,
264
+ },
265
+ };
266
+ return definition.uiEditable
267
+ ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
268
+ };
269
+ /**
270
+ * Get validation rules for a phonenumber field.
271
+ *
272
+ * @param { PhoneNumberFieldDefinition } definition the field definition
273
+ * @returns { ValidationRules} the validation rules
274
+ */
275
+ const getPhoneNumberValidationRules = (definition) => {
276
+ const defaultRules = {};
277
+ const pattern = {
278
+ validate: value => libphonenumberJs.isValidPhoneNumber(value) || value === "",
279
+ };
280
+ return definition.uiEditable
281
+ ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
282
+ };
283
+
284
+ /**
285
+ * A component that renders a custom field based on the field definition
286
+ *
287
+ * @param field A field definition and value
288
+ * @param validation A validation object that contains the register, setValue and formState
289
+ * @param unitPreference A unit preference that can be used to override the default unit preference
290
+ * @param fieldId An optional Id to override the definition.key
291
+ * @returns { JSX.Element } A JSX.Element or null if the field definition is undefined
292
+ */
293
+ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldId) => {
294
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
295
+ const [isEditing, setIsEditing] = React.useState(false);
296
+ const [numberValue, setNumberValue] = React.useState(() => {
297
+ var _a;
298
+ if ((field === null || field === void 0 ? void 0 : field.definition) && field.definition.type === irisAppRuntimeCoreApi.CustomFieldType.NUMBER) {
299
+ const typedValue = field.value;
300
+ return (_a = typedValue.numberValue) !== null && _a !== void 0 ? _a : field.definition.defaultNumberValue;
301
+ }
302
+ else {
303
+ return "";
304
+ }
305
+ });
306
+ if ((field === null || field === void 0 ? void 0 : field.definition) === undefined || ((_a = field === null || field === void 0 ? void 0 : field.definition) === null || _a === void 0 ? void 0 : _a.type) === undefined) {
307
+ return null;
308
+ }
309
+ const key = (_b = fieldId !== null && fieldId !== void 0 ? fieldId : field.definition.key) !== null && _b !== void 0 ? _b : "";
310
+ const fieldError = key ? validation.formState.errors[key] : undefined;
311
+ const errorMessage = fieldError ? fieldError.message + "" : undefined;
312
+ const { type, description, title } = field.definition;
313
+ switch (type) {
314
+ case irisAppRuntimeCoreApi.CustomFieldType.WEB_ADDRESS: {
315
+ const typedDefinition = field.definition;
316
+ const typedValue = field.value;
317
+ const rules = getWebAddressValidationRules(typedDefinition);
318
+ return (jsxRuntime.jsx(reactComponents.TextField, Object.assign({ id: key, label: title, placeholder: (_c = typedDefinition.title) !== null && _c !== void 0 ? _c : "", defaultValue: (_e = (_d = typedValue.stringValue) !== null && _d !== void 0 ? _d : typedDefinition.defaultStringValue) !== null && _e !== void 0 ? _e : "", dataTestId: "webAddressField", actions: !typedDefinition.uiEditable &&
319
+ (typedValue.stringValue || typedDefinition.defaultStringValue) && (jsxRuntime.jsx(reactComponents.ActionButton, { value: (_f = typedValue.stringValue) !== null && _f !== void 0 ? _f : typedDefinition.defaultStringValue, type: "WEB_ADDRESS" })), readOnly: !typedDefinition.uiEditable, helpText: description, errorMessage: errorMessage }, validation.register(key, rules))));
320
+ }
321
+ case irisAppRuntimeCoreApi.CustomFieldType.EMAIL: {
322
+ const typedDefinition = field.definition;
323
+ const typedValue = field.value;
324
+ const rules = getEmailValidationRules(typedDefinition);
325
+ return (jsxRuntime.jsx(reactComponents.TextField, Object.assign({ id: key, label: title, placeholder: (_g = typedDefinition.title) !== null && _g !== void 0 ? _g : "", defaultValue: (_j = (_h = typedValue.stringValue) !== null && _h !== void 0 ? _h : typedDefinition.defaultStringValue) !== null && _j !== void 0 ? _j : "", actions: !typedDefinition.uiEditable &&
326
+ (typedValue.stringValue || typedDefinition.defaultStringValue) && (jsxRuntime.jsx(reactComponents.ActionButton, { value: (_k = typedValue.stringValue) !== null && _k !== void 0 ? _k : typedDefinition.defaultStringValue, type: "EMAIL" })), readOnly: !typedDefinition.uiEditable, helpText: description, errorMessage: errorMessage }, validation.register(key, rules))));
327
+ }
328
+ case irisAppRuntimeCoreApi.CustomFieldType.PHONE_NUMBER: {
329
+ const typedDefinition = field.definition;
330
+ const typedValue = field.value;
331
+ const rules = getPhoneNumberValidationRules(typedDefinition);
332
+ return (jsxRuntime.jsx(reactComponents.TextField, Object.assign({ label: title, id: key, placeholder: (_l = typedDefinition.title) !== null && _l !== void 0 ? _l : "", defaultValue: (_o = (_m = typedValue.stringValue) !== null && _m !== void 0 ? _m : typedDefinition.defaultStringValue) !== null && _o !== void 0 ? _o : "", actions: !typedDefinition.uiEditable &&
333
+ (typedValue.stringValue || typedDefinition.defaultStringValue) && (jsxRuntime.jsx(reactComponents.ActionButton, { value: (_p = typedValue.stringValue) !== null && _p !== void 0 ? _p : typedDefinition.defaultStringValue, type: "PHONE_NUMBER" })), readOnly: !typedDefinition.uiEditable, helpText: description, errorMessage: errorMessage === "" ? "Must be a phone number" : undefined }, validation.register(key, rules))));
334
+ }
335
+ case irisAppRuntimeCoreApi.CustomFieldType.STRING: {
336
+ const typedDefinition = field.definition;
337
+ const typedValue = field.value;
338
+ const rules = getStringValidationRules(typedDefinition);
339
+ return (jsxRuntime.jsx(reactComponents.TextField, Object.assign({ label: title, id: key || "string-field", placeholder: (_q = typedDefinition.title) !== null && _q !== void 0 ? _q : "", defaultValue: (_s = (_r = typedValue.stringValue) !== null && _r !== void 0 ? _r : typedDefinition.defaultStringValue) !== null && _s !== void 0 ? _s : "", readOnly: !typedDefinition.uiEditable, helpText: description, errorMessage: errorMessage, dataTestId: `stringField` }, validation.register(key, rules))));
340
+ }
341
+ case irisAppRuntimeCoreApi.CustomFieldType.NUMBER: {
342
+ const typedDefinition = field.definition;
343
+ const typedValue = field.value;
344
+ const rules = getNumberValidationRules(typedDefinition);
345
+ const unit = unitPreference === "US_CUSTOMARY" ? typedDefinition.unitUs : typedDefinition.unitSi;
346
+ const numberProps = {
347
+ placeholder: (_t = typedDefinition.title) !== null && _t !== void 0 ? _t : "",
348
+ addonAfter: unit,
349
+ };
350
+ return (jsxRuntime.jsx(reactComponents.FormGroup, Object.assign({ label: title, isInvalid: errorMessage ? true : false, helpText: errorMessage || description, dataTestId: `numberField-FormGroup`, disabled: !typedDefinition.uiEditable }, { children: isEditing ? (jsxRuntime.jsx(reactComponents.NumberInput, Object.assign({ id: key || "number-field", dataTestId: "numberField", defaultValue: (_v = (_u = typedValue.numberValue) !== null && _u !== void 0 ? _u : typedDefinition.defaultNumberValue) !== null && _v !== void 0 ? _v : "", readOnly: !typedDefinition.uiEditable, step: typedDefinition.isInteger ? 1 : "any", min: (_w = typedDefinition.minimumNumber) !== null && _w !== void 0 ? _w : undefined, max: (_x = typedDefinition.maximumNumber) !== null && _x !== void 0 ? _x : undefined }, validation.register(key, rules), { onBlur: () => setIsEditing(!isEditing), onChange: e => {
351
+ setNumberValue(e.target.value);
352
+ validation.register(key, rules).onChange(e);
353
+ } }, numberProps))) : (jsxRuntime.jsx(reactComponents.BaseInput, Object.assign({ type: "text", id: `${key}-number-field`, dataTestId: `${key}-numberField`, defaultValue: parseFloat(Number(numberValue).toPrecision(4)), readOnly: true, actions: jsxRuntime.jsx(ActionContainer, { children: jsxRuntime.jsx(StyledIconButton, { dataTestId: "editIconButtonId", size: "small", color: "tertiary", icon: jsxRuntime.jsx(reactComponents.Icon, { size: "small", name: "PencilIcon" }), onClick: () => setIsEditing(!isEditing) }) }) }, numberProps))) })));
354
+ }
355
+ case irisAppRuntimeCoreApi.CustomFieldType.BOOLEAN: {
356
+ const typedDefinition = field.definition;
357
+ const typedValue = field.value;
358
+ const rules = getBooleanValidationRules();
359
+ return (jsxRuntime.jsx(BooleanCustomField, { label: (_y = typedDefinition.title) !== null && _y !== void 0 ? _y : "", id: key || "boolean-field", defaultValue: (_0 = (_z = typedValue.booleanValue) !== null && _z !== void 0 ? _z : typedDefinition.defaultBooleanValue) !== null && _0 !== void 0 ? _0 : undefined, readOnly: !typedDefinition.uiEditable, register: validation.register, validationRules: rules, helpText: description, setValue: validation.setValue, errorMessage: errorMessage, dataTestId: "booleanField" }, key));
360
+ }
361
+ case irisAppRuntimeCoreApi.CustomFieldType.DROPDOWN: {
362
+ const typedDefinition = field.definition;
363
+ const typedValue = field.value;
364
+ const rules = getDropdownValidationRules();
365
+ return (jsxRuntime.jsx(DropdownCustomField, { label: typedDefinition.title || "", id: key || "dropdown-field", defaultValue: (_2 = (_1 = typedValue.stringArrayValue) !== null && _1 !== void 0 ? _1 : typedDefinition.defaultStringArrayValue) !== null && _2 !== void 0 ? _2 : undefined, disabled: !typedDefinition.uiEditable, allValues: (_3 = typedDefinition.allValues) !== null && _3 !== void 0 ? _3 : undefined, multiSelect: (_4 = typedDefinition.multiSelect) !== null && _4 !== void 0 ? _4 : false, register: validation.register, validationRules: rules, helpText: description, setValue: validation.setValue, errorMessage: errorMessage, dataTestId: "dropdownField" }, key));
366
+ }
367
+ case irisAppRuntimeCoreApi.CustomFieldType.DATE: {
368
+ const typedDefinition = field.definition;
369
+ const typedValue = field.value;
370
+ const rules = getDateValidationRules();
371
+ let defaultValue;
372
+ if (typedValue.dateValue !== undefined && typedValue.dateValue !== null) {
373
+ defaultValue = new Date(typedValue.dateValue);
374
+ }
375
+ else if (typedDefinition.defaultDateValue !== undefined && typedDefinition.defaultDateValue !== null) {
376
+ defaultValue = new Date(typedDefinition.defaultDateValue);
377
+ }
378
+ return (jsxRuntime.jsx(DateCustomField, { dataTestId: "dateField", id: key || "date-field", defaultValue: defaultValue, readOnly: !typedDefinition.uiEditable, register: validation.register, label: typedDefinition.title || "", validationRules: rules, helpText: description, errorMessage: errorMessage, setValue: validation.setValue, title: field.definition.title || "" }, key));
379
+ }
380
+ default:
381
+ throw new Error(`Type not supported: ${type}`);
382
+ }
383
+ };
384
+ /**
385
+ *
386
+ */
387
+ const CustomField = ({ field, register, formState, setValue, unitPreference, fieldId }) => {
388
+ const fieldComponent = useCustomFieldResolver(field, { register, setValue, formState }, unitPreference, fieldId);
389
+ return fieldComponent;
390
+ };
391
+ const ActionContainer = tailwindStyledComponents.tw.div `
392
+ tu-action-container
393
+ `;
394
+ const StyledIconButton = tailwindStyledComponents.twx(reactComponents.IconButton) `
395
+ tu-action-button
396
+ `;
397
+
398
+ exports.CustomField = CustomField;
399
+ exports.useCustomFieldResolver = useCustomFieldResolver;
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@trackunit/custom-field-components",
3
- "version": "0.0.279",
3
+ "version": "0.0.281-alpha-0b53b6cf53.0",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
7
- "@trackunit/react-core-contexts-test": "0.1.33",
8
- "@trackunit/react-components": "0.1.64",
7
+ "@trackunit/react-core-contexts-test": "0.1.35-alpha-0b53b6cf53.0",
8
+ "@trackunit/react-components": "0.1.65-alpha-0b53b6cf53.0",
9
9
  "react": "18.2.0",
10
10
  "react-hook-form": "7.40.0",
11
- "@trackunit/iris-app-runtime-core": "0.3.21",
12
- "@trackunit/iris-app-runtime-core-api": "0.3.19",
11
+ "@trackunit/iris-app-runtime-core": "0.3.23-alpha-0b53b6cf53.0",
12
+ "@trackunit/iris-app-runtime-core-api": "0.3.21-alpha-0b53b6cf53.0",
13
13
  "@trackunit/tailwind-styled-components": "0.0.54",
14
14
  "react-select": "5.7.0",
15
15
  "libphonenumber-js": "1.10.24"
16
16
  },
17
17
  "module": "./index.js",
18
- "main": "./index.js",
18
+ "main": "./index.cjs",
19
19
  "type": "module",
20
20
  "types": "./src/index.d.ts",
21
21
  "peerDependencies": {}