Skip to content

Commit 9931308

Browse files
authored
refactor: Migrate Modal component to TypeScript (#263)
1 parent df8fb22 commit 9931308

File tree

2 files changed

+43
-63
lines changed

2 files changed

+43
-63
lines changed

exports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default {
123123
'ui/MessageSearchFileItem': 'src/ui/MessageSearchFileItem/index.tsx',
124124
'ui/MessageSearchItem': 'src/ui/MessageSearchItem/index.tsx',
125125
'ui/MessageStatus': 'src/ui/MessageStatus/index.tsx',
126-
'ui/Modal': 'src/ui/Modal/index.jsx',
126+
'ui/Modal': 'src/ui/Modal/index.tsx',
127127
'ui/OGMessageItemBody': 'src/ui/OGMessageItemBody/index.tsx',
128128
'ui/OpenChannelAdminMessage': 'src/ui/OpenChannelAdminMessage/index.tsx',
129129
// should we rename it to OpenChannel?
Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
import React, { useContext } from 'react';
2-
import PropTypes from 'prop-types';
1+
import React, { ReactElement, useContext } from 'react';
32
import { createPortal } from 'react-dom';
43

54
import './index.scss';
65

7-
import { LocalizationContext } from '../../lib/LocalizationContext';
86
import { MODAL_ROOT } from '../../hooks/useModal/ModalRoot';
9-
import IconButton from '../IconButton';
10-
import Icon, { IconTypes, IconColors } from '../Icon';
7+
import { LocalizationContext } from '../../lib/LocalizationContext';
8+
119
import Button, { ButtonTypes } from '../Button';
10+
import Icon, { IconTypes, IconColors } from '../Icon';
11+
import IconButton from '../IconButton';
1212
import Label, { LabelTypography, LabelColors } from '../Label';
13-
import { noop } from '../../utils/utils';
1413

15-
export const ModalHeader = ({ titleText }) => (
14+
export interface ModalHeaderProps {
15+
titleText: string;
16+
}
17+
export const ModalHeader = ({ titleText }: ModalHeaderProps): ReactElement => (
1618
<div className="sendbird-modal__header">
1719
<Label type={LabelTypography.H_1} color={LabelColors.ONBACKGROUND_1}>
1820
{titleText}
1921
</Label>
2022
</div>
2123
);
22-
ModalHeader.propTypes = {
23-
titleText: PropTypes.string.isRequired,
24-
};
2524

26-
export const ModalBody = ({ children }) => (
25+
export interface ModalBodyProps {
26+
children?: ReactElement;
27+
}
28+
export const ModalBody = ({ children }: ModalBodyProps): ReactElement => (
2729
<div className="sendbird-modal__body">
2830
<Label
2931
type={LabelTypography.SUBTITLE_1}
@@ -33,23 +35,21 @@ export const ModalBody = ({ children }) => (
3335
</Label>
3436
</div>
3537
);
36-
ModalBody.propTypes = {
37-
children: PropTypes.oneOfType([
38-
PropTypes.element.isRequired,
39-
PropTypes.arrayOf(PropTypes.element.isRequired),
40-
]),
41-
};
42-
ModalBody.defaultProps = {
43-
children: null,
44-
};
4538

39+
export interface ModalFooterProps {
40+
submitText: string;
41+
disabled?: boolean;
42+
type?: string;
43+
onCancel: () => void;
44+
onSubmit: () => void;
45+
}
4646
export const ModalFooter = ({
47+
submitText,
48+
disabled = false,
49+
type = ButtonTypes.DANGER,
4750
onSubmit,
4851
onCancel,
49-
disabled = false,
50-
submitText,
51-
type,
52-
}) => {
52+
}: ModalFooterProps): ReactElement => {
5353
const { stringSet } = useContext(LocalizationContext);
5454
return (
5555
<div className="sendbird-modal__footer">
@@ -65,28 +65,26 @@ export const ModalFooter = ({
6565
);
6666
};
6767

68-
ModalFooter.propTypes = {
69-
onCancel: PropTypes.func.isRequired,
70-
onSubmit: PropTypes.func.isRequired,
71-
submitText: PropTypes.string.isRequired,
72-
disabled: PropTypes.bool,
73-
type: PropTypes.string,
74-
};
75-
ModalFooter.defaultProps = {
76-
disabled: false,
77-
type: ButtonTypes.DANGER,
78-
};
79-
80-
export default function Modal(props) {
68+
export interface ModalProps {
69+
children: ReactElement;
70+
titleText?: string;
71+
submitText?: string;
72+
disabled?: boolean;
73+
hideFooter?: boolean;
74+
type?: string;
75+
onCancel?: () => void;
76+
onSubmit?: () => void;
77+
}
78+
export default function Modal(props: ModalProps): ReactElement {
8179
const {
82-
children,
83-
onCancel,
84-
onSubmit = noop,
85-
disabled,
86-
submitText,
80+
children = null,
8781
titleText,
88-
hideFooter,
89-
type,
82+
submitText,
83+
disabled = false,
84+
hideFooter = false,
85+
type = ButtonTypes.DANGER,
86+
onCancel = () => {/* noop */},
87+
onSubmit = () => {/* noop */},
9088
} = props;
9189
return createPortal((
9290
<div className="sendbird-modal">
@@ -123,21 +121,3 @@ export default function Modal(props) {
123121
</div>
124122
), document.getElementById(MODAL_ROOT));
125123
}
126-
127-
Modal.propTypes = {
128-
children: PropTypes.oneOfType([
129-
PropTypes.element,
130-
PropTypes.arrayOf(PropTypes.element),
131-
]),
132-
onCancel: PropTypes.func.isRequired,
133-
onSubmit: PropTypes.func,
134-
hideFooter: PropTypes.bool,
135-
disabled: PropTypes.bool,
136-
type: PropTypes.string,
137-
};
138-
Modal.defaultProps = {
139-
children: null,
140-
hideFooter: false,
141-
disabled: false,
142-
type: ButtonTypes.DANGER,
143-
};

0 commit comments

Comments
 (0)