diff --git a/packages/components/src/components/dialog/dialog.jsx b/packages/components/src/components/dialog/dialog.tsx similarity index 81% rename from packages/components/src/components/dialog/dialog.jsx rename to packages/components/src/components/dialog/dialog.tsx index 5111835762d9..eada85092e89 100644 --- a/packages/components/src/components/dialog/dialog.jsx +++ b/packages/components/src/components/dialog/dialog.tsx @@ -1,6 +1,5 @@ import React from 'react'; import classNames from 'classnames'; -import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import { CSSTransition } from 'react-transition-group'; import Icon from '../icon/icon'; @@ -8,19 +7,41 @@ import Button from '../button/button'; import Text from '../text'; import { useOnClickOutside } from '../../hooks'; +type TDialog = { + cancel_button_text?: string; + className?: string; + confirm_button_text?: string; + dismissable?: boolean; + disableApp?: () => void; + enableApp?: () => void; + has_close_icon?: boolean; + is_closed_on_cancel?: boolean; + is_closed_on_confirm?: boolean; + is_content_centered?: boolean; + is_loading?: boolean; + is_mobile_full_width?: boolean; + is_visible?: boolean; + onCancel?: () => void; + onClose?: () => void; + onConfirm: () => void; + onEscapeButtonCancel?: () => void; + portal_element_id?: string; + title?: string; +}; + const Dialog = ({ disableApp, dismissable, enableApp, - is_closed_on_cancel, - is_closed_on_confirm, + is_closed_on_cancel = true, + is_closed_on_confirm = true, is_visible, onCancel, onClose, onConfirm, onEscapeButtonCancel, ...other_props -}) => { +}: React.PropsWithChildren) => { const { cancel_button_text, className, @@ -34,7 +55,7 @@ const Dialog = ({ has_close_icon, } = other_props; - const wrapper_ref = React.useRef(); + const wrapper_ref = React.useRef() as React.MutableRefObject; React.useEffect(() => { if (is_visible && !!disableApp) { @@ -43,7 +64,7 @@ const Dialog = ({ }, [is_visible, disableApp]); React.useEffect(() => { - const close = e => { + const close = (e: { key: string }) => { if (e.key === 'Escape') { onEscapeButtonCancel?.(); } @@ -57,7 +78,7 @@ const Dialog = ({ if (is_closed_on_cancel && enableApp) { enableApp(); } - onCancel(); + onCancel?.(); }; const handleConfirm = () => { @@ -84,8 +105,10 @@ const Dialog = ({ const content_classes = classNames('dc-dialog__content', { 'dc-dialog__content--centered': is_content_centered, }); - - const is_text = typeof children === 'string' || typeof children?.props?.i18n_default_text === 'string'; + // + const is_text = + typeof children === 'string' || + (React.isValidElement(children) && typeof children?.props?.i18n_default_text === 'string'); const dialog = (