@abgov/jsonforms-components 1.2.4 → 1.3.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
@@ -3,8 +3,8 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import { GoAFormItem, GoACallout, GoAInputDate, GoAInput, GoATextArea, GoAInputDateTime, GoAInputTime, GoADropdown, GoADropdownItem, GoARadioGroup, GoARadioItem, GoACheckbox, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAIconButton, GoAFileUploadInput, GoAModal, GoACircularProgress, GoAGrid, GoAContainer, GoAButtonGroup, GoADetails } from '@abgov/react-components';
4
4
  import { Hidden, Typography, FormHelperText } from '@mui/material';
5
5
  import styled from 'styled-components';
6
- import { rankWith, isDateControl, isStringControl, and, optionIs, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, isDescriptionHidden, isVisible, isEnabled, deriveLabelForUISchemaElement, uiTypeIs, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
7
- import { withJsonFormsControlProps, withJsonFormsEnumProps, withTranslateProps, withJsonFormsLayoutProps, JsonFormsDispatch, useJsonForms, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
6
+ import { rankWith, uiTypeIs, isDateControl, isStringControl, and, optionIs, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, isDescriptionHidden, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
7
+ import { withJsonFormsRendererProps, withJsonFormsControlProps, withJsonFormsEnumProps, withTranslateProps, withJsonFormsLayoutProps, JsonFormsDispatch, useJsonForms, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
8
8
  import React, { createContext, useEffect, useState, useMemo, useContext, useCallback } from 'react';
9
9
  import merge from 'lodash/merge';
10
10
  import axios from 'axios';
@@ -2407,24 +2407,23 @@ const GoAInputBaseControl = props => {
2407
2407
  });
2408
2408
  };
2409
2409
 
2410
- /**
2411
- * Used internally by registered Controls, the MessageControl
2412
- * is used to display an error message if a component cannot be rendered
2413
- * due to input errors - typically from options.componentProps.
2414
- *
2415
- * NOTE: The component itself is not, and should not, be registered.
2416
- *
2417
- * @param message the message to be displayed
2418
- *
2419
- * @returns component for displaying the message in the correct style
2420
- */
2421
- // TODO: Add styling
2422
- const MessageControl = message => {
2423
- return jsx(GoACallout, {
2424
- type: "emergency",
2425
- children: message
2426
- });
2410
+ // Used locally for callout presentation
2411
+ const callout = props => {
2412
+ const componentProps = Object.assign({
2413
+ size: 'medium',
2414
+ type: 'emergency',
2415
+ message: 'unknown'
2416
+ }, props);
2417
+ return jsx(GoACallout, Object.assign({}, componentProps, {
2418
+ children: componentProps.message
2419
+ }));
2427
2420
  };
2421
+ const CalloutControl = props => {
2422
+ var _a, _b;
2423
+ return callout(((_b = (_a = props === null || props === void 0 ? void 0 : props.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.componentProps) || {});
2424
+ };
2425
+ const GoACalloutControlTester = rankWith(1, uiTypeIs('Callout'));
2426
+ var GoACalloutControl = withJsonFormsRendererProps(CalloutControl);
2428
2427
 
2429
2428
  const errMalformedDate = (scope, type) => {
2430
2429
  return `${type}-date for variable '${scope}' has an incorrect format.`;
@@ -2442,7 +2441,9 @@ const isValidDateFormat = date => {
2442
2441
  return standardized !== undefined;
2443
2442
  };
2444
2443
  const invalidDateFormat = (scope, type) => {
2445
- return MessageControl(errMalformedDate(scope, type));
2444
+ return callout({
2445
+ message: errMalformedDate(scope, type)
2446
+ });
2446
2447
  };
2447
2448
  const reformatDateProps = props => {
2448
2449
  if (props) {
@@ -4849,7 +4850,7 @@ const isLayoutType = schema => {
4849
4850
  return hasType(schema, 'VerticalLayout') || hasType(schema, 'HorizontalLayout') || hasType(schema, 'Categorization') || hasType(schema, 'Group');
4850
4851
  };
4851
4852
  const isKnownType = schema => {
4852
- return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') || isListWithDetail(schema);
4853
+ return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') || isListWithDetail(schema) || hasType(schema, 'Callout');
4853
4854
  };
4854
4855
  const isListWithDetail = schema => {
4855
4856
  return hasType(schema, 'ListWithDetail');
@@ -4873,9 +4874,6 @@ const isEmptyElements = schema => {
4873
4874
  const hasVariant = schema => {
4874
4875
  return 'options' in schema && schema.options !== undefined && schema.options !== null && 'variant' in schema.options;
4875
4876
  };
4876
- const isValidJsonObject = schema => {
4877
- return typeof schema === 'object' && Object.keys(schema).length === 0 || 'properties' in schema && ('type' in schema && schema.type === 'object' || !('type' in schema));
4878
- };
4879
4877
 
4880
4878
  const errCategorizationHasNonCategories = "Each element of 'Categorizations' must be of type 'Category'";
4881
4879
  const errCategorizationHasNoElements = 'A Categorization must contain Categories.';
@@ -4967,15 +4965,6 @@ const getUISchemaErrors = (uiSchema, schema) => {
4967
4965
  return null;
4968
4966
  };
4969
4967
 
4970
- const isValidJsonSchema = schema => {
4971
- if (isNullSchema(schema)) {
4972
- return '';
4973
- }
4974
- if (!isValidJsonObject(schema)) {
4975
- return 'Unable to render: json schema is not valid.';
4976
- }
4977
- return null;
4978
- };
4979
4968
  // Some 'errors' need not be reported, but we want to handle them
4980
4969
  // here. e.g. A layout with empty elements should be quietly ignored.
4981
4970
  // this is handled by the errors !== '' check.
@@ -4984,17 +4973,11 @@ const ErrorControl = props => {
4984
4973
  schema,
4985
4974
  uischema
4986
4975
  } = props;
4987
- // Report data schema errors over ui schema ones, as errors in the former
4988
- // can cause cascading errors in the latter.
4989
- const dataSchemaErrors = isValidJsonSchema(schema);
4990
- if (dataSchemaErrors && dataSchemaErrors !== '') {
4991
- return jsx("p", {
4992
- children: dataSchemaErrors
4993
- });
4994
- }
4995
4976
  const uiSchemaErrors = getUISchemaErrors(uischema, schema);
4996
4977
  if (uiSchemaErrors && uiSchemaErrors !== '') {
4997
- return MessageControl(uiSchemaErrors);
4978
+ return callout({
4979
+ message: uiSchemaErrors
4980
+ });
4998
4981
  }
4999
4982
  return jsx("span", {});
5000
4983
  };
@@ -5003,9 +4986,8 @@ const ErrorControl = props => {
5003
4986
  * one that must get used if there are any errors whatsoever.
5004
4987
  */
5005
4988
  const GoAErrorControlTester = rankWith(1000, (uischema, schema, context) => {
5006
- const validJsonSchema = isValidJsonSchema(schema);
5007
4989
  const validUiSchema = getUISchemaErrors(uischema, schema);
5008
- return validUiSchema != null || validJsonSchema != null;
4990
+ return validUiSchema != null;
5009
4991
  });
5010
4992
  var GoAErrorControl = withJsonFormsControlProps(ErrorControl);
5011
4993
 
@@ -5037,6 +5019,9 @@ const GoABaseRenderers = [
5037
5019
  }, {
5038
5020
  tester: GoATimeControlTester,
5039
5021
  renderer: GoAInputTimeControl
5022
+ }, {
5023
+ tester: GoACalloutControlTester,
5024
+ renderer: GoACalloutControl
5040
5025
  }, {
5041
5026
  tester: materialSliderControlTester,
5042
5027
  renderer: MaterialSliderControl
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.2.4",
3
+ "version": "1.3.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,12 @@
1
+ import React from 'react';
2
+ import { RankedTester } from '@jsonforms/core';
3
+ import { GoACalloutSize, GoACalloutType } from '@abgov/react-components-new';
4
+ export interface CalloutProps {
5
+ size?: GoACalloutSize;
6
+ type?: GoACalloutType;
7
+ message?: string;
8
+ }
9
+ export declare const callout: (props: CalloutProps) => JSX.Element;
10
+ export declare const GoACalloutControlTester: RankedTester;
11
+ declare const _default: React.ComponentType<import("@jsonforms/core").OwnPropsOfJsonFormsRenderer>;
12
+ export default _default;
@@ -11,4 +11,3 @@ export declare const isCategorization: (uiSchema: UISchemaElement) => boolean;
11
11
  export declare const hasElements: (schema: object) => boolean;
12
12
  export declare const isEmptyElements: (schema: object) => boolean;
13
13
  export declare const hasVariant: (schema: UISchemaElement) => boolean;
14
- export declare const isValidJsonObject: (schema: JsonSchema) => boolean;
@@ -1,12 +0,0 @@
1
- /**
2
- * Used internally by registered Controls, the MessageControl
3
- * is used to display an error message if a component cannot be rendered
4
- * due to input errors - typically from options.componentProps.
5
- *
6
- * NOTE: The component itself is not, and should not, be registered.
7
- *
8
- * @param message the message to be displayed
9
- *
10
- * @returns component for displaying the message in the correct style
11
- */
12
- export declare const MessageControl: (message: string) => JSX.Element;