fix: standarize form field UI

This commit is contained in:
Ahmad Abdolsaheb
2019-02-15 17:52:45 +03:00
committed by Valeriy
parent e727acb281
commit 4edd995c76
4 changed files with 36 additions and 57 deletions

View File

@ -6,11 +6,10 @@ import {
Col, Col,
ControlLabel, ControlLabel,
FormControl, FormControl,
FormGroup,
HelpBlock HelpBlock
} from '@freecodecamp/react-bootstrap'; } from '@freecodecamp/react-bootstrap';
import './form-fields.css';
const propTypes = { const propTypes = {
errors: PropTypes.objectOf(PropTypes.string), errors: PropTypes.objectOf(PropTypes.string),
fields: PropTypes.objectOf( fields: PropTypes.objectOf(
@ -48,15 +47,12 @@ function FormFields(props) {
const key = kebabCase(name); const key = kebabCase(name);
const type = name in types ? types[name] : 'text'; const type = name in types ? types[name] : 'text';
return ( return (
<div className='inline-form-field' key={key}> <Col key={key} xs={12}>
<Col sm={3} xs={12}> <FormGroup>
{type === 'hidden' ? null : ( {type === 'hidden' ? null : (
<ControlLabel htmlFor={key}>{startCase(name)}</ControlLabel> <ControlLabel htmlFor={key}>{startCase(name)}</ControlLabel>
)} )}
</Col>
<Col sm={9} xs={12}>
<FormControl <FormControl
bsSize='lg'
componentClass={type === 'textarea' ? type : 'input'} componentClass={type === 'textarea' ? type : 'input'}
id={key} id={key}
name={name} name={name}
@ -72,8 +68,8 @@ function FormFields(props) {
<Alert bsStyle='danger'>{errors[name]}</Alert> <Alert bsStyle='danger'>{errors[name]}</Alert>
</HelpBlock> </HelpBlock>
) : null} ) : null}
</Col> </FormGroup>
</div> </Col>
); );
})} })}
</div> </div>

View File

@ -11,10 +11,10 @@ exports[`<DynamicForm /> snapshot 1`] = `
> >
<div> <div>
<div <div
className="inline-form-field" className="col-xs-12"
> >
<div <div
className="col-sm-3 col-xs-12" className="form-group"
> >
<label <label
className="control-label" className="control-label"
@ -22,12 +22,8 @@ exports[`<DynamicForm /> snapshot 1`] = `
> >
Name Name
</label> </label>
</div>
<div
className="col-sm-9 col-xs-12"
>
<input <input
className="form-control input-lg" className="form-control"
id="name" id="name"
name="name" name="name"
onChange={[Function]} onChange={[Function]}

View File

@ -1,6 +0,0 @@
.inline-form-field {
height: 100%;
display: flex;
align-items: center;
margin-bottom: 5px;
}

View File

@ -161,42 +161,35 @@ export class BackEnd extends Component {
<LearnLayout> <LearnLayout>
<Grid> <Grid>
<Row> <Row>
<Col xs={12}> <Col md={8} mdOffset={2} sm={10} smOffset={1} xs={12} >
<Spacer /> <Spacer />
<div> <ChallengeTitle>{blockNameTitle}</ChallengeTitle>
<ChallengeTitle>{blockNameTitle}</ChallengeTitle> <ChallengeDescription
<ChallengeDescription description={description}
description={description} instructions={instructions}
instructions={instructions} />
/> <Form
</div> buttonText={buttonCopy + '(Ctrl + Enter)'}
<div> formFields={formFields}
<Form id={backendNS}
buttonText={buttonCopy + '(Ctrl + Enter)'} options={options}
formFields={formFields} submit={executeChallenge}
id={backendNS} />
options={options} <ProjectToolPanel guideUrl={createGuideUrl(slug)} />
submit={executeChallenge} <br />
/> <Output
<ProjectToolPanel guideUrl={createGuideUrl(slug)} /> defaultOutput={`/**
</div> *
<div> * Test output will go here
<br /> *
<Output *
defaultOutput={`/** */`}
* dimensions={this.state}
* Test output will go here height={150}
* output={output}
* />
*/`} <TestSuite tests={tests} />
dimensions={this.state}
height={150}
output={output}
/>
</div>
<div>
<TestSuite tests={tests} />
</div>
<Spacer /> <Spacer />
</Col> </Col>
<CompletionModal /> <CompletionModal />