This repository has been archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeatureLabel.js
61 lines (48 loc) · 1.51 KB
/
FeatureLabel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const h = require('react-hyperscript')
const styled = require('styled-components').default
const { TextGroup } = require('@zendeskgarden/react-textfields')
const { XL, MD, SM } = require('@zendeskgarden/react-typography')
const Box = styled(TextGroup)`
max-width: 400px;
min-height: 200px;
background-color: #e9ebed;
`
const Subtle = styled(SM)`
color: #777777;
padding: 0 10px 5px;
`
const Title = ({title}) => h(XL, {tag: 'span'}, title)
const Header = ({feature}) => {
const children = [h(Title, {title: feature.properties.title})]
if (feature.geometry === undefined) {
children.push(h(Subtle, {tag: 'span'}, [h('i', 'not shown on map')]))
}
return h('div', {style: {padding: '5px 10px'}}, children)
}
const Description = styled(MD)`
padding: 0 10px 5px;
`
const separator = h('span', ' | ')
const separate = array => array.reduce(
(separated, value) => [...separated, value, separator], []
).slice(0, -1)
const description = feature => feature.descriptions
? separate(feature.descriptions.map(description => description.value))
: []
const names = (feature, title) => feature.names
? separate(feature.names.map(n => n.toponym).filter(n => n !== title))
: []
module.exports = function({feature}) {
return h(
Box,
feature && feature.properties && feature.properties.title
?
[
h(Header, {feature}),
h(Subtle, names(feature, feature.properties.title)),
h(Description, description(feature, feature.properties.title)),
]
: []
)
}