Skip to content

Commit

Permalink
feat(line): init typescript migration
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Dec 4, 2023
1 parent 4423820 commit 18caae7
Show file tree
Hide file tree
Showing 34 changed files with 1,339 additions and 987 deletions.
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
4 changes: 2 additions & 2 deletions packages/line/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 23 additions & 21 deletions packages/line/src/Areas.js → packages/line/src/Areas.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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 @@ -26,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

0 comments on commit 18caae7

Please sign in to comment.