2023-05-31 03:08:41 +00:00
|
|
|
import { ComponentType, PropsWithChildren } from 'react';
|
2023-05-31 05:58:41 +00:00
|
|
|
import clsx from 'clsx';
|
2021-11-23 05:16:50 +00:00
|
|
|
|
|
|
|
import { useInputGroupContext } from './InputGroup';
|
|
|
|
|
2023-05-31 05:58:41 +00:00
|
|
|
type BaseProps<TProps> = {
|
|
|
|
as?: ComponentType<TProps> | string;
|
|
|
|
required?: boolean;
|
|
|
|
};
|
|
|
|
|
2023-05-31 03:08:41 +00:00
|
|
|
export function InputGroupAddon<TProps>({
|
|
|
|
children,
|
|
|
|
as = 'span',
|
2023-05-31 05:58:41 +00:00
|
|
|
required,
|
2023-05-31 03:08:41 +00:00
|
|
|
...props
|
2023-05-31 05:58:41 +00:00
|
|
|
}: PropsWithChildren<BaseProps<TProps> & TProps>) {
|
2021-11-23 05:16:50 +00:00
|
|
|
useInputGroupContext();
|
2023-05-31 03:08:41 +00:00
|
|
|
const Component = as as 'span';
|
2021-11-23 05:16:50 +00:00
|
|
|
|
2023-05-31 03:08:41 +00:00
|
|
|
return (
|
2023-05-31 05:58:41 +00:00
|
|
|
<Component
|
|
|
|
className={clsx('input-group-addon', required && 'required')}
|
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
{...props}
|
|
|
|
>
|
2023-05-31 03:08:41 +00:00
|
|
|
{children}
|
|
|
|
</Component>
|
|
|
|
);
|
2021-11-23 05:16:50 +00:00
|
|
|
}
|