mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-22 22:16:13 -04:00
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import classNames from 'classnames';
|
|
import React, { Children, ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
import { Size } from 'Helpers/Props/sizes';
|
|
import styles from './FormGroup.css';
|
|
|
|
interface FormGroupProps extends ComponentPropsWithoutRef<'div'> {
|
|
className?: string;
|
|
children: ReactNode;
|
|
size?: Extract<Size, keyof typeof styles>;
|
|
advancedSettings?: boolean;
|
|
isAdvanced?: boolean;
|
|
}
|
|
|
|
function FormGroup(props: FormGroupProps) {
|
|
const {
|
|
className = styles.group,
|
|
children,
|
|
size = 'small',
|
|
advancedSettings = false,
|
|
isAdvanced = false,
|
|
...otherProps
|
|
} = props;
|
|
|
|
if (!advancedSettings && isAdvanced) {
|
|
return null;
|
|
}
|
|
|
|
const childProps = isAdvanced ? { isAdvanced } : {};
|
|
|
|
return (
|
|
<div className={classNames(className, styles[size])} {...otherProps}>
|
|
{Children.map(children, (child) => {
|
|
if (!React.isValidElement(child)) {
|
|
return child;
|
|
}
|
|
|
|
return React.cloneElement(child, childProps);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default FormGroup;
|