@woosmap/ui 4.107.0 → 4.107.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.
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding">
4
+ <file url="PROJECT" charset="UTF-8" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,18 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
+ <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
6
+ <option name="ignoredPackages">
7
+ <value>
8
+ <list size="4">
9
+ <item index="0" class="java.lang.String" itemvalue="Fabric" />
10
+ <item index="1" class="java.lang.String" itemvalue="PyYAML" />
11
+ <item index="2" class="java.lang.String" itemvalue="Jinja2" />
12
+ <item index="3" class="java.lang.String" itemvalue="github3.py" />
13
+ </list>
14
+ </value>
15
+ </option>
16
+ </inspection_tool>
17
+ </profile>
18
+ </component>
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <settings>
3
+ <option name="USE_PROJECT_PROFILE" value="false" />
4
+ <version value="1.0" />
5
+ </settings>
6
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="EslintConfiguration">
4
+ <option name="fix-on-save" value="true" />
5
+ </component>
6
+ </project>
package/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
4
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/ui.iml" filepath="$PROJECT_DIR$/.idea/ui.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="PrettierConfiguration">
4
+ <option name="myRunOnReformat" value="true" />
5
+ </component>
6
+ </project>
package/.idea/ui.iml ADDED
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$" />
5
+ <orderEntry type="inheritedJdk" />
6
+ <orderEntry type="sourceFolder" forTests="false" />
7
+ </component>
8
+ <component name="TemplatesService">
9
+ <option name="TEMPLATE_FOLDERS">
10
+ <list>
11
+ <option value="$MODULE_DIR$/node_modules/@storybook/core/dist/server/templates" />
12
+ </list>
13
+ </option>
14
+ </component>
15
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@woosmap/ui",
3
- "version": "4.107.0",
3
+ "version": "4.107.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/WebGeoServices/ui.git"
@@ -0,0 +1,317 @@
1
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
2
+ import axios from 'axios';
3
+ import cl from 'classnames';
4
+ import React, { Component } from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import Demo from './SkeletonDemo';
7
+ import Input from '../Input/Input';
8
+ import Button from '../Button/Button';
9
+ import ButtonGroup from '../Button/ButtonGroup';
10
+ import Constants from '../../Constants';
11
+ import { tr } from '../utils/locale';
12
+ import markerIcon from '../../images/marker.png';
13
+ import markerIconAlt from '../../images/marker-alt.png';
14
+ import { createWoosmapMap } from '../Map/drawOnMap';
15
+
16
+ const languages = [
17
+ { value: 'fr', label: 'French' },
18
+ { value: 'en', label: 'English' },
19
+ { value: 'es', label: 'Spanish' },
20
+ { value: 'it', label: 'Italian' },
21
+ { value: 'de', label: 'German' },
22
+ { value: 'nl', label: 'Dutch' },
23
+ ];
24
+
25
+ export default class W3WDemo extends Component {
26
+ constructor(props) {
27
+ super(props);
28
+ const lang = (typeof window === 'object' && (navigator.language || navigator.userLanguage)) || 'gb';
29
+ const defaultLang = languages.find((item) => lang.startsWith(item.value));
30
+ this.state = {
31
+ w3w: null,
32
+ selectedAddress: null,
33
+ error: null,
34
+ input: '///walnuts.octopus.mount',
35
+ language: (defaultLang || languages[1]).value,
36
+ suggestions: null,
37
+ };
38
+
39
+ this.mounted = true;
40
+ this.map = null;
41
+ this.markers = [];
42
+ this.viewport = null;
43
+ this.baseRequestUrl = 'https://develop-api.woosmap.com/what3words/';
44
+ this.demoRef = React.createRef();
45
+ this.overlay = null;
46
+ }
47
+
48
+ componentDidMount() {
49
+ this.displayMap();
50
+ }
51
+
52
+ componentWillUnmount() {
53
+ this.mounted = false;
54
+ }
55
+
56
+ requestW3W = (words) => {
57
+ axios
58
+ .get(`${this.baseRequestUrl}convert-to-address`, {
59
+ params: this.getRequestparams({ words }),
60
+ })
61
+ .then((response) => {
62
+ if (this.mounted) {
63
+ const selectedAddress = response.data.results.length > 0 ? response.data.results[0] : null;
64
+ this.setState(
65
+ {
66
+ w3w: response.data,
67
+ error: null,
68
+ },
69
+ () => this.selectAddress(selectedAddress)
70
+ );
71
+ }
72
+ })
73
+ .catch((error) => {
74
+ const errorResult = (error && error.response && error.response.data) || 'Unhandled error';
75
+ this.setState({ error: errorResult });
76
+ });
77
+ };
78
+
79
+ autosuggestW3W = () => {
80
+ const { input } = this.state;
81
+ axios
82
+ .get(`${this.baseRequestUrl}autosuggest`, {
83
+ params: this.getRequestparams({ input }),
84
+ })
85
+ .then((response) => {
86
+ if (this.mounted) {
87
+ this.setState({
88
+ w3w: null,
89
+ suggestions: response.data,
90
+ error: null,
91
+ });
92
+ }
93
+ })
94
+ .catch((error) => {
95
+ const errorResult = (error && error.response && error.response.data) || 'Unhandled error';
96
+ this.setState({ error: errorResult });
97
+ });
98
+ };
99
+
100
+ getRequestparams = (input) => {
101
+ const { language } = this.state;
102
+ return {
103
+ key: 'woos-0efb08b8-9072-3717-8dfb-a9c776c7ada9',
104
+ language,
105
+ ...input,
106
+ };
107
+ };
108
+
109
+ selectAddress = (address) => {
110
+ this.setState({ selectedAddress: address }, this.displayOnMap);
111
+ };
112
+
113
+ // eslint-disable-next-line sonarjs/cognitive-complexity
114
+ displayOnMap = () => {
115
+ const { w3w, selectedAddress } = this.state;
116
+ if (this.map) {
117
+ if (this.markers.length > 0) {
118
+ this.markers.forEach((marker) => marker.setMap(null));
119
+ this.marker = [];
120
+ }
121
+ w3w.results.forEach((address) => {
122
+ if (address.geometry.location) {
123
+ const marker = new window.woosmap.map.Marker({
124
+ icon: {
125
+ url: address === selectedAddress ? markerIconAlt : markerIcon,
126
+ scaledSize: { height: 46, width: 30 },
127
+ },
128
+ position: address.geometry.location,
129
+ map: this.map,
130
+ });
131
+ this.markers.push(marker);
132
+ marker.addListener('click', () => {
133
+ this.markers.forEach((_marker) => {
134
+ _marker.setIcon({
135
+ url: marker === _marker ? markerIconAlt : markerIcon,
136
+ scaledSize: { height: 46, width: 30 },
137
+ });
138
+ });
139
+ this.setState({ selectedAddress: address });
140
+ });
141
+
142
+ this.map.setCenter(address.geometry.location);
143
+ this.map.setZoom(18);
144
+ }
145
+ });
146
+ }
147
+ };
148
+
149
+ renderAutocompleteList = () => {
150
+ const { w3w, suggestions } = this.state;
151
+ if (w3w) {
152
+ const result = w3w.results.map((address) => {
153
+ const { selectedAddress } = this.state;
154
+ return (
155
+ <li key={address.public_id}>
156
+ <Button
157
+ type="link-flex"
158
+ label={address.formatted_address}
159
+ active={selectedAddress === address}
160
+ onClick={() => this.selectAddress(address)}
161
+ />
162
+ </li>
163
+ );
164
+ });
165
+ if (result.length === 0) {
166
+ return (
167
+ <div className="demo__results__content__action">
168
+ {suggestions && (
169
+ <Button
170
+ icon="arrow-left"
171
+ type="secondary"
172
+ size="mini"
173
+ label={tr('Back')}
174
+ onClick={() => this.setState({ w3w: null })}
175
+ />
176
+ )}
177
+ <div className="demo__empty">{tr('No address found for this location')}</div>
178
+ </div>
179
+ );
180
+ }
181
+ return (
182
+ <div className="demo__results__content__action">
183
+ {suggestions && (
184
+ <Button
185
+ icon="arrow-left"
186
+ type="secondary"
187
+ size="mini"
188
+ label={tr('Back')}
189
+ onClick={() => this.setState({ w3w: null })}
190
+ />
191
+ )}
192
+ <ul>{result}</ul>
193
+ </div>
194
+ );
195
+ }
196
+ if (suggestions) {
197
+ const result = suggestions.suggestions.map((suggestion) => (
198
+ <li key={`sugg_${suggestion.words}`}>
199
+ <button
200
+ type="button"
201
+ className="btn btn--link-flex btn--two-lines"
202
+ onClick={() => this.requestW3W(suggestion.words)}
203
+ >
204
+ <span>{suggestion.nearestPlace}</span>
205
+ <strong>{suggestion.words}</strong>
206
+ </button>
207
+ </li>
208
+ ));
209
+ if (result.length === 0) {
210
+ return <div className="demo__empty">{tr('No locality found')}</div>;
211
+ }
212
+ return <ul>{result}</ul>;
213
+ }
214
+
215
+ return <div className="demo__empty">{tr('No locality found')}</div>;
216
+ };
217
+
218
+ displayMap = () => {
219
+ if (this.timeoutMap) {
220
+ clearTimeout(this.timeoutMap);
221
+ }
222
+
223
+ if (window.woosmap && window.woosmap.map && this.demoRef.current) {
224
+ window.woosmap.map.config.setApiKey(Constants.woosmapKey);
225
+ this.map = createWoosmapMap(this.demoRef.current.getMap());
226
+ const { input } = this.state;
227
+ this.requestW3W(input);
228
+ } else {
229
+ this.timeoutMap = setTimeout(this.displayMap, 300);
230
+ }
231
+ };
232
+
233
+ renderHeaderFilters = () => {
234
+ const { input } = this.state;
235
+ const { usecaseFilter } = this.props;
236
+ const inputFilter = {
237
+ label: tr('Type in '),
238
+ component: (
239
+ <Input
240
+ value={input}
241
+ autocomplete={false}
242
+ placeholder={tr('Type a locality name...')}
243
+ onChange={(e) => {
244
+ let { value } = e.target;
245
+ if (value.indexOf('///') !== 0) {
246
+ value = `///${value.replaceAll('/', '')}`;
247
+ }
248
+ this.setState({ input: value }, this.autosuggestW3W);
249
+ }}
250
+ />
251
+ ),
252
+ };
253
+ return [usecaseFilter, inputFilter];
254
+ };
255
+
256
+ renderFooterFilters = () => {
257
+ const { language, input } = this.state;
258
+ const filterCountries = {
259
+ label: tr('Response language'),
260
+ component: (
261
+ <ButtonGroup className="language" isLight>
262
+ {languages.map((item) => (
263
+ <Button
264
+ size="small"
265
+ type="group"
266
+ key={item.value}
267
+ active={language === item.value}
268
+ onClick={() => {
269
+ this.setState({ language: item.value }, () => this.requestW3W(input));
270
+ }}
271
+ >
272
+ <span className={cl('flag', `flag-${item.value}`)} title={item.label} />
273
+ </Button>
274
+ ))}
275
+ </ButtonGroup>
276
+ ),
277
+ };
278
+ return [filterCountries];
279
+ };
280
+
281
+ render() {
282
+ const { w3w, error } = this.state;
283
+ const { noheader, headerLabels, subHeader } = this.props;
284
+ return (
285
+ <Demo
286
+ id="w3w-demo"
287
+ header={headerLabels}
288
+ subHeader={subHeader}
289
+ docLink="https://developers.woosmap.com/products/w3w/get-started/"
290
+ className="demo--w3w"
291
+ footerFilters={this.renderFooterFilters()}
292
+ headerFilters={this.renderHeaderFilters()}
293
+ request={this.requestUrl}
294
+ noheader={noheader}
295
+ params={this.getRequestparams()}
296
+ referer="http://localhost/"
297
+ response={error || w3w}
298
+ result={this.renderAutocompleteList()}
299
+ withMap
300
+ ref={this.demoRef}
301
+ />
302
+ );
303
+ }
304
+ }
305
+
306
+ W3WDemo.defaultProps = {
307
+ noheader: false,
308
+ headerLabels: {},
309
+ usecaseFilter: null,
310
+ subHeader: null,
311
+ };
312
+ W3WDemo.propTypes = {
313
+ noheader: PropTypes.bool,
314
+ headerLabels: PropTypes.object,
315
+ usecaseFilter: PropTypes.object,
316
+ subHeader: PropTypes.object,
317
+ };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import W3WDemo from './W3WDemo';
3
+
4
+ const Story = {
5
+ title: 'demo/W3WDemo',
6
+ component: W3WDemo,
7
+ };
8
+
9
+ export default Story;
10
+
11
+ const TemplateW3W = () => <W3WDemo />;
12
+ export const Localities = TemplateW3W.bind({});
@@ -22,7 +22,6 @@
22
22
  box-shadow 0 .3rem 1rem rgba($secondary, .15)
