updated UI

This commit is contained in:
Ritesh Kumar committed 2017-06-18 03:08:44 +05:30
1 parent 8265bae04d
commit a8733f83c8
8 files changed
+443 -200

No files matched your search

+227
View File
@@ -0,0 +1,227 @@
import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import isBrowser from 'is-in-browser'
import { transform } from 'babel-standalone'
import store from 'store2'
import {js_beautify} from 'js-beautify'
import copy from 'copy-text-to-clipboard'
import Head from 'next/head'
import Layout from '../components/Layout'
let brace
let AceEditor
if (isBrowser) {
brace = require('brace').default
AceEditor = require('react-ace').default
require('brace/mode/javascript')
require('brace/theme/tomorrow')
}
export default class ConversionPanel extends PureComponent {
static propTypes = {
plugin: PropTypes.func.isRequired,
name: PropTypes.string.isRequired,
leftMode: PropTypes.string,
rightMode: PropTypes.string
}
static defaultProps = {
leftMode: 'javascript',
rightMode: 'javascript'
}
constructor (props) {
super(props)
this.state = {
resultValue: '',
value: '',
info: ''
}
}
componentDidMount() {
this.setState({
value: store(`${name}_code`) || this.props.defaultText,
resultValue: store(`${name}_result`) || this.props.getTransformedValue(this.props.defaultText)
})
}
onChange = (newValue) => {
const {name} = this.props;
try {
const code = this.props.getTransformedValue(newValue)
this.setState({
resultValue: code,
info: ''
})
store(`${name}_code`, newValue)
store(`${name}_result`, code)
} catch (e) {
this.setState({
info: e.message
})
}
this.setState({
value: newValue
})
}
prettifyCode = () => {
this.setState({
value: js_beautify(this.state.value)
})
}
copyCode = () => {
copy(this.state.resultValue)
this.setState({
info: 'Code copied to clipboard.'
})
}
render () {
return (
<Layout>
<div className="wrapper">
<Head>
<title>Transform | Convert an object to propTypes</title>
<meta rel="description" content="Convert an object to propTypes"/>
</Head>
<style jsx>{`
@import url('https://fonts.googleapis.com/css?family=Lato');
.wrapper {
display: flex;
flex: 1;
height: 100vh;
flex-direction: column;
}
.footer{
height: 50px;
width: 100%;
font-family: 'Lato';
background-color: white;
box-shadow: 0 0 1px 1px rgba(0,0,0,0.2);
z-index: 999;
display: flex;
align-items: center;
text-align: center;
justify-content: center;
}
.content-wrapper {
flex: 1;
display: flex;
flex-direction: row;
}
.section {
flex: 1;
position: relative;
}
.right {
border-left: 1px solid #eee;
padding: 20px;
}
.error {
color: red;
font: 14px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
}
.btn {
position: absolute;
top: 20px;
right: 20px;
background-color: #2196F3;
font-size: 14px;
padding: 7px 14px;
z-index: 9;
border: 0;
border-radius: 2px;
cursor: pointer;
outline: none;
color: #fff;
line-height: 16px;
}
.btn:hover {
background-color: #2380ca;
}
`}</style>
<style global jsx>{`
*{
margin: 0;
padding: 0;
-webkit-font-smoothing: antialiased;
}
#code{
display: flex;
flex: 1;
width: 100% !important;
height: 100% !important;
}
.right .ace_content, .right, .right .ace-tomorrow {
background-color: #fafafa;
}
`}</style>
<div className="content-wrapper">
<div className="section left">
{isBrowser &&
<AceEditor
mode="javascript"
theme="tomorrow"
onChange={this.onChange}
name="code"
value={this.state.value}
editorProps={{$blockScrolling: true}}
highlightActiveLine={false}
scrollMargin={[20]}
focus
fontSize={14}
wrapEnabled
/>
}
<button className="btn" onClick={this.prettifyCode}>Prettify</button>
</div>
<div className="section right">
{isBrowser &&
<AceEditor
mode="javascript"
theme="tomorrow"
name="code"
readOnly
value={js_beautify(this.state.resultValue)}
editorProps={{$blockScrolling: true}}
scrollMargin={[20]}
fontSize={14}
showGutter={false}
highlightActiveLine={false}
wrapEnabled
/>
}
<button className="btn" onClick={this.copyCode}>Copy</button>
</div>
</div>
<div className="footer">
<span className="error">{this.state.info}</span>
</div>
</div>
</Layout>
)
}
}
+95
View File
@@ -0,0 +1,95 @@
import React from 'react'
import isBrowser from 'is-in-browser'
import Link from 'next/link'
function isActiveRoute (routeName) {
if (isBrowser) {
return window.location.pathname === routeName
}
}
function Logo () {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 125" fill="#ffffff" width="190">
<path
d="M68.6 34c-2.6 0-4.7 1.6-5.7 3.8l-25.4-6v-.4c0-3.4-2.8-6.2-6.2-6.2-3.4 0-6.2 2.8-6.2 6.2 0 3.1 2.2 5.6 5.2 6.1v25.1c-2.9.5-5.2 3-5.2 6.1 0 3.4 2.8 6.2 6.2 6.2 3.1 0 5.6-2.2 6.1-5.2h16.7c.5 2.9 3 5.2 6.1 5.2 3.4 0 6.2-2.8 6.2-6.2 0-2.4-1.4-4.4-3.3-5.5l4.8-16.9c.3 0 .6.1.9.1 3.4 0 6.2-2.8 6.2-6.2-.2-3.4-3-6.2-6.4-6.2zm0 10.3c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2zM31.4 27.2c2.3 0 4.2 1.9 4.2 4.2s-1.9 4.2-4.2 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2zm4.1 41.4c0 2.3-1.9 4.2-4.2 4.2-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2c2.4.1 4.2 1.9 4.2 4.2zm24.7 4.2c-2.3 0-4.2-1.9-4.2-4.2s1.9-4.2 4.2-4.2 4.2 1.9 4.2 4.2-1.9 4.2-4.2 4.2zm.9-10.3c-.3 0-.6-.1-.9-.1-3.1 0-5.6 2.2-6.1 5.2H37.5C37 65 35 63 32.4 62.5v-25c2.1-.3 3.9-1.8 4.7-3.7l25.4 6v.4c0 2.4 1.4 4.5 3.4 5.5l-4.8 16.8z" />
</svg>
)
}
export default function ({children}) {
return (
<div className="main-wrapper">
<style jsx>{`
.sidebar{
height: 100vh;
width: 250px;
background-color: #424242;
font-size: 15px;
display: flex;
flex-direction: column;
}
.main-wrapper {
flex-direction: row;
display: flex;
flex: 1;
}
.content {
flex: 1;
}
ul {
padding: 20px 0;
flex: 1;
}
li {
color: whitesmoke;
font-family: 'Lato', sans-serif;
line-height: 40px;
padding-left: 15px;
cursor: pointer;
}
li:hover {
color: #fff;
background-color: #2d2d2d;
}
a {
color: #fff;
}
.logo {
height: 180px;
margin: 0 auto;
}
.footer {
height: 40px;
text-align: center;
color: #fff;
font-family: 'Lato', sans-serif;
}
`}</style>
<div className="sidebar">
<div className="logo">
<Logo/>
</div>
<ul>
<li><Link prefetch href="/"><a>JS Object to React PropTypes</a></Link></li>
</ul>
<div className="footer">
Created by <a href="https://github.com/ritz078">@ritz078</a>
</div>
</div>
<div className="content">
{children}
</div>
</div>
)
}