Skip to content

Commit

Permalink
feat(bullet): init package migration to typescript
Browse files Browse the repository at this point in the history
Close #1224
  • Loading branch information
wyze authored and plouc committed Nov 9, 2020
1 parent df211c0 commit d07378a
Show file tree
Hide file tree
Showing 22 changed files with 521 additions and 552 deletions.
11 changes: 8 additions & 3 deletions packages/bullet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,30 @@
],
"main": "./dist/nivo-bullet.cjs.js",
"module": "./dist/nivo-bullet.es.js",
"typings": "./dist/types/index.d.ts",
"files": [
"README.md",
"LICENSE.md",
"index.d.ts",
"dist/"
],
"dependencies": {
"@nivo/axes": "0.64.0",
"@nivo/colors": "0.64.0",
"@nivo/core": "0.64.0",
"@nivo/legends": "0.64.0",
"@nivo/tooltip": "0.64.0",
"d3-scale": "^3.0.0",
"lodash": "^4.17.11",
"react-motion": "^0.5.2",
"recompose": "^0.30.0"
},
"devDependencies": {
"@nivo/core": "*",
"@types/d3-scale": "^3.2.1",
"@types/react-motion": "^0.0.29",
"@types/recompose": "^0.30.7"
},
"peerDependencies": {
"prop-types": ">= 15.5.10 < 16.0.0",
"@nivo/core": "^0.64.0",
"react": ">= 16.8.4 < 17.0.0"
},
"publishConfig": {
Expand Down
27 changes: 10 additions & 17 deletions packages/bullet/src/Bullet.js → packages/bullet/src/Bullet.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +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 React, { Component } from 'react'
import { scaleLinear } from 'd3-scale'
// @ts-ignore
import setDisplayName from 'recompose/setDisplayName'
// @ts-ignore
import { Container, SvgWrapper } from '@nivo/core'
import { BulletPropTypes } from './props'
import { defaultProps } from './props'
import { BulletSvgProps, TooltipHandlers } from './types'
import enhance from './enhance'
import BulletItem from './BulletItem'

export class Bullet extends Component {
static propTypes = BulletPropTypes
export class Bullet extends Component<BulletSvgProps> {
static displayName = 'Bullet'

render() {
const {
Expand Down Expand Up @@ -61,9 +56,9 @@ export class Bullet extends Component {
onMarkerClick,

role,
} = this.props
} = { height: 0, width: 0, ...defaultProps, ...this.props }

let itemHeight
let itemHeight: number
if (layout === 'horizontal') {
itemHeight = (height - spacing * (data.length - 1)) / data.length
} else {
Expand All @@ -73,7 +68,7 @@ export class Bullet extends Component {
const markerHeight = itemHeight * markerSize

const enhancedData = data.map(d => {
const all = [...d.ranges, ...d.measures, ...d.markers]
const all = [...d.ranges, ...d.measures, ...(d.markers ?? [])]

const max = Math.max(...all)

Expand Down Expand Up @@ -101,7 +96,7 @@ export class Bullet extends Component {
motionStiffness={motionStiffness}
motionDamping={motionDamping}
>
{({ showTooltip, hideTooltip }) => (
{({ showTooltip, hideTooltip }: TooltipHandlers<unknown>) => (
<SvgWrapper
width={outerWidth}
height={outerHeight}
Expand Down Expand Up @@ -151,6 +146,4 @@ export class Bullet extends Component {
}
}

Bullet.displayName = 'Bullet'

export default setDisplayName(Bullet.displayName)(enhance(Bullet))
Loading

0 comments on commit d07378a

Please sign in to comment.