| 1 |
import { css } from '@patternfly/react-styles'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/ModalBox/modal-box'; |
| 3 |
import topSpacer from '@patternfly/react-tokens/dist/esm/c_modal_box_m_align_top_spacer'; |
| 4 |
|
| 5 |
export interface ModalBoxProps extends React.HTMLProps<HTMLDivElement> { |
| 6 |
/** Id to use for the modal box description. This should match the ModalHeader labelId or descriptorId */ |
| 7 |
'aria-describedby'?: string; |
| 8 |
/** Adds an accessible name to the modal when there is no title in the ModalHeader. */ |
| 9 |
'aria-label'?: string; |
| 10 |
/** Id to use for the modal box label. */ |
| 11 |
'aria-labelledby'?: string; |
| 12 |
/** Content rendered inside the modal box. */ |
| 13 |
children: React.ReactNode; |
| 14 |
/** Additional classes added to the modal box. */ |
| 15 |
className?: string; |
| 16 |
/** Position of the modal. By default a modal will be positioned vertically and horizontally centered. */ |
| 17 |
position?: 'default' | 'top'; |
| 18 |
/** Offset from alternate position. Can be any valid CSS length/percentage. */ |
| 19 |
positionOffset?: string; |
| 20 |
/** Variant of the modal. */ |
| 21 |
variant?: 'small' | 'medium' | 'large' | 'default'; |
| 22 |
} |
| 23 |
|
| 24 |
export const ModalBox: React.FunctionComponent<ModalBoxProps> = ({ |
| 25 |
children, |
| 26 |
className, |
| 27 |
variant = 'default', |
| 28 |
position, |
| 29 |
positionOffset, |
| 30 |
'aria-labelledby': ariaLabelledby, |
| 31 |
'aria-label': ariaLabel, |
| 32 |
'aria-describedby': ariaDescribedby, |
| 33 |
style, |
| 34 |
...props |
| 35 |
}: ModalBoxProps) => { |
| 36 |
if (positionOffset) { |
| 37 |
style = style || {}; |
| 38 |
(style as any)[topSpacer.name] = positionOffset; |
| 39 |
} |
| 40 |
return ( |
| 41 |
<div |
| 42 |
role="dialog" |
| 43 |
aria-label={ariaLabel || null} |
| 44 |
aria-labelledby={ariaLabelledby || null} |
| 45 |
aria-describedby={ariaDescribedby} |
| 46 |
aria-modal="true" |
| 47 |
className={css( |
| 48 |
styles.modalBox, |
| 49 |
className, |
| 50 |
position === 'top' && styles.modifiers.alignTop, |
| 51 |
variant === 'large' && styles.modifiers.lg, |
| 52 |
variant === 'small' && styles.modifiers.sm, |
| 53 |
variant === 'medium' && styles.modifiers.md |
| 54 |
)} |
| 55 |
style={style} |
| 56 |
{...props} |
| 57 |
> |
| 58 |
{children} |
| 59 |
</div> |
| 60 |
); |
| 61 |
}; |
| 62 |
ModalBox.displayName = 'ModalBox'; |