Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
feat(FormInput): add label prop
Browse files Browse the repository at this point in the history
a new label prop that when used wraps the input component in a
Form.Group with a label
  • Loading branch information
jonthomp committed May 31, 2018
1 parent 564c7dd commit 519d28d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/Form/FormInput.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as React from "react";
import { Icon } from "../";
import cn from "classnames";
import FormGroup from "./FormGroup.react";

type FormStyle = {|
+className?: string,
Expand Down Expand Up @@ -30,6 +31,10 @@ export type Props = {|
+placeholder?: string,
+type?: "checkbox" | "radio" | "text" | "email" | "password",
+value?: string | number | boolean,
/**
* Wraps the input in Form.Group and adds a label
*/
+label?: string,
|};

function FormInput(props: Props): React.Node {
Expand All @@ -50,6 +55,7 @@ function FormInput(props: Props): React.Node {
onBlur,
disabled,
readOnly,
label,
} = props;
const type = props.type || "text";

Expand Down Expand Up @@ -79,7 +85,7 @@ function FormInput(props: Props): React.Node {
onBlur,
};

return !icon ? (
const contents = !icon ? (
<React.Fragment>
{type === "checkbox" || type === "radio" ? (
<input {...allInputProps} checked={checked} />
Expand All @@ -106,6 +112,8 @@ function FormInput(props: Props): React.Node {
{feedback && <span className="invalid-feedback">{feedback}</span>}
</React.Fragment>
);

return label ? <FormGroup label={label}>{contents}</FormGroup> : contents;
}

FormInput.displayName = "Form.Input";
Expand Down

0 comments on commit 519d28d

Please sign in to comment.