@abgov/jsonforms-components 1.37.1 → 1.38.1

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.esm.js CHANGED
@@ -8131,6 +8131,377 @@ const createSchemaMatchTester = (props, isExactMatch = false) => {
8131
8131
  const isAddressLookup = createSchemaMatchTester(['addressLine2', 'municipality', 'addressLine1', 'subdivisionCode', 'postalCode']);
8132
8132
  const AddressLookUpTester = rankWith(4, isAddressLookup);
8133
8133
 
8134
+ const NameInputs = ({
8135
+ firstName,
8136
+ middleName,
8137
+ lastName,
8138
+ handleInputChange,
8139
+ data,
8140
+ requiredFields
8141
+ }) => {
8142
+ var _a, _b;
8143
+ const [errors, setErrors] = useState({});
8144
+ /* istanbul ignore next */
8145
+ // eslint-disable-next-line
8146
+ const handleRequiredFieldBlur = (name, updatedData) => {
8147
+ const err = Object.assign({}, errors);
8148
+ if ((!(data === null || data === void 0 ? void 0 : data[name]) || (data === null || data === void 0 ? void 0 : data[name]) === '') && requiredFields.includes(name) && (!updatedData || (updatedData === null || updatedData === void 0 ? void 0 : updatedData[name]) === '')) {
8149
+ const modifiedName = name === 'firstName' ? 'First name' : name === 'lastName' ? 'Last name' : '';
8150
+ err[name] = `${modifiedName} is required`;
8151
+ } else {
8152
+ err[name] = '';
8153
+ }
8154
+ setErrors(err);
8155
+ };
8156
+ return jsxs(GoAGrid, {
8157
+ minChildWidth: "0ch",
8158
+ gap: "s",
8159
+ testId: "wrapper",
8160
+ children: [jsx(GoAFormItem, {
8161
+ testId: "formitem-first-name",
8162
+ label: "First Name",
8163
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('firstName')) ? 'required' : undefined,
8164
+ error: (_a = errors === null || errors === void 0 ? void 0 : errors['firstName']) !== null && _a !== void 0 ? _a : '',
8165
+ children: jsx(GoAInput, {
8166
+ type: "text",
8167
+ name: "firstName",
8168
+ testId: "name-form-first-name",
8169
+ ariaLabel: 'name-form-first-name',
8170
+ value: firstName || '',
8171
+ onChange: (name, value) => handleInputChange(name, value),
8172
+ onBlur: name => {
8173
+ /* istanbul ignore next */
8174
+ handleRequiredFieldBlur(name);
8175
+ },
8176
+ width: "100%"
8177
+ })
8178
+ }), jsx(GoAFormItem, {
8179
+ testId: "formitem-middle-name",
8180
+ label: "Middle Name",
8181
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('middleName')) ? 'required' : undefined,
8182
+ children: jsx(GoAInput, {
8183
+ type: "text",
8184
+ name: "middleName",
8185
+ testId: "name-form-middle-name",
8186
+ ariaLabel: 'name-form-middle-name',
8187
+ value: middleName || '',
8188
+ onChange: (name, value) => handleInputChange(name, value),
8189
+ width: "100%"
8190
+ })
8191
+ }), jsx(GoAFormItem, {
8192
+ testId: "formitem-last-name",
8193
+ label: "Last Name",
8194
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('lastName')) ? 'required' : undefined,
8195
+ error: (_b = errors === null || errors === void 0 ? void 0 : errors['lastName']) !== null && _b !== void 0 ? _b : '',
8196
+ children: jsx(GoAInput, {
8197
+ type: "text",
8198
+ name: "lastName",
8199
+ testId: "name-form-last-name",
8200
+ ariaLabel: 'name-form-last-name',
8201
+ value: lastName || '',
8202
+ onChange: (name, value) => handleInputChange(name, value),
8203
+ onBlur: name => {
8204
+ /* istanbul ignore next */
8205
+ handleRequiredFieldBlur(name);
8206
+ },
8207
+ width: "100%"
8208
+ })
8209
+ })]
8210
+ });
8211
+ };
8212
+
8213
+ const FullNameReviewControl = props => {
8214
+ var _a, _b, _c;
8215
+ const requiredFields = props.schema.required;
8216
+ return jsxs(GoAGrid, {
8217
+ minChildWidth: "0ch",
8218
+ gap: "s",
8219
+ children: [jsx(GoAFormItem, {
8220
+ label: "First Name",
8221
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('firstName')) ? 'required' : undefined,
8222
+ children: jsx("div", {
8223
+ "data-testid": `firstName-control-${props.id}`,
8224
+ children: (_a = props.data) === null || _a === void 0 ? void 0 : _a.firstName
8225
+ })
8226
+ }), jsx(GoAFormItem, {
8227
+ label: "Middle Name",
8228
+ children: jsx("div", {
8229
+ "data-testid": `middleName-control-${props.id}`,
8230
+ children: (_b = props.data) === null || _b === void 0 ? void 0 : _b.middleName
8231
+ })
8232
+ }), jsx(GoAFormItem, {
8233
+ label: "Last Name",
8234
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('lastName')) ? 'required' : undefined,
8235
+ children: jsx("div", {
8236
+ "data-testid": `lastName-control-${props.id}`,
8237
+ children: (_c = props.data) === null || _c === void 0 ? void 0 : _c.lastName
8238
+ })
8239
+ })]
8240
+ });
8241
+ };
8242
+ const FullNameControl = props => {
8243
+ const {
8244
+ data,
8245
+ path,
8246
+ schema,
8247
+ handleChange
8248
+ } = props;
8249
+ const requiredFields = schema.required;
8250
+ const defaultName = {
8251
+ firstName: '',
8252
+ middleName: '',
8253
+ lastName: ''
8254
+ };
8255
+ const [nameData, setNameData] = useState(data || defaultName);
8256
+ const updateFormData = updatedData => {
8257
+ handleChange(path, updatedData);
8258
+ };
8259
+ const handleInputChange = (field, value) => {
8260
+ const updatedName = Object.assign(Object.assign({}, nameData), {
8261
+ [field]: value
8262
+ });
8263
+ setNameData(updatedName);
8264
+ updateFormData(updatedName);
8265
+ };
8266
+ return jsx(NameInputs, {
8267
+ firstName: defaultName.firstName,
8268
+ middleName: defaultName.middleName,
8269
+ lastName: defaultName.lastName,
8270
+ handleInputChange: handleInputChange,
8271
+ data: data,
8272
+ requiredFields: requiredFields
8273
+ });
8274
+ };
8275
+
8276
+ const isFullNameSchema = obj => {
8277
+ if (isObject$e(obj)) {
8278
+ const keys = Object.keys(obj);
8279
+ return ['firstName', 'middleName', 'lastName'].every(attr => keys.includes(attr)) && keys.length === 3;
8280
+ }
8281
+ return false;
8282
+ };
8283
+ const isFullName = (uischema, schema, context) => {
8284
+ if (!isControl(uischema) || !isScoped(uischema)) {
8285
+ return false;
8286
+ }
8287
+ if ((schema === null || schema === void 0 ? void 0 : schema.properties) && isObject$e(schema === null || schema === void 0 ? void 0 : schema.properties)) {
8288
+ const propertyFromScope = uischema['scope'].split('/').pop();
8289
+ if (isObject$e(schema.properties[propertyFromScope]) && 'properties' in schema.properties[propertyFromScope]) {
8290
+ const objToTest = schema.properties[propertyFromScope]['properties'];
8291
+ if (objToTest && isFullNameSchema(objToTest)) {
8292
+ return true;
8293
+ }
8294
+ }
8295
+ }
8296
+ return false;
8297
+ };
8298
+ const FullNameTester = rankWith(4, isFullName);
8299
+
8300
+ const FullNameDobControl = props => {
8301
+ var _a, _b, _c, _d, _e, _f;
8302
+ const {
8303
+ data,
8304
+ path,
8305
+ schema,
8306
+ handleChange,
8307
+ uischema
8308
+ } = props;
8309
+ const requiredFields = schema.required;
8310
+ const [errors, setErrors] = useState({});
8311
+ const defaultNameAndDob = {
8312
+ firstName: '',
8313
+ middleName: '',
8314
+ lastName: '',
8315
+ dateOfBirth: undefined
8316
+ };
8317
+ const validDates = () => {
8318
+ const currentDate = new Date();
8319
+ const minDate = new Date(currentDate.getFullYear() - 150, currentDate.getMonth(), currentDate.getDate()).toISOString().substring(0, 10);
8320
+ return {
8321
+ minDate,
8322
+ maxDate: currentDate.toISOString().substring(0, 10)
8323
+ };
8324
+ };
8325
+ const [formData, setFormData] = useState(data || defaultNameAndDob);
8326
+ const updateFormData = updatedData => {
8327
+ handleChange(path, updatedData);
8328
+ };
8329
+ const handleInputChange = (field, value) => {
8330
+ const updatedData = Object.assign(Object.assign({}, formData), {
8331
+ [field]: value
8332
+ });
8333
+ setFormData(updatedData);
8334
+ updateFormData(updatedData);
8335
+ handleRequiredFieldBlur(field, updatedData);
8336
+ };
8337
+ const handleDobChange = (field, value) => {
8338
+ const updatedData = Object.assign(Object.assign({}, formData), {
8339
+ [field]: value
8340
+ });
8341
+ setFormData(updatedData);
8342
+ updateFormData(updatedData);
8343
+ };
8344
+ /* istanbul ignore next */
8345
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8346
+ const handleRequiredFieldBlur = (name, updatedData) => {
8347
+ const err = Object.assign({}, errors);
8348
+ if ((!(data === null || data === void 0 ? void 0 : data[name]) || (data === null || data === void 0 ? void 0 : data[name]) === '') && requiredFields.includes(name) && (!updatedData || (updatedData === null || updatedData === void 0 ? void 0 : updatedData[name]) === '')) {
8349
+ const modifiedName = name === 'firstName' ? 'First name' : name === 'lastName' ? 'Last name' : name === 'dateOfBirth' ? 'Date of birth' : '';
8350
+ err[name] = `${modifiedName} is required`;
8351
+ } else {
8352
+ err[name] = '';
8353
+ }
8354
+ setErrors(err);
8355
+ };
8356
+ return jsxs(Fragment, {
8357
+ children: [jsxs(GoAGrid, {
8358
+ minChildWidth: "0ch",
8359
+ gap: "s",
8360
+ children: [jsx(GoAFormItem, {
8361
+ label: "First Name",
8362
+ requirement: ((_a = schema === null || schema === void 0 ? void 0 : schema.required) === null || _a === void 0 ? void 0 : _a.includes('firstName')) ? 'required' : undefined,
8363
+ error: (_b = errors === null || errors === void 0 ? void 0 : errors['firstName']) !== null && _b !== void 0 ? _b : '',
8364
+ children: jsx(GoAInput, {
8365
+ type: "text",
8366
+ name: "firstName",
8367
+ testId: "name-form-first-name",
8368
+ ariaLabel: 'name-form-first-name',
8369
+ value: formData.firstName || '',
8370
+ onChange: (name, value) => {
8371
+ handleInputChange(name, value);
8372
+ handleRequiredFieldBlur(name);
8373
+ },
8374
+ onBlur: name => {
8375
+ /* istanbul ignore next */
8376
+ handleRequiredFieldBlur(name);
8377
+ },
8378
+ width: "100%"
8379
+ })
8380
+ }), jsx(GoAFormItem, {
8381
+ label: "Middle Name",
8382
+ requirement: ((_c = schema === null || schema === void 0 ? void 0 : schema.required) === null || _c === void 0 ? void 0 : _c.includes('middleName')) ? 'required' : undefined,
8383
+ children: jsx(GoAInput, {
8384
+ type: "text",
8385
+ name: "middleName",
8386
+ testId: "name-form-middle-name",
8387
+ ariaLabel: 'name-form-middle-name',
8388
+ value: formData.middleName || '',
8389
+ onChange: (name, value) => handleInputChange(name, value),
8390
+ width: "100%"
8391
+ })
8392
+ }), jsx(GoAFormItem, {
8393
+ label: "Last Name",
8394
+ requirement: ((_d = schema === null || schema === void 0 ? void 0 : schema.required) === null || _d === void 0 ? void 0 : _d.includes('lastName')) ? 'required' : undefined,
8395
+ error: (_e = errors === null || errors === void 0 ? void 0 : errors['lastName']) !== null && _e !== void 0 ? _e : '',
8396
+ children: jsx(GoAInput, {
8397
+ type: "text",
8398
+ name: "lastName",
8399
+ testId: "name-form-last-name",
8400
+ ariaLabel: 'name-form-last-name',
8401
+ value: formData.lastName || '',
8402
+ onChange: (name, value) => handleInputChange(name, value),
8403
+ onBlur: name => {
8404
+ /* istanbul ignore next */
8405
+ handleRequiredFieldBlur(name);
8406
+ },
8407
+ width: "100%"
8408
+ })
8409
+ })]
8410
+ }), jsx(GoAGrid, {
8411
+ minChildWidth: "0ch",
8412
+ gap: "s",
8413
+ children: jsx(GoAFormItem, {
8414
+ label: "Date of Birth",
8415
+ error: (_f = errors === null || errors === void 0 ? void 0 : errors['dateOfBirth']) !== null && _f !== void 0 ? _f : '',
8416
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('dateOfBirth')) ? 'required' : undefined,
8417
+ children: jsx(GoAInput, {
8418
+ type: "date",
8419
+ name: "dateOfBirth",
8420
+ min: validDates().minDate,
8421
+ max: validDates().maxDate,
8422
+ testId: `dob-form-dateOfBirth`,
8423
+ ariaLabel: "dob-form-dateOfBirth",
8424
+ placeholder: "YYYY-MM-DD",
8425
+ value: formData === null || formData === void 0 ? void 0 : formData.dateOfBirth,
8426
+ onChange: (name, value) => handleDobChange(name, value),
8427
+ onBlur: name => {
8428
+ /* istanbul ignore next */
8429
+ handleRequiredFieldBlur(name);
8430
+ },
8431
+ width: "100%"
8432
+ })
8433
+ })
8434
+ })]
8435
+ });
8436
+ };
8437
+
8438
+ const FullNameDobReviewControl = props => {
8439
+ var _a, _b, _c, _d;
8440
+ const requiredFields = props.schema.required;
8441
+ return jsxs(Fragment, {
8442
+ children: [jsxs(GoAGrid, {
8443
+ minChildWidth: "0ch",
8444
+ gap: "s",
8445
+ children: [jsx(GoAFormItem, {
8446
+ label: "First Name",
8447
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('firstName')) ? 'required' : undefined,
8448
+ children: jsx("div", {
8449
+ "data-testid": `firstName-control-${props.id}`,
8450
+ children: (_a = props.data) === null || _a === void 0 ? void 0 : _a.firstName
8451
+ })
8452
+ }), jsx(GoAFormItem, {
8453
+ label: "Middle Name",
8454
+ children: jsx("div", {
8455
+ "data-testid": `middleName-control-${props.id}`,
8456
+ children: (_b = props.data) === null || _b === void 0 ? void 0 : _b.middleName
8457
+ })
8458
+ }), jsx(GoAFormItem, {
8459
+ label: "Last Name",
8460
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('lastName')) ? 'required' : undefined,
8461
+ children: jsx("div", {
8462
+ "data-testid": `lastName-control-${props.id}`,
8463
+ children: (_c = props.data) === null || _c === void 0 ? void 0 : _c.lastName
8464
+ })
8465
+ })]
8466
+ }), jsx(GoAGrid, {
8467
+ minChildWidth: "0ch",
8468
+ gap: "s",
8469
+ children: jsx(GoAFormItem, {
8470
+ label: "Date of birth",
8471
+ requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('dateOfBirth')) ? 'required' : undefined,
8472
+ children: jsx("div", {
8473
+ "data-testid": `dob-control-${props.id}`,
8474
+ children: (_d = props.data) === null || _d === void 0 ? void 0 : _d.dateOfBirth
8475
+ })
8476
+ })
8477
+ })]
8478
+ });
8479
+ };
8480
+
8481
+ const isFullNameDoBSchema = obj => {
8482
+ if (isObject$e(obj)) {
8483
+ const keys = Object.keys(obj);
8484
+ return ['firstName', 'middleName', 'lastName', 'dateOfBirth'].every(attr => keys.includes(attr)) && keys.length === 4;
8485
+ }
8486
+ return false;
8487
+ };
8488
+ const isFullNameDoB = (uischema, schema, context) => {
8489
+ if (!isControl(uischema) || !isScoped(uischema)) {
8490
+ return false;
8491
+ }
8492
+ if ((schema === null || schema === void 0 ? void 0 : schema.properties) && isObject$e(schema === null || schema === void 0 ? void 0 : schema.properties)) {
8493
+ const propertyFromScope = uischema['scope'].split('/').pop();
8494
+ if (isObject$e(schema.properties[propertyFromScope]) && 'properties' in schema.properties[propertyFromScope]) {
8495
+ const objToTest = schema.properties[propertyFromScope]['properties'];
8496
+ if (objToTest && isFullNameDoBSchema(objToTest)) {
8497
+ return true;
8498
+ }
8499
+ }
8500
+ }
8501
+ return false;
8502
+ };
8503
+ const FullNameDobTester = rankWith(4, isFullNameDoB);
8504
+
8134
8505
  const GoATextCell = props => jsx(GoAInputText, Object.assign({}, props));
