import React from 'react';
import { default as Box, IBoxProps } from '../Box';
import type { IInputProps } from '../Input';
import { getAttachedChildren } from '../../../utils';
import { useColorModeValue } from '../../../core/color-mode/hooks';
import Flex from '../Flex';
import { themeTools } from '../../../theme';
export const InputLeftAddon = React.memo((props: IBoxProps & IInputProps) => {
const addonsDefaultStyle = {
p: 3,
borderColor: useColorModeValue('gray.300', 'gray.600'),
borderWidth: 1,
};
return (
{props.children}
);
});
export const InputRightAddon = React.memo((props: IBoxProps & IInputProps) => {
const addonsDefaultStyle = {
p: 3,
borderColor: useColorModeValue('gray.300', 'gray.600'),
borderWidth: 1,
};
return (
{props.children}
);
});
type InputGroupProps = IBoxProps & {
children: JSX.Element | JSX.Element[];
variant?: string;
size?: string;
};
const supplyPropsToChildren = (children: any, props: any) => {
return React.Children.map(children, (child: JSX.Element) => {
return React.cloneElement(child, props, child.props.children);
});
};
export const InputGroup = React.memo(
React.forwardRef(({ children, ...props }: InputGroupProps, ref: any) => {
let [layoutProps, remProps] = themeTools.extractInObject(props, [
'w',
'width',
'm',
'mr',
'ml',
'mt',
'mb',
'mx',
'my',
]);
return (
{supplyPropsToChildren(getAttachedChildren(children), remProps)}
);
})
);