Skip to content

Commit

Permalink
feat(bump): add additional props to custom layers (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze authored Jun 2, 2021
1 parent 0def428 commit 8bd5a77
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/bump/src/bump/Bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import React, { memo, useState, Fragment } from 'react'
import React, { createElement, memo, useMemo, useState, Fragment } from 'react'
import { withContainer, useDimensions, SvgWrapper } from '@nivo/core'
import { Grid, Axes } from '@nivo/axes'
import { useBump } from './hooks'
Expand Down Expand Up @@ -181,20 +181,26 @@ const Bump = props => {
)
}

const bumpLayerContext = useMemo(
() => ({
currentSerie,
innerHeight,
innerWidth,
lineGenerator,
points,
series,
setCurrentSerie,
xScale,
yScale,
}),
[currentSerie, innerHeight, innerWidth, lineGenerator, points, series, xScale, yScale]
)

return (
<SvgWrapper width={outerWidth} height={outerHeight} margin={margin} role={role}>
{layers.map((layer, i) => {
if (typeof layer === 'function') {
return (
<Fragment key={i}>
{layer({
innerWidth,
innerHeight,
xScale,
yScale,
})}
</Fragment>
)
return <Fragment key={i}>{createElement(layer, bumpLayerContext)}</Fragment>
}

return layerById[layer]
Expand Down

0 comments on commit 8bd5a77

Please sign in to comment.