-
Notifications
You must be signed in to change notification settings - Fork 82
/
ClusterMarker.js
75 lines (72 loc) · 1.7 KB
/
ClusterMarker.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react';
import compose from 'recompose/compose';
import defaultProps from 'recompose/defaultProps';
import withPropsOnChange from 'recompose/withPropsOnChange';
import pure from 'recompose/pure';
import { Motion, spring } from 'react-motion';
import clusterMarkerStyles from './ClusterMarker.sass';
export const clusterMarker = ({
styles, text,
defaultMotionStyle, motionStyle,
}) => (
<Motion
defaultStyle={defaultMotionStyle}
style={motionStyle}
>
{
({ scale }) => (
<div
className={styles.marker}
style={{
transform: `translate3D(0,0,0) scale(${scale}, ${scale})`,
}}
>
<div
className={styles.text}
>
{text}
</div>
</div>
)
}
</Motion>
);
export const clusterMarkerHOC = compose(
defaultProps({
text: '0',
styles: clusterMarkerStyles,
initialScale: 0.6,
defaultScale: 1,
hoveredScale: 1.15,
hovered: false,
stiffness: 320,
damping: 7,
precision: 0.001,
}),
// pure optimization can cause some effects you don't want,
// don't use it in development for markers
pure,
withPropsOnChange(
['initialScale'],
({ initialScale, defaultScale, $prerender }) => ({
initialScale,
defaultMotionStyle: { scale: $prerender ? defaultScale : initialScale },
})
),
withPropsOnChange(
['hovered'],
({
hovered, hoveredScale, defaultScale,
stiffness, damping, precision,
}) => ({
hovered,
motionStyle: {
scale: spring(
hovered ? hoveredScale : defaultScale,
{ stiffness, damping, precision }
),
},
})
)
);
export default clusterMarkerHOC(clusterMarker);