- {options !== undefined && options.closeButton === false ? null : (
+ {options.closeButton === false ? null : (
- {options !== undefined && options.title !== undefined && (
+ {options.title !== undefined && (
{options.title}
@@ -119,7 +120,7 @@ const Modal = ({
{renderBody()}
- {options && options.buttons && options.buttons.length > 0 && renderFooter()}
+ {options.buttons && options.buttons.length > 0 && renderFooter()}
@@ -127,12 +128,35 @@ const Modal = ({
) : null;
};
+Modal.propTypes = {
+ isModalVisible: PropTypes.bool.isRequired,
+ hide: PropTypes.func.isRequired,
+ options: PropTypes.shape({
+ onShow: PropTypes.func,
+ onHide: PropTypes.func,
+ onEscapeKeyDown: PropTypes.func,
+ onOverlayClick: PropTypes.func,
+ title: PropTypes.string,
+ message: PropTypes.string,
+ buttons: PropTypes.arrayOf(PropTypes.exact({
+ key: PropTypes.string,
+ content: PropTypes.any,
+ })),
+ closeButton: PropTypes.bool,
+ animated: PropTypes.bool,
+ centered: PropTypes.bool,
+ large: PropTypes.bool,
+ overlayClose: PropTypes.bool,
+ keyboardClose: PropTypes.bool,
+ }).isRequired,
+};
+
const Modali = () => {};
Modali.Button = Button;
Modali.Modal = Modal;
export default Modali;
-export const useModali = (options) => {
+export const useModali = (options = {}) => {
const [hasToggledBefore, setHasToggledBefore] = useState(false);
const [isModalVisible, setIsModalVisible] = useState(false);
const [isShown, setIsShown] = useState(false);
@@ -150,23 +174,23 @@ export const useModali = (options) => {
}
function handleKeyDown(event) {
- if (event.keyCode !== 27 || (options && options.keyboardClose === false)) return;
+ if (event.keyCode !== 27 || (options.keyboardClose === false)) return;
toggle();
- if (options && options.onEscapeKeyDown) {
+ if (options.onEscapeKeyDown) {
options.onEscapeKeyDown();
}
}
useEffect(() => {
if (isShown) {
- if (options && options.onShow) {
+ if (options.onShow) {
options.onShow();
}
document.addEventListener('keydown', handleKeyDown);
document.body.classList.add('modali-open');
}
if (!isShown && hasToggledBefore) {
- if (options && options.onHide) {
+ if (options.onHide) {
options.onHide();
}
document.body.classList.remove('modali-open');