@woosmap/ui 4.221.0 → 4.222.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.
Files changed (137) hide show
  1. package/package.json +108 -120
  2. package/src/components/Button/Button.js +2 -2
  3. package/src/components/Button/Button.stories.js +5 -5
  4. package/src/components/Button/Button.test.js +1 -1
  5. package/src/components/Button/ButtonSwitch.js +1 -1
  6. package/src/components/Button/ButtonWithDropdown.js +3 -3
  7. package/src/components/Button/ButtonWithDropdown.test.js +1 -1
  8. package/src/components/Card/Card.js +29 -29
  9. package/src/components/Card/Card.stories.js +6 -6
  10. package/src/components/Card/Card.test.js +1 -1
  11. package/src/components/Card/SimpleCard.js +2 -2
  12. package/src/components/Card/SimpleCard.test.js +1 -1
  13. package/src/components/CodeSnippet/CodeSnippet.stories.js +1 -1
  14. package/src/components/CodeSnippet/CodeSnippet.test.js +1 -1
  15. package/src/components/CopyClipboardButton/CopyClipboardButton.js +3 -3
  16. package/src/components/CopyClipboardButton/CopyToClipboard.stories.js +1 -1
  17. package/src/components/CopyClipboardButton/CopyToClipboard.test.js +1 -1
  18. package/src/components/DateTime/DateTime.stories.js +1 -1
  19. package/src/components/DateTime/DateTime.test.js +1 -1
  20. package/src/components/Demo/AddressDemo.js +10 -10
  21. package/src/components/Demo/AddressDemo.stories.js +1 -1
  22. package/src/components/Demo/AutocompleteAddressDemo.js +10 -10
  23. package/src/components/Demo/AutocompleteAddressDemo.stories.js +2 -2
  24. package/src/components/Demo/DistanceDemo.js +12 -12
  25. package/src/components/Demo/DistanceDemo.stories.js +1 -1
  26. package/src/components/Demo/DistanceDemo.test.js +1 -1
  27. package/src/components/Demo/GeolocationDemo.js +7 -7
  28. package/src/components/Demo/GeolocationDemo.stories.js +1 -1
  29. package/src/components/Demo/GeolocationDemo.test.js +1 -1
  30. package/src/components/Demo/LocalitiesAddressDemo.js +8 -8
  31. package/src/components/Demo/LocalitiesAddressDemo.stories.js +1 -1
  32. package/src/components/Demo/LocalitiesAllDemo.js +5 -5
  33. package/src/components/Demo/LocalitiesAllDemo.stories.js +1 -1
  34. package/src/components/Demo/LocalitiesDemo.js +10 -10
  35. package/src/components/Demo/LocalitiesDemo.stories.js +1 -1
  36. package/src/components/Demo/LocalitiesFRAddressDemo.js +239 -261
  37. package/src/components/Demo/LocalitiesFRAddressDemo.stories.js +2 -2
  38. package/src/components/Demo/LocalitiesUKAddressDemo.js +271 -294
  39. package/src/components/Demo/LocalitiesUKAddressDemo.stories.js +1 -1
  40. package/src/components/Demo/MapDemo.js +231 -233
  41. package/src/components/Demo/MapDemo.stories.js +1 -1
  42. package/src/components/Demo/SearchDemo.js +9 -9
  43. package/src/components/Demo/SearchDemo.stories.js +1 -1
  44. package/src/components/Demo/SearchDemo.test.js +1 -1
  45. package/src/components/Demo/Showcase.stories.js +7 -7
  46. package/src/components/Demo/SkeletonDemo.js +8 -8
  47. package/src/components/Demo/SkeletonDemo.stories.js +2 -2
  48. package/src/components/Demo/SkeletonDemo.test.js +2 -2
  49. package/src/components/Demo/W3WDemo.js +9 -9
  50. package/src/components/Demo/W3WDemo.stories.js +2 -2
  51. package/src/components/Dropdown/Dropdown.js +4 -4
  52. package/src/components/Dropdown/Dropdown.stories.js +1 -1
  53. package/src/components/Dropdown/Dropdown.test.js +1 -1
  54. package/src/components/DynamicTag/DynamicTag.js +5 -5
  55. package/src/components/DynamicTag/DynamicTag.stories.js +1 -1
  56. package/src/components/DynamicTag/DynamicTag.test.js +1 -1
  57. package/src/components/Flash/Flash.js +1 -1
  58. package/src/components/Flash/Flash.stories.js +1 -1
  59. package/src/components/Flash/Flash.test.js +1 -1
  60. package/src/components/Icon/Icon.js +409 -409
  61. package/src/components/Icon/Icon.stories.js +1 -1
  62. package/src/components/Icon/Icon.test.js +1 -1
  63. package/src/components/Icon/WebSiteIcon.js +231 -231
  64. package/src/components/InfoMessage/Flash.js +1 -1
  65. package/src/components/InfoMessage/InfoMessage.js +2 -2
  66. package/src/components/InfoMessage/InfoMessage.stories.js +1 -1
  67. package/src/components/InfoMessage/InfoMessage.test.js +1 -1
  68. package/src/components/Input/Input.js +2 -2
  69. package/src/components/Input/Input.password.test.js +1 -1
  70. package/src/components/Input/Input.stories.js +1 -1
  71. package/src/components/Input/Input.test.js +1 -1
  72. package/src/components/Label/Label.js +1 -1
  73. package/src/components/Label/Label.stories.js +1 -1
  74. package/src/components/Label/Label.test.js +1 -1
  75. package/src/components/Map/InfoWindow.test.js +1 -1
  76. package/src/components/Map/Map.stories.js +3 -3
  77. package/src/components/Map/Marker.test.js +1 -1
  78. package/src/components/Map/drawOnMap.test.js +2 -10
  79. package/src/components/Modal/ConfirmationModal.js +2 -2
  80. package/src/components/Modal/ConfirmationModal.test.js +1 -1
  81. package/src/components/Modal/Modal.js +6 -6
  82. package/src/components/Modal/Modal.stories.js +3 -3
  83. package/src/components/Modal/Modal.test.js +1 -1
  84. package/src/components/OfflineChatBot/OfflineChatBot.js +4 -4
  85. package/src/components/OfflineChatBot/OfflineChatBot.stories.js +2 -2
  86. package/src/components/Panel/Panel.js +2 -2
  87. package/src/components/Panel/Panel.stories.js +2 -2
  88. package/src/components/Panel/Panel.test.js +1 -1
  89. package/src/components/PasswordStrengthBar/PasswordStrengthBar.stories.js +1 -1
  90. package/src/components/PasswordStrengthBar/PasswordStrengthBar.test.js +1 -1
  91. package/src/components/Popover/ConfirmationPopover.js +3 -3
  92. package/src/components/Popover/ConfirmationPopover.test.js +1 -1
  93. package/src/components/Popover/Popover.js +1 -1
  94. package/src/components/Popover/Popover.stories.js +3 -3
  95. package/src/components/Popover/Popover.test.js +2 -2
  96. package/src/components/PricingSlider/PricingData.js +97 -107
  97. package/src/components/PricingSlider/PricingSimulator.js +3 -3
  98. package/src/components/PricingSlider/PricingSimulator.stories.js +1 -1
  99. package/src/components/PricingSlider/PricingSlider.js +4 -5
  100. package/src/components/ProgressBar/ProgressBar.js +1 -1
  101. package/src/components/ProgressBar/ProgressBar.stories.js +1 -1
  102. package/src/components/ProgressBar/ProgressBar.test.js +1 -1
  103. package/src/components/ScrollBar/ScrollBar.stories.js +1 -1
  104. package/src/components/ScrollBar/ScrollBar.test.js +1 -1
  105. package/src/components/Select/Select.stories.js +4 -4
  106. package/src/components/Select/TagSelect.test.js +1 -1
  107. package/src/components/ServiceMessage/ServiceMessage.js +1 -1
  108. package/src/components/ServiceMessage/ServiceMessage.stories.js +2 -2
  109. package/src/components/SnackBar/SnackBar.js +2 -2
  110. package/src/components/SnackBar/SnackBar.stories.js +3 -3
  111. package/src/components/SnackBar/SnackBar.test.js +3 -3
  112. package/src/components/SnackBar/withSnackBar.js +1 -1
  113. package/src/components/Stepper/Stepper.js +2 -2
  114. package/src/components/Stepper/Stepper.stories.js +1 -1
  115. package/src/components/Switch/Switch.stories.js +1 -1
  116. package/src/components/Switch/Switch.test.js +1 -1
  117. package/src/components/Tab/Tab.js +1 -1
  118. package/src/components/Tab/Tab.stories.js +1 -1
  119. package/src/components/Tooltip/Tooltip.stories.js +1 -1
  120. package/src/components/Tooltip/Tooltip.test.js +1 -1
  121. package/src/components/UseCase/UseCase.js +9 -9
  122. package/src/components/UseCase/UseCase.stories.js +4 -4
  123. package/src/components/Woosmap/AddressAutocomplete.js +3 -3
  124. package/src/components/Woosmap/LocalitiesAutocomplete.js +1 -1
  125. package/src/components/Woosmap/Woosmap.stories.js +3 -3
  126. package/src/components/utils/Script.test.js +1 -1
  127. package/src/components/utils/locale.js +2 -2
  128. package/src/components/withClickOutside/withClickOutside.test.js +1 -1
  129. package/src/components/withFormValidation/withFormValidation.js +2 -2
  130. package/src/components/withFormValidation/withFormValidation.stories.js +2 -2
  131. package/src/components/withFormValidation/withFormValidation.test.js +2 -2
  132. package/src/index.js +61 -61
  133. package/src/locales/en/translation.json +143 -128
  134. package/src/locales/fr/translation.json +143 -128
  135. package/src/styles/console/pricing-slider-back.styl +593 -0
  136. package/src/website.js +25 -25
  137. package/craco.config.js +0 -9
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import LocalitiesFRAddressDemo from '@/components/Demo/LocalitiesFRAddressDemo';
3
- import { changeLanguage } from '@/components/utils/locale';
2
+ import LocalitiesFRAddressDemo from './LocalitiesFRAddressDemo';
3
+ import { changeLanguage } from '../utils/locale';
4
4
 
