-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fields component and Form examples #94
Changes from all commits
bc0025d
f6e754a
182cbc9
0a80eb4
608a671
d946e79
921d8f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {Component} from 'react'; | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'; | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'; | ||
|
||
export default class FormTypesExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Content'> | ||
<ComponentExample | ||
title='Field' | ||
description='A field is a form element containing a label and an input.' | ||
examplePath='collections/Form/Content/FormFieldExample' | ||
/> | ||
</ExampleSection> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, {Component} from 'react'; | ||
import {Field, Form, Input} from 'stardust'; | ||
|
||
export default class FormFieldInlineExample extends Component { | ||
render() { | ||
return ( | ||
<Form> | ||
<Field label='First name' className='inline'> | ||
<Input placeholder='First name' /> | ||
</Field> | ||
</Form> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {Component} from 'react'; | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'; | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'; | ||
|
||
export default class FormFieldVariationsExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Field Variations'> | ||
<ComponentExample | ||
title='Inline' | ||
description='A field can have its label next to instead of above it.' | ||
examplePath='collections/Form/FieldVariations/FormFieldInlineExample' | ||
/> | ||
</ExampleSection> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forms can be large or small!? wat?! Oh here's the docs for it, http://semantic-ui.com/collections/form.html#size |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, {Component} from 'react'; | ||
import FormContentExamples from './Content/FormContentExamples'; | ||
import FormTypesExamples from './Types/FormTypesExamples'; | ||
import FormFieldVariationsExamples from './FieldVariations/FormFieldVariationsExamples'; | ||
import FormGroupVariationsExamples from './GroupVariations/FormGroupVariationsExamples'; | ||
import FormFormVariationsExamples from './FormVariations/FormFormVariationsExamples'; | ||
import FormStatesExamples from './States/FormStatesExamples'; | ||
|
||
export default class FormExamples extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<FormTypesExamples /> | ||
<FormContentExamples /> | ||
<FormStatesExamples /> | ||
<FormFormVariationsExamples /> | ||
<FormFieldVariationsExamples /> | ||
<FormGroupVariationsExamples /> | ||
</div> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, {Component} from 'react'; | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'; | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'; | ||
|
||
export default class FormFormVariationsExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Form Variations'> | ||
<ComponentExample | ||
title='Size' | ||
description='A form can also be small or large.' | ||
examplePath='collections/Form/FormVariations/FormSizeSmallExample' | ||
/> | ||
<ComponentExample | ||
examplePath='collections/Form/FormVariations/FormSizeLargeExample' | ||
/> | ||
</ExampleSection> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, {Component} from 'react'; | ||
import {Button, Field, Fields, Form, Input} from 'stardust'; | ||
|
||
export default class FormSizeLargeExample extends Component { | ||
render() { | ||
return ( | ||
<Form className='large'> | ||
<Fields> | ||
<Field label='First name'> | ||
<Input placeholder='First name' /> | ||
</Field> | ||
<Field label='Last name'> | ||
<Input placeholder='Last name' /> | ||
</Field> | ||
</Fields> | ||
<Button type='submit'>Submit</Button> | ||
</Form> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, {Component} from 'react'; | ||
import {Button, Field, Fields, Form, Input} from 'stardust'; | ||
|
||
export default class FormSizeSmallExample extends Component { | ||
render() { | ||
return ( | ||
<Form className='small'> | ||
<Fields> | ||
<Field label='First name'> | ||
<Input placeholder='First name' /> | ||
</Field> | ||
<Field label='Last name'> | ||
<Input placeholder='Last name' /> | ||
</Field> | ||
</Fields> | ||
<Button type='submit'>Submit</Button> | ||
</Form> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React, {Component} from 'react'; | ||
import {Field, Fields, Form, Input} from 'stardust'; | ||
|
||
export default class FormGroupEvenlyDividedExample extends Component { | ||
render() { | ||
return ( | ||
<Form> | ||
<Fields evenlyDivided> | ||
<Field label='First name'> | ||
<Input placeholder='First name' /> | ||
</Field> | ||
<Field label='Last name'> | ||
<Input placeholder='Last name' /> | ||
</Field> | ||
</Fields> | ||
</Form> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {Component} from 'react'; | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'; | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'; | ||
|
||
export default class FormGroupVariationsExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Group Variations'> | ||
<ComponentExample | ||
title='Evenly Divided' | ||
description='Fields can have their widths divided evenly.' | ||
examplePath='collections/Form/GroupVariations/FormGroupEvenlyDividedExample' | ||
/> | ||
</ExampleSection> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {Component} from 'react'; | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'; | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'; | ||
|
||
export default class FormStatesExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='States'> | ||
<ComponentExample | ||
title='Error' | ||
description='If a form is in an error state, it will automatically show any error message blocks.' | ||
examplePath='collections/Form/States/FormFieldErrorExample' | ||
/> | ||
</ExampleSection> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React, {Component} from 'react'; | ||
import {Button, Checkbox, Field, Form, Input} from 'stardust'; | ||
|
||
export default class FormFieldExample extends Component { | ||
render() { | ||
return ( | ||
<Form> | ||
<Field label='First Name'> | ||
<Input placeholder='First Name' /> | ||
</Field> | ||
<Field label='Last Name'> | ||
<Input placeholder='Last Name' /> | ||
</Field> | ||
<Field label='First Name'> | ||
<Checkbox label='I agree to the Terms and Conditions' /> | ||
</Field> | ||
<Button type='submit'>Submit</Button> | ||
</Form> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, {Component} from 'react'; | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection'; | ||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample'; | ||
|
||
export default class FormTypesExamples extends Component { | ||
render() { | ||
return ( | ||
<ExampleSection title='Types'> | ||
<ComponentExample | ||
title='Form' | ||
description='A form.' | ||
examplePath='collections/Form/Types/FormFormExample' | ||
/> | ||
</ExampleSection> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ export default config => { | |
config.set({ | ||
browsers: ['PhantomJS'], | ||
singleRun: !ENV.isDevelopment(), | ||
reporters: ['mocha'], | ||
reporters: [ENV.isDevelopment() ? 'mocha' : 'dots'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the |
||
files: [ | ||
'./node_modules/phantomjs-polyfill/bind-polyfill.js', | ||
'./test/tests.bundle.js' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import _ from 'lodash'; | ||
import React, {Children, Component, PropTypes} from 'react'; | ||
import classNames from 'classnames'; | ||
import getUnhandledProps from 'src/utils/getUnhandledProps'; | ||
import numberToWord from 'src/utils/numberToWord'; | ||
import META from 'src/utils/Meta.js'; | ||
|
||
export default class Fields extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
/** | ||
* Dynamically adds className='<count> fields'. | ||
*/ | ||
evenlyDivided: PropTypes.bool, | ||
}; | ||
|
||
static _meta = { | ||
library: META.library.semanticUI, | ||
name: 'Fields', | ||
parent: 'Form', | ||
type: META.type.collection, | ||
}; | ||
|
||
render() { | ||
let fieldCount = 0; | ||
Children.forEach(this.props.children, child => { | ||
_.get(child, 'type._meta.name') === 'Field' && fieldCount++; | ||
}); | ||
fieldCount = numberToWord(fieldCount); | ||
|
||
const classes = classNames( | ||
'sd-fields', | ||
this.props.evenlyDivided && fieldCount, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the && syntax here as the would be object key name is a variable, |
||
this.props.className, | ||
'fields' | ||
); | ||
const props = getUnhandledProps(this); | ||
return ( | ||
<div {...props} className={classes}> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import _ from 'lodash'; | ||
import React, {Component, PropTypes} from 'react'; | ||
import classNames from 'classnames'; | ||
import META from 'src/utils/Meta'; | ||
|
@@ -23,13 +22,10 @@ export default class Image extends Component { | |
this.props.className, | ||
'image' | ||
); | ||
const props = _.clone(this.props); | ||
delete props.src; | ||
delete props.alt; | ||
|
||
return ( | ||
<div {...props} className={classes}> | ||
<img src={this.props.src} alt={this.props.alt} /> | ||
<div className={classes}> | ||
<img {...this.props} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing lint errors. |
||
</div> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,12 @@ import _ from 'lodash'; | |
import classNames from 'classnames'; | ||
import React, {Component, PropTypes, Children} from 'react'; | ||
import META from 'src/utils/Meta'; | ||
import getUnhandledProps from 'src/utils/getUnhandledProps'; | ||
|
||
export default class Input extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
dataContent: PropTypes.string, | ||
defaultValue: PropTypes.string, | ||
icon: PropTypes.string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup |
||
ref: PropTypes.string, | ||
}; | ||
|
@@ -63,14 +62,13 @@ export default class Input extends Component { | |
this.props.className, | ||
'input' | ||
); | ||
const inputProps = _.clone(this.props); | ||
delete inputProps.className; | ||
delete inputProps.children; | ||
const props = getUnhandledProps(this); | ||
|
||
return ( | ||
<div className={classes}> | ||
{isLeftLabeled && labelChildren} | ||
{isLeftAction && actionChildren} | ||
<input {...inputProps} /> | ||
<input {...props} /> | ||
{this.props.icon && icon} | ||
{isRightLabeled && labelChildren} | ||
{isRightAction && actionChildren} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import META from 'src/utils/Meta'; | |
|
||
export default class List extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
}; | ||
|
||
|
@@ -16,7 +17,9 @@ export default class List extends Component { | |
render() { | ||
const classes = classNames('sd-list', 'ui', this.props.className, 'list'); | ||
return ( | ||
<div {...this.props} className={classes}></div> | ||
<div {...this.props} className={classes}> | ||
{this.props.children} | ||
</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. List was missing children. |
||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format props table to use monospace font and red dot for required.