1- import { memo } from 'react'
2- import PropTypes from 'prop-types'
31import { useSpring , animated } from '@react-spring/web'
4- import { useAnimatedPath , useMotionConfig , blendModePropType } from '@nivo/core'
5- import { useSerieHandlers } from './hooks'
2+ import { useAnimatedPath , useMotionConfig } from '@nivo/core'
3+ import { useAreaBumpSerieHandlers } from './hooks'
4+ import {
5+ AreaBumpAreaGenerator ,
6+ AreaBumpCommonProps ,
7+ AreaBumpComputedSerie ,
8+ AreaBumpDatum ,
9+ } from './types'
610
7- const Area = ( {
11+ interface AreaProps < D extends AreaBumpDatum > {
12+ serie : AreaBumpComputedSerie < D >
13+ areaGenerator : AreaBumpAreaGenerator
14+ blendMode : AreaBumpCommonProps < D > [ 'blendMode' ]
15+ isInteractive : AreaBumpCommonProps < D > [ 'isInteractive' ]
16+ onMouseEnter ?: AreaBumpCommonProps < D > [ 'onMouseEnter' ]
17+ onMouseMove ?: AreaBumpCommonProps < D > [ 'onMouseMove' ]
18+ onMouseLeave ?: AreaBumpCommonProps < D > [ 'onMouseLeave' ]
19+ onClick ?: AreaBumpCommonProps < D > [ 'onClick' ]
20+ setCurrentSerie : any
21+ tooltip : AreaBumpCommonProps < D > [ 'tooltip' ]
22+ }
23+
24+ export const Area = < D extends AreaBumpDatum > ( {
825 serie,
926 areaGenerator,
1027 blendMode,
@@ -15,8 +32,8 @@ const Area = ({
1532 onClick,
1633 setCurrentSerie,
1734 tooltip,
18- } ) => {
19- const handlers = useSerieHandlers ( {
35+ } : AreaProps < D > ) => {
36+ const handlers = useAreaBumpSerieHandlers < D > ( {
2037 serie,
2138 isInteractive,
2239 onMouseEnter,
@@ -29,8 +46,13 @@ const Area = ({
2946
3047 const { animate, config : springConfig } = useMotionConfig ( )
3148
32- const animatedPath = useAnimatedPath ( areaGenerator ( serie . areaPoints ) )
33- const animatedProps = useSpring ( {
49+ const animatedPath = useAnimatedPath ( areaGenerator ( serie . areaPoints ) ! )
50+ const animatedProps = useSpring < {
51+ color : string
52+ fillOpacity : number
53+ stroke : string
54+ strokeOpacity : number
55+ } > ( {
3456 color : serie . color ,
3557 fillOpacity : serie . style . fillOpacity ,
3658 stroke : serie . style . borderColor ,
@@ -55,29 +77,3 @@ const Area = ({
5577 />
5678 )
5779}
58-
59- Area . propTypes = {
60- serie : PropTypes . shape ( {
61- id : PropTypes . string . isRequired ,
62- color : PropTypes . string . isRequired ,
63- fill : PropTypes . string ,
64- areaPoints : PropTypes . array . isRequired ,
65- style : PropTypes . shape ( {
66- fillOpacity : PropTypes . number . isRequired ,
67- borderWidth : PropTypes . number . isRequired ,
68- borderColor : PropTypes . string . isRequired ,
69- borderOpacity : PropTypes . number . isRequired ,
70- } ) . isRequired ,
71- } ) . isRequired ,
72- areaGenerator : PropTypes . func . isRequired ,
73- blendMode : blendModePropType . isRequired ,
74- isInteractive : PropTypes . bool . isRequired ,
75- onMouseEnter : PropTypes . func ,
76- onMouseMove : PropTypes . func ,
77- onMouseLeave : PropTypes . func ,
78- onClick : PropTypes . func ,
79- setCurrentSerie : PropTypes . func . isRequired ,
80- tooltip : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) . isRequired ,
81- }
82-
83- export default memo ( Area )
0 commit comments