badgen.net/pages/builder.js

47 wiersze
1.3 KiB
JavaScript
Czysty Zwykły widok Historia

2018-09-04 07:00:54 +00:00
import React from 'react'
2018-09-13 06:21:46 +00:00
import Preview from '../components/builder-preview.js'
import Bar from '../components/builder-bar.js'
import Helper from '../components/builder-helper.js'
export default class BuilderPage extends React.Component {
state = {
host: undefined,
badgeURL: '',
placeholder: ''
}
setBadgeURL = badgeURL => this.setState({ badgeURL })
selectExample = exampleURL => this.setState({ badgeURL: exampleURL })
componentDidMount () {
const forceHost = new URL(window.location).searchParams.get('host')
const autoHost = window.location.host === 'flat.badgen.net'
? 'https://flat.badgen.net'
: 'https://badgen.net'
this.setState({
host: (forceHost || autoHost) + '/',
placeholder: 'badge/:subject/:status/:color'
})
}
2018-09-04 07:00:54 +00:00
render () {
2018-09-13 06:21:46 +00:00
const { host, placeholder, badgeURL } = this.state
2018-09-06 09:54:28 +00:00
return (
<div>
2018-09-13 06:21:46 +00:00
<Preview host={host} badgeURL={badgeURL} />
<Bar host={host} badgeURL={badgeURL} placeholder={placeholder} onChange={this.setBadgeURL} />
<Helper host={host} badgeURL={badgeURL} onSelect={this.selectExample} />
2018-09-06 09:54:28 +00:00
<style jsx>{`
div {
height: 100%;
2018-09-13 06:21:46 +00:00
display: flex;
flex-direction: column;
align-items: center;
2018-09-06 09:54:28 +00:00
}
`}</style>
</div>
)
2018-09-04 07:00:54 +00:00
}
}