@abgov/jsonforms-components 1.32.1 → 1.33.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
@@ -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
 
@@ -1934,16 +1935,55 @@ $$e({ target: 'RegExp', proto: true, forced: !DELEGATES_TO_EXEC }, {
1934
1935
  }
1935
1936
  });
1936
1937
 
1938
+ var call$b = functionCall;
1939
+ var hasOwn$4 = hasOwnProperty_1;
1940
+ var isPrototypeOf$5 = objectIsPrototypeOf;
1941
+ var regExpFlags = regexpFlags$1;
1942
+
1943
+ var RegExpPrototype$4 = RegExp.prototype;
1944
+
1945
+ var regexpGetFlags = function (R) {
1946
+ var flags = R.flags;
1947
+ return flags === undefined && !('flags' in RegExpPrototype$4) && !hasOwn$4(R, 'flags') && isPrototypeOf$5(RegExpPrototype$4, R)
1948
+ ? call$b(regExpFlags, R) : flags;
1949
+ };
1950
+
1951
+ var PROPER_FUNCTION_NAME = functionName.PROPER;
1952
+ var defineBuiltIn$4 = defineBuiltIn$8;
1953
+ var anObject$7 = anObject$e;
1954
+ var $toString = toString$a;
1955
+ var fails$b = fails$q;
1956
+ var getRegExpFlags$1 = regexpGetFlags;
1957
+
1958
+ var TO_STRING = 'toString';
1959
+ var RegExpPrototype$3 = RegExp.prototype;
1960
+ var nativeToString = RegExpPrototype$3[TO_STRING];
1961
+
1962
+ var NOT_GENERIC = fails$b(function () { return nativeToString.call({ source: 'a', flags: 'b' }) !== '/a/b'; });
1963
+ // FF44- RegExp#toString has a wrong name
1964
+ var INCORRECT_NAME = PROPER_FUNCTION_NAME && nativeToString.name !== TO_STRING;
1965
+
1966
+ // `RegExp.prototype.toString` method
1967
+ // https://tc39.es/ecma262/#sec-regexp.prototype.tostring
1968
+ if (NOT_GENERIC || INCORRECT_NAME) {
1969
+ defineBuiltIn$4(RegExpPrototype$3, TO_STRING, function toString() {
1970
+ var R = anObject$7(this);
1971
+ var pattern = $toString(R.source);
1972
+ var flags = $toString(getRegExpFlags$1(R));
1973
+ return '/' + pattern + '/' + flags;
1974
+ }, { unsafe: true });
1975
+ }
1976
+
1937
1977
  var $$d = _export;
1938
1978
  var uncurryThis$d = functionUncurryThis;
1939
1979
  var requireObjectCoercible$3 = requireObjectCoercible$7;
1940
1980
  var toIntegerOrInfinity$2 = toIntegerOrInfinity$6;
1941
1981
  var toString$7 = toString$a;
1942
- var fails$b = fails$q;
1982
+ var fails$a = fails$q;
1943
1983
 
1944
1984
  var charAt$5 = uncurryThis$d(''.charAt);
1945
1985
 
