Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map component #60

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,6 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

# JetBrains IntelliJ IDEA
.idea/
5 changes: 5 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ module.exports = {
],
});

config.module.rules.push({
test: /\.png$/i,
type: 'asset/resource'
});

config.resolve.alias = {
...config.resolve.alias,
'@': AppSourceDir,
Expand Down
2 changes: 2 additions & 0 deletions __mocks__/png.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default 'PngURL';
export const ReactComponent = 'div';
5 changes: 5 additions & 0 deletions custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ declare module '*.css' {
const styles: { [className: string]: string };
export default styles;
}

declare module '*.png' {
const value: any;
export = value;
}
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ module.exports = {
moduleNameMapper: {
'.(css|less|scss)$': 'identity-obj-proxy',
'\\.svg$': '<rootDir>/__mocks__/svg.ts',
'\\.png$': '<rootDir>/__mocks__/png.ts',
'^@/(.*)$': '<rootDir>/src/$1',
'^@test/(.*)$': '<rootDir>/test/$1',
},
modulePathIgnorePatterns: ['<rootDir>/dist/'],
setupFilesAfterEnv: ['<rootDir>/test/jest.setup.ts'],
testPathIgnorePatterns: ['/node_modules/', '/scripts/templates/'],
globals: {
'ts-jest': {
tsconfig: {
allowJs: true,
},
},
},
transform: { '\\.js$': ['ts-jest'] },
transformIgnorePatterns: ['node_modules/(?!react-leaflet)/'],
};
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"dependencies": {
"@altinn/figma-design-tokens": "^0.3.0",
"@react-hookz/web": "^15.0.1",
"leaflet": "^1.8.0",
"react-leaflet": "^4.0.1",
"react-number-format": "^4.9.3"
},
"resolutions": {
Expand All @@ -37,6 +39,7 @@
"@babel/core": "^7.18.10",
"@mdx-js/react": "^1.6.22",
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-image": "^2.1.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-typescript": "^8.3.3",
Expand Down Expand Up @@ -65,6 +68,7 @@
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^14.3.0",
"@types/jest": "^28.1.6",
"@types/leaflet": "^1.7.11",
"@types/node": "^17.0.45",
"@types/react": "^18.0.15",
"@types/testing-library__jest-dom": "^5.14.5",
Expand Down
4 changes: 4 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
import image from '@rollup/plugin-image';
import dts from 'rollup-plugin-dts';
import postcss from 'rollup-plugin-postcss';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
Expand Down Expand Up @@ -30,6 +31,8 @@ export default [
altinnFigmaTokensExceptCss,
/@react-hookz\/web/,
/react-number-format/,
/react-leaflet/,
/leaflet/,
],
plugins: [
peerDepsExternal(),
Expand All @@ -40,6 +43,7 @@ export default [
svgr({ exportType: 'named' }),
josteitv marked this conversation as resolved.
Show resolved Hide resolved
postcss(),
terser(),
image(),
],
},
{
Expand Down
5 changes: 5 additions & 0 deletions src/components/Map/Map.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.map {
position: relative;
height: 50rem;
width: 100%;
}
155 changes: 155 additions & 0 deletions src/components/Map/Map.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import React, { useState } from 'react';
import type { ComponentStory, ComponentMeta } from '@storybook/react';
import { config } from 'storybook-addon-designs';

import { StoryPage } from '@sb/StoryPage';

import type { Location } from './Map';
import { Map } from './Map';

const figmaLink = '';

export default {
title: `Components/Map`,
component: Map,
parameters: {
layout: 'fullscreen',
design: config([
{
type: 'figma',
url: figmaLink,
},
{
type: 'link',
url: figmaLink,
},
]),
docs: {
page: () => <StoryPage description={`Map component`} />,
},
},
args: {
//
},
} as ComponentMeta<typeof Map>;

const Template: ComponentStory<typeof Map> = (args) => {
const [markerLocation, setMarkerLocation] = useState<Location | undefined>(
args.markerLocation,
);

const mapClicked = (location: Location) => {
setMarkerLocation(location);
console.log(`Map clicked at [${location.latitude},${location.longitude}]`);
};

return (
<Map
{...args}
markerLocation={markerLocation}
onClick={mapClicked}
/>
);
};

export const Default = Template.bind({});
Default.args = {};
Default.parameters = {
docs: {
description: {
story:
'This is the default map you get if you do not specify any map layers. Kartverket with layers "europa_forenklet" and "norgeskart_bakgrunn2"',
},
},
};

export const MapWithMarkerZoomAndCenter = Template.bind({});
MapWithMarkerZoomAndCenter.args = {
markerLocation: {
latitude: 59.2641592,
longitude: 10.4036248,
},
zoom: 16,
centerLocation: {
latitude: 59.2641592,
longitude: 10.4036248,
},
};
MapWithMarkerZoomAndCenter.parameters = {
docs: {
description: {
story: 'Default map with marker location and center location set',
},
},
};

export const OpenStreetMap = Template.bind({});
OpenStreetMap.args = {
layers: [
{
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
attribution:
'&copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap contributors</a>',
},
],
};
OpenStreetMap.parameters = {
docs: {
description: {
story: 'OpenStreetMap',
},
},
};

export const KartverketTerrain = Template.bind({});
KartverketTerrain.args = {
layers: [
{
url: 'https://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=terreng_norgeskart&zoom={z}&x={x}&y={y}',
attribution: 'Data © <a href="https://www.kartverket.no/">Kartverket</a>',
},
],
};
KartverketTerrain.parameters = {
docs: {
description: {
story: 'Kartverket terrain map',
},
},
};

export const KartverketSea = Template.bind({});
KartverketSea.args = {
layers: [
{
url: 'https://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=sjokartraster&zoom={z}&x={x}&y={y}',
attribution: 'Data © <a href="https://www.kartverket.no/">Kartverket</a>',
},
],
};
KartverketSea.parameters = {
docs: {
description: {
story: 'Kartverket sea map',
},
},
};

export const GoogleMaps = Template.bind({});
GoogleMaps.args = {
layers: [
{
url: 'https://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
subdomains: ['mt0', 'mt1', 'mt2', 'mt3'],
attribution: '© Google Maps',
},
],
};
GoogleMaps.parameters = {
docs: {
description: {
story: 'Google Maps',
},
},
};
Loading