add Use element and add example for it

add Use element and add example for it
This commit is contained in:
Horcrux
2016-01-23 19:25:12 +08:00
parent af0995022d
commit 11c211a9a9
12 changed files with 166 additions and 29 deletions
+37
View File
@@ -0,0 +1,37 @@
import React, {
Component,
PropTypes,
ART,
cloneElement
} from 'react-native';
let {Group} = ART;
import Defs from './Defs';
import transformFilter from '../lib/transformFilter';
let idReg = /^#(.+)/;
class Use extends Component{
static displayName = 'Use';
static propType = {
href: PropTypes.string
};
render() {
let href = this.props.href;
if (href) {
let matched = href.match(idReg);
if (matched) {
let template = Defs.get(matched[1] + ':' + this.props.svgId);
if (template) {
let props = {
...this.props,
href: null
};
return cloneElement(template, props);
}
}
}
return <Group />;
}
}
export default Use;