@abgov/jsonforms-components 1.34.1 → 1.34.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
@@ -2424,7 +2424,7 @@ const checkFieldValidity = props => {
2424
2424
  const extraSchema = schema;
2425
2425
  if (extraSchema && data && (extraSchema === null || extraSchema === void 0 ? void 0 : extraSchema.title) === 'Social insurance number') {
2426
2426
  if (data.length === 11 && !validateSinWithLuhn(data)) {
2427
- return 'Please enter valid SIN';
2427
+ return 'Social insurance number is invalid';
2428
2428
  } else if (data.length < 11) {
2429
2429
  return extraSchema.errorMessage;
2430
2430
  }
@@ -6837,9 +6837,16 @@ const filterAlbertaAddresses = suggestions => {
6837
6837
  return suggestions.filter(suggestion => suggestion.Description.includes('AB'));
6838
6838
  };
6839
6839
  const mapSuggestionToAddress = suggestion => {
6840
- const textParts = suggestion.Text.split(',');
6841
- const addressLine1 = textParts.length > 1 ? textParts[1].trim() : textParts[0].trim();
6842
- const addressLine2 = textParts.length > 1 ? textParts[0].trim() : '';
6840
+ let addressLine1, addressLine2;
6841
+ const suiteMatch = suggestion.Text.match(/(Suite|Apt|Unit|#)+/i);
6842
+ const textParts = suggestion.Text.split(' ');
6843
+ if (suiteMatch) {
6844
+ addressLine1 = suggestion.Text.replace(textParts[0], '').trim();
6845
+ addressLine2 = textParts[0].trim();
6846
+ } else {
6847
+ addressLine2 = '';
6848
+ addressLine1 = suggestion.Text.trim();
6849
+ }
6843
6850
  const descriptionParts = suggestion.Description.split(',');
6844
6851
  const city = descriptionParts[0].trim();
6845
6852
  const provinceAndPostalCode = descriptionParts[1].trim().split(' ');
@@ -6857,11 +6864,14 @@ const mapSuggestionToAddress = suggestion => {
6857
6864
 
6858
6865
  let _$1 = t => t,
6859
6866
  _t$1;
6860
- const AddressSearch = styled.div(_t$1 || (_t$1 = _$1`
6867
+ const SearchBox = styled.div(_t$1 || (_t$1 = _$1`
6868
+ position: relative;
6869
+
6861
6870
  .suggestions {
6871
+ width: 100%;
6872
+ margin-top: 3px;
6862
6873
  border-top-width: 0;
6863
6874
  list-style: none;
6864
- margin-top: 0;
6865
6875
  max-height: 15.5rem;
6866
6876
  width: 100%;
6867
6877
  position: absolute;
@@ -6888,17 +6898,21 @@ const AddressSearch = styled.div(_t$1 || (_t$1 = _$1`
6888
6898
 
6889
6899
  const ADDRESS_PATH = 'api/gateway/v1/address/v1/find';
6890
6900
  const AddressLookUpControl = props => {
6891
- var _a, _b;
6901
+ var _a, _b, _c;
6892
6902
  const {
6893
6903
  data,
6894
6904
  path,
6895
6905
  schema,
6896
- handleChange
6906
+ handleChange,
6907
+ uischema
6897
6908
  } = props;
6898
6909
  const isAlbertaAddress = ((_b = (_a = schema === null || schema === void 0 ? void 0 : schema.properties) === null || _a === void 0 ? void 0 : _a.subdivisionCode) === null || _b === void 0 ? void 0 : _b.const) === 'AB';
6899
6910
  const formCtx = useContext(JsonFormContext);
6900
6911
  const formHost = formCtx === null || formCtx === void 0 ? void 0 : formCtx.formUrl;
6901
6912
  const formUrl = `${formHost}/${ADDRESS_PATH}`;
6913
+ const autocompletion = ((_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.autocomplete) === true;
6914
+ const [open, setOpen] = useState(false);
6915
+ const label = typeof (uischema === null || uischema === void 0 ? void 0 : uischema.label) === 'string' ? uischema.label : '';
6902
6916
  const defaultAddress = {
6903
6917
  addressLine1: '',
6904
6918
  addressLine2: '',
@@ -6926,6 +6940,7 @@ const AddressLookUpControl = props => {
6926
6940
  const fetchSuggestions = () => __awaiter(void 0, void 0, void 0, function* () {
6927
6941
  if (searchTerm.length > 2) {
6928
6942
  setLoading(true);
6943
+ setOpen(true);
6929
6944
  const suggestions = yield fetchAddressSuggestions(formUrl, searchTerm, isAlbertaAddress);
6930
6945
  if (isAlbertaAddress) {
6931
6946
  setSuggestions(filterAlbertaAddresses(suggestions));
@@ -6935,6 +6950,7 @@ const AddressLookUpControl = props => {
6935
6950
  setLoading(false);
6936
6951
  } else {
6937
6952
  setSuggestions([]);
6953
+ setOpen(false);
6938
6954
  }
6939
6955
  });
6940
6956
  fetchSuggestions();
@@ -6948,28 +6964,31 @@ const AddressLookUpControl = props => {
6948
6964
  handleChange(path, suggestAddress);
6949
6965
  setSuggestions([]);
6950
6966
  };
6951
- return jsxs(AddressSearch, {
6952
- children: [jsxs(GoAFormItem, {
6953
- label: "",
6954
- children: [jsx(GoAInput, {
6955
- leadingIcon: "search",
6956
- name: "address-form-address1",
6957
- testId: "address-form-address1",
6958
- ariaLabel: 'address-form-address1',
6959
- placeholder: "Start typing the first line of your address",
6960
- value: (address === null || address === void 0 ? void 0 : address.addressLine1) || '',
6961
- onChange: (name, value) => handleDropdownChange(value),
6962
- width: "100%"
6963
- }), loading && jsx(GoASkeleton, {
6964
- type: "text",
6965
- "data-testId": "loading"
6966
- }, 1), jsx("ul", {
6967
- className: "suggestions",
6968
- children: suggestions && suggestions.map((suggestion, index) => jsx("li", {
6969
- onClick: () => handleSuggestionClick(suggestion),
6970
- children: `${suggestion.Text} ${suggestion.Description}`
6971
- }, index))
6972
- })]
6967
+ return jsxs("div", {
6968
+ children: [jsx(GoAFormItem, {
6969
+ label: label,
6970
+ children: jsxs(SearchBox, {
6971
+ children: [jsx(GoAInput, {
6972
+ leadingIcon: "search",
6973
+ name: "address-form-address1",
6974
+ testId: "address-form-address1",
6975
+ ariaLabel: 'address-form-address1',
6976
+ placeholder: "Start typing the first line of your address",
6977
+ value: (address === null || address === void 0 ? void 0 : address.addressLine1) || '',
6978
+ onChange: (name, value) => handleDropdownChange(value),
6979
+ width: "100%"
6980
+ }), loading && jsx(GoASkeleton, {
6981
+ type: "text",
6982
+ "data-testId": "loading"
6983
+ }, 1), suggestions && jsx("ul", {
6984
+ className: "suggestions",
6985
+ tabIndex: 0,
6986
+ children: suggestions && autocompletion && open && suggestions.map((suggestion, index) => jsx("li", {
6987
+ onClick: () => handleSuggestionClick(suggestion),
6988
+ children: `${suggestion.Text} ${suggestion.Description}`
6989
+ }, index))
6990
+ })]
6991
+ })
6973
6992
  }), jsx("br", {}), jsx(AddressInputs, {
6974
6993
  address: address,
6975
6994
  handleInputChange: handleInputChange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.34.1",
3
+ "version": "1.34.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",
@@ -1 +1 @@
1
- export declare const AddressSearch: import("styled-components").StyledComponent<"div", any, {}, never>;
1
+ export declare const SearchBox: import("styled-components").StyledComponent<"div", any, {}, never>;