badgen.net/pages/builder.js

63 wiersze
1.7 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'
2018-10-19 05:06:41 +00:00
import Hints from '../components/builder-hints.js'
2018-09-13 06:21:46 +00:00
import Helper from '../components/builder-helper.js'
import Footer from '../components/footer.js'
2018-09-13 06:21:46 +00:00
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
}
2019-08-24 08:24:46 +00:00
handleBlur = () => this.setState({ focus: false })
2019-07-12 02:20:56 +00:00
2019-08-24 08:24:46 +00:00
handleFocus = () => this.setState({ focus: true })
2019-07-12 02:20:56 +00:00
2019-08-24 08:24:46 +00:00
handleChange = badgeURL => this.setState({ badgeURL })
2019-07-12 02:20:56 +00:00
2019-08-24 08:24:46 +00:00
handleSelect = exampleURL => this.setState({ badgeURL: exampleURL })
2018-09-13 06:21:46 +00:00
componentDidMount () {
const forceHost = new URL(window.location).searchParams.get('host')
this.setState({
2019-06-03 02:57:14 +00:00
host: (forceHost || window.location.origin) + '/',
badgeURL: window.location.hash.replace(/^#/, ''),
2018-10-19 05:06:41 +00:00
placeholder: 'badge/:subject/:status/:color?icon=github'
2018-09-13 06:21:46 +00:00
})
}
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 (
2018-10-25 07:38:22 +00:00
<div className='home'>
<div className='hero'>
<Preview host={host} badgeURL={badgeURL} focus={focus} />
<Bar
host={host}
badgeURL={badgeURL}
placeholder={placeholder}
2019-08-24 08:24:46 +00:00
onChange={this.handleChange}
onBlur={this.handleBlur}
onFocus={this.handleFocus}
/>
<Hints focus={focus} badgeURL={badgeURL} />
2019-08-24 08:24:46 +00:00
{badgeURL && <Helper host={host} badgeURL={badgeURL} onSelect={this.handleSelect} />}
</div>
<Footer />
2018-09-06 09:54:28 +00:00
<style jsx>{`
.hero {
2018-10-26 07:19:09 +00:00
min-height: 100vh;
2018-10-25 07:38:22 +00:00
position: relative;
}
2019-08-24 08:24:46 +00:00
`}
</style>
2018-09-06 09:54:28 +00:00
</div>
)
2018-09-04 07:00:54 +00:00
}
}