mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-22 22:16:13 -04:00
Convert Form Components to TypeScript
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user