badgen.net/pages-/builder.tsx

63 wiersze
1.7 KiB
TypeScript
Czysty Zwykły widok Historia

2018-09-04 07:00:54 +00:00
import React from 'react'
2019-10-04 12:45:52 +00:00
import Preview from '../components/builder-preview'
import Bar from '../components/builder-bar'
import Hints from '../components/builder-hints'
import Helper from '../components/builder-helper'
import Footer from '../components/footer'
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 () {
2019-10-04 13:44:20 +00:00
const forceHost = new URL(window.location.href).searchParams.get('host')
2018-09-13 06:21:46 +00:00
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
}
}