Skip to content
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

Merged
merged 7 commits into from
Oct 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/app/Components/ComponentDoc/ComponentProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default class ComponentProps extends Component {
};

nameRenderer(item) {
const required = item.required && <span className='ui mini red circular label'>required</span>;
return <div>{item.name} {required}</div>;
const required = item.required && <span className='ui empty mini red circular label' />;
return <code>{item.name} {required}</code>;
Copy link
Member Author

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.

}

defaultValueRenderer(item) {
Expand Down Expand Up @@ -57,7 +57,7 @@ export default class ComponentProps extends Component {
});

return (
<Segment className='vertical'>
<Segment className='basic vertical'>
<h2 className='ui header'>Props</h2>
<Table data={content} className='very basic'>
<TableColumn dataKey='name' cellRenderer={this.nameRenderer} />
Expand Down
17 changes: 17 additions & 0 deletions docs/app/Examples/collections/Form/Content/FormContentExamples.js
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

);
}
}
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The 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

);
}
}
22 changes: 22 additions & 0 deletions docs/app/Examples/collections/Form/FormExamples.js
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

);
}
}
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

);
}
}
17 changes: 17 additions & 0 deletions docs/app/Examples/collections/Form/States/FormStatesExamples.js
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

);
}
}
21 changes: 21 additions & 0 deletions docs/app/Examples/collections/Form/Types/FormFormExample.js
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>
);
}
}
17 changes: 17 additions & 0 deletions docs/app/Examples/collections/Form/Types/FormTypesExamples.js
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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

);
}
}
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default config => {
config.set({
browsers: ['PhantomJS'],
singleRun: !ENV.isDevelopment(),
reporters: ['mocha'],
reporters: [ENV.isDevelopment() ? 'mocha' : 'dots'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the mocha reporter when in development (running local) and dots otherwise.

files: [
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
'./test/tests.bundle.js'
Expand Down
45 changes: 45 additions & 0 deletions src/collections/Form/Fields.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,
Copy link
Member Author

Choose a reason for hiding this comment

The 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, fieldCount.

this.props.className,
'fields'
);
const props = getUnhandledProps(this);
return (
<div {...props} className={classes}>
{this.props.children}
</div>
);
}
}
8 changes: 2 additions & 6 deletions src/elements/Image/Image.js
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';
Expand All @@ -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} />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing lint errors.

</div>
);
}
Expand Down
10 changes: 4 additions & 6 deletions src/elements/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup

ref: PropTypes.string,
};
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 4 additions & 1 deletion src/elements/List/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import META from 'src/utils/Meta';

export default class List extends Component {
static propTypes = {
children: PropTypes.node,
className: PropTypes.string,
};

Expand All @@ -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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List was missing children.

);
}
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Textarea from 'src/addons/Textarea/Textarea';
// Collections
import Column from 'src/collections/Grid/Column';
import Field from 'src/collections/Form/Field';
import Fields from 'src/collections/Form/Fields';
import Form from 'src/collections/Form/Form';
import Grid from 'src/collections/Grid/Grid';
import Row from 'src/collections/Grid/Row';
Expand Down Expand Up @@ -43,6 +44,7 @@ export default {
// Collections
Column,
Field,
Fields,
Form,
Grid,
Row,
Expand Down
Loading