UNPKG

1.21 kBTypeScriptView Raw
1import React from 'react';
2import { withoutXY } from '../lib/extract/extractProps';
3import { NumberProp } from '../lib/extract/types';
4import { idPattern } from '../lib/util';
5import Shape from './Shape';
6import { RNSVGUse } from './NativeComponents';
7
8export default class Use extends Shape<{
9 x?: NumberProp;
10 y?: NumberProp;
11 width?: NumberProp;
12 height?: NumberProp;
13 xlinkHref?: string;
14 href?: string;
15}> {
16 static displayName = 'Use';
17
18 static defaultProps = {
19 x: 0,
20 y: 0,
21 width: 0,
22 height: 0,
23 };
24
25 render() {
26 const { props } = this;
27 const {
28 children,
29 x,
30 y,
31 width,
32 height,
33 xlinkHref,
34 href = xlinkHref,
35 } = props;
36
37 const matched = href && href.match(idPattern);
38 const match = matched && matched[1];
39
40 if (!match) {
41 console.warn(
42 'Invalid `href` prop for `Use` element, expected a href like "#id", but got: "' +
43 href +
44 '"',
45 );
46 }
47 const useProps = {
48 href: match,
49 x,
50 y,
51 width,
52 height,
53 };
54 return (
55 <RNSVGUse ref={this.refMethod} {...withoutXY(this, props)} {...useProps}>
56 {children}
57 </RNSVGUse>
58 );
59 }
60}