5
5
  const Story = {
6
6
  title: 'demo/LocalitiesFRAddress',
@@ -1,317 +1,294 @@
1
1
  /* eslint-disable */
2
2
  import axios from 'axios';
3
3
  import React, { Component } from 'react';
4
- import Demo from '@/components/Demo/SkeletonDemo';
5
- import LocalitiesAutocomplete from '@/components/Woosmap/LocalitiesAutocomplete';
6
- import Constants from '@/Constants';
7
- import { tr } from '@/components/utils/locale';
8
- import Input from '@/components/Input/Input';
4
+ import { changeLanguage } from '../utils/locale';
5
+ import Demo from './SkeletonDemo';
6
+ import LocalitiesAutocomplete from '../Woosmap/LocalitiesAutocomplete';
7
+ import Constants from '../../Constants';
8
+ import { tr } from '../utils/locale';
9
+ import Input from '../Input/Input';
9
10
 
10
11
  export default class LocalitiesDemo extends Component {
11
- constructor(props) {
12
- super(props);
13
- const types = [
14
- { label: tr("Localities"), value: "locality" },
15
- { label: tr("Postal codes"), value: "postal_code" },
16
- {
17
- label: tr("Administrative areas (States, regions, ...)"),
18
- value: "admin_level",
19
- },
20
- { label: tr("Airports"), value: "airport" },
21
- { label: tr("Train stations"), value: "train_station" },
22
- { label: tr("Metro stations"), value: "metro_station" },
23
- { label: tr("Shopping centers"), value: "shopping" },
24
- { label: tr("Museums"), value: "museum" },
25
- { label: tr("Tourist attractions"), value: "tourist_attraction" },
26
- { label: tr("Amusement parks"), value: "amusement_park" },
27
- { label: tr("Art galleries"), value: "art_gallery" },
28
- { label: tr("Zoos"), value: "zoo" },
29
- ];
30
- this.state = {
31
- localities: null,
32
- selectedLocality: null,
33
- error: null,
34
- input: "",
35
- localitiesTypes: [{ label: "Address", value: "address" }],
36
- countries: [
37
- { label: "UK", value: "gb" },
38
- { label: "JE", value: "je" },
39
- { label: "GG", value: "gg" },
40
- { label: "IM", value: "im" },
41
- ],
42
- language: "en",
43
- };
44
- this.types = types.map((item) => ({
45
- label: item.label,
46
- value: item.value,
47
- }));
48
- this.mounted = true;
49
- this.viewport = null;
50
- this.requestUrl = "https://api.woosmap.com/localities/autocomplete/";
51
- this.requestDetailsUrl = "https://api.woosmap.com/localities/details/";
52
- this.inputRef = React.createRef();
53
- }
54
-
55
- componentDidMount() {
56
- this.requestLocalities();
57
- }
58
-
59
- componentWillUnmount() {
60
- this.mounted = false;
61
- }
62
-
63
- requestLocalities = () => {
64
- axios
65
- .get(this.requestUrl, {
66
- params: this.getRequestparams(),
67
- })
68
- .then((response) => {
69
- if (this.mounted) {
70
- this.setState({
71
- localities: response.data,
12
+ constructor(props) {
13
+ super(props);
14
+ const types = [
15
+ { label: tr('Localities'), value: 'locality' },
16
+ { label: tr('Postal codes'), value: 'postal_code' },
17
+ {
18
+ label: tr('Administrative areas (States, regions, ...)'),
19
+ value: 'admin_level',
20
+ },
21
+ { label: tr('Airports'), value: 'airport' },
22
+ { label: tr('Train stations'), value: 'train_station' },
23
+ { label: tr('Metro stations'), value: 'metro_station' },
24
+ { label: tr('Shopping centers'), value: 'shopping' },
25
+ { label: tr('Museums'), value: 'museum' },
26
+ { label: tr('Tourist attractions'), value: 'tourist_attraction' },
27
+ { label: tr('Amusement parks'), value: 'amusement_park' },
28
+ { label: tr('Art galleries'), value: 'art_gallery' },
29
+ { label: tr('Zoos'), value: 'zoo' },
30
+ ];
31
+ this.state = {
32
+ localities: null,
33
+ selectedLocality: null,
72
34
  error: null,
73
- });
74
- }
75
- })
76
- .catch((error) => {
77
- const errorResult =
78
- (error && error.response && error.response.data) || "Unhandled error";
79
- this.setState({ error: errorResult });
80
- });
81
- };
82
-
83
- requestLocalityDetails = (publicId) => {
84
- axios
85
- .get(this.requestDetailsUrl, {
86
- params: {
87
- public_id: publicId,
88
- key: Constants.woosmapKey,
89
- language: "en",
90
- },
91
- })
92
- .then((response) => {
93
- if (this.mounted) {
94
- this.setState({
95
- error: null,
96
- selectedLocality: response.data.result,
97
- });
98
- }
99
- })
100
- .catch((error) => {
101
- const errorResult =
102
- (error && error.response && error.response.data) || "Unhandled error";
103
- this.setState({ error: errorResult });
104
- });
105
- };
106
-
107
- getRequestparams = () => {
108
- const { input, language, localitiesTypes, countries, selectedLocality } =
109
- this.state;
110
- if (selectedLocality) {
111
- return {
112
- key: Constants.woosmapKey,
113
- public_id: selectedLocality.public_id,
114
- };
35
+ input: '',
36
+ localitiesTypes: [{ label: 'Address', value: 'address' }],
37
+ countries: [
38
+ { label: 'UK', value: 'gb' },
39
+ { label: 'JE', value: 'je' },
40
+ { label: 'GG', value: 'gg' },
41
+ { label: 'IM', value: 'im' },
42
+ ],
43
+ language: 'en',
44
+ };
45
+ this.types = types.map((item) => ({
46
+ label: item.label,
47
+ value: item.value,
48
+ }));
49
+ this.mounted = true;
50
+ this.viewport = null;
51
+ this.requestUrl = 'https://api.woosmap.com/localities/autocomplete/';
52
+ this.requestDetailsUrl = 'https://api.woosmap.com/localities/details/';
53
+ this.inputRef = React.createRef();
115
54
  }
116
- return {
117
- key: Constants.woosmapKey,
118
- input,
119
- language,
120
- types: localitiesTypes.map((item) => item.value).join("|"),
121
- components: countries.map((item) => `country:${item.value}`).join("|"),
122
- };
123
- };
124
55
 
125
- selectLocality = (locality) => {
126
- if (locality) {
127
- this.requestLocalityDetails(locality.public_id);
128
- } else {
129
- this.setState({
130
- error: null,
131
- selectedLocality: null,
132
- });
56
+ componentDidMount() {
57
+ this.requestLocalities();
133
58
  }
134
- };
135
59
 
136
- getHighlightedLocalityDesc = (locality) => {
137
- let { description } = locality;
138
-
139
- if (
140
- locality.matched_substrings &&
141
- locality.matched_substrings.description
142
- ) {
143
- for (
144
- let j = locality.matched_substrings.description.length - 1;
145
- j >= 0;
146
- j--
147
- ) {
148
- const match = locality.matched_substrings.description[j];
149
- description = `${description.substring(
150
- 0,
151
- match.offset,
152
- )}<span class="localities-matched">${description.substring(
153
- match.offset,
154
- match.offset + match.length,
155
- )}</span>${description.substring(match.offset + match.length)}`;
156
- }
60
+ componentWillUnmount() {
61
+ this.mounted = false;
157
62
  }
158
- // eslint-disable-next-line react/no-danger
159
- return <div dangerouslySetInnerHTML={{ __html: description }} />;
160
- };
161
63
 
162
- renderHeaderFilters = () => {
163
- const inputFilter = {
164
- label: tr("Type in a UK address "),
165
- component: (
166
- <LocalitiesAutocomplete
167
- inputRef={this.inputRef}
168
- woosmapKey={Constants.woosmapKey}
169
- placeholder="Type in an address"
170
- defaultLocality={this.defaultOrigin}
171
- language="en"
172
- components="country:gb|country:je|country:gg|country:im"
173
- types="address"
174
- callback={this.selectLocality}
175
- />
176
- ),
64
+ requestLocalities = () => {
65
+ axios
66
+ .get(this.requestUrl, {
67
+ params: this.getRequestparams(),
68
+ })
69
+ .then((response) => {
70
+ if (this.mounted) {
71
+ this.setState({
72
+ localities: response.data,
73
+ error: null,
74
+ });
75
+ }
76
+ })
77
+ .catch((error) => {
78
+ const errorResult = (error && error.response && error.response.data) || 'Unhandled error';
79
+ this.setState({ error: errorResult });
80
+ });
177
81
  };
178
- return [inputFilter];
179
- };
180
82
 
181
- renderFooterFilters = () => [];
83
+ requestLocalityDetails = (publicId) => {
84
+ axios
85
+ .get(this.requestDetailsUrl, {
86
+ params: {
87
+ public_id: publicId,
88
+ key: Constants.woosmapKey,
89
+ language: 'en',
90
+ },
91
+ })
92
+ .then((response) => {
93
+ if (this.mounted) {
94
+ this.setState({
95
+ error: null,
96
+ selectedLocality: response.data.result,
97
+ });
98
+ }
99
+ })
100
+ .catch((error) => {
101
+ const errorResult = (error && error.response && error.response.data) || 'Unhandled error';
102
+ this.setState({ error: errorResult });
103
+ });
104
+ };
182
105
 
183
- renderAddress = () => {
184
- const { selectedLocality } = this.state;
185
- let addressComponents = [];
186
- const hasComponents =
187
- selectedLocality && selectedLocality.address_components;
188
- if (hasComponents) {
189
- addressComponents = selectedLocality.address_components;
190
- }
191
- let shippingAddress = "";
192
- let shippingAddress2 = "";
193
- let postcode = "";
194
- let locality = "";
195
- let state = "";
196
- let country = "";
197
- addressComponents.forEach((component) => {
198
- const [componentType] = component.types;
199
- switch (componentType) {
200
- case "street_number": {
201
- shippingAddress = `${component.long_name} ${shippingAddress}`;
202
- break;
203
- }
204
- case "route": {
205
- shippingAddress += component.short_name;
206
- break;
207
- }
208
- case "postal_codes": {
209
- postcode = `${component.long_name}${postcode}`;
210
- break;
106
+ getRequestparams = () => {
107
+ const { input, language, localitiesTypes, countries, selectedLocality } = this.state;
108
+ if (selectedLocality) {
109
+ return {
110
+ key: Constants.woosmapKey,
111
+ public_id: selectedLocality.public_id,
112
+ };
211
113
  }
212
- case "postal_code_suffix": {
213
- postcode = `${postcode}-${component.long_name}`;
214
- break;
215
- }
216
- case "locality":
217
- locality = component.long_name;
218
- break;
114
+ return {
115
+ key: Constants.woosmapKey,
116
+ input,
117
+ language,
118
+ types: localitiesTypes.map((item) => item.value).join('|'),
119
+ components: countries.map((item) => `country:${item.value}`).join('|'),
120
+ };
121
+ };
219
122
 
220
- case "state": {
221
- state = component.long_name;
222
- break;
223
- }
224
- case "administrative_area_level_1": {
225
- state = component.long_name;
226
- break;
227
- }
228
- case "country": {
229
- country = component.long_name;
230
- break;
123
+ selectLocality = (locality) => {
124
+ if (locality) {
125
+ this.requestLocalityDetails(locality.public_id);
126
+ } else {
127
+ this.setState({
128
+ error: null,
129
+ selectedLocality: null,
130
+ });
231
131
  }
232
- case "premise": {
233
- shippingAddress2 = component.long_name;
234
- break;
132
+ };
133
+
134
+ getHighlightedLocalityDesc = (locality) => {
135
+ let { description } = locality;
136
+
137
+ if (locality.matched_substrings && locality.matched_substrings.description) {
138
+ for (let j = locality.matched_substrings.description.length - 1; j >= 0; j--) {
139
+ const match = locality.matched_substrings.description[j];
140
+ description = `${description.substring(
141
+ 0,
142
+ match.offset
143
+ )}<span class="localities-matched">${description.substring(
144
+ match.offset,
145
+ match.offset + match.length
146
+ )}</span>${description.substring(match.offset + match.length)}`;
147
+ }
235
148
  }
236
- default:
237
- break;
238
- }
239
- });
149
+ // eslint-disable-next-line react/no-danger
150
+ return <div dangerouslySetInnerHTML={{ __html: description }} />;
151
+ };
240
152
 
241
- return (
242
- <div className="demo--localities--uk__formcontainer">
243
- {!hasComponents && (
244
- // eslint-disable-next-line jsx-a11y/interactive-supports-focus
245
- <div
246
- role="button"
247
- className="overlay"
248
- onClick={() => {
249
- this.inputRef.current.focus();
250
- }}
251
- />
252
- )}
253
- <Input
254
- label="Apartment, unit, suite, or floor #"
255
- placeholder="Apartment, unit, suite, or floor #"
256
- value={shippingAddress2}
257
- onChange={() => {}}
258
- />
259
- <Input
260
- label="Street number, street name"
261
- placeholder="Street number, street name"
262
- value={shippingAddress}
263
- onChange={() => {}}
264
- />
265
- <Input
266
- label="City"
267
- value={locality}
268
- placeholder="City"
269
- onChange={() => {}}
270
- disabled
271
- />
272
- <div className="demo__input-container--inline">
273
- <Input
274
- className="fullw"
275
- label="State/Province"
276
- placeholder="State/Province"
277
- value={state}
278
- onChange={() => {}}
279
- />
280
- <Input
281
- className="fullw"
282
- label="Postal code"
283
- placeholder="Postal code"
284
- value={postcode}
285
- onChange={() => {}}
286
- />
287
- </div>
288
- <Input
289
- label="Country/Region"
290
- placeholder="Country/Region"
291
- value={country}
292
- onChange={() => {}}
293
- />
294
- </div>
295
- );
296
- };
153
+ renderHeaderFilters = () => {
154
+ const inputFilter = {
155
+ label: tr('Type in a UK address '),
156
+ component: (
157
+ <LocalitiesAutocomplete
158
+ inputRef={this.inputRef}
159
+ woosmapKey={Constants.woosmapKey}
160
+ placeholder="Type in an address"
161
+ defaultLocality={this.defaultOrigin}
162
+ language="en"
163
+ components="country:gb|country:je|country:gg|country:im"
164
+ types="address"
165
+ callback={this.selectLocality}
166
+ />
167
+ ),
168
+ };
169
+ return [inputFilter];
170
+ };
171
+
172
+ renderFooterFilters = () => [];
297
173
 
298
- render() {
299
- const { localities, error, selectedLocality } = this.state;
300
- return (
301
- <Demo
302
- noheader
303
- id="localities-demo-uk"
304
- className="demo--localities--uk"
305
- footerFilters={this.renderFooterFilters()}
306
- headerFilters={this.renderHeaderFilters()}
307
- request={selectedLocality ? this.requestDetailsUrl : this.requestUrl}
308
- params={this.getRequestparams()}
309
- referer="http://localhost/"
310
- response={
311
- error || selectedLocality ? { result: selectedLocality } : localities
174
+ renderAddress = () => {
175
+ const { selectedLocality } = this.state;
176
+ let addressComponents = [];
177
+ const hasComponents = selectedLocality && selectedLocality.address_components;
178
+ if (hasComponents) {
179
+ addressComponents = selectedLocality.address_components;
312
180
  }
313
- result={this.renderAddress()}
314
- />
315
- );
316
- }
181
+ let shippingAddress = '';
182
+ let shippingAddress2 = '';
183
+ let postcode = '';
184
+ let locality = '';
185
+ let state = '';
186
+ let country = '';
187
+ addressComponents.forEach((component) => {
188
+ const [componentType] = component.types;
189
+ switch (componentType) {
190
+ case 'street_number': {
191
+ shippingAddress = `${component.long_name} ${shippingAddress}`;
192
+ break;
193
+ }
194
+ case 'route': {
195
+ shippingAddress += component.short_name;
196
+ break;
197
+ }
198
+ case 'postal_codes': {
199
+ postcode = `${component.long_name}${postcode}`;
200
+ break;
201
+ }
202
+ case 'postal_code_suffix': {
203
+ postcode = `${postcode}-${component.long_name}`;
204
+ break;
205
+ }
206
+ case 'locality':
207
+ locality = component.long_name;
208
+ break;
209
+
210
+ case 'state': {
211
+ state = component.long_name;
212
+ break;
213
+ }
214
+ case 'administrative_area_level_1': {
215
+ state = component.long_name;
216
+ break;
217
+ }
218
+ case 'country': {
219
+ country = component.long_name;
220
+ break;
221
+ }
222
+ case 'premise': {
223
+ shippingAddress2 = component.long_name;
224
+ break;
225
+ }
226
+ default:
227
+ break;
228
+ }
229
+ });
230
+
231
+ return (
232
+ <div className="demo--localities--uk__formcontainer">
233
+ {!hasComponents && (
234
+ // eslint-disable-next-line jsx-a11y/interactive-supports-focus
235
+ <div
236
+ role="button"
237
+ className="overlay"
238
+ onClick={() => {
239
+ this.inputRef.current.focus();
240
+ }}
241
+ />
242
+ )}
243
+ <Input
244
+ label="Apartment, unit, suite, or floor #"
245
+ placeholder="Apartment, unit, suite, or floor #"
246
+ value={shippingAddress2}
247
+ onChange={() => {}}
248
+ />
249
+ <Input
250
+ label="Street number, street name"
251
+ placeholder="Street number, street name"
252
+ value={shippingAddress}
253
+ onChange={() => {}}
254
+ />
255
+ <Input label="City" value={locality} placeholder="City" onChange={() => {}} disabled />
256
+ <div className="demo__input-container--inline">
257
+ <Input
258
+ className="fullw"
259
+ label="State/Province"
260
+ placeholder="State/Province"
261
+ value={state}
262
+ onChange={() => {}}
263
+ />
264
+ <Input
265
+ className="fullw"
266
+ label="Postal code"
267
+ placeholder="Postal code"
268
+ value={postcode}
269
+ onChange={() => {}}
270
+ />
271
+ </div>
272
+ <Input label="Country/Region" placeholder="Country/Region" value={country} onChange={() => {}} />
273
+ </div>
274
+ );
275
+ };
276
+
277
+ render() {
278
+ const { localities, error, selectedLocality } = this.state;
279
+ return (
280
+ <Demo
281
+ noheader
282
+ id="localities-demo-uk"
283
+ className="demo--localities--uk"
284
+ footerFilters={this.renderFooterFilters()}
285
+ headerFilters={this.renderHeaderFilters()}
286
+ request={selectedLocality ? this.requestDetailsUrl : this.requestUrl}
287
+ params={this.getRequestparams()}
288
+ referer="http://localhost/"
289
+ response={error || selectedLocality ? { result: selectedLocality } : localities}
290
+ result={this.renderAddress()}
291
+ />
292
+ );
293
+ }
317
294
  }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import LocalitiesUKAddressDemo from '@/components/Demo/LocalitiesUKAddressDemo';
2
+ import LocalitiesUKAddressDemo from './LocalitiesUKAddressDemo';
3
3
 
4
4
  const Story = {
5
5
  title: 'demo/LocalitiesUKAddress',