1// tslint:disable max-classes-per-file
2import React from 'react';
3import * as Svg from 'react-native-svg';
4import Example from './Example';
5
6const {
7  Defs,
8  G,
9  Path,
10  Use,
11  Symbol,
12  Circle,
13  ClipPath,
14  LinearGradient,
15  RadialGradient,
16  Stop,
17  Rect,
18} = Svg;
19
20class UseExample extends React.Component {
21  static title = 'Reuse svg code';
22  render() {
23    return (
24      <Svg.Svg height="100" width="300">
25        <Defs>
26          <G id="shape">
27            <G>
28              <Circle cx="50" cy="50" r="50" />
29              <Rect x="50" y="50" width="50" height="50" />
30              <Circle cx="50" cy="50" r="5" fill="blue" />
31            </G>
32          </G>
33        </Defs>
34        <Use href="#shape" x="20" y="0" />
35        <Use href="#shape" x="170" y="0" />
36      </Svg.Svg>
37    );
38  }
39}
40
41class UseShapes extends React.Component {
42  static title = 'Using Shapes Outside of a Defs Element';
43  render() {
44    return (
45      <Svg.Svg height="110" width="200">
46        <G id="shape">
47          <Rect x="0" y="0" width="50" height="50" />
48        </G>
49        <Use href="#shape" x="75" y="50" fill="#0f0" />
50        <Use href="#shape" x="110" y="0" stroke="#0ff" fill="#8a3" rotation="45" origin="25, 25" />
51        <Use href="#shape" x="150" y="50" stroke="#0f0" strokeWidth="1" fill="none" />
52      </Svg.Svg>
53    );
54  }
55}
56
57class DefsExample extends React.Component {
58  static title = 'Basic Defs usage';
59
60  render() {
61    return (
62      <Svg.Svg height="100" width="100">
63        <Defs>
64          <G id="path" x="5" y="2" opacity="0.9">
65            <Path
66              id="test"
67              // tslint:disable-next-line: max-line-length
68              d="M38.459,1.66A0.884,0.884,0,0,1,39,2.5a0.7,0.7,0,0,1-.3.575L23.235,16.092,27.58,26.1a1.4,1.4,0,0,1,.148.3,1.3,1.3,0,0,1,0,.377,1.266,1.266,0,0,1-2.078.991L15.526,20.6l-7.58,4.35a1.255,1.255,0,0,1-.485,0,1.267,1.267,0,0,1-1.277-1.258q0-.01,0-0.02a1.429,1.429,0,0,1,0-.446C7.243,20.253,8.6,16.369,8.6,16.29L3.433,13.545A0.743,0.743,0,0,1,2.9,12.822a0.822,0.822,0,0,1,.623-0.773l8.164-2.972,3.018-8.5A0.822,0.822,0,0,1,15.427,0a0.752,0.752,0,0,1,.752.555l2.563,6.936S37.65,1.727,37.792,1.685A1.15,1.15,0,0,1,38.459,1.66Z"
69            />
70          </G>
71          <ClipPath id="clip">
72            <Circle r="25%" cx="0%" cy="0%" />
73          </ClipPath>
74          <LinearGradient id="linear" x1="0%" y1="0%" x2="100%" y2="0%">
75            <Stop offset="0%" stopColor="yellow" />
76            <Stop offset="50%" stopColor="red" />
77            <Stop offset="100%" stopColor="blue" />
78          </LinearGradient>
79          <RadialGradient id="radial" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
80            <Stop offset="0%" stopColor="yellow" />
81            <Stop offset="50%" stopColor="red" />
82            <Stop offset="100%" stopColor="blue" />
83          </RadialGradient>
84        </Defs>
85        <Use href="#path" x="0" fill="blue" opacity="0.6" />
86        <Use href="#path" x="20" y="5" fill="url(#linear)" />
87        <Use href="#path" clipPath="url(#clip)" fillOpacity="0.6" stroke="#000" strokeWidth="1" />
88        <Use href="#path" x="-10" y="20" fill="url(#radial)" />
89      </Svg.Svg>
90    );
91  }
92}
93
94class SymbolExample extends React.Component {
95  static title = 'Symbol example, reuse elements with viewBox prop';
96  render() {
97    return (
98      <Svg.Svg height="150" width="110">
99        <Symbol id="symbol" viewBox="0 0 150 110">
100          <Circle cx="50" cy="50" r="40" strokeWidth="8" stroke="red" fill="red" />
101          <Circle cx="90" cy="60" r="40" strokeWidth="8" stroke="green" fill="white" />
102        </Symbol>
103
104        <Use href="#symbol" x="0" y="0" width="100" height="50" />
105        <Use href="#symbol" x="10" y="50" width="75" height="38" />
106        <Use href="#symbol" x="20" y="100" width="50" height="25" />
107      </Svg.Svg>
108    );
109  }
110}
111
112const icon = (
113  <Svg.Svg height="20" width="20">
114    <Defs>
115      <G id="path" scale="0.5">
116        {/* tslint:disable-next-line: max-line-length */}
117        <Path d="M38.459,1.66A0.884,0.884,0,0,1,39,2.5a0.7,0.7,0,0,1-.3.575L23.235,16.092,27.58,26.1a1.4,1.4,0,0,1,.148.3,1.3,1.3,0,0,1,0,.377,1.266,1.266,0,0,1-2.078.991L15.526,20.6l-7.58,4.35a1.255,1.255,0,0,1-.485,0,1.267,1.267,0,0,1-1.277-1.258q0-.01,0-0.02a1.429,1.429,0,0,1,0-.446C7.243,20.253,8.6,16.369,8.6,16.29L3.433,13.545A0.743,0.743,0,0,1,2.9,12.822a0.822,0.822,0,0,1,.623-0.773l8.164-2.972,3.018-8.5A0.822,0.822,0,0,1,15.427,0a0.752,0.752,0,0,1,.752.555l2.563,6.936S37.65,1.727,37.792,1.685A1.15,1.15,0,0,1,38.459,1.66Z" />
118      </G>
119      <ClipPath id="clip">
120        <Circle r="50%" cx="0%" cy="0%" />
121      </ClipPath>
122    </Defs>
123    <Use href="#path" fill="#3a8" />
124    <Use
125      href="#path"
126      fill="red"
127      clipPath="url(#clip)"
128      fillOpacity="0.6"
129      stroke="#000"
130      strokeWidth="1"
131    />
132  </Svg.Svg>
133);
134
135const Reusable: Example = {
136  icon,
137  samples: [UseExample, UseShapes, DefsExample, SymbolExample],
138};
139
140export default Reusable;
141