File size: 1,334 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
// @flow
import * as React from "react";
import cn from "classnames";
import Form from "./Form.react";
import FormInputGroupAppend from "./FormInputGroupAppend.react";
import FormInputGroupPrepend from "./FormInputGroupPrepend.react";
import type { Props as InputProps } from "./FormInput.react";
type Props = {|
+children?: React.Node,
+className?: string,
+append?: React.Node,
+prepend?: React.Node,
+RootComponent?: React.ElementType,
+inputProps?: InputProps,
|};
function FormInputGroup(props: Props): React.Node {
const { className, append, prepend, RootComponent, inputProps } = props;
const classes = cn(
{
"input-group": true,
},
className
);
const Component = RootComponent || "div";
const children = inputProps ? <Form.Input {...inputProps} /> : props.children;
if (prepend === true) {
return <FormInputGroupPrepend>{children}</FormInputGroupPrepend>;
}
if (append === true) {
return <FormInputGroupAppend>{children}</FormInputGroupAppend>;
}
return (
<Component className={classes}>
{prepend && <FormInputGroupPrepend>{prepend}</FormInputGroupPrepend>}
{children}
{append && <FormInputGroupAppend>{append}</FormInputGroupAppend>}
</Component>
);
}
FormInputGroup.displayName = "Form.InputGroup";
export default FormInputGroup;
|