Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate @nivo/line to TypeScript #1932

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/line/index.d.ts → packages/line/__old_index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*
* This file is part of the nivo project.
*
* Copyright 2016-present, Raphaël Benitte.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import * as React from 'react'
import {
Dimensions,
Expand Down
5 changes: 3 additions & 2 deletions packages/line/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
],
"main": "./dist/nivo-line.cjs.js",
"module": "./dist/nivo-line.es.js",
"typings": "./dist/types/index.d.ts",
"files": [
"README.md",
"LICENSE.md",
"index.d.ts",
"dist/"
"dist/",
"!dist/tsconfig.tsbuildinfo"
],
"dependencies": {
"@nivo/annotations": "0.79.1",
Expand Down
68 changes: 0 additions & 68 deletions packages/line/src/Areas.js

This file was deleted.

69 changes: 69 additions & 0 deletions packages/line/src/Areas.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { memo } from 'react'
import { useSpring, animated } from '@react-spring/web'
import { useAnimatedPath, useMotionConfig, CssMixBlendMode } from '@nivo/core'
import { AreaGenerator, LineDatum } from './types'

const AreaPath = ({
blendMode,
opacity,
color,
fill,
path,
}: {
blendMode: CssMixBlendMode
opacity: number
color: string
fill?: string
path: string
}) => {
const { animate, config: springConfig } = useMotionConfig()

const animatedPath = useAnimatedPath(path)
const animatedProps = useSpring({
color,
config: springConfig,
immediate: !animate,
})

return (
<animated.path
d={animatedPath}
fill={fill ? fill : animatedProps.color}
fillOpacity={opacity}
strokeWidth={0}
style={{
mixBlendMode: blendMode,
}}
/>
)
}

const NonMemoizedAreas = <Datum extends LineDatum>({
areaGenerator,
areaOpacity,
areaBlendMode,
lines,
}: {
areaGenerator: AreaGenerator<Datum>
areaOpacity: number
areaBlendMode: CssMixBlendMode
lines: any[]
}) => {
const computedLines = lines.slice(0).reverse()

return (
<g>
{computedLines.map(line => (
<AreaPath
key={line.id}
path={areaGenerator(line.data.map(d => d.position))}
opacity={areaOpacity}
blendMode={areaBlendMode}
{...line}
/>
))}
</g>
)
}

export const Areas = memo(NonMemoizedAreas) as typeof NonMemoizedAreas
Loading