1946
- var FORCED$3 = fails$b(function () {
1986
+ var FORCED$3 = fails$a(function () {
1947
1987
  // eslint-disable-next-line es/no-array-string-prototype-at -- safe
1948
1988
  return '𠮷'.at(-2) !== '\uD842';
1949
1989
  });
@@ -1964,36 +2004,36 @@ var NATIVE_BIND$1 = functionBindNative;
1964
2004
 
1965
2005
  var FunctionPrototype = Function.prototype;
1966
2006
  var apply$4 = FunctionPrototype.apply;
1967
- var call$b = FunctionPrototype.call;
2007
+ var call$a = FunctionPrototype.call;
1968
2008
 
1969
2009
  // eslint-disable-next-line es/no-reflect -- safe
1970
- var functionApply = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND$1 ? call$b.bind(apply$4) : function () {
1971
- return call$b.apply(apply$4, arguments);
2010
+ var functionApply = typeof Reflect == 'object' && Reflect.apply || (NATIVE_BIND$1 ? call$a.bind(apply$4) : function () {
2011
+ return call$a.apply(apply$4, arguments);
1972
2012
  });
1973
2013
 
1974
2014
  // TODO: Remove from `core-js@4` since it's moved to entry points
1975
2015
 
1976
- var call$a = functionCall;
1977
- var defineBuiltIn$4 = defineBuiltIn$8;
2016
+ var call$9 = functionCall;
2017
+ var defineBuiltIn$3 = defineBuiltIn$8;
1978
2018
  var regexpExec$1 = regexpExec$2;
1979
- var fails$a = fails$q;
2019
+ var fails$9 = fails$q;
1980
2020
  var wellKnownSymbol$a = wellKnownSymbol$j;
1981
2021
  var createNonEnumerableProperty$4 = createNonEnumerableProperty$9;
1982
2022
 
1983
2023
  var SPECIES$3 = wellKnownSymbol$a('species');
1984
- var RegExpPrototype$4 = RegExp.prototype;
2024
+ var RegExpPrototype$2 = RegExp.prototype;
1985
2025
 
1986
2026
  var fixRegexpWellKnownSymbolLogic = function (KEY, exec, FORCED, SHAM) {
1987
2027
  var SYMBOL = wellKnownSymbol$a(KEY);
1988
2028
 
1989
- var DELEGATES_TO_SYMBOL = !fails$a(function () {
2029
+ var DELEGATES_TO_SYMBOL = !fails$9(function () {
1990
2030
  // String methods call symbol-named RegExp methods
1991
2031
  var O = {};
1992
2032
  O[SYMBOL] = function () { return 7; };
1993
2033
  return ''[KEY](O) !== 7;
1994
2034
  });
1995
2035
 
1996
- var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails$a(function () {
2036
+ var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails$9(function () {
1997
2037
  // Symbol-named RegExp methods call .exec
1998
2038
  var execCalled = false;
1999
2039
  var re = /a/;
@@ -2028,23 +2068,23 @@ var fixRegexpWellKnownSymbolLogic = function (KEY, exec, FORCED, SHAM) {
2028
2068
  var nativeRegExpMethod = /./[SYMBOL];
2029
2069
  var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
2030
2070
  var $exec = regexp.exec;
2031
- if ($exec === regexpExec$1 || $exec === RegExpPrototype$4.exec) {
2071
+ if ($exec === regexpExec$1 || $exec === RegExpPrototype$2.exec) {
2032
2072
  if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
2033
2073
  // The native String method already delegates to @@method (this
2034
2074
  // polyfilled function), leasing to infinite recursion.
2035
2075
  // We avoid it by directly calling the native @@method method.
2036
- return { done: true, value: call$a(nativeRegExpMethod, regexp, str, arg2) };
2076
+ return { done: true, value: call$9(nativeRegExpMethod, regexp, str, arg2) };
2037
2077
  }
2038
- return { done: true, value: call$a(nativeMethod, str, regexp, arg2) };
2078
+ return { done: true, value: call$9(nativeMethod, str, regexp, arg2) };
2039
2079
  }
2040
2080
  return { done: false };
2041
2081
  });
2042
2082
 
2043
- defineBuiltIn$4(String.prototype, KEY, methods[0]);
2044
- defineBuiltIn$4(RegExpPrototype$4, SYMBOL, methods[1]);
2083
+ defineBuiltIn$3(String.prototype, KEY, methods[0]);
2084
+ defineBuiltIn$3(RegExpPrototype$2, SYMBOL, methods[1]);
2045
2085
  }
2046
2086
 
2047
- if (SHAM) createNonEnumerableProperty$4(RegExpPrototype$4[SYMBOL], 'sham', true);
2087
+ if (SHAM) createNonEnumerableProperty$4(RegExpPrototype$2[SYMBOL], 'sham', true);
2048
2088
  };
2049
2089
 
2050
2090
  var uncurryThis$c = functionUncurryThis;
@@ -2138,8 +2178,8 @@ var getSubstitution$1 = function (matched, str, position, captures, namedCapture
2138
2178
  });
2139
2179
  };
2140
2180
 
2141
- var call$9 = functionCall;
2142
- var anObject$7 = anObject$e;
2181
+ var call$8 = functionCall;
2182
+ var anObject$6 = anObject$e;
2143
2183
  var isCallable$a = isCallable$q;
2144
2184
  var classof$7 = classofRaw$2;
2145
2185
  var regexpExec = regexpExec$2;
@@ -2151,20 +2191,20 @@ var $TypeError$b = TypeError;
2151
2191
  var regexpExecAbstract = function (R, S) {
2152
2192
  var exec = R.exec;
2153
2193
  if (isCallable$a(exec)) {
2154
- var result = call$9(exec, R, S);
2155
- if (result !== null) anObject$7(result);
2194
+ var result = call$8(exec, R, S);
2195
+ if (result !== null) anObject$6(result);
2156
2196
  return result;
2157
2197
  }
2158
- if (classof$7(R) === 'RegExp') return call$9(regexpExec, R, S);
2198
+ if (classof$7(R) === 'RegExp') return call$8(regexpExec, R, S);
2159
2199
  throw new $TypeError$b('RegExp#exec called on incompatible receiver');
2160
2200
  };
2161
2201
 
2162
2202
  var apply$3 = functionApply;
2163
- var call$8 = functionCall;
2203
+ var call$7 = functionCall;
2164
2204
  var uncurryThis$a = functionUncurryThis;
2165
2205
  var fixRegExpWellKnownSymbolLogic = fixRegexpWellKnownSymbolLogic;
2166
- var fails$9 = fails$q;
2167
- var anObject$6 = anObject$e;
2206
+ var fails$8 = fails$q;
2207
+ var anObject$5 = anObject$e;
2168
2208
  var isCallable$9 = isCallable$q;
2169
2209
  var isNullOrUndefined$2 = isNullOrUndefined$5;
2170
2210
  var toIntegerOrInfinity = toIntegerOrInfinity$6;
@@ -2204,7 +2244,7 @@ var REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE = (function () {
2204
2244
  return false;
2205
2245
  })();
2206
2246
 
2207
- var REPLACE_SUPPORTS_NAMED_GROUPS = !fails$9(function () {
2247
+ var REPLACE_SUPPORTS_NAMED_GROUPS = !fails$8(function () {
2208
2248
  var re = /./;
2209
2249
  re.exec = function () {
2210
2250
  var result = [];
@@ -2226,13 +2266,13 @@ fixRegExpWellKnownSymbolLogic('replace', function (_, nativeReplace, maybeCallNa
2226
2266
  var O = requireObjectCoercible$1(this);
2227
2267
  var replacer = isNullOrUndefined$2(searchValue) ? undefined : getMethod$2(searchValue, REPLACE);
2228
2268
  return replacer
2229
- ? call$8(replacer, searchValue, O, replaceValue)
2230
- : call$8(nativeReplace, toString$5(O), searchValue, replaceValue);
2269
+ ? call$7(replacer, searchValue, O, replaceValue)
2270
+ : call$7(nativeReplace, toString$5(O), searchValue, replaceValue);
2231
2271
  },
2232
2272
  // `RegExp.prototype[@@replace]` method
2233
2273
  // https://tc39.es/ecma262/#sec-regexp.prototype-@@replace
2234
2274
  function (string, replaceValue) {
2235
- var rx = anObject$6(this);
2275
+ var rx = anObject$5(this);
2236
2276
  var S = toString$5(string);
2237
2277
 
2238
2278
  if (
@@ -2347,6 +2387,24 @@ const isEmptyBoolean = (schema, data) => {
2347
2387
  const isEmptyNumber = (schema, data) => {
2348
2388
  return data === '' || data === undefined || data === null || (schema.type === 'number' || schema.type === 'integer') && isNaN(+data);
2349
2389
  };
2390
+ const validateSinWithLuhn = input => {
2391
+ const cardNumber = input.toString();
2392
+ const digits = cardNumber.replace(/\D/g, '').split('').map(Number);
2393
+ let sum = 0;
2394
+ let isSecond = false;
2395
+ for (let i = digits.length - 1; i >= 0; i--) {
2396
+ let digit = digits[i];
2397
+ if (isSecond) {
2398
+ digit *= 2;
2399
+ if (digit > 9) {
2400
+ digit -= 9;
2401
+ }
2402
+ }
2403
+ sum += digit;
2404
+ isSecond = !isSecond;
2405
+ }
2406
+ return sum % 10 === 0;
2407
+ };
2350
2408
  /**
2351
2409
  * Check if a required, defined input value is valid. Returns an appropriate
2352
2410
  * error message if not.
@@ -2363,6 +2421,12 @@ const checkFieldValidity = props => {
2363
2421
  schema
2364
2422
  } = props;
2365
2423
  const labelToUpdate = getLabelText(uischema.scope, label);
2424
+ const extraSchema = schema;
2425
+ if (extraSchema && data && (extraSchema === null || extraSchema === void 0 ? void 0 : extraSchema.title) === 'Social insurance number') {
2426
+ if (!validateSinWithLuhn(data)) {
2427
+ return extraSchema.errorMessage;
2428
+ }
2429
+ }
2366
2430
  if (required) {
2367
2431
  if (data === undefined) return '';
2368
2432
  if (schema) {
@@ -2717,16 +2781,16 @@ const onChangeForNumericControl = props => {
2717
2781
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2718
2782
  const onChangeForCheckboxData = (data, name, value) => data ? !value ? data === null || data === void 0 ? void 0 : data.filter(item => item !== name) : [...data, name] : [name];
2719
2783
 
2720
- let _$6 = t => t,
2721
- _t$6,
2722
- _t2$3;
2723
- styled.div(_t$6 || (_t$6 = _$6`
2784
+ let _$7 = t => t,
2785
+ _t$7,
2786
+ _t2$4;
2787
+ styled.div(_t$7 || (_t$7 = _$7`
2724
2788
  height: 70vh;
2725
2789
  overflow-y: auto;
2726
2790
  padding-left: var(--goa-space-2xs);
2727
2791
  padding-right: var(--goa-space-2xs);
2728
2792
  `));
2729
- const Visible = styled.div(_t2$3 || (_t2$3 = _$6`
2793
+ const Visible = styled.div(_t2$4 || (_t2$4 = _$7`
2730
2794
  display: ${0};
2731
2795
  `), p => p.visible ? 'initial' : 'none');
2732
2796
 
@@ -2784,9 +2848,9 @@ var toObject$1 = toObject$7;
2784
2848
  var lengthOfArrayLike$2 = lengthOfArrayLike$5;
2785
2849
  var setArrayLength = arraySetLength;
2786
2850
  var doesNotExceedSafeInteger = doesNotExceedSafeInteger$1;
2787
- var fails$8 = fails$q;
2851
+ var fails$7 = fails$q;
2788
2852
 
2789
- var INCORRECT_TO_LENGTH = fails$8(function () {
2853
+ var INCORRECT_TO_LENGTH = fails$7(function () {
2790
2854
  return [].push.call({ length: 0x100000000 }, 1) !== 4294967297;
2791
2855
  });
2792
2856
 
@@ -2858,11 +2922,11 @@ function registerReducer(state, action) {
2858
2922
 
2859
2923
  var $$b = _export;
2860
2924
  var $includes = arrayIncludes.includes;
2861
- var fails$7 = fails$q;
2925
+ var fails$6 = fails$q;
2862
2926
  var addToUnscopables = addToUnscopables$3;
2863
2927
 
2864
2928
  // FF99+ bug
2865
- var BROKEN_ON_SPARSE = fails$7(function () {
2929
+ var BROKEN_ON_SPARSE = fails$6(function () {
2866
2930
  // eslint-disable-next-line es/no-array-prototype-includes -- detection
2867
2931
  return !Array(1).includes();
2868
2932
  });
@@ -2915,9 +2979,9 @@ var getJsonReplacerFunction = function (replacer) {
2915
2979
  var $$a = _export;
2916
2980
  var getBuiltIn$5 = getBuiltIn$9;
2917
2981
  var apply$2 = functionApply;
2918
- var call$7 = functionCall;
2982
+ var call$6 = functionCall;
2919
2983
  var uncurryThis$7 = functionUncurryThis;
2920
- var fails$6 = fails$q;
2984
+ var fails$5 = fails$q;
2921
2985
  var isCallable$7 = isCallable$q;
2922
2986
  var isSymbol = isSymbol$3;
2923
2987
  var arraySlice$1 = arraySlice$2;
@@ -2936,7 +3000,7 @@ var tester = /[\uD800-\uDFFF]/g;
2936
3000
  var low = /^[\uD800-\uDBFF]$/;
2937
3001
  var hi = /^[\uDC00-\uDFFF]$/;
2938
3002
 
2939
- var WRONG_SYMBOLS_CONVERSION = !NATIVE_SYMBOL$1 || fails$6(function () {
3003
+ var WRONG_SYMBOLS_CONVERSION = !NATIVE_SYMBOL$1 || fails$5(function () {
2940
3004
  var symbol = getBuiltIn$5('Symbol')('stringify detection');
2941
3005
  // MS Edge converts symbol values to JSON as {}
2942
3006
  return $stringify([symbol]) !== '[null]'
@@ -2947,7 +3011,7 @@ var WRONG_SYMBOLS_CONVERSION = !NATIVE_SYMBOL$1 || fails$6(function () {
2947
3011
  });
2948
3012
 
2949
3013
  // https://github.com/tc39/proposal-well-formed-stringify
2950
- var ILL_FORMED_UNICODE = fails$6(function () {
3014
+ var ILL_FORMED_UNICODE = fails$5(function () {
2951
3015
  return $stringify('\uDF06\uD834') !== '"\\udf06\\ud834"'
2952
3016
  || $stringify('\uDEAD') !== '"\\udead"';
2953
3017
  });
@@ -2958,7 +3022,7 @@ var stringifyWithSymbolsFix = function (it, replacer) {
2958
3022
  if (!isCallable$7($replacer) && (it === undefined || isSymbol(it))) return; // IE8 returns string on undefined
2959
3023
  args[1] = function (key, value) {
2960
3024
  // some old implementations (like WebKit) could pass numbers as keys
2961
- if (isCallable$7($replacer)) value = call$7($replacer, this, $String(key), value);
3025
+ if (isCallable$7($replacer)) value = call$6($replacer, this, $String(key), value);
2962
3026
  if (!isSymbol(value)) return value;
2963
3027
  };
2964
3028
  return apply$2($stringify, null, args);
@@ -2985,45 +3049,6 @@ if ($stringify) {
2985
3049
  });
2986
3050
  }
2987
3051
 
2988
- var call$6 = functionCall;
2989
- var hasOwn$4 = hasOwnProperty_1;
2990
- var isPrototypeOf$5 = objectIsPrototypeOf;
2991
- var regExpFlags = regexpFlags$1;
2992
-
2993
- var RegExpPrototype$3 = RegExp.prototype;
2994
-
2995
- var regexpGetFlags = function (R) {
2996
- var flags = R.flags;
2997
- return flags === undefined && !('flags' in RegExpPrototype$3) && !hasOwn$4(R, 'flags') && isPrototypeOf$5(RegExpPrototype$3, R)
2998
- ? call$6(regExpFlags, R) : flags;
2999
- };
3000
-
3001
- var PROPER_FUNCTION_NAME = functionName.PROPER;
3002
- var defineBuiltIn$3 = defineBuiltIn$8;
3003
- var anObject$5 = anObject$e;
3004
- var $toString = toString$a;
3005
- var fails$5 = fails$q;
3006
- var getRegExpFlags$1 = regexpGetFlags;
3007
-
3008
- var TO_STRING = 'toString';
3009
- var RegExpPrototype$2 = RegExp.prototype;
3010
- var nativeToString = RegExpPrototype$2[TO_STRING];
3011
-
3012
- var NOT_GENERIC = fails$5(function () { return nativeToString.call({ source: 'a', flags: 'b' }) !== '/a/b'; });
3013
- // FF44- RegExp#toString has a wrong name
3014
- var INCORRECT_NAME = PROPER_FUNCTION_NAME && nativeToString.name !== TO_STRING;
3015
-
3016
- // `RegExp.prototype.toString` method
3017
- // https://tc39.es/ecma262/#sec-regexp.prototype.tostring
3018
- if (NOT_GENERIC || INCORRECT_NAME) {
3019
- defineBuiltIn$3(RegExpPrototype$2, TO_STRING, function toString() {
3020
- var R = anObject$5(this);
3021
- var pattern = $toString(R.source);
3022
- var flags = $toString(getRegExpFlags$1(R));
3023
- return '/' + pattern + '/' + flags;
3024
- }, { unsafe: true });
3025
- }
3026
-
3027
3052
  var isObject$4 = isObject$d;
3028
3053
  var classof$4 = classofRaw$2;
3029
3054
  var wellKnownSymbol$8 = wellKnownSymbol$j;
@@ -4211,13 +4236,127 @@ const GoATimeControl = props => jsx(GoAInputBaseControl, Object.assign({}, props
4211
4236
  const GoATimeControlTester = rankWith(4, isTimeControl);
4212
4237
  const GoAInputTimeControl = withJsonFormsControlProps(GoATimeControl);
4213
4238
 
4239
+ let _$6 = t => t,
4240
+ _t$6,
4241
+ _t2$3,
4242
+ _t3$3,
4243
+ _t4$2;
4244
+ styled.div(_t$6 || (_t$6 = _$6`
4245
+ text-overflow: ellipsis;
4246
+ overflow: hidden;
4247
+ min-height: 43px;
4248
+ box-sizing: border-box;
4249
+ width: 100%;
4250
+ padding: 8px;
4251
+ padding-right: 8px;
4252
+ border-radius: 4px;
4253
+ border: 1px solid #666;
4254
+ font-size: 18px;
4255
+ font-weight: 400;
4256
+ -webkit-appearance: none;
4257
+ -moz-appearance: none;
4258
+ appearance: none;
4259
+ box-shadow: ${0};
4260
+ `), p => p.isOpen ? `0 0 0 3px #feba35` : '');
4261
+ const GoADropdownListContainerWrapper = styled.div(_t2$3 || (_t2$3 = _$6`
4262
+ position: relative;
4263
+ display: ${0};
4264
+ `), p => !(p === null || p === void 0 ? void 0 : p.isOpen) && 'none');
4265
+ const GoADropdownListContainer = styled.div(_t3$3 || (_t3$3 = _$6`
4266
+ border: solid 1px #dcdcdc;
4267
+ border-radius: 4px;
4268
+ background: #fff;
4269
+ padding: 0;
4270
+ margin-top: 3px;
4271
+ width: 100%;
4272
+ overflow-y: auto;
4273
+ z-index: 1000;
4274
+ position: absolute;
4275
+ line-height: 2rem;
4276
+ max-height: ${0};
4277
+ `), p => p.optionListMaxHeight || '272px');
4278
+ const GoADropdownListOption = styled.div(_t4$2 || (_t4$2 = _$6`
4279
+ padding: 4px 12px;
4280
+ text-overflow: ellipsis;
4281
+ color: ${0} !important;
4282
+ border: 1px solid #f1f1f1;
4283
+ z-index: 1001;
4284
+ background: ${0};
4285
+ &:hover {
4286
+ background-color: ${0};
4287
+ color: ${0} !important;
4288
+ }
4289
+ `), 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');
4290
+ const Dropdown = props => {
4291
+ const {
4292
+ label,
4293
+ selected,
4294
+ onChange,
4295
+ optionListMaxHeight,
4296
+ isAutocompletion,
4297
+ id
4298
+ } = props;
4299
+ const [isOpen, setIsOpen] = useState(false);
4300
+ const [selectedOption, setSelectedOption] = useState(selected);
4301
+ const trailingIcon = isOpen ? 'chevron-up' : 'chevron-down';
4302
+ const [items, setItems] = useState(props.items);
4303
+ const [inputText, setInputText] = useState(selected);
4304
+ useEffect(() => {
4305
+ setItems(props.items);
4306
+ }, [isEqual(props.items, items)]);
4307
+ return jsxs("div", {
4308
+ "data-testid": id,
4309
+ children: [jsx(GoAInput, {
4310
+ name: `dropdown-${label}`,
4311
+ width: "100%",
4312
+ value: inputText,
4313
+ testId: `${id}-input`,
4314
+ id: `${id}-input`,
4315
+ readonly: !isAutocompletion,
4316
+ onChange: (name, value) => {
4317
+ if (isAutocompletion) {
4318
+ setIsOpen(true);
4319
+ const selectedItems = props.items.filter(item => {
4320
+ return item.label.includes(value);
4321
+ });
4322
+ setItems(selectedItems);
4323
+ }
4324
+ },
4325
+ trailingIcon: trailingIcon,
4326
+ onFocus: () => {
4327
+ setIsOpen(!isOpen);
4328
+ }
4329
+ }), jsx(GoADropdownListContainerWrapper, {
4330
+ isOpen: isOpen,
4331
+ children: jsx(GoADropdownListContainer, {
4332
+ optionListMaxHeight: optionListMaxHeight,
4333
+ children: items.map(item => {
4334
+ return jsx(GoADropdownListOption, {
4335
+ isSelected: item.value === selected,
4336
+ children: jsx("div", {
4337
+ "data-testid": `${id}-${item.label}-option`,
4338
+ onClick: () => {
4339
+ onChange(item.value);
4340
+ setSelectedOption(item.value);
4341
+ setInputText(item.value);
4342
+ setIsOpen(false);
4343
+ },
4344
+ children: item.label
4345
+ }, `jsonforms-dropdown-${label}-${item.value}`)
4346
+ });
4347
+ })
4348
+ })
4349
+ })]
4350
+ });
4351
+ };
4352
+
4214
4353
  function fetchRegisterConfigFromOptions(options) {
4215
4354
  if (!(options === null || options === void 0 ? void 0 : options.url) && !(options === null || options === void 0 ? void 0 : options.urn)) return undefined;
4216
4355
  const config = Object.assign({}, options);
4217
4356
  return config;
4218
4357
  }
4219
4358
  const EnumSelect = props => {
4220
- var _a, _b, _c, _d, _e;
4359
+ var _a, _b, _c, _d;
4221
4360
  const {
4222
4361
  data,
4223
4362
  id,
@@ -4242,9 +4381,8 @@ const EnumSelect = props => {
4242
4381
  error = (registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.fetchErrors(registerConfig)) || '';
4243
4382
  }
4244
4383
  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
4384
  const mergedOptions = useMemo(() => {
4247
- const newOptions = [...(options || []), ...registerData.map(d => {
4385
+ const newOptions = [...(options || []), ...((registerData === null || registerData === void 0 ? void 0 : registerData.map(d => {
4248
4386
  if (typeof d === 'string') {
4249
4387
  return {
4250
4388
  value: d,
@@ -4253,7 +4391,7 @@ const EnumSelect = props => {
4253
4391
  } else {
4254
4392
  return Object.assign({}, d);
4255
4393
  }
4256
- })];
4394
+ })) || [])];
4257
4395
  const hasNonEmptyOptions = newOptions.some(option => option.value !== '');
4258
4396
  if (!hasNonEmptyOptions && newOptions.length === 1 && newOptions[0].value === '') {
4259
4397
  return newOptions;
@@ -4266,6 +4404,7 @@ const EnumSelect = props => {
4266
4404
  }
4267
4405
  return newOptions.filter(option => option.value !== '');
4268
4406
  }, [registerData, options]);
4407
+ console.log(mergedOptions);
4269
4408
  useEffect(() => {
4270
4409
  if (registerConfig) {
4271
4410
  registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.fetchRegisterByUrl(registerConfig);
@@ -4274,25 +4413,16 @@ const EnumSelect = props => {
4274
4413
  return jsx("div", {
4275
4414
  children: error.length > 0 ? callout({
4276
4415
  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) => {
4416
+ }) : jsx(Dropdown, {
4417
+ items: mergedOptions,
4418
+ selected: data,
4419
+ id: `jsonforms-${label}-dropdown`,
4420
+ label: label,
4421
+ isAutocompletion: autocompletion,
4422
+ onChange: value => {
4286
4423
  handleChange(path, value);
4287
4424
  }
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`)
4425
+ })
4296
4426
  });
4297
4427
  };
4298
4428
  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.33.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,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 {};
@@ -19,6 +19,7 @@ export declare const controlScopeMatchesLabel: (scope: string, label: string) =>
19
19
  * @returns
20
20
  */
21
21
  export declare const getLabelText: (scope: string, label: string) => string;
22
+ export declare const validateSinWithLuhn: (input: number) => boolean;
22
23
  /**
23
24
  * Check if a required, defined input value is valid. Returns an appropriate
24
25
  * error message if not.