Skip to content

Commit 7a2f56c

Browse files
author
Jovert Lota Palonpon
committed
[UI] Added modals component
1 parent 1a39b2b commit 7a2f56c

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

resources/js/ui/Modal.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import { Confirmation } from './Modals';
5+
6+
const Modal = props => {
7+
const { type, ...other } = props;
8+
9+
switch (type) {
10+
case 'confirmation':
11+
return <Confirmation {...props} />;
12+
break;
13+
}
14+
};
15+
16+
Modal.propTypes = {
17+
type: PropTypes.oneOf(['confirmation']),
18+
title: PropTypes.string.isRequired,
19+
body: PropTypes.oneOfType([PropTypes.string, PropTypes.element]).isRequired,
20+
};
21+
22+
export default Modal;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import {
5+
Button,
6+
Dialog,
7+
DialogActions,
8+
DialogContent,
9+
DialogContentText,
10+
DialogTitle,
11+
} from '@material-ui/core';
12+
13+
const Confirmation = props => {
14+
const {
15+
title,
16+
body,
17+
confirmText,
18+
confirmed,
19+
cancelText,
20+
cancelled,
21+
} = props;
22+
23+
return (
24+
<Dialog
25+
open
26+
onClose={cancelled}
27+
aria-labelledby="alert-dialog-title"
28+
aria-describedby="alert-dialog-description"
29+
>
30+
<DialogTitle id="alert-dialog-title">{title}</DialogTitle>
31+
32+
<DialogContent>
33+
<DialogContentText id="alert-dialog-description">
34+
{body}
35+
</DialogContentText>
36+
</DialogContent>
37+
38+
<DialogActions>
39+
<Button onClick={cancelled} color="primary">
40+
{cancelText ? cancelText : Lang.get('resources.cancel')}
41+
</Button>
42+
43+
<Button onClick={confirmed} color="secondary" autoFocus>
44+
{confirmText ? confirmText : Lang.get('resources.confirm')}
45+
</Button>
46+
</DialogActions>
47+
</Dialog>
48+
);
49+
};
50+
51+
Confirmation.propTypes = {
52+
title: PropTypes.string.isRequired,
53+
body: PropTypes.string.isRequired,
54+
confirmText: PropTypes.string,
55+
confirmed: PropTypes.func,
56+
cancelText: PropTypes.string,
57+
cancelled: PropTypes.func,
58+
};
59+
60+
export default Confirmation;

resources/js/ui/Modals/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Confirmation } from './Confirmation';

resources/js/ui/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { default as Modal } from './Modal';
12
export { default as Snackbar } from './Snackbar';
23
export { default as Table } from './Table';
34
export { default as TableToolbar } from './TableToolbar/TableToolbar';

0 commit comments

Comments
 (0)