23
23
  .demo--merchant &
24
24
  border .1rem solid $light
25
-
26
25
  &__showcase
27
26
  &__data
28
27
  display flex
@@ -90,6 +89,53 @@
90
89
  padding $demoPadding
91
90
  background-color $light
92
91
  overflow-y auto
92
+ .demo--w3w &
93
+ mbib(1.6)
94
+ li
95
+ margin-bottom 1.4rem
96
+ .btn
97
+ color $primary
98
+ &.active
99
+ &:hover
100
+ font-weight bold
101
+ color $logo5 !important
102
+ &--link-flex
103
+ text-decoration none
104
+ .btn__label
105
+ line-height 1.4
106
+ &--two-lines
107
+ &.btn
108
+ mbib(.6)
109
+ color $dark
110
+ display flex
111
+ flex-direction column
112
+ align-items flex-start
113
+ strong
114
+ font-weight 600
115
+ color $primary
116
+ &.active
117
+ &:hover
118
+ font-weight 400
119
+ color $logo5
120
+ strong
121
+ font-weight 600
122
+ color $logo5
123
+
124
+ &__action
125
+ mbib(1.6)
126
+ display flex
127
+ justify-content space-between
128
+ align-items flex-start
129
+ flex-direction column
130
+ .btn
131
+ .icon
132
+ fill none !important
133
+ stroke $dark !important
134
+ &:hover
135
+ .icon
136
+ stroke $light !important
137
+ &__empty
138
+ color $error
93
139
  &__code
