mirror of
https://github.com/ritz078/transform.git
synced 2026-11-29 12:10:14 +03:00
feat: separate SVG to React Native conversation
This commit is contained in:
1 parent
736f241dab
commit
16e5a58a13
3 files changed
+49
-1
No files matched your search
+3
-1
@@ -5,4 +5,6 @@ node_modules
|
||||
.idea
|
||||
out
|
||||
yarn-error.log
|
||||
transform
|
||||
transform
|
||||
|
||||
.vscode
|
||||
@@ -0,0 +1,40 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import convertSvgString from 'transform-svg-to-native'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import isSvg from 'is-svg'
|
||||
import svgo from 'transform-svg-to-native/dist/svgo'
|
||||
|
||||
const defaultText = `<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1">
|
||||
<rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/>
|
||||
</svg>`
|
||||
|
||||
export default class Svg2ReactNative extends PureComponent {
|
||||
getTransformedValue = async (newValue: string) => {
|
||||
if (!isSvg(newValue)) {
|
||||
throw new Error('Please provide a valid SVG markup.')
|
||||
}
|
||||
|
||||
return new Promise(resolve =>
|
||||
convertSvgString(newValue, code => resolve(code))
|
||||
)
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
url={this.props.url}
|
||||
leftTitle='SVG'
|
||||
rightTitle='JSX'
|
||||
leftMode='html'
|
||||
rightMode='jsx'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
name={'svg_to_react_native'}
|
||||
defaultText={defaultText}
|
||||
extensions={['.svg', '.html']}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,12 @@ export const categorizedRoutes = [
|
||||
desc:
|
||||
'An online REPL for converting HTML to JSX with proper support for SVG.'
|
||||
},
|
||||
{
|
||||
label: 'SVG to React Native',
|
||||
path: '/svg-to-react-native',
|
||||
desc:
|
||||
'An online REPL for converting SVG to React Native compatible equivalent.'
|
||||
},
|
||||
{
|
||||
label: 'CSS to JS Objects',
|
||||
path: '/css-to-js',
|
||||
|
||||
Reference in new issue
Block a user