mirror of
https://github.com/Radarr/Radarr.git
synced 2026-03-29 18:15:37 -04:00
Co-authored-by: Mark McDowall <mark@mcdowall.ca> Remove defaultProps from TypeScript components (cherry picked from commit a90c13e86f798841cb6db038bb6b6d1408a00585) Fix multi-select checkboxes not appearing (cherry picked from commit e199710c15fbfa643a9f71c7a20f70b1722d0df6)
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;
|