Skip to content

Commit 2d35f2a

Browse files
author
MartinP460
committed
Add constituencies.
1 parent b9ac53a commit 2d35f2a

File tree

7 files changed

+164
-28
lines changed

7 files changed

+164
-28
lines changed

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ React Denmark Map exports several components, each being a map of Denmark with d
266266
| Component | Description |
267267
| ---------------- | -------------------------------------------------- |
268268
| `Municipalities` | All 98 municipalities of Denmark. |
269+
| `Constituencies` | The 10 constituencies of Denmark. |
269270
| `Regions` | The five regions of Denmark. |
270271
| `Islands` | Zealand, Fyn and Jutland (Sjælland, Fyn, Jylland). |
271272
| `Denmark` | A map of Denmark with no subsequent areas. |
@@ -275,21 +276,21 @@ React Denmark Map exports several components, each being a map of Denmark with d
275276
| Prop | Description | Type | Default |
276277
| ---------------- | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ------- |
277278
| `className` | The `className` applied directly to the `<svg>` element. | string | "" |
278-
| `style` | The style object applied directly to the `<svg>` element. | CSSProperties<sup>1</sup> | {} |
279+
| `style` | The style object applied directly to the `<svg>` element. | CSSProperties<sup>\*</sup> | {} |
279280
| `color` | The default color of each municipality. | CSSProperties["fill"] | #ccc |
280281
| `clickable` | Whether the clickable styles should be applied to the `<path>` element (the area). | boolean | false |
281282
| `hoverable` | Whether the hoverable styles should be applied to the `<path>` element (the area). | boolean | true |
282283
| `showTooltip` | Whether the tooltip should be shown. | boolean | true |
283-
| `customTooltip` | A function that returns a custom tooltip. | (area: AreaType<sup>2</sup>) => ReactNode | |
284+
| `customTooltip` | A function that returns a custom tooltip. | (area: AreaType<sup>\*\*</sup>) => ReactNode | |
284285
| `customizeAreas` | A function that is invoked for every area and returns an object to style the area. | (area: AreaType) => { className?: string, style? CSSProperties } \| undefined | |
285286
| `onClick` | A function that is invoked when an area is clicked. | (area: AreaType) => void | |
286287
| `onHover` | A function that is invoked when an area is hovered. | (area: AreaType) => void | |
287288
| `onMouseEnter` | A function that is invoked when the mouse enters an area. | (area: AreaType) => void | |
288289
| `onMouseLeave` | A function that is invoked when the mouse leaves an area. | (area: AreaType) => void | |
289290
290-
1: CSSProperties refers to the object provided to the style attribute in React. Fields in this object are denoted as CSSProperties["property"].
291+
\*: CSSProperties refers to the object provided to the style attribute in React. Fields in this object are denoted as CSSProperties["property"].
291292
292-
2: AreaType is one of the four types corresponding to the component used (see "Types" below).
293+
\*\*: AreaType is one of the four types corresponding to the component used (see "Types" below).
293294
294295
### Types
295296
@@ -309,12 +310,15 @@ type AreaType = {
309310
310311
The types corresponding to each component are:
311312
312-
| Component | Name of exported type | Included in type |
313-
| ---------------- | --------------------- | ----------------------------------------------- |
314-
| `Municipalities` | MunicipalityType | { id, name, en_name, display_name, d, code } |
315-
| `Regions` | RegionType | { id, name, en_name, display_name, d, code } |
316-
| `Islands` | IslandType | { id, name, en_name, display_name, d, en_term } |
317-
| `Denmark` | DenmarkType | { id, name, en_name, display_name, d, en_term } |
313+
| Component | Name of exported type | Included in type |
314+
| ---------------------------- | --------------------- | ----------------------------------------------- |
315+
| `Municipalities` | MunicipalityType | { id, name, en_name, display_name, d, code } |
316+
| `Constituencies`<sup>\*<sup> | ConstituencyType | { id, name, en_name, display_name, d } |
317+
| `Regions` | RegionType | { id, name, en_name, display_name, d, code } |
318+
| `Islands` | IslandType | { id, name, en_name, display_name, d, en_term } |
319+
| `Denmark` | DenmarkType | { id, name, en_name, display_name, d, en_term } |
320+
321+
\*: When filtering using any of the strings in the ConstituencyType be aware that the constituencies (danish: "storkredse"), e.g. "sydjyllands storkreds", have the word "storkreds" omitted in the properties `id`, `name` and `en_name`. Thus, "sydjyllands storkreds" is just "sydjyllands" and so on.
318322
319323
Using the `Denmark` component means that there's only one path element, so DenmarkType describes just that one area.
320324

package-lock.json

Lines changed: 18 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-denmark-map",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Customizable plug-and-play map of Denmark for visual presentation.",
55
"scripts": {
66
"test": "jest --watchAll",
@@ -44,7 +44,8 @@
4444
"@storybook/testing-library": "^0.0.13",
4545
"@testing-library/react": "^13.4.0",
4646
"@types/jest": "^29.0.0",
47-
"@types/react": "^18.0.18",
47+
"@types/react": "^18.0.25",
48+
"@types/react-dom": "^18.0.9",
4849
"babel-jest": "^29.0.1",
4950
"babel-loader": "^8.2.5",
5051
"identity-obj-proxy": "^3.0.0",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ComponentStory, ComponentMeta } from '@storybook/react'
2+
import Constituencies from './Constituencies'
3+
4+
const defaultStyle = {
5+
maxWidth: '750px',
6+
margin: '0 auto'
7+
}
8+
9+
export default {
10+
title: 'ReactDenmarkMap/Constituencies',
11+
component: Constituencies,
12+
argTypes: {
13+
customizeAreas: {
14+
description: 'A function that is invoked for every geographical area.'
15+
}
16+
}
17+
} as ComponentMeta<typeof Constituencies>
18+
19+
const Template: ComponentStory<typeof Constituencies> = (args) => <Constituencies {...args} />
20+
21+
export const Default = Template.bind({})
22+
Default.args = {
23+
onClick: undefined,
24+
style: defaultStyle
25+
}
26+
27+
export const WithCustomizeConstituencies = Template.bind({})
28+
WithCustomizeConstituencies.args = {
29+
customizeAreas: (constituency) => {
30+
if (constituency.id === 'sjaellands' || constituency.id === 'fyns') {
31+
return {
32+
style: { fill: 'darkred' }
33+
}
34+
}
35+
},
36+
onClick: undefined,
37+
style: defaultStyle
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Map, { MapProps } from '../../map/Map'
2+
import { constituencies, ConstituencyType } from './data'
3+
4+
/**
5+
* Component displaying a map of Denmark with the 10 constituencies (storkredse).
6+
*/
7+
export default function Constituencies(props: MapProps<ConstituencyType>) {
8+
return <Map areas={constituencies} viewBoxWidth="12155" viewBoxHeight="14763" {...props} />
9+
}

src/components/areas/constituencies/data.ts

Lines changed: 80 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default } from './Constituencies'
2+
export { ConstituencyType } from './data'

0 commit comments

Comments
 (0)