Skip to content

Commit

Permalink
Add placeholder support to <InputField />
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Palmer committed Jun 7, 2017
1 parent 5a370f1 commit af4b19f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
12 changes: 12 additions & 0 deletions components/Form/FormComponents.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@
width: auto;
}


.placeholder {
display: block;
composes: fontRegular from '../../globals/typography.css';
color: var(--color-greyLight);
text-align: center;
display: inline-block;
width: auto;
}

.error {
color: var(--color-danger);
}
Expand All @@ -63,6 +73,7 @@
* + .headline,
* + .label,
* + .value,
* + .placeholder,
* + .inputWrapper {
margin-top: var(--size-sm-ii);
}
Expand All @@ -74,6 +85,7 @@
.headline + .meta,
.headline + .description,
.headline + .value,
.headline + .placeholder,
.headline + .inputWrapper {
margin-top: var(--size-sm-i);
}
Expand Down
6 changes: 6 additions & 0 deletions components/Form/FormComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export const Value = ({ className, children }) => (
</span>
);

export const Placeholder = ({ className, children }) => (
<span className={ cx(css.placeholder, className) }>
{ children }
</span>
);

export const InputWrapper = ({ className, children }) => (
<div className={ cx(css.inputWrapper, className) }>
{ children }
Expand Down
4 changes: 4 additions & 0 deletions components/Form/FormComponents.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Description,
Label,
Value,
Placeholder,
} from './FormComponents';

const stories = storiesOf('FormComponents', module);
Expand Down Expand Up @@ -35,4 +36,7 @@ stories.add('Field', () => (
))
.add('Value', () => (
<Value>900sq ft - 1500 sq ft</Value>
))
.add('Placeholder', () => (
<Placeholder>Any size</Placeholder>
));
12 changes: 11 additions & 1 deletion components/Form/InputField/InputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Meta,
Label,
Value,
Placeholder,
Description,
InputWrapper,
} from '../FormComponents';
Expand All @@ -29,6 +30,7 @@ export default class InputField extends Component {
children: PropTypes.element,
error: PropTypes.node,
valueReplay: PropTypes.node,
placeholder: PropTypes.node,
required: PropTypes.bool,
optionalLabel: PropTypes.string,
};
Expand All @@ -49,6 +51,7 @@ export default class InputField extends Component {
classNames,
error,
valueReplay,
placeholder,
required,
optionalLabel,
...rest,
Expand All @@ -75,7 +78,14 @@ export default class InputField extends Component {
>
{ label }
</Label>
{ valueReplay && (
{ !valueReplay && placeholder ? (
<Placeholder
{ ...sharedProps }
className={ classNames.valueReplay }
>
{ placeholder }
</Placeholder>
) : (
<Value
{ ...sharedProps }
className={ classNames.valueReplay }
Expand Down
1 change: 1 addition & 0 deletions components/FunnelInputField/FunnelInputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ FunnelInputField.propTypes = {
meta: PropTypes.string,
label: PropTypes.string,
valueReplay: PropTypes.string,
placeholder: PropTypes.string,
description: PropTypes.string,
}),
valueReplay: PropTypes.any,
Expand Down

0 comments on commit af4b19f

Please sign in to comment.