UNPKG

883 BTypeScriptView Raw
1import React from 'react';
2import Path from './Path';
3import Shape from './Shape';
4import { NumberProp } from '../lib/extract/types';
5import extractPolyPoints from '../lib/extract/extractPolyPoints';
6
7export default class Polygon extends Shape<{ points?: number[] }> {
8 static displayName = 'Polygon';
9
10 static defaultProps = {
11 points: '',
12 };
13
14 setNativeProps = (
15 props: Object & {
16 points?: string | NumberProp[];
17 d?: string;
18 },
19 ) => {
20 const { points } = props;
21 if (points) {
22 props.d = `M${extractPolyPoints(points)}z`;
23 }
24 this.root && this.root.setNativeProps(props);
25 };
26
27 render() {
28 const { props } = this;
29 const { points } = props;
30 return (
31 <Path
32 ref={this.refMethod as (instance: Path | null) => void}
33 d={points && `M${extractPolyPoints(points)}z`}
34 {...props}
35 />
36 );
37 }
38}