Skip to content

Commit

Permalink
update(Modal): Add optional zIndex to props (#412)
Browse files Browse the repository at this point in the history
* [Modal] Add optional zIndex to props

* Lint

* Trigger Build

Co-authored-by: Nil Gradisnik <nil.gradisnik@airbnb.com>
  • Loading branch information
nilgradisnik and Nil Gradisnik authored Mar 15, 2021
1 parent abe339c commit 5fa4524
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 13 additions & 2 deletions packages/core/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import Portal from '../Portal';
import ModalInner, { ModalInnerProps } from './private/Inner';
import { ESCAPE } from '../../keys';
import { styleSheetModal } from './styles';
import { Z_INDEX_MODAL } from '../../constants';

export type ModalProps = ModalInnerProps & {
/** Custom style sheet. */
innerStyleSheet?: StyleSheet;
/** Z-index of the modal. */
zIndex?: number | 'auto';
};

/** A modal component with a backdrop and a standardized layout. */
export default function Modal({ onClose, styleSheet, innerStyleSheet, ...props }: ModalProps) {
export default function Modal({
onClose,
styleSheet,
innerStyleSheet,
zIndex,
...props
}: ModalProps) {
const [styles, cx] = useStyles(styleSheet ?? styleSheetModal);

const handleClose = (event: React.MouseEvent | React.KeyboardEvent) => {
Expand All @@ -32,9 +41,11 @@ export default function Modal({ onClose, styleSheet, innerStyleSheet, ...props }
};
}, []);

const containerZIndex = { zIndex: zIndex ?? Z_INDEX_MODAL };

return (
<Portal>
<div className={cx(styles.container)}>
<div className={cx(containerZIndex, styles.container)}>
<div role="presentation" className={cx(styles.wrapper)} onKeyUp={handleKeyUp}>
<ModalInner {...props} styleSheet={innerStyleSheet} onClose={onClose} />
</div>
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/components/Modal/styles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { StyleSheet } from '../../hooks/useStyles';
import { Z_INDEX_MODAL } from '../../constants';
import toRGBA from '../../utils/toRGBA';

export const MODAL_MAX_WIDTH_SMALL = 400;
Expand All @@ -14,7 +13,6 @@ export const styleSheetModal: StyleSheet = ({ unit, color }) => ({
position: 'fixed',
right: 0,
top: 0,
zIndex: Z_INDEX_MODAL,
},

wrapper: {
Expand Down

0 comments on commit 5fa4524

Please sign in to comment.