Skip to content

Commit

Permalink
fix(atoms): fix row direction in the form field
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed Jun 29, 2018
1 parent dd95b23 commit 6aed206
Show file tree
Hide file tree
Showing 4 changed files with 1,192 additions and 695 deletions.
22 changes: 15 additions & 7 deletions src/atoms/dataEntry/Form/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const theme = createTheme(name, {

const FormFieldTag = createStyledTag(name, props => ({
position: 'relative',
display: 'inline-flex',
width: props.stretch ? '100%' : 'auto',
}));

const FormFieldDirectionTag = createStyledTag(name, props => ({
display: 'inline-flex',
flexDirection: props.direction === 'row' ? 'row-reverse' : 'column',
alignItems: props.direction === 'row' ? 'center' : 'flex-start',
Expand Down Expand Up @@ -56,6 +61,7 @@ const FormField = ({
label,
children,
direction,
stretch,
hideErrorLabel,
...rest
}: FormFieldProps) => {
Expand All @@ -64,13 +70,15 @@ const FormField = ({
const hasLabel = !!label;

return (
<FormFieldTag { ...rest } direction={ direction } tagName="div">
<If condition={ hasLabel }>
<ControlLabelTag direction={ direction } tagName="div">
{ label }
</ControlLabelTag>
</If>
{ children }
<FormFieldTag { ...rest } stretch={ stretch } tagName="div">
<FormFieldDirectionTag direction={ direction } stretch={ stretch } tagName="div">
<If condition={ hasLabel }>
<ControlLabelTag direction={ direction } tagName="div">
{ label }
</ControlLabelTag>
</If>
{ children }
</FormFieldDirectionTag>
<If condition={ hasError && !hideErrorLabel }>
<ControlErrorWrapperTag tagName="div">
<ControlErrorTag tagName="span">{ error }</ControlErrorTag>
Expand Down
3 changes: 3 additions & 0 deletions src/atoms/dataEntry/Input/Input.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default (asStory) => {
.add('with stretch=false', () => (
<Input name="input" stretch={ false } onChange={ () => null } />
))
.add('with square=true', () => (
<Input name="input" square onChange={ () => null } />
))
.add('with left icon', () => (
<Input name="input" leftIcon="i" />
))
Expand Down
5 changes: 4 additions & 1 deletion src/atoms/dataEntry/InputField/InputField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default (asStory) => {
.add('with error', () => (
<InputField label="Input" input={{ name: 'input', onChange }} meta={{ error: 'Required', touched: true }} />
))
.add('with error and row direction', () => (
<InputField label="Input" direction="row" input={{ name: 'input', onChange }} meta={{ error: 'Required', touched: true }} />
))
.add('without label', () => (
<InputField input={{ name: 'input', onChange }} />
))
Expand All @@ -29,7 +32,7 @@ export default (asStory) => {
.add('with row direction', () => (
<InputField direction="row" label="Input" input={{ name: 'input', onChange }} />
))
.add('with row direction stretch=false', () => (
.add('with row direction and stretch=false', () => (
<InputField direction="row" stretch={ false } label="Input" input={{ name: 'input', onChange }} />
))
.add('with square input', () => (
Expand Down
Loading

0 comments on commit 6aed206

Please sign in to comment.