-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from leandrohsilveira/select-branches-livedemo
Live demo improvement and fixes
- Loading branch information
Showing
17 changed files
with
443 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react' | ||
|
||
import axios from 'axios' | ||
|
||
export class AjaxGet extends React.Component { | ||
|
||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
data: null, | ||
cancelTokenSource: axios.CancelToken.source() | ||
} | ||
this.request = this.request.bind(this) | ||
this.handleRefresh = this.handleRefresh.bind(this) | ||
} | ||
|
||
componentWillMount() { | ||
const {url} = this.props | ||
this.request(url) | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const {url} = this.props | ||
if(nextProps.url !== url) this.handleRefresh(nextProps.url) | ||
} | ||
|
||
componentWillUnmount() { | ||
this.state.cancelTokenSource.cancel('Component\'s request source unmounted.') | ||
} | ||
|
||
request(url) { | ||
const {onError} = this.props | ||
const requestConfig = { | ||
cancelToken: this.state.cancelTokenSource.token | ||
} | ||
axios.get(url, requestConfig) | ||
.then(({data}) => this.setState(state => ({data}))) | ||
.catch(error => onError ? onError(error) : console.error(error)) | ||
} | ||
|
||
handleRefresh(url) { | ||
this.setState(state => { | ||
this.request(url) | ||
return {data: null} | ||
}) | ||
} | ||
|
||
render() { | ||
const {data} = this.state | ||
const {url, children} = this.props | ||
if(data) { | ||
return React.cloneElement(children, { ...children.props, data, refresh: () => this.handleRefresh(url) }) | ||
} | ||
return children | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
packages/react-formctrl-examples/src/components/badges.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React from 'react' | ||
|
||
import {AjaxGet} from './ajax' | ||
|
||
const SNYK_IO_URL = 'https://snyk.io/test/github/leandrohsilveira/react-formctrl/badge.svg' | ||
|
||
function parseKb(size) { | ||
return (size / 1024).toFixed(1) | ||
} | ||
|
||
function getMinifiedColor(size) { | ||
if(size < 20000) { | ||
return 'brightgreen' | ||
} else if(size < 30000) { | ||
return 'green' | ||
} else if(size < 35000) { | ||
return 'yellow' | ||
} else if(size < 40000) { | ||
return 'orange' | ||
} else { | ||
return 'red' | ||
} | ||
} | ||
|
||
function getGzippedColor(size) { | ||
if(size < 7000) { | ||
return 'brightgreen' | ||
} else if(size < 9000) { | ||
return 'green' | ||
} else if(size < 11000) { | ||
return 'yellow' | ||
} else if(size < 15000) { | ||
return 'orange' | ||
} else { | ||
return 'red' | ||
} | ||
} | ||
|
||
function ShieldsIoBadge({title, content, color, alt}) { | ||
const SHIELDS_IO_URL = 'https://img.shields.io/badge' | ||
return <img src={`${SHIELDS_IO_URL}/${title}-${content}-${color}.svg`} alt={alt} /> | ||
} | ||
|
||
function PackageSizesBadges({data}) { | ||
if(data) { | ||
const {minified, gzipped} = data | ||
return ( | ||
<span> | ||
<ShieldsIoBadge title="minified" content={`${parseKb(minified)} Kb`} color={getMinifiedColor(minified)} alt="Minified bundle size" /> | ||
<ShieldsIoBadge title="gzipped" content={`${parseKb(gzipped)} Kb`} color={getGzippedColor(gzipped)} alt="Gzipped bundle size" /> | ||
</span> | ||
) | ||
} | ||
return null | ||
} | ||
|
||
import "./badges.scss" | ||
|
||
export function AppBadges({branch = 'master'}) { | ||
return ( | ||
<div className="badges"> | ||
<a href={`https://travis-ci.org/leandrohsilveira/react-formctrl?branch=${branch}`}> | ||
<img src={`https://travis-ci.org/leandrohsilveira/react-formctrl.svg?branch=${branch}`} alt="Travis CI Status"/> | ||
</a> | ||
<a href={`https://coveralls.io/github/leandrohsilveira/react-formctrl?branch=${branch}`}> | ||
<img src={`https://coveralls.io/repos/github/leandrohsilveira/react-formctrl/badge.svg?branch=${branch}`} alt='Coverage Status' /> | ||
</a> | ||
<AjaxGet url="/packages.sizes.json"> | ||
<PackageSizesBadges /> | ||
</AjaxGet> | ||
<img src={`${SNYK_IO_URL}?targetFile=packages%2Freact-formctrl%2Fpackage.json`} alt="Known Vulnerabilities" /> | ||
|
||
</div> | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/react-formctrl-examples/src/components/badges.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.badges { | ||
|
||
a, | ||
img, | ||
span { | ||
margin: 0 3px; | ||
|
||
&:first-child { | ||
margin-left: 0; | ||
} | ||
&:last-child { | ||
margin-right: 0; | ||
} | ||
|
||
} | ||
|
||
|
||
} |
74 changes: 0 additions & 74 deletions
74
packages/react-formctrl-examples/src/components/bundle-size.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.markdown { | ||
|
||
> p:first-child { | ||
margin-top: 0; | ||
display: none; | ||
} | ||
|
||
table { | ||
|
Oops, something went wrong.