Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/Modal/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BBBTypography } from '../Typography';
import { MdClose } from 'react-icons/md';
import { BBBDivider } from '../Divider';
import { ModalProps } from './types';
import { MODAL_PRIORITY_Z_INDEX } from './constants';
import { BBButton } from '../..';

/**
Expand All @@ -13,6 +14,8 @@ import { BBButton } from '../..';
* This component provides a customizable modal with optional title, body, and footer.
* It supports accessibility, dividers, scrollable body, and sticky footer.
*
* Use the `priority` prop to control z-index stacking when multiple modals
* coexist: `'low'` (1001), `'medium'` (1002), `'high'` (1003).
*/
const Modal: React.FC<ModalProps> = ({
isOpen = true,
Expand All @@ -28,16 +31,25 @@ const Modal: React.FC<ModalProps> = ({
footerContent = null,
stickyFooter = true,
children,
priority,
...rest
}) => {
const overlayStyle = priority
? { ...Styled.modalStyles.overlay, zIndex: MODAL_PRIORITY_Z_INDEX[priority] }
: Styled.modalStyles.overlay;

const modalStyles = {
overlay: overlayStyle,
content: Styled.modalStyles.content,
};

return (
<ReactModal
{...rest}
isOpen={isOpen}
onRequestClose={onRequestClose}
contentLabel={contentLabel}
style={Styled.modalStyles}
style={modalStyles}
shouldCloseOnOverlayClick={shouldCloseOnOverlayClick}
shouldCloseOnEsc={shouldCloseOnEsc}
appElement={appElement}
Expand Down
11 changes: 11 additions & 0 deletions src/components/Modal/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const MODAL_PRIORITIES = {
LOW: 'low',
MEDIUM: 'medium',
HIGH: 'high',
} as const;
export const MODAL_PRIORITY_VALUES = Object.values(MODAL_PRIORITIES);
export const MODAL_PRIORITY_Z_INDEX: Record<typeof MODAL_PRIORITY_VALUES[number], number> = {
low: 1001,
medium: 1002,
high: 1003,
};
2 changes: 2 additions & 0 deletions src/components/Modal/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default as BBBModal } from './component';
export type { ModalPriority } from './types';
export { MODAL_PRIORITIES, MODAL_PRIORITY_VALUES, MODAL_PRIORITY_Z_INDEX } from './constants';
14 changes: 13 additions & 1 deletion src/components/Modal/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react';
import ReactModal from 'react-modal';
import { MODAL_PRIORITY_VALUES } from './constants';

export type ModalPriority = typeof MODAL_PRIORITY_VALUES[number];


export interface StyledModalBodyProps {
$allowScroll: boolean;
Expand All @@ -19,4 +22,13 @@ export interface ModalProps extends Omit<ReactModal.Props, 'style'> {
stickyFooter?: boolean;
footerContent?: React.ReactNode;
children: React.ReactNode;
/**
* Controls z-index when multiple modals coexist.
* - `low` → z-index 1001
* - `medium` → z-index 1002
* - `high` → z-index 1003
*
* When omitted the default overlay z-index (100) is used.
*/
priority?: ModalPriority;
}
3 changes: 2 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export { BBButton } from './Button';
export { BBBCheckbox } from './Checkbox';
export { BBBDivider } from './Divider';
export { BBBHint } from './Hint';
export { BBBModal } from './Modal';
export { BBBModal, MODAL_PRIORITY_Z_INDEX } from './Modal';
export type { ModalPriority } from './Modal';
export { BBBNavigation } from './Navigation';
export { BBBSelect } from './Select';
export { BBBSpinner } from './Spinner';
Expand Down
Loading