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

Commit 34f95b2

Browse files
committed
feat(FormGroup): create input from prop
Adds ability to create Form.Group containing a Form.Input from the new prop
1 parent d2d4628 commit 34f95b2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/components/Form/FormGroup.react.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
import * as React from "react";
44
import cn from "classnames";
55
import FormLabel from "./FormLabel.react";
6+
import FormInput from "./FormInput.react";
7+
import type { Props as InputProps } from "./FormInput.react";
68

79
type Props = {|
810
+children?: React.Node,
911
+className?: string,
1012
+label?: React.Node,
1113
+isRequired?: boolean,
14+
+inputProps?: InputProps,
1215
|};
1316

1417
function FormGroup({
1518
className,
1619
children,
1720
label,
1821
isRequired,
22+
inputProps,
1923
}: Props): React.Node {
2024
const classes = cn("form-group", className);
25+
const inputComponent =
26+
inputProps && React.createElement(FormInput, inputProps);
2127
return (
2228
<div className={classes}>
2329
{!label ? null : typeof label === "string" ? (
@@ -28,7 +34,7 @@ function FormGroup({
2834
) : (
2935
label
3036
)}
31-
{children}
37+
{inputComponent || children}
3238
</div>
3339
);
3440
}

0 commit comments

Comments
 (0)