Show the checkbox

This commit is contained in:
joshaber 2016-12-07 14:01:32 -05:00
parent 3cfe4dbb64
commit 3e4da8db0e

View file

@ -11,6 +11,7 @@ import { Form } from '../lib/form'
import { TextBox } from '../lib/text-box'
import { Button } from '../lib/button'
import { Row } from '../lib/row'
import { Checkbox, CheckboxValue } from '../lib/checkbox'
interface ICreateRepositoryProps {
readonly dispatcher: Dispatcher
@ -19,6 +20,7 @@ interface ICreateRepositoryProps {
interface ICreateRepositoryState {
readonly path: string
readonly name: string
readonly createWithREADME: boolean
}
/** The Create New Repository component. */
@ -26,17 +28,29 @@ export class CreateRepository extends React.Component<ICreateRepositoryProps, IC
public constructor(props: ICreateRepositoryProps) {
super(props)
this.state = { path: defaultPath(), name: '' }
this.state = {
path: defaultPath(),
name: '',
createWithREADME: false,
}
}
private onPathChanged = (event: React.FormEvent<HTMLInputElement>) => {
const path = event.currentTarget.value
this.setState({ path, name: this.state.name })
this.setState({
path,
name: this.state.name,
createWithREADME: this.state.createWithREADME,
})
}
private onNameChanged = (event: React.FormEvent<HTMLInputElement>) => {
const name = event.currentTarget.value
this.setState({ path: this.state.path, name })
this.setState({
path: this.state.path,
name,
createWithREADME: this.state.createWithREADME,
})
}
private showFilePicker = () => {
@ -44,7 +58,11 @@ export class CreateRepository extends React.Component<ICreateRepositoryProps, IC
if (!directory) { return }
const path = directory[0]
this.setState({ path, name: this.state.name })
this.setState({
path,
name: this.state.name,
createWithREADME: this.state.createWithREADME,
})
}
private createRepository = async () => {
@ -65,6 +83,14 @@ export class CreateRepository extends React.Component<ICreateRepositoryProps, IC
})
}
private onCreateWithREADMEChange = (event: React.FormEvent<HTMLInputElement>) => {
this.setState({
path: this.state.path,
name: this.state.name,
createWithREADME: event.currentTarget.checked,
})
}
private renderError() {
const sanitizedName = sanitizedRepositoryName(this.state.name)
if (this.state.name === sanitizedName) { return null }
@ -95,6 +121,11 @@ export class CreateRepository extends React.Component<ICreateRepositoryProps, IC
<Button onClick={this.showFilePicker}>Choose</Button>
</Row>
<Checkbox
label='Initialize this repository with a README'
value={this.state.createWithREADME ? CheckboxValue.On : CheckboxValue.Off}
onChange={this.onCreateWithREADMEChange}/>
<hr/>
<Button type='submit' disabled={disabled} onClick={this.createRepository}>