Skip to content

Commit

Permalink
chore: implement typescript types
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnowack committed Jan 7, 2022
1 parent 29225da commit 00571c9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
},
"main": "dist/react-map-gl-cluster.cjs.js",
"module": "dist/react-map-gl-cluster.esm.js",
"types": "src/index.d.ts",
"files": [
"src/index.d.ts",
"dist"
],
"scripts": {
Expand Down Expand Up @@ -45,6 +47,7 @@
"@babel/preset-flow": "^7.9.0",
"@babel/preset-react": "^7.9.4",
"@turf/random": "^6.0.2",
"@types/react": "^16.9.56",
"@urbica/react-map-gl": "^1.13.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
Expand Down
73 changes: 73 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* eslint-disable react/no-unused-prop-types */
/* eslint-disable flowtype/no-types-missing-file-annotation */
import { Component, PureComponent } from 'react'

export type SuperclusterFeature = {
type: 'Feature',
id: number,
properties: {
cluster: true,
cluster_id: number,
point_count: number,
point_count_abbreviated: string | number
},
geometry: {
type: 'Point',
coordinates: [number, number]
}
};

export type ClusterComponentProps = {
longitude: number,
latitude: number,
clusterId: number,
pointCount: number,
pointCountAbbreviated: string | number
};

export type ClusterMapFunction = (props: Record<string, any>) => any;

export type ClusterReduceFunction = (
accumulated: Record<string, any>,
props: Record<string, any>,
) => void;

export type ClusterComponent = Component<ClusterComponentProps, any>
| React.FC<ClusterComponentProps>


type Props = {
/** Minimum zoom level at which clusters are generated */
minZoom?: number,

/** Maximum zoom level at which clusters are generated */
maxZoom?: number,

/** Cluster radius, in pixels */
radius?: number,

/** (Tiles) Tile extent. Radius is calculated relative to this value */
extent?: number,

/** Size of the KD-tree leaf node. Affects performance */
nodeSize?: number,

/**
* A function that returns cluster properties
* corresponding to a single point.
* */
// eslint-disable-next-line react/no-unused-prop-types
map?: ClusterMapFunction,

/** A reduce function that merges properties of two clusters into one. */
// eslint-disable-next-line react/no-unused-prop-types
reduce?: ClusterReduceFunction,

/** React Component for rendering Cluster */
component: ClusterComponent,
}


export default class Cluster extends PureComponent<Props, any> {

}

0 comments on commit 00571c9

Please sign in to comment.