Skip to content

Commit fe75e17

Browse files
authored
Merge pull request #58 from lvlsgroup/fix-react-datepicker-api
created a url base modal to account for mobile back button and fixed …
2 parents ee9132e + 6532ec4 commit fe75e17

File tree

15 files changed

+653
-75
lines changed

15 files changed

+653
-75
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "react-component-lib",
66
"author": "lvlsgroup",
77
"description": "A component library for react",
8-
"version": "0.9.32",
8+
"version": "0.9.33",
99
"main": "src/server/server.js",
1010
"license": "MIT",
1111
"scripts": {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import React from 'react';
2+
import classNames from 'classnames';
3+
import PropTypes from 'prop-types';
4+
import Button from '@rc-lib-client/components/inputs/button/Button';
5+
import Flex from '@rc-lib-client/components/flex/Flex';
6+
import CrossIcon from '@rc-lib-client/components/icons/crossIcon/CrossIcon';
7+
import Image from '@rc-lib-client/components/images/image/Image';
8+
import styles from './defaultDialog.scss';
9+
10+
const DefaultDialog = ({
11+
className,
12+
title,
13+
description,
14+
onConfirm,
15+
toggleModal,
16+
btnContainerClassName,
17+
confirmBtnClassName,
18+
labelBtnConfirm = 'Yes',
19+
cancelBtnClassName,
20+
labelBtnCancel = 'No',
21+
closeImgClassName,
22+
closeImgIcon,
23+
passBackData,
24+
}) => {
25+
function handleConfirm() {
26+
onConfirm(toggleModal, passBackData);
27+
}
28+
29+
return (
30+
<div className={classNames(styles.defaultDialog, className)}>
31+
{closeImgIcon ? (
32+
<Image
33+
className={classNames(closeImgClassName)}
34+
src={closeImgIcon}
35+
alt="Close"
36+
/>
37+
) : (
38+
<CrossIcon
39+
className={classNames(styles.btnCross)}
40+
onClick={toggleModal}
41+
crossColor="black"
42+
mdCross
43+
/>
44+
)}
45+
{title && <h3 className={styles.title}>{title}</h3>}
46+
{description && <p className={styles.description}>{description}</p>}
47+
{(onConfirm || toggleModal) && (
48+
<Flex
49+
className={classNames(styles.btnContainer, btnContainerClassName)}
50+
>
51+
{onConfirm && (
52+
<Button
53+
className={classNames(styles.buttonConfirm, confirmBtnClassName)}
54+
label={labelBtnConfirm}
55+
onClick={handleConfirm}
56+
/>
57+
)}
58+
{toggleModal && (
59+
<Button
60+
className={classNames(styles.btnCancel, cancelBtnClassName)}
61+
label={labelBtnCancel}
62+
onClick={toggleModal}
63+
/>
64+
)}
65+
</Flex>
66+
)}
67+
</div>
68+
);
69+
};
70+
71+
DefaultDialog.propTypes = {
72+
className: PropTypes.string,
73+
title: PropTypes.string,
74+
CustomClose: PropTypes.any,
75+
description: PropTypes.string,
76+
onConfirm: PropTypes.func,
77+
toggleModal: PropTypes.func,
78+
btnContainerClassName: PropTypes.string,
79+
confirmBtnClassName: PropTypes.string,
80+
labelBtnConfirm: PropTypes.string,
81+
cancelBtnClassName: PropTypes.string,
82+
labelBtnCancel: PropTypes.string,
83+
closeImgClassName: PropTypes.string,
84+
closeImgIcon: PropTypes.string,
85+
passBackData: PropTypes.any,
86+
};
87+
88+
export default DefaultDialog;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.defaultDialog {
2+
width: 632px;
3+
background-color: $color-white;
4+
padding: 16px 16px 72px 16px;
5+
6+
@include bpMobileLandscape(){
7+
box-shadow: 0 -1px 20px 0 rgba(0, 0, 0, 0.19);
8+
}
9+
10+
.btnCross {
11+
margin-left: auto;
12+
}
13+
14+
.title {
15+
margin: 24px auto 0 auto;
16+
text-align: center;
17+
max-width: 415px;
18+
}
19+
20+
.description {
21+
margin: 16px auto 0 auto;
22+
text-align: center;
23+
max-width: 415px;
24+
}
25+
26+
.btnContainer {
27+
margin: 56px auto 0 auto;
28+
width: 262px;
29+
30+
.buttonConfirm {
31+
flex: 1;
32+
}
33+
34+
.btnCancel {
35+
margin-left: 16px;
36+
flex: 1;
37+
38+
&:first-child {
39+
margin-left: 0;
40+
}
41+
}
42+
}
43+
}

src/client/components/flex/Flex.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const RES_COL_SYSTEM = [
1414
'col222s1616',
1515
'col12_s1616',
1616
'col12_s88',
17-
'col12_s1616',
1817
'col12_s2424',
1918
];
2019

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import classNames from 'classnames';
34
import { DivOrButton } from '@rc-lib-client/shared/utils/dom/dom';
45
import styles from './crossIcon.scss';
56

6-
const CrossIcon = React.memo(({ onClick, crossColor, style }) => {
7+
const CrossIcon = ({
8+
className,
9+
onClick,
10+
crossColor,
11+
style,
12+
lgCross,
13+
mdCross,
14+
expandXonHover = true,
15+
}) => {
716
return (
817
<DivOrButton
9-
className={`${styles.crossIcon} ${styles[crossColor]}`}
18+
className={classNames(
19+
className,
20+
styles.crossIcon,
21+
styles[crossColor],
22+
lgCross && styles.lgCross,
23+
mdCross && styles.mdCross,
24+
expandXonHover && styles.expandCrossOnHover
25+
)}
1026
onClick={onClick}
1127
style={style}
1228
/>
1329
);
14-
});
30+
};
1531

1632
CrossIcon.propTypes = {
33+
className: PropTypes.string,
1734
onClick: PropTypes.func,
1835
crossColor: PropTypes.string,
1936
style: PropTypes.object,
37+
lgCross: PropTypes.bool,
38+
mdCross: PropTypes.bool,
39+
expandXonHover: PropTypes.bool,
2040
};
2141

22-
export default CrossIcon;
42+
export default React.memo(CrossIcon);

src/client/components/icons/crossIcon/crossIcon.scss

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
width: 3px;
1616
}
1717

