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