react-spatial 1.5.2 → 1.5.3
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/.github/workflows/conventional-pr-title.yml +21 -0
- package/.github/workflows/main.yml +28 -0
- package/.husky/commit-msg +4 -0
- package/.husky/post-checkout +4 -0
- package/.husky/post-merge +4 -0
- package/.husky/post-rebase +4 -0
- package/.husky/pre-commit +4 -0
- package/.nvmrc +1 -0
- package/.whitesource +8 -0
- package/CHANGELOG.md +65 -0
- package/DEVELOP.md +113 -0
- package/__mocks__/mapbox-gl.js +11 -0
- package/__mocks__/resize-observer-polyfill.js +9 -0
- package/babel.config.js +3 -0
- package/commitlint.config.js +1 -0
- package/data/topic1.js +119 -0
- package/data/topic2.js +28 -0
- package/doc/README.md +21 -0
- package/doc/doc-config.json +4 -0
- package/package.json +4 -3
- package/pull_request_template.md +16 -0
- package/renovate.json +4 -0
- package/scripts/read-pkg-json.js +17 -0
- package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.js +322 -0
- package/src/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +69 -0
- package/src/components/BaseLayerSwitcher/README.md +61 -0
- package/src/components/BaseLayerSwitcher/__snapshots__/BaseLayerSwitcher.test.js.snap +88 -0
- package/src/components/BaseLayerSwitcher/index.js +1 -0
- package/src/components/BasicMap/BasicMap.js +413 -0
- package/src/components/BasicMap/BasicMap.test.js +281 -0
- package/src/components/BasicMap/README.md +18 -0
- package/src/components/BasicMap/index.js +1 -0
- package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.js +320 -93
- package/src/components/CanvasSaveButton/CanvasSaveButton.test.js +148 -0
- package/src/components/CanvasSaveButton/README.md +76 -0
- package/src/components/CanvasSaveButton/__snapshots__/CanvasSaveButton.test.js.snap +76 -0
- package/src/components/CanvasSaveButton/index.js +1 -0
- package/src/components/Copyright/Copyright.js +89 -0
- package/src/components/Copyright/Copyright.test.js +134 -0
- package/src/components/Copyright/README.md +36 -0
- package/src/components/Copyright/index.js +1 -0
- package/src/components/FeatureExportButton/FeatureExportButton.js +118 -0
- package/src/components/FeatureExportButton/FeatureExportButton.test.js +417 -0
- package/src/components/FeatureExportButton/README.md +76 -0
- package/src/components/FeatureExportButton/__snapshots__/FeatureExportButton.test.js.snap +67 -0
- package/src/components/FeatureExportButton/index.js +1 -0
- package/src/components/FitExtent/FitExtent.js +62 -0
- package/src/components/FitExtent/FitExtent.test.js +48 -0
- package/src/components/FitExtent/README.md +34 -0
- package/src/components/FitExtent/__snapshots__/FitExtent.test.js.snap +13 -0
- package/src/components/FitExtent/index.js +1 -0
- package/{components → src/components}/Geolocation/Geolocation.js +144 -61
- package/src/components/Geolocation/Geolocation.test.js +267 -0
- package/src/components/Geolocation/README.md +25 -0
- package/src/components/Geolocation/__snapshots__/Geolocation.test.js.snap +92 -0
- package/src/components/Geolocation/index.js +1 -0
- package/src/components/LayerTree/LayerTree.js +487 -0
- package/src/components/LayerTree/LayerTree.test.js +337 -0
- package/src/components/LayerTree/README.md +92 -0
- package/src/components/LayerTree/__snapshots__/LayerTree.test.js.snap +1746 -0
- package/src/components/LayerTree/index.js +1 -0
- package/src/components/MousePosition/MousePosition.js +175 -0
- package/src/components/MousePosition/MousePosition.test.js +132 -0
- package/src/components/MousePosition/README.md +50 -0
- package/src/components/MousePosition/__snapshots__/MousePosition.test.js.snap +76 -0
- package/src/components/MousePosition/index.js +1 -0
- package/src/components/NorthArrow/NorthArrow.js +75 -0
- package/src/components/NorthArrow/NorthArrow.test.js +104 -0
- package/src/components/NorthArrow/README.md +59 -0
- package/src/components/NorthArrow/__snapshots__/NorthArrow.test.js.snap +117 -0
- package/src/components/NorthArrow/index.js +1 -0
- package/src/components/Overlay/Overlay.js +176 -0
- package/src/components/Overlay/Overlay.test.js +149 -0
- package/src/components/Overlay/README.md +59 -0
- package/src/components/Overlay/__snapshots__/Overlay.test.js.snap +9 -0
- package/src/components/Overlay/index.js +1 -0
- package/src/components/Permalink/Permalink.js +326 -0
- package/src/components/Permalink/Permalink.test.js +285 -0
- package/src/components/Permalink/README.md +105 -0
- package/src/components/Permalink/index.js +1 -0
- package/{components → src/components}/Popup/Popup.js +165 -55
- package/src/components/Popup/Popup.test.js +307 -0
- package/src/components/Popup/README.md +93 -0
- package/src/components/Popup/__snapshots__/Popup.test.js.snap +180 -0
- package/src/components/Popup/index.js +1 -0
- package/src/components/README.md +41 -0
- package/{components → src/components}/ResizeHandler/ResizeHandler.js +50 -15
- package/src/components/ResizeHandler/ResizeHandler.test.js +344 -0
- package/src/components/ResizeHandler/index.js +1 -0
- package/src/components/RouteSchedule/README.md +118 -0
- package/src/components/RouteSchedule/RouteSchedule.js +370 -0
- package/src/components/RouteSchedule/RouteSchedule.test.js +113 -0
- package/src/components/RouteSchedule/__snapshots__/RouteSchedule.test.js.snap +248 -0
- package/src/components/RouteSchedule/index.js +1 -0
- package/src/components/ScaleLine/README.md +29 -0
- package/src/components/ScaleLine/ScaleLine.js +50 -0
- package/src/components/ScaleLine/ScaleLine.test.js +30 -0
- package/src/components/ScaleLine/__snapshots__/ScaleLine.test.js.snap +7 -0
- package/src/components/ScaleLine/index.js +1 -0
- package/src/components/StopsFinder/README.md +50 -0
- package/src/components/StopsFinder/StopsFinder.js +284 -0
- package/src/components/StopsFinder/StopsFinder.test.js +17 -0
- package/src/components/StopsFinder/StopsFinderOption.js +61 -0
- package/src/components/StopsFinder/__snapshots__/StopsFinder.test.js.snap +133 -0
- package/src/components/StopsFinder/index.js +1 -0
- package/src/components/Zoom/README.md +25 -0
- package/src/components/Zoom/Zoom.js +180 -0
- package/src/components/Zoom/Zoom.test.js +141 -0
- package/src/components/Zoom/__snapshots__/Zoom.test.js.snap +201 -0
- package/src/components/Zoom/index.js +1 -0
- package/{propTypes.js → src/propTypes.js} +16 -12
- package/{setupTests.js → src/setupTests.js} +1 -1
- package/src/styleguidist/ComponentsList.js +52 -0
- package/src/styleguidist/StyleGuide.js +277 -0
- package/src/styleguidist/styleguidist.css +38 -0
- package/src/utils/GlobalsForOle.js +99 -0
- package/src/utils/KML.js +594 -0
- package/src/utils/KML.test.js +337 -0
- package/src/utils/KMLFormat.js +100 -0
- package/src/utils/KMLFormat.test.js +50 -0
- package/{utils → src/utils}/Styles.js +20 -14
- package/src/utils/__snapshots__/KML.test.js.snap.KML-readFeatures()-and-writeFeatures()-should-read-and-write-lineDash-and-fillPattern-style-for-polygon.canvas-image.png +0 -0
- package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-2-(cross)-color-and-(light-blue)-opacity.canvas-image.png +0 -0
- package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-3-(diagonal-line-from-bottom-left-tot-top-right)-with-color-(light-blue)-and-opacity.canvas-image.png +0 -0
- package/src/utils/__snapshots__/getPolygonPattern.test.js.snap.getPolygonPattern()-render-pattern-4-(diagonal-line-from-top-left-to-bottom-right)-with-color-(light-blue)-and-opacity.canvas-image.png +0 -0
- package/{utils → src/utils}/getPolygonPattern.js +34 -6
- package/src/utils/getPolygonPattern.test.js +61 -0
- package/src/utils/timeUtils.js +52 -0
- package/src/utils/timeUtils.test.js +30 -0
- package/styleguide.config.js +251 -0
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +0 -231
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +0 -7
- package/components/BaseLayerSwitcher/index.js +0 -1
- package/components/BaseLayerSwitcher/index.js.map +0 -7
- package/components/BasicMap/BasicMap.js +0 -278
- package/components/BasicMap/BasicMap.js.map +0 -7
- package/components/BasicMap/index.js +0 -1
- package/components/BasicMap/index.js.map +0 -7
- package/components/CanvasSaveButton/CanvasSaveButton.js.map +0 -7
- package/components/CanvasSaveButton/index.js +0 -1
- package/components/CanvasSaveButton/index.js.map +0 -7
- package/components/Copyright/Copyright.js +0 -55
- package/components/Copyright/Copyright.js.map +0 -7
- package/components/Copyright/index.js +0 -1
- package/components/Copyright/index.js.map +0 -7
- package/components/FeatureExportButton/FeatureExportButton.js +0 -62
- package/components/FeatureExportButton/FeatureExportButton.js.map +0 -7
- package/components/FeatureExportButton/index.js +0 -1
- package/components/FeatureExportButton/index.js.map +0 -7
- package/components/FitExtent/FitExtent.js +0 -32
- package/components/FitExtent/FitExtent.js.map +0 -7
- package/components/FitExtent/index.js +0 -1
- package/components/FitExtent/index.js.map +0 -7
- package/components/Geolocation/Geolocation.js.map +0 -7
- package/components/Geolocation/index.js +0 -1
- package/components/Geolocation/index.js.map +0 -7
- package/components/LayerTree/LayerTree.js +0 -278
- package/components/LayerTree/LayerTree.js.map +0 -7
- package/components/LayerTree/index.js +0 -1
- package/components/LayerTree/index.js.map +0 -7
- package/components/MousePosition/MousePosition.js +0 -110
- package/components/MousePosition/MousePosition.js.map +0 -7
- package/components/MousePosition/index.js +0 -1
- package/components/MousePosition/index.js.map +0 -7
- package/components/NorthArrow/NorthArrow.js +0 -43
- package/components/NorthArrow/NorthArrow.js.map +0 -7
- package/components/NorthArrow/index.js +0 -1
- package/components/NorthArrow/index.js.map +0 -7
- package/components/Overlay/Overlay.js +0 -122
- package/components/Overlay/Overlay.js.map +0 -7
- package/components/Overlay/index.js +0 -1
- package/components/Overlay/index.js.map +0 -7
- package/components/Permalink/Permalink.js +0 -206
- package/components/Permalink/Permalink.js.map +0 -7
- package/components/Permalink/index.js +0 -1
- package/components/Permalink/index.js.map +0 -7
- package/components/Popup/Popup.js.map +0 -7
- package/components/Popup/index.js +0 -1
- package/components/Popup/index.js.map +0 -7
- package/components/ResizeHandler/ResizeHandler.js.map +0 -7
- package/components/ResizeHandler/index.js +0 -1
- package/components/ResizeHandler/index.js.map +0 -7
- package/components/RouteSchedule/RouteSchedule.js +0 -220
- package/components/RouteSchedule/RouteSchedule.js.map +0 -7
- package/components/RouteSchedule/index.js +0 -1
- package/components/RouteSchedule/index.js.map +0 -7
- package/components/ScaleLine/ScaleLine.js +0 -32
- package/components/ScaleLine/ScaleLine.js.map +0 -7
- package/components/ScaleLine/index.js +0 -1
- package/components/ScaleLine/index.js.map +0 -7
- package/components/StopsFinder/StopsFinder.js +0 -210
- package/components/StopsFinder/StopsFinder.js.map +0 -7
- package/components/StopsFinder/StopsFinderOption.js +0 -51
- package/components/StopsFinder/StopsFinderOption.js.map +0 -7
- package/components/StopsFinder/index.js +0 -1
- package/components/StopsFinder/index.js.map +0 -7
- package/components/Zoom/Zoom.js +0 -130
- package/components/Zoom/Zoom.js.map +0 -7
- package/components/Zoom/index.js +0 -1
- package/components/Zoom/index.js.map +0 -7
- package/propTypes.js.map +0 -7
- package/setupTests.js.map +0 -7
- package/utils/GlobalsForOle.js +0 -94
- package/utils/GlobalsForOle.js.map +0 -7
- package/utils/KML.js +0 -412
- package/utils/KML.js.map +0 -7
- package/utils/KMLFormat.js +0 -69
- package/utils/KMLFormat.js.map +0 -7
- package/utils/Styles.js.map +0 -7
- package/utils/getPolygonPattern.js.map +0 -7
- package/utils/timeUtils.js +0 -31
- package/utils/timeUtils.js.map +0 -7
- /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.md.scss +0 -0
- /package/{components → src/components}/BaseLayerSwitcher/BaseLayerSwitcher.scss +0 -0
- /package/{components → src/components}/BasicMap/BasicMap.md.scss +0 -0
- /package/{components → src/components}/CanvasSaveButton/CanvasSaveButton.md.scss +0 -0
- /package/{components → src/components}/Copyright/Copyright.md.scss +0 -0
- /package/{components → src/components}/FeatureExportButton/FeatureExportButton.md.scss +0 -0
- /package/{components → src/components}/FitExtent/FitExtent.md.scss +0 -0
- /package/{components → src/components}/Geolocation/Geolocation.md.scss +0 -0
- /package/{components → src/components}/Geolocation/Geolocation.scss +0 -0
- /package/{components → src/components}/LayerTree/LayerTree.md.scss +0 -0
- /package/{components → src/components}/LayerTree/LayerTree.scss +0 -0
- /package/{components → src/components}/MousePosition/MousePosition.md.scss +0 -0
- /package/{components → src/components}/NorthArrow/NorthArrow.scss +0 -0
- /package/{components → src/components}/Overlay/Overlay.md.scss +0 -0
- /package/{components → src/components}/Overlay/Overlay.scss +0 -0
- /package/{components → src/components}/Permalink/Permalink.md.scss +0 -0
- /package/{components → src/components}/Popup/Popup.md.scss +0 -0
- /package/{components → src/components}/Popup/Popup.scss +0 -0
- /package/{components → src/components}/RouteSchedule/RouteSchedule.md.scss +0 -0
- /package/{components → src/components}/RouteSchedule/RouteSchedule.scss +0 -0
- /package/{components → src/components}/ScaleLine/ScaleLine.scss +0 -0
- /package/{components → src/components}/Zoom/Zoom.md.scss +0 -0
- /package/{components → src/components}/Zoom/Zoom.scss +0 -0
- /package/{images → src/images}/RouteSchedule/firstStation.png +0 -0
- /package/{images → src/images}/RouteSchedule/lastStation.png +0 -0
- /package/{images → src/images}/RouteSchedule/line.png +0 -0
- /package/{images → src/images}/RouteSchedule/station.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.basebright.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.osm.png +0 -0
- /package/{images → src/images}/baselayer/baselayer.travic.png +0 -0
- /package/{images → src/images}/baselayer/open.topo.map.png +0 -0
- /package/{images → src/images}/baselayer/osm.baselayer.hot.png +0 -0
- /package/{images → src/images}/baselayer/osm.baselayer.png +0 -0
- /package/{images → src/images}/favicon.png +0 -0
- /package/{images → src/images}/geops_logo.png +0 -0
- /package/{images → src/images}/geops_logo.svg +0 -0
- /package/{images → src/images}/geops_qr.png +0 -0
- /package/{images → src/images}/mots/bus_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/bus_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/bus_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/bus_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/cable_car_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/ferry_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/funicular_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/gondola_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/rail_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/rail_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/rail_square-grey-01.svg +0 -0
- /package/{images → src/images}/mots/subway_round blue-01.svg +0 -0
- /package/{images → src/images}/mots/subway_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_poi-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_poi-grey-01.svg +0 -0
- /package/{images → src/images}/mots/tram_round-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_round-grey-01.svg +0 -0
- /package/{images → src/images}/mots/tram_square-blue-01.svg +0 -0
- /package/{images → src/images}/mots/tram_square-grey-01.svg +0 -0
- /package/{images → src/images}/northArrow.svg +0 -0
- /package/{images → src/images}/northArrow.url.svg +0 -0
- /package/{images → src/images}/northArrowCircle.svg +0 -0
- /package/{images → src/images}/northArrowCircle.url.svg +0 -0
- /package/{themes → src/themes}/README.md +0 -0
- /package/{themes → src/themes}/default/components.scss +0 -0
- /package/{themes → src/themes}/default/examples.scss +0 -0
- /package/{themes → src/themes}/default/index.scss +0 -0
- /package/{themes → src/themes}/default/mixins.scss +0 -0
- /package/{themes → src/themes}/default/variables.scss +0 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
The following example demonstrates the use of Popup.
|
|
3
|
+
|
|
4
|
+
```jsx
|
|
5
|
+
import React, { useState, useMemo, useCallback } from 'react';
|
|
6
|
+
import { Layer, MapboxLayer} from 'mobility-toolbox-js/ol';
|
|
7
|
+
import VectorLayer from 'ol/layer/Vector';
|
|
8
|
+
import { Map, Feature } from 'ol';
|
|
9
|
+
import Point from 'ol/geom/Point';
|
|
10
|
+
import OSM from 'ol/source/OSM';
|
|
11
|
+
import VectorSource from 'ol/source/Vector';
|
|
12
|
+
import TileGrid from 'ol/tilegrid/TileGrid';
|
|
13
|
+
import { getCenter } from 'ol/extent';
|
|
14
|
+
import { Style, Circle, Fill, Icon } from 'ol/style';
|
|
15
|
+
import BasicMap from 'react-spatial/components/BasicMap';
|
|
16
|
+
import Popup from 'react-spatial/components/Popup';
|
|
17
|
+
|
|
18
|
+
const map = new Map({ controls: [] });
|
|
19
|
+
|
|
20
|
+
const layers = [
|
|
21
|
+
new MapboxLayer({
|
|
22
|
+
url: `https://maps.geops.io/styles/base_dark_v2/style.json?key=${apiKey}`,
|
|
23
|
+
}),
|
|
24
|
+
new Layer({
|
|
25
|
+
olLayer: new VectorLayer({
|
|
26
|
+
source: new VectorSource({
|
|
27
|
+
features: [
|
|
28
|
+
new Feature({
|
|
29
|
+
geometry: new Point([874105.13, 6106172.77]),
|
|
30
|
+
}),
|
|
31
|
+
new Feature({
|
|
32
|
+
geometry: new Point([873105.13, 6106172.77]),
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
}),
|
|
36
|
+
style: new Style({
|
|
37
|
+
image: new Icon({
|
|
38
|
+
anchor: [0.5, 46],
|
|
39
|
+
anchorXUnits: 'fraction',
|
|
40
|
+
anchorYUnits: 'pixels',
|
|
41
|
+
src: 'https://openlayers.org/en/latest/examples/data/icon.png',
|
|
42
|
+
imgSize: [32, 48]
|
|
43
|
+
}),
|
|
44
|
+
}),
|
|
45
|
+
}),
|
|
46
|
+
}),
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function PopupExample() {
|
|
51
|
+
const [featureClicked, setFeatureClicked] = useState();
|
|
52
|
+
|
|
53
|
+
const content = useMemo(() => {
|
|
54
|
+
return featureClicked &&
|
|
55
|
+
featureClicked
|
|
56
|
+
.getGeometry()
|
|
57
|
+
.getCoordinates()
|
|
58
|
+
.toString();
|
|
59
|
+
}, [featureClicked]);
|
|
60
|
+
|
|
61
|
+
const onFeaturesClick = useCallback((features) => {
|
|
62
|
+
setFeatureClicked(features.length ? features[0] : null);
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
const onCloseClick = useCallback(()=> {
|
|
66
|
+
setFeatureClicked(null);
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div className="rs-popup-example">
|
|
71
|
+
<BasicMap
|
|
72
|
+
map={map}
|
|
73
|
+
center={[874105.13, 6106172.77]}
|
|
74
|
+
zoom={17}
|
|
75
|
+
layers={layers}
|
|
76
|
+
onFeaturesClick={onFeaturesClick}
|
|
77
|
+
tabIndex={0}
|
|
78
|
+
/>
|
|
79
|
+
<Popup
|
|
80
|
+
map={map}
|
|
81
|
+
header="Geometry"
|
|
82
|
+
feature={featureClicked}
|
|
83
|
+
onCloseClick={onCloseClick}
|
|
84
|
+
panIntoView
|
|
85
|
+
>
|
|
86
|
+
<div>{content}</div>
|
|
87
|
+
</Popup>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
<PopupExample />;
|
|
93
|
+
```
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Popup should match snapshot with default values. 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="rs-popup"
|
|
6
|
+
style={
|
|
7
|
+
{
|
|
8
|
+
"left": 0,
|
|
9
|
+
"top": 0,
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
>
|
|
13
|
+
<div
|
|
14
|
+
className="rs-popup-container"
|
|
15
|
+
tabIndex=""
|
|
16
|
+
>
|
|
17
|
+
<div
|
|
18
|
+
className="rs-popup-header"
|
|
19
|
+
>
|
|
20
|
+
<div
|
|
21
|
+
aria-label="Close"
|
|
22
|
+
className="rs-popup-close-bt"
|
|
23
|
+
onClick={[Function]}
|
|
24
|
+
onKeyPress={[Function]}
|
|
25
|
+
role="button"
|
|
26
|
+
tabIndex={0}
|
|
27
|
+
title="Close"
|
|
28
|
+
>
|
|
29
|
+
<svg
|
|
30
|
+
fill="currentColor"
|
|
31
|
+
focusable={false}
|
|
32
|
+
height="1em"
|
|
33
|
+
stroke="currentColor"
|
|
34
|
+
strokeWidth="0"
|
|
35
|
+
style={
|
|
36
|
+
{
|
|
37
|
+
"color": undefined,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
viewBox="0 0 24 24"
|
|
41
|
+
width="1em"
|
|
42
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
43
|
+
>
|
|
44
|
+
<path
|
|
45
|
+
d="M0 0h24v24H0z"
|
|
46
|
+
fill="none"
|
|
47
|
+
/>
|
|
48
|
+
<path
|
|
49
|
+
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
|
|
50
|
+
/>
|
|
51
|
+
</svg>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
<div
|
|
55
|
+
className="rs-popup-body"
|
|
56
|
+
>
|
|
57
|
+
<div
|
|
58
|
+
id="foo"
|
|
59
|
+
/>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
exports[`Popup should match snapshot with tabIndex defined. 1`] = `
|
|
66
|
+
<div
|
|
67
|
+
className="rs-popup"
|
|
68
|
+
style={
|
|
69
|
+
{
|
|
70
|
+
"left": 0,
|
|
71
|
+
"top": 0,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
>
|
|
75
|
+
<div
|
|
76
|
+
className="rs-popup-container"
|
|
77
|
+
tabIndex="0"
|
|
78
|
+
>
|
|
79
|
+
<div
|
|
80
|
+
className="rs-popup-header"
|
|
81
|
+
>
|
|
82
|
+
<div
|
|
83
|
+
aria-label="Close"
|
|
84
|
+
className="rs-popup-close-bt"
|
|
85
|
+
onClick={[Function]}
|
|
86
|
+
onKeyPress={[Function]}
|
|
87
|
+
role="button"
|
|
88
|
+
tabIndex={0}
|
|
89
|
+
title="Close"
|
|
90
|
+
>
|
|
91
|
+
<svg
|
|
92
|
+
fill="currentColor"
|
|
93
|
+
focusable={false}
|
|
94
|
+
height="1em"
|
|
95
|
+
stroke="currentColor"
|
|
96
|
+
strokeWidth="0"
|
|
97
|
+
style={
|
|
98
|
+
{
|
|
99
|
+
"color": undefined,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
viewBox="0 0 24 24"
|
|
103
|
+
width="1em"
|
|
104
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
105
|
+
>
|
|
106
|
+
<path
|
|
107
|
+
d="M0 0h24v24H0z"
|
|
108
|
+
fill="none"
|
|
109
|
+
/>
|
|
110
|
+
<path
|
|
111
|
+
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"
|
|
112
|
+
/>
|
|
113
|
+
</svg>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
<div
|
|
117
|
+
className="rs-popup-body"
|
|
118
|
+
>
|
|
119
|
+
<div
|
|
120
|
+
id="bar"
|
|
121
|
+
/>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
`;
|
|
126
|
+
|
|
127
|
+
exports[`Popup should match snapshot without close button. 1`] = `
|
|
128
|
+
<div
|
|
129
|
+
className="rs-popup"
|
|
130
|
+
style={
|
|
131
|
+
{
|
|
132
|
+
"left": 0,
|
|
133
|
+
"top": 0,
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
>
|
|
137
|
+
<div
|
|
138
|
+
className="rs-popup-container"
|
|
139
|
+
tabIndex=""
|
|
140
|
+
>
|
|
141
|
+
<div
|
|
142
|
+
className="rs-popup-header"
|
|
143
|
+
/>
|
|
144
|
+
<div
|
|
145
|
+
className="rs-popup-body"
|
|
146
|
+
>
|
|
147
|
+
<div
|
|
148
|
+
id="bar"
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
`;
|
|
154
|
+
|
|
155
|
+
exports[`Popup should match snapshot without feature 1`] = `null`;
|
|
156
|
+
|
|
157
|
+
exports[`Popup should match snapshot without header. 1`] = `
|
|
158
|
+
<div
|
|
159
|
+
className="rs-popup"
|
|
160
|
+
style={
|
|
161
|
+
{
|
|
162
|
+
"left": 0,
|
|
163
|
+
"top": 0,
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
>
|
|
167
|
+
<div
|
|
168
|
+
className="rs-popup-container"
|
|
169
|
+
tabIndex=""
|
|
170
|
+
>
|
|
171
|
+
<div
|
|
172
|
+
className="rs-popup-body"
|
|
173
|
+
>
|
|
174
|
+
<div
|
|
175
|
+
id="bar"
|
|
176
|
+
/>
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Popup';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Components
|
|
2
|
+
|
|
3
|
+
This folder contains all the components.
|
|
4
|
+
|
|
5
|
+
## Create a new component
|
|
6
|
+
|
|
7
|
+
Each component must have this structure:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
src/
|
|
11
|
+
components/
|
|
12
|
+
MyCategory/
|
|
13
|
+
MyComponent/
|
|
14
|
+
index.js // ES module export.
|
|
15
|
+
MyComponent.js // The JSX component WITHOUT hardcoded classNames !!!!
|
|
16
|
+
MyComponent.test.js // The test file with at least snapshots tests.
|
|
17
|
+
MyComponent.scss // A sass file with default CSS when the main html element of MyComponent uses rs-mycomponent CSS class.
|
|
18
|
+
README.md // The MyComponentExample component of use to display in the doc.
|
|
19
|
+
MyComponent.md.scss // A sass file for the MyComponentExample component used in README.md
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Some rules must be followed:
|
|
23
|
+
|
|
24
|
+
- a component must allow to provide a className to the main html element of the component.
|
|
25
|
+
- a component must be controlled by his parent via props.
|
|
26
|
+
- a component must use `children` property instead of `renderXXX` functions when possible.
|
|
27
|
+
- a component must propagate basic props `<NewComp {...this.props}>` when possible.
|
|
28
|
+
- a component must have tests.
|
|
29
|
+
- a component can provide a translation function using a `t` property.
|
|
30
|
+
- default props must have a value or `undefined` (no `null` otherwise the attribute is created in the snapshot).
|
|
31
|
+
- no redux stuff.
|
|
32
|
+
- no hardcoded `className`, only in default props.
|
|
33
|
+
- no translation library specific stuff.
|
|
34
|
+
|
|
35
|
+
## Create a new component from another
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
yarn cp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
then follow the guide.
|
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
import ReactDOM from
|
|
2
|
-
import { PureComponent, Component } from
|
|
3
|
-
import PropTypes from
|
|
4
|
-
import ResizeObserver from
|
|
1
|
+
import ReactDOM from 'react-dom';
|
|
2
|
+
import { PureComponent, Component } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import ResizeObserver from 'resize-observer-polyfill';
|
|
5
|
+
|
|
5
6
|
const propTypes = {
|
|
6
7
|
observe: PropTypes.oneOfType([
|
|
7
8
|
PropTypes.string,
|
|
8
9
|
PropTypes.node,
|
|
9
10
|
PropTypes.instanceOf(Component),
|
|
10
11
|
PropTypes.shape({ current: PropTypes.node }),
|
|
11
|
-
PropTypes.shape({ current: PropTypes.instanceOf(Component) })
|
|
12
|
+
PropTypes.shape({ current: PropTypes.instanceOf(Component) }),
|
|
12
13
|
]),
|
|
13
14
|
maxHeightBrkpts: PropTypes.objectOf(PropTypes.number),
|
|
14
15
|
maxWidthBrkpts: PropTypes.objectOf(PropTypes.number),
|
|
15
16
|
stylePropHeight: PropTypes.string,
|
|
16
17
|
onResize: PropTypes.func,
|
|
18
|
+
|
|
19
|
+
// This property is used to re-apply the classes, for example when the className of the observed node changes.
|
|
17
20
|
forceUpdate: PropTypes.oneOfType([
|
|
18
21
|
PropTypes.string,
|
|
19
22
|
PropTypes.number,
|
|
20
|
-
PropTypes.bool
|
|
21
|
-
])
|
|
23
|
+
PropTypes.bool,
|
|
24
|
+
]),
|
|
22
25
|
};
|
|
26
|
+
|
|
27
|
+
// Same as bootstrap
|
|
23
28
|
const defaultProps = {
|
|
24
29
|
observe: null,
|
|
25
30
|
maxHeightBrkpts: {
|
|
@@ -27,19 +32,22 @@ const defaultProps = {
|
|
|
27
32
|
s: 768,
|
|
28
33
|
m: 992,
|
|
29
34
|
l: 1200,
|
|
30
|
-
xl: Infinity
|
|
35
|
+
xl: Infinity,
|
|
31
36
|
},
|
|
32
37
|
maxWidthBrkpts: {
|
|
33
38
|
xs: 576,
|
|
34
39
|
s: 768,
|
|
35
40
|
m: 992,
|
|
36
41
|
l: 1200,
|
|
37
|
-
xl: Infinity
|
|
42
|
+
xl: Infinity,
|
|
38
43
|
},
|
|
39
44
|
stylePropHeight: null,
|
|
40
45
|
onResize: null,
|
|
41
|
-
forceUpdate: null
|
|
46
|
+
forceUpdate: null,
|
|
42
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* This component adds css class to an element depending on his size.
|
|
50
|
+
*/
|
|
43
51
|
class ResizeHandler extends PureComponent {
|
|
44
52
|
static applyBreakpoints(entry, breakpoints, size, direction) {
|
|
45
53
|
let found = false;
|
|
@@ -55,6 +63,7 @@ class ResizeHandler extends PureComponent {
|
|
|
55
63
|
});
|
|
56
64
|
return screenSize;
|
|
57
65
|
}
|
|
66
|
+
|
|
58
67
|
constructor(props) {
|
|
59
68
|
super(props);
|
|
60
69
|
this.observer = new ResizeObserver((entries) => {
|
|
@@ -62,40 +71,54 @@ class ResizeHandler extends PureComponent {
|
|
|
62
71
|
});
|
|
63
72
|
this.nodes = [];
|
|
64
73
|
}
|
|
74
|
+
|
|
65
75
|
componentDidMount() {
|
|
66
76
|
this.observe();
|
|
67
77
|
}
|
|
78
|
+
|
|
68
79
|
componentDidUpdate(prevProps) {
|
|
69
80
|
const { observe, forceUpdate } = this.props;
|
|
70
|
-
|
|
81
|
+
|
|
82
|
+
if (
|
|
83
|
+
observe !== prevProps.observe ||
|
|
84
|
+
forceUpdate !== prevProps.forceUpdate
|
|
85
|
+
) {
|
|
71
86
|
this.observe();
|
|
72
87
|
}
|
|
73
88
|
}
|
|
89
|
+
|
|
74
90
|
componentWillUnmount() {
|
|
75
91
|
this.observer.disconnect();
|
|
76
92
|
}
|
|
93
|
+
|
|
77
94
|
onResize(entries) {
|
|
78
|
-
const { maxHeightBrkpts, maxWidthBrkpts, stylePropHeight, onResize } =
|
|
95
|
+
const { maxHeightBrkpts, maxWidthBrkpts, stylePropHeight, onResize } =
|
|
96
|
+
this.props;
|
|
97
|
+
|
|
79
98
|
if (stylePropHeight) {
|
|
80
99
|
const vh = window.innerHeight * 0.01;
|
|
81
100
|
document.documentElement.style.setProperty(stylePropHeight, `${vh}px`);
|
|
82
101
|
}
|
|
102
|
+
|
|
83
103
|
if (!maxWidthBrkpts && !maxHeightBrkpts) {
|
|
84
104
|
onResize(entries);
|
|
85
105
|
return;
|
|
86
106
|
}
|
|
107
|
+
|
|
87
108
|
let newScreenWidth;
|
|
88
109
|
let newScreenHeight;
|
|
110
|
+
|
|
89
111
|
for (let i = 0; i < entries.length; i += 1) {
|
|
90
112
|
const entry = entries[i];
|
|
91
113
|
const rect = entry.contentRect;
|
|
92
114
|
const { height, width } = rect;
|
|
115
|
+
|
|
93
116
|
if (maxWidthBrkpts) {
|
|
94
117
|
newScreenWidth = ResizeHandler.applyBreakpoints(
|
|
95
118
|
entry,
|
|
96
119
|
maxWidthBrkpts,
|
|
97
120
|
width,
|
|
98
|
-
|
|
121
|
+
'w',
|
|
99
122
|
);
|
|
100
123
|
}
|
|
101
124
|
if (maxHeightBrkpts) {
|
|
@@ -103,41 +126,53 @@ class ResizeHandler extends PureComponent {
|
|
|
103
126
|
entry,
|
|
104
127
|
maxHeightBrkpts,
|
|
105
128
|
height,
|
|
106
|
-
|
|
129
|
+
'h',
|
|
107
130
|
);
|
|
108
131
|
}
|
|
109
132
|
}
|
|
133
|
+
|
|
110
134
|
if (onResize) {
|
|
111
135
|
onResize(entries, newScreenWidth, newScreenHeight);
|
|
112
136
|
}
|
|
113
137
|
}
|
|
138
|
+
|
|
114
139
|
observe() {
|
|
115
140
|
this.observer.disconnect();
|
|
116
141
|
const { observe } = this.props;
|
|
142
|
+
|
|
117
143
|
if (!observe) {
|
|
118
144
|
return;
|
|
119
145
|
}
|
|
120
|
-
|
|
146
|
+
|
|
147
|
+
if (typeof observe === 'string' || observe instanceof String) {
|
|
121
148
|
this.nodes = document.querySelectorAll(observe);
|
|
122
149
|
} else if (observe instanceof Component) {
|
|
150
|
+
// eslint-disable-next-line react/no-find-dom-node
|
|
123
151
|
this.nodes.push(ReactDOM.findDOMNode(observe));
|
|
124
152
|
} else if (observe instanceof Element) {
|
|
125
153
|
this.nodes.push(observe);
|
|
126
154
|
} else if (observe.current instanceof Element) {
|
|
155
|
+
// observe value created with React.createRef() on a html node.
|
|
127
156
|
this.nodes.push(observe.current);
|
|
128
157
|
} else if (observe.current instanceof Component) {
|
|
158
|
+
// observe value created with React.createRef() on a React component.
|
|
159
|
+
// eslint-disable-next-line react/no-find-dom-node
|
|
129
160
|
this.nodes.push(ReactDOM.findDOMNode(observe.current));
|
|
130
161
|
}
|
|
162
|
+
|
|
131
163
|
if (this.nodes.length) {
|
|
132
164
|
this.nodes.forEach((node) => {
|
|
133
165
|
return this.observer.observe(node);
|
|
134
166
|
});
|
|
135
167
|
}
|
|
136
168
|
}
|
|
169
|
+
|
|
137
170
|
render() {
|
|
138
171
|
return null;
|
|
139
172
|
}
|
|
140
173
|
}
|
|
174
|
+
|
|
141
175
|
ResizeHandler.propTypes = propTypes;
|
|
142
176
|
ResizeHandler.defaultProps = defaultProps;
|
|
177
|
+
|
|
143
178
|
export default ResizeHandler;
|