18+
&.mdCross {
19+
&:before, &:after {
20+
height: 60%;
21+
}
22+
}
23+
24+
&.lgCross {
25+
&:before, &:after {
26+
height: 80%;
27+
}
28+
}
29+
1830
&:before {
1931
transform: rotate(45deg);
2032
}
@@ -41,9 +53,27 @@ button.crossIcon {
4153
border: none;
4254
cursor: pointer;
4355

44-
&:hover {
45-
&:before, &:after {
46-
height: 60%;
56+
&.expandCrossOnHover {
57+
&:hover {
58+
&:before, &:after {
59+
height: 56%;
60+
}
61+
}
62+
63+
&.mdCross {
64+
&:hover {
65+
&:before, &:after {
66+
height: 72%;
67+
}
68+
}
69+
}
70+
71+
&.lgCross {
72+
&:hover {
73+
&:before, &:after {
74+
height: 92%;
75+
}
76+
}
4777
}
4878
}
4979
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React, { useEffect } from 'react';
2+
import classNames from 'classnames';
3+
import { toggleFixedBody } from '@rc-lib-client/shared/utils/dom/dom';
4+
import styles from './modalUtils.scss';
5+
6+
export const ModalFixedCentered = React.memo(
7+
({
8+
ModalContent,
9+
modalClassName,
10+
toggleModal,
11+
isModalOpen,
12+
stopBackgroundScroll,
13+
}) => {
14+
const onMountAndUnMount = () => {
15+
if (stopBackgroundScroll && isModalOpen) {
16+
toggleFixedBody();
17+
}
18+
19+
const closeOnEscapeKey = (e) => {
20+
if (e.keyCode === 27) {
21+
toggleModal();
22+
}
23+
};
24+
25+
window.addEventListener('keyup', closeOnEscapeKey, false);
26+
27+
return () => {
28+
if (stopBackgroundScroll && isModalOpen) {
29+
toggleFixedBody();
30+
}
31+
window.removeEventListener('keyup', closeOnEscapeKey, false);
32+
};
33+
};
34+
35+
useEffect(onMountAndUnMount, []);
36+
37+
const isDiv = ModalContent && ModalContent.type === 'div';
38+
39+
return (
40+
<div className={classNames(styles.modal, modalClassName)}>
41+
{React.cloneElement(
42+
ModalContent,
43+
!isDiv && { toggleModal, isModalOpen }
44+
)}
45+
</div>
46+
);
47+
}
48+
);
49+
50+
export const OverLay = React.memo(({ overlayClassName, onClick }) => {
51+
return (
52+
<div
53+
className={classNames(styles.overLay, overlayClassName)}
54+
onClick={onClick}
55+
/>
56+
);
57+
});
58+
59+
export const Trigger = React.memo(
60+
({
61+
TriggerElement,
62+
triggerPropKey,
63+
shouldTriggerReceiveState,
64+
isTriggerOpen,
65+
onClick,
66+
}) => {
67+
return (
68+
<>
69+
{React.cloneElement(TriggerElement, {
70+
[triggerPropKey]: onClick,
71+
...(shouldTriggerReceiveState && {
72+
isTriggerOpen: isTriggerOpen,
73+
}),
74+
})}
75+
</>
76+
);
77+
}
78+
);

src/client/components/modals/modalQuick/modalTrigger.scss renamed to src/client/components/modals/modalFixedCentered/modalUtils.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
}
1414

1515
.modal {
16+
max-width: 100%;
17+
max-height: 100%;
1618
position: fixed;
1719
top: 50%;
1820
left: 50%;
19-
max-height: 80%;
2021
transform: translate(-50%, -50%);
2122
z-index: 981;
2223
display: flex;

0 commit comments

Comments
 (0)