@abgov/jsonforms-components 1.32.1 → 1.32.2

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
@@ -1,11 +1,12 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
2
  import React, { createContext, useContext, useReducer, useMemo, useEffect, useState, useCallback, useRef } from 'react';
3
- import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputDateTime, GoAInputTime, GoADropdown, GoADropdownItem, GoARadioGroup, GoARadioItem, GoACheckbox, GoAGrid, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoADetails } from '@abgov/react-components';
3
+ import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputDateTime, GoAInputTime, GoARadioGroup, GoARadioItem, GoACheckbox, GoAGrid, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoADetails } from '@abgov/react-components';
4
4
  import styled from 'styled-components';
5
5
  import axios from 'axios';
6
6
  import get$1 from 'lodash/get';
7
7
  import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
8
8
  import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
9
+ import { isEqual } from 'lodash';
9
10
  import merge from 'lodash/merge';
10
11
  import isEmpty$1 from 'lodash/isEmpty';
11
12
  import range from 'lodash/range';
@@ -1627,9 +1628,9 @@ $$h({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign }
1627
1628
  assign: assign
1628
1629
  });
1629
1630
 
1630
- let _$7 = t => t,
1631
- _t$7;
1632
- const FormFieldWrapper = styled.div(_t$7 || (_t$7 = _$7`
1631
+ let _$8 = t => t,
1632
+ _t$8;
1633
+ const FormFieldWrapper = styled.div(_t$8 || (_t$8 = _$8`
1633
1634
  margin-bottom: var(--goa-space-l);
1634
1635
  `));
1635
1636
 
@@ -2717,16 +2718,16 @@ const onChangeForNumericControl = props => {
2717
2718
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2718
2719
  const onChangeForCheckboxData = (data, name, value) => data ? !value ? data === null || data === void 0 ? void 0 : data.filter(item => item !== name) : [...data, name] : [name];
2719
2720
 
2720
- let _$6 = t => t,
2721
- _t$6,
2722
- _t2$3;
2723
- styled.div(_t$6 || (_t$6 = _$6`
2721
+ let _$7 = t => t,
2722
+ _t$7,
2723
+ _t2$4;
2724
+ styled.div(_t$7 || (_t$7 = _$7`
2724
2725
  height: 70vh;
2725
2726
  overflow-y: auto;
2726
2727
  padding-left: var(--goa-space-2xs);
2727
2728
  padding-right: var(--goa-space-2xs);
2728
2729
  `));
2729
- const Visible = styled.div(_t2$3 || (_t2$3 = _$6`
2730
+ const Visible = styled.div(_t2$4 || (_t2$4 = _$7`
2730
2731
  display: ${0};
2731
2732
  `), p => p.visible ? 'initial' : 'none');
2732
2733
 
@@ -4211,13 +4212,127 @@ const GoATimeControl = props => jsx(GoAInputBaseControl, Object.assign({}, props
4211
4212
  const GoATimeControlTester = rankWith(4, isTimeControl);
4212
4213
  const GoAInputTimeControl = withJsonFormsControlProps(GoATimeControl);
4213
4214
 
4215
+ let _$6 = t => t,
4216
+ _t$6,
4217
+ _t2$3,
4218
+ _t3$3,
4219
+ _t4$2;
4220
+ styled.div(_t$6 || (_t$6 = _$6`
4221
+ text-overflow: ellipsis;
4222
+ overflow: hidden;
4223
+ min-height: 43px;
4224
+ box-sizing: border-box;
4225
+ width: 100%;
4226
+ padding: 8px;
4227
+ padding-right: 8px;
4228
+ border-radius: 4px;
4229
+ border: 1px solid #666;
4230
+ font-size: 18px;
4231
+ font-weight: 400;
4232
+ -webkit-appearance: none;
4233
+ -moz-appearance: none;
4234
+ appearance: none;
4235
+ box-shadow: ${0};
4236
+ `), p => p.isOpen ? `0 0 0 3px #feba35` : '');
4237
+ const GoADropdownListContainerWrapper = styled.div(_t2$3 || (_t2$3 = _$6`
4238
+ position: relative;
4239
+ display: ${0};
4240
+ `), p => !(p === null || p === void 0 ? void 0 : p.isOpen) && 'none');
4241
+ const GoADropdownListContainer = styled.div(_t3$3 || (_t3$3 = _$6`
4242
+ border: solid 1px #dcdcdc;
4243
+ border-radius: 4px;
4244
+ background: #fff;
4245
+ padding: 0;
4246
+ margin-top: 3px;
4247
+ width: 100%;
4248
+ overflow-y: auto;
4249
+ z-index: 1000;
4250
+ position: absolute;
4251
+ line-height: 2rem;
4252
+ max-height: ${0};
4253
+ `), p => p.optionListMaxHeight || '272px');
4254
+ const GoADropdownListOption = styled.div(_t4$2 || (_t4$2 = _$6`
4255
+ padding: 4px 12px;
4256
+ text-overflow: ellipsis;
4257
+ color: ${0} !important;
4258
+ border: 1px solid #f1f1f1;
4259
+ z-index: 1001;
4260
+ background: ${0};
4261
+ &:hover {
4262
+ background-color: ${0};
4263
+ color: ${0} !important;
4264
+ }
4265
+ `), p => p.isSelected ? 'white' : 'var(--goa-color-greyscale-black)', p => p.isSelected ? 'var(--goa-color-interactive-default)' : '#fff', p => p.isSelected ? 'var(--goa-color-interactive-default)' : '#f1f1f1', p => p.isSelected ? 'white' : '#333');
4266
+ const Dropdown = props => {
4267
+ const {
4268
+ label,
4269
+ selected,
4270
+ onChange,
4271
+ optionListMaxHeight,
4272
+ isAutocompletion,
4273
+ id
4274
+ } = props;
4275
+ const [isOpen, setIsOpen] = useState(false);
4276
+ const [selectedOption, setSelectedOption] = useState(selected);
4277
+ const trailingIcon = isOpen ? 'chevron-up' : 'chevron-down';
4278
+ const [items, setItems] = useState(props.items);
4279
+ const [inputText, setInputText] = useState(selected);
4280
+ useEffect(() => {
4281
+ setItems(props.items);
4282
+ }, [isEqual(props.items, items)]);
4283
+ return jsxs("div", {
4284
+ "data-testid": id,
4285
+ children: [jsx(GoAInput, {
4286
+ name: `dropdown-${label}`,
4287
+ width: "100%",
4288
+ value: inputText,
4289
+ testId: `${id}-input`,
4290
+ id: `${id}-input`,
4291
+ readonly: !isAutocompletion,
4292
+ onChange: (name, value) => {
4293
+ if (isAutocompletion) {
4294
+ setIsOpen(true);
4295
+ const selectedItems = props.items.filter(item => {
4296
+ return item.label.includes(value);
4297
+ });
4298
+ setItems(selectedItems);
4299
+ }
4300
+ },
4301
+ trailingIcon: trailingIcon,
4302
+ onFocus: () => {
4303
+ setIsOpen(!isOpen);
4304
+ }
4305
+ }), jsx(GoADropdownListContainerWrapper, {
4306
+ isOpen: isOpen,
4307
+ children: jsx(GoADropdownListContainer, {
4308
+ optionListMaxHeight: optionListMaxHeight,
4309
+ children: items.map(item => {
4310
+ return jsx(GoADropdownListOption, {
4311
+ isSelected: item.value === selected,
4312
+ children: jsx("div", {
4313
+ "data-testid": `${id}-${item.label}-option`,
4314
+ onClick: () => {
4315
+ onChange(item.value);
4316
+ setSelectedOption(item.value);
4317
+ setInputText(item.value);
4318
+ setIsOpen(false);
4319
+ },
4320
+ children: item.label
4321
+ }, `jsonforms-dropdown-${label}-${item.value}`)
4322
+ });
4323
+ })
4324
+ })
4325
+ })]
4326
+ });
4327
+ };
4328
+
4214
4329
  function fetchRegisterConfigFromOptions(options) {
4215
4330
  if (!(options === null || options === void 0 ? void 0 : options.url) && !(options === null || options === void 0 ? void 0 : options.urn)) return undefined;
4216
4331
  const config = Object.assign({}, options);
4217
4332
  return config;
4218
4333
  }
4219
4334
  const EnumSelect = props => {
4220
- var _a, _b, _c, _d, _e;
4335
+ var _a, _b, _c, _d;
4221
4336
  const {
4222
4337
  data,
4223
4338
  id,
@@ -4242,9 +4357,8 @@ const EnumSelect = props => {
4242
4357
  error = (registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.fetchErrors(registerConfig)) || '';
4243
4358
  }
4244
4359
  const autocompletion = ((_d = (_c = props.uischema) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.autocomplete) === true;
4245
- const appliedUiSchemaOptions = merge({}, config, props.uischema.options);
4246
4360
  const mergedOptions = useMemo(() => {
4247
- const newOptions = [...(options || []), ...registerData.map(d => {
4361
+ const newOptions = [...(options || []), ...((registerData === null || registerData === void 0 ? void 0 : registerData.map(d => {
4248
4362
  if (typeof d === 'string') {
4249
4363
  return {
4250
4364
  value: d,
@@ -4253,7 +4367,7 @@ const EnumSelect = props => {
4253
4367
  } else {
4254
4368
  return Object.assign({}, d);
4255
4369
  }
4256
- })];
4370
+ })) || [])];
4257
4371
  const hasNonEmptyOptions = newOptions.some(option => option.value !== '');
4258
4372
  if (!hasNonEmptyOptions && newOptions.length === 1 && newOptions[0].value === '') {
4259
4373
  return newOptions;
@@ -4266,6 +4380,7 @@ const EnumSelect = props => {
4266
4380
  }
4267
4381
  return newOptions.filter(option => option.value !== '');
4268
4382
  }, [registerData, options]);
4383
+ console.log(mergedOptions);
4269
4384
  useEffect(() => {
4270
4385
  if (registerConfig) {
4271
4386
  registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.fetchRegisterByUrl(registerConfig);
@@ -4274,25 +4389,16 @@ const EnumSelect = props => {
4274
4389
  return jsx("div", {
4275
4390
  children: error.length > 0 ? callout({
4276
4391
  message: error
4277
- }) : jsx(GoADropdown, Object.assign({
4278
- name: `${label}`,
4279
- value: data,
4280
- disabled: !enabled,
4281
- relative: true,
4282
- filterable: autocompletion,
4283
- testId: `${id || label}-jsonform`
4284
- }, appliedUiSchemaOptions, {
4285
- onChange: (name, value) => {
4392
+ }) : jsx(Dropdown, {
4393
+ items: mergedOptions,
4394
+ selected: data,
4395
+ id: `jsonforms-${label}-dropdown`,
4396
+ label: label,
4397
+ isAutocompletion: autocompletion,
4398
+ onChange: value => {
4286
4399
  handleChange(path, value);
4287
4400
  }
4288
- }, (_e = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _e === void 0 ? void 0 : _e.componentProps, {
4289
- children: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.map(item => {
4290
- return jsx(GoADropdownItem, {
4291
- value: `${item.value}`,
4292
- label: `${item.label}`
4293
- }, `json-form-dropdown-${item.value}`);
4294
- })
4295
- }), `${id}-jsonform-key`)
4401
+ })
4296
4402
  });
4297
4403
  };
4298
4404
  const enumControl = props => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.32.1",
3
+ "version": "1.32.2",
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,15 @@
1
+ export interface Item {
2
+ label: string;
3
+ value: string;
4
+ }
5
+ interface DropdownProps {
6
+ items: Array<Item>;
7
+ label: string;
8
+ selected: string;
9
+ optionListMaxHeight?: string;
10
+ onChange: (value: string) => void;
11
+ isAutocompletion?: boolean;
12
+ id?: string;
13
+ }
14
+ export declare const Dropdown: (props: DropdownProps) => JSX.Element;
15
+ export {};