badgen.net/pages/builder.js

51 wiersze
1.4 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: '',
2018-09-20 06:38:02 +00:00
placeholder: '',
focus: false
2018-09-13 06:21:46 +00:00
}
2018-09-20 06:38:02 +00:00
setFocus = () => this.state.focus || this.setState({ focus: true })
2018-09-13 06:21:46 +00:00
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-20 06:38:02 +00:00
const { host, placeholder, badgeURL, focus } = this.state
2018-09-13 06:21:46 +00:00
2018-09-06 09:54:28 +00:00
return (
<div>
2018-09-20 06:38:02 +00:00
<Preview host={host} badgeURL={badgeURL} focus={focus} />
2018-09-13 06:44:03 +00:00
<Bar
host={host}
badgeURL={badgeURL}
placeholder={placeholder}
2018-09-20 06:38:02 +00:00
onChange={this.setBadgeURL}
onFocus={this.setFocus} />
2018-09-13 06:21:46 +00:00
<Helper host={host} badgeURL={badgeURL} onSelect={this.selectExample} />
2018-09-06 09:54:28 +00:00
<style jsx>{`
div {
height: 100%;
}
`}</style>
</div>
)
2018-09-04 07:00:54 +00:00
}
}