Skip to content

Commit

Permalink
Merge pull request #378 from appfolio/gtAddFormLabelGroup
Browse files Browse the repository at this point in the history
gt - Form label group additions
  • Loading branch information
choruk authored Apr 5, 2018
2 parents c8bf225 + 0482e35 commit 4a953c9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
28 changes: 25 additions & 3 deletions src/components/FormLabelGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ import PropTypes from 'prop-types';
import React from 'react';
import Col from './Col';
import FormGroup from './FormGroup';
import FormText from './FormText';
import FormFeedback from './FormFeedback';
import Label from './Label';
import Row from './Row';

const FormLabelGroup = props => {
const FormLabelGroup = (props) => {
const {
children,
color,
feedback,
inputId,
invalid,
hint,
label,
required,
rowClassName,
size,
stacked,
width
} = props;

const rowColor = color || (invalid && 'danger');
Expand All @@ -25,15 +31,19 @@ const FormLabelGroup = props => {
return (
<FormGroup row className={rowClassName} color={rowColor}>
{label && (
<Label for={inputId} sm={labelWidth} className={labelAlignment}>
<Label for={inputId} sm={labelWidth} size={size} className={labelAlignment}>
{label}
{required && label ? <span className="text-danger">&nbsp;*</span> : null}
</Label>
)}
<Col sm={inputContainerWidth}>
<Row>
{children}
<Col {...width}>
{children}
</Col>
</Row>
{hint && <FormText color="muted">{hint}</FormText>}
{feedback && <FormFeedback>{feedback}</FormFeedback>}
</Col>
</FormGroup>
);
Expand All @@ -42,16 +52,28 @@ const FormLabelGroup = props => {
FormLabelGroup.propTypes = {
children: PropTypes.node.isRequired,
color: PropTypes.string,
feedback: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object
]),
inline: PropTypes.bool,
inputId: PropTypes.string,
invalid: PropTypes.bool,
hint: PropTypes.string,
label: PropTypes.node,
required: PropTypes.bool,
rowClassName: PropTypes.string,
size: PropTypes.string,
stacked: PropTypes.bool,
width: PropTypes.object
};

FormLabelGroup.defaultProps = {
inline: false,
invalid: false,
required: false,
stacked: false,
width: { xs: 12 }
};

export default FormLabelGroup;
4 changes: 2 additions & 2 deletions src/components/FormRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function parseFeedback(feedback) {
[feedback, {}];
}

const FormRow = props => {
const FormRow = (props) => {
const {
children,
color,
Expand Down Expand Up @@ -74,7 +74,7 @@ const FormRow = props => {
)}
<Col sm={inputContainerWidth}>
<Row>
<Col {...width} >
<Col {...width}>
<InputElement
id={id}
size={size}
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Fade from './components/Fade';
import Form from './components/Form';
import FormFeedback from './components/FormFeedback';
import FormGroup from './components/FormGroup';
import FormLabelGroup from './components/FormLabelGroup';
import FormText from './components/FormText';
import Input from './components/Input';
import InputGroup from './components/InputGroup';
Expand Down Expand Up @@ -154,6 +155,7 @@ export {
Form,
FormFeedback,
FormGroup,
FormLabelGroup,
FormText,
Input,
InputGroup,
Expand Down
21 changes: 21 additions & 0 deletions stories/FormLabelGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { boolean, text, select } from '@storybook/addon-knobs';
import { AddressInput, FormLabelGroup } from '../src';

storiesOf('FormLabelGroup', module)
.addWithInfo('Live example', () => (
<div>
<FormLabelGroup
label={text('label', 'Some Input')}
feedback={text('feedback', 'You must give a first name')}
color={select('color', ['', 'success', 'warning', 'danger'], 'danger')}
hint={text('hint', '')}
required={boolean('required', false)}
inline={boolean('inline', false)}
stacked={boolean('stacked', false)}
>
<img alt="Sample" src="https://placeimg.com/320/240/tech" width="320" height="240" />
</FormLabelGroup>
</div>
));
1 change: 1 addition & 0 deletions stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import './FeatureBanner';
import './FilterList';
import './Flag';
import './FormRow';
import './FormLabelGroup';
import './Forms';
import './HasManyFields';
import './HelpBubble';
Expand Down

0 comments on commit 4a953c9

Please sign in to comment.