94
140
  inputFont()
95
141
  width 100%
package/src/index.js CHANGED
@@ -49,6 +49,7 @@ export { default as withClickOutside } from './components/withClickOutside/withC
49
49
  export { default as withFormValidation } from './components/withFormValidation/withFormValidation';
50
50
  export { default as Marker } from './components/Map/Marker';
51
51
  export { default as LocalitiesDemo } from './components/Demo/LocalitiesDemo';
52
+ export { default as W3WDemo } from './components/Demo/W3WDemo';
52
53
  export { default as LocalitiesCheckoutUKDemo } from './components/Demo/LocalitiesUKAddressDemo';
53
54
  export { default as LocalitiesCheckoutFRDemo } from './components/Demo/LocalitiesFRAddressDemo';
54
55
  export { default as LocalitiesAddressDemo } from './components/Demo/LocalitiesAddressDemo';
@@ -372,7 +372,11 @@
372
372
  trans()
373
373
  .btn__label
374
374
  trans()
375
-
375
+ &--link-flex
376
+ &.active
377
+ color $primary
378
+ .icon
379
+ stroke $primary
376
380
  &--has-icon
377
381
  &:not(.btn--icon):not(.btn--link):not(.btn--link-primary):not(.btn--link-info):not(.btn--link-flex):not(.btn--link-flex-info):not(.btn--loading):not(.btn--mini):not(.btn--small):not(.btn--large):not(.btn--dropdown-item):not(.btn--tab):not(.btn--sidebar-link):not(.btn--icon-right)
