-
Notifications
You must be signed in to change notification settings - Fork 392
Expand file tree
/
Copy pathModalBox.tsx
More file actions
72 lines (70 loc) · 2.51 KB
/
Copy pathModalBox.tsx
File metadata and controls
72 lines (70 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/ModalBox/modal-box';
import stylesAnimated from '@patternfly/react-styles/css/components/ModalAnimations/modal-animations';
import topSpacer from '@patternfly/react-tokens/dist/esm/c_modal_box_m_align_top_spacer';
export interface ModalBoxProps extends React.HTMLProps<HTMLDivElement> {
/** Id to use for the modal box description. This should match the ModalHeader labelId or descriptorId */
'aria-describedby'?: string;
/** Adds an accessible name to the modal when there is no title in the ModalHeader. */
'aria-label'?: string;
/** Id to use for the modal box label. */
'aria-labelledby'?: string;
/** Content rendered inside the modal box. */
children: React.ReactNode;
/** Additional classes added to the modal box. */
className?: string;
/** Position of the modal. By default a modal will be positioned vertically and horizontally centered. */
position?: 'default' | 'top';
/** Offset from alternate position. Can be any valid CSS length/percentage. */
positionOffset?: string;
/** Variant of the modal. */
variant?: 'small' | 'medium' | 'large' | 'default';
/** Flag indicating whether animations are enabled. */
hasAnimations?: boolean;
/** Flag to show the modal. */
isOpen?: boolean;
}
export const ModalBox: React.FunctionComponent<ModalBoxProps> = ({
children,
className,
variant = 'default',
position,
positionOffset,
'aria-labelledby': ariaLabelledby,
'aria-label': ariaLabel,
'aria-describedby': ariaDescribedby,
style,
isOpen,
hasAnimations,
...props
}: ModalBoxProps) => {
if (positionOffset) {
style = style || {};
(style as any)[topSpacer.name] = positionOffset;
}
return (
<div
role="dialog"
aria-label={ariaLabel || null}
aria-labelledby={ariaLabelledby || null}
aria-describedby={ariaDescribedby}
aria-modal="true"
className={css(
styles.modalBox,
hasAnimations && stylesAnimated.modalAnimated,
hasAnimations && isOpen === true && stylesAnimated.modalAnimatedOpen,
hasAnimations && isOpen !== true && stylesAnimated.modalAnimatedClosed,
className,
position === 'top' && styles.modifiers.alignTop,
variant === 'large' && styles.modifiers.lg,
variant === 'small' && styles.modifiers.sm,
variant === 'medium' && styles.modifiers.md
)}
style={style}
{...props}
>
{children}
</div>
);
};
ModalBox.displayName = 'ModalBox';