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

+3 -1
View File
@@ -2,4 +2,6 @@
node_modules
.idea
.idea
yarn-error.log
+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>
)
}
+4
View File
@@ -2,6 +2,10 @@ module.exports = {
webpack: (config, { dev }) => {
config.plugins = config.plugins.filter(plugin => plugin.constructor.name !== 'UglifyJsPlugin');
config.node = {
fs: 'empty'
}
return config;
}
};
+3
View File
@@ -19,9 +19,12 @@
"js-beautify": "^1.6.14",
"lodash": "^4.17.4",
"next": "^2.4.3",
"prop-types": "^15.5.10",
"react": "^15.6.0",
"react-ace": "^5.0.1",
"react-alert": "^2.1.2",
"react-dom": "^15.6.0",
"react-toastify": "^1.7.0",
"store2": "^2.5.1"
}
}
+14 -196
View File
@@ -1,23 +1,13 @@
import React, { PureComponent } from 'react'
import isBrowser from 'is-in-browser'
import React, {PureComponent} from 'react'
import { transform } from 'babel-standalone'
import store from 'store2'
import {js_beautify} from 'js-beautify'
import copy from 'copy-text-to-clipboard'
import plugin from '../utils/plugin'
import ConversionPanel from '../components/ConversionPanel'
let brace
let AceEditor
if (isBrowser) {
brace = require('brace').default
AceEditor = require('react-ace').default
require('brace/mode/javascript')
require('brace/theme/tomorrow')
}
const defaultText = `
// Enter the object you want to convert in the following form
const defaultText = `// Enter the object you want to convert in the
// following form
//
// const x = your_object
//
// You need to assign your object to a variable (for now.)
const x = {
@@ -27,193 +17,21 @@ const x = {
`
export default class Main extends PureComponent {
constructor (props) {
super(props)
this.state = {
resultValue: '',
value: '',
error: ''
}
}
componentDidMount() {
this.setState({
value: store('code') || defaultText,
resultValue: store('result') || this.getTransformedValue(defaultText).code
})
}
getTransformedValue = (newValue) => {
return transform(newValue, {
const { code } = transform(newValue, {
presets: ['es2015'],
plugins: [plugin]
})
return code
}
onChange = (newValue) => {
try {
const {code, ast} = this.getTransformedValue(newValue)
this.setState({
resultValue: code,
error: ''
})
store('code', newValue)
store('result', code)
} catch (e) {
this.setState({
error: e.message
})
}
this.setState({
value: newValue
})
}
prettifyCode = () => {
this.setState({
value: js_beautify(this.state.value)
})
}
copyCode = () => {
copy(this.state.resultValue)
}
render () {
render() {
return (
<div className="wrapper">
<div className="header">
Object to PropTypes
</div>
<style jsx>{`
@import url('https://fonts.googleapis.com/css?family=Lato');
.wrapper {
display: flex;
flex: 1;
height: 100vh;
flex-direction: column;
}
.header, .footer{
height: 50px;
width: 100%;
font-family: 'Lato';
font-weight: bold;
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;
}
.header {
color: #666;
letter-spacing: 1.2px;
}
.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: #fff;
font-size: 14px;
padding: 8px 14px;
z-index: 9;
border: 0;
border-radius: 2px;
cursor: pointer;
outline: none;
border: 1px solid #eee;
}
.btn:hover {
background-color: #f6f6f6;
}
`}</style>
<style global jsx>{`
*{
margin: 0;
padding: 0;
}
#code{
width: 100% !important;
height: 100% !important;
}
`}</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">
{this.state.error ? <span className="error">{this.state.error}</span> : <span>Created by <a href="https://twitter.com/ritz078">Ritesh Kumar</a></span>}
</div>
</div>
<ConversionPanel
getTransformedValue={this.getTransformedValue}
name={'prop_types'}
defaultText={defaultText}
/>
)
}
}
+6 -1
View File
@@ -1,5 +1,10 @@
import {uniqBy, isEmpty} from 'lodash'
/**
* This is a babel plugin that converts an object to PropTypes
* @param t
* @returns {{visitor: {ArrayExpression: (function(*)), NullLiteral: (function(*)), StringLiteral: (function(*)), NumericLiteral: (function(*)), ArrowFunctionExpression: (function(*)), FunctionExpression: (function(*)), BooleanLiteral: (function(*)), Program: (function(*, *)), ObjectExpression: (function(*))}}}
*/
export default function ({types: t}) {
return {
visitor: {
@@ -46,7 +51,7 @@ export default function ({types: t}) {
path.replaceWith(t.identifier('PropTypes.bool'))
},
Program(path, state) {
Program(path) {
path.traverse({
enter(path) {
t.removeComments(path.node);
+91 -2
View File
@@ -881,6 +881,10 @@ braces@^1.8.2:
preserve "^0.2.0"
repeat-element "^1.1.2"
brcast@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/brcast/-/brcast-2.0.0.tgz#9e627ab82209895664c1d6c1f45cd8c43422e3f6"
brorand@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f"
@@ -990,6 +994,10 @@ center-align@^0.1.1:
align-text "^0.1.3"
lazy-cache "^1.0.3"
chain-function@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/chain-function/-/chain-function-1.0.0.tgz#0d4ab37e7e18ead0bdc47b920764118ce58733dc"
chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
@@ -1269,6 +1277,10 @@ diffie-hellman@^5.0.0:
miller-rabin "^4.0.0"
randombytes "^2.0.0"
dom-helpers@^3.2.0:
version "3.2.1"
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.2.1.tgz#3203e07fed217bd1f424b019735582fc37b2825a"
dom-walk@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.1.tgz#672226dc74c8f799ad35307df936aba11acd6018"
@@ -1419,7 +1431,11 @@ extsprintf@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.0.2.tgz#e1080e0658e300b06294990cc70e1502235fd550"
fbjs@^0.8.9:
fast-memoize@^2.2.7:
version "2.2.7"
resolved "https://registry.yarnpkg.com/fast-memoize/-/fast-memoize-2.2.7.tgz#f145c5c22039cedf0a1d4ff6ca592ad0268470ca"
fbjs@^0.8.8, fbjs@^0.8.9:
version "0.8.12"
resolved "https://registry.yarnpkg.com/fbjs/-/fbjs-0.8.12.tgz#10b5d92f76d45575fd63a217d4ea02bea2f8ed04"
dependencies:
@@ -1568,6 +1584,25 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"
glamor@^2.20.24:
version "2.20.25"
resolved "https://registry.yarnpkg.com/glamor/-/glamor-2.20.25.tgz#71b84b82b67a9327771ac59de53ee915d148a4a3"
dependencies:
babel-runtime "^6.18.0"
fbjs "^0.8.8"
object-assign "^4.1.0"
prop-types "^15.5.8"
glamorous@^3.13.1:
version "3.23.3"
resolved "https://registry.yarnpkg.com/glamorous/-/glamorous-3.23.3.tgz#4f64b8e3fab01bf9e51d50564955a0b8fdecb0fe"
dependencies:
brcast "^2.0.0"
fast-memoize "^2.2.7"
html-tag-names "^1.1.1"
react-html-attributes "^1.3.0"
svg-tag-names "^1.1.0"
glob-base@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4"
@@ -1705,10 +1740,18 @@ hosted-git-info@^2.1.4:
version "2.4.2"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.4.2.tgz#0076b9f46a270506ddbaaea56496897460612a67"
html-element-attributes@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/html-element-attributes/-/html-element-attributes-1.2.0.tgz#8b1c7aaf94353fd9b455c27ec7ebaf1583e29fd0"
html-entities@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f"
html-tag-names@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/html-tag-names/-/html-tag-names-1.1.1.tgz#f8a076113f16e393518937f6b3b5d22296755d4a"
htmlescape@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/htmlescape/-/htmlescape-1.1.1.tgz#3a03edc2214bca3b66424a3e7959349509cb0351"
@@ -2639,7 +2682,7 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"
prop-types@15.5.10, prop-types@^15.5.4, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@~15.5.7:
prop-types@15.5.10, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@~15.5.7:
version "15.5.10"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154"
dependencies:
@@ -2724,6 +2767,15 @@ react-ace@^5.0.1:
opencollective "^1.0.3"
prop-types "^15.5.8"
react-alert@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/react-alert/-/react-alert-2.1.2.tgz#fc8a5d03a13561e02b92979a104338d999bf11de"
dependencies:
glamor "^2.20.24"
glamorous "^3.13.1"
react-transition-group "^1.1.2"
shortid "^2.2.8"
react-deep-force-update@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/react-deep-force-update/-/react-deep-force-update-2.0.1.tgz#4f7f6c12c3e7de42f345992a3c518236fa1ecad3"
@@ -2748,12 +2800,35 @@ react-hot-loader@3.0.0-beta.7:
redbox-react "^1.3.6"
source-map "^0.4.4"
react-html-attributes@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/react-html-attributes/-/react-html-attributes-1.3.0.tgz#c97896e9cac47ad9c4e6618b835029a826f5d28c"
dependencies:
html-element-attributes "^1.0.0"
react-proxy@^3.0.0-alpha.0:
version "3.0.0-alpha.1"
resolved "https://registry.yarnpkg.com/react-proxy/-/react-proxy-3.0.0-alpha.1.tgz#4400426bcfa80caa6724c7755695315209fa4b07"
dependencies:
lodash "^4.6.1"
react-toastify@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/react-toastify/-/react-toastify-1.7.0.tgz#8731c37e5000ddb33eed40fd10951e0451c5f9d0"
dependencies:
prop-types "^15.5.8"
react-transition-group "^1.1.2"
react-transition-group@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-1.2.0.tgz#b51fc921b0c3835a7ef7c571c79fc82c73e9204f"
dependencies:
chain-function "^1.0.0"
dom-helpers "^3.2.0"
loose-envify "^1.3.1"
prop-types "^15.5.6"
warning "^3.0.0"
react@^15.6.0:
version "15.6.0"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.0.tgz#c23299b48e30ed302508ce89e1a02c919f826bce"
@@ -3013,6 +3088,10 @@ shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
shortid@^2.2.8:
version "2.2.8"
resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.8.tgz#033b117d6a2e975804f6f0969dbe7d3d0b355131"
sigmund@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
@@ -3202,6 +3281,10 @@ supports-color@^3.1.0:
dependencies:
has-flag "^1.0.0"
svg-tag-names@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/svg-tag-names/-/svg-tag-names-1.1.0.tgz#24c04db37f2ee2ee28bc619f4e8a25ee21fc0203"
tapable@^0.2.5, tapable@~0.2.5:
version "0.2.6"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.6.tgz#206be8e188860b514425375e6f1ae89bfb01fd8d"
@@ -3362,6 +3445,12 @@ w3c-blob@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/w3c-blob/-/w3c-blob-0.0.1.tgz#b0cd352a1a50f515563420ffd5861f950f1d85b8"
warning@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
dependencies:
loose-envify "^1.0.0"
watchpack@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.3.1.tgz#7d8693907b28ce6013e7f3610aa2a1acf07dad87"