378
382
  padding 0 $padding 0 $padding - .6
@@ -675,7 +679,7 @@
675
679
  .icon
676
680
  margin-right .4rem
677
681
  &.btn--has-icon
678
- padding-left $padding - .6
682
+ padding-left $padding - .8
679
683
  &.btn--loading
680
684
  padding-left $padding - .3
681
685
  disableHoverEffect()
@@ -619,6 +619,21 @@
619
619
  disableHoverEffect()
620
620
  .icon
621
621
  sq(3.2)
622
+ &--mini
623
+ buttonMini()
624
+ &:not(.btn--custom-icon-size)
625
+ .icon
626
+ sq(1.6)
627
+ &:not(.btn--icon)
628
+ .icon
629
+ margin-right .4rem
630
+ &.btn--has-icon
631
+ padding-left $padding - 1.6
632
+ &.btn--loading
633
+ padding-left $padding - .3
634
+ disableHoverEffect()
635
+ .icon
636
+ sq(1.6)
622
637
  &--group
623
638
  btn()
624
639
  color $secondary-medium40
@@ -137,6 +137,18 @@ buttonLarge()
137
137
  &.btn--link-flex
138
138
  height auto
139
139
  line-height unset
140
+ buttonMini()
141
+ height $buttonHeightMini
142
+ font-size $buttonFontSizeMini
143
+ line-height $buttonLineHeightMini
144
+ padding $buttonPaddingMini
145
+ &.btn--no-label
146
+ &.btn--link
147
+ &.btn--link-primary
148
+ &.btn--link-info
149
+ &.btn--link-flex
150
+ height auto
151
+ line-height unset
140
152
 
