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

Line package TypeScript migration #2485

Draft
wants to merge 4 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
2 changes: 1 addition & 1 deletion packages/colors/src/inheritedColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const isInheritedColorConfigFromContext = <Datum>(
export const getInheritedColorGenerator = <Datum = any>(
config: InheritedColorConfig<Datum>,
theme?: Theme
) => {
): ((datum: Datum) => string) => {
// user provided function
if (typeof config === 'function') {
return config
Expand Down
4 changes: 2 additions & 2 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ interface CartesianMarkersProps<
height: number
xScale: (value: X) => number
yScale: (value: Y) => number
markers: CartesianMarkerProps<X | Y>[]
markers: readonly CartesianMarkerProps<X | Y>[]
}
type CartesianMarkersType = <X extends DatumValue = DatumValue, Y extends DatumValue = DatumValue>(
props: CartesianMarkersProps<X, Y>
Expand Down Expand Up @@ -623,7 +623,7 @@ export interface DotsItemProps<D = any> {
color: string
borderWidth: number
borderColor: string
label?: string | number
label?: string | number | null
labelTextAnchor?: 'start' | 'middle' | 'end'
labelYOffset?: number
symbol?: DotsItemSymbolComponent
Expand Down
2 changes: 1 addition & 1 deletion packages/legends/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type Datum = {
}

type CommonLegendProps = {
data?: Datum[]
data?: readonly Datum[]
direction: LegendDirection
padding?: number | Partial<Record<'top' | 'right' | 'bottom' | 'left', number>>
justify?: boolean
Expand Down
8 changes: 0 additions & 8 deletions packages/line/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
10 changes: 5 additions & 5 deletions packages/line/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
],
"main": "./dist/nivo-line.cjs.js",
"module": "./dist/nivo-line.es.js",
"types": "./index.d.ts",
"types": "./dist/types/index.d.ts",
"files": [
"README.md",
"LICENSE.md",
"index.d.ts",
"dist/"
"dist/",
"!dist/tsconfig.tsbuildinfo"
],
"dependencies": {
"@nivo/annotations": "workspace:*",
Expand All @@ -38,8 +38,8 @@
"@nivo/tooltip": "workspace:*",
"@nivo/voronoi": "workspace:*",
"@react-spring/web": "9.4.5 || ^9.7.2",
"d3-shape": "^1.3.5",
"prop-types": "^15.7.2"
"@types/d3-shape": "^2.0.0",
"d3-shape": "^1.3.5"
},
"peerDependencies": {
"react": ">= 16.14.0 < 19.0.0"
Expand Down
52 changes: 23 additions & 29 deletions packages/line/src/Areas.js → packages/line/src/Areas.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/*
* 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 { memo } from 'react'
import PropTypes from 'prop-types'
import { useSpring, animated } from '@react-spring/web'
import { useAnimatedPath, useMotionConfig, blendModePropType } from '@nivo/core'
import { useAnimatedPath, useMotionConfig, CssMixBlendMode } from '@nivo/core'
import { AreaGenerator, ComputedSeries, LineSeries } from './types'

interface AreaPathProps {
areaBlendMode: CssMixBlendMode
areaOpacity: number
color: string
fill?: string
path: string
}

const AreaPath = ({ areaBlendMode, areaOpacity, color, fill, path }) => {
const AreaPath = ({ areaBlendMode, areaOpacity, color, fill, path }: AreaPathProps) => {
const { animate, config: springConfig } = useMotionConfig()

const animatedPath = useAnimatedPath(path)
Expand All @@ -34,35 +33,30 @@ const AreaPath = ({ areaBlendMode, areaOpacity, color, fill, path }) => {
)
}

AreaPath.propTypes = {
areaBlendMode: blendModePropType.isRequired,
areaOpacity: PropTypes.number.isRequired,
color: PropTypes.string,
fill: PropTypes.string,
path: PropTypes.string.isRequired,
interface AreasProps<Series extends LineSeries> {
areaGenerator: AreaGenerator
areaOpacity: number
areaBlendMode: CssMixBlendMode
lines: readonly ComputedSeries<Series>[]
}

const Areas = ({ areaGenerator, areaOpacity, areaBlendMode, lines }) => {
export const Areas = <Series extends LineSeries>({
areaGenerator,
areaOpacity,
areaBlendMode,
lines,
}: AreasProps<Series>) => {
const computedLines = lines.slice(0).reverse()

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

Areas.propTypes = {
areaGenerator: PropTypes.func.isRequired,
areaOpacity: PropTypes.number.isRequired,
areaBlendMode: blendModePropType.isRequired,
lines: PropTypes.arrayOf(PropTypes.object).isRequired,
}

export default memo(Areas)
Loading
Loading