| 1 |
import { forwardRef } from 'react'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/Form/form'; |
| 3 |
import { css } from '@patternfly/react-styles'; |
| 4 |
import cssMaxWidth from '@patternfly/react-tokens/dist/esm/c_form_m_limit_width_MaxWidth'; |
| 5 |
|
| 6 |
export interface FormProps extends Omit<React.HTMLProps<HTMLFormElement>, 'ref'> { |
| 7 |
/** Anything that can be rendered as Form content. */ |
| 8 |
children?: React.ReactNode; |
| 9 |
/** Additional classes added to the Form. */ |
| 10 |
className?: string; |
| 11 |
/** Sets the Form to horizontal. */ |
| 12 |
isHorizontal?: boolean; |
| 13 |
/** Limits the max-width of the form. */ |
| 14 |
isWidthLimited?: boolean; |
| 15 |
/** Sets a custom max-width for the form. */ |
| 16 |
maxWidth?: string; |
| 17 |
/** @hide Forwarded ref */ |
| 18 |
innerRef?: React.Ref<any>; |
| 19 |
} |
| 20 |
|
| 21 |
const FormBase: React.FunctionComponent<FormProps> = ({ |
| 22 |
children = null, |
| 23 |
className = '', |
| 24 |
isHorizontal = false, |
| 25 |
isWidthLimited = false, |
| 26 |
maxWidth = '', |
| 27 |
innerRef, |
| 28 |
...props |
| 29 |
}: FormProps) => ( |
| 30 |
<form |
| 31 |
noValidate |
| 32 |
{...(maxWidth && { |
| 33 |
style: { |
| 34 |
[cssMaxWidth.name]: maxWidth, |
| 35 |
...props.style |
| 36 |
} as React.CSSProperties |
| 37 |
})} |
| 38 |
{...props} |
| 39 |
className={css( |
| 40 |
styles.form, |
| 41 |
isHorizontal && styles.modifiers.horizontal, |
| 42 |
(isWidthLimited || maxWidth) && styles.modifiers.limitWidth, |
| 43 |
className |
| 44 |
)} |
| 45 |
ref={innerRef} |
| 46 |
> |
| 47 |
{children} |
| 48 |
</form> |
| 49 |
); |
| 50 |
|
| 51 |
export const Form = forwardRef((props: FormProps, ref: React.Ref<any>) => <FormBase innerRef={ref} {...props} />); |
| 52 |
|
| 53 |
Form.displayName = 'Form'; |