import React, { Fragment } from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { staticBadgeUrl } from '../lib/badge-url'
import { advertisedStyles, logos } from '../../supported-features.json'
import StaticBadgeMaker from './static-badge-maker'
import DynamicBadgeMaker from './dynamic-badge-maker'
import { H2, H3, Badge, VerticalSpace } from './common'
import { Snippet, StyledCode } from './snippet'
const LogoName = styled.span`
white-space: nowrap;
`
const Lhs = styled.td`
text-align: right;
`
const EscapingRuleTable = styled.table`
margin: auto;
`
const QueryParamTable = styled.table`
min-width: 50%;
margin: auto;
table-layout: fixed;
border-spacing: 20px 10px;
`
const QueryParamSyntax = styled.td`
max-width: 300px;
text-align: left;
`
const QueryParamDocumentation = styled.td`
max-width: 600px;
text-align: left;
`
const QueryParam = ({ snippet, documentation }) => (
{documentation}
)
QueryParam.propTypes = {
snippet: PropTypes.string.isRequired,
documentation: PropTypes.element.isRequired,
}
const EscapingConversion = ({ lhs, rhs }) => (
{lhs}
| → |
{rhs} |
)
EscapingConversion.propTypes = {
lhs: PropTypes.element.isRequired,
rhs: PropTypes.element.isRequired,
}
export default class Usage extends React.PureComponent {
static propTypes = {
baseUrl: PropTypes.string.isRequired,
}
renderColorExamples() {
const { baseUrl } = this.props
const colors = [
'brightgreen',
'green',
'yellowgreen',
'yellow',
'orange',
'red',
'lightgrey',
'blue',
'ff69b4',
]
return (
{colors.map((color, i) => (
))}
)
}
renderStyleExamples() {
const { baseUrl } = this.props
return (
{advertisedStyles.map(style => {
const snippet = `?style=${style}&logo=appveyor`
const badgeUrl = staticBadgeUrl(baseUrl, 'style', style, 'green', {
logo: 'appveyor',
style,
})
return (
}
/>
)
})}
)
}
static renderNamedLogos() {
const renderLogo = logo => {logo}
const [first, ...rest] = logos
return [renderLogo(first)].concat(
rest.reduce((result, logo) => result.concat([', ', renderLogo(logo)]), [])
)
}
static renderStaticBadgeEscapingRules() {
return (
Dashes --
}
rhs={
- Dash
}
/>
Underscores __
}
rhs={
_ Underscore
}
/>
_ or Space
}
rhs={
Space
}
/>
)
}
render() {
const { baseUrl } = this.props
return (
Your Badge
Static
--.svg`}
/>
{this.constructor.renderStaticBadgeEscapingRules()}
{this.renderColorExamples()}
Dynamic
{baseUrl}
/badge/dynamic/json.svg?url=<URL>&label=<LABEL>&query=<
$.DATA.SUBDATA
>&colorB=<COLOR>&prefix=<PREFIX>&suffix=<SUFFIX>
{baseUrl}
/badge/dynamic/xml.svg?url=<URL>&label=<LABEL>&query=<
//data/subdata
>&colorB=<COLOR>&prefix=<PREFIX>&suffix=<SUFFIX>
{baseUrl}
/badge/dynamic/yaml.svg?url=<URL>&label=<LABEL>&query=<
$.DATA.SUBDATA
>&colorB=<COLOR>&prefix=<PREFIX>&suffix=<SUFFIX>
Styles
The following styles are available. Flat is the default. Examples are
shown with an optional logo:
{this.renderStyleExamples()}
Here are a few other parameters you can use: (connecting several with
"&" is possible)
Override the default left-hand-side text (
URL-Encoding
{} needed for spaces or special characters!)
}
/>
Insert one of the named logos from (
{this.constructor.renderNamedLogos()}) or{' '}
simple-icons
}
/>
Insert custom logo image (≥ 14px high)
}
/>
Set the color of the logo (hex, rgb, rgba, hsl, hsla and css
named colors supported)
}
/>
Set the horizontal space to give to the logo
}
/>
Specify what clicking on the left/right of a badge should do
(esp. for social badge style)
}
/>
Set background of the left part (hex, rgb, rgba, hsl, hsla and
css named colors supported)
}
/>
Set background of the right part (hex, rgb, rgba, hsl, hsla
and css named colors supported)
}
/>
Set the HTTP cache lifetime in secs (rules are applied to
infer a default value on a per-badge basis, any values
specified below the default will be ignored)
}
/>
We support .svg, .json, .png{' '}
and a few others, but use them responsibly.
)
}
}