141
153
  fullw()
142
154
  width 100%
@@ -86,8 +86,8 @@ $buttonFontSizeSmall = $fontSize - .1
86
86
  $buttonLineHeightSmall = $buttonFontSizeSmall * 2
87
87
 
88
88
  $buttonHeightMini = $buttonHeight - 1
89
- $buttonPaddingMini = 0 $padding - .4 0 $padding - .4
90
- $buttonFontSizeMini = $fontSizeSmall
89
+ $buttonPaddingMini = 0 $padding - 1.2 0 $padding - 1.2
90
+ $buttonFontSizeMini = $fontSizeSmall - .4
91
91
  $buttonLineHeightMini = $buttonFontSizeMini * 2
92
92
 
93
93
  $buttonHeightNano = $buttonHeight - 1.4
package/src/website.js CHANGED
@@ -11,6 +11,7 @@ export { default as Popover } from './components/Popover/Popover';
11
11
  export { default as Select } from './components/Select/Select';
12
12
 
13
13
  export { default as LocalitiesDemo } from './components/Demo/LocalitiesDemo';
14
+ export { default as W3WDemo } from './components/Demo/W3WDemo';
14
15
  export { default as LocalitiesCheckoutUKDemo } from './components/Demo/LocalitiesUKAddressDemo';
15
16
  export { default as LocalitiesCheckoutFRDemo } from './components/Demo/LocalitiesFRAddressDemo';
16
17
  export { default as LocalitiesAddressDemo } from './components/Demo/LocalitiesAddressDemo';