8135
8506
  const GoATextCellTester = rankWith(1, isStringControl);
8136
8507
  withJsonFormsCellProps(GoATextCell);
@@ -9648,6 +10019,12 @@ const GoABaseReviewRenderers = [
9648
10019
  const GoAReviewRenderers = [...GoABaseReviewRenderers, {
9649
10020
  tester: FileUploaderTester,
9650
10021
  renderer: withJsonFormsControlProps(FileUploaderReview)
10022
+ }, {
10023
+ tester: FullNameTester,
10024
+ renderer: withJsonFormsControlProps(FullNameReviewControl)
10025
+ }, {
10026
+ tester: FullNameDobTester,
10027
+ renderer: withJsonFormsControlProps(FullNameDobReviewControl)
9651
10028
  }, {
9652
10029
  tester: AddressLookUpTester,
9653
10030
  renderer: withJsonFormsControlProps(AddressLookUpControlReview)
@@ -9661,6 +10038,12 @@ const GoARenderers = [...GoABaseRenderers, {
9661
10038
  }, {
9662
10039
  tester: AddressLookUpTester,
9663
10040
  renderer: withJsonFormsControlProps(AddressLookUpControl)
10041
+ }, {
10042
+ tester: FullNameTester,
10043
+ renderer: withJsonFormsControlProps(FullNameControl)
10044
+ }, {
10045
+ tester: FullNameDobTester,
10046
+ renderer: withJsonFormsControlProps(FullNameDobControl)
9664
10047
  }];
9665
10048
  const GoACells = [...InputCells];
9666
10049
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.37.1",
3
+ "version": "1.38.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
6
6
  "repository": "https://github.com/GovAlta/adsp-monorepo",
@@ -0,0 +1,5 @@
1
+ import { ControlProps } from '@jsonforms/core';
2
+ type FullNameProps = ControlProps;
3
+ export declare const FullNameReviewControl: (props: FullNameProps) => JSX.Element;
4
+ export declare const FullNameControl: (props: FullNameProps) => JSX.Element;
5
+ export {};
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ interface NameInputsProps {
3
+ firstName: string;
4
+ middleName?: string;
5
+ lastName: string;
6
+ isStepperReview?: boolean;
7
+ data: any;
8
+ requiredFields: string[];
9
+ handleInputChange: (field: string, value: string) => void;
10
+ }
11
+ export declare const NameInputs: React.FC<NameInputsProps>;
12
+ export {};
@@ -0,0 +1,3 @@
1
+ import { RankedTester, UISchemaElement, JsonSchema, TesterContext } from '@jsonforms/core';
2
+ export declare const isFullName: (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => boolean;
3
+ export declare const FullNameTester: RankedTester;
@@ -0,0 +1,2 @@
1
+ export * from './FullNameControl';
2
+ export * from './FullNameTester';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { ControlProps } from '@jsonforms/core';
2
+ type DateOfBirthControlProps = ControlProps;
3
+ export declare const FullNameDobControl: (props: DateOfBirthControlProps) => JSX.Element;
4
+ export {};
@@ -0,0 +1,4 @@
1
+ import { ControlProps } from '@jsonforms/core';
2
+ type DateOfBirthReviewControlProps = ControlProps;
3
+ export declare const FullNameDobReviewControl: (props: DateOfBirthReviewControlProps) => JSX.Element;
4
+ export {};
@@ -0,0 +1,3 @@
1
+ import { RankedTester, UISchemaElement, JsonSchema, TesterContext } from '@jsonforms/core';
2
+ export declare const isFullNameDoB: (uischema: UISchemaElement, schema: JsonSchema, context: TesterContext) => boolean;
3
+ export declare const FullNameDobTester: RankedTester;
@@ -0,0 +1,3 @@
1
+ export * from './FullNameDobControl';
2
+ export * from './FullNameDobReviewControl';
3
+ export * from './FullNameDobTester';
@@ -3,3 +3,5 @@ export * from './FormStepper';
3
3
  export * from './FileUploader';
4
4
  export * from './ObjectArray';
5
5
  export * from './AddressLookup';
6
+ export * from './FullName';
7
+ export * from './FullNameDOB';