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

feat(Form): add unstackable prop #1921

Merged
merged 2 commits into from
Aug 10, 2017
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { Button, Form } from 'semantic-ui-react'

const FormExampleUnstackableGroup = () => (
<Form>
<Form.Group unstackable widths={2}>
<Form.Input label='First name' placeholder='First name' />
<Form.Input label='Last name' placeholder='Last name' />
</Form.Group>
<Form.Group widths={2}>
<Form.Input label='Address' placeholder='Address' />
<Form.Input label='Phone' placeholder='Phone' />
</Form.Group>
<Form.Checkbox label='I agree to the Terms and Conditions' />
<Button type='submit'>Submit</Button>
</Form>
)

export default FormExampleUnstackableGroup
5 changes: 5 additions & 0 deletions docs/app/Examples/collections/Form/GroupVariations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const FormGroupVariationsExamples = () => (
description='Multiple fields may be inline in a row.'
examplePath='collections/Form/GroupVariations/FormExampleInlineGroupedFields'
/>
<ComponentExample
title='Unstackable'
description='A form group can prevent itself from stacking on mobile, too.'
examplePath='collections/Form/GroupVariations/FormExampleUnstackableGroup'
/>
</ExampleSection>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'
import { Button, Form } from 'semantic-ui-react'

const FormExampleUnstackable = () => (
<Form unstackable>
<Form.Group widths={2}>
<Form.Input label='First name' placeholder='First name' />
<Form.Input label='Last name' placeholder='Last name' />
</Form.Group>
<Form.Checkbox label='I agree to the Terms and Conditions' />
<Button type='submit'>Submit</Button>
</Form>
)
export default FormExampleUnstackable
4 changes: 4 additions & 0 deletions docs/app/Examples/collections/Form/Variations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const FormFormVariationsExamples = () => (
description='A form on a dark background may have to invert its color scheme.'
examplePath='collections/Form/Variations/FormExampleInverted'
/>
<ComponentExample
description='A form can prevent itself from stacking on mobile.'
examplePath='collections/Form/Variations/FormExampleUnstackable'
/>
</ExampleSection>
)

Expand Down
3 changes: 3 additions & 0 deletions src/collections/Form/Form.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export interface FormProps {
/** Automatically show any success Message children. */
success?: boolean;

/** A form can prevent itself from stacking on mobile. */
unstackable?: boolean;

/** Automatically show any warning Message children. */
warning?: boolean;

Expand Down
7 changes: 6 additions & 1 deletion src/collections/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class Form extends Component {
/** Automatically show any success Message children. */
success: PropTypes.bool,

/** Automatically show any warning Message children . */
/** A form can prevent itself from stacking on mobile. */
unstackable: PropTypes.bool,

/** Automatically show any warning Message children. */
warning: PropTypes.bool,

/** Forms can automatically divide fields to be equal width. */
Expand Down Expand Up @@ -114,6 +117,7 @@ class Form extends Component {
reply,
size,
success,
unstackable,
warning,
widths,
} = this.props
Expand All @@ -126,6 +130,7 @@ class Form extends Component {
useKeyOnly(loading, 'loading'),
useKeyOnly(reply, 'reply'),
useKeyOnly(success, 'success'),
useKeyOnly(unstackable, 'unstackable'),
useKeyOnly(warning, 'warning'),
useWidthProp(widths, null, true),
'form',
Expand Down
3 changes: 3 additions & 0 deletions src/collections/Form/FormGroup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export interface FormGroupProps {
/** Multiple fields may be inline in a row. */
inline?: boolean;

/** A form group can prevent itself from stacking on mobile. */
unstackable?: boolean;

/** Fields Groups can specify their width in grid columns or automatically divide fields to be equal width. */
widths?: SemanticWIDTHS | 'equal';
}
Expand Down
5 changes: 5 additions & 0 deletions src/collections/Form/FormGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ function FormGroup(props) {
className,
grouped,
inline,
unstackable,
widths,
} = props

const classes = cx(
useKeyOnly(grouped, 'grouped'),
useKeyOnly(inline, 'inline'),
useKeyOnly(unstackable, 'unstackable'),
useWidthProp(widths, null, true),
'fields',
className,
Expand Down Expand Up @@ -66,6 +68,9 @@ FormGroup.propTypes = {
PropTypes.bool,
]),

/** A form group can prevent itself from stacking on mobile. */
unstackable: PropTypes.bool,

/** Fields Groups can specify their width in grid columns or automatically divide fields to be equal width. */
widths: PropTypes.oneOf([...SUI.WIDTHS, 'equal']),
}
Expand Down
1 change: 1 addition & 0 deletions test/specs/collections/Form/Form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Form', () => {
common.propKeyOnlyToClassName(Form, 'loading')
common.propKeyOnlyToClassName(Form, 'reply')
common.propKeyOnlyToClassName(Form, 'success')
common.propKeyOnlyToClassName(Form, 'unstackable')
common.propKeyOnlyToClassName(Form, 'warning')

common.propValueOnlyToClassName(Form, 'size', _.without(SUI.SIZES, 'medium'))
Expand Down
1 change: 1 addition & 0 deletions test/specs/collections/Form/FormGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ describe('FormGroup', () => {

common.propKeyOnlyToClassName(FormGroup, 'grouped')
common.propKeyOnlyToClassName(FormGroup, 'inline')
common.propKeyOnlyToClassName(FormGroup, 'unstackable')
})